]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/3.7.6/grsecurity-2.9.1-3.7.6-201302071938.patch
Auto commit, grsecurity-3.1-4.9.13-201703052141.patch added.
[thirdparty/grsecurity-scrape.git] / test / 3.7.6 / grsecurity-2.9.1-3.7.6-201302071938.patch
CommitLineData
077766f4
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 b6de2ea..5ba90ee 100644
255--- a/Makefile
256+++ b/Makefile
257@@ -241,8 +241,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
258
259 HOSTCC = gcc
260 HOSTCXX = g++
261-HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
262-HOSTCXXFLAGS = -O2
263+HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
264+HOSTCLFAGS += $(call cc-option, -Wno-empty-body)
265+HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
266
267 # Decide whether to build built-in, modular, or both.
268 # Normally, just do built-in.
269@@ -414,8 +415,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
270 # Rules shared between *config targets and build targets
271
272 # Basic helpers built in scripts/
273-PHONY += scripts_basic
274-scripts_basic:
275+PHONY += scripts_basic gcc-plugins
276+scripts_basic: gcc-plugins
277 $(Q)$(MAKE) $(build)=scripts/basic
278 $(Q)rm -f .tmp_quiet_recordmcount
279
280@@ -575,6 +576,60 @@ else
281 KBUILD_CFLAGS += -O2
282 endif
283
284+ifndef DISABLE_PAX_PLUGINS
285+PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
286+ifneq ($(PLUGINCC),)
287+ifndef DISABLE_PAX_CONSTIFY_PLUGIN
288+ifndef CONFIG_UML
289+CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
290+endif
291+endif
292+ifdef CONFIG_PAX_MEMORY_STACKLEAK
293+STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
294+STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
295+endif
296+ifdef CONFIG_KALLOCSTAT_PLUGIN
297+KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
298+endif
299+ifdef CONFIG_PAX_KERNEXEC_PLUGIN
300+KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
301+KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
302+KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
303+endif
304+ifdef CONFIG_CHECKER_PLUGIN
305+ifeq ($(call cc-ifversion, -ge, 0406, y), y)
306+CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
307+endif
308+endif
309+COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
310+ifdef CONFIG_PAX_SIZE_OVERFLOW
311+SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
312+endif
313+ifdef CONFIG_PAX_LATENT_ENTROPY
314+LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
315+endif
316+GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
317+GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
318+GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS)
319+GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
320+export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN
321+ifeq ($(KBUILD_EXTMOD),)
322+gcc-plugins:
323+ $(Q)$(MAKE) $(build)=tools/gcc
324+else
325+gcc-plugins: ;
326+endif
327+else
328+gcc-plugins:
329+ifeq ($(call cc-ifversion, -ge, 0405, y), y)
330+ $(error Your gcc installation does not support plugins. If the necessary headers for plugin support are missing, they should be installed. On Debian, apt-get install gcc-<ver>-plugin-dev. If you choose to ignore this error and lessen the improvements provided by this patch, re-run make with the DISABLE_PAX_PLUGINS=y argument.))
331+else
332+ $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
333+endif
334+ $(Q)echo "PAX_MEMORY_STACKLEAK and other features will be less secure"
335+endif
336+endif
337+
338 include $(srctree)/arch/$(SRCARCH)/Makefile
339
340 ifdef CONFIG_READABLE_ASM
341@@ -731,7 +786,7 @@ export mod_sign_cmd
342
343
344 ifeq ($(KBUILD_EXTMOD),)
345-core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
346+core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
347
348 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
349 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
350@@ -778,6 +833,8 @@ endif
351
352 # The actual objects are generated when descending,
353 # make sure no implicit rule kicks in
354+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
355+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
356 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
357
358 # Handle descending into subdirectories listed in $(vmlinux-dirs)
359@@ -787,7 +844,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
360 # Error messages still appears in the original language
361
362 PHONY += $(vmlinux-dirs)
363-$(vmlinux-dirs): prepare scripts
364+$(vmlinux-dirs): gcc-plugins prepare scripts
365 $(Q)$(MAKE) $(build)=$@
366
367 # Store (new) KERNELRELASE string in include/config/kernel.release
368@@ -831,6 +888,7 @@ prepare0: archprepare FORCE
369 $(Q)$(MAKE) $(build)=.
370
371 # All the preparing..
372+prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
373 prepare: prepare0
374
375 # Generate some files
376@@ -938,6 +996,8 @@ all: modules
377 # using awk while concatenating to the final file.
378
379 PHONY += modules
380+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
381+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
382 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
383 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
384 @$(kecho) ' Building modules, stage 2.';
385@@ -953,7 +1013,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
386
387 # Target to prepare building external modules
388 PHONY += modules_prepare
389-modules_prepare: prepare scripts
390+modules_prepare: gcc-plugins prepare scripts
391
392 # Target to install modules
393 PHONY += modules_install
394@@ -1013,7 +1073,7 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
395 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
396 signing_key.priv signing_key.x509 x509.genkey \
397 extra_certificates signing_key.x509.keyid \
398- signing_key.x509.signer
399+ signing_key.x509.signer tools/gcc/size_overflow_hash.h
400
401 # clean - Delete most, but leave enough to build external modules
402 #
403@@ -1053,6 +1113,7 @@ distclean: mrproper
404 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
405 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
406 -o -name '.*.rej' \
407+ -o -name '.*.rej' -o -name '*.so' \
408 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
409 -type f -print | xargs rm -f
410
411@@ -1213,6 +1274,8 @@ PHONY += $(module-dirs) modules
412 $(module-dirs): crmodverdir $(objtree)/Module.symvers
413 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
414
415+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
416+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
417 modules: $(module-dirs)
418 @$(kecho) ' Building modules, stage 2.';
419 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
420@@ -1349,17 +1412,21 @@ else
421 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
422 endif
423
424-%.s: %.c prepare scripts FORCE
425+%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
426+%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
427+%.s: %.c gcc-plugins prepare scripts FORCE
428 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
429 %.i: %.c prepare scripts FORCE
430 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
431-%.o: %.c prepare scripts FORCE
432+%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
433+%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
434+%.o: %.c gcc-plugins prepare scripts FORCE
435 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
436 %.lst: %.c prepare scripts FORCE
437 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
438-%.s: %.S prepare scripts FORCE
439+%.s: %.S gcc-plugins prepare scripts FORCE
440 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
441-%.o: %.S prepare scripts FORCE
442+%.o: %.S gcc-plugins prepare scripts FORCE
443 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
444 %.symtypes: %.c prepare scripts FORCE
445 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
446@@ -1369,11 +1436,15 @@ endif
447 $(cmd_crmodverdir)
448 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
449 $(build)=$(build-dir)
450-%/: prepare scripts FORCE
451+%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
452+%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
453+%/: gcc-plugins prepare scripts FORCE
454 $(cmd_crmodverdir)
455 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
456 $(build)=$(build-dir)
457-%.ko: prepare scripts FORCE
458+%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
459+%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
460+%.ko: gcc-plugins prepare scripts FORCE
461 $(cmd_crmodverdir)
462 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
463 $(build)=$(build-dir) $(@:.ko=.o)
464diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
465index c2cbe4f..f7264b4 100644
466--- a/arch/alpha/include/asm/atomic.h
467+++ b/arch/alpha/include/asm/atomic.h
468@@ -250,6 +250,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
469 #define atomic_dec(v) atomic_sub(1,(v))
470 #define atomic64_dec(v) atomic64_sub(1,(v))
471
472+#define atomic64_read_unchecked(v) atomic64_read(v)
473+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
474+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
475+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
476+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
477+#define atomic64_inc_unchecked(v) atomic64_inc(v)
478+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
479+#define atomic64_dec_unchecked(v) atomic64_dec(v)
480+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
481+
482 #define smp_mb__before_atomic_dec() smp_mb()
483 #define smp_mb__after_atomic_dec() smp_mb()
484 #define smp_mb__before_atomic_inc() smp_mb()
485diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
486index ad368a9..fbe0f25 100644
487--- a/arch/alpha/include/asm/cache.h
488+++ b/arch/alpha/include/asm/cache.h
489@@ -4,19 +4,19 @@
490 #ifndef __ARCH_ALPHA_CACHE_H
491 #define __ARCH_ALPHA_CACHE_H
492
493+#include <linux/const.h>
494
495 /* Bytes per L1 (data) cache line. */
496 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
497-# define L1_CACHE_BYTES 64
498 # define L1_CACHE_SHIFT 6
499 #else
500 /* Both EV4 and EV5 are write-through, read-allocate,
501 direct-mapped, physical.
502 */
503-# define L1_CACHE_BYTES 32
504 # define L1_CACHE_SHIFT 5
505 #endif
506
507+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
508 #define SMP_CACHE_BYTES L1_CACHE_BYTES
509
510 #endif
511diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
512index 968d999..d36b2df 100644
513--- a/arch/alpha/include/asm/elf.h
514+++ b/arch/alpha/include/asm/elf.h
515@@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
516
517 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
518
519+#ifdef CONFIG_PAX_ASLR
520+#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
521+
522+#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
523+#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
524+#endif
525+
526 /* $0 is set by ld.so to a pointer to a function which might be
527 registered using atexit. This provides a mean for the dynamic
528 linker to call DT_FINI functions for shared libraries that have
529diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
530index bc2a0da..8ad11ee 100644
531--- a/arch/alpha/include/asm/pgalloc.h
532+++ b/arch/alpha/include/asm/pgalloc.h
533@@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
534 pgd_set(pgd, pmd);
535 }
536
537+static inline void
538+pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
539+{
540+ pgd_populate(mm, pgd, pmd);
541+}
542+
543 extern pgd_t *pgd_alloc(struct mm_struct *mm);
544
545 static inline void
546diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
547index 81a4342..348b927 100644
548--- a/arch/alpha/include/asm/pgtable.h
549+++ b/arch/alpha/include/asm/pgtable.h
550@@ -102,6 +102,17 @@ struct vm_area_struct;
551 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
552 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
553 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
554+
555+#ifdef CONFIG_PAX_PAGEEXEC
556+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
557+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
558+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
559+#else
560+# define PAGE_SHARED_NOEXEC PAGE_SHARED
561+# define PAGE_COPY_NOEXEC PAGE_COPY
562+# define PAGE_READONLY_NOEXEC PAGE_READONLY
563+#endif
564+
565 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
566
567 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
568diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
569index 2fd00b7..cfd5069 100644
570--- a/arch/alpha/kernel/module.c
571+++ b/arch/alpha/kernel/module.c
572@@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
573
574 /* The small sections were sorted to the end of the segment.
575 The following should definitely cover them. */
576- gp = (u64)me->module_core + me->core_size - 0x8000;
577+ gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
578 got = sechdrs[me->arch.gotsecindex].sh_addr;
579
580 for (i = 0; i < n; i++) {
581diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
582index 14db93e..47bed62 100644
583--- a/arch/alpha/kernel/osf_sys.c
584+++ b/arch/alpha/kernel/osf_sys.c
585@@ -1295,16 +1295,16 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
586 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
587
588 static unsigned long
589-arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
590- unsigned long limit)
591+arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
592+ unsigned long limit, unsigned long flags)
593 {
594 struct vm_area_struct *vma = find_vma(current->mm, addr);
595-
596+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
597 while (1) {
598 /* At this point: (!vma || addr < vma->vm_end). */
599 if (limit - len < addr)
600 return -ENOMEM;
601- if (!vma || addr + len <= vma->vm_start)
602+ if (check_heap_stack_gap(vma, addr, len, offset))
603 return addr;
604 addr = vma->vm_end;
605 vma = vma->vm_next;
606@@ -1340,20 +1340,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
607 merely specific addresses, but regions of memory -- perhaps
608 this feature should be incorporated into all ports? */
609
610+#ifdef CONFIG_PAX_RANDMMAP
611+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
612+#endif
613+
614 if (addr) {
615- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
616+ addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
617 if (addr != (unsigned long) -ENOMEM)
618 return addr;
619 }
620
621 /* Next, try allocating at TASK_UNMAPPED_BASE. */
622- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
623- len, limit);
624+ addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
625+
626 if (addr != (unsigned long) -ENOMEM)
627 return addr;
628
629 /* Finally, try allocating in low memory. */
630- addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
631+ addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
632
633 return addr;
634 }
635diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
636index 0c4132d..88f0d53 100644
637--- a/arch/alpha/mm/fault.c
638+++ b/arch/alpha/mm/fault.c
639@@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
640 __reload_thread(pcb);
641 }
642
643+#ifdef CONFIG_PAX_PAGEEXEC
644+/*
645+ * PaX: decide what to do with offenders (regs->pc = fault address)
646+ *
647+ * returns 1 when task should be killed
648+ * 2 when patched PLT trampoline was detected
649+ * 3 when unpatched PLT trampoline was detected
650+ */
651+static int pax_handle_fetch_fault(struct pt_regs *regs)
652+{
653+
654+#ifdef CONFIG_PAX_EMUPLT
655+ int err;
656+
657+ do { /* PaX: patched PLT emulation #1 */
658+ unsigned int ldah, ldq, jmp;
659+
660+ err = get_user(ldah, (unsigned int *)regs->pc);
661+ err |= get_user(ldq, (unsigned int *)(regs->pc+4));
662+ err |= get_user(jmp, (unsigned int *)(regs->pc+8));
663+
664+ if (err)
665+ break;
666+
667+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
668+ (ldq & 0xFFFF0000U) == 0xA77B0000U &&
669+ jmp == 0x6BFB0000U)
670+ {
671+ unsigned long r27, addr;
672+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
673+ unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
674+
675+ addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
676+ err = get_user(r27, (unsigned long *)addr);
677+ if (err)
678+ break;
679+
680+ regs->r27 = r27;
681+ regs->pc = r27;
682+ return 2;
683+ }
684+ } while (0);
685+
686+ do { /* PaX: patched PLT emulation #2 */
687+ unsigned int ldah, lda, br;
688+
689+ err = get_user(ldah, (unsigned int *)regs->pc);
690+ err |= get_user(lda, (unsigned int *)(regs->pc+4));
691+ err |= get_user(br, (unsigned int *)(regs->pc+8));
692+
693+ if (err)
694+ break;
695+
696+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
697+ (lda & 0xFFFF0000U) == 0xA77B0000U &&
698+ (br & 0xFFE00000U) == 0xC3E00000U)
699+ {
700+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
701+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
702+ unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
703+
704+ regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
705+ regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
706+ return 2;
707+ }
708+ } while (0);
709+
710+ do { /* PaX: unpatched PLT emulation */
711+ unsigned int br;
712+
713+ err = get_user(br, (unsigned int *)regs->pc);
714+
715+ if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
716+ unsigned int br2, ldq, nop, jmp;
717+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
718+
719+ addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
720+ err = get_user(br2, (unsigned int *)addr);
721+ err |= get_user(ldq, (unsigned int *)(addr+4));
722+ err |= get_user(nop, (unsigned int *)(addr+8));
723+ err |= get_user(jmp, (unsigned int *)(addr+12));
724+ err |= get_user(resolver, (unsigned long *)(addr+16));
725+
726+ if (err)
727+ break;
728+
729+ if (br2 == 0xC3600000U &&
730+ ldq == 0xA77B000CU &&
731+ nop == 0x47FF041FU &&
732+ jmp == 0x6B7B0000U)
733+ {
734+ regs->r28 = regs->pc+4;
735+ regs->r27 = addr+16;
736+ regs->pc = resolver;
737+ return 3;
738+ }
739+ }
740+ } while (0);
741+#endif
742+
743+ return 1;
744+}
745+
746+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
747+{
748+ unsigned long i;
749+
750+ printk(KERN_ERR "PAX: bytes at PC: ");
751+ for (i = 0; i < 5; i++) {
752+ unsigned int c;
753+ if (get_user(c, (unsigned int *)pc+i))
754+ printk(KERN_CONT "???????? ");
755+ else
756+ printk(KERN_CONT "%08x ", c);
757+ }
758+ printk("\n");
759+}
760+#endif
761
762 /*
763 * This routine handles page faults. It determines the address,
764@@ -133,8 +251,29 @@ retry:
765 good_area:
766 si_code = SEGV_ACCERR;
767 if (cause < 0) {
768- if (!(vma->vm_flags & VM_EXEC))
769+ if (!(vma->vm_flags & VM_EXEC)) {
770+
771+#ifdef CONFIG_PAX_PAGEEXEC
772+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
773+ goto bad_area;
774+
775+ up_read(&mm->mmap_sem);
776+ switch (pax_handle_fetch_fault(regs)) {
777+
778+#ifdef CONFIG_PAX_EMUPLT
779+ case 2:
780+ case 3:
781+ return;
782+#endif
783+
784+ }
785+ pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
786+ do_group_exit(SIGKILL);
787+#else
788 goto bad_area;
789+#endif
790+
791+ }
792 } else if (!cause) {
793 /* Allow reads even for write-only mappings */
794 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
795diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
796index c79f61f..9ac0642 100644
797--- a/arch/arm/include/asm/atomic.h
798+++ b/arch/arm/include/asm/atomic.h
799@@ -17,17 +17,35 @@
800 #include <asm/barrier.h>
801 #include <asm/cmpxchg.h>
802
803+#ifdef CONFIG_GENERIC_ATOMIC64
804+#include <asm-generic/atomic64.h>
805+#endif
806+
807 #define ATOMIC_INIT(i) { (i) }
808
809 #ifdef __KERNEL__
810
811+#define _ASM_EXTABLE(from, to) \
812+" .pushsection __ex_table,\"a\"\n"\
813+" .align 3\n" \
814+" .long " #from ", " #to"\n" \
815+" .popsection"
816+
817 /*
818 * On ARM, ordinary assignment (str instruction) doesn't clear the local
819 * strex/ldrex monitor on some implementations. The reason we can use it for
820 * atomic_set() is the clrex or dummy strex done on every exception return.
821 */
822 #define atomic_read(v) (*(volatile int *)&(v)->counter)
823+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
824+{
825+ return v->counter;
826+}
827 #define atomic_set(v,i) (((v)->counter) = (i))
828+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
829+{
830+ v->counter = i;
831+}
832
833 #if __LINUX_ARM_ARCH__ >= 6
834
835@@ -42,6 +60,35 @@ static inline void atomic_add(int i, atomic_t *v)
836 int result;
837
838 __asm__ __volatile__("@ atomic_add\n"
839+"1: ldrex %1, [%3]\n"
840+" adds %0, %1, %4\n"
841+
842+#ifdef CONFIG_PAX_REFCOUNT
843+" bvc 3f\n"
844+"2: bkpt 0xf103\n"
845+"3:\n"
846+#endif
847+
848+" strex %1, %0, [%3]\n"
849+" teq %1, #0\n"
850+" bne 1b"
851+
852+#ifdef CONFIG_PAX_REFCOUNT
853+"\n4:\n"
854+ _ASM_EXTABLE(2b, 4b)
855+#endif
856+
857+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
858+ : "r" (&v->counter), "Ir" (i)
859+ : "cc");
860+}
861+
862+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
863+{
864+ unsigned long tmp;
865+ int result;
866+
867+ __asm__ __volatile__("@ atomic_add_unchecked\n"
868 "1: ldrex %0, [%3]\n"
869 " add %0, %0, %4\n"
870 " strex %1, %0, [%3]\n"
871@@ -60,6 +107,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
872 smp_mb();
873
874 __asm__ __volatile__("@ atomic_add_return\n"
875+"1: ldrex %1, [%3]\n"
876+" adds %0, %1, %4\n"
877+
878+#ifdef CONFIG_PAX_REFCOUNT
879+" bvc 3f\n"
880+" mov %0, %1\n"
881+"2: bkpt 0xf103\n"
882+"3:\n"
883+#endif
884+
885+" strex %1, %0, [%3]\n"
886+" teq %1, #0\n"
887+" bne 1b"
888+
889+#ifdef CONFIG_PAX_REFCOUNT
890+"\n4:\n"
891+ _ASM_EXTABLE(2b, 4b)
892+#endif
893+
894+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
895+ : "r" (&v->counter), "Ir" (i)
896+ : "cc");
897+
898+ smp_mb();
899+
900+ return result;
901+}
902+
903+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
904+{
905+ unsigned long tmp;
906+ int result;
907+
908+ smp_mb();
909+
910+ __asm__ __volatile__("@ atomic_add_return_unchecked\n"
911 "1: ldrex %0, [%3]\n"
912 " add %0, %0, %4\n"
913 " strex %1, %0, [%3]\n"
914@@ -80,6 +163,35 @@ static inline void atomic_sub(int i, atomic_t *v)
915 int result;
916
917 __asm__ __volatile__("@ atomic_sub\n"
918+"1: ldrex %1, [%3]\n"
919+" subs %0, %1, %4\n"
920+
921+#ifdef CONFIG_PAX_REFCOUNT
922+" bvc 3f\n"
923+"2: bkpt 0xf103\n"
924+"3:\n"
925+#endif
926+
927+" strex %1, %0, [%3]\n"
928+" teq %1, #0\n"
929+" bne 1b"
930+
931+#ifdef CONFIG_PAX_REFCOUNT
932+"\n4:\n"
933+ _ASM_EXTABLE(2b, 4b)
934+#endif
935+
936+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
937+ : "r" (&v->counter), "Ir" (i)
938+ : "cc");
939+}
940+
941+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
942+{
943+ unsigned long tmp;
944+ int result;
945+
946+ __asm__ __volatile__("@ atomic_sub_unchecked\n"
947 "1: ldrex %0, [%3]\n"
948 " sub %0, %0, %4\n"
949 " strex %1, %0, [%3]\n"
950@@ -98,11 +210,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
951 smp_mb();
952
953 __asm__ __volatile__("@ atomic_sub_return\n"
954-"1: ldrex %0, [%3]\n"
955-" sub %0, %0, %4\n"
956+"1: ldrex %1, [%3]\n"
957+" subs %0, %1, %4\n"
958+
959+#ifdef CONFIG_PAX_REFCOUNT
960+" bvc 3f\n"
961+" mov %0, %1\n"
962+"2: bkpt 0xf103\n"
963+"3:\n"
964+#endif
965+
966 " strex %1, %0, [%3]\n"
967 " teq %1, #0\n"
968 " bne 1b"
969+
970+#ifdef CONFIG_PAX_REFCOUNT
971+"\n4:\n"
972+ _ASM_EXTABLE(2b, 4b)
973+#endif
974+
975 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
976 : "r" (&v->counter), "Ir" (i)
977 : "cc");
978@@ -134,6 +260,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
979 return oldval;
980 }
981
982+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
983+{
984+ unsigned long oldval, res;
985+
986+ smp_mb();
987+
988+ do {
989+ __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
990+ "ldrex %1, [%3]\n"
991+ "mov %0, #0\n"
992+ "teq %1, %4\n"
993+ "strexeq %0, %5, [%3]\n"
994+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
995+ : "r" (&ptr->counter), "Ir" (old), "r" (new)
996+ : "cc");
997+ } while (res);
998+
999+ smp_mb();
1000+
1001+ return oldval;
1002+}
1003+
1004 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1005 {
1006 unsigned long tmp, tmp2;
1007@@ -167,7 +315,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1008
1009 return val;
1010 }
1011+
1012+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1013+{
1014+ return atomic_add_return(i, v);
1015+}
1016+
1017 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1018+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1019+{
1020+ (void) atomic_add_return(i, v);
1021+}
1022
1023 static inline int atomic_sub_return(int i, atomic_t *v)
1024 {
1025@@ -182,6 +340,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1026 return val;
1027 }
1028 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1029+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1030+{
1031+ (void) atomic_sub_return(i, v);
1032+}
1033
1034 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1035 {
1036@@ -197,6 +359,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1037 return ret;
1038 }
1039
1040+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1041+{
1042+ return atomic_cmpxchg(v, old, new);
1043+}
1044+
1045 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1046 {
1047 unsigned long flags;
1048@@ -209,6 +376,10 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1049 #endif /* __LINUX_ARM_ARCH__ */
1050
1051 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1052+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1053+{
1054+ return xchg(&v->counter, new);
1055+}
1056
1057 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1058 {
1059@@ -221,11 +392,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1060 }
1061
1062 #define atomic_inc(v) atomic_add(1, v)
1063+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1064+{
1065+ atomic_add_unchecked(1, v);
1066+}
1067 #define atomic_dec(v) atomic_sub(1, v)
1068+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1069+{
1070+ atomic_sub_unchecked(1, v);
1071+}
1072
1073 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1074+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1075+{
1076+ return atomic_add_return_unchecked(1, v) == 0;
1077+}
1078 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1079 #define atomic_inc_return(v) (atomic_add_return(1, v))
1080+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1081+{
1082+ return atomic_add_return_unchecked(1, v);
1083+}
1084 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1085 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1086
1087@@ -241,6 +428,14 @@ typedef struct {
1088 u64 __aligned(8) counter;
1089 } atomic64_t;
1090
1091+#ifdef CONFIG_PAX_REFCOUNT
1092+typedef struct {
1093+ u64 __aligned(8) counter;
1094+} atomic64_unchecked_t;
1095+#else
1096+typedef atomic64_t atomic64_unchecked_t;
1097+#endif
1098+
1099 #define ATOMIC64_INIT(i) { (i) }
1100
1101 static inline u64 atomic64_read(const atomic64_t *v)
1102@@ -256,6 +451,19 @@ static inline u64 atomic64_read(const atomic64_t *v)
1103 return result;
1104 }
1105
1106+static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
1107+{
1108+ u64 result;
1109+
1110+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1111+" ldrexd %0, %H0, [%1]"
1112+ : "=&r" (result)
1113+ : "r" (&v->counter), "Qo" (v->counter)
1114+ );
1115+
1116+ return result;
1117+}
1118+
1119 static inline void atomic64_set(atomic64_t *v, u64 i)
1120 {
1121 u64 tmp;
1122@@ -270,6 +478,20 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1123 : "cc");
1124 }
1125
1126+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1127+{
1128+ u64 tmp;
1129+
1130+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1131+"1: ldrexd %0, %H0, [%2]\n"
1132+" strexd %0, %3, %H3, [%2]\n"
1133+" teq %0, #0\n"
1134+" bne 1b"
1135+ : "=&r" (tmp), "=Qo" (v->counter)
1136+ : "r" (&v->counter), "r" (i)
1137+ : "cc");
1138+}
1139+
1140 static inline void atomic64_add(u64 i, atomic64_t *v)
1141 {
1142 u64 result;
1143@@ -278,6 +500,36 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1144 __asm__ __volatile__("@ atomic64_add\n"
1145 "1: ldrexd %0, %H0, [%3]\n"
1146 " adds %0, %0, %4\n"
1147+" adcs %H0, %H0, %H4\n"
1148+
1149+#ifdef CONFIG_PAX_REFCOUNT
1150+" bvc 3f\n"
1151+"2: bkpt 0xf103\n"
1152+"3:\n"
1153+#endif
1154+
1155+" strexd %1, %0, %H0, [%3]\n"
1156+" teq %1, #0\n"
1157+" bne 1b"
1158+
1159+#ifdef CONFIG_PAX_REFCOUNT
1160+"\n4:\n"
1161+ _ASM_EXTABLE(2b, 4b)
1162+#endif
1163+
1164+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1165+ : "r" (&v->counter), "r" (i)
1166+ : "cc");
1167+}
1168+
1169+static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
1170+{
1171+ u64 result;
1172+ unsigned long tmp;
1173+
1174+ __asm__ __volatile__("@ atomic64_add_unchecked\n"
1175+"1: ldrexd %0, %H0, [%3]\n"
1176+" adds %0, %0, %4\n"
1177 " adc %H0, %H0, %H4\n"
1178 " strexd %1, %0, %H0, [%3]\n"
1179 " teq %1, #0\n"
1180@@ -289,12 +541,49 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1181
1182 static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
1183 {
1184- u64 result;
1185- unsigned long tmp;
1186+ u64 result, tmp;
1187
1188 smp_mb();
1189
1190 __asm__ __volatile__("@ atomic64_add_return\n"
1191+"1: ldrexd %1, %H1, [%3]\n"
1192+" adds %0, %1, %4\n"
1193+" adcs %H0, %H1, %H4\n"
1194+
1195+#ifdef CONFIG_PAX_REFCOUNT
1196+" bvc 3f\n"
1197+" mov %0, %1\n"
1198+" mov %H0, %H1\n"
1199+"2: bkpt 0xf103\n"
1200+"3:\n"
1201+#endif
1202+
1203+" strexd %1, %0, %H0, [%3]\n"
1204+" teq %1, #0\n"
1205+" bne 1b"
1206+
1207+#ifdef CONFIG_PAX_REFCOUNT
1208+"\n4:\n"
1209+ _ASM_EXTABLE(2b, 4b)
1210+#endif
1211+
1212+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1213+ : "r" (&v->counter), "r" (i)
1214+ : "cc");
1215+
1216+ smp_mb();
1217+
1218+ return result;
1219+}
1220+
1221+static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
1222+{
1223+ u64 result;
1224+ unsigned long tmp;
1225+
1226+ smp_mb();
1227+
1228+ __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1229 "1: ldrexd %0, %H0, [%3]\n"
1230 " adds %0, %0, %4\n"
1231 " adc %H0, %H0, %H4\n"
1232@@ -318,6 +607,36 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1233 __asm__ __volatile__("@ atomic64_sub\n"
1234 "1: ldrexd %0, %H0, [%3]\n"
1235 " subs %0, %0, %4\n"
1236+" sbcs %H0, %H0, %H4\n"
1237+
1238+#ifdef CONFIG_PAX_REFCOUNT
1239+" bvc 3f\n"
1240+"2: bkpt 0xf103\n"
1241+"3:\n"
1242+#endif
1243+
1244+" strexd %1, %0, %H0, [%3]\n"
1245+" teq %1, #0\n"
1246+" bne 1b"
1247+
1248+#ifdef CONFIG_PAX_REFCOUNT
1249+"\n4:\n"
1250+ _ASM_EXTABLE(2b, 4b)
1251+#endif
1252+
1253+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1254+ : "r" (&v->counter), "r" (i)
1255+ : "cc");
1256+}
1257+
1258+static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
1259+{
1260+ u64 result;
1261+ unsigned long tmp;
1262+
1263+ __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1264+"1: ldrexd %0, %H0, [%3]\n"
1265+" subs %0, %0, %4\n"
1266 " sbc %H0, %H0, %H4\n"
1267 " strexd %1, %0, %H0, [%3]\n"
1268 " teq %1, #0\n"
1269@@ -329,18 +648,32 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1270
1271 static inline u64 atomic64_sub_return(u64 i, atomic64_t *v)
1272 {
1273- u64 result;
1274- unsigned long tmp;
1275+ u64 result, tmp;
1276
1277 smp_mb();
1278
1279 __asm__ __volatile__("@ atomic64_sub_return\n"
1280-"1: ldrexd %0, %H0, [%3]\n"
1281-" subs %0, %0, %4\n"
1282-" sbc %H0, %H0, %H4\n"
1283+"1: ldrexd %1, %H1, [%3]\n"
1284+" subs %0, %1, %4\n"
1285+" sbcs %H0, %H1, %H4\n"
1286+
1287+#ifdef CONFIG_PAX_REFCOUNT
1288+" bvc 3f\n"
1289+" mov %0, %1\n"
1290+" mov %H0, %H1\n"
1291+"2: bkpt 0xf103\n"
1292+"3:\n"
1293+#endif
1294+
1295 " strexd %1, %0, %H0, [%3]\n"
1296 " teq %1, #0\n"
1297 " bne 1b"
1298+
1299+#ifdef CONFIG_PAX_REFCOUNT
1300+"\n4:\n"
1301+ _ASM_EXTABLE(2b, 4b)
1302+#endif
1303+
1304 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1305 : "r" (&v->counter), "r" (i)
1306 : "cc");
1307@@ -374,6 +707,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1308 return oldval;
1309 }
1310
1311+static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1312+{
1313+ u64 oldval;
1314+ unsigned long res;
1315+
1316+ smp_mb();
1317+
1318+ do {
1319+ __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1320+ "ldrexd %1, %H1, [%3]\n"
1321+ "mov %0, #0\n"
1322+ "teq %1, %4\n"
1323+ "teqeq %H1, %H4\n"
1324+ "strexdeq %0, %5, %H5, [%3]"
1325+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1326+ : "r" (&ptr->counter), "r" (old), "r" (new)
1327+ : "cc");
1328+ } while (res);
1329+
1330+ smp_mb();
1331+
1332+ return oldval;
1333+}
1334+
1335 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1336 {
1337 u64 result;
1338@@ -397,21 +754,34 @@ static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1339
1340 static inline u64 atomic64_dec_if_positive(atomic64_t *v)
1341 {
1342- u64 result;
1343- unsigned long tmp;
1344+ u64 result, tmp;
1345
1346 smp_mb();
1347
1348 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1349-"1: ldrexd %0, %H0, [%3]\n"
1350-" subs %0, %0, #1\n"
1351-" sbc %H0, %H0, #0\n"
1352+"1: ldrexd %1, %H1, [%3]\n"
1353+" subs %0, %1, #1\n"
1354+" sbcs %H0, %H1, #0\n"
1355+
1356+#ifdef CONFIG_PAX_REFCOUNT
1357+" bvc 3f\n"
1358+" mov %0, %1\n"
1359+" mov %H0, %H1\n"
1360+"2: bkpt 0xf103\n"
1361+"3:\n"
1362+#endif
1363+
1364 " teq %H0, #0\n"
1365-" bmi 2f\n"
1366+" bmi 4f\n"
1367 " strexd %1, %0, %H0, [%3]\n"
1368 " teq %1, #0\n"
1369 " bne 1b\n"
1370-"2:"
1371+"4:\n"
1372+
1373+#ifdef CONFIG_PAX_REFCOUNT
1374+ _ASM_EXTABLE(2b, 4b)
1375+#endif
1376+
1377 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1378 : "r" (&v->counter)
1379 : "cc");
1380@@ -434,13 +804,25 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1381 " teq %0, %5\n"
1382 " teqeq %H0, %H5\n"
1383 " moveq %1, #0\n"
1384-" beq 2f\n"
1385+" beq 4f\n"
1386 " adds %0, %0, %6\n"
1387-" adc %H0, %H0, %H6\n"
1388+" adcs %H0, %H0, %H6\n"
1389+
1390+#ifdef CONFIG_PAX_REFCOUNT
1391+" bvc 3f\n"
1392+"2: bkpt 0xf103\n"
1393+"3:\n"
1394+#endif
1395+
1396 " strexd %2, %0, %H0, [%4]\n"
1397 " teq %2, #0\n"
1398 " bne 1b\n"
1399-"2:"
1400+"4:\n"
1401+
1402+#ifdef CONFIG_PAX_REFCOUNT
1403+ _ASM_EXTABLE(2b, 4b)
1404+#endif
1405+
1406 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1407 : "r" (&v->counter), "r" (u), "r" (a)
1408 : "cc");
1409@@ -453,10 +835,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1410
1411 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1412 #define atomic64_inc(v) atomic64_add(1LL, (v))
1413+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1414 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1415+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1416 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1417 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1418 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1419+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1420 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1421 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1422 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1423diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1424index 75fe66b..ba3dee4 100644
1425--- a/arch/arm/include/asm/cache.h
1426+++ b/arch/arm/include/asm/cache.h
1427@@ -4,8 +4,10 @@
1428 #ifndef __ASMARM_CACHE_H
1429 #define __ASMARM_CACHE_H
1430
1431+#include <linux/const.h>
1432+
1433 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1434-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1435+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1436
1437 /*
1438 * Memory returned by kmalloc() may be used for DMA, so we must make
1439@@ -24,5 +26,6 @@
1440 #endif
1441
1442 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1443+#define __read_only __attribute__ ((__section__(".data..read_only")))
1444
1445 #endif
1446diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1447index e1489c5..d418304 100644
1448--- a/arch/arm/include/asm/cacheflush.h
1449+++ b/arch/arm/include/asm/cacheflush.h
1450@@ -116,7 +116,7 @@ struct cpu_cache_fns {
1451 void (*dma_unmap_area)(const void *, size_t, int);
1452
1453 void (*dma_flush_range)(const void *, const void *);
1454-};
1455+} __no_const;
1456
1457 /*
1458 * Select the calling method
1459diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1460index 7eb18c1..e38b6d2 100644
1461--- a/arch/arm/include/asm/cmpxchg.h
1462+++ b/arch/arm/include/asm/cmpxchg.h
1463@@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1464
1465 #define xchg(ptr,x) \
1466 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1467+#define xchg_unchecked(ptr,x) \
1468+ ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1469
1470 #include <asm-generic/cmpxchg-local.h>
1471
1472diff --git a/arch/arm/include/asm/delay.h b/arch/arm/include/asm/delay.h
1473index ab98fdd..6b19938 100644
1474--- a/arch/arm/include/asm/delay.h
1475+++ b/arch/arm/include/asm/delay.h
1476@@ -24,9 +24,9 @@ extern struct arm_delay_ops {
1477 void (*delay)(unsigned long);
1478 void (*const_udelay)(unsigned long);
1479 void (*udelay)(unsigned long);
1480-} arm_delay_ops;
1481+} *arm_delay_ops;
1482
1483-#define __delay(n) arm_delay_ops.delay(n)
1484+#define __delay(n) arm_delay_ops->delay(n)
1485
1486 /*
1487 * This function intentionally does not exist; if you see references to
1488@@ -47,8 +47,8 @@ extern void __bad_udelay(void);
1489 * first constant multiplications gets optimized away if the delay is
1490 * a constant)
1491 */
1492-#define __udelay(n) arm_delay_ops.udelay(n)
1493-#define __const_udelay(n) arm_delay_ops.const_udelay(n)
1494+#define __udelay(n) arm_delay_ops->udelay(n)
1495+#define __const_udelay(n) arm_delay_ops->const_udelay(n)
1496
1497 #define udelay(n) \
1498 (__builtin_constant_p(n) ? \
1499diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1500index 38050b1..9d90e8b 100644
1501--- a/arch/arm/include/asm/elf.h
1502+++ b/arch/arm/include/asm/elf.h
1503@@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1504 the loader. We need to make sure that it is out of the way of the program
1505 that it will "exec", and that there is sufficient room for the brk. */
1506
1507-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1508+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1509+
1510+#ifdef CONFIG_PAX_ASLR
1511+#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1512+
1513+#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1514+#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1515+#endif
1516
1517 /* When the program starts, a1 contains a pointer to a function to be
1518 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1519@@ -126,8 +133,4 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1520 extern void elf_set_personality(const struct elf32_hdr *);
1521 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1522
1523-struct mm_struct;
1524-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1525-#define arch_randomize_brk arch_randomize_brk
1526-
1527 #endif
1528diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1529index 83eb2f7..ed77159 100644
1530--- a/arch/arm/include/asm/kmap_types.h
1531+++ b/arch/arm/include/asm/kmap_types.h
1532@@ -4,6 +4,6 @@
1533 /*
1534 * This is the "bare minimum". AIO seems to require this.
1535 */
1536-#define KM_TYPE_NR 16
1537+#define KM_TYPE_NR 17
1538
1539 #endif
1540diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1541index 9e614a1..3302cca 100644
1542--- a/arch/arm/include/asm/mach/dma.h
1543+++ b/arch/arm/include/asm/mach/dma.h
1544@@ -22,7 +22,7 @@ struct dma_ops {
1545 int (*residue)(unsigned int, dma_t *); /* optional */
1546 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1547 const char *type;
1548-};
1549+} __do_const;
1550
1551 struct dma_struct {
1552 void *addr; /* single DMA address */
1553diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1554index 195ac2f..2272f0d 100644
1555--- a/arch/arm/include/asm/mach/map.h
1556+++ b/arch/arm/include/asm/mach/map.h
1557@@ -34,6 +34,9 @@ struct map_desc {
1558 #define MT_MEMORY_ITCM 13
1559 #define MT_MEMORY_SO 14
1560 #define MT_MEMORY_DMA_READY 15
1561+#define MT_MEMORY_R 16
1562+#define MT_MEMORY_RW 17
1563+#define MT_MEMORY_RX 18
1564
1565 #ifdef CONFIG_MMU
1566 extern void iotable_init(struct map_desc *, int);
1567diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1568index 53426c6..c7baff3 100644
1569--- a/arch/arm/include/asm/outercache.h
1570+++ b/arch/arm/include/asm/outercache.h
1571@@ -35,7 +35,7 @@ struct outer_cache_fns {
1572 #endif
1573 void (*set_debug)(unsigned long);
1574 void (*resume)(void);
1575-};
1576+} __no_const;
1577
1578 #ifdef CONFIG_OUTER_CACHE
1579
1580diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1581index 812a494..71fc0b6 100644
1582--- a/arch/arm/include/asm/page.h
1583+++ b/arch/arm/include/asm/page.h
1584@@ -114,7 +114,7 @@ struct cpu_user_fns {
1585 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1586 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1587 unsigned long vaddr, struct vm_area_struct *vma);
1588-};
1589+} __no_const;
1590
1591 #ifdef MULTI_USER
1592 extern struct cpu_user_fns cpu_user;
1593diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1594index 943504f..84d0f84 100644
1595--- a/arch/arm/include/asm/pgalloc.h
1596+++ b/arch/arm/include/asm/pgalloc.h
1597@@ -17,6 +17,7 @@
1598 #include <asm/processor.h>
1599 #include <asm/cacheflush.h>
1600 #include <asm/tlbflush.h>
1601+#include <asm/system_info.h>
1602
1603 #define check_pgt_cache() do { } while (0)
1604
1605@@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1606 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1607 }
1608
1609+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1610+{
1611+ pud_populate(mm, pud, pmd);
1612+}
1613+
1614 #else /* !CONFIG_ARM_LPAE */
1615
1616 /*
1617@@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1618 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1619 #define pmd_free(mm, pmd) do { } while (0)
1620 #define pud_populate(mm,pmd,pte) BUG()
1621+#define pud_populate_kernel(mm,pmd,pte) BUG()
1622
1623 #endif /* CONFIG_ARM_LPAE */
1624
1625@@ -126,6 +133,16 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1626 __free_page(pte);
1627 }
1628
1629+static inline void __pmd_update(pmd_t *pmdp, pmdval_t prot)
1630+{
1631+ pmdval_t pmdval = pmd_val(*pmdp) | prot;
1632+ pmdp[0] = __pmd(pmdval);
1633+#ifndef CONFIG_ARM_LPAE
1634+ pmdp[1] = __pmd(pmdval + 256 * sizeof(pte_t));
1635+#endif
1636+ flush_pmd_entry(pmdp);
1637+}
1638+
1639 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1640 pmdval_t prot)
1641 {
1642@@ -155,7 +172,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1643 static inline void
1644 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1645 {
1646- __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1647+ __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1648 }
1649 #define pmd_pgtable(pmd) pmd_page(pmd)
1650
1651diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1652index 5cfba15..d437dc2 100644
1653--- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1654+++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1655@@ -20,12 +20,15 @@
1656 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1657 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1658 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1659+#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* PXN */
1660 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1661 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1662 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1663+
1664 /*
1665 * - section
1666 */
1667+#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0)
1668 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1669 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1670 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1671@@ -37,6 +40,7 @@
1672 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1673 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1674 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1675+#define PMD_SECT_AP_RDONLY (_AT(pmdval_t, 0))
1676
1677 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1678 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1679diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1680index 2317a71..1897391 100644
1681--- a/arch/arm/include/asm/pgtable-2level.h
1682+++ b/arch/arm/include/asm/pgtable-2level.h
1683@@ -123,6 +123,7 @@
1684 #define L_PTE_USER (_AT(pteval_t, 1) << 8)
1685 #define L_PTE_XN (_AT(pteval_t, 1) << 9)
1686 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
1687+#define L_PTE_PXN (_AT(pteval_t, 1) << 11) /* v7*/
1688
1689 /*
1690 * These are the memory types, defined to be compatible with
1691diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
1692index d795282..d82ff13 100644
1693--- a/arch/arm/include/asm/pgtable-3level-hwdef.h
1694+++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
1695@@ -32,6 +32,7 @@
1696 #define PMD_TYPE_SECT (_AT(pmdval_t, 1) << 0)
1697 #define PMD_BIT4 (_AT(pmdval_t, 0))
1698 #define PMD_DOMAIN(x) (_AT(pmdval_t, 0))
1699+#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 59) /* PXNTable */
1700
1701 /*
1702 * - section
1703@@ -41,9 +42,11 @@
1704 #define PMD_SECT_S (_AT(pmdval_t, 3) << 8)
1705 #define PMD_SECT_AF (_AT(pmdval_t, 1) << 10)
1706 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 11)
1707+#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 53)
1708 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 54)
1709 #define PMD_SECT_AP_WRITE (_AT(pmdval_t, 0))
1710 #define PMD_SECT_AP_READ (_AT(pmdval_t, 0))
1711+#define PMD_SECT_AP_RDONLY (_AT(pmdval_t, 1) << 7)
1712 #define PMD_SECT_TEX(x) (_AT(pmdval_t, 0))
1713
1714 /*
1715@@ -66,6 +69,7 @@
1716 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1717 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
1718 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
1719+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1720 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
1721
1722 /*
1723diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
1724index b249035..4ab204b 100644
1725--- a/arch/arm/include/asm/pgtable-3level.h
1726+++ b/arch/arm/include/asm/pgtable-3level.h
1727@@ -73,6 +73,7 @@
1728 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
1729 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1730 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
1731+#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1732 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
1733 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
1734 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
1735@@ -80,6 +81,7 @@
1736 /*
1737 * To be used in assembly code with the upper page attributes.
1738 */
1739+#define L_PTE_PXN_HIGH (1 << (53 - 32))
1740 #define L_PTE_XN_HIGH (1 << (54 - 32))
1741 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
1742
1743diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
1744index 08c1231..1031bb4 100644
1745--- a/arch/arm/include/asm/pgtable.h
1746+++ b/arch/arm/include/asm/pgtable.h
1747@@ -30,6 +30,9 @@
1748 #include <asm/pgtable-2level.h>
1749 #endif
1750
1751+#define ktla_ktva(addr) (addr)
1752+#define ktva_ktla(addr) (addr)
1753+
1754 /*
1755 * Just any arbitrary offset to the start of the vmalloc VM area: the
1756 * current 8MB value just means that there will be a 8MB "hole" after the
1757@@ -45,6 +48,9 @@
1758 #define LIBRARY_TEXT_START 0x0c000000
1759
1760 #ifndef __ASSEMBLY__
1761+extern pteval_t __supported_pte_mask;
1762+extern pmdval_t __supported_pmd_mask;
1763+
1764 extern void __pte_error(const char *file, int line, pte_t);
1765 extern void __pmd_error(const char *file, int line, pmd_t);
1766 extern void __pgd_error(const char *file, int line, pgd_t);
1767@@ -53,6 +59,17 @@ extern void __pgd_error(const char *file, int line, pgd_t);
1768 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
1769 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
1770
1771+#define __HAVE_ARCH_PAX_OPEN_KERNEL
1772+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
1773+
1774+#ifdef CONFIG_PAX_KERNEXEC
1775+static inline unsigned long pax_open_kernel(void) { return 0; /* TODO */ }
1776+static inline unsigned long pax_close_kernel(void) { return 0; /* TODO */ }
1777+#else
1778+static inline unsigned long pax_open_kernel(void) { return 0; }
1779+static inline unsigned long pax_close_kernel(void) { return 0; }
1780+#endif
1781+
1782 /*
1783 * This is the lowest virtual address we can permit any user space
1784 * mapping to be mapped at. This is particularly important for
1785@@ -63,8 +80,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
1786 /*
1787 * The pgprot_* and protection_map entries will be fixed up in runtime
1788 * to include the cachable and bufferable bits based on memory policy,
1789- * as well as any architecture dependent bits like global/ASID and SMP
1790- * shared mapping bits.
1791+ * as well as any architecture dependent bits like global/ASID, PXN,
1792+ * and SMP shared mapping bits.
1793 */
1794 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
1795
1796@@ -242,7 +259,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
1797
1798 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
1799 {
1800- const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER;
1801+ const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER | __supported_pte_mask;
1802 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
1803 return pte;
1804 }
1805diff --git a/arch/arm/include/asm/proc-fns.h b/arch/arm/include/asm/proc-fns.h
1806index f3628fb..a0672dd 100644
1807--- a/arch/arm/include/asm/proc-fns.h
1808+++ b/arch/arm/include/asm/proc-fns.h
1809@@ -75,7 +75,7 @@ extern struct processor {
1810 unsigned int suspend_size;
1811 void (*do_suspend)(void *);
1812 void (*do_resume)(void *);
1813-} processor;
1814+} __do_const processor;
1815
1816 #ifndef MULTI_CPU
1817 extern void cpu_proc_init(void);
1818diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
1819index 2e3be16..4dc90fc 100644
1820--- a/arch/arm/include/asm/smp.h
1821+++ b/arch/arm/include/asm/smp.h
1822@@ -106,7 +106,7 @@ struct smp_operations {
1823 int (*cpu_disable)(unsigned int cpu);
1824 #endif
1825 #endif
1826-};
1827+} __no_const;
1828
1829 /*
1830 * set platform specific SMP operations
1831diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
1832index 8477b4c..801a6a9 100644
1833--- a/arch/arm/include/asm/thread_info.h
1834+++ b/arch/arm/include/asm/thread_info.h
1835@@ -151,6 +151,12 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1836 #define TIF_SYSCALL_TRACE 8
1837 #define TIF_SYSCALL_AUDIT 9
1838 #define TIF_SYSCALL_TRACEPOINT 10
1839+
1840+/* within 8 bits of TIF_SYSCALL_TRACE
1841+ to meet flexible second operand requirements
1842+*/
1843+#define TIF_GRSEC_SETXID 11
1844+
1845 #define TIF_USING_IWMMXT 17
1846 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
1847 #define TIF_RESTORE_SIGMASK 20
1848@@ -165,9 +171,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1849 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
1850 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
1851 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
1852+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
1853
1854 /* Checks for any syscall work in entry-common.S */
1855-#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
1856+#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | \
1857+ _TIF_GRSEC_SETXID)
1858
1859 /*
1860 * Change these and you break ASM code in entry-common.S
1861diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
1862index 7e1f760..f2c37b1 100644
1863--- a/arch/arm/include/asm/uaccess.h
1864+++ b/arch/arm/include/asm/uaccess.h
1865@@ -418,8 +418,23 @@ do { \
1866
1867
1868 #ifdef CONFIG_MMU
1869-extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
1870-extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
1871+extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
1872+extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
1873+
1874+static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
1875+{
1876+ check_object_size(to, n, false);
1877+
1878+ return ___copy_from_user(to, from, n);
1879+}
1880+
1881+static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
1882+{
1883+ check_object_size(from, n, true);
1884+
1885+ return ___copy_to_user(to, from, n);
1886+}
1887+
1888 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
1889 extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
1890 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
1891@@ -431,6 +446,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
1892
1893 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
1894 {
1895+ if ((long)n < 0)
1896+ return n;
1897+
1898 if (access_ok(VERIFY_READ, from, n))
1899 n = __copy_from_user(to, from, n);
1900 else /* security hole - plug it */
1901@@ -440,6 +458,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
1902
1903 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
1904 {
1905+ if ((long)n < 0)
1906+ return n;
1907+
1908 if (access_ok(VERIFY_WRITE, to, n))
1909 n = __copy_to_user(to, from, n);
1910 return n;
1911diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
1912index 96ee092..37f1844 100644
1913--- a/arch/arm/include/uapi/asm/ptrace.h
1914+++ b/arch/arm/include/uapi/asm/ptrace.h
1915@@ -73,7 +73,7 @@
1916 * ARMv7 groups of PSR bits
1917 */
1918 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
1919-#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
1920+#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
1921 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
1922 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
1923
1924diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
1925index 60d3b73..9168db0 100644
1926--- a/arch/arm/kernel/armksyms.c
1927+++ b/arch/arm/kernel/armksyms.c
1928@@ -89,8 +89,8 @@ EXPORT_SYMBOL(__memzero);
1929 #ifdef CONFIG_MMU
1930 EXPORT_SYMBOL(copy_page);
1931
1932-EXPORT_SYMBOL(__copy_from_user);
1933-EXPORT_SYMBOL(__copy_to_user);
1934+EXPORT_SYMBOL(___copy_from_user);
1935+EXPORT_SYMBOL(___copy_to_user);
1936 EXPORT_SYMBOL(__clear_user);
1937
1938 EXPORT_SYMBOL(__get_user_1);
1939diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
1940index 486a15a..d95523a 100644
1941--- a/arch/arm/kernel/head.S
1942+++ b/arch/arm/kernel/head.S
1943@@ -52,7 +52,9 @@
1944 .equ swapper_pg_dir, KERNEL_RAM_VADDR - PG_DIR_SIZE
1945
1946 .macro pgtbl, rd, phys
1947- add \rd, \phys, #TEXT_OFFSET - PG_DIR_SIZE
1948+ mov \rd, #TEXT_OFFSET
1949+ sub \rd, #PG_DIR_SIZE
1950+ add \rd, \rd, \phys
1951 .endm
1952
1953 /*
1954diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
1955index 1e9be5d..ef22b26 100644
1956--- a/arch/arm/kernel/module.c
1957+++ b/arch/arm/kernel/module.c
1958@@ -37,12 +37,37 @@
1959 #endif
1960
1961 #ifdef CONFIG_MMU
1962-void *module_alloc(unsigned long size)
1963+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
1964 {
1965+ if (!size || PAGE_ALIGN(size) > (MODULES_END - MODULES_VADDR))
1966+ return NULL;
1967 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
1968- GFP_KERNEL, PAGE_KERNEL_EXEC, -1,
1969+ GFP_KERNEL, prot, -1,
1970 __builtin_return_address(0));
1971 }
1972+
1973+void *module_alloc(unsigned long size)
1974+{
1975+
1976+#ifdef CONFIG_PAX_KERNEXEC
1977+ return __module_alloc(size, PAGE_KERNEL);
1978+#else
1979+ return __module_alloc(size, PAGE_KERNEL_EXEC);
1980+#endif
1981+
1982+}
1983+
1984+#ifdef CONFIG_PAX_KERNEXEC
1985+void module_free_exec(struct module *mod, void *module_region)
1986+{
1987+ module_free(mod, module_region);
1988+}
1989+
1990+void *module_alloc_exec(unsigned long size)
1991+{
1992+ return __module_alloc(size, PAGE_KERNEL_EXEC);
1993+}
1994+#endif
1995 #endif
1996
1997 int
1998diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
1999index 90084a6..a8b26bc 100644
2000--- a/arch/arm/kernel/process.c
2001+++ b/arch/arm/kernel/process.c
2002@@ -28,7 +28,6 @@
2003 #include <linux/tick.h>
2004 #include <linux/utsname.h>
2005 #include <linux/uaccess.h>
2006-#include <linux/random.h>
2007 #include <linux/hw_breakpoint.h>
2008 #include <linux/cpuidle.h>
2009 #include <linux/leds.h>
2010@@ -256,9 +255,10 @@ void machine_power_off(void)
2011 machine_shutdown();
2012 if (pm_power_off)
2013 pm_power_off();
2014+ BUG();
2015 }
2016
2017-void machine_restart(char *cmd)
2018+__noreturn void machine_restart(char *cmd)
2019 {
2020 machine_shutdown();
2021
2022@@ -283,8 +283,8 @@ void __show_regs(struct pt_regs *regs)
2023 init_utsname()->release,
2024 (int)strcspn(init_utsname()->version, " "),
2025 init_utsname()->version);
2026- print_symbol("PC is at %s\n", instruction_pointer(regs));
2027- print_symbol("LR is at %s\n", regs->ARM_lr);
2028+ printk("PC is at %pA\n", instruction_pointer(regs));
2029+ printk("LR is at %pA\n", regs->ARM_lr);
2030 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2031 "sp : %08lx ip : %08lx fp : %08lx\n",
2032 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2033@@ -451,12 +451,6 @@ unsigned long get_wchan(struct task_struct *p)
2034 return 0;
2035 }
2036
2037-unsigned long arch_randomize_brk(struct mm_struct *mm)
2038-{
2039- unsigned long range_end = mm->brk + 0x02000000;
2040- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2041-}
2042-
2043 #ifdef CONFIG_MMU
2044 /*
2045 * The vectors page is always readable from user space for the
2046diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2047index 739db3a..7f4a272 100644
2048--- a/arch/arm/kernel/ptrace.c
2049+++ b/arch/arm/kernel/ptrace.c
2050@@ -916,6 +916,10 @@ enum ptrace_syscall_dir {
2051 PTRACE_SYSCALL_EXIT,
2052 };
2053
2054+#ifdef CONFIG_GRKERNSEC_SETXID
2055+extern void gr_delayed_cred_worker(void);
2056+#endif
2057+
2058 static int ptrace_syscall_trace(struct pt_regs *regs, int scno,
2059 enum ptrace_syscall_dir dir)
2060 {
2061@@ -923,6 +927,11 @@ static int ptrace_syscall_trace(struct pt_regs *regs, int scno,
2062
2063 current_thread_info()->syscall = scno;
2064
2065+#ifdef CONFIG_GRKERNSEC_SETXID
2066+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2067+ gr_delayed_cred_worker();
2068+#endif
2069+
2070 if (!test_thread_flag(TIF_SYSCALL_TRACE))
2071 return scno;
2072
2073diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
2074index da1d1aa..ef9bc58 100644
2075--- a/arch/arm/kernel/setup.c
2076+++ b/arch/arm/kernel/setup.c
2077@@ -97,21 +97,23 @@ EXPORT_SYMBOL(system_serial_high);
2078 unsigned int elf_hwcap __read_mostly;
2079 EXPORT_SYMBOL(elf_hwcap);
2080
2081+pteval_t __supported_pte_mask __read_only;
2082+pmdval_t __supported_pmd_mask __read_only;
2083
2084 #ifdef MULTI_CPU
2085-struct processor processor __read_mostly;
2086+struct processor processor;
2087 #endif
2088 #ifdef MULTI_TLB
2089-struct cpu_tlb_fns cpu_tlb __read_mostly;
2090+struct cpu_tlb_fns cpu_tlb __read_only;
2091 #endif
2092 #ifdef MULTI_USER
2093-struct cpu_user_fns cpu_user __read_mostly;
2094+struct cpu_user_fns cpu_user __read_only;
2095 #endif
2096 #ifdef MULTI_CACHE
2097-struct cpu_cache_fns cpu_cache __read_mostly;
2098+struct cpu_cache_fns cpu_cache __read_only;
2099 #endif
2100 #ifdef CONFIG_OUTER_CACHE
2101-struct outer_cache_fns outer_cache __read_mostly;
2102+struct outer_cache_fns outer_cache __read_only;
2103 EXPORT_SYMBOL(outer_cache);
2104 #endif
2105
2106@@ -236,9 +238,13 @@ static int __get_cpu_architecture(void)
2107 asm("mrc p15, 0, %0, c0, c1, 4"
2108 : "=r" (mmfr0));
2109 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
2110- (mmfr0 & 0x000000f0) >= 0x00000030)
2111+ (mmfr0 & 0x000000f0) >= 0x00000030) {
2112 cpu_arch = CPU_ARCH_ARMv7;
2113- else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
2114+ if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
2115+ __supported_pte_mask |= L_PTE_PXN;
2116+ __supported_pmd_mask |= PMD_PXNTABLE;
2117+ }
2118+ } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
2119 (mmfr0 & 0x000000f0) == 0x00000020)
2120 cpu_arch = CPU_ARCH_ARMv6;
2121 else
2122@@ -455,7 +461,7 @@ static void __init setup_processor(void)
2123 __cpu_architecture = __get_cpu_architecture();
2124
2125 #ifdef MULTI_CPU
2126- processor = *list->proc;
2127+ memcpy((void *)&processor, list->proc, sizeof processor);
2128 #endif
2129 #ifdef MULTI_TLB
2130 cpu_tlb = *list->tlb;
2131diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
2132index fbc8b26..000ded0 100644
2133--- a/arch/arm/kernel/smp.c
2134+++ b/arch/arm/kernel/smp.c
2135@@ -70,7 +70,7 @@ enum ipi_msg_type {
2136
2137 static DECLARE_COMPLETION(cpu_running);
2138
2139-static struct smp_operations smp_ops;
2140+static struct smp_operations smp_ops __read_only;
2141
2142 void __init smp_set_ops(struct smp_operations *ops)
2143 {
2144diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
2145index b0179b8..7713948 100644
2146--- a/arch/arm/kernel/traps.c
2147+++ b/arch/arm/kernel/traps.c
2148@@ -57,7 +57,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
2149 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
2150 {
2151 #ifdef CONFIG_KALLSYMS
2152- printk("[<%08lx>] (%pS) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
2153+ printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
2154 #else
2155 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
2156 #endif
2157@@ -266,6 +266,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
2158 static int die_owner = -1;
2159 static unsigned int die_nest_count;
2160
2161+extern void gr_handle_kernel_exploit(void);
2162+
2163 static unsigned long oops_begin(void)
2164 {
2165 int cpu;
2166@@ -308,6 +310,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
2167 panic("Fatal exception in interrupt");
2168 if (panic_on_oops)
2169 panic("Fatal exception");
2170+
2171+ gr_handle_kernel_exploit();
2172+
2173 if (signr)
2174 do_exit(signr);
2175 }
2176diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
2177index 36ff15b..75d9e9d 100644
2178--- a/arch/arm/kernel/vmlinux.lds.S
2179+++ b/arch/arm/kernel/vmlinux.lds.S
2180@@ -8,7 +8,11 @@
2181 #include <asm/thread_info.h>
2182 #include <asm/memory.h>
2183 #include <asm/page.h>
2184-
2185+
2186+#ifdef CONFIG_PAX_KERNEXEC
2187+#include <asm/pgtable.h>
2188+#endif
2189+
2190 #define PROC_INFO \
2191 . = ALIGN(4); \
2192 VMLINUX_SYMBOL(__proc_info_begin) = .; \
2193@@ -90,6 +94,11 @@ SECTIONS
2194 _text = .;
2195 HEAD_TEXT
2196 }
2197+
2198+#ifdef CONFIG_PAX_KERNEXEC
2199+ . = ALIGN(1<<SECTION_SHIFT);
2200+#endif
2201+
2202 .text : { /* Real text segment */
2203 _stext = .; /* Text and read-only data */
2204 __exception_text_start = .;
2205@@ -133,6 +142,10 @@ SECTIONS
2206
2207 _etext = .; /* End of text and rodata section */
2208
2209+#ifdef CONFIG_PAX_KERNEXEC
2210+ . = ALIGN(1<<SECTION_SHIFT);
2211+#endif
2212+
2213 #ifndef CONFIG_XIP_KERNEL
2214 . = ALIGN(PAGE_SIZE);
2215 __init_begin = .;
2216@@ -192,6 +205,11 @@ SECTIONS
2217 . = PAGE_OFFSET + TEXT_OFFSET;
2218 #else
2219 __init_end = .;
2220+
2221+#ifdef CONFIG_PAX_KERNEXEC
2222+ . = ALIGN(1<<SECTION_SHIFT);
2223+#endif
2224+
2225 . = ALIGN(THREAD_SIZE);
2226 __data_loc = .;
2227 #endif
2228diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
2229index 66a477a..bee61d3 100644
2230--- a/arch/arm/lib/copy_from_user.S
2231+++ b/arch/arm/lib/copy_from_user.S
2232@@ -16,7 +16,7 @@
2233 /*
2234 * Prototype:
2235 *
2236- * size_t __copy_from_user(void *to, const void *from, size_t n)
2237+ * size_t ___copy_from_user(void *to, const void *from, size_t n)
2238 *
2239 * Purpose:
2240 *
2241@@ -84,11 +84,11 @@
2242
2243 .text
2244
2245-ENTRY(__copy_from_user)
2246+ENTRY(___copy_from_user)
2247
2248 #include "copy_template.S"
2249
2250-ENDPROC(__copy_from_user)
2251+ENDPROC(___copy_from_user)
2252
2253 .pushsection .fixup,"ax"
2254 .align 0
2255diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
2256index 6ee2f67..d1cce76 100644
2257--- a/arch/arm/lib/copy_page.S
2258+++ b/arch/arm/lib/copy_page.S
2259@@ -10,6 +10,7 @@
2260 * ASM optimised string functions
2261 */
2262 #include <linux/linkage.h>
2263+#include <linux/const.h>
2264 #include <asm/assembler.h>
2265 #include <asm/asm-offsets.h>
2266 #include <asm/cache.h>
2267diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
2268index d066df6..df28194 100644
2269--- a/arch/arm/lib/copy_to_user.S
2270+++ b/arch/arm/lib/copy_to_user.S
2271@@ -16,7 +16,7 @@
2272 /*
2273 * Prototype:
2274 *
2275- * size_t __copy_to_user(void *to, const void *from, size_t n)
2276+ * size_t ___copy_to_user(void *to, const void *from, size_t n)
2277 *
2278 * Purpose:
2279 *
2280@@ -88,11 +88,11 @@
2281 .text
2282
2283 ENTRY(__copy_to_user_std)
2284-WEAK(__copy_to_user)
2285+WEAK(___copy_to_user)
2286
2287 #include "copy_template.S"
2288
2289-ENDPROC(__copy_to_user)
2290+ENDPROC(___copy_to_user)
2291 ENDPROC(__copy_to_user_std)
2292
2293 .pushsection .fixup,"ax"
2294diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
2295index 0dc5385..45833ef 100644
2296--- a/arch/arm/lib/delay.c
2297+++ b/arch/arm/lib/delay.c
2298@@ -28,12 +28,14 @@
2299 /*
2300 * Default to the loop-based delay implementation.
2301 */
2302-struct arm_delay_ops arm_delay_ops = {
2303+static struct arm_delay_ops arm_loop_delay_ops = {
2304 .delay = __loop_delay,
2305 .const_udelay = __loop_const_udelay,
2306 .udelay = __loop_udelay,
2307 };
2308
2309+struct arm_delay_ops *arm_delay_ops __read_only = &arm_loop_delay_ops;
2310+
2311 static const struct delay_timer *delay_timer;
2312 static bool delay_calibrated;
2313
2314@@ -67,6 +69,12 @@ static void __timer_udelay(unsigned long usecs)
2315 __timer_const_udelay(usecs * UDELAY_MULT);
2316 }
2317
2318+static struct arm_delay_ops arm_timer_delay_ops = {
2319+ .delay = __timer_delay,
2320+ .const_udelay = __timer_const_udelay,
2321+ .udelay = __timer_udelay,
2322+};
2323+
2324 void __init register_current_timer_delay(const struct delay_timer *timer)
2325 {
2326 if (!delay_calibrated) {
2327@@ -74,9 +82,7 @@ void __init register_current_timer_delay(const struct delay_timer *timer)
2328 delay_timer = timer;
2329 lpj_fine = timer->freq / HZ;
2330 loops_per_jiffy = lpj_fine;
2331- arm_delay_ops.delay = __timer_delay;
2332- arm_delay_ops.const_udelay = __timer_const_udelay;
2333- arm_delay_ops.udelay = __timer_udelay;
2334+ arm_delay_ops = &arm_timer_delay_ops;
2335 delay_calibrated = true;
2336 } else {
2337 pr_info("Ignoring duplicate/late registration of read_current_timer delay\n");
2338diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
2339index 025f742..8432b08 100644
2340--- a/arch/arm/lib/uaccess_with_memcpy.c
2341+++ b/arch/arm/lib/uaccess_with_memcpy.c
2342@@ -104,7 +104,7 @@ out:
2343 }
2344
2345 unsigned long
2346-__copy_to_user(void __user *to, const void *from, unsigned long n)
2347+___copy_to_user(void __user *to, const void *from, unsigned long n)
2348 {
2349 /*
2350 * This test is stubbed out of the main function above to keep
2351diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
2352index 2c6c218..2b87c2d 100644
2353--- a/arch/arm/mach-kirkwood/common.c
2354+++ b/arch/arm/mach-kirkwood/common.c
2355@@ -150,7 +150,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
2356 clk_gate_ops.disable(hw);
2357 }
2358
2359-static struct clk_ops clk_gate_fn_ops;
2360+static int clk_gate_fn_is_enabled(struct clk_hw *hw)
2361+{
2362+ return clk_gate_ops.is_enabled(hw);
2363+}
2364+
2365+static struct clk_ops clk_gate_fn_ops = {
2366+ .enable = clk_gate_fn_enable,
2367+ .disable = clk_gate_fn_disable,
2368+ .is_enabled = clk_gate_fn_is_enabled,
2369+};
2370
2371 static struct clk __init *clk_register_gate_fn(struct device *dev,
2372 const char *name,
2373@@ -184,14 +193,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
2374 gate_fn->fn_en = fn_en;
2375 gate_fn->fn_dis = fn_dis;
2376
2377- /* ops is the gate ops, but with our enable/disable functions */
2378- if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
2379- clk_gate_fn_ops.disable != clk_gate_fn_disable) {
2380- clk_gate_fn_ops = clk_gate_ops;
2381- clk_gate_fn_ops.enable = clk_gate_fn_enable;
2382- clk_gate_fn_ops.disable = clk_gate_fn_disable;
2383- }
2384-
2385 clk = clk_register(dev, &gate_fn->gate.hw);
2386
2387 if (IS_ERR(clk))
2388diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
2389index d95f727..12f10dd 100644
2390--- a/arch/arm/mach-omap2/board-n8x0.c
2391+++ b/arch/arm/mach-omap2/board-n8x0.c
2392@@ -589,7 +589,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
2393 }
2394 #endif
2395
2396-static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
2397+static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
2398 .late_init = n8x0_menelaus_late_init,
2399 };
2400
2401diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
2402index 87cc6d0..fd4f248 100644
2403--- a/arch/arm/mach-omap2/omap_hwmod.c
2404+++ b/arch/arm/mach-omap2/omap_hwmod.c
2405@@ -189,10 +189,10 @@ struct omap_hwmod_soc_ops {
2406 int (*is_hardreset_asserted)(struct omap_hwmod *oh,
2407 struct omap_hwmod_rst_info *ohri);
2408 int (*init_clkdm)(struct omap_hwmod *oh);
2409-};
2410+} __no_const;
2411
2412 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
2413-static struct omap_hwmod_soc_ops soc_ops;
2414+static struct omap_hwmod_soc_ops soc_ops __read_only;
2415
2416 /* omap_hwmod_list contains all registered struct omap_hwmods */
2417 static LIST_HEAD(omap_hwmod_list);
2418diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
2419index 5dbf13f..9be36fd 100644
2420--- a/arch/arm/mm/fault.c
2421+++ b/arch/arm/mm/fault.c
2422@@ -25,6 +25,7 @@
2423 #include <asm/system_misc.h>
2424 #include <asm/system_info.h>
2425 #include <asm/tlbflush.h>
2426+#include <asm/sections.h>
2427
2428 #include "fault.h"
2429
2430@@ -138,6 +139,19 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
2431 if (fixup_exception(regs))
2432 return;
2433
2434+#ifdef CONFIG_PAX_KERNEXEC
2435+ if (fsr & FSR_WRITE) {
2436+ if (((unsigned long)_stext <= addr && addr < init_mm.end_code) || (MODULES_VADDR <= addr && addr < MODULES_END)) {
2437+ if (current->signal->curr_ip)
2438+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
2439+ &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
2440+ else
2441+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
2442+ current->comm, task_pid_nr(current), current_uid(), current_euid());
2443+ }
2444+ }
2445+#endif
2446+
2447 /*
2448 * No handler, we'll have to terminate things with extreme prejudice.
2449 */
2450@@ -174,6 +188,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
2451 }
2452 #endif
2453
2454+#ifdef CONFIG_PAX_PAGEEXEC
2455+ if (fsr & FSR_LNX_PF) {
2456+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
2457+ do_group_exit(SIGKILL);
2458+ }
2459+#endif
2460+
2461 tsk->thread.address = addr;
2462 tsk->thread.error_code = fsr;
2463 tsk->thread.trap_no = 14;
2464@@ -398,6 +419,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
2465 }
2466 #endif /* CONFIG_MMU */
2467
2468+#ifdef CONFIG_PAX_PAGEEXEC
2469+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2470+{
2471+ long i;
2472+
2473+ printk(KERN_ERR "PAX: bytes at PC: ");
2474+ for (i = 0; i < 20; i++) {
2475+ unsigned char c;
2476+ if (get_user(c, (__force unsigned char __user *)pc+i))
2477+ printk(KERN_CONT "?? ");
2478+ else
2479+ printk(KERN_CONT "%02x ", c);
2480+ }
2481+ printk("\n");
2482+
2483+ printk(KERN_ERR "PAX: bytes at SP-4: ");
2484+ for (i = -1; i < 20; i++) {
2485+ unsigned long c;
2486+ if (get_user(c, (__force unsigned long __user *)sp+i))
2487+ printk(KERN_CONT "???????? ");
2488+ else
2489+ printk(KERN_CONT "%08lx ", c);
2490+ }
2491+ printk("\n");
2492+}
2493+#endif
2494+
2495 /*
2496 * First Level Translation Fault Handler
2497 *
2498@@ -575,12 +623,41 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
2499 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
2500 struct siginfo info;
2501
2502+#ifdef CONFIG_PAX_KERNEXEC
2503+ if (!user_mode(regs) && is_xn_fault(ifsr)) {
2504+ if (current->signal->curr_ip)
2505+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n",
2506+ &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid(),
2507+ addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
2508+ else
2509+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n",
2510+ current->comm, task_pid_nr(current), current_uid(), current_euid(),
2511+ addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
2512+ goto die;
2513+ }
2514+#endif
2515+
2516+#ifdef CONFIG_PAX_REFCOUNT
2517+ if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
2518+ unsigned int bkpt;
2519+
2520+ if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
2521+ current->thread.error_code = ifsr;
2522+ current->thread.trap_no = 0;
2523+ pax_report_refcount_overflow(regs);
2524+ fixup_exception(regs);
2525+ return;
2526+ }
2527+ }
2528+#endif
2529+
2530 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
2531 return;
2532
2533 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
2534 inf->name, ifsr, addr);
2535
2536+die:
2537 info.si_signo = inf->sig;
2538 info.si_errno = 0;
2539 info.si_code = inf->code;
2540diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
2541index cf08bdf..f1a0383 100644
2542--- a/arch/arm/mm/fault.h
2543+++ b/arch/arm/mm/fault.h
2544@@ -3,6 +3,7 @@
2545
2546 /*
2547 * Fault status register encodings. We steal bit 31 for our own purposes.
2548+ * Set when the FSR value is from an instruction fault.
2549 */
2550 #define FSR_LNX_PF (1 << 31)
2551 #define FSR_WRITE (1 << 11)
2552@@ -22,6 +23,12 @@ static inline int fsr_fs(unsigned int fsr)
2553 }
2554 #endif
2555
2556+/* valid for LPAE and !LPAE */
2557+static inline int is_xn_fault(unsigned int fsr)
2558+{
2559+ return ((fsr_fs(fsr) & 0x3c) == 0xc);
2560+}
2561+
2562 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
2563 unsigned long search_exception_table(unsigned long addr);
2564
2565diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
2566index ad722f1..46b670e 100644
2567--- a/arch/arm/mm/init.c
2568+++ b/arch/arm/mm/init.c
2569@@ -734,9 +734,43 @@ void __init mem_init(void)
2570
2571 void free_initmem(void)
2572 {
2573+
2574+#ifdef CONFIG_PAX_KERNEXEC
2575+ unsigned long addr;
2576+ pgd_t *pgd;
2577+ pud_t *pud;
2578+ pmd_t *pmd;
2579+#endif
2580+
2581 #ifdef CONFIG_HAVE_TCM
2582 extern char __tcm_start, __tcm_end;
2583+#endif
2584
2585+#ifdef CONFIG_PAX_KERNEXEC
2586+ /* make pages tables, etc before .text NX */
2587+ for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += PMD_SIZE) {
2588+ pgd = pgd_offset_k(addr);
2589+ pud = pud_offset(pgd, addr);
2590+ pmd = pmd_offset(pud, addr);
2591+ __pmd_update(pmd, PMD_SECT_XN);
2592+ }
2593+ /* make init NX */
2594+ for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += PMD_SIZE) {
2595+ pgd = pgd_offset_k(addr);
2596+ pud = pud_offset(pgd, addr);
2597+ pmd = pmd_offset(pud, addr);
2598+ __pmd_update(pmd, PMD_SECT_XN);
2599+ }
2600+ /* make kernel code/rodata read-only */
2601+ for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += PMD_SIZE) {
2602+ pgd = pgd_offset_k(addr);
2603+ pud = pud_offset(pgd, addr);
2604+ pmd = pmd_offset(pud, addr);
2605+ __pmd_update(pmd, PMD_SECT_AP_RDONLY);
2606+ }
2607+#endif
2608+
2609+#ifdef CONFIG_HAVE_TCM
2610 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
2611 totalram_pages += free_area(__phys_to_pfn(__pa(&__tcm_start)),
2612 __phys_to_pfn(__pa(&__tcm_end)),
2613diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
2614index ce8cb19..061aa14 100644
2615--- a/arch/arm/mm/mmap.c
2616+++ b/arch/arm/mm/mmap.c
2617@@ -72,6 +72,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
2618 unsigned long start_addr;
2619 int do_align = 0;
2620 int aliasing = cache_is_vipt_aliasing();
2621+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
2622
2623 /*
2624 * We only need to do colour alignment if either the I or D
2625@@ -93,6 +94,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
2626 if (len > TASK_SIZE)
2627 return -ENOMEM;
2628
2629+#ifdef CONFIG_PAX_RANDMMAP
2630+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
2631+#endif
2632+
2633 if (addr) {
2634 if (do_align)
2635 addr = COLOUR_ALIGN(addr, pgoff);
2636@@ -100,15 +105,14 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
2637 addr = PAGE_ALIGN(addr);
2638
2639 vma = find_vma(mm, addr);
2640- if (TASK_SIZE - len >= addr &&
2641- (!vma || addr + len <= vma->vm_start))
2642+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
2643 return addr;
2644 }
2645 if (len > mm->cached_hole_size) {
2646- start_addr = addr = mm->free_area_cache;
2647+ start_addr = addr = mm->free_area_cache;
2648 } else {
2649- start_addr = addr = mm->mmap_base;
2650- mm->cached_hole_size = 0;
2651+ start_addr = addr = mm->mmap_base;
2652+ mm->cached_hole_size = 0;
2653 }
2654
2655 full_search:
2656@@ -124,14 +128,14 @@ full_search:
2657 * Start a new search - just in case we missed
2658 * some holes.
2659 */
2660- if (start_addr != TASK_UNMAPPED_BASE) {
2661- start_addr = addr = TASK_UNMAPPED_BASE;
2662+ if (start_addr != mm->mmap_base) {
2663+ start_addr = addr = mm->mmap_base;
2664 mm->cached_hole_size = 0;
2665 goto full_search;
2666 }
2667 return -ENOMEM;
2668 }
2669- if (!vma || addr + len <= vma->vm_start) {
2670+ if (check_heap_stack_gap(vma, addr, len, offset)) {
2671 /*
2672 * Remember the place where we stopped the search:
2673 */
2674@@ -156,6 +160,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
2675 unsigned long addr = addr0;
2676 int do_align = 0;
2677 int aliasing = cache_is_vipt_aliasing();
2678+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
2679
2680 /*
2681 * We only need to do colour alignment if either the I or D
2682@@ -175,6 +180,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
2683 return addr;
2684 }
2685
2686+#ifdef CONFIG_PAX_RANDMMAP
2687+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
2688+#endif
2689+
2690 /* requesting a specific address */
2691 if (addr) {
2692 if (do_align)
2693@@ -182,8 +191,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
2694 else
2695 addr = PAGE_ALIGN(addr);
2696 vma = find_vma(mm, addr);
2697- if (TASK_SIZE - len >= addr &&
2698- (!vma || addr + len <= vma->vm_start))
2699+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
2700 return addr;
2701 }
2702
2703@@ -203,7 +211,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
2704 /* make sure it can fit in the remaining address space */
2705 if (addr > len) {
2706 vma = find_vma(mm, addr-len);
2707- if (!vma || addr <= vma->vm_start)
2708+ if (check_heap_stack_gap(vma, addr - len, len, offset))
2709 /* remember the address as a hint for next time */
2710 return (mm->free_area_cache = addr-len);
2711 }
2712@@ -212,17 +220,17 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
2713 goto bottomup;
2714
2715 addr = mm->mmap_base - len;
2716- if (do_align)
2717- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
2718
2719 do {
2720+ if (do_align)
2721+ addr = COLOUR_ALIGN_DOWN(addr, pgoff);
2722 /*
2723 * Lookup failure means no vma is above this address,
2724 * else if new region fits below vma->vm_start,
2725 * return with success:
2726 */
2727 vma = find_vma(mm, addr);
2728- if (!vma || addr+len <= vma->vm_start)
2729+ if (check_heap_stack_gap(vma, addr, len, offset))
2730 /* remember the address as a hint for next time */
2731 return (mm->free_area_cache = addr);
2732
2733@@ -231,10 +239,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
2734 mm->cached_hole_size = vma->vm_start - addr;
2735
2736 /* try just below the current vma->vm_start */
2737- addr = vma->vm_start - len;
2738- if (do_align)
2739- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
2740- } while (len < vma->vm_start);
2741+ addr = skip_heap_stack_gap(vma, len, offset);
2742+ } while (!IS_ERR_VALUE(addr));
2743
2744 bottomup:
2745 /*
2746@@ -259,6 +265,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
2747 {
2748 unsigned long random_factor = 0UL;
2749
2750+#ifdef CONFIG_PAX_RANDMMAP
2751+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
2752+#endif
2753+
2754 /* 8 bits of randomness in 20 address space bits */
2755 if ((current->flags & PF_RANDOMIZE) &&
2756 !(current->personality & ADDR_NO_RANDOMIZE))
2757@@ -266,10 +276,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
2758
2759 if (mmap_is_legacy()) {
2760 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
2761+
2762+#ifdef CONFIG_PAX_RANDMMAP
2763+ if (mm->pax_flags & MF_PAX_RANDMMAP)
2764+ mm->mmap_base += mm->delta_mmap;
2765+#endif
2766+
2767 mm->get_unmapped_area = arch_get_unmapped_area;
2768 mm->unmap_area = arch_unmap_area;
2769 } else {
2770 mm->mmap_base = mmap_base(random_factor);
2771+
2772+#ifdef CONFIG_PAX_RANDMMAP
2773+ if (mm->pax_flags & MF_PAX_RANDMMAP)
2774+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
2775+#endif
2776+
2777 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
2778 mm->unmap_area = arch_unmap_area_topdown;
2779 }
2780diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
2781index 99b47b9..579b667 100644
2782--- a/arch/arm/mm/mmu.c
2783+++ b/arch/arm/mm/mmu.c
2784@@ -227,16 +227,16 @@ static struct mem_type mem_types[] = {
2785 [MT_UNCACHED] = {
2786 .prot_pte = PROT_PTE_DEVICE,
2787 .prot_l1 = PMD_TYPE_TABLE,
2788- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
2789+ .prot_sect = PROT_SECT_DEVICE | PMD_SECT_XN,
2790 .domain = DOMAIN_IO,
2791 },
2792 [MT_CACHECLEAN] = {
2793- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
2794+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_AP_RDONLY,
2795 .domain = DOMAIN_KERNEL,
2796 },
2797 #ifndef CONFIG_ARM_LPAE
2798 [MT_MINICLEAN] = {
2799- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
2800+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE | PMD_SECT_AP_RDONLY,
2801 .domain = DOMAIN_KERNEL,
2802 },
2803 #endif
2804@@ -258,8 +258,26 @@ static struct mem_type mem_types[] = {
2805 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
2806 .domain = DOMAIN_KERNEL,
2807 },
2808+ [MT_MEMORY_R] = {
2809+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_RDONLY | L_PTE_XN,
2810+ .prot_l1 = PMD_TYPE_TABLE,
2811+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_RDONLY | PMD_SECT_XN,
2812+ .domain = DOMAIN_KERNEL,
2813+ },
2814+ [MT_MEMORY_RW] = {
2815+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY | L_PTE_XN,
2816+ .prot_l1 = PMD_TYPE_TABLE,
2817+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_SECT_XN,
2818+ .domain = DOMAIN_KERNEL,
2819+ },
2820+ [MT_MEMORY_RX] = {
2821+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_RDONLY,
2822+ .prot_l1 = PMD_TYPE_TABLE,
2823+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_RDONLY,
2824+ .domain = DOMAIN_KERNEL,
2825+ },
2826 [MT_ROM] = {
2827- .prot_sect = PMD_TYPE_SECT,
2828+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_RDONLY,
2829 .domain = DOMAIN_KERNEL,
2830 },
2831 [MT_MEMORY_NONCACHED] = {
2832@@ -273,7 +291,7 @@ static struct mem_type mem_types[] = {
2833 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
2834 L_PTE_XN,
2835 .prot_l1 = PMD_TYPE_TABLE,
2836- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
2837+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_AP_RDONLY,
2838 .domain = DOMAIN_KERNEL,
2839 },
2840 [MT_MEMORY_ITCM] = {
2841@@ -432,6 +450,8 @@ static void __init build_mem_type_table(void)
2842 * from SVC mode and no access from userspace.
2843 */
2844 mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
2845+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
2846+ mem_types[MT_MEMORY_R].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
2847 mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
2848 mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
2849 #endif
2850@@ -450,6 +470,12 @@ static void __init build_mem_type_table(void)
2851 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
2852 mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
2853 mem_types[MT_MEMORY].prot_pte |= L_PTE_SHARED;
2854+ mem_types[MT_MEMORY_R].prot_sect |= PMD_SECT_S;
2855+ mem_types[MT_MEMORY_R].prot_pte |= L_PTE_SHARED;
2856+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
2857+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
2858+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
2859+ mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
2860 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
2861 mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_S;
2862 mem_types[MT_MEMORY_NONCACHED].prot_pte |= L_PTE_SHARED;
2863@@ -487,6 +513,8 @@ static void __init build_mem_type_table(void)
2864 vecs_pgprot |= PTE_EXT_AF;
2865 #endif
2866
2867+ user_pgprot |= __supported_pte_mask;
2868+
2869 for (i = 0; i < 16; i++) {
2870 pteval_t v = pgprot_val(protection_map[i]);
2871 protection_map[i] = __pgprot(v | user_pgprot);
2872@@ -503,6 +531,12 @@ static void __init build_mem_type_table(void)
2873 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
2874 mem_types[MT_MEMORY].prot_sect |= ecc_mask | cp->pmd;
2875 mem_types[MT_MEMORY].prot_pte |= kern_pgprot;
2876+ mem_types[MT_MEMORY_R].prot_sect |= ecc_mask | cp->pmd;
2877+ mem_types[MT_MEMORY_R].prot_pte |= kern_pgprot;
2878+ mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
2879+ mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
2880+ mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
2881+ mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
2882 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
2883 mem_types[MT_MEMORY_NONCACHED].prot_sect |= ecc_mask;
2884 mem_types[MT_ROM].prot_sect |= cp->pmd;
2885@@ -1198,7 +1232,41 @@ static void __init map_lowmem(void)
2886 map.pfn = __phys_to_pfn(start);
2887 map.virtual = __phys_to_virt(start);
2888 map.length = end - start;
2889+
2890+#ifdef CONFIG_PAX_KERNEXEC
2891+ if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
2892+ struct map_desc kernel;
2893+ struct map_desc initmap;
2894+
2895+ /* when freeing initmem we will make this RW */
2896+ initmap.pfn = __phys_to_pfn(__pa(__init_begin));
2897+ initmap.virtual = (unsigned long)__init_begin;
2898+ initmap.length = _sdata - __init_begin;
2899+ initmap.type = MT_MEMORY;
2900+ create_mapping(&initmap);
2901+
2902+ /* when freeing initmem we will make this RX */
2903+ kernel.pfn = __phys_to_pfn(__pa(_stext));
2904+ kernel.virtual = (unsigned long)_stext;
2905+ kernel.length = __init_begin - _stext;
2906+ kernel.type = MT_MEMORY;
2907+ create_mapping(&kernel);
2908+
2909+ if (map.virtual < (unsigned long)_stext) {
2910+ map.length = (unsigned long)_stext - map.virtual;
2911+ map.type = MT_MEMORY;
2912+ create_mapping(&map);
2913+ }
2914+
2915+ map.pfn = __phys_to_pfn(__pa(_sdata));
2916+ map.virtual = (unsigned long)_sdata;
2917+ map.length = end - __pa(_sdata);
2918+ }
2919+
2920+ map.type = MT_MEMORY_RW;
2921+#else
2922 map.type = MT_MEMORY;
2923+#endif
2924
2925 create_mapping(&map);
2926 }
2927diff --git a/arch/arm/plat-orion/include/plat/addr-map.h b/arch/arm/plat-orion/include/plat/addr-map.h
2928index ec63e4a..62aa5f1d 100644
2929--- a/arch/arm/plat-orion/include/plat/addr-map.h
2930+++ b/arch/arm/plat-orion/include/plat/addr-map.h
2931@@ -26,7 +26,7 @@ struct orion_addr_map_cfg {
2932 value in bridge_virt_base */
2933 void __iomem *(*win_cfg_base) (const struct orion_addr_map_cfg *cfg,
2934 const int win);
2935-};
2936+} __no_const;
2937
2938 /*
2939 * Information needed to setup one address mapping.
2940diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
2941index f5144cd..71f6d1f 100644
2942--- a/arch/arm/plat-samsung/include/plat/dma-ops.h
2943+++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
2944@@ -47,7 +47,7 @@ struct samsung_dma_ops {
2945 int (*started)(unsigned ch);
2946 int (*flush)(unsigned ch);
2947 int (*stop)(unsigned ch);
2948-};
2949+} __no_const;
2950
2951 extern void *samsung_dmadev_get_ops(void);
2952 extern void *s3c_dma_get_ops(void);
2953diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
2954index c3a58a1..78fbf54 100644
2955--- a/arch/avr32/include/asm/cache.h
2956+++ b/arch/avr32/include/asm/cache.h
2957@@ -1,8 +1,10 @@
2958 #ifndef __ASM_AVR32_CACHE_H
2959 #define __ASM_AVR32_CACHE_H
2960
2961+#include <linux/const.h>
2962+
2963 #define L1_CACHE_SHIFT 5
2964-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2965+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2966
2967 /*
2968 * Memory returned by kmalloc() may be used for DMA, so we must make
2969diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
2970index e2c3287..6c4f98c 100644
2971--- a/arch/avr32/include/asm/elf.h
2972+++ b/arch/avr32/include/asm/elf.h
2973@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
2974 the loader. We need to make sure that it is out of the way of the program
2975 that it will "exec", and that there is sufficient room for the brk. */
2976
2977-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
2978+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2979
2980+#ifdef CONFIG_PAX_ASLR
2981+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
2982+
2983+#define PAX_DELTA_MMAP_LEN 15
2984+#define PAX_DELTA_STACK_LEN 15
2985+#endif
2986
2987 /* This yields a mask that user programs can use to figure out what
2988 instruction set this CPU supports. This could be done in user space,
2989diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
2990index 479330b..53717a8 100644
2991--- a/arch/avr32/include/asm/kmap_types.h
2992+++ b/arch/avr32/include/asm/kmap_types.h
2993@@ -2,9 +2,9 @@
2994 #define __ASM_AVR32_KMAP_TYPES_H
2995
2996 #ifdef CONFIG_DEBUG_HIGHMEM
2997-# define KM_TYPE_NR 29
2998+# define KM_TYPE_NR 30
2999 #else
3000-# define KM_TYPE_NR 14
3001+# define KM_TYPE_NR 15
3002 #endif
3003
3004 #endif /* __ASM_AVR32_KMAP_TYPES_H */
3005diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
3006index b2f2d2d..d1c85cb 100644
3007--- a/arch/avr32/mm/fault.c
3008+++ b/arch/avr32/mm/fault.c
3009@@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
3010
3011 int exception_trace = 1;
3012
3013+#ifdef CONFIG_PAX_PAGEEXEC
3014+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3015+{
3016+ unsigned long i;
3017+
3018+ printk(KERN_ERR "PAX: bytes at PC: ");
3019+ for (i = 0; i < 20; i++) {
3020+ unsigned char c;
3021+ if (get_user(c, (unsigned char *)pc+i))
3022+ printk(KERN_CONT "???????? ");
3023+ else
3024+ printk(KERN_CONT "%02x ", c);
3025+ }
3026+ printk("\n");
3027+}
3028+#endif
3029+
3030 /*
3031 * This routine handles page faults. It determines the address and the
3032 * problem, and then passes it off to one of the appropriate routines.
3033@@ -174,6 +191,16 @@ bad_area:
3034 up_read(&mm->mmap_sem);
3035
3036 if (user_mode(regs)) {
3037+
3038+#ifdef CONFIG_PAX_PAGEEXEC
3039+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
3040+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
3041+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
3042+ do_group_exit(SIGKILL);
3043+ }
3044+ }
3045+#endif
3046+
3047 if (exception_trace && printk_ratelimit())
3048 printk("%s%s[%d]: segfault at %08lx pc %08lx "
3049 "sp %08lx ecr %lu\n",
3050diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
3051index 568885a..f8008df 100644
3052--- a/arch/blackfin/include/asm/cache.h
3053+++ b/arch/blackfin/include/asm/cache.h
3054@@ -7,6 +7,7 @@
3055 #ifndef __ARCH_BLACKFIN_CACHE_H
3056 #define __ARCH_BLACKFIN_CACHE_H
3057
3058+#include <linux/const.h>
3059 #include <linux/linkage.h> /* for asmlinkage */
3060
3061 /*
3062@@ -14,7 +15,7 @@
3063 * Blackfin loads 32 bytes for cache
3064 */
3065 #define L1_CACHE_SHIFT 5
3066-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3067+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3068 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3069
3070 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
3071diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
3072index aea2718..3639a60 100644
3073--- a/arch/cris/include/arch-v10/arch/cache.h
3074+++ b/arch/cris/include/arch-v10/arch/cache.h
3075@@ -1,8 +1,9 @@
3076 #ifndef _ASM_ARCH_CACHE_H
3077 #define _ASM_ARCH_CACHE_H
3078
3079+#include <linux/const.h>
3080 /* Etrax 100LX have 32-byte cache-lines. */
3081-#define L1_CACHE_BYTES 32
3082 #define L1_CACHE_SHIFT 5
3083+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3084
3085 #endif /* _ASM_ARCH_CACHE_H */
3086diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
3087index 7caf25d..ee65ac5 100644
3088--- a/arch/cris/include/arch-v32/arch/cache.h
3089+++ b/arch/cris/include/arch-v32/arch/cache.h
3090@@ -1,11 +1,12 @@
3091 #ifndef _ASM_CRIS_ARCH_CACHE_H
3092 #define _ASM_CRIS_ARCH_CACHE_H
3093
3094+#include <linux/const.h>
3095 #include <arch/hwregs/dma.h>
3096
3097 /* A cache-line is 32 bytes. */
3098-#define L1_CACHE_BYTES 32
3099 #define L1_CACHE_SHIFT 5
3100+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3101
3102 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
3103
3104diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
3105index b86329d..6709906 100644
3106--- a/arch/frv/include/asm/atomic.h
3107+++ b/arch/frv/include/asm/atomic.h
3108@@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
3109 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
3110 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
3111
3112+#define atomic64_read_unchecked(v) atomic64_read(v)
3113+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3114+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3115+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3116+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3117+#define atomic64_inc_unchecked(v) atomic64_inc(v)
3118+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3119+#define atomic64_dec_unchecked(v) atomic64_dec(v)
3120+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3121+
3122 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
3123 {
3124 int c, old;
3125diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
3126index 2797163..c2a401d 100644
3127--- a/arch/frv/include/asm/cache.h
3128+++ b/arch/frv/include/asm/cache.h
3129@@ -12,10 +12,11 @@
3130 #ifndef __ASM_CACHE_H
3131 #define __ASM_CACHE_H
3132
3133+#include <linux/const.h>
3134
3135 /* bytes per L1 cache line */
3136 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
3137-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3138+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3139
3140 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
3141 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
3142diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
3143index 43901f2..0d8b865 100644
3144--- a/arch/frv/include/asm/kmap_types.h
3145+++ b/arch/frv/include/asm/kmap_types.h
3146@@ -2,6 +2,6 @@
3147 #ifndef _ASM_KMAP_TYPES_H
3148 #define _ASM_KMAP_TYPES_H
3149
3150-#define KM_TYPE_NR 17
3151+#define KM_TYPE_NR 18
3152
3153 #endif
3154diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
3155index 385fd30..3aaf4fe 100644
3156--- a/arch/frv/mm/elf-fdpic.c
3157+++ b/arch/frv/mm/elf-fdpic.c
3158@@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
3159 {
3160 struct vm_area_struct *vma;
3161 unsigned long limit;
3162+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
3163
3164 if (len > TASK_SIZE)
3165 return -ENOMEM;
3166@@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
3167 if (addr) {
3168 addr = PAGE_ALIGN(addr);
3169 vma = find_vma(current->mm, addr);
3170- if (TASK_SIZE - len >= addr &&
3171- (!vma || addr + len <= vma->vm_start))
3172+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
3173 goto success;
3174 }
3175
3176@@ -89,7 +89,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
3177 for (; vma; vma = vma->vm_next) {
3178 if (addr > limit)
3179 break;
3180- if (addr + len <= vma->vm_start)
3181+ if (check_heap_stack_gap(vma, addr, len, offset))
3182 goto success;
3183 addr = vma->vm_end;
3184 }
3185@@ -104,7 +104,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
3186 for (; vma; vma = vma->vm_next) {
3187 if (addr > limit)
3188 break;
3189- if (addr + len <= vma->vm_start)
3190+ if (check_heap_stack_gap(vma, addr, len, offset))
3191 goto success;
3192 addr = vma->vm_end;
3193 }
3194diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
3195index f4ca594..adc72fd6 100644
3196--- a/arch/hexagon/include/asm/cache.h
3197+++ b/arch/hexagon/include/asm/cache.h
3198@@ -21,9 +21,11 @@
3199 #ifndef __ASM_CACHE_H
3200 #define __ASM_CACHE_H
3201
3202+#include <linux/const.h>
3203+
3204 /* Bytes per L1 cache line */
3205-#define L1_CACHE_SHIFT (5)
3206-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3207+#define L1_CACHE_SHIFT 5
3208+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3209
3210 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
3211 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
3212diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
3213index 6e6fe18..a6ae668 100644
3214--- a/arch/ia64/include/asm/atomic.h
3215+++ b/arch/ia64/include/asm/atomic.h
3216@@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
3217 #define atomic64_inc(v) atomic64_add(1, (v))
3218 #define atomic64_dec(v) atomic64_sub(1, (v))
3219
3220+#define atomic64_read_unchecked(v) atomic64_read(v)
3221+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3222+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3223+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3224+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3225+#define atomic64_inc_unchecked(v) atomic64_inc(v)
3226+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3227+#define atomic64_dec_unchecked(v) atomic64_dec(v)
3228+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3229+
3230 /* Atomic operations are already serializing */
3231 #define smp_mb__before_atomic_dec() barrier()
3232 #define smp_mb__after_atomic_dec() barrier()
3233diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
3234index 988254a..e1ee885 100644
3235--- a/arch/ia64/include/asm/cache.h
3236+++ b/arch/ia64/include/asm/cache.h
3237@@ -1,6 +1,7 @@
3238 #ifndef _ASM_IA64_CACHE_H
3239 #define _ASM_IA64_CACHE_H
3240
3241+#include <linux/const.h>
3242
3243 /*
3244 * Copyright (C) 1998-2000 Hewlett-Packard Co
3245@@ -9,7 +10,7 @@
3246
3247 /* Bytes per L1 (data) cache line. */
3248 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
3249-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3250+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3251
3252 #ifdef CONFIG_SMP
3253 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
3254diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
3255index b5298eb..67c6e62 100644
3256--- a/arch/ia64/include/asm/elf.h
3257+++ b/arch/ia64/include/asm/elf.h
3258@@ -42,6 +42,13 @@
3259 */
3260 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
3261
3262+#ifdef CONFIG_PAX_ASLR
3263+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
3264+
3265+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
3266+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
3267+#endif
3268+
3269 #define PT_IA_64_UNWIND 0x70000001
3270
3271 /* IA-64 relocations: */
3272diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
3273index 96a8d92..617a1cf 100644
3274--- a/arch/ia64/include/asm/pgalloc.h
3275+++ b/arch/ia64/include/asm/pgalloc.h
3276@@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
3277 pgd_val(*pgd_entry) = __pa(pud);
3278 }
3279
3280+static inline void
3281+pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
3282+{
3283+ pgd_populate(mm, pgd_entry, pud);
3284+}
3285+
3286 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
3287 {
3288 return quicklist_alloc(0, GFP_KERNEL, NULL);
3289@@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
3290 pud_val(*pud_entry) = __pa(pmd);
3291 }
3292
3293+static inline void
3294+pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
3295+{
3296+ pud_populate(mm, pud_entry, pmd);
3297+}
3298+
3299 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
3300 {
3301 return quicklist_alloc(0, GFP_KERNEL, NULL);
3302diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
3303index 815810c..d60bd4c 100644
3304--- a/arch/ia64/include/asm/pgtable.h
3305+++ b/arch/ia64/include/asm/pgtable.h
3306@@ -12,7 +12,7 @@
3307 * David Mosberger-Tang <davidm@hpl.hp.com>
3308 */
3309
3310-
3311+#include <linux/const.h>
3312 #include <asm/mman.h>
3313 #include <asm/page.h>
3314 #include <asm/processor.h>
3315@@ -142,6 +142,17 @@
3316 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
3317 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
3318 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
3319+
3320+#ifdef CONFIG_PAX_PAGEEXEC
3321+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
3322+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
3323+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
3324+#else
3325+# define PAGE_SHARED_NOEXEC PAGE_SHARED
3326+# define PAGE_READONLY_NOEXEC PAGE_READONLY
3327+# define PAGE_COPY_NOEXEC PAGE_COPY
3328+#endif
3329+
3330 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
3331 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
3332 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
3333diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
3334index 54ff557..70c88b7 100644
3335--- a/arch/ia64/include/asm/spinlock.h
3336+++ b/arch/ia64/include/asm/spinlock.h
3337@@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
3338 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
3339
3340 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
3341- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
3342+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
3343 }
3344
3345 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
3346diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
3347index 449c8c0..50cdf87 100644
3348--- a/arch/ia64/include/asm/uaccess.h
3349+++ b/arch/ia64/include/asm/uaccess.h
3350@@ -42,6 +42,8 @@
3351 #include <asm/pgtable.h>
3352 #include <asm/io.h>
3353
3354+extern void check_object_size(const void *ptr, unsigned long n, bool to);
3355+
3356 /*
3357 * For historical reasons, the following macros are grossly misnamed:
3358 */
3359@@ -240,12 +242,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
3360 static inline unsigned long
3361 __copy_to_user (void __user *to, const void *from, unsigned long count)
3362 {
3363+ if (count > INT_MAX)
3364+ return count;
3365+
3366+ if (!__builtin_constant_p(count))
3367+ check_object_size(from, count, true);
3368+
3369 return __copy_user(to, (__force void __user *) from, count);
3370 }
3371
3372 static inline unsigned long
3373 __copy_from_user (void *to, const void __user *from, unsigned long count)
3374 {
3375+ if (count > INT_MAX)
3376+ return count;
3377+
3378+ if (!__builtin_constant_p(count))
3379+ check_object_size(to, count, false);
3380+
3381 return __copy_user((__force void __user *) to, from, count);
3382 }
3383
3384@@ -255,10 +269,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
3385 ({ \
3386 void __user *__cu_to = (to); \
3387 const void *__cu_from = (from); \
3388- long __cu_len = (n); \
3389+ unsigned long __cu_len = (n); \
3390 \
3391- if (__access_ok(__cu_to, __cu_len, get_fs())) \
3392+ if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
3393+ if (!__builtin_constant_p(n)) \
3394+ check_object_size(__cu_from, __cu_len, true); \
3395 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
3396+ } \
3397 __cu_len; \
3398 })
3399
3400@@ -266,11 +283,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
3401 ({ \
3402 void *__cu_to = (to); \
3403 const void __user *__cu_from = (from); \
3404- long __cu_len = (n); \
3405+ unsigned long __cu_len = (n); \
3406 \
3407 __chk_user_ptr(__cu_from); \
3408- if (__access_ok(__cu_from, __cu_len, get_fs())) \
3409+ if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
3410+ if (!__builtin_constant_p(n)) \
3411+ check_object_size(__cu_to, __cu_len, false); \
3412 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
3413+ } \
3414 __cu_len; \
3415 })
3416
3417diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
3418index 24603be..948052d 100644
3419--- a/arch/ia64/kernel/module.c
3420+++ b/arch/ia64/kernel/module.c
3421@@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
3422 void
3423 module_free (struct module *mod, void *module_region)
3424 {
3425- if (mod && mod->arch.init_unw_table &&
3426- module_region == mod->module_init) {
3427+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
3428 unw_remove_unwind_table(mod->arch.init_unw_table);
3429 mod->arch.init_unw_table = NULL;
3430 }
3431@@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
3432 }
3433
3434 static inline int
3435+in_init_rx (const struct module *mod, uint64_t addr)
3436+{
3437+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
3438+}
3439+
3440+static inline int
3441+in_init_rw (const struct module *mod, uint64_t addr)
3442+{
3443+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
3444+}
3445+
3446+static inline int
3447 in_init (const struct module *mod, uint64_t addr)
3448 {
3449- return addr - (uint64_t) mod->module_init < mod->init_size;
3450+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
3451+}
3452+
3453+static inline int
3454+in_core_rx (const struct module *mod, uint64_t addr)
3455+{
3456+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
3457+}
3458+
3459+static inline int
3460+in_core_rw (const struct module *mod, uint64_t addr)
3461+{
3462+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
3463 }
3464
3465 static inline int
3466 in_core (const struct module *mod, uint64_t addr)
3467 {
3468- return addr - (uint64_t) mod->module_core < mod->core_size;
3469+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
3470 }
3471
3472 static inline int
3473@@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
3474 break;
3475
3476 case RV_BDREL:
3477- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
3478+ if (in_init_rx(mod, val))
3479+ val -= (uint64_t) mod->module_init_rx;
3480+ else if (in_init_rw(mod, val))
3481+ val -= (uint64_t) mod->module_init_rw;
3482+ else if (in_core_rx(mod, val))
3483+ val -= (uint64_t) mod->module_core_rx;
3484+ else if (in_core_rw(mod, val))
3485+ val -= (uint64_t) mod->module_core_rw;
3486 break;
3487
3488 case RV_LTV:
3489@@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
3490 * addresses have been selected...
3491 */
3492 uint64_t gp;
3493- if (mod->core_size > MAX_LTOFF)
3494+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
3495 /*
3496 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
3497 * at the end of the module.
3498 */
3499- gp = mod->core_size - MAX_LTOFF / 2;
3500+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
3501 else
3502- gp = mod->core_size / 2;
3503- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
3504+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
3505+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
3506 mod->arch.gp = gp;
3507 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
3508 }
3509diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
3510index d9439ef..d0cac6b 100644
3511--- a/arch/ia64/kernel/sys_ia64.c
3512+++ b/arch/ia64/kernel/sys_ia64.c
3513@@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
3514 unsigned long start_addr, align_mask = PAGE_SIZE - 1;
3515 struct mm_struct *mm = current->mm;
3516 struct vm_area_struct *vma;
3517+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
3518
3519 if (len > RGN_MAP_LIMIT)
3520 return -ENOMEM;
3521@@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
3522 if (REGION_NUMBER(addr) == RGN_HPAGE)
3523 addr = 0;
3524 #endif
3525+
3526+#ifdef CONFIG_PAX_RANDMMAP
3527+ if (mm->pax_flags & MF_PAX_RANDMMAP)
3528+ addr = mm->free_area_cache;
3529+ else
3530+#endif
3531+
3532 if (!addr)
3533 addr = mm->free_area_cache;
3534
3535@@ -61,14 +69,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
3536 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
3537 /* At this point: (!vma || addr < vma->vm_end). */
3538 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
3539- if (start_addr != TASK_UNMAPPED_BASE) {
3540+ if (start_addr != mm->mmap_base) {
3541 /* Start a new search --- just in case we missed some holes. */
3542- addr = TASK_UNMAPPED_BASE;
3543+ addr = mm->mmap_base;
3544 goto full_search;
3545 }
3546 return -ENOMEM;
3547 }
3548- if (!vma || addr + len <= vma->vm_start) {
3549+ if (check_heap_stack_gap(vma, addr, len, offset)) {
3550 /* Remember the address where we stopped this search: */
3551 mm->free_area_cache = addr + len;
3552 return addr;
3553diff --git a/arch/ia64/kernel/topology.c b/arch/ia64/kernel/topology.c
3554index c64460b..4d250a6 100644
3555--- a/arch/ia64/kernel/topology.c
3556+++ b/arch/ia64/kernel/topology.c
3557@@ -445,7 +445,7 @@ static int __cpuinit cache_cpu_callback(struct notifier_block *nfb,
3558 return NOTIFY_OK;
3559 }
3560
3561-static struct notifier_block __cpuinitdata cache_cpu_notifier =
3562+static struct notifier_block cache_cpu_notifier =
3563 {
3564 .notifier_call = cache_cpu_callback
3565 };
3566diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
3567index 0ccb28f..8992469 100644
3568--- a/arch/ia64/kernel/vmlinux.lds.S
3569+++ b/arch/ia64/kernel/vmlinux.lds.S
3570@@ -198,7 +198,7 @@ SECTIONS {
3571 /* Per-cpu data: */
3572 . = ALIGN(PERCPU_PAGE_SIZE);
3573 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
3574- __phys_per_cpu_start = __per_cpu_load;
3575+ __phys_per_cpu_start = per_cpu_load;
3576 /*
3577 * ensure percpu data fits
3578 * into percpu page size
3579diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
3580index 6cf0341..d352594 100644
3581--- a/arch/ia64/mm/fault.c
3582+++ b/arch/ia64/mm/fault.c
3583@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
3584 return pte_present(pte);
3585 }
3586
3587+#ifdef CONFIG_PAX_PAGEEXEC
3588+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3589+{
3590+ unsigned long i;
3591+
3592+ printk(KERN_ERR "PAX: bytes at PC: ");
3593+ for (i = 0; i < 8; i++) {
3594+ unsigned int c;
3595+ if (get_user(c, (unsigned int *)pc+i))
3596+ printk(KERN_CONT "???????? ");
3597+ else
3598+ printk(KERN_CONT "%08x ", c);
3599+ }
3600+ printk("\n");
3601+}
3602+#endif
3603+
3604 # define VM_READ_BIT 0
3605 # define VM_WRITE_BIT 1
3606 # define VM_EXEC_BIT 2
3607@@ -149,8 +166,21 @@ retry:
3608 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
3609 goto bad_area;
3610
3611- if ((vma->vm_flags & mask) != mask)
3612+ if ((vma->vm_flags & mask) != mask) {
3613+
3614+#ifdef CONFIG_PAX_PAGEEXEC
3615+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
3616+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
3617+ goto bad_area;
3618+
3619+ up_read(&mm->mmap_sem);
3620+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
3621+ do_group_exit(SIGKILL);
3622+ }
3623+#endif
3624+
3625 goto bad_area;
3626+ }
3627
3628 /*
3629 * If for any reason at all we couldn't handle the fault, make
3630diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
3631index 5ca674b..127c3cb 100644
3632--- a/arch/ia64/mm/hugetlbpage.c
3633+++ b/arch/ia64/mm/hugetlbpage.c
3634@@ -149,6 +149,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
3635 unsigned long pgoff, unsigned long flags)
3636 {
3637 struct vm_area_struct *vmm;
3638+ unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
3639
3640 if (len > RGN_MAP_LIMIT)
3641 return -ENOMEM;
3642@@ -171,7 +172,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
3643 /* At this point: (!vmm || addr < vmm->vm_end). */
3644 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
3645 return -ENOMEM;
3646- if (!vmm || (addr + len) <= vmm->vm_start)
3647+ if (check_heap_stack_gap(vmm, addr, len, offset))
3648 return addr;
3649 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
3650 }
3651diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
3652index 082e383..fb7be80 100644
3653--- a/arch/ia64/mm/init.c
3654+++ b/arch/ia64/mm/init.c
3655@@ -120,6 +120,19 @@ ia64_init_addr_space (void)
3656 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
3657 vma->vm_end = vma->vm_start + PAGE_SIZE;
3658 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
3659+
3660+#ifdef CONFIG_PAX_PAGEEXEC
3661+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
3662+ vma->vm_flags &= ~VM_EXEC;
3663+
3664+#ifdef CONFIG_PAX_MPROTECT
3665+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
3666+ vma->vm_flags &= ~VM_MAYEXEC;
3667+#endif
3668+
3669+ }
3670+#endif
3671+
3672 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
3673 down_write(&current->mm->mmap_sem);
3674 if (insert_vm_struct(current->mm, vma)) {
3675diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
3676index 40b3ee9..8c2c112 100644
3677--- a/arch/m32r/include/asm/cache.h
3678+++ b/arch/m32r/include/asm/cache.h
3679@@ -1,8 +1,10 @@
3680 #ifndef _ASM_M32R_CACHE_H
3681 #define _ASM_M32R_CACHE_H
3682
3683+#include <linux/const.h>
3684+
3685 /* L1 cache line size */
3686 #define L1_CACHE_SHIFT 4
3687-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3688+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3689
3690 #endif /* _ASM_M32R_CACHE_H */
3691diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
3692index 82abd15..d95ae5d 100644
3693--- a/arch/m32r/lib/usercopy.c
3694+++ b/arch/m32r/lib/usercopy.c
3695@@ -14,6 +14,9 @@
3696 unsigned long
3697 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
3698 {
3699+ if ((long)n < 0)
3700+ return n;
3701+
3702 prefetch(from);
3703 if (access_ok(VERIFY_WRITE, to, n))
3704 __copy_user(to,from,n);
3705@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
3706 unsigned long
3707 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
3708 {
3709+ if ((long)n < 0)
3710+ return n;
3711+
3712 prefetchw(to);
3713 if (access_ok(VERIFY_READ, from, n))
3714 __copy_user_zeroing(to,from,n);
3715diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
3716index 0395c51..5f26031 100644
3717--- a/arch/m68k/include/asm/cache.h
3718+++ b/arch/m68k/include/asm/cache.h
3719@@ -4,9 +4,11 @@
3720 #ifndef __ARCH_M68K_CACHE_H
3721 #define __ARCH_M68K_CACHE_H
3722
3723+#include <linux/const.h>
3724+
3725 /* bytes per L1 cache line */
3726 #define L1_CACHE_SHIFT 4
3727-#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
3728+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3729
3730 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
3731
3732diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
3733index 4efe96a..60e8699 100644
3734--- a/arch/microblaze/include/asm/cache.h
3735+++ b/arch/microblaze/include/asm/cache.h
3736@@ -13,11 +13,12 @@
3737 #ifndef _ASM_MICROBLAZE_CACHE_H
3738 #define _ASM_MICROBLAZE_CACHE_H
3739
3740+#include <linux/const.h>
3741 #include <asm/registers.h>
3742
3743 #define L1_CACHE_SHIFT 5
3744 /* word-granular cache in microblaze */
3745-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3746+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3747
3748 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3749
3750diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
3751index 01cc6ba..bcb7a5d 100644
3752--- a/arch/mips/include/asm/atomic.h
3753+++ b/arch/mips/include/asm/atomic.h
3754@@ -21,6 +21,10 @@
3755 #include <asm/cmpxchg.h>
3756 #include <asm/war.h>
3757
3758+#ifdef CONFIG_GENERIC_ATOMIC64
3759+#include <asm-generic/atomic64.h>
3760+#endif
3761+
3762 #define ATOMIC_INIT(i) { (i) }
3763
3764 /*
3765@@ -759,6 +763,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
3766 */
3767 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
3768
3769+#define atomic64_read_unchecked(v) atomic64_read(v)
3770+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3771+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3772+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3773+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3774+#define atomic64_inc_unchecked(v) atomic64_inc(v)
3775+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3776+#define atomic64_dec_unchecked(v) atomic64_dec(v)
3777+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3778+
3779 #endif /* CONFIG_64BIT */
3780
3781 /*
3782diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
3783index b4db69f..8f3b093 100644
3784--- a/arch/mips/include/asm/cache.h
3785+++ b/arch/mips/include/asm/cache.h
3786@@ -9,10 +9,11 @@
3787 #ifndef _ASM_CACHE_H
3788 #define _ASM_CACHE_H
3789
3790+#include <linux/const.h>
3791 #include <kmalloc.h>
3792
3793 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
3794-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3795+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3796
3797 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
3798 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3799diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
3800index 455c0ac..ad65fbe 100644
3801--- a/arch/mips/include/asm/elf.h
3802+++ b/arch/mips/include/asm/elf.h
3803@@ -372,13 +372,16 @@ extern const char *__elf_platform;
3804 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
3805 #endif
3806
3807+#ifdef CONFIG_PAX_ASLR
3808+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
3809+
3810+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3811+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3812+#endif
3813+
3814 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
3815 struct linux_binprm;
3816 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
3817 int uses_interp);
3818
3819-struct mm_struct;
3820-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
3821-#define arch_randomize_brk arch_randomize_brk
3822-
3823 #endif /* _ASM_ELF_H */
3824diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
3825index c1f6afa..38cc6e9 100644
3826--- a/arch/mips/include/asm/exec.h
3827+++ b/arch/mips/include/asm/exec.h
3828@@ -12,6 +12,6 @@
3829 #ifndef _ASM_EXEC_H
3830 #define _ASM_EXEC_H
3831
3832-extern unsigned long arch_align_stack(unsigned long sp);
3833+#define arch_align_stack(x) ((x) & ~0xfUL)
3834
3835 #endif /* _ASM_EXEC_H */
3836diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
3837index da9bd7d..91aa7ab 100644
3838--- a/arch/mips/include/asm/page.h
3839+++ b/arch/mips/include/asm/page.h
3840@@ -98,7 +98,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
3841 #ifdef CONFIG_CPU_MIPS32
3842 typedef struct { unsigned long pte_low, pte_high; } pte_t;
3843 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
3844- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
3845+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
3846 #else
3847 typedef struct { unsigned long long pte; } pte_t;
3848 #define pte_val(x) ((x).pte)
3849diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
3850index 881d18b..cea38bc 100644
3851--- a/arch/mips/include/asm/pgalloc.h
3852+++ b/arch/mips/include/asm/pgalloc.h
3853@@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3854 {
3855 set_pud(pud, __pud((unsigned long)pmd));
3856 }
3857+
3858+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3859+{
3860+ pud_populate(mm, pud, pmd);
3861+}
3862 #endif
3863
3864 /*
3865diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
3866index 18806a5..141ffcf 100644
3867--- a/arch/mips/include/asm/thread_info.h
3868+++ b/arch/mips/include/asm/thread_info.h
3869@@ -110,6 +110,8 @@ register struct thread_info *__current_thread_info __asm__("$28");
3870 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
3871 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
3872 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
3873+/* li takes a 32bit immediate */
3874+#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
3875 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
3876
3877 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
3878@@ -125,15 +127,18 @@ register struct thread_info *__current_thread_info __asm__("$28");
3879 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
3880 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
3881 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
3882+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
3883+
3884+#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
3885
3886 /* work to do in syscall_trace_leave() */
3887-#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
3888+#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
3889
3890 /* work to do on interrupt/exception return */
3891 #define _TIF_WORK_MASK \
3892 (_TIF_SIGPENDING | _TIF_NEED_RESCHED | _TIF_NOTIFY_RESUME)
3893 /* work to do on any return to u-space */
3894-#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT)
3895+#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT | _TIF_GRSEC_SETXID)
3896
3897 #endif /* __KERNEL__ */
3898
3899diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
3900index 9fdd8bc..4bd7f1a 100644
3901--- a/arch/mips/kernel/binfmt_elfn32.c
3902+++ b/arch/mips/kernel/binfmt_elfn32.c
3903@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
3904 #undef ELF_ET_DYN_BASE
3905 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
3906
3907+#ifdef CONFIG_PAX_ASLR
3908+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
3909+
3910+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3911+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3912+#endif
3913+
3914 #include <asm/processor.h>
3915 #include <linux/module.h>
3916 #include <linux/elfcore.h>
3917diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
3918index ff44823..97f8906 100644
3919--- a/arch/mips/kernel/binfmt_elfo32.c
3920+++ b/arch/mips/kernel/binfmt_elfo32.c
3921@@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
3922 #undef ELF_ET_DYN_BASE
3923 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
3924
3925+#ifdef CONFIG_PAX_ASLR
3926+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
3927+
3928+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3929+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3930+#endif
3931+
3932 #include <asm/processor.h>
3933
3934 /*
3935diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
3936index 69b17a9..9db82f9 100644
3937--- a/arch/mips/kernel/process.c
3938+++ b/arch/mips/kernel/process.c
3939@@ -478,15 +478,3 @@ unsigned long get_wchan(struct task_struct *task)
3940 out:
3941 return pc;
3942 }
3943-
3944-/*
3945- * Don't forget that the stack pointer must be aligned on a 8 bytes
3946- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
3947- */
3948-unsigned long arch_align_stack(unsigned long sp)
3949-{
3950- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
3951- sp -= get_random_int() & ~PAGE_MASK;
3952-
3953- return sp & ALMASK;
3954-}
3955diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
3956index 4812c6d..2069554 100644
3957--- a/arch/mips/kernel/ptrace.c
3958+++ b/arch/mips/kernel/ptrace.c
3959@@ -528,6 +528,10 @@ static inline int audit_arch(void)
3960 return arch;
3961 }
3962
3963+#ifdef CONFIG_GRKERNSEC_SETXID
3964+extern void gr_delayed_cred_worker(void);
3965+#endif
3966+
3967 /*
3968 * Notification of system call entry/exit
3969 * - triggered by current->work.syscall_trace
3970@@ -537,6 +541,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
3971 /* do the secure computing check first */
3972 secure_computing_strict(regs->regs[2]);
3973
3974+#ifdef CONFIG_GRKERNSEC_SETXID
3975+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
3976+ gr_delayed_cred_worker();
3977+#endif
3978+
3979 if (!(current->ptrace & PT_PTRACED))
3980 goto out;
3981
3982diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
3983index 374f66e..1c882a0 100644
3984--- a/arch/mips/kernel/scall32-o32.S
3985+++ b/arch/mips/kernel/scall32-o32.S
3986@@ -52,7 +52,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3987
3988 stack_done:
3989 lw t0, TI_FLAGS($28) # syscall tracing enabled?
3990- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3991+ li t1, _TIF_SYSCALL_WORK
3992 and t0, t1
3993 bnez t0, syscall_trace_entry # -> yes
3994
3995diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
3996index 169de6a..f594a89 100644
3997--- a/arch/mips/kernel/scall64-64.S
3998+++ b/arch/mips/kernel/scall64-64.S
3999@@ -54,7 +54,7 @@ NESTED(handle_sys64, PT_SIZE, sp)
4000
4001 sd a3, PT_R26(sp) # save a3 for syscall restarting
4002
4003- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
4004+ li t1, _TIF_SYSCALL_WORK
4005 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
4006 and t0, t1, t0
4007 bnez t0, syscall_trace_entry
4008diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
4009index 86ec03f..1235baf 100644
4010--- a/arch/mips/kernel/scall64-n32.S
4011+++ b/arch/mips/kernel/scall64-n32.S
4012@@ -53,7 +53,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
4013
4014 sd a3, PT_R26(sp) # save a3 for syscall restarting
4015
4016- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
4017+ li t1, _TIF_SYSCALL_WORK
4018 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
4019 and t0, t1, t0
4020 bnez t0, n32_syscall_trace_entry
4021diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
4022index 53c2d72..3734584 100644
4023--- a/arch/mips/kernel/scall64-o32.S
4024+++ b/arch/mips/kernel/scall64-o32.S
4025@@ -81,7 +81,7 @@ NESTED(handle_sys, PT_SIZE, sp)
4026 PTR 4b, bad_stack
4027 .previous
4028
4029- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
4030+ li t1, _TIF_SYSCALL_WORK
4031 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
4032 and t0, t1, t0
4033 bnez t0, trace_a_syscall
4034diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
4035index ddcec1e..c7f983e 100644
4036--- a/arch/mips/mm/fault.c
4037+++ b/arch/mips/mm/fault.c
4038@@ -27,6 +27,23 @@
4039 #include <asm/highmem.h> /* For VMALLOC_END */
4040 #include <linux/kdebug.h>
4041
4042+#ifdef CONFIG_PAX_PAGEEXEC
4043+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4044+{
4045+ unsigned long i;
4046+
4047+ printk(KERN_ERR "PAX: bytes at PC: ");
4048+ for (i = 0; i < 5; i++) {
4049+ unsigned int c;
4050+ if (get_user(c, (unsigned int *)pc+i))
4051+ printk(KERN_CONT "???????? ");
4052+ else
4053+ printk(KERN_CONT "%08x ", c);
4054+ }
4055+ printk("\n");
4056+}
4057+#endif
4058+
4059 /*
4060 * This routine handles page faults. It determines the address,
4061 * and the problem, and then passes it off to one of the appropriate
4062diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
4063index 302d779..6459dc0 100644
4064--- a/arch/mips/mm/mmap.c
4065+++ b/arch/mips/mm/mmap.c
4066@@ -71,6 +71,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
4067 struct vm_area_struct *vma;
4068 unsigned long addr = addr0;
4069 int do_color_align;
4070+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4071
4072 if (unlikely(len > TASK_SIZE))
4073 return -ENOMEM;
4074@@ -95,6 +96,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
4075 do_color_align = 1;
4076
4077 /* requesting a specific address */
4078+
4079+#ifdef CONFIG_PAX_RANDMMAP
4080+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
4081+#endif
4082+
4083 if (addr) {
4084 if (do_color_align)
4085 addr = COLOUR_ALIGN(addr, pgoff);
4086@@ -102,8 +108,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
4087 addr = PAGE_ALIGN(addr);
4088
4089 vma = find_vma(mm, addr);
4090- if (TASK_SIZE - len >= addr &&
4091- (!vma || addr + len <= vma->vm_start))
4092+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len, offset))
4093 return addr;
4094 }
4095
4096@@ -118,7 +123,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
4097 /* At this point: (!vma || addr < vma->vm_end). */
4098 if (TASK_SIZE - len < addr)
4099 return -ENOMEM;
4100- if (!vma || addr + len <= vma->vm_start)
4101+ if (check_heap_stack_gap(vmm, addr, len, offset))
4102 return addr;
4103 addr = vma->vm_end;
4104 if (do_color_align)
4105@@ -145,7 +150,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
4106 /* make sure it can fit in the remaining address space */
4107 if (likely(addr > len)) {
4108 vma = find_vma(mm, addr - len);
4109- if (!vma || addr <= vma->vm_start) {
4110+ if (check_heap_stack_gap(vmm, addr - len, len, offset))
4111 /* cache the address as a hint for next time */
4112 return mm->free_area_cache = addr - len;
4113 }
4114@@ -155,17 +160,17 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
4115 goto bottomup;
4116
4117 addr = mm->mmap_base - len;
4118- if (do_color_align)
4119- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4120
4121 do {
4122+ if (do_color_align)
4123+ addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4124 /*
4125 * Lookup failure means no vma is above this address,
4126 * else if new region fits below vma->vm_start,
4127 * return with success:
4128 */
4129 vma = find_vma(mm, addr);
4130- if (likely(!vma || addr + len <= vma->vm_start)) {
4131+ if (check_heap_stack_gap(vmm, addr, len, offset)) {
4132 /* cache the address as a hint for next time */
4133 return mm->free_area_cache = addr;
4134 }
4135@@ -175,10 +180,8 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
4136 mm->cached_hole_size = vma->vm_start - addr;
4137
4138 /* try just below the current vma->vm_start */
4139- addr = vma->vm_start - len;
4140- if (do_color_align)
4141- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4142- } while (likely(len < vma->vm_start));
4143+ addr = skip_heap_stack_gap(vma, len, offset);
4144+ } while (!IS_ERR_VALUE(addr));
4145
4146 bottomup:
4147 /*
4148@@ -223,6 +226,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4149 {
4150 unsigned long random_factor = 0UL;
4151
4152+#ifdef CONFIG_PAX_RANDMMAP
4153+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
4154+#endif
4155+
4156 if (current->flags & PF_RANDOMIZE) {
4157 random_factor = get_random_int();
4158 random_factor = random_factor << PAGE_SHIFT;
4159@@ -234,38 +241,23 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4160
4161 if (mmap_is_legacy()) {
4162 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4163+
4164+#ifdef CONFIG_PAX_RANDMMAP
4165+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4166+ mm->mmap_base += mm->delta_mmap;
4167+#endif
4168+
4169 mm->get_unmapped_area = arch_get_unmapped_area;
4170 mm->unmap_area = arch_unmap_area;
4171 } else {
4172 mm->mmap_base = mmap_base(random_factor);
4173+
4174+#ifdef CONFIG_PAX_RANDMMAP
4175+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4176+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4177+#endif
4178+
4179 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4180 mm->unmap_area = arch_unmap_area_topdown;
4181 }
4182 }
4183-
4184-static inline unsigned long brk_rnd(void)
4185-{
4186- unsigned long rnd = get_random_int();
4187-
4188- rnd = rnd << PAGE_SHIFT;
4189- /* 8MB for 32bit, 256MB for 64bit */
4190- if (TASK_IS_32BIT_ADDR)
4191- rnd = rnd & 0x7ffffful;
4192- else
4193- rnd = rnd & 0xffffffful;
4194-
4195- return rnd;
4196-}
4197-
4198-unsigned long arch_randomize_brk(struct mm_struct *mm)
4199-{
4200- unsigned long base = mm->brk;
4201- unsigned long ret;
4202-
4203- ret = PAGE_ALIGN(base + brk_rnd());
4204-
4205- if (ret < mm->brk)
4206- return mm->brk;
4207-
4208- return ret;
4209-}
4210diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
4211index 967d144..db12197 100644
4212--- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
4213+++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
4214@@ -11,12 +11,14 @@
4215 #ifndef _ASM_PROC_CACHE_H
4216 #define _ASM_PROC_CACHE_H
4217
4218+#include <linux/const.h>
4219+
4220 /* L1 cache */
4221
4222 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
4223 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
4224-#define L1_CACHE_BYTES 16 /* bytes per entry */
4225 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
4226+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
4227 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
4228
4229 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
4230diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
4231index bcb5df2..84fabd2 100644
4232--- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
4233+++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
4234@@ -16,13 +16,15 @@
4235 #ifndef _ASM_PROC_CACHE_H
4236 #define _ASM_PROC_CACHE_H
4237
4238+#include <linux/const.h>
4239+
4240 /*
4241 * L1 cache
4242 */
4243 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
4244 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
4245-#define L1_CACHE_BYTES 32 /* bytes per entry */
4246 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
4247+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
4248 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
4249
4250 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
4251diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
4252index 4ce7a01..449202a 100644
4253--- a/arch/openrisc/include/asm/cache.h
4254+++ b/arch/openrisc/include/asm/cache.h
4255@@ -19,11 +19,13 @@
4256 #ifndef __ASM_OPENRISC_CACHE_H
4257 #define __ASM_OPENRISC_CACHE_H
4258
4259+#include <linux/const.h>
4260+
4261 /* FIXME: How can we replace these with values from the CPU...
4262 * they shouldn't be hard-coded!
4263 */
4264
4265-#define L1_CACHE_BYTES 16
4266 #define L1_CACHE_SHIFT 4
4267+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4268
4269 #endif /* __ASM_OPENRISC_CACHE_H */
4270diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
4271index af9cf30..2aae9b2 100644
4272--- a/arch/parisc/include/asm/atomic.h
4273+++ b/arch/parisc/include/asm/atomic.h
4274@@ -229,6 +229,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
4275
4276 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
4277
4278+#define atomic64_read_unchecked(v) atomic64_read(v)
4279+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4280+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4281+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4282+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4283+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4284+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4285+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4286+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4287+
4288 #endif /* !CONFIG_64BIT */
4289
4290
4291diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
4292index 47f11c7..3420df2 100644
4293--- a/arch/parisc/include/asm/cache.h
4294+++ b/arch/parisc/include/asm/cache.h
4295@@ -5,6 +5,7 @@
4296 #ifndef __ARCH_PARISC_CACHE_H
4297 #define __ARCH_PARISC_CACHE_H
4298
4299+#include <linux/const.h>
4300
4301 /*
4302 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
4303@@ -15,13 +16,13 @@
4304 * just ruin performance.
4305 */
4306 #ifdef CONFIG_PA20
4307-#define L1_CACHE_BYTES 64
4308 #define L1_CACHE_SHIFT 6
4309 #else
4310-#define L1_CACHE_BYTES 32
4311 #define L1_CACHE_SHIFT 5
4312 #endif
4313
4314+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4315+
4316 #ifndef __ASSEMBLY__
4317
4318 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4319diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
4320index 19f6cb1..6c78cf2 100644
4321--- a/arch/parisc/include/asm/elf.h
4322+++ b/arch/parisc/include/asm/elf.h
4323@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
4324
4325 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
4326
4327+#ifdef CONFIG_PAX_ASLR
4328+#define PAX_ELF_ET_DYN_BASE 0x10000UL
4329+
4330+#define PAX_DELTA_MMAP_LEN 16
4331+#define PAX_DELTA_STACK_LEN 16
4332+#endif
4333+
4334 /* This yields a mask that user programs can use to figure out what
4335 instruction set this CPU supports. This could be done in user space,
4336 but it's not easy, and we've already done it here. */
4337diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
4338index fc987a1..6e068ef 100644
4339--- a/arch/parisc/include/asm/pgalloc.h
4340+++ b/arch/parisc/include/asm/pgalloc.h
4341@@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
4342 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
4343 }
4344
4345+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
4346+{
4347+ pgd_populate(mm, pgd, pmd);
4348+}
4349+
4350 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
4351 {
4352 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
4353@@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
4354 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
4355 #define pmd_free(mm, x) do { } while (0)
4356 #define pgd_populate(mm, pmd, pte) BUG()
4357+#define pgd_populate_kernel(mm, pmd, pte) BUG()
4358
4359 #endif
4360
4361diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
4362index ee99f23..802b0a1 100644
4363--- a/arch/parisc/include/asm/pgtable.h
4364+++ b/arch/parisc/include/asm/pgtable.h
4365@@ -212,6 +212,17 @@ struct vm_area_struct;
4366 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
4367 #define PAGE_COPY PAGE_EXECREAD
4368 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
4369+
4370+#ifdef CONFIG_PAX_PAGEEXEC
4371+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
4372+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
4373+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
4374+#else
4375+# define PAGE_SHARED_NOEXEC PAGE_SHARED
4376+# define PAGE_COPY_NOEXEC PAGE_COPY
4377+# define PAGE_READONLY_NOEXEC PAGE_READONLY
4378+#endif
4379+
4380 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
4381 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
4382 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
4383diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
4384index 4ba2c93..f5e3974 100644
4385--- a/arch/parisc/include/asm/uaccess.h
4386+++ b/arch/parisc/include/asm/uaccess.h
4387@@ -251,10 +251,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
4388 const void __user *from,
4389 unsigned long n)
4390 {
4391- int sz = __compiletime_object_size(to);
4392+ size_t sz = __compiletime_object_size(to);
4393 int ret = -EFAULT;
4394
4395- if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
4396+ if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
4397 ret = __copy_from_user(to, from, n);
4398 else
4399 copy_from_user_overflow();
4400diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
4401index 5e34ccf..672bc9c 100644
4402--- a/arch/parisc/kernel/module.c
4403+++ b/arch/parisc/kernel/module.c
4404@@ -98,16 +98,38 @@
4405
4406 /* three functions to determine where in the module core
4407 * or init pieces the location is */
4408+static inline int in_init_rx(struct module *me, void *loc)
4409+{
4410+ return (loc >= me->module_init_rx &&
4411+ loc < (me->module_init_rx + me->init_size_rx));
4412+}
4413+
4414+static inline int in_init_rw(struct module *me, void *loc)
4415+{
4416+ return (loc >= me->module_init_rw &&
4417+ loc < (me->module_init_rw + me->init_size_rw));
4418+}
4419+
4420 static inline int in_init(struct module *me, void *loc)
4421 {
4422- return (loc >= me->module_init &&
4423- loc <= (me->module_init + me->init_size));
4424+ return in_init_rx(me, loc) || in_init_rw(me, loc);
4425+}
4426+
4427+static inline int in_core_rx(struct module *me, void *loc)
4428+{
4429+ return (loc >= me->module_core_rx &&
4430+ loc < (me->module_core_rx + me->core_size_rx));
4431+}
4432+
4433+static inline int in_core_rw(struct module *me, void *loc)
4434+{
4435+ return (loc >= me->module_core_rw &&
4436+ loc < (me->module_core_rw + me->core_size_rw));
4437 }
4438
4439 static inline int in_core(struct module *me, void *loc)
4440 {
4441- return (loc >= me->module_core &&
4442- loc <= (me->module_core + me->core_size));
4443+ return in_core_rx(me, loc) || in_core_rw(me, loc);
4444 }
4445
4446 static inline int in_local(struct module *me, void *loc)
4447@@ -373,13 +395,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
4448 }
4449
4450 /* align things a bit */
4451- me->core_size = ALIGN(me->core_size, 16);
4452- me->arch.got_offset = me->core_size;
4453- me->core_size += gots * sizeof(struct got_entry);
4454+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
4455+ me->arch.got_offset = me->core_size_rw;
4456+ me->core_size_rw += gots * sizeof(struct got_entry);
4457
4458- me->core_size = ALIGN(me->core_size, 16);
4459- me->arch.fdesc_offset = me->core_size;
4460- me->core_size += fdescs * sizeof(Elf_Fdesc);
4461+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
4462+ me->arch.fdesc_offset = me->core_size_rw;
4463+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
4464
4465 me->arch.got_max = gots;
4466 me->arch.fdesc_max = fdescs;
4467@@ -397,7 +419,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
4468
4469 BUG_ON(value == 0);
4470
4471- got = me->module_core + me->arch.got_offset;
4472+ got = me->module_core_rw + me->arch.got_offset;
4473 for (i = 0; got[i].addr; i++)
4474 if (got[i].addr == value)
4475 goto out;
4476@@ -415,7 +437,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
4477 #ifdef CONFIG_64BIT
4478 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
4479 {
4480- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
4481+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
4482
4483 if (!value) {
4484 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
4485@@ -433,7 +455,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
4486
4487 /* Create new one */
4488 fdesc->addr = value;
4489- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
4490+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
4491 return (Elf_Addr)fdesc;
4492 }
4493 #endif /* CONFIG_64BIT */
4494@@ -845,7 +867,7 @@ register_unwind_table(struct module *me,
4495
4496 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
4497 end = table + sechdrs[me->arch.unwind_section].sh_size;
4498- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
4499+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
4500
4501 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
4502 me->arch.unwind_section, table, end, gp);
4503diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
4504index f76c108..92bad82 100644
4505--- a/arch/parisc/kernel/sys_parisc.c
4506+++ b/arch/parisc/kernel/sys_parisc.c
4507@@ -33,9 +33,11 @@
4508 #include <linux/utsname.h>
4509 #include <linux/personality.h>
4510
4511-static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
4512+static unsigned long get_unshared_area(struct file *filp, unsigned long addr, unsigned long len,
4513+ unsigned long flags)
4514 {
4515 struct vm_area_struct *vma;
4516+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4517
4518 addr = PAGE_ALIGN(addr);
4519
4520@@ -43,7 +45,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
4521 /* At this point: (!vma || addr < vma->vm_end). */
4522 if (TASK_SIZE - len < addr)
4523 return -ENOMEM;
4524- if (!vma || addr + len <= vma->vm_start)
4525+ if (check_heap_stack_gap(vma, addr, len, offset))
4526 return addr;
4527 addr = vma->vm_end;
4528 }
4529@@ -67,11 +69,12 @@ static int get_offset(struct address_space *mapping)
4530 return offset & 0x3FF000;
4531 }
4532
4533-static unsigned long get_shared_area(struct address_space *mapping,
4534- unsigned long addr, unsigned long len, unsigned long pgoff)
4535+static unsigned long get_shared_area(struct file *filp, struct address_space *mapping,
4536+ unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags)
4537 {
4538 struct vm_area_struct *vma;
4539 int offset = mapping ? get_offset(mapping) : 0;
4540+ unsigned long rand_offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4541
4542 offset = (offset + (pgoff << PAGE_SHIFT)) & 0x3FF000;
4543
4544@@ -81,7 +84,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
4545 /* At this point: (!vma || addr < vma->vm_end). */
4546 if (TASK_SIZE - len < addr)
4547 return -ENOMEM;
4548- if (!vma || addr + len <= vma->vm_start)
4549+ if (check_heap_stack_gap(vma, addr, len, rand_offset))
4550 return addr;
4551 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
4552 if (addr < vma->vm_end) /* handle wraparound */
4553@@ -100,14 +103,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
4554 if (flags & MAP_FIXED)
4555 return addr;
4556 if (!addr)
4557- addr = TASK_UNMAPPED_BASE;
4558+ addr = current->mm->mmap_base;
4559
4560 if (filp) {
4561- addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
4562+ addr = get_shared_area(filp, filp->f_mapping, addr, len, pgoff, flags);
4563 } else if(flags & MAP_SHARED) {
4564- addr = get_shared_area(NULL, addr, len, pgoff);
4565+ addr = get_shared_area(filp, NULL, addr, len, pgoff, flags);
4566 } else {
4567- addr = get_unshared_area(addr, len);
4568+ addr = get_unshared_area(filp, addr, len, flags);
4569 }
4570 return addr;
4571 }
4572diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
4573index 45ba99f..8e22c33 100644
4574--- a/arch/parisc/kernel/traps.c
4575+++ b/arch/parisc/kernel/traps.c
4576@@ -732,9 +732,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
4577
4578 down_read(&current->mm->mmap_sem);
4579 vma = find_vma(current->mm,regs->iaoq[0]);
4580- if (vma && (regs->iaoq[0] >= vma->vm_start)
4581- && (vma->vm_flags & VM_EXEC)) {
4582-
4583+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
4584 fault_address = regs->iaoq[0];
4585 fault_space = regs->iasq[0];
4586
4587diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
4588index 18162ce..94de376 100644
4589--- a/arch/parisc/mm/fault.c
4590+++ b/arch/parisc/mm/fault.c
4591@@ -15,6 +15,7 @@
4592 #include <linux/sched.h>
4593 #include <linux/interrupt.h>
4594 #include <linux/module.h>
4595+#include <linux/unistd.h>
4596
4597 #include <asm/uaccess.h>
4598 #include <asm/traps.h>
4599@@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
4600 static unsigned long
4601 parisc_acctyp(unsigned long code, unsigned int inst)
4602 {
4603- if (code == 6 || code == 16)
4604+ if (code == 6 || code == 7 || code == 16)
4605 return VM_EXEC;
4606
4607 switch (inst & 0xf0000000) {
4608@@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
4609 }
4610 #endif
4611
4612+#ifdef CONFIG_PAX_PAGEEXEC
4613+/*
4614+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
4615+ *
4616+ * returns 1 when task should be killed
4617+ * 2 when rt_sigreturn trampoline was detected
4618+ * 3 when unpatched PLT trampoline was detected
4619+ */
4620+static int pax_handle_fetch_fault(struct pt_regs *regs)
4621+{
4622+
4623+#ifdef CONFIG_PAX_EMUPLT
4624+ int err;
4625+
4626+ do { /* PaX: unpatched PLT emulation */
4627+ unsigned int bl, depwi;
4628+
4629+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
4630+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
4631+
4632+ if (err)
4633+ break;
4634+
4635+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
4636+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
4637+
4638+ err = get_user(ldw, (unsigned int *)addr);
4639+ err |= get_user(bv, (unsigned int *)(addr+4));
4640+ err |= get_user(ldw2, (unsigned int *)(addr+8));
4641+
4642+ if (err)
4643+ break;
4644+
4645+ if (ldw == 0x0E801096U &&
4646+ bv == 0xEAC0C000U &&
4647+ ldw2 == 0x0E881095U)
4648+ {
4649+ unsigned int resolver, map;
4650+
4651+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
4652+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
4653+ if (err)
4654+ break;
4655+
4656+ regs->gr[20] = instruction_pointer(regs)+8;
4657+ regs->gr[21] = map;
4658+ regs->gr[22] = resolver;
4659+ regs->iaoq[0] = resolver | 3UL;
4660+ regs->iaoq[1] = regs->iaoq[0] + 4;
4661+ return 3;
4662+ }
4663+ }
4664+ } while (0);
4665+#endif
4666+
4667+#ifdef CONFIG_PAX_EMUTRAMP
4668+
4669+#ifndef CONFIG_PAX_EMUSIGRT
4670+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
4671+ return 1;
4672+#endif
4673+
4674+ do { /* PaX: rt_sigreturn emulation */
4675+ unsigned int ldi1, ldi2, bel, nop;
4676+
4677+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
4678+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
4679+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
4680+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
4681+
4682+ if (err)
4683+ break;
4684+
4685+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
4686+ ldi2 == 0x3414015AU &&
4687+ bel == 0xE4008200U &&
4688+ nop == 0x08000240U)
4689+ {
4690+ regs->gr[25] = (ldi1 & 2) >> 1;
4691+ regs->gr[20] = __NR_rt_sigreturn;
4692+ regs->gr[31] = regs->iaoq[1] + 16;
4693+ regs->sr[0] = regs->iasq[1];
4694+ regs->iaoq[0] = 0x100UL;
4695+ regs->iaoq[1] = regs->iaoq[0] + 4;
4696+ regs->iasq[0] = regs->sr[2];
4697+ regs->iasq[1] = regs->sr[2];
4698+ return 2;
4699+ }
4700+ } while (0);
4701+#endif
4702+
4703+ return 1;
4704+}
4705+
4706+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4707+{
4708+ unsigned long i;
4709+
4710+ printk(KERN_ERR "PAX: bytes at PC: ");
4711+ for (i = 0; i < 5; i++) {
4712+ unsigned int c;
4713+ if (get_user(c, (unsigned int *)pc+i))
4714+ printk(KERN_CONT "???????? ");
4715+ else
4716+ printk(KERN_CONT "%08x ", c);
4717+ }
4718+ printk("\n");
4719+}
4720+#endif
4721+
4722 int fixup_exception(struct pt_regs *regs)
4723 {
4724 const struct exception_table_entry *fix;
4725@@ -192,8 +303,33 @@ good_area:
4726
4727 acc_type = parisc_acctyp(code,regs->iir);
4728
4729- if ((vma->vm_flags & acc_type) != acc_type)
4730+ if ((vma->vm_flags & acc_type) != acc_type) {
4731+
4732+#ifdef CONFIG_PAX_PAGEEXEC
4733+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
4734+ (address & ~3UL) == instruction_pointer(regs))
4735+ {
4736+ up_read(&mm->mmap_sem);
4737+ switch (pax_handle_fetch_fault(regs)) {
4738+
4739+#ifdef CONFIG_PAX_EMUPLT
4740+ case 3:
4741+ return;
4742+#endif
4743+
4744+#ifdef CONFIG_PAX_EMUTRAMP
4745+ case 2:
4746+ return;
4747+#endif
4748+
4749+ }
4750+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
4751+ do_group_exit(SIGKILL);
4752+ }
4753+#endif
4754+
4755 goto bad_area;
4756+ }
4757
4758 /*
4759 * If for any reason at all we couldn't handle the fault, make
4760diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
4761index e3b1d41..8e81edf 100644
4762--- a/arch/powerpc/include/asm/atomic.h
4763+++ b/arch/powerpc/include/asm/atomic.h
4764@@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
4765 return t1;
4766 }
4767
4768+#define atomic64_read_unchecked(v) atomic64_read(v)
4769+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4770+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4771+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4772+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4773+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4774+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4775+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4776+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4777+
4778 #endif /* __powerpc64__ */
4779
4780 #endif /* __KERNEL__ */
4781diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
4782index 9e495c9..b6878e5 100644
4783--- a/arch/powerpc/include/asm/cache.h
4784+++ b/arch/powerpc/include/asm/cache.h
4785@@ -3,6 +3,7 @@
4786
4787 #ifdef __KERNEL__
4788
4789+#include <linux/const.h>
4790
4791 /* bytes per L1 cache line */
4792 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
4793@@ -22,7 +23,7 @@
4794 #define L1_CACHE_SHIFT 7
4795 #endif
4796
4797-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4798+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4799
4800 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4801
4802diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
4803index 6abf0a1..459d0f1 100644
4804--- a/arch/powerpc/include/asm/elf.h
4805+++ b/arch/powerpc/include/asm/elf.h
4806@@ -28,8 +28,19 @@
4807 the loader. We need to make sure that it is out of the way of the program
4808 that it will "exec", and that there is sufficient room for the brk. */
4809
4810-extern unsigned long randomize_et_dyn(unsigned long base);
4811-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
4812+#define ELF_ET_DYN_BASE (0x20000000)
4813+
4814+#ifdef CONFIG_PAX_ASLR
4815+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
4816+
4817+#ifdef __powerpc64__
4818+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
4819+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
4820+#else
4821+#define PAX_DELTA_MMAP_LEN 15
4822+#define PAX_DELTA_STACK_LEN 15
4823+#endif
4824+#endif
4825
4826 /*
4827 * Our registers are always unsigned longs, whether we're a 32 bit
4828@@ -124,10 +135,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
4829 (0x7ff >> (PAGE_SHIFT - 12)) : \
4830 (0x3ffff >> (PAGE_SHIFT - 12)))
4831
4832-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
4833-#define arch_randomize_brk arch_randomize_brk
4834-
4835-
4836 #ifdef CONFIG_SPU_BASE
4837 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
4838 #define NT_SPU 1
4839diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
4840index 8196e9c..d83a9f3 100644
4841--- a/arch/powerpc/include/asm/exec.h
4842+++ b/arch/powerpc/include/asm/exec.h
4843@@ -4,6 +4,6 @@
4844 #ifndef _ASM_POWERPC_EXEC_H
4845 #define _ASM_POWERPC_EXEC_H
4846
4847-extern unsigned long arch_align_stack(unsigned long sp);
4848+#define arch_align_stack(x) ((x) & ~0xfUL)
4849
4850 #endif /* _ASM_POWERPC_EXEC_H */
4851diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
4852index 5acabbd..7ea14fa 100644
4853--- a/arch/powerpc/include/asm/kmap_types.h
4854+++ b/arch/powerpc/include/asm/kmap_types.h
4855@@ -10,7 +10,7 @@
4856 * 2 of the License, or (at your option) any later version.
4857 */
4858
4859-#define KM_TYPE_NR 16
4860+#define KM_TYPE_NR 17
4861
4862 #endif /* __KERNEL__ */
4863 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
4864diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
4865index 8565c25..2865190 100644
4866--- a/arch/powerpc/include/asm/mman.h
4867+++ b/arch/powerpc/include/asm/mman.h
4868@@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
4869 }
4870 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
4871
4872-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
4873+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
4874 {
4875 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
4876 }
4877diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
4878index f072e97..b436dee 100644
4879--- a/arch/powerpc/include/asm/page.h
4880+++ b/arch/powerpc/include/asm/page.h
4881@@ -220,8 +220,9 @@ extern long long virt_phys_offset;
4882 * and needs to be executable. This means the whole heap ends
4883 * up being executable.
4884 */
4885-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
4886- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
4887+#define VM_DATA_DEFAULT_FLAGS32 \
4888+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
4889+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
4890
4891 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
4892 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
4893@@ -249,6 +250,9 @@ extern long long virt_phys_offset;
4894 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
4895 #endif
4896
4897+#define ktla_ktva(addr) (addr)
4898+#define ktva_ktla(addr) (addr)
4899+
4900 /*
4901 * Use the top bit of the higher-level page table entries to indicate whether
4902 * the entries we point to contain hugepages. This works because we know that
4903diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
4904index cd915d6..c10cee8 100644
4905--- a/arch/powerpc/include/asm/page_64.h
4906+++ b/arch/powerpc/include/asm/page_64.h
4907@@ -154,15 +154,18 @@ do { \
4908 * stack by default, so in the absence of a PT_GNU_STACK program header
4909 * we turn execute permission off.
4910 */
4911-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
4912- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
4913+#define VM_STACK_DEFAULT_FLAGS32 \
4914+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
4915+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
4916
4917 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
4918 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
4919
4920+#ifndef CONFIG_PAX_PAGEEXEC
4921 #define VM_STACK_DEFAULT_FLAGS \
4922 (is_32bit_task() ? \
4923 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
4924+#endif
4925
4926 #include <asm-generic/getorder.h>
4927
4928diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
4929index 292725c..f87ae14 100644
4930--- a/arch/powerpc/include/asm/pgalloc-64.h
4931+++ b/arch/powerpc/include/asm/pgalloc-64.h
4932@@ -50,6 +50,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
4933 #ifndef CONFIG_PPC_64K_PAGES
4934
4935 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
4936+#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
4937
4938 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
4939 {
4940@@ -67,6 +68,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
4941 pud_set(pud, (unsigned long)pmd);
4942 }
4943
4944+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
4945+{
4946+ pud_populate(mm, pud, pmd);
4947+}
4948+
4949 #define pmd_populate(mm, pmd, pte_page) \
4950 pmd_populate_kernel(mm, pmd, page_address(pte_page))
4951 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
4952@@ -76,6 +82,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
4953 #else /* CONFIG_PPC_64K_PAGES */
4954
4955 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
4956+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
4957
4958 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
4959 pte_t *pte)
4960diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
4961index a9cbd3b..3b67efa 100644
4962--- a/arch/powerpc/include/asm/pgtable.h
4963+++ b/arch/powerpc/include/asm/pgtable.h
4964@@ -2,6 +2,7 @@
4965 #define _ASM_POWERPC_PGTABLE_H
4966 #ifdef __KERNEL__
4967
4968+#include <linux/const.h>
4969 #ifndef __ASSEMBLY__
4970 #include <asm/processor.h> /* For TASK_SIZE */
4971 #include <asm/mmu.h>
4972diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
4973index 4aad413..85d86bf 100644
4974--- a/arch/powerpc/include/asm/pte-hash32.h
4975+++ b/arch/powerpc/include/asm/pte-hash32.h
4976@@ -21,6 +21,7 @@
4977 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
4978 #define _PAGE_USER 0x004 /* usermode access allowed */
4979 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
4980+#define _PAGE_EXEC _PAGE_GUARDED
4981 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
4982 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
4983 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
4984diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
4985index d24c141..b60696e 100644
4986--- a/arch/powerpc/include/asm/reg.h
4987+++ b/arch/powerpc/include/asm/reg.h
4988@@ -215,6 +215,7 @@
4989 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
4990 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
4991 #define DSISR_NOHPTE 0x40000000 /* no translation found */
4992+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
4993 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
4994 #define DSISR_ISSTORE 0x02000000 /* access was a store */
4995 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
4996diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
4997index 406b7b9..af63426 100644
4998--- a/arch/powerpc/include/asm/thread_info.h
4999+++ b/arch/powerpc/include/asm/thread_info.h
5000@@ -97,7 +97,6 @@ static inline struct thread_info *current_thread_info(void)
5001 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
5002 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
5003 #define TIF_SINGLESTEP 8 /* singlestepping active */
5004-#define TIF_MEMDIE 9 /* is terminating due to OOM killer */
5005 #define TIF_SECCOMP 10 /* secure computing */
5006 #define TIF_RESTOREALL 11 /* Restore all regs (implies NOERROR) */
5007 #define TIF_NOERROR 12 /* Force successful syscall return */
5008@@ -106,6 +105,9 @@ static inline struct thread_info *current_thread_info(void)
5009 #define TIF_SYSCALL_TRACEPOINT 15 /* syscall tracepoint instrumentation */
5010 #define TIF_EMULATE_STACK_STORE 16 /* Is an instruction emulation
5011 for stack store? */
5012+#define TIF_MEMDIE 17 /* is terminating due to OOM killer */
5013+/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
5014+#define TIF_GRSEC_SETXID 9 /* update credentials on syscall entry/exit */
5015
5016 /* as above, but as bit values */
5017 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
5018@@ -124,8 +126,10 @@ static inline struct thread_info *current_thread_info(void)
5019 #define _TIF_UPROBE (1<<TIF_UPROBE)
5020 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
5021 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
5022+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
5023 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
5024- _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT)
5025+ _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
5026+ _TIF_GRSEC_SETXID)
5027
5028 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
5029 _TIF_NOTIFY_RESUME | _TIF_UPROBE)
5030diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
5031index 4db4959..335e00c 100644
5032--- a/arch/powerpc/include/asm/uaccess.h
5033+++ b/arch/powerpc/include/asm/uaccess.h
5034@@ -13,6 +13,8 @@
5035 #define VERIFY_READ 0
5036 #define VERIFY_WRITE 1
5037
5038+extern void check_object_size(const void *ptr, unsigned long n, bool to);
5039+
5040 /*
5041 * The fs value determines whether argument validity checking should be
5042 * performed or not. If get_fs() == USER_DS, checking is performed, with
5043@@ -318,52 +320,6 @@ do { \
5044 extern unsigned long __copy_tofrom_user(void __user *to,
5045 const void __user *from, unsigned long size);
5046
5047-#ifndef __powerpc64__
5048-
5049-static inline unsigned long copy_from_user(void *to,
5050- const void __user *from, unsigned long n)
5051-{
5052- unsigned long over;
5053-
5054- if (access_ok(VERIFY_READ, from, n))
5055- return __copy_tofrom_user((__force void __user *)to, from, n);
5056- if ((unsigned long)from < TASK_SIZE) {
5057- over = (unsigned long)from + n - TASK_SIZE;
5058- return __copy_tofrom_user((__force void __user *)to, from,
5059- n - over) + over;
5060- }
5061- return n;
5062-}
5063-
5064-static inline unsigned long copy_to_user(void __user *to,
5065- const void *from, unsigned long n)
5066-{
5067- unsigned long over;
5068-
5069- if (access_ok(VERIFY_WRITE, to, n))
5070- return __copy_tofrom_user(to, (__force void __user *)from, n);
5071- if ((unsigned long)to < TASK_SIZE) {
5072- over = (unsigned long)to + n - TASK_SIZE;
5073- return __copy_tofrom_user(to, (__force void __user *)from,
5074- n - over) + over;
5075- }
5076- return n;
5077-}
5078-
5079-#else /* __powerpc64__ */
5080-
5081-#define __copy_in_user(to, from, size) \
5082- __copy_tofrom_user((to), (from), (size))
5083-
5084-extern unsigned long copy_from_user(void *to, const void __user *from,
5085- unsigned long n);
5086-extern unsigned long copy_to_user(void __user *to, const void *from,
5087- unsigned long n);
5088-extern unsigned long copy_in_user(void __user *to, const void __user *from,
5089- unsigned long n);
5090-
5091-#endif /* __powerpc64__ */
5092-
5093 static inline unsigned long __copy_from_user_inatomic(void *to,
5094 const void __user *from, unsigned long n)
5095 {
5096@@ -387,6 +343,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
5097 if (ret == 0)
5098 return 0;
5099 }
5100+
5101+ if (!__builtin_constant_p(n))
5102+ check_object_size(to, n, false);
5103+
5104 return __copy_tofrom_user((__force void __user *)to, from, n);
5105 }
5106
5107@@ -413,6 +373,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
5108 if (ret == 0)
5109 return 0;
5110 }
5111+
5112+ if (!__builtin_constant_p(n))
5113+ check_object_size(from, n, true);
5114+
5115 return __copy_tofrom_user(to, (__force const void __user *)from, n);
5116 }
5117
5118@@ -430,6 +394,92 @@ static inline unsigned long __copy_to_user(void __user *to,
5119 return __copy_to_user_inatomic(to, from, size);
5120 }
5121
5122+#ifndef __powerpc64__
5123+
5124+static inline unsigned long __must_check copy_from_user(void *to,
5125+ const void __user *from, unsigned long n)
5126+{
5127+ unsigned long over;
5128+
5129+ if ((long)n < 0)
5130+ return n;
5131+
5132+ if (access_ok(VERIFY_READ, from, n)) {
5133+ if (!__builtin_constant_p(n))
5134+ check_object_size(to, n, false);
5135+ return __copy_tofrom_user((__force void __user *)to, from, n);
5136+ }
5137+ if ((unsigned long)from < TASK_SIZE) {
5138+ over = (unsigned long)from + n - TASK_SIZE;
5139+ if (!__builtin_constant_p(n - over))
5140+ check_object_size(to, n - over, false);
5141+ return __copy_tofrom_user((__force void __user *)to, from,
5142+ n - over) + over;
5143+ }
5144+ return n;
5145+}
5146+
5147+static inline unsigned long __must_check copy_to_user(void __user *to,
5148+ const void *from, unsigned long n)
5149+{
5150+ unsigned long over;
5151+
5152+ if ((long)n < 0)
5153+ return n;
5154+
5155+ if (access_ok(VERIFY_WRITE, to, n)) {
5156+ if (!__builtin_constant_p(n))
5157+ check_object_size(from, n, true);
5158+ return __copy_tofrom_user(to, (__force void __user *)from, n);
5159+ }
5160+ if ((unsigned long)to < TASK_SIZE) {
5161+ over = (unsigned long)to + n - TASK_SIZE;
5162+ if (!__builtin_constant_p(n))
5163+ check_object_size(from, n - over, true);
5164+ return __copy_tofrom_user(to, (__force void __user *)from,
5165+ n - over) + over;
5166+ }
5167+ return n;
5168+}
5169+
5170+#else /* __powerpc64__ */
5171+
5172+#define __copy_in_user(to, from, size) \
5173+ __copy_tofrom_user((to), (from), (size))
5174+
5175+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
5176+{
5177+ if ((long)n < 0 || n > INT_MAX)
5178+ return n;
5179+
5180+ if (!__builtin_constant_p(n))
5181+ check_object_size(to, n, false);
5182+
5183+ if (likely(access_ok(VERIFY_READ, from, n)))
5184+ n = __copy_from_user(to, from, n);
5185+ else
5186+ memset(to, 0, n);
5187+ return n;
5188+}
5189+
5190+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
5191+{
5192+ if ((long)n < 0 || n > INT_MAX)
5193+ return n;
5194+
5195+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
5196+ if (!__builtin_constant_p(n))
5197+ check_object_size(from, n, true);
5198+ n = __copy_to_user(to, from, n);
5199+ }
5200+ return n;
5201+}
5202+
5203+extern unsigned long copy_in_user(void __user *to, const void __user *from,
5204+ unsigned long n);
5205+
5206+#endif /* __powerpc64__ */
5207+
5208 extern unsigned long __clear_user(void __user *addr, unsigned long size);
5209
5210 static inline unsigned long clear_user(void __user *addr, unsigned long size)
5211diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
5212index 4684e33..acc4d19e 100644
5213--- a/arch/powerpc/kernel/exceptions-64e.S
5214+++ b/arch/powerpc/kernel/exceptions-64e.S
5215@@ -715,6 +715,7 @@ storage_fault_common:
5216 std r14,_DAR(r1)
5217 std r15,_DSISR(r1)
5218 addi r3,r1,STACK_FRAME_OVERHEAD
5219+ bl .save_nvgprs
5220 mr r4,r14
5221 mr r5,r15
5222 ld r14,PACA_EXGEN+EX_R14(r13)
5223@@ -723,8 +724,7 @@ storage_fault_common:
5224 cmpdi r3,0
5225 bne- 1f
5226 b .ret_from_except_lite
5227-1: bl .save_nvgprs
5228- mr r5,r3
5229+1: mr r5,r3
5230 addi r3,r1,STACK_FRAME_OVERHEAD
5231 ld r4,_DAR(r1)
5232 bl .bad_page_fault
5233diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
5234index 10b658a..e542888 100644
5235--- a/arch/powerpc/kernel/exceptions-64s.S
5236+++ b/arch/powerpc/kernel/exceptions-64s.S
5237@@ -1013,10 +1013,10 @@ handle_page_fault:
5238 11: ld r4,_DAR(r1)
5239 ld r5,_DSISR(r1)
5240 addi r3,r1,STACK_FRAME_OVERHEAD
5241+ bl .save_nvgprs
5242 bl .do_page_fault
5243 cmpdi r3,0
5244 beq+ 12f
5245- bl .save_nvgprs
5246 mr r5,r3
5247 addi r3,r1,STACK_FRAME_OVERHEAD
5248 lwz r4,_DAR(r1)
5249diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
5250index 2e3200c..72095ce 100644
5251--- a/arch/powerpc/kernel/module_32.c
5252+++ b/arch/powerpc/kernel/module_32.c
5253@@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
5254 me->arch.core_plt_section = i;
5255 }
5256 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
5257- printk("Module doesn't contain .plt or .init.plt sections.\n");
5258+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
5259 return -ENOEXEC;
5260 }
5261
5262@@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
5263
5264 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
5265 /* Init, or core PLT? */
5266- if (location >= mod->module_core
5267- && location < mod->module_core + mod->core_size)
5268+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
5269+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
5270 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
5271- else
5272+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
5273+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
5274 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
5275+ else {
5276+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
5277+ return ~0UL;
5278+ }
5279
5280 /* Find this entry, or if that fails, the next avail. entry */
5281 while (entry->jump[0]) {
5282diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
5283index ba48233..16ac31d 100644
5284--- a/arch/powerpc/kernel/process.c
5285+++ b/arch/powerpc/kernel/process.c
5286@@ -680,8 +680,8 @@ void show_regs(struct pt_regs * regs)
5287 * Lookup NIP late so we have the best change of getting the
5288 * above info out without failing
5289 */
5290- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
5291- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
5292+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
5293+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
5294 #endif
5295 show_stack(current, (unsigned long *) regs->gpr[1]);
5296 if (!user_mode(regs))
5297@@ -1175,10 +1175,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
5298 newsp = stack[0];
5299 ip = stack[STACK_FRAME_LR_SAVE];
5300 if (!firstframe || ip != lr) {
5301- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
5302+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
5303 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
5304 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
5305- printk(" (%pS)",
5306+ printk(" (%pA)",
5307 (void *)current->ret_stack[curr_frame].ret);
5308 curr_frame--;
5309 }
5310@@ -1198,7 +1198,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
5311 struct pt_regs *regs = (struct pt_regs *)
5312 (sp + STACK_FRAME_OVERHEAD);
5313 lr = regs->link;
5314- printk("--- Exception: %lx at %pS\n LR = %pS\n",
5315+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
5316 regs->trap, (void *)regs->nip, (void *)lr);
5317 firstframe = 1;
5318 }
5319@@ -1240,58 +1240,3 @@ void __ppc64_runlatch_off(void)
5320 mtspr(SPRN_CTRLT, ctrl);
5321 }
5322 #endif /* CONFIG_PPC64 */
5323-
5324-unsigned long arch_align_stack(unsigned long sp)
5325-{
5326- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
5327- sp -= get_random_int() & ~PAGE_MASK;
5328- return sp & ~0xf;
5329-}
5330-
5331-static inline unsigned long brk_rnd(void)
5332-{
5333- unsigned long rnd = 0;
5334-
5335- /* 8MB for 32bit, 1GB for 64bit */
5336- if (is_32bit_task())
5337- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
5338- else
5339- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
5340-
5341- return rnd << PAGE_SHIFT;
5342-}
5343-
5344-unsigned long arch_randomize_brk(struct mm_struct *mm)
5345-{
5346- unsigned long base = mm->brk;
5347- unsigned long ret;
5348-
5349-#ifdef CONFIG_PPC_STD_MMU_64
5350- /*
5351- * If we are using 1TB segments and we are allowed to randomise
5352- * the heap, we can put it above 1TB so it is backed by a 1TB
5353- * segment. Otherwise the heap will be in the bottom 1TB
5354- * which always uses 256MB segments and this may result in a
5355- * performance penalty.
5356- */
5357- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
5358- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
5359-#endif
5360-
5361- ret = PAGE_ALIGN(base + brk_rnd());
5362-
5363- if (ret < mm->brk)
5364- return mm->brk;
5365-
5366- return ret;
5367-}
5368-
5369-unsigned long randomize_et_dyn(unsigned long base)
5370-{
5371- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
5372-
5373- if (ret < base)
5374- return base;
5375-
5376- return ret;
5377-}
5378diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
5379index 79d8e56..38ffcbb 100644
5380--- a/arch/powerpc/kernel/ptrace.c
5381+++ b/arch/powerpc/kernel/ptrace.c
5382@@ -1663,6 +1663,10 @@ long arch_ptrace(struct task_struct *child, long request,
5383 return ret;
5384 }
5385
5386+#ifdef CONFIG_GRKERNSEC_SETXID
5387+extern void gr_delayed_cred_worker(void);
5388+#endif
5389+
5390 /*
5391 * We must return the syscall number to actually look up in the table.
5392 * This can be -1L to skip running any syscall at all.
5393@@ -1673,6 +1677,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
5394
5395 secure_computing_strict(regs->gpr[0]);
5396
5397+#ifdef CONFIG_GRKERNSEC_SETXID
5398+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5399+ gr_delayed_cred_worker();
5400+#endif
5401+
5402 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
5403 tracehook_report_syscall_entry(regs))
5404 /*
5405@@ -1707,6 +1716,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
5406 {
5407 int step;
5408
5409+#ifdef CONFIG_GRKERNSEC_SETXID
5410+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5411+ gr_delayed_cred_worker();
5412+#endif
5413+
5414 audit_syscall_exit(regs);
5415
5416 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
5417diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
5418index 804e323..79181c1 100644
5419--- a/arch/powerpc/kernel/signal_32.c
5420+++ b/arch/powerpc/kernel/signal_32.c
5421@@ -851,7 +851,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
5422 /* Save user registers on the stack */
5423 frame = &rt_sf->uc.uc_mcontext;
5424 addr = frame;
5425- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
5426+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
5427 if (save_user_regs(regs, frame, 0, 1))
5428 goto badframe;
5429 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
5430diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
5431index d183f87..1867f1a 100644
5432--- a/arch/powerpc/kernel/signal_64.c
5433+++ b/arch/powerpc/kernel/signal_64.c
5434@@ -430,7 +430,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
5435 current->thread.fpscr.val = 0;
5436
5437 /* Set up to return from userspace. */
5438- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
5439+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
5440 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
5441 } else {
5442 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
5443diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
5444index 3251840..3f7c77a 100644
5445--- a/arch/powerpc/kernel/traps.c
5446+++ b/arch/powerpc/kernel/traps.c
5447@@ -133,6 +133,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
5448 return flags;
5449 }
5450
5451+extern void gr_handle_kernel_exploit(void);
5452+
5453 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
5454 int signr)
5455 {
5456@@ -182,6 +184,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
5457 panic("Fatal exception in interrupt");
5458 if (panic_on_oops)
5459 panic("Fatal exception");
5460+
5461+ gr_handle_kernel_exploit();
5462+
5463 do_exit(signr);
5464 }
5465
5466diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
5467index 1b2076f..835e4be 100644
5468--- a/arch/powerpc/kernel/vdso.c
5469+++ b/arch/powerpc/kernel/vdso.c
5470@@ -34,6 +34,7 @@
5471 #include <asm/firmware.h>
5472 #include <asm/vdso.h>
5473 #include <asm/vdso_datapage.h>
5474+#include <asm/mman.h>
5475
5476 #include "setup.h"
5477
5478@@ -218,7 +219,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
5479 vdso_base = VDSO32_MBASE;
5480 #endif
5481
5482- current->mm->context.vdso_base = 0;
5483+ current->mm->context.vdso_base = ~0UL;
5484
5485 /* vDSO has a problem and was disabled, just don't "enable" it for the
5486 * process
5487@@ -238,7 +239,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
5488 vdso_base = get_unmapped_area(NULL, vdso_base,
5489 (vdso_pages << PAGE_SHIFT) +
5490 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
5491- 0, 0);
5492+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
5493 if (IS_ERR_VALUE(vdso_base)) {
5494 rc = vdso_base;
5495 goto fail_mmapsem;
5496diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
5497index 5eea6f3..5d10396 100644
5498--- a/arch/powerpc/lib/usercopy_64.c
5499+++ b/arch/powerpc/lib/usercopy_64.c
5500@@ -9,22 +9,6 @@
5501 #include <linux/module.h>
5502 #include <asm/uaccess.h>
5503
5504-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
5505-{
5506- if (likely(access_ok(VERIFY_READ, from, n)))
5507- n = __copy_from_user(to, from, n);
5508- else
5509- memset(to, 0, n);
5510- return n;
5511-}
5512-
5513-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
5514-{
5515- if (likely(access_ok(VERIFY_WRITE, to, n)))
5516- n = __copy_to_user(to, from, n);
5517- return n;
5518-}
5519-
5520 unsigned long copy_in_user(void __user *to, const void __user *from,
5521 unsigned long n)
5522 {
5523@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
5524 return n;
5525 }
5526
5527-EXPORT_SYMBOL(copy_from_user);
5528-EXPORT_SYMBOL(copy_to_user);
5529 EXPORT_SYMBOL(copy_in_user);
5530
5531diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
5532index 0a6b283..7674925 100644
5533--- a/arch/powerpc/mm/fault.c
5534+++ b/arch/powerpc/mm/fault.c
5535@@ -32,6 +32,10 @@
5536 #include <linux/perf_event.h>
5537 #include <linux/magic.h>
5538 #include <linux/ratelimit.h>
5539+#include <linux/slab.h>
5540+#include <linux/pagemap.h>
5541+#include <linux/compiler.h>
5542+#include <linux/unistd.h>
5543
5544 #include <asm/firmware.h>
5545 #include <asm/page.h>
5546@@ -68,6 +72,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
5547 }
5548 #endif
5549
5550+#ifdef CONFIG_PAX_PAGEEXEC
5551+/*
5552+ * PaX: decide what to do with offenders (regs->nip = fault address)
5553+ *
5554+ * returns 1 when task should be killed
5555+ */
5556+static int pax_handle_fetch_fault(struct pt_regs *regs)
5557+{
5558+ return 1;
5559+}
5560+
5561+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5562+{
5563+ unsigned long i;
5564+
5565+ printk(KERN_ERR "PAX: bytes at PC: ");
5566+ for (i = 0; i < 5; i++) {
5567+ unsigned int c;
5568+ if (get_user(c, (unsigned int __user *)pc+i))
5569+ printk(KERN_CONT "???????? ");
5570+ else
5571+ printk(KERN_CONT "%08x ", c);
5572+ }
5573+ printk("\n");
5574+}
5575+#endif
5576+
5577 /*
5578 * Check whether the instruction at regs->nip is a store using
5579 * an update addressing form which will update r1.
5580@@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
5581 * indicate errors in DSISR but can validly be set in SRR1.
5582 */
5583 if (trap == 0x400)
5584- error_code &= 0x48200000;
5585+ error_code &= 0x58200000;
5586 else
5587 is_write = error_code & DSISR_ISSTORE;
5588 #else
5589@@ -367,7 +398,7 @@ good_area:
5590 * "undefined". Of those that can be set, this is the only
5591 * one which seems bad.
5592 */
5593- if (error_code & 0x10000000)
5594+ if (error_code & DSISR_GUARDED)
5595 /* Guarded storage error. */
5596 goto bad_area;
5597 #endif /* CONFIG_8xx */
5598@@ -382,7 +413,7 @@ good_area:
5599 * processors use the same I/D cache coherency mechanism
5600 * as embedded.
5601 */
5602- if (error_code & DSISR_PROTFAULT)
5603+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
5604 goto bad_area;
5605 #endif /* CONFIG_PPC_STD_MMU */
5606
5607@@ -465,6 +496,23 @@ bad_area:
5608 bad_area_nosemaphore:
5609 /* User mode accesses cause a SIGSEGV */
5610 if (user_mode(regs)) {
5611+
5612+#ifdef CONFIG_PAX_PAGEEXEC
5613+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
5614+#ifdef CONFIG_PPC_STD_MMU
5615+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
5616+#else
5617+ if (is_exec && regs->nip == address) {
5618+#endif
5619+ switch (pax_handle_fetch_fault(regs)) {
5620+ }
5621+
5622+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
5623+ do_group_exit(SIGKILL);
5624+ }
5625+ }
5626+#endif
5627+
5628 _exception(SIGSEGV, regs, code, address);
5629 return 0;
5630 }
5631diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
5632index 67a42ed..c16ef80 100644
5633--- a/arch/powerpc/mm/mmap_64.c
5634+++ b/arch/powerpc/mm/mmap_64.c
5635@@ -57,6 +57,10 @@ static unsigned long mmap_rnd(void)
5636 {
5637 unsigned long rnd = 0;
5638
5639+#ifdef CONFIG_PAX_RANDMMAP
5640+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
5641+#endif
5642+
5643 if (current->flags & PF_RANDOMIZE) {
5644 /* 8MB for 32bit, 1GB for 64bit */
5645 if (is_32bit_task())
5646@@ -91,10 +95,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5647 */
5648 if (mmap_is_legacy()) {
5649 mm->mmap_base = TASK_UNMAPPED_BASE;
5650+
5651+#ifdef CONFIG_PAX_RANDMMAP
5652+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5653+ mm->mmap_base += mm->delta_mmap;
5654+#endif
5655+
5656 mm->get_unmapped_area = arch_get_unmapped_area;
5657 mm->unmap_area = arch_unmap_area;
5658 } else {
5659 mm->mmap_base = mmap_base();
5660+
5661+#ifdef CONFIG_PAX_RANDMMAP
5662+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5663+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5664+#endif
5665+
5666 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5667 mm->unmap_area = arch_unmap_area_topdown;
5668 }
5669diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
5670index 5829d2a..af84242 100644
5671--- a/arch/powerpc/mm/slice.c
5672+++ b/arch/powerpc/mm/slice.c
5673@@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
5674 if ((mm->task_size - len) < addr)
5675 return 0;
5676 vma = find_vma(mm, addr);
5677- return (!vma || (addr + len) <= vma->vm_start);
5678+ return check_heap_stack_gap(vma, addr, len, 0);
5679 }
5680
5681 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
5682@@ -272,7 +272,7 @@ full_search:
5683 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
5684 continue;
5685 }
5686- if (!vma || addr + len <= vma->vm_start) {
5687+ if (check_heap_stack_gap(vma, addr, len, 0)) {
5688 /*
5689 * Remember the place where we stopped the search:
5690 */
5691@@ -329,10 +329,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
5692 }
5693 }
5694
5695- addr = mm->mmap_base;
5696- while (addr > len) {
5697+ if (mm->mmap_base < len)
5698+ addr = -ENOMEM;
5699+ else
5700+ addr = mm->mmap_base - len;
5701+
5702+ while (!IS_ERR_VALUE(addr)) {
5703 /* Go down by chunk size */
5704- addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
5705+ addr = _ALIGN_DOWN(addr, 1ul << pshift);
5706
5707 /* Check for hit with different page size */
5708 mask = slice_range_to_mask(addr, len);
5709@@ -352,7 +356,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
5710 * return with success:
5711 */
5712 vma = find_vma(mm, addr);
5713- if (!vma || (addr + len) <= vma->vm_start) {
5714+ if (check_heap_stack_gap(vma, addr, len, 0)) {
5715 /* remember the address as a hint for next time */
5716 if (use_cache)
5717 mm->free_area_cache = addr;
5718@@ -364,7 +368,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
5719 mm->cached_hole_size = vma->vm_start - addr;
5720
5721 /* try just below the current vma->vm_start */
5722- addr = vma->vm_start;
5723+ addr = skip_heap_stack_gap(vma, len, 0);
5724 }
5725
5726 /*
5727@@ -442,6 +446,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
5728 if (fixed && addr > (mm->task_size - len))
5729 return -EINVAL;
5730
5731+#ifdef CONFIG_PAX_RANDMMAP
5732+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
5733+ addr = 0;
5734+#endif
5735+
5736 /* If hint, make sure it matches our alignment restrictions */
5737 if (!fixed && addr) {
5738 addr = _ALIGN_UP(addr, 1ul << pshift);
5739diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
5740index c797832..ce575c8 100644
5741--- a/arch/s390/include/asm/atomic.h
5742+++ b/arch/s390/include/asm/atomic.h
5743@@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
5744 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
5745 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5746
5747+#define atomic64_read_unchecked(v) atomic64_read(v)
5748+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5749+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5750+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5751+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5752+#define atomic64_inc_unchecked(v) atomic64_inc(v)
5753+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5754+#define atomic64_dec_unchecked(v) atomic64_dec(v)
5755+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5756+
5757 #define smp_mb__before_atomic_dec() smp_mb()
5758 #define smp_mb__after_atomic_dec() smp_mb()
5759 #define smp_mb__before_atomic_inc() smp_mb()
5760diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
5761index 4d7ccac..d03d0ad 100644
5762--- a/arch/s390/include/asm/cache.h
5763+++ b/arch/s390/include/asm/cache.h
5764@@ -9,8 +9,10 @@
5765 #ifndef __ARCH_S390_CACHE_H
5766 #define __ARCH_S390_CACHE_H
5767
5768-#define L1_CACHE_BYTES 256
5769+#include <linux/const.h>
5770+
5771 #define L1_CACHE_SHIFT 8
5772+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5773 #define NET_SKB_PAD 32
5774
5775 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
5776diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
5777index 178ff96..8c93bd1 100644
5778--- a/arch/s390/include/asm/elf.h
5779+++ b/arch/s390/include/asm/elf.h
5780@@ -160,8 +160,14 @@ extern unsigned int vdso_enabled;
5781 the loader. We need to make sure that it is out of the way of the program
5782 that it will "exec", and that there is sufficient room for the brk. */
5783
5784-extern unsigned long randomize_et_dyn(unsigned long base);
5785-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
5786+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
5787+
5788+#ifdef CONFIG_PAX_ASLR
5789+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
5790+
5791+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
5792+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
5793+#endif
5794
5795 /* This yields a mask that user programs can use to figure out what
5796 instruction set this CPU supports. */
5797@@ -210,9 +216,6 @@ struct linux_binprm;
5798 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
5799 int arch_setup_additional_pages(struct linux_binprm *, int);
5800
5801-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
5802-#define arch_randomize_brk arch_randomize_brk
5803-
5804 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
5805
5806 #endif
5807diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
5808index c4a93d6..4d2a9b4 100644
5809--- a/arch/s390/include/asm/exec.h
5810+++ b/arch/s390/include/asm/exec.h
5811@@ -7,6 +7,6 @@
5812 #ifndef __ASM_EXEC_H
5813 #define __ASM_EXEC_H
5814
5815-extern unsigned long arch_align_stack(unsigned long sp);
5816+#define arch_align_stack(x) ((x) & ~0xfUL)
5817
5818 #endif /* __ASM_EXEC_H */
5819diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
5820index 34268df..ea97318 100644
5821--- a/arch/s390/include/asm/uaccess.h
5822+++ b/arch/s390/include/asm/uaccess.h
5823@@ -252,6 +252,10 @@ static inline unsigned long __must_check
5824 copy_to_user(void __user *to, const void *from, unsigned long n)
5825 {
5826 might_fault();
5827+
5828+ if ((long)n < 0)
5829+ return n;
5830+
5831 if (access_ok(VERIFY_WRITE, to, n))
5832 n = __copy_to_user(to, from, n);
5833 return n;
5834@@ -277,6 +281,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
5835 static inline unsigned long __must_check
5836 __copy_from_user(void *to, const void __user *from, unsigned long n)
5837 {
5838+ if ((long)n < 0)
5839+ return n;
5840+
5841 if (__builtin_constant_p(n) && (n <= 256))
5842 return uaccess.copy_from_user_small(n, from, to);
5843 else
5844@@ -308,10 +315,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
5845 static inline unsigned long __must_check
5846 copy_from_user(void *to, const void __user *from, unsigned long n)
5847 {
5848- unsigned int sz = __compiletime_object_size(to);
5849+ size_t sz = __compiletime_object_size(to);
5850
5851 might_fault();
5852- if (unlikely(sz != -1 && sz < n)) {
5853+
5854+ if ((long)n < 0)
5855+ return n;
5856+
5857+ if (unlikely(sz != (size_t)-1 && sz < n)) {
5858 copy_from_user_overflow();
5859 return n;
5860 }
5861diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
5862index 4610dea..cf0af21 100644
5863--- a/arch/s390/kernel/module.c
5864+++ b/arch/s390/kernel/module.c
5865@@ -171,11 +171,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
5866
5867 /* Increase core size by size of got & plt and set start
5868 offsets for got and plt. */
5869- me->core_size = ALIGN(me->core_size, 4);
5870- me->arch.got_offset = me->core_size;
5871- me->core_size += me->arch.got_size;
5872- me->arch.plt_offset = me->core_size;
5873- me->core_size += me->arch.plt_size;
5874+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
5875+ me->arch.got_offset = me->core_size_rw;
5876+ me->core_size_rw += me->arch.got_size;
5877+ me->arch.plt_offset = me->core_size_rx;
5878+ me->core_size_rx += me->arch.plt_size;
5879 return 0;
5880 }
5881
5882@@ -252,7 +252,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
5883 if (info->got_initialized == 0) {
5884 Elf_Addr *gotent;
5885
5886- gotent = me->module_core + me->arch.got_offset +
5887+ gotent = me->module_core_rw + me->arch.got_offset +
5888 info->got_offset;
5889 *gotent = val;
5890 info->got_initialized = 1;
5891@@ -276,7 +276,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
5892 else if (r_type == R_390_GOTENT ||
5893 r_type == R_390_GOTPLTENT)
5894 *(unsigned int *) loc =
5895- (val + (Elf_Addr) me->module_core - loc) >> 1;
5896+ (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
5897 else if (r_type == R_390_GOT64 ||
5898 r_type == R_390_GOTPLT64)
5899 *(unsigned long *) loc = val;
5900@@ -290,7 +290,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
5901 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
5902 if (info->plt_initialized == 0) {
5903 unsigned int *ip;
5904- ip = me->module_core + me->arch.plt_offset +
5905+ ip = me->module_core_rx + me->arch.plt_offset +
5906 info->plt_offset;
5907 #ifndef CONFIG_64BIT
5908 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
5909@@ -315,7 +315,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
5910 val - loc + 0xffffUL < 0x1ffffeUL) ||
5911 (r_type == R_390_PLT32DBL &&
5912 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
5913- val = (Elf_Addr) me->module_core +
5914+ val = (Elf_Addr) me->module_core_rx +
5915 me->arch.plt_offset +
5916 info->plt_offset;
5917 val += rela->r_addend - loc;
5918@@ -337,7 +337,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
5919 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
5920 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
5921 val = val + rela->r_addend -
5922- ((Elf_Addr) me->module_core + me->arch.got_offset);
5923+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
5924 if (r_type == R_390_GOTOFF16)
5925 *(unsigned short *) loc = val;
5926 else if (r_type == R_390_GOTOFF32)
5927@@ -347,7 +347,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
5928 break;
5929 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
5930 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
5931- val = (Elf_Addr) me->module_core + me->arch.got_offset +
5932+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
5933 rela->r_addend - loc;
5934 if (r_type == R_390_GOTPC)
5935 *(unsigned int *) loc = val;
5936diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
5937index cd31ad4..201c5a3 100644
5938--- a/arch/s390/kernel/process.c
5939+++ b/arch/s390/kernel/process.c
5940@@ -283,39 +283,3 @@ unsigned long get_wchan(struct task_struct *p)
5941 }
5942 return 0;
5943 }
5944-
5945-unsigned long arch_align_stack(unsigned long sp)
5946-{
5947- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
5948- sp -= get_random_int() & ~PAGE_MASK;
5949- return sp & ~0xf;
5950-}
5951-
5952-static inline unsigned long brk_rnd(void)
5953-{
5954- /* 8MB for 32bit, 1GB for 64bit */
5955- if (is_32bit_task())
5956- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
5957- else
5958- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
5959-}
5960-
5961-unsigned long arch_randomize_brk(struct mm_struct *mm)
5962-{
5963- unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
5964-
5965- if (ret < mm->brk)
5966- return mm->brk;
5967- return ret;
5968-}
5969-
5970-unsigned long randomize_et_dyn(unsigned long base)
5971-{
5972- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
5973-
5974- if (!(current->flags & PF_RANDOMIZE))
5975- return base;
5976- if (ret < base)
5977- return base;
5978- return ret;
5979-}
5980diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
5981index c59a5ef..3fae59c 100644
5982--- a/arch/s390/mm/mmap.c
5983+++ b/arch/s390/mm/mmap.c
5984@@ -90,10 +90,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5985 */
5986 if (mmap_is_legacy()) {
5987 mm->mmap_base = TASK_UNMAPPED_BASE;
5988+
5989+#ifdef CONFIG_PAX_RANDMMAP
5990+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5991+ mm->mmap_base += mm->delta_mmap;
5992+#endif
5993+
5994 mm->get_unmapped_area = arch_get_unmapped_area;
5995 mm->unmap_area = arch_unmap_area;
5996 } else {
5997 mm->mmap_base = mmap_base();
5998+
5999+#ifdef CONFIG_PAX_RANDMMAP
6000+ if (mm->pax_flags & MF_PAX_RANDMMAP)
6001+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
6002+#endif
6003+
6004 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
6005 mm->unmap_area = arch_unmap_area_topdown;
6006 }
6007@@ -172,10 +184,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6008 */
6009 if (mmap_is_legacy()) {
6010 mm->mmap_base = TASK_UNMAPPED_BASE;
6011+
6012+#ifdef CONFIG_PAX_RANDMMAP
6013+ if (mm->pax_flags & MF_PAX_RANDMMAP)
6014+ mm->mmap_base += mm->delta_mmap;
6015+#endif
6016+
6017 mm->get_unmapped_area = s390_get_unmapped_area;
6018 mm->unmap_area = arch_unmap_area;
6019 } else {
6020 mm->mmap_base = mmap_base();
6021+
6022+#ifdef CONFIG_PAX_RANDMMAP
6023+ if (mm->pax_flags & MF_PAX_RANDMMAP)
6024+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
6025+#endif
6026+
6027 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
6028 mm->unmap_area = arch_unmap_area_topdown;
6029 }
6030diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
6031index ae3d59f..f65f075 100644
6032--- a/arch/score/include/asm/cache.h
6033+++ b/arch/score/include/asm/cache.h
6034@@ -1,7 +1,9 @@
6035 #ifndef _ASM_SCORE_CACHE_H
6036 #define _ASM_SCORE_CACHE_H
6037
6038+#include <linux/const.h>
6039+
6040 #define L1_CACHE_SHIFT 4
6041-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6042+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6043
6044 #endif /* _ASM_SCORE_CACHE_H */
6045diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
6046index f9f3cd5..58ff438 100644
6047--- a/arch/score/include/asm/exec.h
6048+++ b/arch/score/include/asm/exec.h
6049@@ -1,6 +1,6 @@
6050 #ifndef _ASM_SCORE_EXEC_H
6051 #define _ASM_SCORE_EXEC_H
6052
6053-extern unsigned long arch_align_stack(unsigned long sp);
6054+#define arch_align_stack(x) (x)
6055
6056 #endif /* _ASM_SCORE_EXEC_H */
6057diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
6058index 637970c..0b6556b 100644
6059--- a/arch/score/kernel/process.c
6060+++ b/arch/score/kernel/process.c
6061@@ -161,8 +161,3 @@ unsigned long get_wchan(struct task_struct *task)
6062
6063 return task_pt_regs(task)->cp0_epc;
6064 }
6065-
6066-unsigned long arch_align_stack(unsigned long sp)
6067-{
6068- return sp;
6069-}
6070diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
6071index ef9e555..331bd29 100644
6072--- a/arch/sh/include/asm/cache.h
6073+++ b/arch/sh/include/asm/cache.h
6074@@ -9,10 +9,11 @@
6075 #define __ASM_SH_CACHE_H
6076 #ifdef __KERNEL__
6077
6078+#include <linux/const.h>
6079 #include <linux/init.h>
6080 #include <cpu/cache.h>
6081
6082-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6083+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6084
6085 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
6086
6087diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
6088index afeb710..e8366ef 100644
6089--- a/arch/sh/mm/mmap.c
6090+++ b/arch/sh/mm/mmap.c
6091@@ -49,6 +49,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
6092 struct vm_area_struct *vma;
6093 unsigned long start_addr;
6094 int do_colour_align;
6095+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
6096
6097 if (flags & MAP_FIXED) {
6098 /* We do not accept a shared mapping if it would violate
6099@@ -74,8 +75,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
6100 addr = PAGE_ALIGN(addr);
6101
6102 vma = find_vma(mm, addr);
6103- if (TASK_SIZE - len >= addr &&
6104- (!vma || addr + len <= vma->vm_start))
6105+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
6106 return addr;
6107 }
6108
6109@@ -106,7 +106,7 @@ full_search:
6110 }
6111 return -ENOMEM;
6112 }
6113- if (likely(!vma || addr + len <= vma->vm_start)) {
6114+ if (likely(check_heap_stack_gap(vma, addr, len, offset))) {
6115 /*
6116 * Remember the place where we stopped the search:
6117 */
6118@@ -131,6 +131,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6119 struct mm_struct *mm = current->mm;
6120 unsigned long addr = addr0;
6121 int do_colour_align;
6122+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
6123
6124 if (flags & MAP_FIXED) {
6125 /* We do not accept a shared mapping if it would violate
6126@@ -157,8 +158,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6127 addr = PAGE_ALIGN(addr);
6128
6129 vma = find_vma(mm, addr);
6130- if (TASK_SIZE - len >= addr &&
6131- (!vma || addr + len <= vma->vm_start))
6132+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
6133 return addr;
6134 }
6135
6136@@ -179,7 +179,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6137 /* make sure it can fit in the remaining address space */
6138 if (likely(addr > len)) {
6139 vma = find_vma(mm, addr-len);
6140- if (!vma || addr <= vma->vm_start) {
6141+ if (check_heap_stack_gap(vma, addr - len, len, offset)) {
6142 /* remember the address as a hint for next time */
6143 return (mm->free_area_cache = addr-len);
6144 }
6145@@ -188,18 +188,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6146 if (unlikely(mm->mmap_base < len))
6147 goto bottomup;
6148
6149- addr = mm->mmap_base-len;
6150- if (do_colour_align)
6151- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
6152+ addr = mm->mmap_base - len;
6153
6154 do {
6155+ if (do_colour_align)
6156+ addr = COLOUR_ALIGN_DOWN(addr, pgoff);
6157 /*
6158 * Lookup failure means no vma is above this address,
6159 * else if new region fits below vma->vm_start,
6160 * return with success:
6161 */
6162 vma = find_vma(mm, addr);
6163- if (likely(!vma || addr+len <= vma->vm_start)) {
6164+ if (likely(check_heap_stack_gap(vma, addr, len, offset))) {
6165 /* remember the address as a hint for next time */
6166 return (mm->free_area_cache = addr);
6167 }
6168@@ -209,10 +209,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6169 mm->cached_hole_size = vma->vm_start - addr;
6170
6171 /* try just below the current vma->vm_start */
6172- addr = vma->vm_start-len;
6173- if (do_colour_align)
6174- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
6175- } while (likely(len < vma->vm_start));
6176+ addr = skip_heap_stack_gap(vma, len, offset);
6177+ } while (!IS_ERR_VALUE(addr));
6178
6179 bottomup:
6180 /*
6181diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
6182index be56a24..443328f 100644
6183--- a/arch/sparc/include/asm/atomic_64.h
6184+++ b/arch/sparc/include/asm/atomic_64.h
6185@@ -14,18 +14,40 @@
6186 #define ATOMIC64_INIT(i) { (i) }
6187
6188 #define atomic_read(v) (*(volatile int *)&(v)->counter)
6189+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
6190+{
6191+ return v->counter;
6192+}
6193 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
6194+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
6195+{
6196+ return v->counter;
6197+}
6198
6199 #define atomic_set(v, i) (((v)->counter) = i)
6200+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
6201+{
6202+ v->counter = i;
6203+}
6204 #define atomic64_set(v, i) (((v)->counter) = i)
6205+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
6206+{
6207+ v->counter = i;
6208+}
6209
6210 extern void atomic_add(int, atomic_t *);
6211+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
6212 extern void atomic64_add(long, atomic64_t *);
6213+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
6214 extern void atomic_sub(int, atomic_t *);
6215+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
6216 extern void atomic64_sub(long, atomic64_t *);
6217+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
6218
6219 extern int atomic_add_ret(int, atomic_t *);
6220+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
6221 extern long atomic64_add_ret(long, atomic64_t *);
6222+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
6223 extern int atomic_sub_ret(int, atomic_t *);
6224 extern long atomic64_sub_ret(long, atomic64_t *);
6225
6226@@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
6227 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
6228
6229 #define atomic_inc_return(v) atomic_add_ret(1, v)
6230+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
6231+{
6232+ return atomic_add_ret_unchecked(1, v);
6233+}
6234 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
6235+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
6236+{
6237+ return atomic64_add_ret_unchecked(1, v);
6238+}
6239
6240 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
6241 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
6242
6243 #define atomic_add_return(i, v) atomic_add_ret(i, v)
6244+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
6245+{
6246+ return atomic_add_ret_unchecked(i, v);
6247+}
6248 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
6249+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
6250+{
6251+ return atomic64_add_ret_unchecked(i, v);
6252+}
6253
6254 /*
6255 * atomic_inc_and_test - increment and test
6256@@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
6257 * other cases.
6258 */
6259 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
6260+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
6261+{
6262+ return atomic_inc_return_unchecked(v) == 0;
6263+}
6264 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
6265
6266 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
6267@@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
6268 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
6269
6270 #define atomic_inc(v) atomic_add(1, v)
6271+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
6272+{
6273+ atomic_add_unchecked(1, v);
6274+}
6275 #define atomic64_inc(v) atomic64_add(1, v)
6276+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
6277+{
6278+ atomic64_add_unchecked(1, v);
6279+}
6280
6281 #define atomic_dec(v) atomic_sub(1, v)
6282+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
6283+{
6284+ atomic_sub_unchecked(1, v);
6285+}
6286 #define atomic64_dec(v) atomic64_sub(1, v)
6287+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
6288+{
6289+ atomic64_sub_unchecked(1, v);
6290+}
6291
6292 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
6293 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
6294
6295 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
6296+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
6297+{
6298+ return cmpxchg(&v->counter, old, new);
6299+}
6300 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
6301+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
6302+{
6303+ return xchg(&v->counter, new);
6304+}
6305
6306 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
6307 {
6308- int c, old;
6309+ int c, old, new;
6310 c = atomic_read(v);
6311 for (;;) {
6312- if (unlikely(c == (u)))
6313+ if (unlikely(c == u))
6314 break;
6315- old = atomic_cmpxchg((v), c, c + (a));
6316+
6317+ asm volatile("addcc %2, %0, %0\n"
6318+
6319+#ifdef CONFIG_PAX_REFCOUNT
6320+ "tvs %%icc, 6\n"
6321+#endif
6322+
6323+ : "=r" (new)
6324+ : "0" (c), "ir" (a)
6325+ : "cc");
6326+
6327+ old = atomic_cmpxchg(v, c, new);
6328 if (likely(old == c))
6329 break;
6330 c = old;
6331@@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
6332 #define atomic64_cmpxchg(v, o, n) \
6333 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
6334 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
6335+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
6336+{
6337+ return xchg(&v->counter, new);
6338+}
6339
6340 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
6341 {
6342- long c, old;
6343+ long c, old, new;
6344 c = atomic64_read(v);
6345 for (;;) {
6346- if (unlikely(c == (u)))
6347+ if (unlikely(c == u))
6348 break;
6349- old = atomic64_cmpxchg((v), c, c + (a));
6350+
6351+ asm volatile("addcc %2, %0, %0\n"
6352+
6353+#ifdef CONFIG_PAX_REFCOUNT
6354+ "tvs %%xcc, 6\n"
6355+#endif
6356+
6357+ : "=r" (new)
6358+ : "0" (c), "ir" (a)
6359+ : "cc");
6360+
6361+ old = atomic64_cmpxchg(v, c, new);
6362 if (likely(old == c))
6363 break;
6364 c = old;
6365 }
6366- return c != (u);
6367+ return c != u;
6368 }
6369
6370 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
6371diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
6372index 5bb6991..5c2132e 100644
6373--- a/arch/sparc/include/asm/cache.h
6374+++ b/arch/sparc/include/asm/cache.h
6375@@ -7,10 +7,12 @@
6376 #ifndef _SPARC_CACHE_H
6377 #define _SPARC_CACHE_H
6378
6379+#include <linux/const.h>
6380+
6381 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
6382
6383 #define L1_CACHE_SHIFT 5
6384-#define L1_CACHE_BYTES 32
6385+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6386
6387 #ifdef CONFIG_SPARC32
6388 #define SMP_CACHE_BYTES_SHIFT 5
6389diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
6390index ac74a2c..a9e58af 100644
6391--- a/arch/sparc/include/asm/elf_32.h
6392+++ b/arch/sparc/include/asm/elf_32.h
6393@@ -114,6 +114,13 @@ typedef struct {
6394
6395 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
6396
6397+#ifdef CONFIG_PAX_ASLR
6398+#define PAX_ELF_ET_DYN_BASE 0x10000UL
6399+
6400+#define PAX_DELTA_MMAP_LEN 16
6401+#define PAX_DELTA_STACK_LEN 16
6402+#endif
6403+
6404 /* This yields a mask that user programs can use to figure out what
6405 instruction set this cpu supports. This can NOT be done in userspace
6406 on Sparc. */
6407diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
6408index 370ca1e..d4f4a98 100644
6409--- a/arch/sparc/include/asm/elf_64.h
6410+++ b/arch/sparc/include/asm/elf_64.h
6411@@ -189,6 +189,13 @@ typedef struct {
6412 #define ELF_ET_DYN_BASE 0x0000010000000000UL
6413 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
6414
6415+#ifdef CONFIG_PAX_ASLR
6416+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
6417+
6418+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
6419+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
6420+#endif
6421+
6422 extern unsigned long sparc64_elf_hwcap;
6423 #define ELF_HWCAP sparc64_elf_hwcap
6424
6425diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
6426index 9b1c36d..209298b 100644
6427--- a/arch/sparc/include/asm/pgalloc_32.h
6428+++ b/arch/sparc/include/asm/pgalloc_32.h
6429@@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
6430 }
6431
6432 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
6433+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
6434
6435 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
6436 unsigned long address)
6437diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
6438index bcfe063..b333142 100644
6439--- a/arch/sparc/include/asm/pgalloc_64.h
6440+++ b/arch/sparc/include/asm/pgalloc_64.h
6441@@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
6442 }
6443
6444 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
6445+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
6446
6447 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
6448 {
6449diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
6450index 6fc1348..390c50a 100644
6451--- a/arch/sparc/include/asm/pgtable_32.h
6452+++ b/arch/sparc/include/asm/pgtable_32.h
6453@@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
6454 #define PAGE_SHARED SRMMU_PAGE_SHARED
6455 #define PAGE_COPY SRMMU_PAGE_COPY
6456 #define PAGE_READONLY SRMMU_PAGE_RDONLY
6457+#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
6458+#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
6459+#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
6460 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
6461
6462 /* Top-level page directory - dummy used by init-mm.
6463@@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
6464
6465 /* xwr */
6466 #define __P000 PAGE_NONE
6467-#define __P001 PAGE_READONLY
6468-#define __P010 PAGE_COPY
6469-#define __P011 PAGE_COPY
6470+#define __P001 PAGE_READONLY_NOEXEC
6471+#define __P010 PAGE_COPY_NOEXEC
6472+#define __P011 PAGE_COPY_NOEXEC
6473 #define __P100 PAGE_READONLY
6474 #define __P101 PAGE_READONLY
6475 #define __P110 PAGE_COPY
6476 #define __P111 PAGE_COPY
6477
6478 #define __S000 PAGE_NONE
6479-#define __S001 PAGE_READONLY
6480-#define __S010 PAGE_SHARED
6481-#define __S011 PAGE_SHARED
6482+#define __S001 PAGE_READONLY_NOEXEC
6483+#define __S010 PAGE_SHARED_NOEXEC
6484+#define __S011 PAGE_SHARED_NOEXEC
6485 #define __S100 PAGE_READONLY
6486 #define __S101 PAGE_READONLY
6487 #define __S110 PAGE_SHARED
6488diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
6489index 79da178..c2eede8 100644
6490--- a/arch/sparc/include/asm/pgtsrmmu.h
6491+++ b/arch/sparc/include/asm/pgtsrmmu.h
6492@@ -115,6 +115,11 @@
6493 SRMMU_EXEC | SRMMU_REF)
6494 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
6495 SRMMU_EXEC | SRMMU_REF)
6496+
6497+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
6498+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
6499+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
6500+
6501 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
6502 SRMMU_DIRTY | SRMMU_REF)
6503
6504diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
6505index 9689176..63c18ea 100644
6506--- a/arch/sparc/include/asm/spinlock_64.h
6507+++ b/arch/sparc/include/asm/spinlock_64.h
6508@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
6509
6510 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
6511
6512-static void inline arch_read_lock(arch_rwlock_t *lock)
6513+static inline void arch_read_lock(arch_rwlock_t *lock)
6514 {
6515 unsigned long tmp1, tmp2;
6516
6517 __asm__ __volatile__ (
6518 "1: ldsw [%2], %0\n"
6519 " brlz,pn %0, 2f\n"
6520-"4: add %0, 1, %1\n"
6521+"4: addcc %0, 1, %1\n"
6522+
6523+#ifdef CONFIG_PAX_REFCOUNT
6524+" tvs %%icc, 6\n"
6525+#endif
6526+
6527 " cas [%2], %0, %1\n"
6528 " cmp %0, %1\n"
6529 " bne,pn %%icc, 1b\n"
6530@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
6531 " .previous"
6532 : "=&r" (tmp1), "=&r" (tmp2)
6533 : "r" (lock)
6534- : "memory");
6535+ : "memory", "cc");
6536 }
6537
6538-static int inline arch_read_trylock(arch_rwlock_t *lock)
6539+static inline int arch_read_trylock(arch_rwlock_t *lock)
6540 {
6541 int tmp1, tmp2;
6542
6543@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
6544 "1: ldsw [%2], %0\n"
6545 " brlz,a,pn %0, 2f\n"
6546 " mov 0, %0\n"
6547-" add %0, 1, %1\n"
6548+" addcc %0, 1, %1\n"
6549+
6550+#ifdef CONFIG_PAX_REFCOUNT
6551+" tvs %%icc, 6\n"
6552+#endif
6553+
6554 " cas [%2], %0, %1\n"
6555 " cmp %0, %1\n"
6556 " bne,pn %%icc, 1b\n"
6557@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
6558 return tmp1;
6559 }
6560
6561-static void inline arch_read_unlock(arch_rwlock_t *lock)
6562+static inline void arch_read_unlock(arch_rwlock_t *lock)
6563 {
6564 unsigned long tmp1, tmp2;
6565
6566 __asm__ __volatile__(
6567 "1: lduw [%2], %0\n"
6568-" sub %0, 1, %1\n"
6569+" subcc %0, 1, %1\n"
6570+
6571+#ifdef CONFIG_PAX_REFCOUNT
6572+" tvs %%icc, 6\n"
6573+#endif
6574+
6575 " cas [%2], %0, %1\n"
6576 " cmp %0, %1\n"
6577 " bne,pn %%xcc, 1b\n"
6578@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
6579 : "memory");
6580 }
6581
6582-static void inline arch_write_lock(arch_rwlock_t *lock)
6583+static inline void arch_write_lock(arch_rwlock_t *lock)
6584 {
6585 unsigned long mask, tmp1, tmp2;
6586
6587@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
6588 : "memory");
6589 }
6590
6591-static void inline arch_write_unlock(arch_rwlock_t *lock)
6592+static inline void arch_write_unlock(arch_rwlock_t *lock)
6593 {
6594 __asm__ __volatile__(
6595 " stw %%g0, [%0]"
6596@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
6597 : "memory");
6598 }
6599
6600-static int inline arch_write_trylock(arch_rwlock_t *lock)
6601+static inline int arch_write_trylock(arch_rwlock_t *lock)
6602 {
6603 unsigned long mask, tmp1, tmp2, result;
6604
6605diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
6606index 25849ae..924c54b 100644
6607--- a/arch/sparc/include/asm/thread_info_32.h
6608+++ b/arch/sparc/include/asm/thread_info_32.h
6609@@ -49,6 +49,8 @@ struct thread_info {
6610 unsigned long w_saved;
6611
6612 struct restart_block restart_block;
6613+
6614+ unsigned long lowest_stack;
6615 };
6616
6617 /*
6618diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
6619index a3fe4dc..cae132a 100644
6620--- a/arch/sparc/include/asm/thread_info_64.h
6621+++ b/arch/sparc/include/asm/thread_info_64.h
6622@@ -63,6 +63,8 @@ struct thread_info {
6623 struct pt_regs *kern_una_regs;
6624 unsigned int kern_una_insn;
6625
6626+ unsigned long lowest_stack;
6627+
6628 unsigned long fpregs[0] __attribute__ ((aligned(64)));
6629 };
6630
6631@@ -193,10 +195,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
6632 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
6633 /* flag bit 6 is available */
6634 #define TIF_32BIT 7 /* 32-bit binary */
6635-/* flag bit 8 is available */
6636+#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
6637 #define TIF_SECCOMP 9 /* secure computing */
6638 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
6639 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
6640+
6641 /* NOTE: Thread flags >= 12 should be ones we have no interest
6642 * in using in assembly, else we can't use the mask as
6643 * an immediate value in instructions such as andcc.
6644@@ -215,12 +218,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
6645 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
6646 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6647 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
6648+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6649
6650 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
6651 _TIF_DO_NOTIFY_RESUME_MASK | \
6652 _TIF_NEED_RESCHED)
6653 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
6654
6655+#define _TIF_WORK_SYSCALL \
6656+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
6657+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6658+
6659+
6660 /*
6661 * Thread-synchronous status.
6662 *
6663diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
6664index 0167d26..9acd8ed 100644
6665--- a/arch/sparc/include/asm/uaccess.h
6666+++ b/arch/sparc/include/asm/uaccess.h
6667@@ -1,5 +1,13 @@
6668 #ifndef ___ASM_SPARC_UACCESS_H
6669 #define ___ASM_SPARC_UACCESS_H
6670+
6671+#ifdef __KERNEL__
6672+#ifndef __ASSEMBLY__
6673+#include <linux/types.h>
6674+extern void check_object_size(const void *ptr, unsigned long n, bool to);
6675+#endif
6676+#endif
6677+
6678 #if defined(__sparc__) && defined(__arch64__)
6679 #include <asm/uaccess_64.h>
6680 #else
6681diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
6682index 53a28dd..50c38c3 100644
6683--- a/arch/sparc/include/asm/uaccess_32.h
6684+++ b/arch/sparc/include/asm/uaccess_32.h
6685@@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
6686
6687 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
6688 {
6689- if (n && __access_ok((unsigned long) to, n))
6690+ if ((long)n < 0)
6691+ return n;
6692+
6693+ if (n && __access_ok((unsigned long) to, n)) {
6694+ if (!__builtin_constant_p(n))
6695+ check_object_size(from, n, true);
6696 return __copy_user(to, (__force void __user *) from, n);
6697- else
6698+ } else
6699 return n;
6700 }
6701
6702 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
6703 {
6704+ if ((long)n < 0)
6705+ return n;
6706+
6707+ if (!__builtin_constant_p(n))
6708+ check_object_size(from, n, true);
6709+
6710 return __copy_user(to, (__force void __user *) from, n);
6711 }
6712
6713 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
6714 {
6715- if (n && __access_ok((unsigned long) from, n))
6716+ if ((long)n < 0)
6717+ return n;
6718+
6719+ if (n && __access_ok((unsigned long) from, n)) {
6720+ if (!__builtin_constant_p(n))
6721+ check_object_size(to, n, false);
6722 return __copy_user((__force void __user *) to, from, n);
6723- else
6724+ } else
6725 return n;
6726 }
6727
6728 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
6729 {
6730+ if ((long)n < 0)
6731+ return n;
6732+
6733 return __copy_user((__force void __user *) to, from, n);
6734 }
6735
6736diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
6737index 73083e1..2bc62a6 100644
6738--- a/arch/sparc/include/asm/uaccess_64.h
6739+++ b/arch/sparc/include/asm/uaccess_64.h
6740@@ -10,6 +10,7 @@
6741 #include <linux/compiler.h>
6742 #include <linux/string.h>
6743 #include <linux/thread_info.h>
6744+#include <linux/kernel.h>
6745 #include <asm/asi.h>
6746 #include <asm/spitfire.h>
6747 #include <asm-generic/uaccess-unaligned.h>
6748@@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
6749 static inline unsigned long __must_check
6750 copy_from_user(void *to, const void __user *from, unsigned long size)
6751 {
6752- unsigned long ret = ___copy_from_user(to, from, size);
6753+ unsigned long ret;
6754
6755+ if ((long)size < 0 || size > INT_MAX)
6756+ return size;
6757+
6758+ if (!__builtin_constant_p(size))
6759+ check_object_size(to, size, false);
6760+
6761+ ret = ___copy_from_user(to, from, size);
6762 if (unlikely(ret))
6763 ret = copy_from_user_fixup(to, from, size);
6764
6765@@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
6766 static inline unsigned long __must_check
6767 copy_to_user(void __user *to, const void *from, unsigned long size)
6768 {
6769- unsigned long ret = ___copy_to_user(to, from, size);
6770+ unsigned long ret;
6771
6772+ if ((long)size < 0 || size > INT_MAX)
6773+ return size;
6774+
6775+ if (!__builtin_constant_p(size))
6776+ check_object_size(from, size, true);
6777+
6778+ ret = ___copy_to_user(to, from, size);
6779 if (unlikely(ret))
6780 ret = copy_to_user_fixup(to, from, size);
6781 return ret;
6782diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
6783index 6cf591b..b49e65a 100644
6784--- a/arch/sparc/kernel/Makefile
6785+++ b/arch/sparc/kernel/Makefile
6786@@ -3,7 +3,7 @@
6787 #
6788
6789 asflags-y := -ansi
6790-ccflags-y := -Werror
6791+#ccflags-y := -Werror
6792
6793 extra-y := head_$(BITS).o
6794
6795diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
6796index 487bffb..955a925 100644
6797--- a/arch/sparc/kernel/process_32.c
6798+++ b/arch/sparc/kernel/process_32.c
6799@@ -126,14 +126,14 @@ void show_regs(struct pt_regs *r)
6800
6801 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
6802 r->psr, r->pc, r->npc, r->y, print_tainted());
6803- printk("PC: <%pS>\n", (void *) r->pc);
6804+ printk("PC: <%pA>\n", (void *) r->pc);
6805 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
6806 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
6807 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
6808 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
6809 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
6810 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
6811- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
6812+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
6813
6814 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
6815 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
6816@@ -168,7 +168,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
6817 rw = (struct reg_window32 *) fp;
6818 pc = rw->ins[7];
6819 printk("[%08lx : ", pc);
6820- printk("%pS ] ", (void *) pc);
6821+ printk("%pA ] ", (void *) pc);
6822 fp = rw->ins[6];
6823 } while (++count < 16);
6824 printk("\n");
6825diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
6826index c6e0c29..052832b 100644
6827--- a/arch/sparc/kernel/process_64.c
6828+++ b/arch/sparc/kernel/process_64.c
6829@@ -181,14 +181,14 @@ static void show_regwindow(struct pt_regs *regs)
6830 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
6831 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
6832 if (regs->tstate & TSTATE_PRIV)
6833- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
6834+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
6835 }
6836
6837 void show_regs(struct pt_regs *regs)
6838 {
6839 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
6840 regs->tpc, regs->tnpc, regs->y, print_tainted());
6841- printk("TPC: <%pS>\n", (void *) regs->tpc);
6842+ printk("TPC: <%pA>\n", (void *) regs->tpc);
6843 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
6844 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
6845 regs->u_regs[3]);
6846@@ -201,7 +201,7 @@ void show_regs(struct pt_regs *regs)
6847 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
6848 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
6849 regs->u_regs[15]);
6850- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
6851+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
6852 show_regwindow(regs);
6853 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
6854 }
6855@@ -290,7 +290,7 @@ void arch_trigger_all_cpu_backtrace(void)
6856 ((tp && tp->task) ? tp->task->pid : -1));
6857
6858 if (gp->tstate & TSTATE_PRIV) {
6859- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
6860+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
6861 (void *) gp->tpc,
6862 (void *) gp->o7,
6863 (void *) gp->i7,
6864diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
6865index 7ff45e4..a58f271 100644
6866--- a/arch/sparc/kernel/ptrace_64.c
6867+++ b/arch/sparc/kernel/ptrace_64.c
6868@@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
6869 return ret;
6870 }
6871
6872+#ifdef CONFIG_GRKERNSEC_SETXID
6873+extern void gr_delayed_cred_worker(void);
6874+#endif
6875+
6876 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
6877 {
6878 int ret = 0;
6879@@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
6880 /* do the secure computing check first */
6881 secure_computing_strict(regs->u_regs[UREG_G1]);
6882
6883+#ifdef CONFIG_GRKERNSEC_SETXID
6884+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6885+ gr_delayed_cred_worker();
6886+#endif
6887+
6888 if (test_thread_flag(TIF_SYSCALL_TRACE))
6889 ret = tracehook_report_syscall_entry(regs);
6890
6891@@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
6892
6893 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
6894 {
6895+#ifdef CONFIG_GRKERNSEC_SETXID
6896+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6897+ gr_delayed_cred_worker();
6898+#endif
6899+
6900 audit_syscall_exit(regs);
6901
6902 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
6903diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
6904index 0c9b31b..55a8ba6 100644
6905--- a/arch/sparc/kernel/sys_sparc_32.c
6906+++ b/arch/sparc/kernel/sys_sparc_32.c
6907@@ -39,6 +39,7 @@ asmlinkage unsigned long sys_getpagesize(void)
6908 unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags)
6909 {
6910 struct vm_area_struct * vmm;
6911+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
6912
6913 if (flags & MAP_FIXED) {
6914 /* We do not accept a shared mapping if it would violate
6915@@ -54,7 +55,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
6916 if (len > TASK_SIZE - PAGE_SIZE)
6917 return -ENOMEM;
6918 if (!addr)
6919- addr = TASK_UNMAPPED_BASE;
6920+ addr = current->mm->mmap_base;
6921
6922 if (flags & MAP_SHARED)
6923 addr = COLOUR_ALIGN(addr);
6924@@ -65,7 +66,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
6925 /* At this point: (!vmm || addr < vmm->vm_end). */
6926 if (TASK_SIZE - PAGE_SIZE - len < addr)
6927 return -ENOMEM;
6928- if (!vmm || addr + len <= vmm->vm_start)
6929+ if (check_heap_stack_gap(vmm, addr, len, offset))
6930 return addr;
6931 addr = vmm->vm_end;
6932 if (flags & MAP_SHARED)
6933diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
6934index 878ef3d..f100719 100644
6935--- a/arch/sparc/kernel/sys_sparc_64.c
6936+++ b/arch/sparc/kernel/sys_sparc_64.c
6937@@ -102,12 +102,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
6938 unsigned long task_size = TASK_SIZE;
6939 unsigned long start_addr;
6940 int do_color_align;
6941+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
6942
6943 if (flags & MAP_FIXED) {
6944 /* We do not accept a shared mapping if it would violate
6945 * cache aliasing constraints.
6946 */
6947- if ((flags & MAP_SHARED) &&
6948+ if ((filp || (flags & MAP_SHARED)) &&
6949 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
6950 return -EINVAL;
6951 return addr;
6952@@ -122,6 +123,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
6953 if (filp || (flags & MAP_SHARED))
6954 do_color_align = 1;
6955
6956+#ifdef CONFIG_PAX_RANDMMAP
6957+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
6958+#endif
6959+
6960 if (addr) {
6961 if (do_color_align)
6962 addr = COLOUR_ALIGN(addr, pgoff);
6963@@ -129,15 +134,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
6964 addr = PAGE_ALIGN(addr);
6965
6966 vma = find_vma(mm, addr);
6967- if (task_size - len >= addr &&
6968- (!vma || addr + len <= vma->vm_start))
6969+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
6970 return addr;
6971 }
6972
6973 if (len > mm->cached_hole_size) {
6974- start_addr = addr = mm->free_area_cache;
6975+ start_addr = addr = mm->free_area_cache;
6976 } else {
6977- start_addr = addr = TASK_UNMAPPED_BASE;
6978+ start_addr = addr = mm->mmap_base;
6979 mm->cached_hole_size = 0;
6980 }
6981
6982@@ -157,14 +161,14 @@ full_search:
6983 vma = find_vma(mm, VA_EXCLUDE_END);
6984 }
6985 if (unlikely(task_size < addr)) {
6986- if (start_addr != TASK_UNMAPPED_BASE) {
6987- start_addr = addr = TASK_UNMAPPED_BASE;
6988+ if (start_addr != mm->mmap_base) {
6989+ start_addr = addr = mm->mmap_base;
6990 mm->cached_hole_size = 0;
6991 goto full_search;
6992 }
6993 return -ENOMEM;
6994 }
6995- if (likely(!vma || addr + len <= vma->vm_start)) {
6996+ if (likely(check_heap_stack_gap(vma, addr, len, offset))) {
6997 /*
6998 * Remember the place where we stopped the search:
6999 */
7000@@ -190,6 +194,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7001 unsigned long task_size = STACK_TOP32;
7002 unsigned long addr = addr0;
7003 int do_color_align;
7004+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7005
7006 /* This should only ever run for 32-bit processes. */
7007 BUG_ON(!test_thread_flag(TIF_32BIT));
7008@@ -198,7 +203,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7009 /* We do not accept a shared mapping if it would violate
7010 * cache aliasing constraints.
7011 */
7012- if ((flags & MAP_SHARED) &&
7013+ if ((filp || (flags & MAP_SHARED)) &&
7014 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
7015 return -EINVAL;
7016 return addr;
7017@@ -219,8 +224,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7018 addr = PAGE_ALIGN(addr);
7019
7020 vma = find_vma(mm, addr);
7021- if (task_size - len >= addr &&
7022- (!vma || addr + len <= vma->vm_start))
7023+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7024 return addr;
7025 }
7026
7027@@ -241,7 +245,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7028 /* make sure it can fit in the remaining address space */
7029 if (likely(addr > len)) {
7030 vma = find_vma(mm, addr-len);
7031- if (!vma || addr <= vma->vm_start) {
7032+ if (check_heap_stack_gap(vma, addr - len, len, offset)) {
7033 /* remember the address as a hint for next time */
7034 return (mm->free_area_cache = addr-len);
7035 }
7036@@ -250,18 +254,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7037 if (unlikely(mm->mmap_base < len))
7038 goto bottomup;
7039
7040- addr = mm->mmap_base-len;
7041- if (do_color_align)
7042- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
7043+ addr = mm->mmap_base - len;
7044
7045 do {
7046+ if (do_color_align)
7047+ addr = COLOUR_ALIGN_DOWN(addr, pgoff);
7048 /*
7049 * Lookup failure means no vma is above this address,
7050 * else if new region fits below vma->vm_start,
7051 * return with success:
7052 */
7053 vma = find_vma(mm, addr);
7054- if (likely(!vma || addr+len <= vma->vm_start)) {
7055+ if (likely(check_heap_stack_gap(vma, addr, len, offset))) {
7056 /* remember the address as a hint for next time */
7057 return (mm->free_area_cache = addr);
7058 }
7059@@ -271,10 +275,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7060 mm->cached_hole_size = vma->vm_start - addr;
7061
7062 /* try just below the current vma->vm_start */
7063- addr = vma->vm_start-len;
7064- if (do_color_align)
7065- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
7066- } while (likely(len < vma->vm_start));
7067+ addr = skip_heap_stack_gap(vma, len, offset);
7068+ } while (!IS_ERR_VALUE(addr));
7069
7070 bottomup:
7071 /*
7072@@ -348,6 +350,10 @@ static unsigned long mmap_rnd(void)
7073 {
7074 unsigned long rnd = 0UL;
7075
7076+#ifdef CONFIG_PAX_RANDMMAP
7077+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
7078+#endif
7079+
7080 if (current->flags & PF_RANDOMIZE) {
7081 unsigned long val = get_random_int();
7082 if (test_thread_flag(TIF_32BIT))
7083@@ -373,6 +379,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7084 gap == RLIM_INFINITY ||
7085 sysctl_legacy_va_layout) {
7086 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
7087+
7088+#ifdef CONFIG_PAX_RANDMMAP
7089+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7090+ mm->mmap_base += mm->delta_mmap;
7091+#endif
7092+
7093 mm->get_unmapped_area = arch_get_unmapped_area;
7094 mm->unmap_area = arch_unmap_area;
7095 } else {
7096@@ -385,6 +397,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7097 gap = (task_size / 6 * 5);
7098
7099 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
7100+
7101+#ifdef CONFIG_PAX_RANDMMAP
7102+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7103+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7104+#endif
7105+
7106 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7107 mm->unmap_area = arch_unmap_area_topdown;
7108 }
7109diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
7110index bf23477..b7425a6 100644
7111--- a/arch/sparc/kernel/syscalls.S
7112+++ b/arch/sparc/kernel/syscalls.S
7113@@ -62,7 +62,7 @@ sys32_rt_sigreturn:
7114 #endif
7115 .align 32
7116 1: ldx [%g6 + TI_FLAGS], %l5
7117- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
7118+ andcc %l5, _TIF_WORK_SYSCALL, %g0
7119 be,pt %icc, rtrap
7120 nop
7121 call syscall_trace_leave
7122@@ -189,7 +189,7 @@ linux_sparc_syscall32:
7123
7124 srl %i5, 0, %o5 ! IEU1
7125 srl %i2, 0, %o2 ! IEU0 Group
7126- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
7127+ andcc %l0, _TIF_WORK_SYSCALL, %g0
7128 bne,pn %icc, linux_syscall_trace32 ! CTI
7129 mov %i0, %l5 ! IEU1
7130 call %l7 ! CTI Group brk forced
7131@@ -212,7 +212,7 @@ linux_sparc_syscall:
7132
7133 mov %i3, %o3 ! IEU1
7134 mov %i4, %o4 ! IEU0 Group
7135- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
7136+ andcc %l0, _TIF_WORK_SYSCALL, %g0
7137 bne,pn %icc, linux_syscall_trace ! CTI Group
7138 mov %i0, %l5 ! IEU0
7139 2: call %l7 ! CTI Group brk forced
7140@@ -228,7 +228,7 @@ ret_sys_call:
7141
7142 cmp %o0, -ERESTART_RESTARTBLOCK
7143 bgeu,pn %xcc, 1f
7144- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
7145+ andcc %l0, _TIF_WORK_SYSCALL, %g0
7146 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
7147
7148 2:
7149diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
7150index a5785ea..405c5f7 100644
7151--- a/arch/sparc/kernel/traps_32.c
7152+++ b/arch/sparc/kernel/traps_32.c
7153@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
7154 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
7155 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
7156
7157+extern void gr_handle_kernel_exploit(void);
7158+
7159 void die_if_kernel(char *str, struct pt_regs *regs)
7160 {
7161 static int die_counter;
7162@@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
7163 count++ < 30 &&
7164 (((unsigned long) rw) >= PAGE_OFFSET) &&
7165 !(((unsigned long) rw) & 0x7)) {
7166- printk("Caller[%08lx]: %pS\n", rw->ins[7],
7167+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
7168 (void *) rw->ins[7]);
7169 rw = (struct reg_window32 *)rw->ins[6];
7170 }
7171 }
7172 printk("Instruction DUMP:");
7173 instruction_dump ((unsigned long *) regs->pc);
7174- if(regs->psr & PSR_PS)
7175+ if(regs->psr & PSR_PS) {
7176+ gr_handle_kernel_exploit();
7177 do_exit(SIGKILL);
7178+ }
7179 do_exit(SIGSEGV);
7180 }
7181
7182diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
7183index b66a779..8e8d66c 100644
7184--- a/arch/sparc/kernel/traps_64.c
7185+++ b/arch/sparc/kernel/traps_64.c
7186@@ -76,7 +76,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
7187 i + 1,
7188 p->trapstack[i].tstate, p->trapstack[i].tpc,
7189 p->trapstack[i].tnpc, p->trapstack[i].tt);
7190- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
7191+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
7192 }
7193 }
7194
7195@@ -96,6 +96,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
7196
7197 lvl -= 0x100;
7198 if (regs->tstate & TSTATE_PRIV) {
7199+
7200+#ifdef CONFIG_PAX_REFCOUNT
7201+ if (lvl == 6)
7202+ pax_report_refcount_overflow(regs);
7203+#endif
7204+
7205 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
7206 die_if_kernel(buffer, regs);
7207 }
7208@@ -114,11 +120,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
7209 void bad_trap_tl1(struct pt_regs *regs, long lvl)
7210 {
7211 char buffer[32];
7212-
7213+
7214 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
7215 0, lvl, SIGTRAP) == NOTIFY_STOP)
7216 return;
7217
7218+#ifdef CONFIG_PAX_REFCOUNT
7219+ if (lvl == 6)
7220+ pax_report_refcount_overflow(regs);
7221+#endif
7222+
7223 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
7224
7225 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
7226@@ -1142,7 +1153,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
7227 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
7228 printk("%s" "ERROR(%d): ",
7229 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
7230- printk("TPC<%pS>\n", (void *) regs->tpc);
7231+ printk("TPC<%pA>\n", (void *) regs->tpc);
7232 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
7233 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
7234 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
7235@@ -1749,7 +1760,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
7236 smp_processor_id(),
7237 (type & 0x1) ? 'I' : 'D',
7238 regs->tpc);
7239- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
7240+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
7241 panic("Irrecoverable Cheetah+ parity error.");
7242 }
7243
7244@@ -1757,7 +1768,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
7245 smp_processor_id(),
7246 (type & 0x1) ? 'I' : 'D',
7247 regs->tpc);
7248- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
7249+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
7250 }
7251
7252 struct sun4v_error_entry {
7253@@ -2104,9 +2115,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
7254
7255 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
7256 regs->tpc, tl);
7257- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
7258+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
7259 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
7260- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
7261+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
7262 (void *) regs->u_regs[UREG_I7]);
7263 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
7264 "pte[%lx] error[%lx]\n",
7265@@ -2128,9 +2139,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
7266
7267 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
7268 regs->tpc, tl);
7269- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
7270+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
7271 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
7272- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
7273+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
7274 (void *) regs->u_regs[UREG_I7]);
7275 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
7276 "pte[%lx] error[%lx]\n",
7277@@ -2336,13 +2347,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
7278 fp = (unsigned long)sf->fp + STACK_BIAS;
7279 }
7280
7281- printk(" [%016lx] %pS\n", pc, (void *) pc);
7282+ printk(" [%016lx] %pA\n", pc, (void *) pc);
7283 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
7284 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
7285 int index = tsk->curr_ret_stack;
7286 if (tsk->ret_stack && index >= graph) {
7287 pc = tsk->ret_stack[index - graph].ret;
7288- printk(" [%016lx] %pS\n", pc, (void *) pc);
7289+ printk(" [%016lx] %pA\n", pc, (void *) pc);
7290 graph++;
7291 }
7292 }
7293@@ -2367,6 +2378,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
7294 return (struct reg_window *) (fp + STACK_BIAS);
7295 }
7296
7297+extern void gr_handle_kernel_exploit(void);
7298+
7299 void die_if_kernel(char *str, struct pt_regs *regs)
7300 {
7301 static int die_counter;
7302@@ -2395,7 +2408,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
7303 while (rw &&
7304 count++ < 30 &&
7305 kstack_valid(tp, (unsigned long) rw)) {
7306- printk("Caller[%016lx]: %pS\n", rw->ins[7],
7307+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
7308 (void *) rw->ins[7]);
7309
7310 rw = kernel_stack_up(rw);
7311@@ -2408,8 +2421,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
7312 }
7313 user_instruction_dump ((unsigned int __user *) regs->tpc);
7314 }
7315- if (regs->tstate & TSTATE_PRIV)
7316+ if (regs->tstate & TSTATE_PRIV) {
7317+ gr_handle_kernel_exploit();
7318 do_exit(SIGKILL);
7319+ }
7320 do_exit(SIGSEGV);
7321 }
7322 EXPORT_SYMBOL(die_if_kernel);
7323diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
7324index 8201c25e..072a2a7 100644
7325--- a/arch/sparc/kernel/unaligned_64.c
7326+++ b/arch/sparc/kernel/unaligned_64.c
7327@@ -286,7 +286,7 @@ static void log_unaligned(struct pt_regs *regs)
7328 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
7329
7330 if (__ratelimit(&ratelimit)) {
7331- printk("Kernel unaligned access at TPC[%lx] %pS\n",
7332+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
7333 regs->tpc, (void *) regs->tpc);
7334 }
7335 }
7336diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
7337index 8410065f2..4fd4ca22 100644
7338--- a/arch/sparc/lib/Makefile
7339+++ b/arch/sparc/lib/Makefile
7340@@ -2,7 +2,7 @@
7341 #
7342
7343 asflags-y := -ansi -DST_DIV0=0x02
7344-ccflags-y := -Werror
7345+#ccflags-y := -Werror
7346
7347 lib-$(CONFIG_SPARC32) += ashrdi3.o
7348 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
7349diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
7350index 85c233d..68500e0 100644
7351--- a/arch/sparc/lib/atomic_64.S
7352+++ b/arch/sparc/lib/atomic_64.S
7353@@ -17,7 +17,12 @@
7354 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
7355 BACKOFF_SETUP(%o2)
7356 1: lduw [%o1], %g1
7357- add %g1, %o0, %g7
7358+ addcc %g1, %o0, %g7
7359+
7360+#ifdef CONFIG_PAX_REFCOUNT
7361+ tvs %icc, 6
7362+#endif
7363+
7364 cas [%o1], %g1, %g7
7365 cmp %g1, %g7
7366 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
7367@@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
7368 2: BACKOFF_SPIN(%o2, %o3, 1b)
7369 ENDPROC(atomic_add)
7370
7371+ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
7372+ BACKOFF_SETUP(%o2)
7373+1: lduw [%o1], %g1
7374+ add %g1, %o0, %g7
7375+ cas [%o1], %g1, %g7
7376+ cmp %g1, %g7
7377+ bne,pn %icc, 2f
7378+ nop
7379+ retl
7380+ nop
7381+2: BACKOFF_SPIN(%o2, %o3, 1b)
7382+ENDPROC(atomic_add_unchecked)
7383+
7384 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
7385 BACKOFF_SETUP(%o2)
7386 1: lduw [%o1], %g1
7387- sub %g1, %o0, %g7
7388+ subcc %g1, %o0, %g7
7389+
7390+#ifdef CONFIG_PAX_REFCOUNT
7391+ tvs %icc, 6
7392+#endif
7393+
7394 cas [%o1], %g1, %g7
7395 cmp %g1, %g7
7396 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
7397@@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
7398 2: BACKOFF_SPIN(%o2, %o3, 1b)
7399 ENDPROC(atomic_sub)
7400
7401+ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
7402+ BACKOFF_SETUP(%o2)
7403+1: lduw [%o1], %g1
7404+ sub %g1, %o0, %g7
7405+ cas [%o1], %g1, %g7
7406+ cmp %g1, %g7
7407+ bne,pn %icc, 2f
7408+ nop
7409+ retl
7410+ nop
7411+2: BACKOFF_SPIN(%o2, %o3, 1b)
7412+ENDPROC(atomic_sub_unchecked)
7413+
7414 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
7415 BACKOFF_SETUP(%o2)
7416 1: lduw [%o1], %g1
7417- add %g1, %o0, %g7
7418+ addcc %g1, %o0, %g7
7419+
7420+#ifdef CONFIG_PAX_REFCOUNT
7421+ tvs %icc, 6
7422+#endif
7423+
7424 cas [%o1], %g1, %g7
7425 cmp %g1, %g7
7426 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
7427@@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
7428 2: BACKOFF_SPIN(%o2, %o3, 1b)
7429 ENDPROC(atomic_add_ret)
7430
7431+ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
7432+ BACKOFF_SETUP(%o2)
7433+1: lduw [%o1], %g1
7434+ addcc %g1, %o0, %g7
7435+ cas [%o1], %g1, %g7
7436+ cmp %g1, %g7
7437+ bne,pn %icc, 2f
7438+ add %g7, %o0, %g7
7439+ sra %g7, 0, %o0
7440+ retl
7441+ nop
7442+2: BACKOFF_SPIN(%o2, %o3, 1b)
7443+ENDPROC(atomic_add_ret_unchecked)
7444+
7445 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
7446 BACKOFF_SETUP(%o2)
7447 1: lduw [%o1], %g1
7448- sub %g1, %o0, %g7
7449+ subcc %g1, %o0, %g7
7450+
7451+#ifdef CONFIG_PAX_REFCOUNT
7452+ tvs %icc, 6
7453+#endif
7454+
7455 cas [%o1], %g1, %g7
7456 cmp %g1, %g7
7457 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
7458@@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
7459 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
7460 BACKOFF_SETUP(%o2)
7461 1: ldx [%o1], %g1
7462- add %g1, %o0, %g7
7463+ addcc %g1, %o0, %g7
7464+
7465+#ifdef CONFIG_PAX_REFCOUNT
7466+ tvs %xcc, 6
7467+#endif
7468+
7469 casx [%o1], %g1, %g7
7470 cmp %g1, %g7
7471 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
7472@@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
7473 2: BACKOFF_SPIN(%o2, %o3, 1b)
7474 ENDPROC(atomic64_add)
7475
7476+ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
7477+ BACKOFF_SETUP(%o2)
7478+1: ldx [%o1], %g1
7479+ addcc %g1, %o0, %g7
7480+ casx [%o1], %g1, %g7
7481+ cmp %g1, %g7
7482+ bne,pn %xcc, 2f
7483+ nop
7484+ retl
7485+ nop
7486+2: BACKOFF_SPIN(%o2, %o3, 1b)
7487+ENDPROC(atomic64_add_unchecked)
7488+
7489 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
7490 BACKOFF_SETUP(%o2)
7491 1: ldx [%o1], %g1
7492- sub %g1, %o0, %g7
7493+ subcc %g1, %o0, %g7
7494+
7495+#ifdef CONFIG_PAX_REFCOUNT
7496+ tvs %xcc, 6
7497+#endif
7498+
7499 casx [%o1], %g1, %g7
7500 cmp %g1, %g7
7501 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
7502@@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
7503 2: BACKOFF_SPIN(%o2, %o3, 1b)
7504 ENDPROC(atomic64_sub)
7505
7506+ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
7507+ BACKOFF_SETUP(%o2)
7508+1: ldx [%o1], %g1
7509+ subcc %g1, %o0, %g7
7510+ casx [%o1], %g1, %g7
7511+ cmp %g1, %g7
7512+ bne,pn %xcc, 2f
7513+ nop
7514+ retl
7515+ nop
7516+2: BACKOFF_SPIN(%o2, %o3, 1b)
7517+ENDPROC(atomic64_sub_unchecked)
7518+
7519 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
7520 BACKOFF_SETUP(%o2)
7521 1: ldx [%o1], %g1
7522- add %g1, %o0, %g7
7523+ addcc %g1, %o0, %g7
7524+
7525+#ifdef CONFIG_PAX_REFCOUNT
7526+ tvs %xcc, 6
7527+#endif
7528+
7529 casx [%o1], %g1, %g7
7530 cmp %g1, %g7
7531 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
7532@@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
7533 2: BACKOFF_SPIN(%o2, %o3, 1b)
7534 ENDPROC(atomic64_add_ret)
7535
7536+ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
7537+ BACKOFF_SETUP(%o2)
7538+1: ldx [%o1], %g1
7539+ addcc %g1, %o0, %g7
7540+ casx [%o1], %g1, %g7
7541+ cmp %g1, %g7
7542+ bne,pn %xcc, 2f
7543+ add %g7, %o0, %g7
7544+ mov %g7, %o0
7545+ retl
7546+ nop
7547+2: BACKOFF_SPIN(%o2, %o3, 1b)
7548+ENDPROC(atomic64_add_ret_unchecked)
7549+
7550 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
7551 BACKOFF_SETUP(%o2)
7552 1: ldx [%o1], %g1
7553- sub %g1, %o0, %g7
7554+ subcc %g1, %o0, %g7
7555+
7556+#ifdef CONFIG_PAX_REFCOUNT
7557+ tvs %xcc, 6
7558+#endif
7559+
7560 casx [%o1], %g1, %g7
7561 cmp %g1, %g7
7562 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
7563diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
7564index 0c4e35e..745d3e4 100644
7565--- a/arch/sparc/lib/ksyms.c
7566+++ b/arch/sparc/lib/ksyms.c
7567@@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
7568
7569 /* Atomic counter implementation. */
7570 EXPORT_SYMBOL(atomic_add);
7571+EXPORT_SYMBOL(atomic_add_unchecked);
7572 EXPORT_SYMBOL(atomic_add_ret);
7573+EXPORT_SYMBOL(atomic_add_ret_unchecked);
7574 EXPORT_SYMBOL(atomic_sub);
7575+EXPORT_SYMBOL(atomic_sub_unchecked);
7576 EXPORT_SYMBOL(atomic_sub_ret);
7577 EXPORT_SYMBOL(atomic64_add);
7578+EXPORT_SYMBOL(atomic64_add_unchecked);
7579 EXPORT_SYMBOL(atomic64_add_ret);
7580+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
7581 EXPORT_SYMBOL(atomic64_sub);
7582+EXPORT_SYMBOL(atomic64_sub_unchecked);
7583 EXPORT_SYMBOL(atomic64_sub_ret);
7584 EXPORT_SYMBOL(atomic64_dec_if_positive);
7585
7586diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
7587index 30c3ecc..736f015 100644
7588--- a/arch/sparc/mm/Makefile
7589+++ b/arch/sparc/mm/Makefile
7590@@ -2,7 +2,7 @@
7591 #
7592
7593 asflags-y := -ansi
7594-ccflags-y := -Werror
7595+#ccflags-y := -Werror
7596
7597 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
7598 obj-y += fault_$(BITS).o
7599diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
7600index e98bfda..ea8d221 100644
7601--- a/arch/sparc/mm/fault_32.c
7602+++ b/arch/sparc/mm/fault_32.c
7603@@ -21,6 +21,9 @@
7604 #include <linux/perf_event.h>
7605 #include <linux/interrupt.h>
7606 #include <linux/kdebug.h>
7607+#include <linux/slab.h>
7608+#include <linux/pagemap.h>
7609+#include <linux/compiler.h>
7610
7611 #include <asm/page.h>
7612 #include <asm/pgtable.h>
7613@@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
7614 return safe_compute_effective_address(regs, insn);
7615 }
7616
7617+#ifdef CONFIG_PAX_PAGEEXEC
7618+#ifdef CONFIG_PAX_DLRESOLVE
7619+static void pax_emuplt_close(struct vm_area_struct *vma)
7620+{
7621+ vma->vm_mm->call_dl_resolve = 0UL;
7622+}
7623+
7624+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
7625+{
7626+ unsigned int *kaddr;
7627+
7628+ vmf->page = alloc_page(GFP_HIGHUSER);
7629+ if (!vmf->page)
7630+ return VM_FAULT_OOM;
7631+
7632+ kaddr = kmap(vmf->page);
7633+ memset(kaddr, 0, PAGE_SIZE);
7634+ kaddr[0] = 0x9DE3BFA8U; /* save */
7635+ flush_dcache_page(vmf->page);
7636+ kunmap(vmf->page);
7637+ return VM_FAULT_MAJOR;
7638+}
7639+
7640+static const struct vm_operations_struct pax_vm_ops = {
7641+ .close = pax_emuplt_close,
7642+ .fault = pax_emuplt_fault
7643+};
7644+
7645+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
7646+{
7647+ int ret;
7648+
7649+ INIT_LIST_HEAD(&vma->anon_vma_chain);
7650+ vma->vm_mm = current->mm;
7651+ vma->vm_start = addr;
7652+ vma->vm_end = addr + PAGE_SIZE;
7653+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
7654+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
7655+ vma->vm_ops = &pax_vm_ops;
7656+
7657+ ret = insert_vm_struct(current->mm, vma);
7658+ if (ret)
7659+ return ret;
7660+
7661+ ++current->mm->total_vm;
7662+ return 0;
7663+}
7664+#endif
7665+
7666+/*
7667+ * PaX: decide what to do with offenders (regs->pc = fault address)
7668+ *
7669+ * returns 1 when task should be killed
7670+ * 2 when patched PLT trampoline was detected
7671+ * 3 when unpatched PLT trampoline was detected
7672+ */
7673+static int pax_handle_fetch_fault(struct pt_regs *regs)
7674+{
7675+
7676+#ifdef CONFIG_PAX_EMUPLT
7677+ int err;
7678+
7679+ do { /* PaX: patched PLT emulation #1 */
7680+ unsigned int sethi1, sethi2, jmpl;
7681+
7682+ err = get_user(sethi1, (unsigned int *)regs->pc);
7683+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
7684+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
7685+
7686+ if (err)
7687+ break;
7688+
7689+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
7690+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
7691+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
7692+ {
7693+ unsigned int addr;
7694+
7695+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
7696+ addr = regs->u_regs[UREG_G1];
7697+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
7698+ regs->pc = addr;
7699+ regs->npc = addr+4;
7700+ return 2;
7701+ }
7702+ } while (0);
7703+
7704+ do { /* PaX: patched PLT emulation #2 */
7705+ unsigned int ba;
7706+
7707+ err = get_user(ba, (unsigned int *)regs->pc);
7708+
7709+ if (err)
7710+ break;
7711+
7712+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
7713+ unsigned int addr;
7714+
7715+ if ((ba & 0xFFC00000U) == 0x30800000U)
7716+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
7717+ else
7718+ addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
7719+ regs->pc = addr;
7720+ regs->npc = addr+4;
7721+ return 2;
7722+ }
7723+ } while (0);
7724+
7725+ do { /* PaX: patched PLT emulation #3 */
7726+ unsigned int sethi, bajmpl, nop;
7727+
7728+ err = get_user(sethi, (unsigned int *)regs->pc);
7729+ err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
7730+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
7731+
7732+ if (err)
7733+ break;
7734+
7735+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7736+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
7737+ nop == 0x01000000U)
7738+ {
7739+ unsigned int addr;
7740+
7741+ addr = (sethi & 0x003FFFFFU) << 10;
7742+ regs->u_regs[UREG_G1] = addr;
7743+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
7744+ addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
7745+ else
7746+ addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
7747+ regs->pc = addr;
7748+ regs->npc = addr+4;
7749+ return 2;
7750+ }
7751+ } while (0);
7752+
7753+ do { /* PaX: unpatched PLT emulation step 1 */
7754+ unsigned int sethi, ba, nop;
7755+
7756+ err = get_user(sethi, (unsigned int *)regs->pc);
7757+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
7758+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
7759+
7760+ if (err)
7761+ break;
7762+
7763+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7764+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
7765+ nop == 0x01000000U)
7766+ {
7767+ unsigned int addr, save, call;
7768+
7769+ if ((ba & 0xFFC00000U) == 0x30800000U)
7770+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
7771+ else
7772+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
7773+
7774+ err = get_user(save, (unsigned int *)addr);
7775+ err |= get_user(call, (unsigned int *)(addr+4));
7776+ err |= get_user(nop, (unsigned int *)(addr+8));
7777+ if (err)
7778+ break;
7779+
7780+#ifdef CONFIG_PAX_DLRESOLVE
7781+ if (save == 0x9DE3BFA8U &&
7782+ (call & 0xC0000000U) == 0x40000000U &&
7783+ nop == 0x01000000U)
7784+ {
7785+ struct vm_area_struct *vma;
7786+ unsigned long call_dl_resolve;
7787+
7788+ down_read(&current->mm->mmap_sem);
7789+ call_dl_resolve = current->mm->call_dl_resolve;
7790+ up_read(&current->mm->mmap_sem);
7791+ if (likely(call_dl_resolve))
7792+ goto emulate;
7793+
7794+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
7795+
7796+ down_write(&current->mm->mmap_sem);
7797+ if (current->mm->call_dl_resolve) {
7798+ call_dl_resolve = current->mm->call_dl_resolve;
7799+ up_write(&current->mm->mmap_sem);
7800+ if (vma)
7801+ kmem_cache_free(vm_area_cachep, vma);
7802+ goto emulate;
7803+ }
7804+
7805+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
7806+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
7807+ up_write(&current->mm->mmap_sem);
7808+ if (vma)
7809+ kmem_cache_free(vm_area_cachep, vma);
7810+ return 1;
7811+ }
7812+
7813+ if (pax_insert_vma(vma, call_dl_resolve)) {
7814+ up_write(&current->mm->mmap_sem);
7815+ kmem_cache_free(vm_area_cachep, vma);
7816+ return 1;
7817+ }
7818+
7819+ current->mm->call_dl_resolve = call_dl_resolve;
7820+ up_write(&current->mm->mmap_sem);
7821+
7822+emulate:
7823+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7824+ regs->pc = call_dl_resolve;
7825+ regs->npc = addr+4;
7826+ return 3;
7827+ }
7828+#endif
7829+
7830+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
7831+ if ((save & 0xFFC00000U) == 0x05000000U &&
7832+ (call & 0xFFFFE000U) == 0x85C0A000U &&
7833+ nop == 0x01000000U)
7834+ {
7835+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7836+ regs->u_regs[UREG_G2] = addr + 4;
7837+ addr = (save & 0x003FFFFFU) << 10;
7838+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
7839+ regs->pc = addr;
7840+ regs->npc = addr+4;
7841+ return 3;
7842+ }
7843+ }
7844+ } while (0);
7845+
7846+ do { /* PaX: unpatched PLT emulation step 2 */
7847+ unsigned int save, call, nop;
7848+
7849+ err = get_user(save, (unsigned int *)(regs->pc-4));
7850+ err |= get_user(call, (unsigned int *)regs->pc);
7851+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
7852+ if (err)
7853+ break;
7854+
7855+ if (save == 0x9DE3BFA8U &&
7856+ (call & 0xC0000000U) == 0x40000000U &&
7857+ nop == 0x01000000U)
7858+ {
7859+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
7860+
7861+ regs->u_regs[UREG_RETPC] = regs->pc;
7862+ regs->pc = dl_resolve;
7863+ regs->npc = dl_resolve+4;
7864+ return 3;
7865+ }
7866+ } while (0);
7867+#endif
7868+
7869+ return 1;
7870+}
7871+
7872+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7873+{
7874+ unsigned long i;
7875+
7876+ printk(KERN_ERR "PAX: bytes at PC: ");
7877+ for (i = 0; i < 8; i++) {
7878+ unsigned int c;
7879+ if (get_user(c, (unsigned int *)pc+i))
7880+ printk(KERN_CONT "???????? ");
7881+ else
7882+ printk(KERN_CONT "%08x ", c);
7883+ }
7884+ printk("\n");
7885+}
7886+#endif
7887+
7888 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
7889 int text_fault)
7890 {
7891@@ -230,6 +504,24 @@ good_area:
7892 if (!(vma->vm_flags & VM_WRITE))
7893 goto bad_area;
7894 } else {
7895+
7896+#ifdef CONFIG_PAX_PAGEEXEC
7897+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
7898+ up_read(&mm->mmap_sem);
7899+ switch (pax_handle_fetch_fault(regs)) {
7900+
7901+#ifdef CONFIG_PAX_EMUPLT
7902+ case 2:
7903+ case 3:
7904+ return;
7905+#endif
7906+
7907+ }
7908+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
7909+ do_group_exit(SIGKILL);
7910+ }
7911+#endif
7912+
7913 /* Allow reads even for write-only mappings */
7914 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
7915 goto bad_area;
7916diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
7917index 097aee7..5ca6697 100644
7918--- a/arch/sparc/mm/fault_64.c
7919+++ b/arch/sparc/mm/fault_64.c
7920@@ -21,6 +21,9 @@
7921 #include <linux/kprobes.h>
7922 #include <linux/kdebug.h>
7923 #include <linux/percpu.h>
7924+#include <linux/slab.h>
7925+#include <linux/pagemap.h>
7926+#include <linux/compiler.h>
7927
7928 #include <asm/page.h>
7929 #include <asm/pgtable.h>
7930@@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
7931 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
7932 regs->tpc);
7933 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
7934- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
7935+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
7936 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
7937 dump_stack();
7938 unhandled_fault(regs->tpc, current, regs);
7939@@ -270,6 +273,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
7940 show_regs(regs);
7941 }
7942
7943+#ifdef CONFIG_PAX_PAGEEXEC
7944+#ifdef CONFIG_PAX_DLRESOLVE
7945+static void pax_emuplt_close(struct vm_area_struct *vma)
7946+{
7947+ vma->vm_mm->call_dl_resolve = 0UL;
7948+}
7949+
7950+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
7951+{
7952+ unsigned int *kaddr;
7953+
7954+ vmf->page = alloc_page(GFP_HIGHUSER);
7955+ if (!vmf->page)
7956+ return VM_FAULT_OOM;
7957+
7958+ kaddr = kmap(vmf->page);
7959+ memset(kaddr, 0, PAGE_SIZE);
7960+ kaddr[0] = 0x9DE3BFA8U; /* save */
7961+ flush_dcache_page(vmf->page);
7962+ kunmap(vmf->page);
7963+ return VM_FAULT_MAJOR;
7964+}
7965+
7966+static const struct vm_operations_struct pax_vm_ops = {
7967+ .close = pax_emuplt_close,
7968+ .fault = pax_emuplt_fault
7969+};
7970+
7971+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
7972+{
7973+ int ret;
7974+
7975+ INIT_LIST_HEAD(&vma->anon_vma_chain);
7976+ vma->vm_mm = current->mm;
7977+ vma->vm_start = addr;
7978+ vma->vm_end = addr + PAGE_SIZE;
7979+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
7980+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
7981+ vma->vm_ops = &pax_vm_ops;
7982+
7983+ ret = insert_vm_struct(current->mm, vma);
7984+ if (ret)
7985+ return ret;
7986+
7987+ ++current->mm->total_vm;
7988+ return 0;
7989+}
7990+#endif
7991+
7992+/*
7993+ * PaX: decide what to do with offenders (regs->tpc = fault address)
7994+ *
7995+ * returns 1 when task should be killed
7996+ * 2 when patched PLT trampoline was detected
7997+ * 3 when unpatched PLT trampoline was detected
7998+ */
7999+static int pax_handle_fetch_fault(struct pt_regs *regs)
8000+{
8001+
8002+#ifdef CONFIG_PAX_EMUPLT
8003+ int err;
8004+
8005+ do { /* PaX: patched PLT emulation #1 */
8006+ unsigned int sethi1, sethi2, jmpl;
8007+
8008+ err = get_user(sethi1, (unsigned int *)regs->tpc);
8009+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
8010+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
8011+
8012+ if (err)
8013+ break;
8014+
8015+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
8016+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
8017+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
8018+ {
8019+ unsigned long addr;
8020+
8021+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
8022+ addr = regs->u_regs[UREG_G1];
8023+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
8024+
8025+ if (test_thread_flag(TIF_32BIT))
8026+ addr &= 0xFFFFFFFFUL;
8027+
8028+ regs->tpc = addr;
8029+ regs->tnpc = addr+4;
8030+ return 2;
8031+ }
8032+ } while (0);
8033+
8034+ do { /* PaX: patched PLT emulation #2 */
8035+ unsigned int ba;
8036+
8037+ err = get_user(ba, (unsigned int *)regs->tpc);
8038+
8039+ if (err)
8040+ break;
8041+
8042+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
8043+ unsigned long addr;
8044+
8045+ if ((ba & 0xFFC00000U) == 0x30800000U)
8046+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
8047+ else
8048+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
8049+
8050+ if (test_thread_flag(TIF_32BIT))
8051+ addr &= 0xFFFFFFFFUL;
8052+
8053+ regs->tpc = addr;
8054+ regs->tnpc = addr+4;
8055+ return 2;
8056+ }
8057+ } while (0);
8058+
8059+ do { /* PaX: patched PLT emulation #3 */
8060+ unsigned int sethi, bajmpl, nop;
8061+
8062+ err = get_user(sethi, (unsigned int *)regs->tpc);
8063+ err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
8064+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
8065+
8066+ if (err)
8067+ break;
8068+
8069+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
8070+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
8071+ nop == 0x01000000U)
8072+ {
8073+ unsigned long addr;
8074+
8075+ addr = (sethi & 0x003FFFFFU) << 10;
8076+ regs->u_regs[UREG_G1] = addr;
8077+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
8078+ addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
8079+ else
8080+ addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
8081+
8082+ if (test_thread_flag(TIF_32BIT))
8083+ addr &= 0xFFFFFFFFUL;
8084+
8085+ regs->tpc = addr;
8086+ regs->tnpc = addr+4;
8087+ return 2;
8088+ }
8089+ } while (0);
8090+
8091+ do { /* PaX: patched PLT emulation #4 */
8092+ unsigned int sethi, mov1, call, mov2;
8093+
8094+ err = get_user(sethi, (unsigned int *)regs->tpc);
8095+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
8096+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
8097+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
8098+
8099+ if (err)
8100+ break;
8101+
8102+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
8103+ mov1 == 0x8210000FU &&
8104+ (call & 0xC0000000U) == 0x40000000U &&
8105+ mov2 == 0x9E100001U)
8106+ {
8107+ unsigned long addr;
8108+
8109+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
8110+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
8111+
8112+ if (test_thread_flag(TIF_32BIT))
8113+ addr &= 0xFFFFFFFFUL;
8114+
8115+ regs->tpc = addr;
8116+ regs->tnpc = addr+4;
8117+ return 2;
8118+ }
8119+ } while (0);
8120+
8121+ do { /* PaX: patched PLT emulation #5 */
8122+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
8123+
8124+ err = get_user(sethi, (unsigned int *)regs->tpc);
8125+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
8126+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
8127+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
8128+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
8129+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
8130+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
8131+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
8132+
8133+ if (err)
8134+ break;
8135+
8136+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
8137+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
8138+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
8139+ (or1 & 0xFFFFE000U) == 0x82106000U &&
8140+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
8141+ sllx == 0x83287020U &&
8142+ jmpl == 0x81C04005U &&
8143+ nop == 0x01000000U)
8144+ {
8145+ unsigned long addr;
8146+
8147+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
8148+ regs->u_regs[UREG_G1] <<= 32;
8149+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
8150+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
8151+ regs->tpc = addr;
8152+ regs->tnpc = addr+4;
8153+ return 2;
8154+ }
8155+ } while (0);
8156+
8157+ do { /* PaX: patched PLT emulation #6 */
8158+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
8159+
8160+ err = get_user(sethi, (unsigned int *)regs->tpc);
8161+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
8162+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
8163+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
8164+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
8165+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
8166+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
8167+
8168+ if (err)
8169+ break;
8170+
8171+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
8172+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
8173+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
8174+ sllx == 0x83287020U &&
8175+ (or & 0xFFFFE000U) == 0x8A116000U &&
8176+ jmpl == 0x81C04005U &&
8177+ nop == 0x01000000U)
8178+ {
8179+ unsigned long addr;
8180+
8181+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
8182+ regs->u_regs[UREG_G1] <<= 32;
8183+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
8184+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
8185+ regs->tpc = addr;
8186+ regs->tnpc = addr+4;
8187+ return 2;
8188+ }
8189+ } while (0);
8190+
8191+ do { /* PaX: unpatched PLT emulation step 1 */
8192+ unsigned int sethi, ba, nop;
8193+
8194+ err = get_user(sethi, (unsigned int *)regs->tpc);
8195+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
8196+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
8197+
8198+ if (err)
8199+ break;
8200+
8201+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
8202+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
8203+ nop == 0x01000000U)
8204+ {
8205+ unsigned long addr;
8206+ unsigned int save, call;
8207+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
8208+
8209+ if ((ba & 0xFFC00000U) == 0x30800000U)
8210+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
8211+ else
8212+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
8213+
8214+ if (test_thread_flag(TIF_32BIT))
8215+ addr &= 0xFFFFFFFFUL;
8216+
8217+ err = get_user(save, (unsigned int *)addr);
8218+ err |= get_user(call, (unsigned int *)(addr+4));
8219+ err |= get_user(nop, (unsigned int *)(addr+8));
8220+ if (err)
8221+ break;
8222+
8223+#ifdef CONFIG_PAX_DLRESOLVE
8224+ if (save == 0x9DE3BFA8U &&
8225+ (call & 0xC0000000U) == 0x40000000U &&
8226+ nop == 0x01000000U)
8227+ {
8228+ struct vm_area_struct *vma;
8229+ unsigned long call_dl_resolve;
8230+
8231+ down_read(&current->mm->mmap_sem);
8232+ call_dl_resolve = current->mm->call_dl_resolve;
8233+ up_read(&current->mm->mmap_sem);
8234+ if (likely(call_dl_resolve))
8235+ goto emulate;
8236+
8237+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
8238+
8239+ down_write(&current->mm->mmap_sem);
8240+ if (current->mm->call_dl_resolve) {
8241+ call_dl_resolve = current->mm->call_dl_resolve;
8242+ up_write(&current->mm->mmap_sem);
8243+ if (vma)
8244+ kmem_cache_free(vm_area_cachep, vma);
8245+ goto emulate;
8246+ }
8247+
8248+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
8249+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
8250+ up_write(&current->mm->mmap_sem);
8251+ if (vma)
8252+ kmem_cache_free(vm_area_cachep, vma);
8253+ return 1;
8254+ }
8255+
8256+ if (pax_insert_vma(vma, call_dl_resolve)) {
8257+ up_write(&current->mm->mmap_sem);
8258+ kmem_cache_free(vm_area_cachep, vma);
8259+ return 1;
8260+ }
8261+
8262+ current->mm->call_dl_resolve = call_dl_resolve;
8263+ up_write(&current->mm->mmap_sem);
8264+
8265+emulate:
8266+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
8267+ regs->tpc = call_dl_resolve;
8268+ regs->tnpc = addr+4;
8269+ return 3;
8270+ }
8271+#endif
8272+
8273+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
8274+ if ((save & 0xFFC00000U) == 0x05000000U &&
8275+ (call & 0xFFFFE000U) == 0x85C0A000U &&
8276+ nop == 0x01000000U)
8277+ {
8278+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
8279+ regs->u_regs[UREG_G2] = addr + 4;
8280+ addr = (save & 0x003FFFFFU) << 10;
8281+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
8282+
8283+ if (test_thread_flag(TIF_32BIT))
8284+ addr &= 0xFFFFFFFFUL;
8285+
8286+ regs->tpc = addr;
8287+ regs->tnpc = addr+4;
8288+ return 3;
8289+ }
8290+
8291+ /* PaX: 64-bit PLT stub */
8292+ err = get_user(sethi1, (unsigned int *)addr);
8293+ err |= get_user(sethi2, (unsigned int *)(addr+4));
8294+ err |= get_user(or1, (unsigned int *)(addr+8));
8295+ err |= get_user(or2, (unsigned int *)(addr+12));
8296+ err |= get_user(sllx, (unsigned int *)(addr+16));
8297+ err |= get_user(add, (unsigned int *)(addr+20));
8298+ err |= get_user(jmpl, (unsigned int *)(addr+24));
8299+ err |= get_user(nop, (unsigned int *)(addr+28));
8300+ if (err)
8301+ break;
8302+
8303+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
8304+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
8305+ (or1 & 0xFFFFE000U) == 0x88112000U &&
8306+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
8307+ sllx == 0x89293020U &&
8308+ add == 0x8A010005U &&
8309+ jmpl == 0x89C14000U &&
8310+ nop == 0x01000000U)
8311+ {
8312+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
8313+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
8314+ regs->u_regs[UREG_G4] <<= 32;
8315+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
8316+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
8317+ regs->u_regs[UREG_G4] = addr + 24;
8318+ addr = regs->u_regs[UREG_G5];
8319+ regs->tpc = addr;
8320+ regs->tnpc = addr+4;
8321+ return 3;
8322+ }
8323+ }
8324+ } while (0);
8325+
8326+#ifdef CONFIG_PAX_DLRESOLVE
8327+ do { /* PaX: unpatched PLT emulation step 2 */
8328+ unsigned int save, call, nop;
8329+
8330+ err = get_user(save, (unsigned int *)(regs->tpc-4));
8331+ err |= get_user(call, (unsigned int *)regs->tpc);
8332+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
8333+ if (err)
8334+ break;
8335+
8336+ if (save == 0x9DE3BFA8U &&
8337+ (call & 0xC0000000U) == 0x40000000U &&
8338+ nop == 0x01000000U)
8339+ {
8340+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
8341+
8342+ if (test_thread_flag(TIF_32BIT))
8343+ dl_resolve &= 0xFFFFFFFFUL;
8344+
8345+ regs->u_regs[UREG_RETPC] = regs->tpc;
8346+ regs->tpc = dl_resolve;
8347+ regs->tnpc = dl_resolve+4;
8348+ return 3;
8349+ }
8350+ } while (0);
8351+#endif
8352+
8353+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
8354+ unsigned int sethi, ba, nop;
8355+
8356+ err = get_user(sethi, (unsigned int *)regs->tpc);
8357+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
8358+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
8359+
8360+ if (err)
8361+ break;
8362+
8363+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
8364+ (ba & 0xFFF00000U) == 0x30600000U &&
8365+ nop == 0x01000000U)
8366+ {
8367+ unsigned long addr;
8368+
8369+ addr = (sethi & 0x003FFFFFU) << 10;
8370+ regs->u_regs[UREG_G1] = addr;
8371+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
8372+
8373+ if (test_thread_flag(TIF_32BIT))
8374+ addr &= 0xFFFFFFFFUL;
8375+
8376+ regs->tpc = addr;
8377+ regs->tnpc = addr+4;
8378+ return 2;
8379+ }
8380+ } while (0);
8381+
8382+#endif
8383+
8384+ return 1;
8385+}
8386+
8387+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
8388+{
8389+ unsigned long i;
8390+
8391+ printk(KERN_ERR "PAX: bytes at PC: ");
8392+ for (i = 0; i < 8; i++) {
8393+ unsigned int c;
8394+ if (get_user(c, (unsigned int *)pc+i))
8395+ printk(KERN_CONT "???????? ");
8396+ else
8397+ printk(KERN_CONT "%08x ", c);
8398+ }
8399+ printk("\n");
8400+}
8401+#endif
8402+
8403 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
8404 {
8405 struct mm_struct *mm = current->mm;
8406@@ -341,6 +804,29 @@ retry:
8407 if (!vma)
8408 goto bad_area;
8409
8410+#ifdef CONFIG_PAX_PAGEEXEC
8411+ /* PaX: detect ITLB misses on non-exec pages */
8412+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
8413+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
8414+ {
8415+ if (address != regs->tpc)
8416+ goto good_area;
8417+
8418+ up_read(&mm->mmap_sem);
8419+ switch (pax_handle_fetch_fault(regs)) {
8420+
8421+#ifdef CONFIG_PAX_EMUPLT
8422+ case 2:
8423+ case 3:
8424+ return;
8425+#endif
8426+
8427+ }
8428+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
8429+ do_group_exit(SIGKILL);
8430+ }
8431+#endif
8432+
8433 /* Pure DTLB misses do not tell us whether the fault causing
8434 * load/store/atomic was a write or not, it only says that there
8435 * was no match. So in such a case we (carefully) read the
8436diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
8437index f76f83d..ee0d859 100644
8438--- a/arch/sparc/mm/hugetlbpage.c
8439+++ b/arch/sparc/mm/hugetlbpage.c
8440@@ -34,6 +34,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
8441 struct vm_area_struct * vma;
8442 unsigned long task_size = TASK_SIZE;
8443 unsigned long start_addr;
8444+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8445
8446 if (test_thread_flag(TIF_32BIT))
8447 task_size = STACK_TOP32;
8448@@ -67,7 +68,7 @@ full_search:
8449 }
8450 return -ENOMEM;
8451 }
8452- if (likely(!vma || addr + len <= vma->vm_start)) {
8453+ if (likely(check_heap_stack_gap(vma, addr, len, offset))) {
8454 /*
8455 * Remember the place where we stopped the search:
8456 */
8457@@ -90,6 +91,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8458 struct vm_area_struct *vma;
8459 struct mm_struct *mm = current->mm;
8460 unsigned long addr = addr0;
8461+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8462
8463 /* This should only ever run for 32-bit processes. */
8464 BUG_ON(!test_thread_flag(TIF_32BIT));
8465@@ -106,7 +108,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8466 /* make sure it can fit in the remaining address space */
8467 if (likely(addr > len)) {
8468 vma = find_vma(mm, addr-len);
8469- if (!vma || addr <= vma->vm_start) {
8470+ if (check_heap_stack_gap(vma, addr - len, len, offset)) {
8471 /* remember the address as a hint for next time */
8472 return (mm->free_area_cache = addr-len);
8473 }
8474@@ -115,16 +117,17 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8475 if (unlikely(mm->mmap_base < len))
8476 goto bottomup;
8477
8478- addr = (mm->mmap_base-len) & HPAGE_MASK;
8479+ addr = mm->mmap_base - len;
8480
8481 do {
8482+ addr &= HPAGE_MASK;
8483 /*
8484 * Lookup failure means no vma is above this address,
8485 * else if new region fits below vma->vm_start,
8486 * return with success:
8487 */
8488 vma = find_vma(mm, addr);
8489- if (likely(!vma || addr+len <= vma->vm_start)) {
8490+ if (likely(check_heap_stack_gap(vma, addr, len, offset))) {
8491 /* remember the address as a hint for next time */
8492 return (mm->free_area_cache = addr);
8493 }
8494@@ -134,8 +137,8 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8495 mm->cached_hole_size = vma->vm_start - addr;
8496
8497 /* try just below the current vma->vm_start */
8498- addr = (vma->vm_start-len) & HPAGE_MASK;
8499- } while (likely(len < vma->vm_start));
8500+ addr = skip_heap_stack_gap(vma, len, offset);
8501+ } while (!IS_ERR_VALUE(addr));
8502
8503 bottomup:
8504 /*
8505@@ -163,6 +166,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
8506 struct mm_struct *mm = current->mm;
8507 struct vm_area_struct *vma;
8508 unsigned long task_size = TASK_SIZE;
8509+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8510
8511 if (test_thread_flag(TIF_32BIT))
8512 task_size = STACK_TOP32;
8513@@ -181,8 +185,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
8514 if (addr) {
8515 addr = ALIGN(addr, HPAGE_SIZE);
8516 vma = find_vma(mm, addr);
8517- if (task_size - len >= addr &&
8518- (!vma || addr + len <= vma->vm_start))
8519+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8520 return addr;
8521 }
8522 if (mm->get_unmapped_area == arch_get_unmapped_area)
8523diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
8524index f4500c6..889656c 100644
8525--- a/arch/tile/include/asm/atomic_64.h
8526+++ b/arch/tile/include/asm/atomic_64.h
8527@@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
8528
8529 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
8530
8531+#define atomic64_read_unchecked(v) atomic64_read(v)
8532+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
8533+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
8534+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
8535+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
8536+#define atomic64_inc_unchecked(v) atomic64_inc(v)
8537+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
8538+#define atomic64_dec_unchecked(v) atomic64_dec(v)
8539+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
8540+
8541 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
8542 #define smp_mb__before_atomic_dec() smp_mb()
8543 #define smp_mb__after_atomic_dec() smp_mb()
8544diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
8545index a9a5299..0fce79e 100644
8546--- a/arch/tile/include/asm/cache.h
8547+++ b/arch/tile/include/asm/cache.h
8548@@ -15,11 +15,12 @@
8549 #ifndef _ASM_TILE_CACHE_H
8550 #define _ASM_TILE_CACHE_H
8551
8552+#include <linux/const.h>
8553 #include <arch/chip.h>
8554
8555 /* bytes per L1 data cache line */
8556 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
8557-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8558+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8559
8560 /* bytes per L2 cache line */
8561 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
8562diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
8563index 9ab078a..d6635c2 100644
8564--- a/arch/tile/include/asm/uaccess.h
8565+++ b/arch/tile/include/asm/uaccess.h
8566@@ -403,9 +403,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
8567 const void __user *from,
8568 unsigned long n)
8569 {
8570- int sz = __compiletime_object_size(to);
8571+ size_t sz = __compiletime_object_size(to);
8572
8573- if (likely(sz == -1 || sz >= n))
8574+ if (likely(sz == (size_t)-1 || sz >= n))
8575 n = _copy_from_user(to, from, n);
8576 else
8577 copy_from_user_overflow();
8578diff --git a/arch/um/Makefile b/arch/um/Makefile
8579index 133f7de..1d6f2f1 100644
8580--- a/arch/um/Makefile
8581+++ b/arch/um/Makefile
8582@@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
8583 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
8584 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
8585
8586+ifdef CONSTIFY_PLUGIN
8587+USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
8588+endif
8589+
8590 #This will adjust *FLAGS accordingly to the platform.
8591 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
8592
8593diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
8594index 19e1bdd..3665b77 100644
8595--- a/arch/um/include/asm/cache.h
8596+++ b/arch/um/include/asm/cache.h
8597@@ -1,6 +1,7 @@
8598 #ifndef __UM_CACHE_H
8599 #define __UM_CACHE_H
8600
8601+#include <linux/const.h>
8602
8603 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
8604 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
8605@@ -12,6 +13,6 @@
8606 # define L1_CACHE_SHIFT 5
8607 #endif
8608
8609-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8610+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8611
8612 #endif
8613diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
8614index 2e0a6b1..a64d0f5 100644
8615--- a/arch/um/include/asm/kmap_types.h
8616+++ b/arch/um/include/asm/kmap_types.h
8617@@ -8,6 +8,6 @@
8618
8619 /* No more #include "asm/arch/kmap_types.h" ! */
8620
8621-#define KM_TYPE_NR 14
8622+#define KM_TYPE_NR 15
8623
8624 #endif
8625diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
8626index 5ff53d9..5850cdf 100644
8627--- a/arch/um/include/asm/page.h
8628+++ b/arch/um/include/asm/page.h
8629@@ -14,6 +14,9 @@
8630 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
8631 #define PAGE_MASK (~(PAGE_SIZE-1))
8632
8633+#define ktla_ktva(addr) (addr)
8634+#define ktva_ktla(addr) (addr)
8635+
8636 #ifndef __ASSEMBLY__
8637
8638 struct page;
8639diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
8640index 0032f92..cd151e0 100644
8641--- a/arch/um/include/asm/pgtable-3level.h
8642+++ b/arch/um/include/asm/pgtable-3level.h
8643@@ -58,6 +58,7 @@
8644 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
8645 #define pud_populate(mm, pud, pmd) \
8646 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
8647+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
8648
8649 #ifdef CONFIG_64BIT
8650 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
8651diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
8652index b6d699c..df7ac1d 100644
8653--- a/arch/um/kernel/process.c
8654+++ b/arch/um/kernel/process.c
8655@@ -387,22 +387,6 @@ int singlestepping(void * t)
8656 return 2;
8657 }
8658
8659-/*
8660- * Only x86 and x86_64 have an arch_align_stack().
8661- * All other arches have "#define arch_align_stack(x) (x)"
8662- * in their asm/system.h
8663- * As this is included in UML from asm-um/system-generic.h,
8664- * we can use it to behave as the subarch does.
8665- */
8666-#ifndef arch_align_stack
8667-unsigned long arch_align_stack(unsigned long sp)
8668-{
8669- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8670- sp -= get_random_int() % 8192;
8671- return sp & ~0xf;
8672-}
8673-#endif
8674-
8675 unsigned long get_wchan(struct task_struct *p)
8676 {
8677 unsigned long stack_page, sp, ip;
8678diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
8679index ad8f795..2c7eec6 100644
8680--- a/arch/unicore32/include/asm/cache.h
8681+++ b/arch/unicore32/include/asm/cache.h
8682@@ -12,8 +12,10 @@
8683 #ifndef __UNICORE_CACHE_H__
8684 #define __UNICORE_CACHE_H__
8685
8686-#define L1_CACHE_SHIFT (5)
8687-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8688+#include <linux/const.h>
8689+
8690+#define L1_CACHE_SHIFT 5
8691+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8692
8693 /*
8694 * Memory returned by kmalloc() may be used for DMA, so we must make
8695diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
8696index 46c3bff..b82f26b 100644
8697--- a/arch/x86/Kconfig
8698+++ b/arch/x86/Kconfig
8699@@ -241,7 +241,7 @@ config X86_HT
8700
8701 config X86_32_LAZY_GS
8702 def_bool y
8703- depends on X86_32 && !CC_STACKPROTECTOR
8704+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
8705
8706 config ARCH_HWEIGHT_CFLAGS
8707 string
8708@@ -1033,6 +1033,7 @@ config MICROCODE_OLD_INTERFACE
8709
8710 config X86_MSR
8711 tristate "/dev/cpu/*/msr - Model-specific register support"
8712+ depends on !GRKERNSEC_KMEM
8713 ---help---
8714 This device gives privileged processes access to the x86
8715 Model-Specific Registers (MSRs). It is a character device with
8716@@ -1056,7 +1057,7 @@ choice
8717
8718 config NOHIGHMEM
8719 bool "off"
8720- depends on !X86_NUMAQ
8721+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
8722 ---help---
8723 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
8724 However, the address space of 32-bit x86 processors is only 4
8725@@ -1093,7 +1094,7 @@ config NOHIGHMEM
8726
8727 config HIGHMEM4G
8728 bool "4GB"
8729- depends on !X86_NUMAQ
8730+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
8731 ---help---
8732 Select this if you have a 32-bit processor and between 1 and 4
8733 gigabytes of physical RAM.
8734@@ -1147,7 +1148,7 @@ config PAGE_OFFSET
8735 hex
8736 default 0xB0000000 if VMSPLIT_3G_OPT
8737 default 0x80000000 if VMSPLIT_2G
8738- default 0x78000000 if VMSPLIT_2G_OPT
8739+ default 0x70000000 if VMSPLIT_2G_OPT
8740 default 0x40000000 if VMSPLIT_1G
8741 default 0xC0000000
8742 depends on X86_32
8743@@ -1548,6 +1549,7 @@ config SECCOMP
8744
8745 config CC_STACKPROTECTOR
8746 bool "Enable -fstack-protector buffer overflow detection"
8747+ depends on X86_64 || !PAX_MEMORY_UDEREF
8748 ---help---
8749 This option turns on the -fstack-protector GCC feature. This
8750 feature puts, at the beginning of functions, a canary value on
8751@@ -1605,6 +1607,7 @@ config KEXEC_JUMP
8752 config PHYSICAL_START
8753 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
8754 default "0x1000000"
8755+ range 0x400000 0x40000000
8756 ---help---
8757 This gives the physical address where the kernel is loaded.
8758
8759@@ -1668,6 +1671,7 @@ config X86_NEED_RELOCS
8760 config PHYSICAL_ALIGN
8761 hex "Alignment value to which kernel should be aligned" if X86_32
8762 default "0x1000000"
8763+ range 0x400000 0x1000000 if PAX_KERNEXEC
8764 range 0x2000 0x1000000
8765 ---help---
8766 This value puts the alignment restrictions on physical address
8767@@ -1699,9 +1703,10 @@ config HOTPLUG_CPU
8768 Say N if you want to disable CPU hotplug.
8769
8770 config COMPAT_VDSO
8771- def_bool y
8772+ def_bool n
8773 prompt "Compat VDSO support"
8774 depends on X86_32 || IA32_EMULATION
8775+ depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
8776 ---help---
8777 Map the 32-bit VDSO to the predictable old-style address too.
8778
8779diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
8780index f3b86d0..17fd30f 100644
8781--- a/arch/x86/Kconfig.cpu
8782+++ b/arch/x86/Kconfig.cpu
8783@@ -335,7 +335,7 @@ config X86_PPRO_FENCE
8784
8785 config X86_F00F_BUG
8786 def_bool y
8787- depends on M586MMX || M586TSC || M586 || M486 || M386
8788+ depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
8789
8790 config X86_INVD_BUG
8791 def_bool y
8792@@ -359,7 +359,7 @@ config X86_POPAD_OK
8793
8794 config X86_ALIGNMENT_16
8795 def_bool y
8796- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
8797+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
8798
8799 config X86_INTEL_USERCOPY
8800 def_bool y
8801@@ -405,7 +405,7 @@ config X86_CMPXCHG64
8802 # generates cmov.
8803 config X86_CMOV
8804 def_bool y
8805- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
8806+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
8807
8808 config X86_MINIMUM_CPU_FAMILY
8809 int
8810diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
8811index b322f12..652d0d9 100644
8812--- a/arch/x86/Kconfig.debug
8813+++ b/arch/x86/Kconfig.debug
8814@@ -84,7 +84,7 @@ config X86_PTDUMP
8815 config DEBUG_RODATA
8816 bool "Write protect kernel read-only data structures"
8817 default y
8818- depends on DEBUG_KERNEL
8819+ depends on DEBUG_KERNEL && BROKEN
8820 ---help---
8821 Mark the kernel read-only data as write-protected in the pagetables,
8822 in order to catch accidental (and incorrect) writes to such const
8823@@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
8824
8825 config DEBUG_SET_MODULE_RONX
8826 bool "Set loadable kernel module data as NX and text as RO"
8827- depends on MODULES
8828+ depends on MODULES && BROKEN
8829 ---help---
8830 This option helps catch unintended modifications to loadable
8831 kernel module's text and read-only data. It also prevents execution
8832@@ -294,7 +294,7 @@ config OPTIMIZE_INLINING
8833
8834 config DEBUG_STRICT_USER_COPY_CHECKS
8835 bool "Strict copy size checks"
8836- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
8837+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
8838 ---help---
8839 Enabling this option turns a certain set of sanity checks for user
8840 copy operations into compile time failures.
8841diff --git a/arch/x86/Makefile b/arch/x86/Makefile
8842index 05afcca..b6ecb51 100644
8843--- a/arch/x86/Makefile
8844+++ b/arch/x86/Makefile
8845@@ -50,6 +50,7 @@ else
8846 UTS_MACHINE := x86_64
8847 CHECKFLAGS += -D__x86_64__ -m64
8848
8849+ biarch := $(call cc-option,-m64)
8850 KBUILD_AFLAGS += -m64
8851 KBUILD_CFLAGS += -m64
8852
8853@@ -229,3 +230,12 @@ define archhelp
8854 echo ' FDARGS="..." arguments for the booted kernel'
8855 echo ' FDINITRD=file initrd for the booted kernel'
8856 endef
8857+
8858+define OLD_LD
8859+
8860+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
8861+*** Please upgrade your binutils to 2.18 or newer
8862+endef
8863+
8864+archprepare:
8865+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
8866diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
8867index ccce0ed..fd9da25 100644
8868--- a/arch/x86/boot/Makefile
8869+++ b/arch/x86/boot/Makefile
8870@@ -65,6 +65,9 @@ KBUILD_CFLAGS := $(USERINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
8871 $(call cc-option, -fno-stack-protector) \
8872 $(call cc-option, -mpreferred-stack-boundary=2)
8873 KBUILD_CFLAGS += $(call cc-option, -m32)
8874+ifdef CONSTIFY_PLUGIN
8875+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
8876+endif
8877 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
8878 GCOV_PROFILE := n
8879
8880diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
8881index 878e4b9..20537ab 100644
8882--- a/arch/x86/boot/bitops.h
8883+++ b/arch/x86/boot/bitops.h
8884@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
8885 u8 v;
8886 const u32 *p = (const u32 *)addr;
8887
8888- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
8889+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
8890 return v;
8891 }
8892
8893@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
8894
8895 static inline void set_bit(int nr, void *addr)
8896 {
8897- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
8898+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
8899 }
8900
8901 #endif /* BOOT_BITOPS_H */
8902diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
8903index 18997e5..83d9c67 100644
8904--- a/arch/x86/boot/boot.h
8905+++ b/arch/x86/boot/boot.h
8906@@ -85,7 +85,7 @@ static inline void io_delay(void)
8907 static inline u16 ds(void)
8908 {
8909 u16 seg;
8910- asm("movw %%ds,%0" : "=rm" (seg));
8911+ asm volatile("movw %%ds,%0" : "=rm" (seg));
8912 return seg;
8913 }
8914
8915@@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
8916 static inline int memcmp(const void *s1, const void *s2, size_t len)
8917 {
8918 u8 diff;
8919- asm("repe; cmpsb; setnz %0"
8920+ asm volatile("repe; cmpsb; setnz %0"
8921 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
8922 return diff;
8923 }
8924diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
8925index 8a84501..b2d165f 100644
8926--- a/arch/x86/boot/compressed/Makefile
8927+++ b/arch/x86/boot/compressed/Makefile
8928@@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
8929 KBUILD_CFLAGS += $(cflags-y)
8930 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
8931 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
8932+ifdef CONSTIFY_PLUGIN
8933+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
8934+endif
8935
8936 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
8937 GCOV_PROFILE := n
8938diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
8939index ccae7e2..8ac70be 100644
8940--- a/arch/x86/boot/compressed/eboot.c
8941+++ b/arch/x86/boot/compressed/eboot.c
8942@@ -144,7 +144,6 @@ again:
8943 *addr = max_addr;
8944 }
8945
8946-free_pool:
8947 efi_call_phys1(sys_table->boottime->free_pool, map);
8948
8949 fail:
8950@@ -208,7 +207,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
8951 if (i == map_size / desc_size)
8952 status = EFI_NOT_FOUND;
8953
8954-free_pool:
8955 efi_call_phys1(sys_table->boottime->free_pool, map);
8956 fail:
8957 return status;
8958diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
8959index ccb2f4a..e49b20e 100644
8960--- a/arch/x86/boot/compressed/head_32.S
8961+++ b/arch/x86/boot/compressed/head_32.S
8962@@ -118,7 +118,7 @@ preferred_addr:
8963 notl %eax
8964 andl %eax, %ebx
8965 #else
8966- movl $LOAD_PHYSICAL_ADDR, %ebx
8967+ movl $____LOAD_PHYSICAL_ADDR, %ebx
8968 #endif
8969
8970 /* Target address to relocate to for decompression */
8971@@ -204,7 +204,7 @@ relocated:
8972 * and where it was actually loaded.
8973 */
8974 movl %ebp, %ebx
8975- subl $LOAD_PHYSICAL_ADDR, %ebx
8976+ subl $____LOAD_PHYSICAL_ADDR, %ebx
8977 jz 2f /* Nothing to be done if loaded at compiled addr. */
8978 /*
8979 * Process relocations.
8980@@ -212,8 +212,7 @@ relocated:
8981
8982 1: subl $4, %edi
8983 movl (%edi), %ecx
8984- testl %ecx, %ecx
8985- jz 2f
8986+ jecxz 2f
8987 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
8988 jmp 1b
8989 2:
8990diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
8991index 2c4b171..e1fa5b1 100644
8992--- a/arch/x86/boot/compressed/head_64.S
8993+++ b/arch/x86/boot/compressed/head_64.S
8994@@ -91,7 +91,7 @@ ENTRY(startup_32)
8995 notl %eax
8996 andl %eax, %ebx
8997 #else
8998- movl $LOAD_PHYSICAL_ADDR, %ebx
8999+ movl $____LOAD_PHYSICAL_ADDR, %ebx
9000 #endif
9001
9002 /* Target address to relocate to for decompression */
9003@@ -273,7 +273,7 @@ preferred_addr:
9004 notq %rax
9005 andq %rax, %rbp
9006 #else
9007- movq $LOAD_PHYSICAL_ADDR, %rbp
9008+ movq $____LOAD_PHYSICAL_ADDR, %rbp
9009 #endif
9010
9011 /* Target address to relocate to for decompression */
9012diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
9013index 88f7ff6..ed695dd 100644
9014--- a/arch/x86/boot/compressed/misc.c
9015+++ b/arch/x86/boot/compressed/misc.c
9016@@ -303,7 +303,7 @@ static void parse_elf(void *output)
9017 case PT_LOAD:
9018 #ifdef CONFIG_RELOCATABLE
9019 dest = output;
9020- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
9021+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
9022 #else
9023 dest = (void *)(phdr->p_paddr);
9024 #endif
9025@@ -352,7 +352,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
9026 error("Destination address too large");
9027 #endif
9028 #ifndef CONFIG_RELOCATABLE
9029- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
9030+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
9031 error("Wrong destination address");
9032 #endif
9033
9034diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
9035index 4d3ff03..e4972ff 100644
9036--- a/arch/x86/boot/cpucheck.c
9037+++ b/arch/x86/boot/cpucheck.c
9038@@ -74,7 +74,7 @@ static int has_fpu(void)
9039 u16 fcw = -1, fsw = -1;
9040 u32 cr0;
9041
9042- asm("movl %%cr0,%0" : "=r" (cr0));
9043+ asm volatile("movl %%cr0,%0" : "=r" (cr0));
9044 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
9045 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
9046 asm volatile("movl %0,%%cr0" : : "r" (cr0));
9047@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
9048 {
9049 u32 f0, f1;
9050
9051- asm("pushfl ; "
9052+ asm volatile("pushfl ; "
9053 "pushfl ; "
9054 "popl %0 ; "
9055 "movl %0,%1 ; "
9056@@ -115,7 +115,7 @@ static void get_flags(void)
9057 set_bit(X86_FEATURE_FPU, cpu.flags);
9058
9059 if (has_eflag(X86_EFLAGS_ID)) {
9060- asm("cpuid"
9061+ asm volatile("cpuid"
9062 : "=a" (max_intel_level),
9063 "=b" (cpu_vendor[0]),
9064 "=d" (cpu_vendor[1]),
9065@@ -124,7 +124,7 @@ static void get_flags(void)
9066
9067 if (max_intel_level >= 0x00000001 &&
9068 max_intel_level <= 0x0000ffff) {
9069- asm("cpuid"
9070+ asm volatile("cpuid"
9071 : "=a" (tfms),
9072 "=c" (cpu.flags[4]),
9073 "=d" (cpu.flags[0])
9074@@ -136,7 +136,7 @@ static void get_flags(void)
9075 cpu.model += ((tfms >> 16) & 0xf) << 4;
9076 }
9077
9078- asm("cpuid"
9079+ asm volatile("cpuid"
9080 : "=a" (max_amd_level)
9081 : "a" (0x80000000)
9082 : "ebx", "ecx", "edx");
9083@@ -144,7 +144,7 @@ static void get_flags(void)
9084 if (max_amd_level >= 0x80000001 &&
9085 max_amd_level <= 0x8000ffff) {
9086 u32 eax = 0x80000001;
9087- asm("cpuid"
9088+ asm volatile("cpuid"
9089 : "+a" (eax),
9090 "=c" (cpu.flags[6]),
9091 "=d" (cpu.flags[1])
9092@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
9093 u32 ecx = MSR_K7_HWCR;
9094 u32 eax, edx;
9095
9096- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
9097+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
9098 eax &= ~(1 << 15);
9099- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
9100+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
9101
9102 get_flags(); /* Make sure it really did something */
9103 err = check_flags();
9104@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
9105 u32 ecx = MSR_VIA_FCR;
9106 u32 eax, edx;
9107
9108- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
9109+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
9110 eax |= (1<<1)|(1<<7);
9111- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
9112+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
9113
9114 set_bit(X86_FEATURE_CX8, cpu.flags);
9115 err = check_flags();
9116@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
9117 u32 eax, edx;
9118 u32 level = 1;
9119
9120- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
9121- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
9122- asm("cpuid"
9123+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
9124+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
9125+ asm volatile("cpuid"
9126 : "+a" (level), "=d" (cpu.flags[0])
9127 : : "ecx", "ebx");
9128- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
9129+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
9130
9131 err = check_flags();
9132 }
9133diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
9134index 8c132a6..13e5c96 100644
9135--- a/arch/x86/boot/header.S
9136+++ b/arch/x86/boot/header.S
9137@@ -387,10 +387,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
9138 # single linked list of
9139 # struct setup_data
9140
9141-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
9142+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
9143
9144 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
9145+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
9146+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
9147+#else
9148 #define VO_INIT_SIZE (VO__end - VO__text)
9149+#endif
9150 #if ZO_INIT_SIZE > VO_INIT_SIZE
9151 #define INIT_SIZE ZO_INIT_SIZE
9152 #else
9153diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
9154index db75d07..8e6d0af 100644
9155--- a/arch/x86/boot/memory.c
9156+++ b/arch/x86/boot/memory.c
9157@@ -19,7 +19,7 @@
9158
9159 static int detect_memory_e820(void)
9160 {
9161- int count = 0;
9162+ unsigned int count = 0;
9163 struct biosregs ireg, oreg;
9164 struct e820entry *desc = boot_params.e820_map;
9165 static struct e820entry buf; /* static so it is zeroed */
9166diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
9167index 11e8c6e..fdbb1ed 100644
9168--- a/arch/x86/boot/video-vesa.c
9169+++ b/arch/x86/boot/video-vesa.c
9170@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
9171
9172 boot_params.screen_info.vesapm_seg = oreg.es;
9173 boot_params.screen_info.vesapm_off = oreg.di;
9174+ boot_params.screen_info.vesapm_size = oreg.cx;
9175 }
9176
9177 /*
9178diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
9179index 43eda28..5ab5fdb 100644
9180--- a/arch/x86/boot/video.c
9181+++ b/arch/x86/boot/video.c
9182@@ -96,7 +96,7 @@ static void store_mode_params(void)
9183 static unsigned int get_entry(void)
9184 {
9185 char entry_buf[4];
9186- int i, len = 0;
9187+ unsigned int i, len = 0;
9188 int key;
9189 unsigned int v;
9190
9191diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
9192index 5b577d5..3c1fed4 100644
9193--- a/arch/x86/crypto/aes-x86_64-asm_64.S
9194+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
9195@@ -8,6 +8,8 @@
9196 * including this sentence is retained in full.
9197 */
9198
9199+#include <asm/alternative-asm.h>
9200+
9201 .extern crypto_ft_tab
9202 .extern crypto_it_tab
9203 .extern crypto_fl_tab
9204@@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
9205 je B192; \
9206 leaq 32(r9),r9;
9207
9208+#define ret pax_force_retaddr 0, 1; ret
9209+
9210 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
9211 movq r1,r2; \
9212 movq r3,r4; \
9213diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
9214index 3470624..201259d 100644
9215--- a/arch/x86/crypto/aesni-intel_asm.S
9216+++ b/arch/x86/crypto/aesni-intel_asm.S
9217@@ -31,6 +31,7 @@
9218
9219 #include <linux/linkage.h>
9220 #include <asm/inst.h>
9221+#include <asm/alternative-asm.h>
9222
9223 #ifdef __x86_64__
9224 .data
9225@@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
9226 pop %r14
9227 pop %r13
9228 pop %r12
9229+ pax_force_retaddr 0, 1
9230 ret
9231+ENDPROC(aesni_gcm_dec)
9232
9233
9234 /*****************************************************************************
9235@@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
9236 pop %r14
9237 pop %r13
9238 pop %r12
9239+ pax_force_retaddr 0, 1
9240 ret
9241+ENDPROC(aesni_gcm_enc)
9242
9243 #endif
9244
9245@@ -1714,6 +1719,7 @@ _key_expansion_256a:
9246 pxor %xmm1, %xmm0
9247 movaps %xmm0, (TKEYP)
9248 add $0x10, TKEYP
9249+ pax_force_retaddr_bts
9250 ret
9251
9252 .align 4
9253@@ -1738,6 +1744,7 @@ _key_expansion_192a:
9254 shufps $0b01001110, %xmm2, %xmm1
9255 movaps %xmm1, 0x10(TKEYP)
9256 add $0x20, TKEYP
9257+ pax_force_retaddr_bts
9258 ret
9259
9260 .align 4
9261@@ -1757,6 +1764,7 @@ _key_expansion_192b:
9262
9263 movaps %xmm0, (TKEYP)
9264 add $0x10, TKEYP
9265+ pax_force_retaddr_bts
9266 ret
9267
9268 .align 4
9269@@ -1769,6 +1777,7 @@ _key_expansion_256b:
9270 pxor %xmm1, %xmm2
9271 movaps %xmm2, (TKEYP)
9272 add $0x10, TKEYP
9273+ pax_force_retaddr_bts
9274 ret
9275
9276 /*
9277@@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
9278 #ifndef __x86_64__
9279 popl KEYP
9280 #endif
9281+ pax_force_retaddr 0, 1
9282 ret
9283+ENDPROC(aesni_set_key)
9284
9285 /*
9286 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
9287@@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
9288 popl KLEN
9289 popl KEYP
9290 #endif
9291+ pax_force_retaddr 0, 1
9292 ret
9293+ENDPROC(aesni_enc)
9294
9295 /*
9296 * _aesni_enc1: internal ABI
9297@@ -1959,6 +1972,7 @@ _aesni_enc1:
9298 AESENC KEY STATE
9299 movaps 0x70(TKEYP), KEY
9300 AESENCLAST KEY STATE
9301+ pax_force_retaddr_bts
9302 ret
9303
9304 /*
9305@@ -2067,6 +2081,7 @@ _aesni_enc4:
9306 AESENCLAST KEY STATE2
9307 AESENCLAST KEY STATE3
9308 AESENCLAST KEY STATE4
9309+ pax_force_retaddr_bts
9310 ret
9311
9312 /*
9313@@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
9314 popl KLEN
9315 popl KEYP
9316 #endif
9317+ pax_force_retaddr 0, 1
9318 ret
9319+ENDPROC(aesni_dec)
9320
9321 /*
9322 * _aesni_dec1: internal ABI
9323@@ -2146,6 +2163,7 @@ _aesni_dec1:
9324 AESDEC KEY STATE
9325 movaps 0x70(TKEYP), KEY
9326 AESDECLAST KEY STATE
9327+ pax_force_retaddr_bts
9328 ret
9329
9330 /*
9331@@ -2254,6 +2272,7 @@ _aesni_dec4:
9332 AESDECLAST KEY STATE2
9333 AESDECLAST KEY STATE3
9334 AESDECLAST KEY STATE4
9335+ pax_force_retaddr_bts
9336 ret
9337
9338 /*
9339@@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
9340 popl KEYP
9341 popl LEN
9342 #endif
9343+ pax_force_retaddr 0, 1
9344 ret
9345+ENDPROC(aesni_ecb_enc)
9346
9347 /*
9348 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
9349@@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
9350 popl KEYP
9351 popl LEN
9352 #endif
9353+ pax_force_retaddr 0, 1
9354 ret
9355+ENDPROC(aesni_ecb_dec)
9356
9357 /*
9358 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
9359@@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
9360 popl LEN
9361 popl IVP
9362 #endif
9363+ pax_force_retaddr 0, 1
9364 ret
9365+ENDPROC(aesni_cbc_enc)
9366
9367 /*
9368 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
9369@@ -2500,7 +2525,9 @@ ENTRY(aesni_cbc_dec)
9370 popl LEN
9371 popl IVP
9372 #endif
9373+ pax_force_retaddr 0, 1
9374 ret
9375+ENDPROC(aesni_cbc_dec)
9376
9377 #ifdef __x86_64__
9378 .align 16
9379@@ -2526,6 +2553,7 @@ _aesni_inc_init:
9380 mov $1, TCTR_LOW
9381 MOVQ_R64_XMM TCTR_LOW INC
9382 MOVQ_R64_XMM CTR TCTR_LOW
9383+ pax_force_retaddr_bts
9384 ret
9385
9386 /*
9387@@ -2554,6 +2582,7 @@ _aesni_inc:
9388 .Linc_low:
9389 movaps CTR, IV
9390 PSHUFB_XMM BSWAP_MASK IV
9391+ pax_force_retaddr_bts
9392 ret
9393
9394 /*
9395@@ -2614,5 +2643,7 @@ ENTRY(aesni_ctr_enc)
9396 .Lctr_enc_ret:
9397 movups IV, (IVP)
9398 .Lctr_enc_just_ret:
9399+ pax_force_retaddr 0, 1
9400 ret
9401+ENDPROC(aesni_ctr_enc)
9402 #endif
9403diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
9404index 391d245..67f35c2 100644
9405--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
9406+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
9407@@ -20,6 +20,8 @@
9408 *
9409 */
9410
9411+#include <asm/alternative-asm.h>
9412+
9413 .file "blowfish-x86_64-asm.S"
9414 .text
9415
9416@@ -151,9 +153,11 @@ __blowfish_enc_blk:
9417 jnz __enc_xor;
9418
9419 write_block();
9420+ pax_force_retaddr 0, 1
9421 ret;
9422 __enc_xor:
9423 xor_block();
9424+ pax_force_retaddr 0, 1
9425 ret;
9426
9427 .align 8
9428@@ -188,6 +192,7 @@ blowfish_dec_blk:
9429
9430 movq %r11, %rbp;
9431
9432+ pax_force_retaddr 0, 1
9433 ret;
9434
9435 /**********************************************************************
9436@@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
9437
9438 popq %rbx;
9439 popq %rbp;
9440+ pax_force_retaddr 0, 1
9441 ret;
9442
9443 __enc_xor4:
9444@@ -349,6 +355,7 @@ __enc_xor4:
9445
9446 popq %rbx;
9447 popq %rbp;
9448+ pax_force_retaddr 0, 1
9449 ret;
9450
9451 .align 8
9452@@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
9453 popq %rbx;
9454 popq %rbp;
9455
9456+ pax_force_retaddr 0, 1
9457 ret;
9458
9459diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
9460index 0b33743..7a56206 100644
9461--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
9462+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
9463@@ -20,6 +20,8 @@
9464 *
9465 */
9466
9467+#include <asm/alternative-asm.h>
9468+
9469 .file "camellia-x86_64-asm_64.S"
9470 .text
9471
9472@@ -229,12 +231,14 @@ __enc_done:
9473 enc_outunpack(mov, RT1);
9474
9475 movq RRBP, %rbp;
9476+ pax_force_retaddr 0, 1
9477 ret;
9478
9479 __enc_xor:
9480 enc_outunpack(xor, RT1);
9481
9482 movq RRBP, %rbp;
9483+ pax_force_retaddr 0, 1
9484 ret;
9485
9486 .global camellia_dec_blk;
9487@@ -275,6 +279,7 @@ __dec_rounds16:
9488 dec_outunpack();
9489
9490 movq RRBP, %rbp;
9491+ pax_force_retaddr 0, 1
9492 ret;
9493
9494 /**********************************************************************
9495@@ -468,6 +473,7 @@ __enc2_done:
9496
9497 movq RRBP, %rbp;
9498 popq %rbx;
9499+ pax_force_retaddr 0, 1
9500 ret;
9501
9502 __enc2_xor:
9503@@ -475,6 +481,7 @@ __enc2_xor:
9504
9505 movq RRBP, %rbp;
9506 popq %rbx;
9507+ pax_force_retaddr 0, 1
9508 ret;
9509
9510 .global camellia_dec_blk_2way;
9511@@ -517,4 +524,5 @@ __dec2_rounds16:
9512
9513 movq RRBP, %rbp;
9514 movq RXOR, %rbx;
9515+ pax_force_retaddr 0, 1
9516 ret;
9517diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
9518index a41a3aa..bdf5753 100644
9519--- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
9520+++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
9521@@ -23,6 +23,8 @@
9522 *
9523 */
9524
9525+#include <asm/alternative-asm.h>
9526+
9527 .file "cast5-avx-x86_64-asm_64.S"
9528
9529 .extern cast5_s1
9530@@ -293,6 +295,7 @@ __skip_enc:
9531 leaq 3*(2*4*4)(%r11), %rax;
9532 outunpack_blocks(%rax, RR4, RL4, RTMP, RX, RKM);
9533
9534+ pax_force_retaddr 0, 1
9535 ret;
9536
9537 __enc_xor16:
9538@@ -303,6 +306,7 @@ __enc_xor16:
9539 leaq 3*(2*4*4)(%r11), %rax;
9540 outunpack_xor_blocks(%rax, RR4, RL4, RTMP, RX, RKM);
9541
9542+ pax_force_retaddr 0, 1
9543 ret;
9544
9545 .align 16
9546@@ -369,6 +373,7 @@ __dec_tail:
9547 leaq 3*(2*4*4)(%r11), %rax;
9548 outunpack_blocks(%rax, RR4, RL4, RTMP, RX, RKM);
9549
9550+ pax_force_retaddr 0, 1
9551 ret;
9552
9553 __skip_dec:
9554diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
9555index 218d283..819e6da 100644
9556--- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
9557+++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
9558@@ -23,6 +23,8 @@
9559 *
9560 */
9561
9562+#include <asm/alternative-asm.h>
9563+
9564 .file "cast6-avx-x86_64-asm_64.S"
9565
9566 .extern cast6_s1
9567@@ -324,12 +326,14 @@ __cast6_enc_blk_8way:
9568 outunpack_blocks(%r11, RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
9569 outunpack_blocks(%rax, RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
9570
9571+ pax_force_retaddr 0, 1
9572 ret;
9573
9574 __enc_xor8:
9575 outunpack_xor_blocks(%r11, RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
9576 outunpack_xor_blocks(%rax, RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
9577
9578+ pax_force_retaddr 0, 1
9579 ret;
9580
9581 .align 16
9582@@ -380,4 +384,5 @@ cast6_dec_blk_8way:
9583 outunpack_blocks(%r11, RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
9584 outunpack_blocks(%rax, RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
9585
9586+ pax_force_retaddr 0, 1
9587 ret;
9588diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
9589index 6214a9b..1f4fc9a 100644
9590--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
9591+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
9592@@ -1,3 +1,5 @@
9593+#include <asm/alternative-asm.h>
9594+
9595 # enter ECRYPT_encrypt_bytes
9596 .text
9597 .p2align 5
9598@@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
9599 add %r11,%rsp
9600 mov %rdi,%rax
9601 mov %rsi,%rdx
9602+ pax_force_retaddr 0, 1
9603 ret
9604 # bytesatleast65:
9605 ._bytesatleast65:
9606@@ -891,6 +894,7 @@ ECRYPT_keysetup:
9607 add %r11,%rsp
9608 mov %rdi,%rax
9609 mov %rsi,%rdx
9610+ pax_force_retaddr
9611 ret
9612 # enter ECRYPT_ivsetup
9613 .text
9614@@ -917,4 +921,5 @@ ECRYPT_ivsetup:
9615 add %r11,%rsp
9616 mov %rdi,%rax
9617 mov %rsi,%rdx
9618+ pax_force_retaddr
9619 ret
9620diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
9621index 504106b..4e50951 100644
9622--- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
9623+++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
9624@@ -24,6 +24,8 @@
9625 *
9626 */
9627
9628+#include <asm/alternative-asm.h>
9629+
9630 .file "serpent-avx-x86_64-asm_64.S"
9631 .text
9632
9633@@ -638,12 +640,14 @@ __serpent_enc_blk_8way_avx:
9634 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
9635 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
9636
9637+ pax_force_retaddr
9638 ret;
9639
9640 __enc_xor8:
9641 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
9642 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
9643
9644+ pax_force_retaddr
9645 ret;
9646
9647 .align 8
9648@@ -701,4 +705,5 @@ serpent_dec_blk_8way_avx:
9649 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
9650 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
9651
9652+ pax_force_retaddr
9653 ret;
9654diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
9655index 3ee1ff0..cbc568b 100644
9656--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
9657+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
9658@@ -24,6 +24,8 @@
9659 *
9660 */
9661
9662+#include <asm/alternative-asm.h>
9663+
9664 .file "serpent-sse2-x86_64-asm_64.S"
9665 .text
9666
9667@@ -692,12 +694,14 @@ __serpent_enc_blk_8way:
9668 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
9669 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
9670
9671+ pax_force_retaddr
9672 ret;
9673
9674 __enc_xor8:
9675 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
9676 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
9677
9678+ pax_force_retaddr
9679 ret;
9680
9681 .align 8
9682@@ -755,4 +759,5 @@ serpent_dec_blk_8way:
9683 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
9684 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
9685
9686+ pax_force_retaddr
9687 ret;
9688diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
9689index 49d6987..df66bd4 100644
9690--- a/arch/x86/crypto/sha1_ssse3_asm.S
9691+++ b/arch/x86/crypto/sha1_ssse3_asm.S
9692@@ -28,6 +28,8 @@
9693 * (at your option) any later version.
9694 */
9695
9696+#include <asm/alternative-asm.h>
9697+
9698 #define CTX %rdi // arg1
9699 #define BUF %rsi // arg2
9700 #define CNT %rdx // arg3
9701@@ -104,6 +106,7 @@
9702 pop %r12
9703 pop %rbp
9704 pop %rbx
9705+ pax_force_retaddr 0, 1
9706 ret
9707
9708 .size \name, .-\name
9709diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
9710index 1585abb..1ff9d9b 100644
9711--- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
9712+++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
9713@@ -23,6 +23,8 @@
9714 *
9715 */
9716
9717+#include <asm/alternative-asm.h>
9718+
9719 .file "twofish-avx-x86_64-asm_64.S"
9720 .text
9721
9722@@ -303,12 +305,14 @@ __twofish_enc_blk_8way:
9723 outunpack_blocks(%r11, RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
9724 outunpack_blocks(%rax, RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
9725
9726+ pax_force_retaddr 0, 1
9727 ret;
9728
9729 __enc_xor8:
9730 outunpack_xor_blocks(%r11, RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
9731 outunpack_xor_blocks(%rax, RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
9732
9733+ pax_force_retaddr 0, 1
9734 ret;
9735
9736 .align 8
9737@@ -354,4 +358,5 @@ twofish_dec_blk_8way:
9738 outunpack_blocks(%r11, RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
9739 outunpack_blocks(%rax, RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
9740
9741+ pax_force_retaddr 0, 1
9742 ret;
9743diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
9744index 5b012a2..36d5364 100644
9745--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
9746+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
9747@@ -20,6 +20,8 @@
9748 *
9749 */
9750
9751+#include <asm/alternative-asm.h>
9752+
9753 .file "twofish-x86_64-asm-3way.S"
9754 .text
9755
9756@@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
9757 popq %r13;
9758 popq %r14;
9759 popq %r15;
9760+ pax_force_retaddr 0, 1
9761 ret;
9762
9763 __enc_xor3:
9764@@ -271,6 +274,7 @@ __enc_xor3:
9765 popq %r13;
9766 popq %r14;
9767 popq %r15;
9768+ pax_force_retaddr 0, 1
9769 ret;
9770
9771 .global twofish_dec_blk_3way
9772@@ -312,5 +316,6 @@ twofish_dec_blk_3way:
9773 popq %r13;
9774 popq %r14;
9775 popq %r15;
9776+ pax_force_retaddr 0, 1
9777 ret;
9778
9779diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
9780index 7bcf3fc..f53832f 100644
9781--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
9782+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
9783@@ -21,6 +21,7 @@
9784 .text
9785
9786 #include <asm/asm-offsets.h>
9787+#include <asm/alternative-asm.h>
9788
9789 #define a_offset 0
9790 #define b_offset 4
9791@@ -268,6 +269,7 @@ twofish_enc_blk:
9792
9793 popq R1
9794 movq $1,%rax
9795+ pax_force_retaddr 0, 1
9796 ret
9797
9798 twofish_dec_blk:
9799@@ -319,4 +321,5 @@ twofish_dec_blk:
9800
9801 popq R1
9802 movq $1,%rax
9803+ pax_force_retaddr 0, 1
9804 ret
9805diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
9806index 07b3a68..bd2a388 100644
9807--- a/arch/x86/ia32/ia32_aout.c
9808+++ b/arch/x86/ia32/ia32_aout.c
9809@@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
9810 unsigned long dump_start, dump_size;
9811 struct user32 dump;
9812
9813+ memset(&dump, 0, sizeof(dump));
9814+
9815 fs = get_fs();
9816 set_fs(KERNEL_DS);
9817 has_dumped = 1;
9818diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
9819index efc6a95..95abfe2 100644
9820--- a/arch/x86/ia32/ia32_signal.c
9821+++ b/arch/x86/ia32/ia32_signal.c
9822@@ -163,8 +163,8 @@ asmlinkage long sys32_sigaltstack(const stack_ia32_t __user *uss_ptr,
9823 }
9824 seg = get_fs();
9825 set_fs(KERNEL_DS);
9826- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
9827- (stack_t __force __user *) &uoss, regs->sp);
9828+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
9829+ (stack_t __force_user *) &uoss, regs->sp);
9830 set_fs(seg);
9831 if (ret >= 0 && uoss_ptr) {
9832 if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(stack_ia32_t)))
9833@@ -396,7 +396,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
9834 sp -= frame_size;
9835 /* Align the stack pointer according to the i386 ABI,
9836 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
9837- sp = ((sp + 4) & -16ul) - 4;
9838+ sp = ((sp - 12) & -16ul) - 4;
9839 return (void __user *) sp;
9840 }
9841
9842@@ -454,7 +454,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
9843 * These are actually not used anymore, but left because some
9844 * gdb versions depend on them as a marker.
9845 */
9846- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
9847+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
9848 } put_user_catch(err);
9849
9850 if (err)
9851@@ -496,7 +496,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
9852 0xb8,
9853 __NR_ia32_rt_sigreturn,
9854 0x80cd,
9855- 0,
9856+ 0
9857 };
9858
9859 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
9860@@ -522,16 +522,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
9861
9862 if (ka->sa.sa_flags & SA_RESTORER)
9863 restorer = ka->sa.sa_restorer;
9864+ else if (current->mm->context.vdso)
9865+ /* Return stub is in 32bit vsyscall page */
9866+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
9867 else
9868- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
9869- rt_sigreturn);
9870+ restorer = &frame->retcode;
9871 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
9872
9873 /*
9874 * Not actually used anymore, but left because some gdb
9875 * versions need it.
9876 */
9877- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
9878+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
9879 } put_user_catch(err);
9880
9881 err |= copy_siginfo_to_user32(&frame->info, info);
9882diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
9883index 076745f..ae8f6cb 100644
9884--- a/arch/x86/ia32/ia32entry.S
9885+++ b/arch/x86/ia32/ia32entry.S
9886@@ -15,8 +15,10 @@
9887 #include <asm/irqflags.h>
9888 #include <asm/asm.h>
9889 #include <asm/smap.h>
9890+#include <asm/pgtable.h>
9891 #include <linux/linkage.h>
9892 #include <linux/err.h>
9893+#include <asm/alternative-asm.h>
9894
9895 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
9896 #include <linux/elf-em.h>
9897@@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
9898 ENDPROC(native_irq_enable_sysexit)
9899 #endif
9900
9901+ .macro pax_enter_kernel_user
9902+ pax_set_fptr_mask
9903+#ifdef CONFIG_PAX_MEMORY_UDEREF
9904+ call pax_enter_kernel_user
9905+#endif
9906+ .endm
9907+
9908+ .macro pax_exit_kernel_user
9909+#ifdef CONFIG_PAX_MEMORY_UDEREF
9910+ call pax_exit_kernel_user
9911+#endif
9912+#ifdef CONFIG_PAX_RANDKSTACK
9913+ pushq %rax
9914+ pushq %r11
9915+ call pax_randomize_kstack
9916+ popq %r11
9917+ popq %rax
9918+#endif
9919+ .endm
9920+
9921+.macro pax_erase_kstack
9922+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
9923+ call pax_erase_kstack
9924+#endif
9925+.endm
9926+
9927 /*
9928 * 32bit SYSENTER instruction entry.
9929 *
9930@@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
9931 CFI_REGISTER rsp,rbp
9932 SWAPGS_UNSAFE_STACK
9933 movq PER_CPU_VAR(kernel_stack), %rsp
9934- addq $(KERNEL_STACK_OFFSET),%rsp
9935- /*
9936- * No need to follow this irqs on/off section: the syscall
9937- * disabled irqs, here we enable it straight after entry:
9938- */
9939- ENABLE_INTERRUPTS(CLBR_NONE)
9940 movl %ebp,%ebp /* zero extension */
9941 pushq_cfi $__USER32_DS
9942 /*CFI_REL_OFFSET ss,0*/
9943@@ -135,24 +157,44 @@ ENTRY(ia32_sysenter_target)
9944 CFI_REL_OFFSET rsp,0
9945 pushfq_cfi
9946 /*CFI_REL_OFFSET rflags,0*/
9947- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
9948- CFI_REGISTER rip,r10
9949+ orl $X86_EFLAGS_IF,(%rsp)
9950+ GET_THREAD_INFO(%r11)
9951+ movl TI_sysenter_return(%r11), %r11d
9952+ CFI_REGISTER rip,r11
9953 pushq_cfi $__USER32_CS
9954 /*CFI_REL_OFFSET cs,0*/
9955 movl %eax, %eax
9956- pushq_cfi %r10
9957+ pushq_cfi %r11
9958 CFI_REL_OFFSET rip,0
9959 pushq_cfi %rax
9960 cld
9961 SAVE_ARGS 0,1,0
9962+ pax_enter_kernel_user
9963+
9964+#ifdef CONFIG_PAX_RANDKSTACK
9965+ pax_erase_kstack
9966+#endif
9967+
9968+ /*
9969+ * No need to follow this irqs on/off section: the syscall
9970+ * disabled irqs, here we enable it straight after entry:
9971+ */
9972+ ENABLE_INTERRUPTS(CLBR_NONE)
9973 /* no need to do an access_ok check here because rbp has been
9974 32bit zero extended */
9975+
9976+#ifdef CONFIG_PAX_MEMORY_UDEREF
9977+ mov $PAX_USER_SHADOW_BASE,%r11
9978+ add %r11,%rbp
9979+#endif
9980+
9981 ASM_STAC
9982 1: movl (%rbp),%ebp
9983 _ASM_EXTABLE(1b,ia32_badarg)
9984 ASM_CLAC
9985- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9986- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9987+ GET_THREAD_INFO(%r11)
9988+ orl $TS_COMPAT,TI_status(%r11)
9989+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
9990 CFI_REMEMBER_STATE
9991 jnz sysenter_tracesys
9992 cmpq $(IA32_NR_syscalls-1),%rax
9993@@ -162,12 +204,15 @@ sysenter_do_call:
9994 sysenter_dispatch:
9995 call *ia32_sys_call_table(,%rax,8)
9996 movq %rax,RAX-ARGOFFSET(%rsp)
9997+ GET_THREAD_INFO(%r11)
9998 DISABLE_INTERRUPTS(CLBR_NONE)
9999 TRACE_IRQS_OFF
10000- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10001+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
10002 jnz sysexit_audit
10003 sysexit_from_sys_call:
10004- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10005+ pax_exit_kernel_user
10006+ pax_erase_kstack
10007+ andl $~TS_COMPAT,TI_status(%r11)
10008 /* clear IF, that popfq doesn't enable interrupts early */
10009 andl $~0x200,EFLAGS-R11(%rsp)
10010 movl RIP-R11(%rsp),%edx /* User %eip */
10011@@ -193,6 +238,9 @@ sysexit_from_sys_call:
10012 movl %eax,%esi /* 2nd arg: syscall number */
10013 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
10014 call __audit_syscall_entry
10015+
10016+ pax_erase_kstack
10017+
10018 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
10019 cmpq $(IA32_NR_syscalls-1),%rax
10020 ja ia32_badsys
10021@@ -204,7 +252,7 @@ sysexit_from_sys_call:
10022 .endm
10023
10024 .macro auditsys_exit exit
10025- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10026+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
10027 jnz ia32_ret_from_sys_call
10028 TRACE_IRQS_ON
10029 sti
10030@@ -215,11 +263,12 @@ sysexit_from_sys_call:
10031 1: setbe %al /* 1 if error, 0 if not */
10032 movzbl %al,%edi /* zero-extend that into %edi */
10033 call __audit_syscall_exit
10034+ GET_THREAD_INFO(%r11)
10035 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
10036 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
10037 cli
10038 TRACE_IRQS_OFF
10039- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10040+ testl %edi,TI_flags(%r11)
10041 jz \exit
10042 CLEAR_RREGS -ARGOFFSET
10043 jmp int_with_check
10044@@ -237,7 +286,7 @@ sysexit_audit:
10045
10046 sysenter_tracesys:
10047 #ifdef CONFIG_AUDITSYSCALL
10048- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10049+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
10050 jz sysenter_auditsys
10051 #endif
10052 SAVE_REST
10053@@ -249,6 +298,9 @@ sysenter_tracesys:
10054 RESTORE_REST
10055 cmpq $(IA32_NR_syscalls-1),%rax
10056 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
10057+
10058+ pax_erase_kstack
10059+
10060 jmp sysenter_do_call
10061 CFI_ENDPROC
10062 ENDPROC(ia32_sysenter_target)
10063@@ -276,19 +328,25 @@ ENDPROC(ia32_sysenter_target)
10064 ENTRY(ia32_cstar_target)
10065 CFI_STARTPROC32 simple
10066 CFI_SIGNAL_FRAME
10067- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
10068+ CFI_DEF_CFA rsp,0
10069 CFI_REGISTER rip,rcx
10070 /*CFI_REGISTER rflags,r11*/
10071 SWAPGS_UNSAFE_STACK
10072 movl %esp,%r8d
10073 CFI_REGISTER rsp,r8
10074 movq PER_CPU_VAR(kernel_stack),%rsp
10075+ SAVE_ARGS 8*6,0,0
10076+ pax_enter_kernel_user
10077+
10078+#ifdef CONFIG_PAX_RANDKSTACK
10079+ pax_erase_kstack
10080+#endif
10081+
10082 /*
10083 * No need to follow this irqs on/off section: the syscall
10084 * disabled irqs and here we enable it straight after entry:
10085 */
10086 ENABLE_INTERRUPTS(CLBR_NONE)
10087- SAVE_ARGS 8,0,0
10088 movl %eax,%eax /* zero extension */
10089 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
10090 movq %rcx,RIP-ARGOFFSET(%rsp)
10091@@ -304,12 +362,19 @@ ENTRY(ia32_cstar_target)
10092 /* no need to do an access_ok check here because r8 has been
10093 32bit zero extended */
10094 /* hardware stack frame is complete now */
10095+
10096+#ifdef CONFIG_PAX_MEMORY_UDEREF
10097+ mov $PAX_USER_SHADOW_BASE,%r11
10098+ add %r11,%r8
10099+#endif
10100+
10101 ASM_STAC
10102 1: movl (%r8),%r9d
10103 _ASM_EXTABLE(1b,ia32_badarg)
10104 ASM_CLAC
10105- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10106- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10107+ GET_THREAD_INFO(%r11)
10108+ orl $TS_COMPAT,TI_status(%r11)
10109+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
10110 CFI_REMEMBER_STATE
10111 jnz cstar_tracesys
10112 cmpq $IA32_NR_syscalls-1,%rax
10113@@ -319,12 +384,15 @@ cstar_do_call:
10114 cstar_dispatch:
10115 call *ia32_sys_call_table(,%rax,8)
10116 movq %rax,RAX-ARGOFFSET(%rsp)
10117+ GET_THREAD_INFO(%r11)
10118 DISABLE_INTERRUPTS(CLBR_NONE)
10119 TRACE_IRQS_OFF
10120- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10121+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
10122 jnz sysretl_audit
10123 sysretl_from_sys_call:
10124- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10125+ pax_exit_kernel_user
10126+ pax_erase_kstack
10127+ andl $~TS_COMPAT,TI_status(%r11)
10128 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
10129 movl RIP-ARGOFFSET(%rsp),%ecx
10130 CFI_REGISTER rip,rcx
10131@@ -352,7 +420,7 @@ sysretl_audit:
10132
10133 cstar_tracesys:
10134 #ifdef CONFIG_AUDITSYSCALL
10135- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10136+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
10137 jz cstar_auditsys
10138 #endif
10139 xchgl %r9d,%ebp
10140@@ -366,6 +434,9 @@ cstar_tracesys:
10141 xchgl %ebp,%r9d
10142 cmpq $(IA32_NR_syscalls-1),%rax
10143 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
10144+
10145+ pax_erase_kstack
10146+
10147 jmp cstar_do_call
10148 END(ia32_cstar_target)
10149
10150@@ -407,19 +478,26 @@ ENTRY(ia32_syscall)
10151 CFI_REL_OFFSET rip,RIP-RIP
10152 PARAVIRT_ADJUST_EXCEPTION_FRAME
10153 SWAPGS
10154- /*
10155- * No need to follow this irqs on/off section: the syscall
10156- * disabled irqs and here we enable it straight after entry:
10157- */
10158- ENABLE_INTERRUPTS(CLBR_NONE)
10159 movl %eax,%eax
10160 pushq_cfi %rax
10161 cld
10162 /* note the registers are not zero extended to the sf.
10163 this could be a problem. */
10164 SAVE_ARGS 0,1,0
10165- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10166- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10167+ pax_enter_kernel_user
10168+
10169+#ifdef CONFIG_PAX_RANDKSTACK
10170+ pax_erase_kstack
10171+#endif
10172+
10173+ /*
10174+ * No need to follow this irqs on/off section: the syscall
10175+ * disabled irqs and here we enable it straight after entry:
10176+ */
10177+ ENABLE_INTERRUPTS(CLBR_NONE)
10178+ GET_THREAD_INFO(%r11)
10179+ orl $TS_COMPAT,TI_status(%r11)
10180+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
10181 jnz ia32_tracesys
10182 cmpq $(IA32_NR_syscalls-1),%rax
10183 ja ia32_badsys
10184@@ -442,6 +520,9 @@ ia32_tracesys:
10185 RESTORE_REST
10186 cmpq $(IA32_NR_syscalls-1),%rax
10187 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
10188+
10189+ pax_erase_kstack
10190+
10191 jmp ia32_do_call
10192 END(ia32_syscall)
10193
10194diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
10195index 86d68d1..f9960fe 100644
10196--- a/arch/x86/ia32/sys_ia32.c
10197+++ b/arch/x86/ia32/sys_ia32.c
10198@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
10199 */
10200 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
10201 {
10202- typeof(ubuf->st_uid) uid = 0;
10203- typeof(ubuf->st_gid) gid = 0;
10204+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
10205+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
10206 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
10207 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
10208 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
10209@@ -303,7 +303,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
10210 mm_segment_t old_fs = get_fs();
10211
10212 set_fs(KERNEL_DS);
10213- ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
10214+ ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
10215 set_fs(old_fs);
10216 if (put_compat_timespec(&t, interval))
10217 return -EFAULT;
10218@@ -319,7 +319,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
10219 mm_segment_t old_fs = get_fs();
10220
10221 set_fs(KERNEL_DS);
10222- ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
10223+ ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
10224 set_fs(old_fs);
10225 if (!ret) {
10226 switch (_NSIG_WORDS) {
10227@@ -344,7 +344,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
10228 if (copy_siginfo_from_user32(&info, uinfo))
10229 return -EFAULT;
10230 set_fs(KERNEL_DS);
10231- ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
10232+ ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
10233 set_fs(old_fs);
10234 return ret;
10235 }
10236@@ -376,7 +376,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
10237 return -EFAULT;
10238
10239 set_fs(KERNEL_DS);
10240- ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
10241+ ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
10242 count);
10243 set_fs(old_fs);
10244
10245diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
10246index 372231c..a5aa1a1 100644
10247--- a/arch/x86/include/asm/alternative-asm.h
10248+++ b/arch/x86/include/asm/alternative-asm.h
10249@@ -18,6 +18,45 @@
10250 .endm
10251 #endif
10252
10253+#ifdef KERNEXEC_PLUGIN
10254+ .macro pax_force_retaddr_bts rip=0
10255+ btsq $63,\rip(%rsp)
10256+ .endm
10257+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
10258+ .macro pax_force_retaddr rip=0, reload=0
10259+ btsq $63,\rip(%rsp)
10260+ .endm
10261+ .macro pax_force_fptr ptr
10262+ btsq $63,\ptr
10263+ .endm
10264+ .macro pax_set_fptr_mask
10265+ .endm
10266+#endif
10267+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
10268+ .macro pax_force_retaddr rip=0, reload=0
10269+ .if \reload
10270+ pax_set_fptr_mask
10271+ .endif
10272+ orq %r10,\rip(%rsp)
10273+ .endm
10274+ .macro pax_force_fptr ptr
10275+ orq %r10,\ptr
10276+ .endm
10277+ .macro pax_set_fptr_mask
10278+ movabs $0x8000000000000000,%r10
10279+ .endm
10280+#endif
10281+#else
10282+ .macro pax_force_retaddr rip=0, reload=0
10283+ .endm
10284+ .macro pax_force_fptr ptr
10285+ .endm
10286+ .macro pax_force_retaddr_bts rip=0
10287+ .endm
10288+ .macro pax_set_fptr_mask
10289+ .endm
10290+#endif
10291+
10292 .macro altinstruction_entry orig alt feature orig_len alt_len
10293 .long \orig - .
10294 .long \alt - .
10295diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
10296index 58ed6d9..f1cbe58 100644
10297--- a/arch/x86/include/asm/alternative.h
10298+++ b/arch/x86/include/asm/alternative.h
10299@@ -105,7 +105,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
10300 ".pushsection .discard,\"aw\",@progbits\n" \
10301 DISCARD_ENTRY(1) \
10302 ".popsection\n" \
10303- ".pushsection .altinstr_replacement, \"ax\"\n" \
10304+ ".pushsection .altinstr_replacement, \"a\"\n" \
10305 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
10306 ".popsection"
10307
10308@@ -119,7 +119,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
10309 DISCARD_ENTRY(1) \
10310 DISCARD_ENTRY(2) \
10311 ".popsection\n" \
10312- ".pushsection .altinstr_replacement, \"ax\"\n" \
10313+ ".pushsection .altinstr_replacement, \"a\"\n" \
10314 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
10315 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
10316 ".popsection"
10317diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
10318index 3388034..ba52312 100644
10319--- a/arch/x86/include/asm/apic.h
10320+++ b/arch/x86/include/asm/apic.h
10321@@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
10322
10323 #ifdef CONFIG_X86_LOCAL_APIC
10324
10325-extern unsigned int apic_verbosity;
10326+extern int apic_verbosity;
10327 extern int local_apic_timer_c2_ok;
10328
10329 extern int disable_apic;
10330@@ -391,7 +391,7 @@ struct apic {
10331 */
10332 int (*x86_32_numa_cpu_node)(int cpu);
10333 #endif
10334-};
10335+} __do_const;
10336
10337 /*
10338 * Pointer to the local APIC driver in use on this system (there's
10339diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
10340index 20370c6..a2eb9b0 100644
10341--- a/arch/x86/include/asm/apm.h
10342+++ b/arch/x86/include/asm/apm.h
10343@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
10344 __asm__ __volatile__(APM_DO_ZERO_SEGS
10345 "pushl %%edi\n\t"
10346 "pushl %%ebp\n\t"
10347- "lcall *%%cs:apm_bios_entry\n\t"
10348+ "lcall *%%ss:apm_bios_entry\n\t"
10349 "setc %%al\n\t"
10350 "popl %%ebp\n\t"
10351 "popl %%edi\n\t"
10352@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
10353 __asm__ __volatile__(APM_DO_ZERO_SEGS
10354 "pushl %%edi\n\t"
10355 "pushl %%ebp\n\t"
10356- "lcall *%%cs:apm_bios_entry\n\t"
10357+ "lcall *%%ss:apm_bios_entry\n\t"
10358 "setc %%bl\n\t"
10359 "popl %%ebp\n\t"
10360 "popl %%edi\n\t"
10361diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
10362index b6c3b82..b4c077a 100644
10363--- a/arch/x86/include/asm/atomic.h
10364+++ b/arch/x86/include/asm/atomic.h
10365@@ -22,7 +22,18 @@
10366 */
10367 static inline int atomic_read(const atomic_t *v)
10368 {
10369- return (*(volatile int *)&(v)->counter);
10370+ return (*(volatile const int *)&(v)->counter);
10371+}
10372+
10373+/**
10374+ * atomic_read_unchecked - read atomic variable
10375+ * @v: pointer of type atomic_unchecked_t
10376+ *
10377+ * Atomically reads the value of @v.
10378+ */
10379+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
10380+{
10381+ return (*(volatile const int *)&(v)->counter);
10382 }
10383
10384 /**
10385@@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
10386 }
10387
10388 /**
10389+ * atomic_set_unchecked - set atomic variable
10390+ * @v: pointer of type atomic_unchecked_t
10391+ * @i: required value
10392+ *
10393+ * Atomically sets the value of @v to @i.
10394+ */
10395+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
10396+{
10397+ v->counter = i;
10398+}
10399+
10400+/**
10401 * atomic_add - add integer to atomic variable
10402 * @i: integer value to add
10403 * @v: pointer of type atomic_t
10404@@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
10405 */
10406 static inline void atomic_add(int i, atomic_t *v)
10407 {
10408- asm volatile(LOCK_PREFIX "addl %1,%0"
10409+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
10410+
10411+#ifdef CONFIG_PAX_REFCOUNT
10412+ "jno 0f\n"
10413+ LOCK_PREFIX "subl %1,%0\n"
10414+ "int $4\n0:\n"
10415+ _ASM_EXTABLE(0b, 0b)
10416+#endif
10417+
10418+ : "+m" (v->counter)
10419+ : "ir" (i));
10420+}
10421+
10422+/**
10423+ * atomic_add_unchecked - add integer to atomic variable
10424+ * @i: integer value to add
10425+ * @v: pointer of type atomic_unchecked_t
10426+ *
10427+ * Atomically adds @i to @v.
10428+ */
10429+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
10430+{
10431+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
10432 : "+m" (v->counter)
10433 : "ir" (i));
10434 }
10435@@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
10436 */
10437 static inline void atomic_sub(int i, atomic_t *v)
10438 {
10439- asm volatile(LOCK_PREFIX "subl %1,%0"
10440+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
10441+
10442+#ifdef CONFIG_PAX_REFCOUNT
10443+ "jno 0f\n"
10444+ LOCK_PREFIX "addl %1,%0\n"
10445+ "int $4\n0:\n"
10446+ _ASM_EXTABLE(0b, 0b)
10447+#endif
10448+
10449+ : "+m" (v->counter)
10450+ : "ir" (i));
10451+}
10452+
10453+/**
10454+ * atomic_sub_unchecked - subtract integer from atomic variable
10455+ * @i: integer value to subtract
10456+ * @v: pointer of type atomic_unchecked_t
10457+ *
10458+ * Atomically subtracts @i from @v.
10459+ */
10460+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
10461+{
10462+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
10463 : "+m" (v->counter)
10464 : "ir" (i));
10465 }
10466@@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
10467 {
10468 unsigned char c;
10469
10470- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
10471+ asm volatile(LOCK_PREFIX "subl %2,%0\n"
10472+
10473+#ifdef CONFIG_PAX_REFCOUNT
10474+ "jno 0f\n"
10475+ LOCK_PREFIX "addl %2,%0\n"
10476+ "int $4\n0:\n"
10477+ _ASM_EXTABLE(0b, 0b)
10478+#endif
10479+
10480+ "sete %1\n"
10481 : "+m" (v->counter), "=qm" (c)
10482 : "ir" (i) : "memory");
10483 return c;
10484@@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
10485 */
10486 static inline void atomic_inc(atomic_t *v)
10487 {
10488- asm volatile(LOCK_PREFIX "incl %0"
10489+ asm volatile(LOCK_PREFIX "incl %0\n"
10490+
10491+#ifdef CONFIG_PAX_REFCOUNT
10492+ "jno 0f\n"
10493+ LOCK_PREFIX "decl %0\n"
10494+ "int $4\n0:\n"
10495+ _ASM_EXTABLE(0b, 0b)
10496+#endif
10497+
10498+ : "+m" (v->counter));
10499+}
10500+
10501+/**
10502+ * atomic_inc_unchecked - increment atomic variable
10503+ * @v: pointer of type atomic_unchecked_t
10504+ *
10505+ * Atomically increments @v by 1.
10506+ */
10507+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
10508+{
10509+ asm volatile(LOCK_PREFIX "incl %0\n"
10510 : "+m" (v->counter));
10511 }
10512
10513@@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
10514 */
10515 static inline void atomic_dec(atomic_t *v)
10516 {
10517- asm volatile(LOCK_PREFIX "decl %0"
10518+ asm volatile(LOCK_PREFIX "decl %0\n"
10519+
10520+#ifdef CONFIG_PAX_REFCOUNT
10521+ "jno 0f\n"
10522+ LOCK_PREFIX "incl %0\n"
10523+ "int $4\n0:\n"
10524+ _ASM_EXTABLE(0b, 0b)
10525+#endif
10526+
10527+ : "+m" (v->counter));
10528+}
10529+
10530+/**
10531+ * atomic_dec_unchecked - decrement atomic variable
10532+ * @v: pointer of type atomic_unchecked_t
10533+ *
10534+ * Atomically decrements @v by 1.
10535+ */
10536+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
10537+{
10538+ asm volatile(LOCK_PREFIX "decl %0\n"
10539 : "+m" (v->counter));
10540 }
10541
10542@@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
10543 {
10544 unsigned char c;
10545
10546- asm volatile(LOCK_PREFIX "decl %0; sete %1"
10547+ asm volatile(LOCK_PREFIX "decl %0\n"
10548+
10549+#ifdef CONFIG_PAX_REFCOUNT
10550+ "jno 0f\n"
10551+ LOCK_PREFIX "incl %0\n"
10552+ "int $4\n0:\n"
10553+ _ASM_EXTABLE(0b, 0b)
10554+#endif
10555+
10556+ "sete %1\n"
10557 : "+m" (v->counter), "=qm" (c)
10558 : : "memory");
10559 return c != 0;
10560@@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
10561 {
10562 unsigned char c;
10563
10564- asm volatile(LOCK_PREFIX "incl %0; sete %1"
10565+ asm volatile(LOCK_PREFIX "incl %0\n"
10566+
10567+#ifdef CONFIG_PAX_REFCOUNT
10568+ "jno 0f\n"
10569+ LOCK_PREFIX "decl %0\n"
10570+ "int $4\n0:\n"
10571+ _ASM_EXTABLE(0b, 0b)
10572+#endif
10573+
10574+ "sete %1\n"
10575+ : "+m" (v->counter), "=qm" (c)
10576+ : : "memory");
10577+ return c != 0;
10578+}
10579+
10580+/**
10581+ * atomic_inc_and_test_unchecked - increment and test
10582+ * @v: pointer of type atomic_unchecked_t
10583+ *
10584+ * Atomically increments @v by 1
10585+ * and returns true if the result is zero, or false for all
10586+ * other cases.
10587+ */
10588+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
10589+{
10590+ unsigned char c;
10591+
10592+ asm volatile(LOCK_PREFIX "incl %0\n"
10593+ "sete %1\n"
10594 : "+m" (v->counter), "=qm" (c)
10595 : : "memory");
10596 return c != 0;
10597@@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
10598 {
10599 unsigned char c;
10600
10601- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
10602+ asm volatile(LOCK_PREFIX "addl %2,%0\n"
10603+
10604+#ifdef CONFIG_PAX_REFCOUNT
10605+ "jno 0f\n"
10606+ LOCK_PREFIX "subl %2,%0\n"
10607+ "int $4\n0:\n"
10608+ _ASM_EXTABLE(0b, 0b)
10609+#endif
10610+
10611+ "sets %1\n"
10612 : "+m" (v->counter), "=qm" (c)
10613 : "ir" (i) : "memory");
10614 return c;
10615@@ -179,7 +341,7 @@ static inline int atomic_add_return(int i, atomic_t *v)
10616 goto no_xadd;
10617 #endif
10618 /* Modern 486+ processor */
10619- return i + xadd(&v->counter, i);
10620+ return i + xadd_check_overflow(&v->counter, i);
10621
10622 #ifdef CONFIG_M386
10623 no_xadd: /* Legacy 386 processor */
10624@@ -192,6 +354,34 @@ no_xadd: /* Legacy 386 processor */
10625 }
10626
10627 /**
10628+ * atomic_add_return_unchecked - add integer and return
10629+ * @i: integer value to add
10630+ * @v: pointer of type atomic_unchecked_t
10631+ *
10632+ * Atomically adds @i to @v and returns @i + @v
10633+ */
10634+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
10635+{
10636+#ifdef CONFIG_M386
10637+ int __i;
10638+ unsigned long flags;
10639+ if (unlikely(boot_cpu_data.x86 <= 3))
10640+ goto no_xadd;
10641+#endif
10642+ /* Modern 486+ processor */
10643+ return i + xadd(&v->counter, i);
10644+
10645+#ifdef CONFIG_M386
10646+no_xadd: /* Legacy 386 processor */
10647+ raw_local_irq_save(flags);
10648+ __i = atomic_read_unchecked(v);
10649+ atomic_set_unchecked(v, i + __i);
10650+ raw_local_irq_restore(flags);
10651+ return i + __i;
10652+#endif
10653+}
10654+
10655+/**
10656 * atomic_sub_return - subtract integer and return
10657 * @v: pointer of type atomic_t
10658 * @i: integer value to subtract
10659@@ -204,6 +394,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
10660 }
10661
10662 #define atomic_inc_return(v) (atomic_add_return(1, v))
10663+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
10664+{
10665+ return atomic_add_return_unchecked(1, v);
10666+}
10667 #define atomic_dec_return(v) (atomic_sub_return(1, v))
10668
10669 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
10670@@ -211,11 +405,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
10671 return cmpxchg(&v->counter, old, new);
10672 }
10673
10674+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
10675+{
10676+ return cmpxchg(&v->counter, old, new);
10677+}
10678+
10679 static inline int atomic_xchg(atomic_t *v, int new)
10680 {
10681 return xchg(&v->counter, new);
10682 }
10683
10684+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
10685+{
10686+ return xchg(&v->counter, new);
10687+}
10688+
10689 /**
10690 * __atomic_add_unless - add unless the number is already a given value
10691 * @v: pointer of type atomic_t
10692@@ -227,12 +431,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
10693 */
10694 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
10695 {
10696- int c, old;
10697+ int c, old, new;
10698 c = atomic_read(v);
10699 for (;;) {
10700- if (unlikely(c == (u)))
10701+ if (unlikely(c == u))
10702 break;
10703- old = atomic_cmpxchg((v), c, c + (a));
10704+
10705+ asm volatile("addl %2,%0\n"
10706+
10707+#ifdef CONFIG_PAX_REFCOUNT
10708+ "jno 0f\n"
10709+ "subl %2,%0\n"
10710+ "int $4\n0:\n"
10711+ _ASM_EXTABLE(0b, 0b)
10712+#endif
10713+
10714+ : "=r" (new)
10715+ : "0" (c), "ir" (a));
10716+
10717+ old = atomic_cmpxchg(v, c, new);
10718 if (likely(old == c))
10719 break;
10720 c = old;
10721@@ -241,6 +458,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
10722 }
10723
10724 /**
10725+ * atomic_inc_not_zero_hint - increment if not null
10726+ * @v: pointer of type atomic_t
10727+ * @hint: probable value of the atomic before the increment
10728+ *
10729+ * This version of atomic_inc_not_zero() gives a hint of probable
10730+ * value of the atomic. This helps processor to not read the memory
10731+ * before doing the atomic read/modify/write cycle, lowering
10732+ * number of bus transactions on some arches.
10733+ *
10734+ * Returns: 0 if increment was not done, 1 otherwise.
10735+ */
10736+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
10737+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
10738+{
10739+ int val, c = hint, new;
10740+
10741+ /* sanity test, should be removed by compiler if hint is a constant */
10742+ if (!hint)
10743+ return __atomic_add_unless(v, 1, 0);
10744+
10745+ do {
10746+ asm volatile("incl %0\n"
10747+
10748+#ifdef CONFIG_PAX_REFCOUNT
10749+ "jno 0f\n"
10750+ "decl %0\n"
10751+ "int $4\n0:\n"
10752+ _ASM_EXTABLE(0b, 0b)
10753+#endif
10754+
10755+ : "=r" (new)
10756+ : "0" (c));
10757+
10758+ val = atomic_cmpxchg(v, c, new);
10759+ if (val == c)
10760+ return 1;
10761+ c = val;
10762+ } while (c);
10763+
10764+ return 0;
10765+}
10766+
10767+/**
10768 * atomic_inc_short - increment of a short integer
10769 * @v: pointer to type int
10770 *
10771@@ -269,14 +529,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
10772 #endif
10773
10774 /* These are x86-specific, used by some header files */
10775-#define atomic_clear_mask(mask, addr) \
10776- asm volatile(LOCK_PREFIX "andl %0,%1" \
10777- : : "r" (~(mask)), "m" (*(addr)) : "memory")
10778+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
10779+{
10780+ asm volatile(LOCK_PREFIX "andl %1,%0"
10781+ : "+m" (v->counter)
10782+ : "r" (~(mask))
10783+ : "memory");
10784+}
10785
10786-#define atomic_set_mask(mask, addr) \
10787- asm volatile(LOCK_PREFIX "orl %0,%1" \
10788- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
10789- : "memory")
10790+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
10791+{
10792+ asm volatile(LOCK_PREFIX "andl %1,%0"
10793+ : "+m" (v->counter)
10794+ : "r" (~(mask))
10795+ : "memory");
10796+}
10797+
10798+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
10799+{
10800+ asm volatile(LOCK_PREFIX "orl %1,%0"
10801+ : "+m" (v->counter)
10802+ : "r" (mask)
10803+ : "memory");
10804+}
10805+
10806+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
10807+{
10808+ asm volatile(LOCK_PREFIX "orl %1,%0"
10809+ : "+m" (v->counter)
10810+ : "r" (mask)
10811+ : "memory");
10812+}
10813
10814 /* Atomic operations are already serializing on x86 */
10815 #define smp_mb__before_atomic_dec() barrier()
10816diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
10817index b154de7..aadebd8 100644
10818--- a/arch/x86/include/asm/atomic64_32.h
10819+++ b/arch/x86/include/asm/atomic64_32.h
10820@@ -12,6 +12,14 @@ typedef struct {
10821 u64 __aligned(8) counter;
10822 } atomic64_t;
10823
10824+#ifdef CONFIG_PAX_REFCOUNT
10825+typedef struct {
10826+ u64 __aligned(8) counter;
10827+} atomic64_unchecked_t;
10828+#else
10829+typedef atomic64_t atomic64_unchecked_t;
10830+#endif
10831+
10832 #define ATOMIC64_INIT(val) { (val) }
10833
10834 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
10835@@ -37,21 +45,31 @@ typedef struct {
10836 ATOMIC64_DECL_ONE(sym##_386)
10837
10838 ATOMIC64_DECL_ONE(add_386);
10839+ATOMIC64_DECL_ONE(add_unchecked_386);
10840 ATOMIC64_DECL_ONE(sub_386);
10841+ATOMIC64_DECL_ONE(sub_unchecked_386);
10842 ATOMIC64_DECL_ONE(inc_386);
10843+ATOMIC64_DECL_ONE(inc_unchecked_386);
10844 ATOMIC64_DECL_ONE(dec_386);
10845+ATOMIC64_DECL_ONE(dec_unchecked_386);
10846 #endif
10847
10848 #define alternative_atomic64(f, out, in...) \
10849 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
10850
10851 ATOMIC64_DECL(read);
10852+ATOMIC64_DECL(read_unchecked);
10853 ATOMIC64_DECL(set);
10854+ATOMIC64_DECL(set_unchecked);
10855 ATOMIC64_DECL(xchg);
10856 ATOMIC64_DECL(add_return);
10857+ATOMIC64_DECL(add_return_unchecked);
10858 ATOMIC64_DECL(sub_return);
10859+ATOMIC64_DECL(sub_return_unchecked);
10860 ATOMIC64_DECL(inc_return);
10861+ATOMIC64_DECL(inc_return_unchecked);
10862 ATOMIC64_DECL(dec_return);
10863+ATOMIC64_DECL(dec_return_unchecked);
10864 ATOMIC64_DECL(dec_if_positive);
10865 ATOMIC64_DECL(inc_not_zero);
10866 ATOMIC64_DECL(add_unless);
10867@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
10868 }
10869
10870 /**
10871+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
10872+ * @p: pointer to type atomic64_unchecked_t
10873+ * @o: expected value
10874+ * @n: new value
10875+ *
10876+ * Atomically sets @v to @n if it was equal to @o and returns
10877+ * the old value.
10878+ */
10879+
10880+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
10881+{
10882+ return cmpxchg64(&v->counter, o, n);
10883+}
10884+
10885+/**
10886 * atomic64_xchg - xchg atomic64 variable
10887 * @v: pointer to type atomic64_t
10888 * @n: value to assign
10889@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
10890 }
10891
10892 /**
10893+ * atomic64_set_unchecked - set atomic64 variable
10894+ * @v: pointer to type atomic64_unchecked_t
10895+ * @n: value to assign
10896+ *
10897+ * Atomically sets the value of @v to @n.
10898+ */
10899+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
10900+{
10901+ unsigned high = (unsigned)(i >> 32);
10902+ unsigned low = (unsigned)i;
10903+ alternative_atomic64(set, /* no output */,
10904+ "S" (v), "b" (low), "c" (high)
10905+ : "eax", "edx", "memory");
10906+}
10907+
10908+/**
10909 * atomic64_read - read atomic64 variable
10910 * @v: pointer to type atomic64_t
10911 *
10912@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
10913 }
10914
10915 /**
10916+ * atomic64_read_unchecked - read atomic64 variable
10917+ * @v: pointer to type atomic64_unchecked_t
10918+ *
10919+ * Atomically reads the value of @v and returns it.
10920+ */
10921+static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
10922+{
10923+ long long r;
10924+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
10925+ return r;
10926+ }
10927+
10928+/**
10929 * atomic64_add_return - add and return
10930 * @i: integer value to add
10931 * @v: pointer to type atomic64_t
10932@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
10933 return i;
10934 }
10935
10936+/**
10937+ * atomic64_add_return_unchecked - add and return
10938+ * @i: integer value to add
10939+ * @v: pointer to type atomic64_unchecked_t
10940+ *
10941+ * Atomically adds @i to @v and returns @i + *@v
10942+ */
10943+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
10944+{
10945+ alternative_atomic64(add_return_unchecked,
10946+ ASM_OUTPUT2("+A" (i), "+c" (v)),
10947+ ASM_NO_INPUT_CLOBBER("memory"));
10948+ return i;
10949+}
10950+
10951 /*
10952 * Other variants with different arithmetic operators:
10953 */
10954@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
10955 return a;
10956 }
10957
10958+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
10959+{
10960+ long long a;
10961+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
10962+ "S" (v) : "memory", "ecx");
10963+ return a;
10964+}
10965+
10966 static inline long long atomic64_dec_return(atomic64_t *v)
10967 {
10968 long long a;
10969@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
10970 }
10971
10972 /**
10973+ * atomic64_add_unchecked - add integer to atomic64 variable
10974+ * @i: integer value to add
10975+ * @v: pointer to type atomic64_unchecked_t
10976+ *
10977+ * Atomically adds @i to @v.
10978+ */
10979+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
10980+{
10981+ __alternative_atomic64(add_unchecked, add_return_unchecked,
10982+ ASM_OUTPUT2("+A" (i), "+c" (v)),
10983+ ASM_NO_INPUT_CLOBBER("memory"));
10984+ return i;
10985+}
10986+
10987+/**
10988 * atomic64_sub - subtract the atomic64 variable
10989 * @i: integer value to subtract
10990 * @v: pointer to type atomic64_t
10991diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
10992index 0e1cbfc..5623683 100644
10993--- a/arch/x86/include/asm/atomic64_64.h
10994+++ b/arch/x86/include/asm/atomic64_64.h
10995@@ -18,7 +18,19 @@
10996 */
10997 static inline long atomic64_read(const atomic64_t *v)
10998 {
10999- return (*(volatile long *)&(v)->counter);
11000+ return (*(volatile const long *)&(v)->counter);
11001+}
11002+
11003+/**
11004+ * atomic64_read_unchecked - read atomic64 variable
11005+ * @v: pointer of type atomic64_unchecked_t
11006+ *
11007+ * Atomically reads the value of @v.
11008+ * Doesn't imply a read memory barrier.
11009+ */
11010+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
11011+{
11012+ return (*(volatile const long *)&(v)->counter);
11013 }
11014
11015 /**
11016@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
11017 }
11018
11019 /**
11020+ * atomic64_set_unchecked - set atomic64 variable
11021+ * @v: pointer to type atomic64_unchecked_t
11022+ * @i: required value
11023+ *
11024+ * Atomically sets the value of @v to @i.
11025+ */
11026+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
11027+{
11028+ v->counter = i;
11029+}
11030+
11031+/**
11032 * atomic64_add - add integer to atomic64 variable
11033 * @i: integer value to add
11034 * @v: pointer to type atomic64_t
11035@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
11036 */
11037 static inline void atomic64_add(long i, atomic64_t *v)
11038 {
11039+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
11040+
11041+#ifdef CONFIG_PAX_REFCOUNT
11042+ "jno 0f\n"
11043+ LOCK_PREFIX "subq %1,%0\n"
11044+ "int $4\n0:\n"
11045+ _ASM_EXTABLE(0b, 0b)
11046+#endif
11047+
11048+ : "=m" (v->counter)
11049+ : "er" (i), "m" (v->counter));
11050+}
11051+
11052+/**
11053+ * atomic64_add_unchecked - add integer to atomic64 variable
11054+ * @i: integer value to add
11055+ * @v: pointer to type atomic64_unchecked_t
11056+ *
11057+ * Atomically adds @i to @v.
11058+ */
11059+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
11060+{
11061 asm volatile(LOCK_PREFIX "addq %1,%0"
11062 : "=m" (v->counter)
11063 : "er" (i), "m" (v->counter));
11064@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
11065 */
11066 static inline void atomic64_sub(long i, atomic64_t *v)
11067 {
11068- asm volatile(LOCK_PREFIX "subq %1,%0"
11069+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
11070+
11071+#ifdef CONFIG_PAX_REFCOUNT
11072+ "jno 0f\n"
11073+ LOCK_PREFIX "addq %1,%0\n"
11074+ "int $4\n0:\n"
11075+ _ASM_EXTABLE(0b, 0b)
11076+#endif
11077+
11078+ : "=m" (v->counter)
11079+ : "er" (i), "m" (v->counter));
11080+}
11081+
11082+/**
11083+ * atomic64_sub_unchecked - subtract the atomic64 variable
11084+ * @i: integer value to subtract
11085+ * @v: pointer to type atomic64_unchecked_t
11086+ *
11087+ * Atomically subtracts @i from @v.
11088+ */
11089+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
11090+{
11091+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
11092 : "=m" (v->counter)
11093 : "er" (i), "m" (v->counter));
11094 }
11095@@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
11096 {
11097 unsigned char c;
11098
11099- asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
11100+ asm volatile(LOCK_PREFIX "subq %2,%0\n"
11101+
11102+#ifdef CONFIG_PAX_REFCOUNT
11103+ "jno 0f\n"
11104+ LOCK_PREFIX "addq %2,%0\n"
11105+ "int $4\n0:\n"
11106+ _ASM_EXTABLE(0b, 0b)
11107+#endif
11108+
11109+ "sete %1\n"
11110 : "=m" (v->counter), "=qm" (c)
11111 : "er" (i), "m" (v->counter) : "memory");
11112 return c;
11113@@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
11114 */
11115 static inline void atomic64_inc(atomic64_t *v)
11116 {
11117+ asm volatile(LOCK_PREFIX "incq %0\n"
11118+
11119+#ifdef CONFIG_PAX_REFCOUNT
11120+ "jno 0f\n"
11121+ LOCK_PREFIX "decq %0\n"
11122+ "int $4\n0:\n"
11123+ _ASM_EXTABLE(0b, 0b)
11124+#endif
11125+
11126+ : "=m" (v->counter)
11127+ : "m" (v->counter));
11128+}
11129+
11130+/**
11131+ * atomic64_inc_unchecked - increment atomic64 variable
11132+ * @v: pointer to type atomic64_unchecked_t
11133+ *
11134+ * Atomically increments @v by 1.
11135+ */
11136+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
11137+{
11138 asm volatile(LOCK_PREFIX "incq %0"
11139 : "=m" (v->counter)
11140 : "m" (v->counter));
11141@@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
11142 */
11143 static inline void atomic64_dec(atomic64_t *v)
11144 {
11145- asm volatile(LOCK_PREFIX "decq %0"
11146+ asm volatile(LOCK_PREFIX "decq %0\n"
11147+
11148+#ifdef CONFIG_PAX_REFCOUNT
11149+ "jno 0f\n"
11150+ LOCK_PREFIX "incq %0\n"
11151+ "int $4\n0:\n"
11152+ _ASM_EXTABLE(0b, 0b)
11153+#endif
11154+
11155+ : "=m" (v->counter)
11156+ : "m" (v->counter));
11157+}
11158+
11159+/**
11160+ * atomic64_dec_unchecked - decrement atomic64 variable
11161+ * @v: pointer to type atomic64_t
11162+ *
11163+ * Atomically decrements @v by 1.
11164+ */
11165+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
11166+{
11167+ asm volatile(LOCK_PREFIX "decq %0\n"
11168 : "=m" (v->counter)
11169 : "m" (v->counter));
11170 }
11171@@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
11172 {
11173 unsigned char c;
11174
11175- asm volatile(LOCK_PREFIX "decq %0; sete %1"
11176+ asm volatile(LOCK_PREFIX "decq %0\n"
11177+
11178+#ifdef CONFIG_PAX_REFCOUNT
11179+ "jno 0f\n"
11180+ LOCK_PREFIX "incq %0\n"
11181+ "int $4\n0:\n"
11182+ _ASM_EXTABLE(0b, 0b)
11183+#endif
11184+
11185+ "sete %1\n"
11186 : "=m" (v->counter), "=qm" (c)
11187 : "m" (v->counter) : "memory");
11188 return c != 0;
11189@@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
11190 {
11191 unsigned char c;
11192
11193- asm volatile(LOCK_PREFIX "incq %0; sete %1"
11194+ asm volatile(LOCK_PREFIX "incq %0\n"
11195+
11196+#ifdef CONFIG_PAX_REFCOUNT
11197+ "jno 0f\n"
11198+ LOCK_PREFIX "decq %0\n"
11199+ "int $4\n0:\n"
11200+ _ASM_EXTABLE(0b, 0b)
11201+#endif
11202+
11203+ "sete %1\n"
11204 : "=m" (v->counter), "=qm" (c)
11205 : "m" (v->counter) : "memory");
11206 return c != 0;
11207@@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
11208 {
11209 unsigned char c;
11210
11211- asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
11212+ asm volatile(LOCK_PREFIX "addq %2,%0\n"
11213+
11214+#ifdef CONFIG_PAX_REFCOUNT
11215+ "jno 0f\n"
11216+ LOCK_PREFIX "subq %2,%0\n"
11217+ "int $4\n0:\n"
11218+ _ASM_EXTABLE(0b, 0b)
11219+#endif
11220+
11221+ "sets %1\n"
11222 : "=m" (v->counter), "=qm" (c)
11223 : "er" (i), "m" (v->counter) : "memory");
11224 return c;
11225@@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
11226 */
11227 static inline long atomic64_add_return(long i, atomic64_t *v)
11228 {
11229+ return i + xadd_check_overflow(&v->counter, i);
11230+}
11231+
11232+/**
11233+ * atomic64_add_return_unchecked - add and return
11234+ * @i: integer value to add
11235+ * @v: pointer to type atomic64_unchecked_t
11236+ *
11237+ * Atomically adds @i to @v and returns @i + @v
11238+ */
11239+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
11240+{
11241 return i + xadd(&v->counter, i);
11242 }
11243
11244@@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
11245 }
11246
11247 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
11248+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
11249+{
11250+ return atomic64_add_return_unchecked(1, v);
11251+}
11252 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
11253
11254 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
11255@@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
11256 return cmpxchg(&v->counter, old, new);
11257 }
11258
11259+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
11260+{
11261+ return cmpxchg(&v->counter, old, new);
11262+}
11263+
11264 static inline long atomic64_xchg(atomic64_t *v, long new)
11265 {
11266 return xchg(&v->counter, new);
11267@@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
11268 */
11269 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
11270 {
11271- long c, old;
11272+ long c, old, new;
11273 c = atomic64_read(v);
11274 for (;;) {
11275- if (unlikely(c == (u)))
11276+ if (unlikely(c == u))
11277 break;
11278- old = atomic64_cmpxchg((v), c, c + (a));
11279+
11280+ asm volatile("add %2,%0\n"
11281+
11282+#ifdef CONFIG_PAX_REFCOUNT
11283+ "jno 0f\n"
11284+ "sub %2,%0\n"
11285+ "int $4\n0:\n"
11286+ _ASM_EXTABLE(0b, 0b)
11287+#endif
11288+
11289+ : "=r" (new)
11290+ : "0" (c), "ir" (a));
11291+
11292+ old = atomic64_cmpxchg(v, c, new);
11293 if (likely(old == c))
11294 break;
11295 c = old;
11296 }
11297- return c != (u);
11298+ return c != u;
11299 }
11300
11301 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
11302diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
11303index 6dfd019..0c6699f 100644
11304--- a/arch/x86/include/asm/bitops.h
11305+++ b/arch/x86/include/asm/bitops.h
11306@@ -40,7 +40,7 @@
11307 * a mask operation on a byte.
11308 */
11309 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
11310-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
11311+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
11312 #define CONST_MASK(nr) (1 << ((nr) & 7))
11313
11314 /**
11315diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
11316index b13fe63..0dab13a 100644
11317--- a/arch/x86/include/asm/boot.h
11318+++ b/arch/x86/include/asm/boot.h
11319@@ -11,10 +11,15 @@
11320 #include <asm/pgtable_types.h>
11321
11322 /* Physical address where kernel should be loaded. */
11323-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
11324+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
11325 + (CONFIG_PHYSICAL_ALIGN - 1)) \
11326 & ~(CONFIG_PHYSICAL_ALIGN - 1))
11327
11328+#ifndef __ASSEMBLY__
11329+extern unsigned char __LOAD_PHYSICAL_ADDR[];
11330+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
11331+#endif
11332+
11333 /* Minimum kernel alignment, as a power of two */
11334 #ifdef CONFIG_X86_64
11335 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
11336diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
11337index 48f99f1..d78ebf9 100644
11338--- a/arch/x86/include/asm/cache.h
11339+++ b/arch/x86/include/asm/cache.h
11340@@ -5,12 +5,13 @@
11341
11342 /* L1 cache line size */
11343 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
11344-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11345+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11346
11347 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
11348+#define __read_only __attribute__((__section__(".data..read_only")))
11349
11350 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
11351-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
11352+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
11353
11354 #ifdef CONFIG_X86_VSMP
11355 #ifdef CONFIG_SMP
11356diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
11357index 9863ee3..4a1f8e1 100644
11358--- a/arch/x86/include/asm/cacheflush.h
11359+++ b/arch/x86/include/asm/cacheflush.h
11360@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
11361 unsigned long pg_flags = pg->flags & _PGMT_MASK;
11362
11363 if (pg_flags == _PGMT_DEFAULT)
11364- return -1;
11365+ return ~0UL;
11366 else if (pg_flags == _PGMT_WC)
11367 return _PAGE_CACHE_WC;
11368 else if (pg_flags == _PGMT_UC_MINUS)
11369diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
11370index 46fc474..b02b0f9 100644
11371--- a/arch/x86/include/asm/checksum_32.h
11372+++ b/arch/x86/include/asm/checksum_32.h
11373@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
11374 int len, __wsum sum,
11375 int *src_err_ptr, int *dst_err_ptr);
11376
11377+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
11378+ int len, __wsum sum,
11379+ int *src_err_ptr, int *dst_err_ptr);
11380+
11381+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
11382+ int len, __wsum sum,
11383+ int *src_err_ptr, int *dst_err_ptr);
11384+
11385 /*
11386 * Note: when you get a NULL pointer exception here this means someone
11387 * passed in an incorrect kernel address to one of these functions.
11388@@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
11389 int *err_ptr)
11390 {
11391 might_sleep();
11392- return csum_partial_copy_generic((__force void *)src, dst,
11393+ return csum_partial_copy_generic_from_user((__force void *)src, dst,
11394 len, sum, err_ptr, NULL);
11395 }
11396
11397@@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
11398 {
11399 might_sleep();
11400 if (access_ok(VERIFY_WRITE, dst, len))
11401- return csum_partial_copy_generic(src, (__force void *)dst,
11402+ return csum_partial_copy_generic_to_user(src, (__force void *)dst,
11403 len, sum, NULL, err_ptr);
11404
11405 if (len)
11406diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
11407index 8d871ea..c1a0dc9 100644
11408--- a/arch/x86/include/asm/cmpxchg.h
11409+++ b/arch/x86/include/asm/cmpxchg.h
11410@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
11411 __compiletime_error("Bad argument size for cmpxchg");
11412 extern void __xadd_wrong_size(void)
11413 __compiletime_error("Bad argument size for xadd");
11414+extern void __xadd_check_overflow_wrong_size(void)
11415+ __compiletime_error("Bad argument size for xadd_check_overflow");
11416 extern void __add_wrong_size(void)
11417 __compiletime_error("Bad argument size for add");
11418+extern void __add_check_overflow_wrong_size(void)
11419+ __compiletime_error("Bad argument size for add_check_overflow");
11420
11421 /*
11422 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
11423@@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
11424 __ret; \
11425 })
11426
11427+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
11428+ ({ \
11429+ __typeof__ (*(ptr)) __ret = (arg); \
11430+ switch (sizeof(*(ptr))) { \
11431+ case __X86_CASE_L: \
11432+ asm volatile (lock #op "l %0, %1\n" \
11433+ "jno 0f\n" \
11434+ "mov %0,%1\n" \
11435+ "int $4\n0:\n" \
11436+ _ASM_EXTABLE(0b, 0b) \
11437+ : "+r" (__ret), "+m" (*(ptr)) \
11438+ : : "memory", "cc"); \
11439+ break; \
11440+ case __X86_CASE_Q: \
11441+ asm volatile (lock #op "q %q0, %1\n" \
11442+ "jno 0f\n" \
11443+ "mov %0,%1\n" \
11444+ "int $4\n0:\n" \
11445+ _ASM_EXTABLE(0b, 0b) \
11446+ : "+r" (__ret), "+m" (*(ptr)) \
11447+ : : "memory", "cc"); \
11448+ break; \
11449+ default: \
11450+ __ ## op ## _check_overflow_wrong_size(); \
11451+ } \
11452+ __ret; \
11453+ })
11454+
11455 /*
11456 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
11457 * Since this is generally used to protect other memory information, we
11458@@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
11459 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
11460 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
11461
11462+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
11463+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
11464+
11465 #define __add(ptr, inc, lock) \
11466 ({ \
11467 __typeof__ (*(ptr)) __ret = (inc); \
11468diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
11469index 8c297aa..7a90f03 100644
11470--- a/arch/x86/include/asm/cpufeature.h
11471+++ b/arch/x86/include/asm/cpufeature.h
11472@@ -205,7 +205,7 @@
11473 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
11474 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
11475 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
11476-#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
11477+#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
11478 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
11479 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
11480 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
11481@@ -379,7 +379,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
11482 ".section .discard,\"aw\",@progbits\n"
11483 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
11484 ".previous\n"
11485- ".section .altinstr_replacement,\"ax\"\n"
11486+ ".section .altinstr_replacement,\"a\"\n"
11487 "3: movb $1,%0\n"
11488 "4:\n"
11489 ".previous\n"
11490diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
11491index 8bf1c06..f723dfd 100644
11492--- a/arch/x86/include/asm/desc.h
11493+++ b/arch/x86/include/asm/desc.h
11494@@ -4,6 +4,7 @@
11495 #include <asm/desc_defs.h>
11496 #include <asm/ldt.h>
11497 #include <asm/mmu.h>
11498+#include <asm/pgtable.h>
11499
11500 #include <linux/smp.h>
11501 #include <linux/percpu.h>
11502@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
11503
11504 desc->type = (info->read_exec_only ^ 1) << 1;
11505 desc->type |= info->contents << 2;
11506+ desc->type |= info->seg_not_present ^ 1;
11507
11508 desc->s = 1;
11509 desc->dpl = 0x3;
11510@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
11511 }
11512
11513 extern struct desc_ptr idt_descr;
11514-extern gate_desc idt_table[];
11515 extern struct desc_ptr nmi_idt_descr;
11516-extern gate_desc nmi_idt_table[];
11517-
11518-struct gdt_page {
11519- struct desc_struct gdt[GDT_ENTRIES];
11520-} __attribute__((aligned(PAGE_SIZE)));
11521-
11522-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
11523+extern gate_desc idt_table[256];
11524+extern gate_desc nmi_idt_table[256];
11525
11526+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
11527 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
11528 {
11529- return per_cpu(gdt_page, cpu).gdt;
11530+ return cpu_gdt_table[cpu];
11531 }
11532
11533 #ifdef CONFIG_X86_64
11534@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
11535 unsigned long base, unsigned dpl, unsigned flags,
11536 unsigned short seg)
11537 {
11538- gate->a = (seg << 16) | (base & 0xffff);
11539- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
11540+ gate->gate.offset_low = base;
11541+ gate->gate.seg = seg;
11542+ gate->gate.reserved = 0;
11543+ gate->gate.type = type;
11544+ gate->gate.s = 0;
11545+ gate->gate.dpl = dpl;
11546+ gate->gate.p = 1;
11547+ gate->gate.offset_high = base >> 16;
11548 }
11549
11550 #endif
11551@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
11552
11553 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
11554 {
11555+ pax_open_kernel();
11556 memcpy(&idt[entry], gate, sizeof(*gate));
11557+ pax_close_kernel();
11558 }
11559
11560 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
11561 {
11562+ pax_open_kernel();
11563 memcpy(&ldt[entry], desc, 8);
11564+ pax_close_kernel();
11565 }
11566
11567 static inline void
11568@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
11569 default: size = sizeof(*gdt); break;
11570 }
11571
11572+ pax_open_kernel();
11573 memcpy(&gdt[entry], desc, size);
11574+ pax_close_kernel();
11575 }
11576
11577 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
11578@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
11579
11580 static inline void native_load_tr_desc(void)
11581 {
11582+ pax_open_kernel();
11583 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
11584+ pax_close_kernel();
11585 }
11586
11587 static inline void native_load_gdt(const struct desc_ptr *dtr)
11588@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
11589 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
11590 unsigned int i;
11591
11592+ pax_open_kernel();
11593 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
11594 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
11595+ pax_close_kernel();
11596 }
11597
11598 #define _LDT_empty(info) \
11599@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
11600 }
11601
11602 #ifdef CONFIG_X86_64
11603-static inline void set_nmi_gate(int gate, void *addr)
11604+static inline void set_nmi_gate(int gate, const void *addr)
11605 {
11606 gate_desc s;
11607
11608@@ -320,7 +333,7 @@ static inline void set_nmi_gate(int gate, void *addr)
11609 }
11610 #endif
11611
11612-static inline void _set_gate(int gate, unsigned type, void *addr,
11613+static inline void _set_gate(int gate, unsigned type, const void *addr,
11614 unsigned dpl, unsigned ist, unsigned seg)
11615 {
11616 gate_desc s;
11617@@ -339,7 +352,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
11618 * Pentium F0 0F bugfix can have resulted in the mapped
11619 * IDT being write-protected.
11620 */
11621-static inline void set_intr_gate(unsigned int n, void *addr)
11622+static inline void set_intr_gate(unsigned int n, const void *addr)
11623 {
11624 BUG_ON((unsigned)n > 0xFF);
11625 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
11626@@ -369,19 +382,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
11627 /*
11628 * This routine sets up an interrupt gate at directory privilege level 3.
11629 */
11630-static inline void set_system_intr_gate(unsigned int n, void *addr)
11631+static inline void set_system_intr_gate(unsigned int n, const void *addr)
11632 {
11633 BUG_ON((unsigned)n > 0xFF);
11634 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
11635 }
11636
11637-static inline void set_system_trap_gate(unsigned int n, void *addr)
11638+static inline void set_system_trap_gate(unsigned int n, const void *addr)
11639 {
11640 BUG_ON((unsigned)n > 0xFF);
11641 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
11642 }
11643
11644-static inline void set_trap_gate(unsigned int n, void *addr)
11645+static inline void set_trap_gate(unsigned int n, const void *addr)
11646 {
11647 BUG_ON((unsigned)n > 0xFF);
11648 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
11649@@ -390,19 +403,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
11650 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
11651 {
11652 BUG_ON((unsigned)n > 0xFF);
11653- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
11654+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
11655 }
11656
11657-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
11658+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
11659 {
11660 BUG_ON((unsigned)n > 0xFF);
11661 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
11662 }
11663
11664-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
11665+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
11666 {
11667 BUG_ON((unsigned)n > 0xFF);
11668 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
11669 }
11670
11671+#ifdef CONFIG_X86_32
11672+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
11673+{
11674+ struct desc_struct d;
11675+
11676+ if (likely(limit))
11677+ limit = (limit - 1UL) >> PAGE_SHIFT;
11678+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
11679+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
11680+}
11681+#endif
11682+
11683 #endif /* _ASM_X86_DESC_H */
11684diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
11685index 278441f..b95a174 100644
11686--- a/arch/x86/include/asm/desc_defs.h
11687+++ b/arch/x86/include/asm/desc_defs.h
11688@@ -31,6 +31,12 @@ struct desc_struct {
11689 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
11690 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
11691 };
11692+ struct {
11693+ u16 offset_low;
11694+ u16 seg;
11695+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
11696+ unsigned offset_high: 16;
11697+ } gate;
11698 };
11699 } __attribute__((packed));
11700
11701diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
11702index 3778256..c5d4fce 100644
11703--- a/arch/x86/include/asm/e820.h
11704+++ b/arch/x86/include/asm/e820.h
11705@@ -69,7 +69,7 @@ struct e820map {
11706 #define ISA_START_ADDRESS 0xa0000
11707 #define ISA_END_ADDRESS 0x100000
11708
11709-#define BIOS_BEGIN 0x000a0000
11710+#define BIOS_BEGIN 0x000c0000
11711 #define BIOS_END 0x00100000
11712
11713 #define BIOS_ROM_BASE 0xffe00000
11714diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
11715index 5939f44..f8845f6 100644
11716--- a/arch/x86/include/asm/elf.h
11717+++ b/arch/x86/include/asm/elf.h
11718@@ -243,7 +243,25 @@ extern int force_personality32;
11719 the loader. We need to make sure that it is out of the way of the program
11720 that it will "exec", and that there is sufficient room for the brk. */
11721
11722+#ifdef CONFIG_PAX_SEGMEXEC
11723+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
11724+#else
11725 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
11726+#endif
11727+
11728+#ifdef CONFIG_PAX_ASLR
11729+#ifdef CONFIG_X86_32
11730+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
11731+
11732+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
11733+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
11734+#else
11735+#define PAX_ELF_ET_DYN_BASE 0x400000UL
11736+
11737+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
11738+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
11739+#endif
11740+#endif
11741
11742 /* This yields a mask that user programs can use to figure out what
11743 instruction set this CPU supports. This could be done in user space,
11744@@ -296,16 +314,12 @@ do { \
11745
11746 #define ARCH_DLINFO \
11747 do { \
11748- if (vdso_enabled) \
11749- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
11750- (unsigned long)current->mm->context.vdso); \
11751+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
11752 } while (0)
11753
11754 #define ARCH_DLINFO_X32 \
11755 do { \
11756- if (vdso_enabled) \
11757- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
11758- (unsigned long)current->mm->context.vdso); \
11759+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
11760 } while (0)
11761
11762 #define AT_SYSINFO 32
11763@@ -320,7 +334,7 @@ else \
11764
11765 #endif /* !CONFIG_X86_32 */
11766
11767-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
11768+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
11769
11770 #define VDSO_ENTRY \
11771 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
11772@@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
11773 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
11774 #define compat_arch_setup_additional_pages syscall32_setup_pages
11775
11776-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
11777-#define arch_randomize_brk arch_randomize_brk
11778-
11779 /*
11780 * True on X86_32 or when emulating IA32 on X86_64
11781 */
11782diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
11783index 75ce3f4..882e801 100644
11784--- a/arch/x86/include/asm/emergency-restart.h
11785+++ b/arch/x86/include/asm/emergency-restart.h
11786@@ -13,6 +13,6 @@ enum reboot_type {
11787
11788 extern enum reboot_type reboot_type;
11789
11790-extern void machine_emergency_restart(void);
11791+extern void machine_emergency_restart(void) __noreturn;
11792
11793 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
11794diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
11795index 41ab26e..a88c9e6 100644
11796--- a/arch/x86/include/asm/fpu-internal.h
11797+++ b/arch/x86/include/asm/fpu-internal.h
11798@@ -126,7 +126,9 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
11799 ({ \
11800 int err; \
11801 asm volatile(ASM_STAC "\n" \
11802- "1:" #insn "\n\t" \
11803+ "1:" \
11804+ __copyuser_seg \
11805+ #insn "\n\t" \
11806 "2: " ASM_CLAC "\n" \
11807 ".section .fixup,\"ax\"\n" \
11808 "3: movl $-1,%[err]\n" \
11809@@ -299,7 +301,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
11810 "emms\n\t" /* clear stack tags */
11811 "fildl %P[addr]", /* set F?P to defined value */
11812 X86_FEATURE_FXSAVE_LEAK,
11813- [addr] "m" (tsk->thread.fpu.has_fpu));
11814+ [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
11815
11816 return fpu_restore_checking(&tsk->thread.fpu);
11817 }
11818diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
11819index f373046..02653e2 100644
11820--- a/arch/x86/include/asm/futex.h
11821+++ b/arch/x86/include/asm/futex.h
11822@@ -12,6 +12,7 @@
11823 #include <asm/smap.h>
11824
11825 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
11826+ typecheck(u32 __user *, uaddr); \
11827 asm volatile("\t" ASM_STAC "\n" \
11828 "1:\t" insn "\n" \
11829 "2:\t" ASM_CLAC "\n" \
11830@@ -20,15 +21,16 @@
11831 "\tjmp\t2b\n" \
11832 "\t.previous\n" \
11833 _ASM_EXTABLE(1b, 3b) \
11834- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
11835+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
11836 : "i" (-EFAULT), "0" (oparg), "1" (0))
11837
11838 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
11839+ typecheck(u32 __user *, uaddr); \
11840 asm volatile("\t" ASM_STAC "\n" \
11841 "1:\tmovl %2, %0\n" \
11842 "\tmovl\t%0, %3\n" \
11843 "\t" insn "\n" \
11844- "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
11845+ "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
11846 "\tjnz\t1b\n" \
11847 "3:\t" ASM_CLAC "\n" \
11848 "\t.section .fixup,\"ax\"\n" \
11849@@ -38,7 +40,7 @@
11850 _ASM_EXTABLE(1b, 4b) \
11851 _ASM_EXTABLE(2b, 4b) \
11852 : "=&a" (oldval), "=&r" (ret), \
11853- "+m" (*uaddr), "=&r" (tem) \
11854+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
11855 : "r" (oparg), "i" (-EFAULT), "1" (0))
11856
11857 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
11858@@ -65,10 +67,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
11859
11860 switch (op) {
11861 case FUTEX_OP_SET:
11862- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
11863+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
11864 break;
11865 case FUTEX_OP_ADD:
11866- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
11867+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
11868 uaddr, oparg);
11869 break;
11870 case FUTEX_OP_OR:
11871@@ -128,14 +130,14 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
11872 return -EFAULT;
11873
11874 asm volatile("\t" ASM_STAC "\n"
11875- "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
11876+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
11877 "2:\t" ASM_CLAC "\n"
11878 "\t.section .fixup, \"ax\"\n"
11879 "3:\tmov %3, %0\n"
11880 "\tjmp 2b\n"
11881 "\t.previous\n"
11882 _ASM_EXTABLE(1b, 3b)
11883- : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
11884+ : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
11885 : "i" (-EFAULT), "r" (newval), "1" (oldval)
11886 : "memory"
11887 );
11888diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
11889index eb92a6e..b98b2f4 100644
11890--- a/arch/x86/include/asm/hw_irq.h
11891+++ b/arch/x86/include/asm/hw_irq.h
11892@@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
11893 extern void enable_IO_APIC(void);
11894
11895 /* Statistics */
11896-extern atomic_t irq_err_count;
11897-extern atomic_t irq_mis_count;
11898+extern atomic_unchecked_t irq_err_count;
11899+extern atomic_unchecked_t irq_mis_count;
11900
11901 /* EISA */
11902 extern void eisa_set_level_irq(unsigned int irq);
11903diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
11904index d8e8eef..15b1179 100644
11905--- a/arch/x86/include/asm/io.h
11906+++ b/arch/x86/include/asm/io.h
11907@@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
11908 return ioremap_nocache(offset, size);
11909 }
11910
11911-extern void iounmap(volatile void __iomem *addr);
11912+extern void iounmap(const volatile void __iomem *addr);
11913
11914 extern void set_iounmap_nonlazy(void);
11915
11916@@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
11917
11918 #include <linux/vmalloc.h>
11919
11920+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
11921+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
11922+{
11923+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
11924+}
11925+
11926+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
11927+{
11928+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
11929+}
11930+
11931 /*
11932 * Convert a virtual cached pointer to an uncached pointer
11933 */
11934diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
11935index bba3cf8..06bc8da 100644
11936--- a/arch/x86/include/asm/irqflags.h
11937+++ b/arch/x86/include/asm/irqflags.h
11938@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
11939 sti; \
11940 sysexit
11941
11942+#define GET_CR0_INTO_RDI mov %cr0, %rdi
11943+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
11944+#define GET_CR3_INTO_RDI mov %cr3, %rdi
11945+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
11946+
11947 #else
11948 #define INTERRUPT_RETURN iret
11949 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
11950diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
11951index d3ddd17..c9fb0cc 100644
11952--- a/arch/x86/include/asm/kprobes.h
11953+++ b/arch/x86/include/asm/kprobes.h
11954@@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
11955 #define RELATIVEJUMP_SIZE 5
11956 #define RELATIVECALL_OPCODE 0xe8
11957 #define RELATIVE_ADDR_SIZE 4
11958-#define MAX_STACK_SIZE 64
11959-#define MIN_STACK_SIZE(ADDR) \
11960- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
11961- THREAD_SIZE - (unsigned long)(ADDR))) \
11962- ? (MAX_STACK_SIZE) \
11963- : (((unsigned long)current_thread_info()) + \
11964- THREAD_SIZE - (unsigned long)(ADDR)))
11965+#define MAX_STACK_SIZE 64UL
11966+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
11967
11968 #define flush_insn_slot(p) do { } while (0)
11969
11970diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
11971index b2e11f4..f293e2e 100644
11972--- a/arch/x86/include/asm/kvm_host.h
11973+++ b/arch/x86/include/asm/kvm_host.h
11974@@ -707,7 +707,7 @@ struct kvm_x86_ops {
11975 int (*check_intercept)(struct kvm_vcpu *vcpu,
11976 struct x86_instruction_info *info,
11977 enum x86_intercept_stage stage);
11978-};
11979+} __do_const;
11980
11981 struct kvm_arch_async_pf {
11982 u32 token;
11983diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
11984index c8bed0d..85c03fd 100644
11985--- a/arch/x86/include/asm/local.h
11986+++ b/arch/x86/include/asm/local.h
11987@@ -10,33 +10,97 @@ typedef struct {
11988 atomic_long_t a;
11989 } local_t;
11990
11991+typedef struct {
11992+ atomic_long_unchecked_t a;
11993+} local_unchecked_t;
11994+
11995 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
11996
11997 #define local_read(l) atomic_long_read(&(l)->a)
11998+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
11999 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
12000+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
12001
12002 static inline void local_inc(local_t *l)
12003 {
12004- asm volatile(_ASM_INC "%0"
12005+ asm volatile(_ASM_INC "%0\n"
12006+
12007+#ifdef CONFIG_PAX_REFCOUNT
12008+ "jno 0f\n"
12009+ _ASM_DEC "%0\n"
12010+ "int $4\n0:\n"
12011+ _ASM_EXTABLE(0b, 0b)
12012+#endif
12013+
12014+ : "+m" (l->a.counter));
12015+}
12016+
12017+static inline void local_inc_unchecked(local_unchecked_t *l)
12018+{
12019+ asm volatile(_ASM_INC "%0\n"
12020 : "+m" (l->a.counter));
12021 }
12022
12023 static inline void local_dec(local_t *l)
12024 {
12025- asm volatile(_ASM_DEC "%0"
12026+ asm volatile(_ASM_DEC "%0\n"
12027+
12028+#ifdef CONFIG_PAX_REFCOUNT
12029+ "jno 0f\n"
12030+ _ASM_INC "%0\n"
12031+ "int $4\n0:\n"
12032+ _ASM_EXTABLE(0b, 0b)
12033+#endif
12034+
12035+ : "+m" (l->a.counter));
12036+}
12037+
12038+static inline void local_dec_unchecked(local_unchecked_t *l)
12039+{
12040+ asm volatile(_ASM_DEC "%0\n"
12041 : "+m" (l->a.counter));
12042 }
12043
12044 static inline void local_add(long i, local_t *l)
12045 {
12046- asm volatile(_ASM_ADD "%1,%0"
12047+ asm volatile(_ASM_ADD "%1,%0\n"
12048+
12049+#ifdef CONFIG_PAX_REFCOUNT
12050+ "jno 0f\n"
12051+ _ASM_SUB "%1,%0\n"
12052+ "int $4\n0:\n"
12053+ _ASM_EXTABLE(0b, 0b)
12054+#endif
12055+
12056+ : "+m" (l->a.counter)
12057+ : "ir" (i));
12058+}
12059+
12060+static inline void local_add_unchecked(long i, local_unchecked_t *l)
12061+{
12062+ asm volatile(_ASM_ADD "%1,%0\n"
12063 : "+m" (l->a.counter)
12064 : "ir" (i));
12065 }
12066
12067 static inline void local_sub(long i, local_t *l)
12068 {
12069- asm volatile(_ASM_SUB "%1,%0"
12070+ asm volatile(_ASM_SUB "%1,%0\n"
12071+
12072+#ifdef CONFIG_PAX_REFCOUNT
12073+ "jno 0f\n"
12074+ _ASM_ADD "%1,%0\n"
12075+ "int $4\n0:\n"
12076+ _ASM_EXTABLE(0b, 0b)
12077+#endif
12078+
12079+ : "+m" (l->a.counter)
12080+ : "ir" (i));
12081+}
12082+
12083+static inline void local_sub_unchecked(long i, local_unchecked_t *l)
12084+{
12085+ asm volatile(_ASM_SUB "%1,%0\n"
12086 : "+m" (l->a.counter)
12087 : "ir" (i));
12088 }
12089@@ -54,7 +118,16 @@ static inline int local_sub_and_test(long i, local_t *l)
12090 {
12091 unsigned char c;
12092
12093- asm volatile(_ASM_SUB "%2,%0; sete %1"
12094+ asm volatile(_ASM_SUB "%2,%0\n"
12095+
12096+#ifdef CONFIG_PAX_REFCOUNT
12097+ "jno 0f\n"
12098+ _ASM_ADD "%2,%0\n"
12099+ "int $4\n0:\n"
12100+ _ASM_EXTABLE(0b, 0b)
12101+#endif
12102+
12103+ "sete %1\n"
12104 : "+m" (l->a.counter), "=qm" (c)
12105 : "ir" (i) : "memory");
12106 return c;
12107@@ -72,7 +145,16 @@ static inline int local_dec_and_test(local_t *l)
12108 {
12109 unsigned char c;
12110
12111- asm volatile(_ASM_DEC "%0; sete %1"
12112+ asm volatile(_ASM_DEC "%0\n"
12113+
12114+#ifdef CONFIG_PAX_REFCOUNT
12115+ "jno 0f\n"
12116+ _ASM_INC "%0\n"
12117+ "int $4\n0:\n"
12118+ _ASM_EXTABLE(0b, 0b)
12119+#endif
12120+
12121+ "sete %1\n"
12122 : "+m" (l->a.counter), "=qm" (c)
12123 : : "memory");
12124 return c != 0;
12125@@ -90,7 +172,16 @@ static inline int local_inc_and_test(local_t *l)
12126 {
12127 unsigned char c;
12128
12129- asm volatile(_ASM_INC "%0; sete %1"
12130+ asm volatile(_ASM_INC "%0\n"
12131+
12132+#ifdef CONFIG_PAX_REFCOUNT
12133+ "jno 0f\n"
12134+ _ASM_DEC "%0\n"
12135+ "int $4\n0:\n"
12136+ _ASM_EXTABLE(0b, 0b)
12137+#endif
12138+
12139+ "sete %1\n"
12140 : "+m" (l->a.counter), "=qm" (c)
12141 : : "memory");
12142 return c != 0;
12143@@ -109,7 +200,16 @@ static inline int local_add_negative(long i, local_t *l)
12144 {
12145 unsigned char c;
12146
12147- asm volatile(_ASM_ADD "%2,%0; sets %1"
12148+ asm volatile(_ASM_ADD "%2,%0\n"
12149+
12150+#ifdef CONFIG_PAX_REFCOUNT
12151+ "jno 0f\n"
12152+ _ASM_SUB "%2,%0\n"
12153+ "int $4\n0:\n"
12154+ _ASM_EXTABLE(0b, 0b)
12155+#endif
12156+
12157+ "sets %1\n"
12158 : "+m" (l->a.counter), "=qm" (c)
12159 : "ir" (i) : "memory");
12160 return c;
12161@@ -132,7 +232,15 @@ static inline long local_add_return(long i, local_t *l)
12162 #endif
12163 /* Modern 486+ processor */
12164 __i = i;
12165- asm volatile(_ASM_XADD "%0, %1;"
12166+ asm volatile(_ASM_XADD "%0, %1\n"
12167+
12168+#ifdef CONFIG_PAX_REFCOUNT
12169+ "jno 0f\n"
12170+ _ASM_MOV "%0,%1\n"
12171+ "int $4\n0:\n"
12172+ _ASM_EXTABLE(0b, 0b)
12173+#endif
12174+
12175 : "+r" (i), "+m" (l->a.counter)
12176 : : "memory");
12177 return i + __i;
12178@@ -147,6 +255,38 @@ no_xadd: /* Legacy 386 processor */
12179 #endif
12180 }
12181
12182+/**
12183+ * local_add_return_unchecked - add and return
12184+ * @i: integer value to add
12185+ * @l: pointer to type local_unchecked_t
12186+ *
12187+ * Atomically adds @i to @l and returns @i + @l
12188+ */
12189+static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
12190+{
12191+ long __i;
12192+#ifdef CONFIG_M386
12193+ unsigned long flags;
12194+ if (unlikely(boot_cpu_data.x86 <= 3))
12195+ goto no_xadd;
12196+#endif
12197+ /* Modern 486+ processor */
12198+ __i = i;
12199+ asm volatile(_ASM_XADD "%0, %1\n"
12200+ : "+r" (i), "+m" (l->a.counter)
12201+ : : "memory");
12202+ return i + __i;
12203+
12204+#ifdef CONFIG_M386
12205+no_xadd: /* Legacy 386 processor */
12206+ local_irq_save(flags);
12207+ __i = local_read_unchecked(l);
12208+ local_set_unchecked(l, i + __i);
12209+ local_irq_restore(flags);
12210+ return i + __i;
12211+#endif
12212+}
12213+
12214 static inline long local_sub_return(long i, local_t *l)
12215 {
12216 return local_add_return(-i, l);
12217@@ -157,6 +297,8 @@ static inline long local_sub_return(long i, local_t *l)
12218
12219 #define local_cmpxchg(l, o, n) \
12220 (cmpxchg_local(&((l)->a.counter), (o), (n)))
12221+#define local_cmpxchg_unchecked(l, o, n) \
12222+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
12223 /* Always has a lock prefix */
12224 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
12225
12226diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
12227index 593e51d..fa69c9a 100644
12228--- a/arch/x86/include/asm/mman.h
12229+++ b/arch/x86/include/asm/mman.h
12230@@ -5,4 +5,14 @@
12231
12232 #include <asm-generic/mman.h>
12233
12234+#ifdef __KERNEL__
12235+#ifndef __ASSEMBLY__
12236+#ifdef CONFIG_X86_32
12237+#define arch_mmap_check i386_mmap_check
12238+int i386_mmap_check(unsigned long addr, unsigned long len,
12239+ unsigned long flags);
12240+#endif
12241+#endif
12242+#endif
12243+
12244 #endif /* _ASM_X86_MMAN_H */
12245diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
12246index 5f55e69..e20bfb1 100644
12247--- a/arch/x86/include/asm/mmu.h
12248+++ b/arch/x86/include/asm/mmu.h
12249@@ -9,7 +9,7 @@
12250 * we put the segment information here.
12251 */
12252 typedef struct {
12253- void *ldt;
12254+ struct desc_struct *ldt;
12255 int size;
12256
12257 #ifdef CONFIG_X86_64
12258@@ -18,7 +18,19 @@ typedef struct {
12259 #endif
12260
12261 struct mutex lock;
12262- void *vdso;
12263+ unsigned long vdso;
12264+
12265+#ifdef CONFIG_X86_32
12266+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
12267+ unsigned long user_cs_base;
12268+ unsigned long user_cs_limit;
12269+
12270+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
12271+ cpumask_t cpu_user_cs_mask;
12272+#endif
12273+
12274+#endif
12275+#endif
12276 } mm_context_t;
12277
12278 #ifdef CONFIG_SMP
12279diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
12280index cdbf367..adb37ac 100644
12281--- a/arch/x86/include/asm/mmu_context.h
12282+++ b/arch/x86/include/asm/mmu_context.h
12283@@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
12284
12285 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
12286 {
12287+
12288+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12289+ unsigned int i;
12290+ pgd_t *pgd;
12291+
12292+ pax_open_kernel();
12293+ pgd = get_cpu_pgd(smp_processor_id());
12294+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
12295+ set_pgd_batched(pgd+i, native_make_pgd(0));
12296+ pax_close_kernel();
12297+#endif
12298+
12299 #ifdef CONFIG_SMP
12300 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
12301 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
12302@@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
12303 struct task_struct *tsk)
12304 {
12305 unsigned cpu = smp_processor_id();
12306+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
12307+ int tlbstate = TLBSTATE_OK;
12308+#endif
12309
12310 if (likely(prev != next)) {
12311 #ifdef CONFIG_SMP
12312+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
12313+ tlbstate = this_cpu_read(cpu_tlbstate.state);
12314+#endif
12315 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
12316 this_cpu_write(cpu_tlbstate.active_mm, next);
12317 #endif
12318 cpumask_set_cpu(cpu, mm_cpumask(next));
12319
12320 /* Re-load page tables */
12321+#ifdef CONFIG_PAX_PER_CPU_PGD
12322+ pax_open_kernel();
12323+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
12324+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
12325+ pax_close_kernel();
12326+ load_cr3(get_cpu_pgd(cpu));
12327+#else
12328 load_cr3(next->pgd);
12329+#endif
12330
12331 /* stop flush ipis for the previous mm */
12332 cpumask_clear_cpu(cpu, mm_cpumask(prev));
12333@@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
12334 */
12335 if (unlikely(prev->context.ldt != next->context.ldt))
12336 load_LDT_nolock(&next->context);
12337- }
12338+
12339+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
12340+ if (!(__supported_pte_mask & _PAGE_NX)) {
12341+ smp_mb__before_clear_bit();
12342+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
12343+ smp_mb__after_clear_bit();
12344+ cpu_set(cpu, next->context.cpu_user_cs_mask);
12345+ }
12346+#endif
12347+
12348+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
12349+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
12350+ prev->context.user_cs_limit != next->context.user_cs_limit))
12351+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
12352 #ifdef CONFIG_SMP
12353+ else if (unlikely(tlbstate != TLBSTATE_OK))
12354+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
12355+#endif
12356+#endif
12357+
12358+ }
12359 else {
12360+
12361+#ifdef CONFIG_PAX_PER_CPU_PGD
12362+ pax_open_kernel();
12363+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
12364+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
12365+ pax_close_kernel();
12366+ load_cr3(get_cpu_pgd(cpu));
12367+#endif
12368+
12369+#ifdef CONFIG_SMP
12370 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
12371 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
12372
12373@@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
12374 * tlb flush IPI delivery. We must reload CR3
12375 * to make sure to use no freed page tables.
12376 */
12377+
12378+#ifndef CONFIG_PAX_PER_CPU_PGD
12379 load_cr3(next->pgd);
12380+#endif
12381+
12382 load_LDT_nolock(&next->context);
12383+
12384+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
12385+ if (!(__supported_pte_mask & _PAGE_NX))
12386+ cpu_set(cpu, next->context.cpu_user_cs_mask);
12387+#endif
12388+
12389+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
12390+#ifdef CONFIG_PAX_PAGEEXEC
12391+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
12392+#endif
12393+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
12394+#endif
12395+
12396 }
12397+#endif
12398 }
12399-#endif
12400 }
12401
12402 #define activate_mm(prev, next) \
12403diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
12404index 9eae775..c914fea 100644
12405--- a/arch/x86/include/asm/module.h
12406+++ b/arch/x86/include/asm/module.h
12407@@ -5,6 +5,7 @@
12408
12409 #ifdef CONFIG_X86_64
12410 /* X86_64 does not define MODULE_PROC_FAMILY */
12411+#define MODULE_PROC_FAMILY ""
12412 #elif defined CONFIG_M386
12413 #define MODULE_PROC_FAMILY "386 "
12414 #elif defined CONFIG_M486
12415@@ -59,8 +60,20 @@
12416 #error unknown processor family
12417 #endif
12418
12419-#ifdef CONFIG_X86_32
12420-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
12421+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
12422+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
12423+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
12424+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
12425+#else
12426+#define MODULE_PAX_KERNEXEC ""
12427 #endif
12428
12429+#ifdef CONFIG_PAX_MEMORY_UDEREF
12430+#define MODULE_PAX_UDEREF "UDEREF "
12431+#else
12432+#define MODULE_PAX_UDEREF ""
12433+#endif
12434+
12435+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
12436+
12437 #endif /* _ASM_X86_MODULE_H */
12438diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
12439index 320f7bb..e89f8f8 100644
12440--- a/arch/x86/include/asm/page_64_types.h
12441+++ b/arch/x86/include/asm/page_64_types.h
12442@@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
12443
12444 /* duplicated to the one in bootmem.h */
12445 extern unsigned long max_pfn;
12446-extern unsigned long phys_base;
12447+extern const unsigned long phys_base;
12448
12449 extern unsigned long __phys_addr(unsigned long);
12450 #define __phys_reloc_hide(x) (x)
12451diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
12452index a0facf3..c017b15 100644
12453--- a/arch/x86/include/asm/paravirt.h
12454+++ b/arch/x86/include/asm/paravirt.h
12455@@ -632,6 +632,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
12456 val);
12457 }
12458
12459+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
12460+{
12461+ pgdval_t val = native_pgd_val(pgd);
12462+
12463+ if (sizeof(pgdval_t) > sizeof(long))
12464+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
12465+ val, (u64)val >> 32);
12466+ else
12467+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
12468+ val);
12469+}
12470+
12471 static inline void pgd_clear(pgd_t *pgdp)
12472 {
12473 set_pgd(pgdp, __pgd(0));
12474@@ -713,6 +725,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
12475 pv_mmu_ops.set_fixmap(idx, phys, flags);
12476 }
12477
12478+#ifdef CONFIG_PAX_KERNEXEC
12479+static inline unsigned long pax_open_kernel(void)
12480+{
12481+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
12482+}
12483+
12484+static inline unsigned long pax_close_kernel(void)
12485+{
12486+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
12487+}
12488+#else
12489+static inline unsigned long pax_open_kernel(void) { return 0; }
12490+static inline unsigned long pax_close_kernel(void) { return 0; }
12491+#endif
12492+
12493 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
12494
12495 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
12496@@ -929,7 +956,7 @@ extern void default_banner(void);
12497
12498 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
12499 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
12500-#define PARA_INDIRECT(addr) *%cs:addr
12501+#define PARA_INDIRECT(addr) *%ss:addr
12502 #endif
12503
12504 #define INTERRUPT_RETURN \
12505@@ -1004,6 +1031,21 @@ extern void default_banner(void);
12506 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
12507 CLBR_NONE, \
12508 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
12509+
12510+#define GET_CR0_INTO_RDI \
12511+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
12512+ mov %rax,%rdi
12513+
12514+#define SET_RDI_INTO_CR0 \
12515+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
12516+
12517+#define GET_CR3_INTO_RDI \
12518+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
12519+ mov %rax,%rdi
12520+
12521+#define SET_RDI_INTO_CR3 \
12522+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
12523+
12524 #endif /* CONFIG_X86_32 */
12525
12526 #endif /* __ASSEMBLY__ */
12527diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
12528index 142236e..57cf5ea 100644
12529--- a/arch/x86/include/asm/paravirt_types.h
12530+++ b/arch/x86/include/asm/paravirt_types.h
12531@@ -312,6 +312,7 @@ struct pv_mmu_ops {
12532 struct paravirt_callee_save make_pud;
12533
12534 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
12535+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
12536 #endif /* PAGETABLE_LEVELS == 4 */
12537 #endif /* PAGETABLE_LEVELS >= 3 */
12538
12539@@ -323,6 +324,12 @@ struct pv_mmu_ops {
12540 an mfn. We can tell which is which from the index. */
12541 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
12542 phys_addr_t phys, pgprot_t flags);
12543+
12544+#ifdef CONFIG_PAX_KERNEXEC
12545+ unsigned long (*pax_open_kernel)(void);
12546+ unsigned long (*pax_close_kernel)(void);
12547+#endif
12548+
12549 };
12550
12551 struct arch_spinlock;
12552diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
12553index b4389a4..7024269 100644
12554--- a/arch/x86/include/asm/pgalloc.h
12555+++ b/arch/x86/include/asm/pgalloc.h
12556@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
12557 pmd_t *pmd, pte_t *pte)
12558 {
12559 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
12560+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
12561+}
12562+
12563+static inline void pmd_populate_user(struct mm_struct *mm,
12564+ pmd_t *pmd, pte_t *pte)
12565+{
12566+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
12567 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
12568 }
12569
12570@@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
12571
12572 #ifdef CONFIG_X86_PAE
12573 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
12574+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
12575+{
12576+ pud_populate(mm, pudp, pmd);
12577+}
12578 #else /* !CONFIG_X86_PAE */
12579 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
12580 {
12581 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
12582 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
12583 }
12584+
12585+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
12586+{
12587+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
12588+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
12589+}
12590 #endif /* CONFIG_X86_PAE */
12591
12592 #if PAGETABLE_LEVELS > 3
12593@@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
12594 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
12595 }
12596
12597+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
12598+{
12599+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
12600+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
12601+}
12602+
12603 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
12604 {
12605 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
12606diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
12607index f2b489c..4f7e2e5 100644
12608--- a/arch/x86/include/asm/pgtable-2level.h
12609+++ b/arch/x86/include/asm/pgtable-2level.h
12610@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
12611
12612 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
12613 {
12614+ pax_open_kernel();
12615 *pmdp = pmd;
12616+ pax_close_kernel();
12617 }
12618
12619 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
12620diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
12621index 4cc9f2b..5fd9226 100644
12622--- a/arch/x86/include/asm/pgtable-3level.h
12623+++ b/arch/x86/include/asm/pgtable-3level.h
12624@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
12625
12626 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
12627 {
12628+ pax_open_kernel();
12629 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
12630+ pax_close_kernel();
12631 }
12632
12633 static inline void native_set_pud(pud_t *pudp, pud_t pud)
12634 {
12635+ pax_open_kernel();
12636 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
12637+ pax_close_kernel();
12638 }
12639
12640 /*
12641diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
12642index a1f780d..a3eb32f 100644
12643--- a/arch/x86/include/asm/pgtable.h
12644+++ b/arch/x86/include/asm/pgtable.h
12645@@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
12646
12647 #ifndef __PAGETABLE_PUD_FOLDED
12648 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
12649+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
12650 #define pgd_clear(pgd) native_pgd_clear(pgd)
12651 #endif
12652
12653@@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
12654
12655 #define arch_end_context_switch(prev) do {} while(0)
12656
12657+#define pax_open_kernel() native_pax_open_kernel()
12658+#define pax_close_kernel() native_pax_close_kernel()
12659 #endif /* CONFIG_PARAVIRT */
12660
12661+#define __HAVE_ARCH_PAX_OPEN_KERNEL
12662+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
12663+
12664+#ifdef CONFIG_PAX_KERNEXEC
12665+static inline unsigned long native_pax_open_kernel(void)
12666+{
12667+ unsigned long cr0;
12668+
12669+ preempt_disable();
12670+ barrier();
12671+ cr0 = read_cr0() ^ X86_CR0_WP;
12672+ BUG_ON(cr0 & X86_CR0_WP);
12673+ write_cr0(cr0);
12674+ return cr0 ^ X86_CR0_WP;
12675+}
12676+
12677+static inline unsigned long native_pax_close_kernel(void)
12678+{
12679+ unsigned long cr0;
12680+
12681+ cr0 = read_cr0() ^ X86_CR0_WP;
12682+ BUG_ON(!(cr0 & X86_CR0_WP));
12683+ write_cr0(cr0);
12684+ barrier();
12685+ preempt_enable_no_resched();
12686+ return cr0 ^ X86_CR0_WP;
12687+}
12688+#else
12689+static inline unsigned long native_pax_open_kernel(void) { return 0; }
12690+static inline unsigned long native_pax_close_kernel(void) { return 0; }
12691+#endif
12692+
12693 /*
12694 * The following only work if pte_present() is true.
12695 * Undefined behaviour if not..
12696 */
12697+static inline int pte_user(pte_t pte)
12698+{
12699+ return pte_val(pte) & _PAGE_USER;
12700+}
12701+
12702 static inline int pte_dirty(pte_t pte)
12703 {
12704 return pte_flags(pte) & _PAGE_DIRTY;
12705@@ -195,9 +235,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
12706 return pte_clear_flags(pte, _PAGE_RW);
12707 }
12708
12709+static inline pte_t pte_mkread(pte_t pte)
12710+{
12711+ return __pte(pte_val(pte) | _PAGE_USER);
12712+}
12713+
12714 static inline pte_t pte_mkexec(pte_t pte)
12715 {
12716- return pte_clear_flags(pte, _PAGE_NX);
12717+#ifdef CONFIG_X86_PAE
12718+ if (__supported_pte_mask & _PAGE_NX)
12719+ return pte_clear_flags(pte, _PAGE_NX);
12720+ else
12721+#endif
12722+ return pte_set_flags(pte, _PAGE_USER);
12723+}
12724+
12725+static inline pte_t pte_exprotect(pte_t pte)
12726+{
12727+#ifdef CONFIG_X86_PAE
12728+ if (__supported_pte_mask & _PAGE_NX)
12729+ return pte_set_flags(pte, _PAGE_NX);
12730+ else
12731+#endif
12732+ return pte_clear_flags(pte, _PAGE_USER);
12733 }
12734
12735 static inline pte_t pte_mkdirty(pte_t pte)
12736@@ -389,6 +449,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
12737 #endif
12738
12739 #ifndef __ASSEMBLY__
12740+
12741+#ifdef CONFIG_PAX_PER_CPU_PGD
12742+extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
12743+static inline pgd_t *get_cpu_pgd(unsigned int cpu)
12744+{
12745+ return cpu_pgd[cpu];
12746+}
12747+#endif
12748+
12749 #include <linux/mm_types.h>
12750
12751 static inline int pte_none(pte_t pte)
12752@@ -565,7 +634,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
12753
12754 static inline int pgd_bad(pgd_t pgd)
12755 {
12756- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
12757+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
12758 }
12759
12760 static inline int pgd_none(pgd_t pgd)
12761@@ -588,7 +657,12 @@ static inline int pgd_none(pgd_t pgd)
12762 * pgd_offset() returns a (pgd_t *)
12763 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
12764 */
12765-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
12766+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
12767+
12768+#ifdef CONFIG_PAX_PER_CPU_PGD
12769+#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
12770+#endif
12771+
12772 /*
12773 * a shortcut which implies the use of the kernel's pgd, instead
12774 * of a process's
12775@@ -599,6 +673,20 @@ static inline int pgd_none(pgd_t pgd)
12776 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
12777 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
12778
12779+#ifdef CONFIG_X86_32
12780+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
12781+#else
12782+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
12783+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
12784+
12785+#ifdef CONFIG_PAX_MEMORY_UDEREF
12786+#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
12787+#else
12788+#define PAX_USER_SHADOW_BASE (_AC(0,UL))
12789+#endif
12790+
12791+#endif
12792+
12793 #ifndef __ASSEMBLY__
12794
12795 extern int direct_gbpages;
12796@@ -763,11 +851,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
12797 * dst and src can be on the same page, but the range must not overlap,
12798 * and must not cross a page boundary.
12799 */
12800-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
12801+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
12802 {
12803- memcpy(dst, src, count * sizeof(pgd_t));
12804+ pax_open_kernel();
12805+ while (count--)
12806+ *dst++ = *src++;
12807+ pax_close_kernel();
12808 }
12809
12810+#ifdef CONFIG_PAX_PER_CPU_PGD
12811+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
12812+#endif
12813+
12814+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12815+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
12816+#else
12817+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
12818+#endif
12819
12820 #include <asm-generic/pgtable.h>
12821 #endif /* __ASSEMBLY__ */
12822diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
12823index 8faa215..a8a17ea 100644
12824--- a/arch/x86/include/asm/pgtable_32.h
12825+++ b/arch/x86/include/asm/pgtable_32.h
12826@@ -25,9 +25,6 @@
12827 struct mm_struct;
12828 struct vm_area_struct;
12829
12830-extern pgd_t swapper_pg_dir[1024];
12831-extern pgd_t initial_page_table[1024];
12832-
12833 static inline void pgtable_cache_init(void) { }
12834 static inline void check_pgt_cache(void) { }
12835 void paging_init(void);
12836@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
12837 # include <asm/pgtable-2level.h>
12838 #endif
12839
12840+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
12841+extern pgd_t initial_page_table[PTRS_PER_PGD];
12842+#ifdef CONFIG_X86_PAE
12843+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
12844+#endif
12845+
12846 #if defined(CONFIG_HIGHPTE)
12847 #define pte_offset_map(dir, address) \
12848 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
12849@@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
12850 /* Clear a kernel PTE and flush it from the TLB */
12851 #define kpte_clear_flush(ptep, vaddr) \
12852 do { \
12853+ pax_open_kernel(); \
12854 pte_clear(&init_mm, (vaddr), (ptep)); \
12855+ pax_close_kernel(); \
12856 __flush_tlb_one((vaddr)); \
12857 } while (0)
12858
12859@@ -75,6 +80,9 @@ do { \
12860
12861 #endif /* !__ASSEMBLY__ */
12862
12863+#define HAVE_ARCH_UNMAPPED_AREA
12864+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
12865+
12866 /*
12867 * kern_addr_valid() is (1) for FLATMEM and (0) for
12868 * SPARSEMEM and DISCONTIGMEM
12869diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
12870index ed5903b..c7fe163 100644
12871--- a/arch/x86/include/asm/pgtable_32_types.h
12872+++ b/arch/x86/include/asm/pgtable_32_types.h
12873@@ -8,7 +8,7 @@
12874 */
12875 #ifdef CONFIG_X86_PAE
12876 # include <asm/pgtable-3level_types.h>
12877-# define PMD_SIZE (1UL << PMD_SHIFT)
12878+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
12879 # define PMD_MASK (~(PMD_SIZE - 1))
12880 #else
12881 # include <asm/pgtable-2level_types.h>
12882@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
12883 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
12884 #endif
12885
12886+#ifdef CONFIG_PAX_KERNEXEC
12887+#ifndef __ASSEMBLY__
12888+extern unsigned char MODULES_EXEC_VADDR[];
12889+extern unsigned char MODULES_EXEC_END[];
12890+#endif
12891+#include <asm/boot.h>
12892+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
12893+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
12894+#else
12895+#define ktla_ktva(addr) (addr)
12896+#define ktva_ktla(addr) (addr)
12897+#endif
12898+
12899 #define MODULES_VADDR VMALLOC_START
12900 #define MODULES_END VMALLOC_END
12901 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
12902diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
12903index 47356f9..deb94a2 100644
12904--- a/arch/x86/include/asm/pgtable_64.h
12905+++ b/arch/x86/include/asm/pgtable_64.h
12906@@ -16,10 +16,14 @@
12907
12908 extern pud_t level3_kernel_pgt[512];
12909 extern pud_t level3_ident_pgt[512];
12910+extern pud_t level3_vmalloc_start_pgt[512];
12911+extern pud_t level3_vmalloc_end_pgt[512];
12912+extern pud_t level3_vmemmap_pgt[512];
12913+extern pud_t level2_vmemmap_pgt[512];
12914 extern pmd_t level2_kernel_pgt[512];
12915 extern pmd_t level2_fixmap_pgt[512];
12916-extern pmd_t level2_ident_pgt[512];
12917-extern pgd_t init_level4_pgt[];
12918+extern pmd_t level2_ident_pgt[512*2];
12919+extern pgd_t init_level4_pgt[512];
12920
12921 #define swapper_pg_dir init_level4_pgt
12922
12923@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
12924
12925 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
12926 {
12927+ pax_open_kernel();
12928 *pmdp = pmd;
12929+ pax_close_kernel();
12930 }
12931
12932 static inline void native_pmd_clear(pmd_t *pmd)
12933@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
12934
12935 static inline void native_set_pud(pud_t *pudp, pud_t pud)
12936 {
12937+ pax_open_kernel();
12938 *pudp = pud;
12939+ pax_close_kernel();
12940 }
12941
12942 static inline void native_pud_clear(pud_t *pud)
12943@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
12944
12945 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
12946 {
12947+ pax_open_kernel();
12948+ *pgdp = pgd;
12949+ pax_close_kernel();
12950+}
12951+
12952+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
12953+{
12954 *pgdp = pgd;
12955 }
12956
12957diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
12958index 766ea16..5b96cb3 100644
12959--- a/arch/x86/include/asm/pgtable_64_types.h
12960+++ b/arch/x86/include/asm/pgtable_64_types.h
12961@@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
12962 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
12963 #define MODULES_END _AC(0xffffffffff000000, UL)
12964 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
12965+#define MODULES_EXEC_VADDR MODULES_VADDR
12966+#define MODULES_EXEC_END MODULES_END
12967+
12968+#define ktla_ktva(addr) (addr)
12969+#define ktva_ktla(addr) (addr)
12970
12971 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
12972diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
12973index ec8a1fc..7ccb593 100644
12974--- a/arch/x86/include/asm/pgtable_types.h
12975+++ b/arch/x86/include/asm/pgtable_types.h
12976@@ -16,13 +16,12 @@
12977 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
12978 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
12979 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
12980-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
12981+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
12982 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
12983 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
12984 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
12985-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
12986-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
12987-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
12988+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
12989+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
12990 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
12991
12992 /* If _PAGE_BIT_PRESENT is clear, we use these: */
12993@@ -40,7 +39,6 @@
12994 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
12995 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
12996 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
12997-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
12998 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
12999 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
13000 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
13001@@ -57,8 +55,10 @@
13002
13003 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
13004 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
13005-#else
13006+#elif defined(CONFIG_KMEMCHECK)
13007 #define _PAGE_NX (_AT(pteval_t, 0))
13008+#else
13009+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
13010 #endif
13011
13012 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
13013@@ -96,6 +96,9 @@
13014 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
13015 _PAGE_ACCESSED)
13016
13017+#define PAGE_READONLY_NOEXEC PAGE_READONLY
13018+#define PAGE_SHARED_NOEXEC PAGE_SHARED
13019+
13020 #define __PAGE_KERNEL_EXEC \
13021 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
13022 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
13023@@ -106,7 +109,7 @@
13024 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
13025 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
13026 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
13027-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
13028+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
13029 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
13030 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
13031 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
13032@@ -168,8 +171,8 @@
13033 * bits are combined, this will alow user to access the high address mapped
13034 * VDSO in the presence of CONFIG_COMPAT_VDSO
13035 */
13036-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
13037-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
13038+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
13039+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
13040 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
13041 #endif
13042
13043@@ -207,7 +210,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
13044 {
13045 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
13046 }
13047+#endif
13048
13049+#if PAGETABLE_LEVELS == 3
13050+#include <asm-generic/pgtable-nopud.h>
13051+#endif
13052+
13053+#if PAGETABLE_LEVELS == 2
13054+#include <asm-generic/pgtable-nopmd.h>
13055+#endif
13056+
13057+#ifndef __ASSEMBLY__
13058 #if PAGETABLE_LEVELS > 3
13059 typedef struct { pudval_t pud; } pud_t;
13060
13061@@ -221,8 +234,6 @@ static inline pudval_t native_pud_val(pud_t pud)
13062 return pud.pud;
13063 }
13064 #else
13065-#include <asm-generic/pgtable-nopud.h>
13066-
13067 static inline pudval_t native_pud_val(pud_t pud)
13068 {
13069 return native_pgd_val(pud.pgd);
13070@@ -242,8 +253,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
13071 return pmd.pmd;
13072 }
13073 #else
13074-#include <asm-generic/pgtable-nopmd.h>
13075-
13076 static inline pmdval_t native_pmd_val(pmd_t pmd)
13077 {
13078 return native_pgd_val(pmd.pud.pgd);
13079@@ -283,7 +292,6 @@ typedef struct page *pgtable_t;
13080
13081 extern pteval_t __supported_pte_mask;
13082 extern void set_nx(void);
13083-extern int nx_enabled;
13084
13085 #define pgprot_writecombine pgprot_writecombine
13086 extern pgprot_t pgprot_writecombine(pgprot_t prot);
13087diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
13088index ad1fc85..0b15fe1 100644
13089--- a/arch/x86/include/asm/processor.h
13090+++ b/arch/x86/include/asm/processor.h
13091@@ -289,7 +289,7 @@ struct tss_struct {
13092
13093 } ____cacheline_aligned;
13094
13095-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
13096+extern struct tss_struct init_tss[NR_CPUS];
13097
13098 /*
13099 * Save the original ist values for checking stack pointers during debugging
13100@@ -818,11 +818,18 @@ static inline void spin_lock_prefetch(const void *x)
13101 */
13102 #define TASK_SIZE PAGE_OFFSET
13103 #define TASK_SIZE_MAX TASK_SIZE
13104+
13105+#ifdef CONFIG_PAX_SEGMEXEC
13106+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
13107+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
13108+#else
13109 #define STACK_TOP TASK_SIZE
13110-#define STACK_TOP_MAX STACK_TOP
13111+#endif
13112+
13113+#define STACK_TOP_MAX TASK_SIZE
13114
13115 #define INIT_THREAD { \
13116- .sp0 = sizeof(init_stack) + (long)&init_stack, \
13117+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
13118 .vm86_info = NULL, \
13119 .sysenter_cs = __KERNEL_CS, \
13120 .io_bitmap_ptr = NULL, \
13121@@ -836,7 +843,7 @@ static inline void spin_lock_prefetch(const void *x)
13122 */
13123 #define INIT_TSS { \
13124 .x86_tss = { \
13125- .sp0 = sizeof(init_stack) + (long)&init_stack, \
13126+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
13127 .ss0 = __KERNEL_DS, \
13128 .ss1 = __KERNEL_CS, \
13129 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
13130@@ -847,11 +854,7 @@ static inline void spin_lock_prefetch(const void *x)
13131 extern unsigned long thread_saved_pc(struct task_struct *tsk);
13132
13133 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
13134-#define KSTK_TOP(info) \
13135-({ \
13136- unsigned long *__ptr = (unsigned long *)(info); \
13137- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
13138-})
13139+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
13140
13141 /*
13142 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
13143@@ -866,7 +869,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
13144 #define task_pt_regs(task) \
13145 ({ \
13146 struct pt_regs *__regs__; \
13147- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
13148+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
13149 __regs__ - 1; \
13150 })
13151
13152@@ -876,13 +879,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
13153 /*
13154 * User space process size. 47bits minus one guard page.
13155 */
13156-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
13157+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
13158
13159 /* This decides where the kernel will search for a free chunk of vm
13160 * space during mmap's.
13161 */
13162 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
13163- 0xc0000000 : 0xFFFFe000)
13164+ 0xc0000000 : 0xFFFFf000)
13165
13166 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
13167 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
13168@@ -893,11 +896,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
13169 #define STACK_TOP_MAX TASK_SIZE_MAX
13170
13171 #define INIT_THREAD { \
13172- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
13173+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
13174 }
13175
13176 #define INIT_TSS { \
13177- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
13178+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
13179 }
13180
13181 /*
13182@@ -925,6 +928,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
13183 */
13184 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
13185
13186+#ifdef CONFIG_PAX_SEGMEXEC
13187+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
13188+#endif
13189+
13190 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
13191
13192 /* Get/set a process' ability to use the timestamp counter instruction */
13193@@ -985,12 +992,12 @@ extern bool cpu_has_amd_erratum(const int *);
13194 #define cpu_has_amd_erratum(x) (false)
13195 #endif /* CONFIG_CPU_SUP_AMD */
13196
13197-extern unsigned long arch_align_stack(unsigned long sp);
13198+#define arch_align_stack(x) ((x) & ~0xfUL)
13199 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
13200
13201 void default_idle(void);
13202 bool set_pm_idle_to_default(void);
13203
13204-void stop_this_cpu(void *dummy);
13205+void stop_this_cpu(void *dummy) __noreturn;
13206
13207 #endif /* _ASM_X86_PROCESSOR_H */
13208diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
13209index 19f16eb..b50624b 100644
13210--- a/arch/x86/include/asm/ptrace.h
13211+++ b/arch/x86/include/asm/ptrace.h
13212@@ -155,28 +155,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
13213 }
13214
13215 /*
13216- * user_mode_vm(regs) determines whether a register set came from user mode.
13217+ * user_mode(regs) determines whether a register set came from user mode.
13218 * This is true if V8086 mode was enabled OR if the register set was from
13219 * protected mode with RPL-3 CS value. This tricky test checks that with
13220 * one comparison. Many places in the kernel can bypass this full check
13221- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
13222+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
13223+ * be used.
13224 */
13225-static inline int user_mode(struct pt_regs *regs)
13226+static inline int user_mode_novm(struct pt_regs *regs)
13227 {
13228 #ifdef CONFIG_X86_32
13229 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
13230 #else
13231- return !!(regs->cs & 3);
13232+ return !!(regs->cs & SEGMENT_RPL_MASK);
13233 #endif
13234 }
13235
13236-static inline int user_mode_vm(struct pt_regs *regs)
13237+static inline int user_mode(struct pt_regs *regs)
13238 {
13239 #ifdef CONFIG_X86_32
13240 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
13241 USER_RPL;
13242 #else
13243- return user_mode(regs);
13244+ return user_mode_novm(regs);
13245 #endif
13246 }
13247
13248@@ -192,15 +193,16 @@ static inline int v8086_mode(struct pt_regs *regs)
13249 #ifdef CONFIG_X86_64
13250 static inline bool user_64bit_mode(struct pt_regs *regs)
13251 {
13252+ unsigned long cs = regs->cs & 0xffff;
13253 #ifndef CONFIG_PARAVIRT
13254 /*
13255 * On non-paravirt systems, this is the only long mode CPL 3
13256 * selector. We do not allow long mode selectors in the LDT.
13257 */
13258- return regs->cs == __USER_CS;
13259+ return cs == __USER_CS;
13260 #else
13261 /* Headers are too twisted for this to go in paravirt.h. */
13262- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
13263+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
13264 #endif
13265 }
13266 #endif
13267diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
13268index fe1ec5b..dc5c3fe 100644
13269--- a/arch/x86/include/asm/realmode.h
13270+++ b/arch/x86/include/asm/realmode.h
13271@@ -22,16 +22,14 @@ struct real_mode_header {
13272 #endif
13273 /* APM/BIOS reboot */
13274 u32 machine_real_restart_asm;
13275-#ifdef CONFIG_X86_64
13276 u32 machine_real_restart_seg;
13277-#endif
13278 };
13279
13280 /* This must match data at trampoline_32/64.S */
13281 struct trampoline_header {
13282 #ifdef CONFIG_X86_32
13283 u32 start;
13284- u16 gdt_pad;
13285+ u16 boot_cs;
13286 u16 gdt_limit;
13287 u32 gdt_base;
13288 #else
13289diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
13290index a82c4f1..f9c9696 100644
13291--- a/arch/x86/include/asm/reboot.h
13292+++ b/arch/x86/include/asm/reboot.h
13293@@ -6,12 +6,12 @@
13294 struct pt_regs;
13295
13296 struct machine_ops {
13297- void (*restart)(char *cmd);
13298- void (*halt)(void);
13299- void (*power_off)(void);
13300+ void (* __noreturn restart)(char *cmd);
13301+ void (* __noreturn halt)(void);
13302+ void (* __noreturn power_off)(void);
13303 void (*shutdown)(void);
13304 void (*crash_shutdown)(struct pt_regs *);
13305- void (*emergency_restart)(void);
13306+ void (* __noreturn emergency_restart)(void);
13307 };
13308
13309 extern struct machine_ops machine_ops;
13310diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
13311index 2dbe4a7..ce1db00 100644
13312--- a/arch/x86/include/asm/rwsem.h
13313+++ b/arch/x86/include/asm/rwsem.h
13314@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
13315 {
13316 asm volatile("# beginning down_read\n\t"
13317 LOCK_PREFIX _ASM_INC "(%1)\n\t"
13318+
13319+#ifdef CONFIG_PAX_REFCOUNT
13320+ "jno 0f\n"
13321+ LOCK_PREFIX _ASM_DEC "(%1)\n"
13322+ "int $4\n0:\n"
13323+ _ASM_EXTABLE(0b, 0b)
13324+#endif
13325+
13326 /* adds 0x00000001 */
13327 " jns 1f\n"
13328 " call call_rwsem_down_read_failed\n"
13329@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
13330 "1:\n\t"
13331 " mov %1,%2\n\t"
13332 " add %3,%2\n\t"
13333+
13334+#ifdef CONFIG_PAX_REFCOUNT
13335+ "jno 0f\n"
13336+ "sub %3,%2\n"
13337+ "int $4\n0:\n"
13338+ _ASM_EXTABLE(0b, 0b)
13339+#endif
13340+
13341 " jle 2f\n\t"
13342 LOCK_PREFIX " cmpxchg %2,%0\n\t"
13343 " jnz 1b\n\t"
13344@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
13345 long tmp;
13346 asm volatile("# beginning down_write\n\t"
13347 LOCK_PREFIX " xadd %1,(%2)\n\t"
13348+
13349+#ifdef CONFIG_PAX_REFCOUNT
13350+ "jno 0f\n"
13351+ "mov %1,(%2)\n"
13352+ "int $4\n0:\n"
13353+ _ASM_EXTABLE(0b, 0b)
13354+#endif
13355+
13356 /* adds 0xffff0001, returns the old value */
13357 " test %1,%1\n\t"
13358 /* was the count 0 before? */
13359@@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
13360 long tmp;
13361 asm volatile("# beginning __up_read\n\t"
13362 LOCK_PREFIX " xadd %1,(%2)\n\t"
13363+
13364+#ifdef CONFIG_PAX_REFCOUNT
13365+ "jno 0f\n"
13366+ "mov %1,(%2)\n"
13367+ "int $4\n0:\n"
13368+ _ASM_EXTABLE(0b, 0b)
13369+#endif
13370+
13371 /* subtracts 1, returns the old value */
13372 " jns 1f\n\t"
13373 " call call_rwsem_wake\n" /* expects old value in %edx */
13374@@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
13375 long tmp;
13376 asm volatile("# beginning __up_write\n\t"
13377 LOCK_PREFIX " xadd %1,(%2)\n\t"
13378+
13379+#ifdef CONFIG_PAX_REFCOUNT
13380+ "jno 0f\n"
13381+ "mov %1,(%2)\n"
13382+ "int $4\n0:\n"
13383+ _ASM_EXTABLE(0b, 0b)
13384+#endif
13385+
13386 /* subtracts 0xffff0001, returns the old value */
13387 " jns 1f\n\t"
13388 " call call_rwsem_wake\n" /* expects old value in %edx */
13389@@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
13390 {
13391 asm volatile("# beginning __downgrade_write\n\t"
13392 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
13393+
13394+#ifdef CONFIG_PAX_REFCOUNT
13395+ "jno 0f\n"
13396+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
13397+ "int $4\n0:\n"
13398+ _ASM_EXTABLE(0b, 0b)
13399+#endif
13400+
13401 /*
13402 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
13403 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
13404@@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
13405 */
13406 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
13407 {
13408- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
13409+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
13410+
13411+#ifdef CONFIG_PAX_REFCOUNT
13412+ "jno 0f\n"
13413+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
13414+ "int $4\n0:\n"
13415+ _ASM_EXTABLE(0b, 0b)
13416+#endif
13417+
13418 : "+m" (sem->count)
13419 : "er" (delta));
13420 }
13421@@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
13422 */
13423 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
13424 {
13425- return delta + xadd(&sem->count, delta);
13426+ return delta + xadd_check_overflow(&sem->count, delta);
13427 }
13428
13429 #endif /* __KERNEL__ */
13430diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
13431index c48a950..c6d7468 100644
13432--- a/arch/x86/include/asm/segment.h
13433+++ b/arch/x86/include/asm/segment.h
13434@@ -64,10 +64,15 @@
13435 * 26 - ESPFIX small SS
13436 * 27 - per-cpu [ offset to per-cpu data area ]
13437 * 28 - stack_canary-20 [ for stack protector ]
13438- * 29 - unused
13439- * 30 - unused
13440+ * 29 - PCI BIOS CS
13441+ * 30 - PCI BIOS DS
13442 * 31 - TSS for double fault handler
13443 */
13444+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
13445+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
13446+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
13447+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
13448+
13449 #define GDT_ENTRY_TLS_MIN 6
13450 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
13451
13452@@ -79,6 +84,8 @@
13453
13454 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
13455
13456+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
13457+
13458 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
13459
13460 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
13461@@ -104,6 +111,12 @@
13462 #define __KERNEL_STACK_CANARY 0
13463 #endif
13464
13465+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
13466+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
13467+
13468+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
13469+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
13470+
13471 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
13472
13473 /*
13474@@ -141,7 +154,7 @@
13475 */
13476
13477 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
13478-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
13479+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
13480
13481
13482 #else
13483@@ -165,6 +178,8 @@
13484 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
13485 #define __USER32_DS __USER_DS
13486
13487+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
13488+
13489 #define GDT_ENTRY_TSS 8 /* needs two entries */
13490 #define GDT_ENTRY_LDT 10 /* needs two entries */
13491 #define GDT_ENTRY_TLS_MIN 12
13492@@ -185,6 +200,7 @@
13493 #endif
13494
13495 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
13496+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
13497 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
13498 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
13499 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
13500@@ -265,7 +281,7 @@ static inline unsigned long get_limit(unsigned long segment)
13501 {
13502 unsigned long __limit;
13503 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
13504- return __limit + 1;
13505+ return __limit;
13506 }
13507
13508 #endif /* !__ASSEMBLY__ */
13509diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
13510index 4f19a15..e04d86f 100644
13511--- a/arch/x86/include/asm/smp.h
13512+++ b/arch/x86/include/asm/smp.h
13513@@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
13514 /* cpus sharing the last level cache: */
13515 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
13516 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
13517-DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
13518+DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
13519
13520 static inline struct cpumask *cpu_sibling_mask(int cpu)
13521 {
13522@@ -190,14 +190,8 @@ extern unsigned disabled_cpus __cpuinitdata;
13523 extern int safe_smp_processor_id(void);
13524
13525 #elif defined(CONFIG_X86_64_SMP)
13526-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
13527-
13528-#define stack_smp_processor_id() \
13529-({ \
13530- struct thread_info *ti; \
13531- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
13532- ti->cpu; \
13533-})
13534+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
13535+#define stack_smp_processor_id() raw_smp_processor_id()
13536 #define safe_smp_processor_id() smp_processor_id()
13537
13538 #endif
13539diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
13540index 33692ea..350a534 100644
13541--- a/arch/x86/include/asm/spinlock.h
13542+++ b/arch/x86/include/asm/spinlock.h
13543@@ -172,6 +172,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
13544 static inline void arch_read_lock(arch_rwlock_t *rw)
13545 {
13546 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
13547+
13548+#ifdef CONFIG_PAX_REFCOUNT
13549+ "jno 0f\n"
13550+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
13551+ "int $4\n0:\n"
13552+ _ASM_EXTABLE(0b, 0b)
13553+#endif
13554+
13555 "jns 1f\n"
13556 "call __read_lock_failed\n\t"
13557 "1:\n"
13558@@ -181,6 +189,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
13559 static inline void arch_write_lock(arch_rwlock_t *rw)
13560 {
13561 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
13562+
13563+#ifdef CONFIG_PAX_REFCOUNT
13564+ "jno 0f\n"
13565+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
13566+ "int $4\n0:\n"
13567+ _ASM_EXTABLE(0b, 0b)
13568+#endif
13569+
13570 "jz 1f\n"
13571 "call __write_lock_failed\n\t"
13572 "1:\n"
13573@@ -210,13 +226,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
13574
13575 static inline void arch_read_unlock(arch_rwlock_t *rw)
13576 {
13577- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
13578+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
13579+
13580+#ifdef CONFIG_PAX_REFCOUNT
13581+ "jno 0f\n"
13582+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
13583+ "int $4\n0:\n"
13584+ _ASM_EXTABLE(0b, 0b)
13585+#endif
13586+
13587 :"+m" (rw->lock) : : "memory");
13588 }
13589
13590 static inline void arch_write_unlock(arch_rwlock_t *rw)
13591 {
13592- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
13593+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
13594+
13595+#ifdef CONFIG_PAX_REFCOUNT
13596+ "jno 0f\n"
13597+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
13598+ "int $4\n0:\n"
13599+ _ASM_EXTABLE(0b, 0b)
13600+#endif
13601+
13602 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
13603 }
13604
13605diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
13606index 6a99859..03cb807 100644
13607--- a/arch/x86/include/asm/stackprotector.h
13608+++ b/arch/x86/include/asm/stackprotector.h
13609@@ -47,7 +47,7 @@
13610 * head_32 for boot CPU and setup_per_cpu_areas() for others.
13611 */
13612 #define GDT_STACK_CANARY_INIT \
13613- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
13614+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
13615
13616 /*
13617 * Initialize the stackprotector canary value.
13618@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
13619
13620 static inline void load_stack_canary_segment(void)
13621 {
13622-#ifdef CONFIG_X86_32
13623+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
13624 asm volatile ("mov %0, %%gs" : : "r" (0));
13625 #endif
13626 }
13627diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
13628index 70bbe39..4ae2bd4 100644
13629--- a/arch/x86/include/asm/stacktrace.h
13630+++ b/arch/x86/include/asm/stacktrace.h
13631@@ -11,28 +11,20 @@
13632
13633 extern int kstack_depth_to_print;
13634
13635-struct thread_info;
13636+struct task_struct;
13637 struct stacktrace_ops;
13638
13639-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
13640- unsigned long *stack,
13641- unsigned long bp,
13642- const struct stacktrace_ops *ops,
13643- void *data,
13644- unsigned long *end,
13645- int *graph);
13646+typedef unsigned long walk_stack_t(struct task_struct *task,
13647+ void *stack_start,
13648+ unsigned long *stack,
13649+ unsigned long bp,
13650+ const struct stacktrace_ops *ops,
13651+ void *data,
13652+ unsigned long *end,
13653+ int *graph);
13654
13655-extern unsigned long
13656-print_context_stack(struct thread_info *tinfo,
13657- unsigned long *stack, unsigned long bp,
13658- const struct stacktrace_ops *ops, void *data,
13659- unsigned long *end, int *graph);
13660-
13661-extern unsigned long
13662-print_context_stack_bp(struct thread_info *tinfo,
13663- unsigned long *stack, unsigned long bp,
13664- const struct stacktrace_ops *ops, void *data,
13665- unsigned long *end, int *graph);
13666+extern walk_stack_t print_context_stack;
13667+extern walk_stack_t print_context_stack_bp;
13668
13669 /* Generic stack tracer with callbacks */
13670
13671@@ -40,7 +32,7 @@ struct stacktrace_ops {
13672 void (*address)(void *data, unsigned long address, int reliable);
13673 /* On negative return stop dumping */
13674 int (*stack)(void *data, char *name);
13675- walk_stack_t walk_stack;
13676+ walk_stack_t *walk_stack;
13677 };
13678
13679 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
13680diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
13681index 4ec45b3..a4f0a8a 100644
13682--- a/arch/x86/include/asm/switch_to.h
13683+++ b/arch/x86/include/asm/switch_to.h
13684@@ -108,7 +108,7 @@ do { \
13685 "call __switch_to\n\t" \
13686 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
13687 __switch_canary \
13688- "movq %P[thread_info](%%rsi),%%r8\n\t" \
13689+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
13690 "movq %%rax,%%rdi\n\t" \
13691 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
13692 "jnz ret_from_fork\n\t" \
13693@@ -119,7 +119,7 @@ do { \
13694 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
13695 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
13696 [_tif_fork] "i" (_TIF_FORK), \
13697- [thread_info] "i" (offsetof(struct task_struct, stack)), \
13698+ [thread_info] "m" (current_tinfo), \
13699 [current_task] "m" (current_task) \
13700 __switch_canary_iparam \
13701 : "memory", "cc" __EXTRA_CLOBBER)
13702diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
13703index 2d946e6..e453ec4 100644
13704--- a/arch/x86/include/asm/thread_info.h
13705+++ b/arch/x86/include/asm/thread_info.h
13706@@ -10,6 +10,7 @@
13707 #include <linux/compiler.h>
13708 #include <asm/page.h>
13709 #include <asm/types.h>
13710+#include <asm/percpu.h>
13711
13712 /*
13713 * low level task data that entry.S needs immediate access to
13714@@ -24,7 +25,6 @@ struct exec_domain;
13715 #include <linux/atomic.h>
13716
13717 struct thread_info {
13718- struct task_struct *task; /* main task structure */
13719 struct exec_domain *exec_domain; /* execution domain */
13720 __u32 flags; /* low level flags */
13721 __u32 status; /* thread synchronous flags */
13722@@ -34,19 +34,13 @@ struct thread_info {
13723 mm_segment_t addr_limit;
13724 struct restart_block restart_block;
13725 void __user *sysenter_return;
13726-#ifdef CONFIG_X86_32
13727- unsigned long previous_esp; /* ESP of the previous stack in
13728- case of nested (IRQ) stacks
13729- */
13730- __u8 supervisor_stack[0];
13731-#endif
13732+ unsigned long lowest_stack;
13733 unsigned int sig_on_uaccess_error:1;
13734 unsigned int uaccess_err:1; /* uaccess failed */
13735 };
13736
13737-#define INIT_THREAD_INFO(tsk) \
13738+#define INIT_THREAD_INFO \
13739 { \
13740- .task = &tsk, \
13741 .exec_domain = &default_exec_domain, \
13742 .flags = 0, \
13743 .cpu = 0, \
13744@@ -57,7 +51,7 @@ struct thread_info {
13745 }, \
13746 }
13747
13748-#define init_thread_info (init_thread_union.thread_info)
13749+#define init_thread_info (init_thread_union.stack)
13750 #define init_stack (init_thread_union.stack)
13751
13752 #else /* !__ASSEMBLY__ */
13753@@ -98,6 +92,7 @@ struct thread_info {
13754 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
13755 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
13756 #define TIF_X32 30 /* 32-bit native x86-64 binary */
13757+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
13758
13759 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
13760 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
13761@@ -122,17 +117,18 @@ struct thread_info {
13762 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
13763 #define _TIF_ADDR32 (1 << TIF_ADDR32)
13764 #define _TIF_X32 (1 << TIF_X32)
13765+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
13766
13767 /* work to do in syscall_trace_enter() */
13768 #define _TIF_WORK_SYSCALL_ENTRY \
13769 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
13770 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
13771- _TIF_NOHZ)
13772+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
13773
13774 /* work to do in syscall_trace_leave() */
13775 #define _TIF_WORK_SYSCALL_EXIT \
13776 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
13777- _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
13778+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
13779
13780 /* work to do on interrupt/exception return */
13781 #define _TIF_WORK_MASK \
13782@@ -143,7 +139,7 @@ struct thread_info {
13783 /* work to do on any return to user space */
13784 #define _TIF_ALLWORK_MASK \
13785 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
13786- _TIF_NOHZ)
13787+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
13788
13789 /* Only used for 64 bit */
13790 #define _TIF_DO_NOTIFY_MASK \
13791@@ -159,45 +155,40 @@ struct thread_info {
13792
13793 #define PREEMPT_ACTIVE 0x10000000
13794
13795-#ifdef CONFIG_X86_32
13796-
13797-#define STACK_WARN (THREAD_SIZE/8)
13798-/*
13799- * macros/functions for gaining access to the thread information structure
13800- *
13801- * preempt_count needs to be 1 initially, until the scheduler is functional.
13802- */
13803-#ifndef __ASSEMBLY__
13804-
13805-
13806-/* how to get the current stack pointer from C */
13807-register unsigned long current_stack_pointer asm("esp") __used;
13808-
13809-/* how to get the thread information struct from C */
13810-static inline struct thread_info *current_thread_info(void)
13811-{
13812- return (struct thread_info *)
13813- (current_stack_pointer & ~(THREAD_SIZE - 1));
13814-}
13815-
13816-#else /* !__ASSEMBLY__ */
13817-
13818+#ifdef __ASSEMBLY__
13819 /* how to get the thread information struct from ASM */
13820 #define GET_THREAD_INFO(reg) \
13821- movl $-THREAD_SIZE, reg; \
13822- andl %esp, reg
13823+ mov PER_CPU_VAR(current_tinfo), reg
13824
13825 /* use this one if reg already contains %esp */
13826-#define GET_THREAD_INFO_WITH_ESP(reg) \
13827- andl $-THREAD_SIZE, reg
13828+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
13829+#else
13830+/* how to get the thread information struct from C */
13831+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
13832+
13833+static __always_inline struct thread_info *current_thread_info(void)
13834+{
13835+ return this_cpu_read_stable(current_tinfo);
13836+}
13837+#endif
13838+
13839+#ifdef CONFIG_X86_32
13840+
13841+#define STACK_WARN (THREAD_SIZE/8)
13842+/*
13843+ * macros/functions for gaining access to the thread information structure
13844+ *
13845+ * preempt_count needs to be 1 initially, until the scheduler is functional.
13846+ */
13847+#ifndef __ASSEMBLY__
13848+
13849+/* how to get the current stack pointer from C */
13850+register unsigned long current_stack_pointer asm("esp") __used;
13851
13852 #endif
13853
13854 #else /* X86_32 */
13855
13856-#include <asm/percpu.h>
13857-#define KERNEL_STACK_OFFSET (5*8)
13858-
13859 /*
13860 * macros/functions for gaining access to the thread information structure
13861 * preempt_count needs to be 1 initially, until the scheduler is functional.
13862@@ -205,27 +196,8 @@ static inline struct thread_info *current_thread_info(void)
13863 #ifndef __ASSEMBLY__
13864 DECLARE_PER_CPU(unsigned long, kernel_stack);
13865
13866-static inline struct thread_info *current_thread_info(void)
13867-{
13868- struct thread_info *ti;
13869- ti = (void *)(this_cpu_read_stable(kernel_stack) +
13870- KERNEL_STACK_OFFSET - THREAD_SIZE);
13871- return ti;
13872-}
13873-
13874-#else /* !__ASSEMBLY__ */
13875-
13876-/* how to get the thread information struct from ASM */
13877-#define GET_THREAD_INFO(reg) \
13878- movq PER_CPU_VAR(kernel_stack),reg ; \
13879- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
13880-
13881-/*
13882- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
13883- * a certain register (to be used in assembler memory operands).
13884- */
13885-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
13886-
13887+/* how to get the current stack pointer from C */
13888+register unsigned long current_stack_pointer asm("rsp") __used;
13889 #endif
13890
13891 #endif /* !X86_32 */
13892@@ -286,5 +258,12 @@ static inline bool is_ia32_task(void)
13893 extern void arch_task_cache_init(void);
13894 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
13895 extern void arch_release_task_struct(struct task_struct *tsk);
13896+
13897+#define __HAVE_THREAD_FUNCTIONS
13898+#define task_thread_info(task) (&(task)->tinfo)
13899+#define task_stack_page(task) ((task)->stack)
13900+#define setup_thread_stack(p, org) do {} while (0)
13901+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
13902+
13903 #endif
13904 #endif /* _ASM_X86_THREAD_INFO_H */
13905diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
13906index 7ccf8d1..9a18110 100644
13907--- a/arch/x86/include/asm/uaccess.h
13908+++ b/arch/x86/include/asm/uaccess.h
13909@@ -7,6 +7,7 @@
13910 #include <linux/compiler.h>
13911 #include <linux/thread_info.h>
13912 #include <linux/string.h>
13913+#include <linux/sched.h>
13914 #include <asm/asm.h>
13915 #include <asm/page.h>
13916 #include <asm/smap.h>
13917@@ -29,7 +30,12 @@
13918
13919 #define get_ds() (KERNEL_DS)
13920 #define get_fs() (current_thread_info()->addr_limit)
13921+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
13922+void __set_fs(mm_segment_t x);
13923+void set_fs(mm_segment_t x);
13924+#else
13925 #define set_fs(x) (current_thread_info()->addr_limit = (x))
13926+#endif
13927
13928 #define segment_eq(a, b) ((a).seg == (b).seg)
13929
13930@@ -77,8 +83,33 @@
13931 * checks that the pointer is in the user space range - after calling
13932 * this function, memory access functions may still return -EFAULT.
13933 */
13934-#define access_ok(type, addr, size) \
13935- (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
13936+#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
13937+#define access_ok(type, addr, size) \
13938+({ \
13939+ long __size = size; \
13940+ unsigned long __addr = (unsigned long)addr; \
13941+ unsigned long __addr_ao = __addr & PAGE_MASK; \
13942+ unsigned long __end_ao = __addr + __size - 1; \
13943+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
13944+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
13945+ while(__addr_ao <= __end_ao) { \
13946+ char __c_ao; \
13947+ __addr_ao += PAGE_SIZE; \
13948+ if (__size > PAGE_SIZE) \
13949+ cond_resched(); \
13950+ if (__get_user(__c_ao, (char __user *)__addr)) \
13951+ break; \
13952+ if (type != VERIFY_WRITE) { \
13953+ __addr = __addr_ao; \
13954+ continue; \
13955+ } \
13956+ if (__put_user(__c_ao, (char __user *)__addr)) \
13957+ break; \
13958+ __addr = __addr_ao; \
13959+ } \
13960+ } \
13961+ __ret_ao; \
13962+})
13963
13964 /*
13965 * The exception table consists of pairs of addresses relative to the
13966@@ -189,13 +220,21 @@ extern int __get_user_bad(void);
13967 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
13968 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
13969
13970-
13971+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
13972+#define __copyuser_seg "gs;"
13973+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
13974+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
13975+#else
13976+#define __copyuser_seg
13977+#define __COPYUSER_SET_ES
13978+#define __COPYUSER_RESTORE_ES
13979+#endif
13980
13981 #ifdef CONFIG_X86_32
13982 #define __put_user_asm_u64(x, addr, err, errret) \
13983 asm volatile(ASM_STAC "\n" \
13984- "1: movl %%eax,0(%2)\n" \
13985- "2: movl %%edx,4(%2)\n" \
13986+ "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
13987+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
13988 "3: " ASM_CLAC "\n" \
13989 ".section .fixup,\"ax\"\n" \
13990 "4: movl %3,%0\n" \
13991@@ -208,8 +247,8 @@ extern int __get_user_bad(void);
13992
13993 #define __put_user_asm_ex_u64(x, addr) \
13994 asm volatile(ASM_STAC "\n" \
13995- "1: movl %%eax,0(%1)\n" \
13996- "2: movl %%edx,4(%1)\n" \
13997+ "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
13998+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
13999 "3: " ASM_CLAC "\n" \
14000 _ASM_EXTABLE_EX(1b, 2b) \
14001 _ASM_EXTABLE_EX(2b, 3b) \
14002@@ -261,7 +300,7 @@ extern void __put_user_8(void);
14003 __typeof__(*(ptr)) __pu_val; \
14004 __chk_user_ptr(ptr); \
14005 might_fault(); \
14006- __pu_val = x; \
14007+ __pu_val = (x); \
14008 switch (sizeof(*(ptr))) { \
14009 case 1: \
14010 __put_user_x(1, __pu_val, ptr, __ret_pu); \
14011@@ -383,7 +422,7 @@ do { \
14012
14013 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
14014 asm volatile(ASM_STAC "\n" \
14015- "1: mov"itype" %2,%"rtype"1\n" \
14016+ "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
14017 "2: " ASM_CLAC "\n" \
14018 ".section .fixup,\"ax\"\n" \
14019 "3: mov %3,%0\n" \
14020@@ -391,7 +430,7 @@ do { \
14021 " jmp 2b\n" \
14022 ".previous\n" \
14023 _ASM_EXTABLE(1b, 3b) \
14024- : "=r" (err), ltype(x) \
14025+ : "=r" (err), ltype (x) \
14026 : "m" (__m(addr)), "i" (errret), "0" (err))
14027
14028 #define __get_user_size_ex(x, ptr, size) \
14029@@ -416,7 +455,7 @@ do { \
14030 } while (0)
14031
14032 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
14033- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
14034+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
14035 "2:\n" \
14036 _ASM_EXTABLE_EX(1b, 2b) \
14037 : ltype(x) : "m" (__m(addr)))
14038@@ -433,13 +472,24 @@ do { \
14039 int __gu_err; \
14040 unsigned long __gu_val; \
14041 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
14042- (x) = (__force __typeof__(*(ptr)))__gu_val; \
14043+ (x) = (__typeof__(*(ptr)))__gu_val; \
14044 __gu_err; \
14045 })
14046
14047 /* FIXME: this hack is definitely wrong -AK */
14048 struct __large_struct { unsigned long buf[100]; };
14049-#define __m(x) (*(struct __large_struct __user *)(x))
14050+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
14051+#define ____m(x) \
14052+({ \
14053+ unsigned long ____x = (unsigned long)(x); \
14054+ if (____x < PAX_USER_SHADOW_BASE) \
14055+ ____x += PAX_USER_SHADOW_BASE; \
14056+ (void __user *)____x; \
14057+})
14058+#else
14059+#define ____m(x) (x)
14060+#endif
14061+#define __m(x) (*(struct __large_struct __user *)____m(x))
14062
14063 /*
14064 * Tell gcc we read from memory instead of writing: this is because
14065@@ -448,7 +498,7 @@ struct __large_struct { unsigned long buf[100]; };
14066 */
14067 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
14068 asm volatile(ASM_STAC "\n" \
14069- "1: mov"itype" %"rtype"1,%2\n" \
14070+ "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
14071 "2: " ASM_CLAC "\n" \
14072 ".section .fixup,\"ax\"\n" \
14073 "3: mov %3,%0\n" \
14074@@ -456,10 +506,10 @@ struct __large_struct { unsigned long buf[100]; };
14075 ".previous\n" \
14076 _ASM_EXTABLE(1b, 3b) \
14077 : "=r"(err) \
14078- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
14079+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
14080
14081 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
14082- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
14083+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
14084 "2:\n" \
14085 _ASM_EXTABLE_EX(1b, 2b) \
14086 : : ltype(x), "m" (__m(addr)))
14087@@ -498,8 +548,12 @@ struct __large_struct { unsigned long buf[100]; };
14088 * On error, the variable @x is set to zero.
14089 */
14090
14091+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
14092+#define __get_user(x, ptr) get_user((x), (ptr))
14093+#else
14094 #define __get_user(x, ptr) \
14095 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
14096+#endif
14097
14098 /**
14099 * __put_user: - Write a simple value into user space, with less checking.
14100@@ -521,8 +575,12 @@ struct __large_struct { unsigned long buf[100]; };
14101 * Returns zero on success, or -EFAULT on error.
14102 */
14103
14104+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
14105+#define __put_user(x, ptr) put_user((x), (ptr))
14106+#else
14107 #define __put_user(x, ptr) \
14108 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
14109+#endif
14110
14111 #define __get_user_unaligned __get_user
14112 #define __put_user_unaligned __put_user
14113@@ -540,7 +598,7 @@ struct __large_struct { unsigned long buf[100]; };
14114 #define get_user_ex(x, ptr) do { \
14115 unsigned long __gue_val; \
14116 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
14117- (x) = (__force __typeof__(*(ptr)))__gue_val; \
14118+ (x) = (__typeof__(*(ptr)))__gue_val; \
14119 } while (0)
14120
14121 #ifdef CONFIG_X86_WP_WORKS_OK
14122@@ -574,8 +632,8 @@ strncpy_from_user(char *dst, const char __user *src, long count);
14123 extern __must_check long strlen_user(const char __user *str);
14124 extern __must_check long strnlen_user(const char __user *str, long n);
14125
14126-unsigned long __must_check clear_user(void __user *mem, unsigned long len);
14127-unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
14128+unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
14129+unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
14130
14131 /*
14132 * movsl can be slow when source and dest are not both 8-byte aligned
14133diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
14134index 7f760a9..04b1c65 100644
14135--- a/arch/x86/include/asm/uaccess_32.h
14136+++ b/arch/x86/include/asm/uaccess_32.h
14137@@ -11,15 +11,15 @@
14138 #include <asm/page.h>
14139
14140 unsigned long __must_check __copy_to_user_ll
14141- (void __user *to, const void *from, unsigned long n);
14142+ (void __user *to, const void *from, unsigned long n) __size_overflow(3);
14143 unsigned long __must_check __copy_from_user_ll
14144- (void *to, const void __user *from, unsigned long n);
14145+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
14146 unsigned long __must_check __copy_from_user_ll_nozero
14147- (void *to, const void __user *from, unsigned long n);
14148+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
14149 unsigned long __must_check __copy_from_user_ll_nocache
14150- (void *to, const void __user *from, unsigned long n);
14151+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
14152 unsigned long __must_check __copy_from_user_ll_nocache_nozero
14153- (void *to, const void __user *from, unsigned long n);
14154+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
14155
14156 /**
14157 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
14158@@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
14159 static __always_inline unsigned long __must_check
14160 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
14161 {
14162+ if ((long)n < 0)
14163+ return n;
14164+
14165+ check_object_size(from, n, true);
14166+
14167 if (__builtin_constant_p(n)) {
14168 unsigned long ret;
14169
14170@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
14171 __copy_to_user(void __user *to, const void *from, unsigned long n)
14172 {
14173 might_fault();
14174+
14175 return __copy_to_user_inatomic(to, from, n);
14176 }
14177
14178 static __always_inline unsigned long
14179 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
14180 {
14181+ if ((long)n < 0)
14182+ return n;
14183+
14184 /* Avoid zeroing the tail if the copy fails..
14185 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
14186 * but as the zeroing behaviour is only significant when n is not
14187@@ -137,6 +146,12 @@ static __always_inline unsigned long
14188 __copy_from_user(void *to, const void __user *from, unsigned long n)
14189 {
14190 might_fault();
14191+
14192+ if ((long)n < 0)
14193+ return n;
14194+
14195+ check_object_size(to, n, false);
14196+
14197 if (__builtin_constant_p(n)) {
14198 unsigned long ret;
14199
14200@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
14201 const void __user *from, unsigned long n)
14202 {
14203 might_fault();
14204+
14205+ if ((long)n < 0)
14206+ return n;
14207+
14208 if (__builtin_constant_p(n)) {
14209 unsigned long ret;
14210
14211@@ -181,15 +200,19 @@ static __always_inline unsigned long
14212 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
14213 unsigned long n)
14214 {
14215- return __copy_from_user_ll_nocache_nozero(to, from, n);
14216+ if ((long)n < 0)
14217+ return n;
14218+
14219+ return __copy_from_user_ll_nocache_nozero(to, from, n);
14220 }
14221
14222-unsigned long __must_check copy_to_user(void __user *to,
14223- const void *from, unsigned long n);
14224-unsigned long __must_check _copy_from_user(void *to,
14225- const void __user *from,
14226- unsigned long n);
14227-
14228+extern void copy_to_user_overflow(void)
14229+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
14230+ __compiletime_error("copy_to_user() buffer size is not provably correct")
14231+#else
14232+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
14233+#endif
14234+;
14235
14236 extern void copy_from_user_overflow(void)
14237 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
14238@@ -199,17 +222,60 @@ extern void copy_from_user_overflow(void)
14239 #endif
14240 ;
14241
14242-static inline unsigned long __must_check copy_from_user(void *to,
14243- const void __user *from,
14244- unsigned long n)
14245+/**
14246+ * copy_to_user: - Copy a block of data into user space.
14247+ * @to: Destination address, in user space.
14248+ * @from: Source address, in kernel space.
14249+ * @n: Number of bytes to copy.
14250+ *
14251+ * Context: User context only. This function may sleep.
14252+ *
14253+ * Copy data from kernel space to user space.
14254+ *
14255+ * Returns number of bytes that could not be copied.
14256+ * On success, this will be zero.
14257+ */
14258+static inline unsigned long __must_check
14259+copy_to_user(void __user *to, const void *from, unsigned long n)
14260 {
14261- int sz = __compiletime_object_size(to);
14262+ size_t sz = __compiletime_object_size(from);
14263
14264- if (likely(sz == -1 || sz >= n))
14265- n = _copy_from_user(to, from, n);
14266- else
14267+ if (unlikely(sz != (size_t)-1 && sz < n))
14268+ copy_to_user_overflow();
14269+ else if (access_ok(VERIFY_WRITE, to, n))
14270+ n = __copy_to_user(to, from, n);
14271+ return n;
14272+}
14273+
14274+/**
14275+ * copy_from_user: - Copy a block of data from user space.
14276+ * @to: Destination address, in kernel space.
14277+ * @from: Source address, in user space.
14278+ * @n: Number of bytes to copy.
14279+ *
14280+ * Context: User context only. This function may sleep.
14281+ *
14282+ * Copy data from user space to kernel space.
14283+ *
14284+ * Returns number of bytes that could not be copied.
14285+ * On success, this will be zero.
14286+ *
14287+ * If some data could not be copied, this function will pad the copied
14288+ * data to the requested size using zero bytes.
14289+ */
14290+static inline unsigned long __must_check
14291+copy_from_user(void *to, const void __user *from, unsigned long n)
14292+{
14293+ size_t sz = __compiletime_object_size(to);
14294+
14295+ check_object_size(to, n, false);
14296+
14297+ if (unlikely(sz != (size_t)-1 && sz < n))
14298 copy_from_user_overflow();
14299-
14300+ else if (access_ok(VERIFY_READ, from, n))
14301+ n = __copy_from_user(to, from, n);
14302+ else if ((long)n > 0)
14303+ memset(to, 0, n);
14304 return n;
14305 }
14306
14307diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
14308index 142810c..4b68a3e 100644
14309--- a/arch/x86/include/asm/uaccess_64.h
14310+++ b/arch/x86/include/asm/uaccess_64.h
14311@@ -10,6 +10,9 @@
14312 #include <asm/alternative.h>
14313 #include <asm/cpufeature.h>
14314 #include <asm/page.h>
14315+#include <asm/pgtable.h>
14316+
14317+#define set_fs(x) (current_thread_info()->addr_limit = (x))
14318
14319 /*
14320 * Copy To/From Userspace
14321@@ -17,13 +20,13 @@
14322
14323 /* Handles exceptions in both to and from, but doesn't do access_ok */
14324 __must_check unsigned long
14325-copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
14326+copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
14327 __must_check unsigned long
14328-copy_user_generic_string(void *to, const void *from, unsigned len);
14329+copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
14330 __must_check unsigned long
14331-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
14332+copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
14333
14334-static __always_inline __must_check unsigned long
14335+static __always_inline __must_check __size_overflow(3) unsigned long
14336 copy_user_generic(void *to, const void *from, unsigned len)
14337 {
14338 unsigned ret;
14339@@ -41,142 +44,203 @@ copy_user_generic(void *to, const void *from, unsigned len)
14340 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
14341 "=d" (len)),
14342 "1" (to), "2" (from), "3" (len)
14343- : "memory", "rcx", "r8", "r9", "r10", "r11");
14344+ : "memory", "rcx", "r8", "r9", "r11");
14345 return ret;
14346 }
14347
14348+static __always_inline __must_check unsigned long
14349+__copy_to_user(void __user *to, const void *from, unsigned long len) __size_overflow(3);
14350+static __always_inline __must_check unsigned long
14351+__copy_from_user(void *to, const void __user *from, unsigned long len) __size_overflow(3);
14352 __must_check unsigned long
14353-_copy_to_user(void __user *to, const void *from, unsigned len);
14354-__must_check unsigned long
14355-_copy_from_user(void *to, const void __user *from, unsigned len);
14356-__must_check unsigned long
14357-copy_in_user(void __user *to, const void __user *from, unsigned len);
14358+copy_in_user(void __user *to, const void __user *from, unsigned long len) __size_overflow(3);
14359+
14360+extern void copy_to_user_overflow(void)
14361+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
14362+ __compiletime_error("copy_to_user() buffer size is not provably correct")
14363+#else
14364+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
14365+#endif
14366+;
14367+
14368+extern void copy_from_user_overflow(void)
14369+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
14370+ __compiletime_error("copy_from_user() buffer size is not provably correct")
14371+#else
14372+ __compiletime_warning("copy_from_user() buffer size is not provably correct")
14373+#endif
14374+;
14375
14376 static inline unsigned long __must_check copy_from_user(void *to,
14377 const void __user *from,
14378 unsigned long n)
14379 {
14380- int sz = __compiletime_object_size(to);
14381-
14382 might_fault();
14383- if (likely(sz == -1 || sz >= n))
14384- n = _copy_from_user(to, from, n);
14385-#ifdef CONFIG_DEBUG_VM
14386- else
14387- WARN(1, "Buffer overflow detected!\n");
14388-#endif
14389+
14390+ check_object_size(to, n, false);
14391+ if (access_ok(VERIFY_READ, from, n))
14392+ n = __copy_from_user(to, from, n);
14393+ else if (n < INT_MAX)
14394+ memset(to, 0, n);
14395 return n;
14396 }
14397
14398 static __always_inline __must_check
14399-int copy_to_user(void __user *dst, const void *src, unsigned size)
14400+int copy_to_user(void __user *dst, const void *src, unsigned long size)
14401 {
14402 might_fault();
14403
14404- return _copy_to_user(dst, src, size);
14405+ if (access_ok(VERIFY_WRITE, dst, size))
14406+ size = __copy_to_user(dst, src, size);
14407+ return size;
14408 }
14409
14410 static __always_inline __must_check
14411-int __copy_from_user(void *dst, const void __user *src, unsigned size)
14412+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
14413 {
14414- int ret = 0;
14415+ size_t sz = __compiletime_object_size(dst);
14416+ unsigned ret = 0;
14417
14418 might_fault();
14419+
14420+ if (size > INT_MAX)
14421+ return size;
14422+
14423+ check_object_size(dst, size, false);
14424+
14425+#ifdef CONFIG_PAX_MEMORY_UDEREF
14426+ if (!__access_ok(VERIFY_READ, src, size))
14427+ return size;
14428+#endif
14429+
14430+ if (unlikely(sz != (size_t)-1 && sz < size)) {
14431+ copy_from_user_overflow();
14432+ return size;
14433+ }
14434+
14435 if (!__builtin_constant_p(size))
14436- return copy_user_generic(dst, (__force void *)src, size);
14437+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
14438 switch (size) {
14439- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
14440+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
14441 ret, "b", "b", "=q", 1);
14442 return ret;
14443- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
14444+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
14445 ret, "w", "w", "=r", 2);
14446 return ret;
14447- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
14448+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
14449 ret, "l", "k", "=r", 4);
14450 return ret;
14451- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
14452+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
14453 ret, "q", "", "=r", 8);
14454 return ret;
14455 case 10:
14456- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
14457+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
14458 ret, "q", "", "=r", 10);
14459 if (unlikely(ret))
14460 return ret;
14461 __get_user_asm(*(u16 *)(8 + (char *)dst),
14462- (u16 __user *)(8 + (char __user *)src),
14463+ (const u16 __user *)(8 + (const char __user *)src),
14464 ret, "w", "w", "=r", 2);
14465 return ret;
14466 case 16:
14467- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
14468+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
14469 ret, "q", "", "=r", 16);
14470 if (unlikely(ret))
14471 return ret;
14472 __get_user_asm(*(u64 *)(8 + (char *)dst),
14473- (u64 __user *)(8 + (char __user *)src),
14474+ (const u64 __user *)(8 + (const char __user *)src),
14475 ret, "q", "", "=r", 8);
14476 return ret;
14477 default:
14478- return copy_user_generic(dst, (__force void *)src, size);
14479+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
14480 }
14481 }
14482
14483 static __always_inline __must_check
14484-int __copy_to_user(void __user *dst, const void *src, unsigned size)
14485+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
14486 {
14487- int ret = 0;
14488+ size_t sz = __compiletime_object_size(src);
14489+ unsigned ret = 0;
14490
14491 might_fault();
14492+
14493+ if (size > INT_MAX)
14494+ return size;
14495+
14496+ check_object_size(src, size, true);
14497+
14498+#ifdef CONFIG_PAX_MEMORY_UDEREF
14499+ if (!__access_ok(VERIFY_WRITE, dst, size))
14500+ return size;
14501+#endif
14502+
14503+ if (unlikely(sz != (size_t)-1 && sz < size)) {
14504+ copy_to_user_overflow();
14505+ return size;
14506+ }
14507+
14508 if (!__builtin_constant_p(size))
14509- return copy_user_generic((__force void *)dst, src, size);
14510+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
14511 switch (size) {
14512- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
14513+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
14514 ret, "b", "b", "iq", 1);
14515 return ret;
14516- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
14517+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
14518 ret, "w", "w", "ir", 2);
14519 return ret;
14520- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
14521+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
14522 ret, "l", "k", "ir", 4);
14523 return ret;
14524- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
14525+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
14526 ret, "q", "", "er", 8);
14527 return ret;
14528 case 10:
14529- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
14530+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
14531 ret, "q", "", "er", 10);
14532 if (unlikely(ret))
14533 return ret;
14534 asm("":::"memory");
14535- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
14536+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
14537 ret, "w", "w", "ir", 2);
14538 return ret;
14539 case 16:
14540- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
14541+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
14542 ret, "q", "", "er", 16);
14543 if (unlikely(ret))
14544 return ret;
14545 asm("":::"memory");
14546- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
14547+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
14548 ret, "q", "", "er", 8);
14549 return ret;
14550 default:
14551- return copy_user_generic((__force void *)dst, src, size);
14552+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
14553 }
14554 }
14555
14556 static __always_inline __must_check
14557-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
14558+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
14559 {
14560- int ret = 0;
14561+ unsigned ret = 0;
14562
14563 might_fault();
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+ if (!__access_ok(VERIFY_WRITE, dst, size))
14572+ return size;
14573+#endif
14574+
14575 if (!__builtin_constant_p(size))
14576- return copy_user_generic((__force void *)dst,
14577- (__force void *)src, size);
14578+ return copy_user_generic((__force_kernel void *)____m(dst),
14579+ (__force_kernel const void *)____m(src), size);
14580 switch (size) {
14581 case 1: {
14582 u8 tmp;
14583- __get_user_asm(tmp, (u8 __user *)src,
14584+ __get_user_asm(tmp, (const u8 __user *)src,
14585 ret, "b", "b", "=q", 1);
14586 if (likely(!ret))
14587 __put_user_asm(tmp, (u8 __user *)dst,
14588@@ -185,7 +249,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
14589 }
14590 case 2: {
14591 u16 tmp;
14592- __get_user_asm(tmp, (u16 __user *)src,
14593+ __get_user_asm(tmp, (const u16 __user *)src,
14594 ret, "w", "w", "=r", 2);
14595 if (likely(!ret))
14596 __put_user_asm(tmp, (u16 __user *)dst,
14597@@ -195,7 +259,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
14598
14599 case 4: {
14600 u32 tmp;
14601- __get_user_asm(tmp, (u32 __user *)src,
14602+ __get_user_asm(tmp, (const u32 __user *)src,
14603 ret, "l", "k", "=r", 4);
14604 if (likely(!ret))
14605 __put_user_asm(tmp, (u32 __user *)dst,
14606@@ -204,7 +268,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
14607 }
14608 case 8: {
14609 u64 tmp;
14610- __get_user_asm(tmp, (u64 __user *)src,
14611+ __get_user_asm(tmp, (const u64 __user *)src,
14612 ret, "q", "", "=r", 8);
14613 if (likely(!ret))
14614 __put_user_asm(tmp, (u64 __user *)dst,
14615@@ -212,41 +276,72 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
14616 return ret;
14617 }
14618 default:
14619- return copy_user_generic((__force void *)dst,
14620- (__force void *)src, size);
14621+ return copy_user_generic((__force_kernel void *)____m(dst),
14622+ (__force_kernel const void *)____m(src), size);
14623 }
14624 }
14625
14626 static __must_check __always_inline int
14627-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
14628+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
14629 {
14630- return copy_user_generic(dst, (__force const void *)src, size);
14631+ if (size > INT_MAX)
14632+ return size;
14633+
14634+#ifdef CONFIG_PAX_MEMORY_UDEREF
14635+ if (!__access_ok(VERIFY_READ, src, size))
14636+ return size;
14637+#endif
14638+
14639+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
14640 }
14641
14642-static __must_check __always_inline int
14643-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
14644+static __must_check __always_inline unsigned long
14645+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
14646 {
14647- return copy_user_generic((__force void *)dst, src, size);
14648+ if (size > INT_MAX)
14649+ return size;
14650+
14651+#ifdef CONFIG_PAX_MEMORY_UDEREF
14652+ if (!__access_ok(VERIFY_WRITE, dst, size))
14653+ return size;
14654+#endif
14655+
14656+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
14657 }
14658
14659-extern long __copy_user_nocache(void *dst, const void __user *src,
14660- unsigned size, int zerorest);
14661+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
14662+ unsigned long size, int zerorest) __size_overflow(3);
14663
14664-static inline int
14665-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
14666+static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
14667 {
14668 might_sleep();
14669+
14670+ if (size > INT_MAX)
14671+ return size;
14672+
14673+#ifdef CONFIG_PAX_MEMORY_UDEREF
14674+ if (!__access_ok(VERIFY_READ, src, size))
14675+ return size;
14676+#endif
14677+
14678 return __copy_user_nocache(dst, src, size, 1);
14679 }
14680
14681-static inline int
14682-__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
14683- unsigned size)
14684+static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
14685+ unsigned long size)
14686 {
14687+ if (size > INT_MAX)
14688+ return size;
14689+
14690+#ifdef CONFIG_PAX_MEMORY_UDEREF
14691+ if (!__access_ok(VERIFY_READ, src, size))
14692+ return size;
14693+#endif
14694+
14695 return __copy_user_nocache(dst, src, size, 0);
14696 }
14697
14698-unsigned long
14699-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
14700+extern unsigned long
14701+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
14702
14703 #endif /* _ASM_X86_UACCESS_64_H */
14704diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
14705index 5b238981..77fdd78 100644
14706--- a/arch/x86/include/asm/word-at-a-time.h
14707+++ b/arch/x86/include/asm/word-at-a-time.h
14708@@ -11,7 +11,7 @@
14709 * and shift, for example.
14710 */
14711 struct word_at_a_time {
14712- const unsigned long one_bits, high_bits;
14713+ unsigned long one_bits, high_bits;
14714 };
14715
14716 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
14717diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
14718index 0415cda..b43d877 100644
14719--- a/arch/x86/include/asm/xsave.h
14720+++ b/arch/x86/include/asm/xsave.h
14721@@ -71,7 +71,9 @@ static inline int xsave_user(struct xsave_struct __user *buf)
14722 return -EFAULT;
14723
14724 __asm__ __volatile__(ASM_STAC "\n"
14725- "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
14726+ "1:"
14727+ __copyuser_seg
14728+ ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
14729 "2: " ASM_CLAC "\n"
14730 ".section .fixup,\"ax\"\n"
14731 "3: movl $-1,%[err]\n"
14732@@ -87,12 +89,14 @@ static inline int xsave_user(struct xsave_struct __user *buf)
14733 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
14734 {
14735 int err;
14736- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
14737+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
14738 u32 lmask = mask;
14739 u32 hmask = mask >> 32;
14740
14741 __asm__ __volatile__(ASM_STAC "\n"
14742- "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
14743+ "1:"
14744+ __copyuser_seg
14745+ ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
14746 "2: " ASM_CLAC "\n"
14747 ".section .fixup,\"ax\"\n"
14748 "3: movl $-1,%[err]\n"
14749diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
14750index 91ce48f..a48ea05 100644
14751--- a/arch/x86/kernel/Makefile
14752+++ b/arch/x86/kernel/Makefile
14753@@ -23,7 +23,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
14754 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
14755 obj-$(CONFIG_IRQ_WORK) += irq_work.o
14756 obj-y += probe_roms.o
14757-obj-$(CONFIG_X86_32) += i386_ksyms_32.o
14758+obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
14759 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
14760 obj-y += syscall_$(BITS).o
14761 obj-$(CONFIG_X86_64) += vsyscall_64.o
14762diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
14763index e651f7a..c995dc4 100644
14764--- a/arch/x86/kernel/acpi/boot.c
14765+++ b/arch/x86/kernel/acpi/boot.c
14766@@ -1576,7 +1576,7 @@ int __init acpi_boot_init(void)
14767 acpi_table_parse(ACPI_SIG_HPET, acpi_parse_hpet);
14768
14769 if (!acpi_noirq)
14770- x86_init.pci.init = pci_acpi_init;
14771+ *(void **)&x86_init.pci.init = pci_acpi_init;
14772
14773 return 0;
14774 }
14775diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
14776index 11676cf..a8cf3ec 100644
14777--- a/arch/x86/kernel/acpi/sleep.c
14778+++ b/arch/x86/kernel/acpi/sleep.c
14779@@ -74,8 +74,12 @@ int acpi_suspend_lowlevel(void)
14780 #else /* CONFIG_64BIT */
14781 #ifdef CONFIG_SMP
14782 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
14783+
14784+ pax_open_kernel();
14785 early_gdt_descr.address =
14786 (unsigned long)get_cpu_gdt_table(smp_processor_id());
14787+ pax_close_kernel();
14788+
14789 initial_gs = per_cpu_offset(smp_processor_id());
14790 #endif
14791 initial_code = (unsigned long)wakeup_long64;
14792diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
14793index 13ab720..95d5442 100644
14794--- a/arch/x86/kernel/acpi/wakeup_32.S
14795+++ b/arch/x86/kernel/acpi/wakeup_32.S
14796@@ -30,13 +30,11 @@ wakeup_pmode_return:
14797 # and restore the stack ... but you need gdt for this to work
14798 movl saved_context_esp, %esp
14799
14800- movl %cs:saved_magic, %eax
14801- cmpl $0x12345678, %eax
14802+ cmpl $0x12345678, saved_magic
14803 jne bogus_magic
14804
14805 # jump to place where we left off
14806- movl saved_eip, %eax
14807- jmp *%eax
14808+ jmp *(saved_eip)
14809
14810 bogus_magic:
14811 jmp bogus_magic
14812diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
14813index ef5ccca..bd83949 100644
14814--- a/arch/x86/kernel/alternative.c
14815+++ b/arch/x86/kernel/alternative.c
14816@@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
14817 */
14818 for (a = start; a < end; a++) {
14819 instr = (u8 *)&a->instr_offset + a->instr_offset;
14820+
14821+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
14822+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
14823+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
14824+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
14825+#endif
14826+
14827 replacement = (u8 *)&a->repl_offset + a->repl_offset;
14828 BUG_ON(a->replacementlen > a->instrlen);
14829 BUG_ON(a->instrlen > sizeof(insnbuf));
14830@@ -299,10 +306,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
14831 for (poff = start; poff < end; poff++) {
14832 u8 *ptr = (u8 *)poff + *poff;
14833
14834+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
14835+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
14836+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
14837+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
14838+#endif
14839+
14840 if (!*poff || ptr < text || ptr >= text_end)
14841 continue;
14842 /* turn DS segment override prefix into lock prefix */
14843- if (*ptr == 0x3e)
14844+ if (*ktla_ktva(ptr) == 0x3e)
14845 text_poke(ptr, ((unsigned char []){0xf0}), 1);
14846 }
14847 mutex_unlock(&text_mutex);
14848@@ -317,10 +330,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
14849 for (poff = start; poff < end; poff++) {
14850 u8 *ptr = (u8 *)poff + *poff;
14851
14852+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
14853+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
14854+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
14855+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
14856+#endif
14857+
14858 if (!*poff || ptr < text || ptr >= text_end)
14859 continue;
14860 /* turn lock prefix into DS segment override prefix */
14861- if (*ptr == 0xf0)
14862+ if (*ktla_ktva(ptr) == 0xf0)
14863 text_poke(ptr, ((unsigned char []){0x3E}), 1);
14864 }
14865 mutex_unlock(&text_mutex);
14866@@ -468,7 +487,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
14867
14868 BUG_ON(p->len > MAX_PATCH_LEN);
14869 /* prep the buffer with the original instructions */
14870- memcpy(insnbuf, p->instr, p->len);
14871+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
14872 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
14873 (unsigned long)p->instr, p->len);
14874
14875@@ -515,7 +534,7 @@ void __init alternative_instructions(void)
14876 if (!uniproc_patched || num_possible_cpus() == 1)
14877 free_init_pages("SMP alternatives",
14878 (unsigned long)__smp_locks,
14879- (unsigned long)__smp_locks_end);
14880+ PAGE_ALIGN((unsigned long)__smp_locks_end));
14881 #endif
14882
14883 apply_paravirt(__parainstructions, __parainstructions_end);
14884@@ -535,13 +554,17 @@ void __init alternative_instructions(void)
14885 * instructions. And on the local CPU you need to be protected again NMI or MCE
14886 * handlers seeing an inconsistent instruction while you patch.
14887 */
14888-void *__init_or_module text_poke_early(void *addr, const void *opcode,
14889+void *__kprobes text_poke_early(void *addr, const void *opcode,
14890 size_t len)
14891 {
14892 unsigned long flags;
14893 local_irq_save(flags);
14894- memcpy(addr, opcode, len);
14895+
14896+ pax_open_kernel();
14897+ memcpy(ktla_ktva(addr), opcode, len);
14898 sync_core();
14899+ pax_close_kernel();
14900+
14901 local_irq_restore(flags);
14902 /* Could also do a CLFLUSH here to speed up CPU recovery; but
14903 that causes hangs on some VIA CPUs. */
14904@@ -563,36 +586,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
14905 */
14906 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
14907 {
14908- unsigned long flags;
14909- char *vaddr;
14910+ unsigned char *vaddr = ktla_ktva(addr);
14911 struct page *pages[2];
14912- int i;
14913+ size_t i;
14914
14915 if (!core_kernel_text((unsigned long)addr)) {
14916- pages[0] = vmalloc_to_page(addr);
14917- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
14918+ pages[0] = vmalloc_to_page(vaddr);
14919+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
14920 } else {
14921- pages[0] = virt_to_page(addr);
14922+ pages[0] = virt_to_page(vaddr);
14923 WARN_ON(!PageReserved(pages[0]));
14924- pages[1] = virt_to_page(addr + PAGE_SIZE);
14925+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
14926 }
14927 BUG_ON(!pages[0]);
14928- local_irq_save(flags);
14929- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
14930- if (pages[1])
14931- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
14932- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
14933- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
14934- clear_fixmap(FIX_TEXT_POKE0);
14935- if (pages[1])
14936- clear_fixmap(FIX_TEXT_POKE1);
14937- local_flush_tlb();
14938- sync_core();
14939- /* Could also do a CLFLUSH here to speed up CPU recovery; but
14940- that causes hangs on some VIA CPUs. */
14941+ text_poke_early(addr, opcode, len);
14942 for (i = 0; i < len; i++)
14943- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
14944- local_irq_restore(flags);
14945+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
14946 return addr;
14947 }
14948
14949diff --git a/arch/x86/kernel/amd_gart_64.c b/arch/x86/kernel/amd_gart_64.c
14950index e663112..21938a3 100644
14951--- a/arch/x86/kernel/amd_gart_64.c
14952+++ b/arch/x86/kernel/amd_gart_64.c
14953@@ -851,7 +851,7 @@ int __init gart_iommu_init(void)
14954
14955 flush_gart();
14956 dma_ops = &gart_dma_ops;
14957- x86_platform.iommu_shutdown = gart_iommu_shutdown;
14958+ *(void **)&x86_platform.iommu_shutdown = gart_iommu_shutdown;
14959 swiotlb = 0;
14960
14961 return 0;
14962diff --git a/arch/x86/kernel/aperture_64.c b/arch/x86/kernel/aperture_64.c
14963index d5fd66f..6119b16 100644
14964--- a/arch/x86/kernel/aperture_64.c
14965+++ b/arch/x86/kernel/aperture_64.c
14966@@ -390,7 +390,7 @@ int __init gart_iommu_hole_init(void)
14967
14968 iommu_detected = 1;
14969 gart_iommu_aperture = 1;
14970- x86_init.iommu.iommu_init = gart_iommu_init;
14971+ *(void **)&x86_init.iommu.iommu_init = gart_iommu_init;
14972
14973 ctl = read_pci_config(bus, slot, 3,
14974 AMD64_GARTAPERTURECTL);
14975diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
14976index b17416e..be6e5dc 100644
14977--- a/arch/x86/kernel/apic/apic.c
14978+++ b/arch/x86/kernel/apic/apic.c
14979@@ -185,7 +185,7 @@ int first_system_vector = 0xfe;
14980 /*
14981 * Debug level, exported for io_apic.c
14982 */
14983-unsigned int apic_verbosity;
14984+int apic_verbosity;
14985
14986 int pic_mode;
14987
14988@@ -1923,7 +1923,7 @@ void smp_error_interrupt(struct pt_regs *regs)
14989 apic_write(APIC_ESR, 0);
14990 v1 = apic_read(APIC_ESR);
14991 ack_APIC_irq();
14992- atomic_inc(&irq_err_count);
14993+ atomic_inc_unchecked(&irq_err_count);
14994
14995 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
14996 smp_processor_id(), v0 , v1);
14997@@ -2155,7 +2155,9 @@ void __init apic_set_eoi_write(void (*eoi_write)(u32 reg, u32 v))
14998 for (drv = __apicdrivers; drv < __apicdrivers_end; drv++) {
14999 /* Should happen once for each apic */
15000 WARN_ON((*drv)->eoi_write == eoi_write);
15001- (*drv)->eoi_write = eoi_write;
15002+ pax_open_kernel();
15003+ *(void **)&(*drv)->eoi_write = eoi_write;
15004+ pax_close_kernel();
15005 }
15006 }
15007
15008diff --git a/arch/x86/kernel/apic/apic_numachip.c b/arch/x86/kernel/apic/apic_numachip.c
15009index a65829a..6ddc249 100644
15010--- a/arch/x86/kernel/apic/apic_numachip.c
15011+++ b/arch/x86/kernel/apic/apic_numachip.c
15012@@ -178,7 +178,7 @@ static int __init numachip_system_init(void)
15013 if (!numachip_system)
15014 return 0;
15015
15016- x86_cpuinit.fixup_cpu_id = fixup_cpu_id;
15017+ *(void **)&x86_cpuinit.fixup_cpu_id = fixup_cpu_id;
15018
15019 map_csrs();
15020
15021diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
15022index 1817fa9..7bff097 100644
15023--- a/arch/x86/kernel/apic/io_apic.c
15024+++ b/arch/x86/kernel/apic/io_apic.c
15025@@ -1084,7 +1084,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
15026 }
15027 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
15028
15029-void lock_vector_lock(void)
15030+void lock_vector_lock(void) __acquires(vector_lock)
15031 {
15032 /* Used to the online set of cpus does not change
15033 * during assign_irq_vector.
15034@@ -1092,7 +1092,7 @@ void lock_vector_lock(void)
15035 raw_spin_lock(&vector_lock);
15036 }
15037
15038-void unlock_vector_lock(void)
15039+void unlock_vector_lock(void) __releases(vector_lock)
15040 {
15041 raw_spin_unlock(&vector_lock);
15042 }
15043@@ -2411,7 +2411,7 @@ static void ack_apic_edge(struct irq_data *data)
15044 ack_APIC_irq();
15045 }
15046
15047-atomic_t irq_mis_count;
15048+atomic_unchecked_t irq_mis_count;
15049
15050 #ifdef CONFIG_GENERIC_PENDING_IRQ
15051 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
15052@@ -2552,7 +2552,7 @@ static void ack_apic_level(struct irq_data *data)
15053 * at the cpu.
15054 */
15055 if (!(v & (1 << (i & 0x1f)))) {
15056- atomic_inc(&irq_mis_count);
15057+ atomic_inc_unchecked(&irq_mis_count);
15058
15059 eoi_ioapic_irq(irq, cfg);
15060 }
15061diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
15062index d661ee9..512c0a1 100644
15063--- a/arch/x86/kernel/apic/numaq_32.c
15064+++ b/arch/x86/kernel/apic/numaq_32.c
15065@@ -257,14 +257,14 @@ static __init void early_check_numaq(void)
15066 early_get_smp_config();
15067
15068 if (found_numaq) {
15069- x86_init.mpparse.mpc_record = numaq_mpc_record;
15070- x86_init.mpparse.setup_ioapic_ids = x86_init_noop;
15071- x86_init.mpparse.mpc_apic_id = mpc_apic_id;
15072- x86_init.mpparse.smp_read_mpc_oem = smp_read_mpc_oem;
15073- x86_init.mpparse.mpc_oem_pci_bus = mpc_oem_pci_bus;
15074- x86_init.mpparse.mpc_oem_bus_info = mpc_oem_bus_info;
15075- x86_init.timers.tsc_pre_init = numaq_tsc_init;
15076- x86_init.pci.init = pci_numaq_init;
15077+ *(void **)&x86_init.mpparse.mpc_record = numaq_mpc_record;
15078+ *(void **)&x86_init.mpparse.setup_ioapic_ids = x86_init_noop;
15079+ *(void **)&x86_init.mpparse.mpc_apic_id = mpc_apic_id;
15080+ *(void **)&x86_init.mpparse.smp_read_mpc_oem = smp_read_mpc_oem;
15081+ *(void **)&x86_init.mpparse.mpc_oem_pci_bus = mpc_oem_pci_bus;
15082+ *(void **)&x86_init.mpparse.mpc_oem_bus_info = mpc_oem_bus_info;
15083+ *(void **)&x86_init.timers.tsc_pre_init = numaq_tsc_init;
15084+ *(void **)&x86_init.pci.init = pci_numaq_init;
15085 }
15086 }
15087
15088diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
15089index 8cfade9..8ea7b51 100644
15090--- a/arch/x86/kernel/apic/x2apic_uv_x.c
15091+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
15092@@ -139,8 +139,8 @@ static int __init uv_acpi_madt_oem_check(char *oem_id, char *oem_table_id)
15093 is_uv1 ? UV1_HUB_REVISION_BASE : UV2_HUB_REVISION_BASE;
15094 pnodeid = early_get_pnodeid();
15095 early_get_apic_pnode_shift();
15096- x86_platform.is_untracked_pat_range = uv_is_untracked_pat_range;
15097- x86_platform.nmi_init = uv_nmi_init;
15098+ *(void **)&x86_platform.is_untracked_pat_range = uv_is_untracked_pat_range;
15099+ *(void **)&x86_platform.nmi_init = uv_nmi_init;
15100 if (!strcmp(oem_table_id, "UVL"))
15101 uv_system_type = UV_LEGACY_APIC;
15102 else if (!strcmp(oem_table_id, "UVX"))
15103diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
15104index d65464e..1035d31 100644
15105--- a/arch/x86/kernel/apm_32.c
15106+++ b/arch/x86/kernel/apm_32.c
15107@@ -412,7 +412,7 @@ static DEFINE_MUTEX(apm_mutex);
15108 * This is for buggy BIOS's that refer to (real mode) segment 0x40
15109 * even though they are called in protected mode.
15110 */
15111-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
15112+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
15113 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
15114
15115 static const char driver_version[] = "1.16ac"; /* no spaces */
15116@@ -590,7 +590,10 @@ static long __apm_bios_call(void *_call)
15117 BUG_ON(cpu != 0);
15118 gdt = get_cpu_gdt_table(cpu);
15119 save_desc_40 = gdt[0x40 / 8];
15120+
15121+ pax_open_kernel();
15122 gdt[0x40 / 8] = bad_bios_desc;
15123+ pax_close_kernel();
15124
15125 apm_irq_save(flags);
15126 APM_DO_SAVE_SEGS;
15127@@ -599,7 +602,11 @@ static long __apm_bios_call(void *_call)
15128 &call->esi);
15129 APM_DO_RESTORE_SEGS;
15130 apm_irq_restore(flags);
15131+
15132+ pax_open_kernel();
15133 gdt[0x40 / 8] = save_desc_40;
15134+ pax_close_kernel();
15135+
15136 put_cpu();
15137
15138 return call->eax & 0xff;
15139@@ -666,7 +673,10 @@ static long __apm_bios_call_simple(void *_call)
15140 BUG_ON(cpu != 0);
15141 gdt = get_cpu_gdt_table(cpu);
15142 save_desc_40 = gdt[0x40 / 8];
15143+
15144+ pax_open_kernel();
15145 gdt[0x40 / 8] = bad_bios_desc;
15146+ pax_close_kernel();
15147
15148 apm_irq_save(flags);
15149 APM_DO_SAVE_SEGS;
15150@@ -674,7 +684,11 @@ static long __apm_bios_call_simple(void *_call)
15151 &call->eax);
15152 APM_DO_RESTORE_SEGS;
15153 apm_irq_restore(flags);
15154+
15155+ pax_open_kernel();
15156 gdt[0x40 / 8] = save_desc_40;
15157+ pax_close_kernel();
15158+
15159 put_cpu();
15160 return error;
15161 }
15162@@ -2345,12 +2359,15 @@ static int __init apm_init(void)
15163 * code to that CPU.
15164 */
15165 gdt = get_cpu_gdt_table(0);
15166+
15167+ pax_open_kernel();
15168 set_desc_base(&gdt[APM_CS >> 3],
15169 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
15170 set_desc_base(&gdt[APM_CS_16 >> 3],
15171 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
15172 set_desc_base(&gdt[APM_DS >> 3],
15173 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
15174+ pax_close_kernel();
15175
15176 proc_create("apm", 0, NULL, &apm_file_ops);
15177
15178diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
15179index 2861082..6d4718e 100644
15180--- a/arch/x86/kernel/asm-offsets.c
15181+++ b/arch/x86/kernel/asm-offsets.c
15182@@ -33,6 +33,8 @@ void common(void) {
15183 OFFSET(TI_status, thread_info, status);
15184 OFFSET(TI_addr_limit, thread_info, addr_limit);
15185 OFFSET(TI_preempt_count, thread_info, preempt_count);
15186+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
15187+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
15188
15189 BLANK();
15190 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
15191@@ -53,8 +55,26 @@ void common(void) {
15192 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
15193 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
15194 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
15195+
15196+#ifdef CONFIG_PAX_KERNEXEC
15197+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
15198 #endif
15199
15200+#ifdef CONFIG_PAX_MEMORY_UDEREF
15201+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
15202+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
15203+#ifdef CONFIG_X86_64
15204+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
15205+#endif
15206+#endif
15207+
15208+#endif
15209+
15210+ BLANK();
15211+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
15212+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
15213+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
15214+
15215 #ifdef CONFIG_XEN
15216 BLANK();
15217 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
15218diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
15219index 1b4754f..fbb4227 100644
15220--- a/arch/x86/kernel/asm-offsets_64.c
15221+++ b/arch/x86/kernel/asm-offsets_64.c
15222@@ -76,6 +76,7 @@ int main(void)
15223 BLANK();
15224 #undef ENTRY
15225
15226+ DEFINE(TSS_size, sizeof(struct tss_struct));
15227 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
15228 BLANK();
15229
15230diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
15231index a0e067d..9c7db16 100644
15232--- a/arch/x86/kernel/cpu/Makefile
15233+++ b/arch/x86/kernel/cpu/Makefile
15234@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
15235 CFLAGS_REMOVE_perf_event.o = -pg
15236 endif
15237
15238-# Make sure load_percpu_segment has no stackprotector
15239-nostackp := $(call cc-option, -fno-stack-protector)
15240-CFLAGS_common.o := $(nostackp)
15241-
15242 obj-y := intel_cacheinfo.o scattered.o topology.o
15243 obj-y += proc.o capflags.o powerflags.o common.o
15244 obj-y += vmware.o hypervisor.o mshyperv.o
15245diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
15246index 1b7d165..b9e2627 100644
15247--- a/arch/x86/kernel/cpu/amd.c
15248+++ b/arch/x86/kernel/cpu/amd.c
15249@@ -738,7 +738,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
15250 unsigned int size)
15251 {
15252 /* AMD errata T13 (order #21922) */
15253- if ((c->x86 == 6)) {
15254+ if (c->x86 == 6) {
15255 /* Duron Rev A0 */
15256 if (c->x86_model == 3 && c->x86_mask == 0)
15257 size = 64;
15258diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
15259index 7505f7b..d59dac0 100644
15260--- a/arch/x86/kernel/cpu/common.c
15261+++ b/arch/x86/kernel/cpu/common.c
15262@@ -86,60 +86,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
15263
15264 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
15265
15266-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
15267-#ifdef CONFIG_X86_64
15268- /*
15269- * We need valid kernel segments for data and code in long mode too
15270- * IRET will check the segment types kkeil 2000/10/28
15271- * Also sysret mandates a special GDT layout
15272- *
15273- * TLS descriptors are currently at a different place compared to i386.
15274- * Hopefully nobody expects them at a fixed place (Wine?)
15275- */
15276- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
15277- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
15278- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
15279- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
15280- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
15281- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
15282-#else
15283- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
15284- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
15285- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
15286- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
15287- /*
15288- * Segments used for calling PnP BIOS have byte granularity.
15289- * They code segments and data segments have fixed 64k limits,
15290- * the transfer segment sizes are set at run time.
15291- */
15292- /* 32-bit code */
15293- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
15294- /* 16-bit code */
15295- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
15296- /* 16-bit data */
15297- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
15298- /* 16-bit data */
15299- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
15300- /* 16-bit data */
15301- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
15302- /*
15303- * The APM segments have byte granularity and their bases
15304- * are set at run time. All have 64k limits.
15305- */
15306- /* 32-bit code */
15307- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
15308- /* 16-bit code */
15309- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
15310- /* data */
15311- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
15312-
15313- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
15314- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
15315- GDT_STACK_CANARY_INIT
15316-#endif
15317-} };
15318-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
15319-
15320 static int __init x86_xsave_setup(char *s)
15321 {
15322 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
15323@@ -389,7 +335,7 @@ void switch_to_new_gdt(int cpu)
15324 {
15325 struct desc_ptr gdt_descr;
15326
15327- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
15328+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
15329 gdt_descr.size = GDT_SIZE - 1;
15330 load_gdt(&gdt_descr);
15331 /* Reload the per-cpu base */
15332@@ -885,6 +831,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
15333 /* Filter out anything that depends on CPUID levels we don't have */
15334 filter_cpuid_features(c, true);
15335
15336+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
15337+ setup_clear_cpu_cap(X86_FEATURE_SEP);
15338+#endif
15339+
15340 /* If the model name is still unset, do table lookup. */
15341 if (!c->x86_model_id[0]) {
15342 const char *p;
15343@@ -1068,10 +1018,12 @@ static __init int setup_disablecpuid(char *arg)
15344 }
15345 __setup("clearcpuid=", setup_disablecpuid);
15346
15347+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
15348+EXPORT_PER_CPU_SYMBOL(current_tinfo);
15349+
15350 #ifdef CONFIG_X86_64
15351 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
15352-struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
15353- (unsigned long) nmi_idt_table };
15354+struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
15355
15356 DEFINE_PER_CPU_FIRST(union irq_stack_union,
15357 irq_stack_union) __aligned(PAGE_SIZE);
15358@@ -1085,7 +1037,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
15359 EXPORT_PER_CPU_SYMBOL(current_task);
15360
15361 DEFINE_PER_CPU(unsigned long, kernel_stack) =
15362- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
15363+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
15364 EXPORT_PER_CPU_SYMBOL(kernel_stack);
15365
15366 DEFINE_PER_CPU(char *, irq_stack_ptr) =
15367@@ -1178,7 +1130,7 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
15368 {
15369 memset(regs, 0, sizeof(struct pt_regs));
15370 regs->fs = __KERNEL_PERCPU;
15371- regs->gs = __KERNEL_STACK_CANARY;
15372+ savesegment(gs, regs->gs);
15373
15374 return regs;
15375 }
15376@@ -1233,7 +1185,7 @@ void __cpuinit cpu_init(void)
15377 int i;
15378
15379 cpu = stack_smp_processor_id();
15380- t = &per_cpu(init_tss, cpu);
15381+ t = init_tss + cpu;
15382 oist = &per_cpu(orig_ist, cpu);
15383
15384 #ifdef CONFIG_NUMA
15385@@ -1259,7 +1211,7 @@ void __cpuinit cpu_init(void)
15386 switch_to_new_gdt(cpu);
15387 loadsegment(fs, 0);
15388
15389- load_idt((const struct desc_ptr *)&idt_descr);
15390+ load_idt(&idt_descr);
15391
15392 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
15393 syscall_init();
15394@@ -1268,7 +1220,6 @@ void __cpuinit cpu_init(void)
15395 wrmsrl(MSR_KERNEL_GS_BASE, 0);
15396 barrier();
15397
15398- x86_configure_nx();
15399 if (cpu != 0)
15400 enable_x2apic();
15401
15402@@ -1321,7 +1272,7 @@ void __cpuinit cpu_init(void)
15403 {
15404 int cpu = smp_processor_id();
15405 struct task_struct *curr = current;
15406- struct tss_struct *t = &per_cpu(init_tss, cpu);
15407+ struct tss_struct *t = init_tss + cpu;
15408 struct thread_struct *thread = &curr->thread;
15409
15410 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
15411diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
15412index 198e019..867575e 100644
15413--- a/arch/x86/kernel/cpu/intel.c
15414+++ b/arch/x86/kernel/cpu/intel.c
15415@@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
15416 * Update the IDT descriptor and reload the IDT so that
15417 * it uses the read-only mapped virtual address.
15418 */
15419- idt_descr.address = fix_to_virt(FIX_F00F_IDT);
15420+ idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
15421 load_idt(&idt_descr);
15422 }
15423 #endif
15424diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
15425index 93c5451..3887433 100644
15426--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
15427+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
15428@@ -983,6 +983,22 @@ static struct attribute *default_attrs[] = {
15429 };
15430
15431 #ifdef CONFIG_AMD_NB
15432+static struct attribute *default_attrs_amd_nb[] = {
15433+ &type.attr,
15434+ &level.attr,
15435+ &coherency_line_size.attr,
15436+ &physical_line_partition.attr,
15437+ &ways_of_associativity.attr,
15438+ &number_of_sets.attr,
15439+ &size.attr,
15440+ &shared_cpu_map.attr,
15441+ &shared_cpu_list.attr,
15442+ NULL,
15443+ NULL,
15444+ NULL,
15445+ NULL
15446+};
15447+
15448 static struct attribute ** __cpuinit amd_l3_attrs(void)
15449 {
15450 static struct attribute **attrs;
15451@@ -993,18 +1009,7 @@ static struct attribute ** __cpuinit amd_l3_attrs(void)
15452
15453 n = ARRAY_SIZE(default_attrs);
15454
15455- if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
15456- n += 2;
15457-
15458- if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
15459- n += 1;
15460-
15461- attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
15462- if (attrs == NULL)
15463- return attrs = default_attrs;
15464-
15465- for (n = 0; default_attrs[n]; n++)
15466- attrs[n] = default_attrs[n];
15467+ attrs = default_attrs_amd_nb;
15468
15469 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
15470 attrs[n++] = &cache_disable_0.attr;
15471@@ -1055,6 +1060,13 @@ static struct kobj_type ktype_cache = {
15472 .default_attrs = default_attrs,
15473 };
15474
15475+#ifdef CONFIG_AMD_NB
15476+static struct kobj_type ktype_cache_amd_nb = {
15477+ .sysfs_ops = &sysfs_ops,
15478+ .default_attrs = default_attrs_amd_nb,
15479+};
15480+#endif
15481+
15482 static struct kobj_type ktype_percpu_entry = {
15483 .sysfs_ops = &sysfs_ops,
15484 };
15485@@ -1120,20 +1132,26 @@ static int __cpuinit cache_add_dev(struct device *dev)
15486 return retval;
15487 }
15488
15489+#ifdef CONFIG_AMD_NB
15490+ amd_l3_attrs();
15491+#endif
15492+
15493 for (i = 0; i < num_cache_leaves; i++) {
15494+ struct kobj_type *ktype;
15495+
15496 this_object = INDEX_KOBJECT_PTR(cpu, i);
15497 this_object->cpu = cpu;
15498 this_object->index = i;
15499
15500 this_leaf = CPUID4_INFO_IDX(cpu, i);
15501
15502- ktype_cache.default_attrs = default_attrs;
15503+ ktype = &ktype_cache;
15504 #ifdef CONFIG_AMD_NB
15505 if (this_leaf->base.nb)
15506- ktype_cache.default_attrs = amd_l3_attrs();
15507+ ktype = &ktype_cache_amd_nb;
15508 #endif
15509 retval = kobject_init_and_add(&(this_object->kobj),
15510- &ktype_cache,
15511+ ktype,
15512 per_cpu(ici_cache_kobject, cpu),
15513 "index%1lu", i);
15514 if (unlikely(retval)) {
15515diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
15516index 46cbf86..55c7292 100644
15517--- a/arch/x86/kernel/cpu/mcheck/mce.c
15518+++ b/arch/x86/kernel/cpu/mcheck/mce.c
15519@@ -45,6 +45,7 @@
15520 #include <asm/processor.h>
15521 #include <asm/mce.h>
15522 #include <asm/msr.h>
15523+#include <asm/local.h>
15524
15525 #include "mce-internal.h"
15526
15527@@ -254,7 +255,7 @@ static void print_mce(struct mce *m)
15528 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
15529 m->cs, m->ip);
15530
15531- if (m->cs == __KERNEL_CS)
15532+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
15533 print_symbol("{%s}", m->ip);
15534 pr_cont("\n");
15535 }
15536@@ -287,10 +288,10 @@ static void print_mce(struct mce *m)
15537
15538 #define PANIC_TIMEOUT 5 /* 5 seconds */
15539
15540-static atomic_t mce_paniced;
15541+static atomic_unchecked_t mce_paniced;
15542
15543 static int fake_panic;
15544-static atomic_t mce_fake_paniced;
15545+static atomic_unchecked_t mce_fake_paniced;
15546
15547 /* Panic in progress. Enable interrupts and wait for final IPI */
15548 static void wait_for_panic(void)
15549@@ -314,7 +315,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
15550 /*
15551 * Make sure only one CPU runs in machine check panic
15552 */
15553- if (atomic_inc_return(&mce_paniced) > 1)
15554+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
15555 wait_for_panic();
15556 barrier();
15557
15558@@ -322,7 +323,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
15559 console_verbose();
15560 } else {
15561 /* Don't log too much for fake panic */
15562- if (atomic_inc_return(&mce_fake_paniced) > 1)
15563+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
15564 return;
15565 }
15566 /* First print corrected ones that are still unlogged */
15567@@ -694,7 +695,7 @@ static int mce_timed_out(u64 *t)
15568 * might have been modified by someone else.
15569 */
15570 rmb();
15571- if (atomic_read(&mce_paniced))
15572+ if (atomic_read_unchecked(&mce_paniced))
15573 wait_for_panic();
15574 if (!monarch_timeout)
15575 goto out;
15576@@ -1659,7 +1660,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
15577 }
15578
15579 /* Call the installed machine check handler for this CPU setup. */
15580-void (*machine_check_vector)(struct pt_regs *, long error_code) =
15581+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
15582 unexpected_machine_check;
15583
15584 /*
15585@@ -1682,7 +1683,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
15586 return;
15587 }
15588
15589+ pax_open_kernel();
15590 machine_check_vector = do_machine_check;
15591+ pax_close_kernel();
15592
15593 __mcheck_cpu_init_generic();
15594 __mcheck_cpu_init_vendor(c);
15595@@ -1696,7 +1699,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
15596 */
15597
15598 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
15599-static int mce_chrdev_open_count; /* #times opened */
15600+static local_t mce_chrdev_open_count; /* #times opened */
15601 static int mce_chrdev_open_exclu; /* already open exclusive? */
15602
15603 static int mce_chrdev_open(struct inode *inode, struct file *file)
15604@@ -1704,7 +1707,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
15605 spin_lock(&mce_chrdev_state_lock);
15606
15607 if (mce_chrdev_open_exclu ||
15608- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
15609+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
15610 spin_unlock(&mce_chrdev_state_lock);
15611
15612 return -EBUSY;
15613@@ -1712,7 +1715,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
15614
15615 if (file->f_flags & O_EXCL)
15616 mce_chrdev_open_exclu = 1;
15617- mce_chrdev_open_count++;
15618+ local_inc(&mce_chrdev_open_count);
15619
15620 spin_unlock(&mce_chrdev_state_lock);
15621
15622@@ -1723,7 +1726,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
15623 {
15624 spin_lock(&mce_chrdev_state_lock);
15625
15626- mce_chrdev_open_count--;
15627+ local_dec(&mce_chrdev_open_count);
15628 mce_chrdev_open_exclu = 0;
15629
15630 spin_unlock(&mce_chrdev_state_lock);
15631@@ -2367,7 +2370,7 @@ mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
15632 return NOTIFY_OK;
15633 }
15634
15635-static struct notifier_block mce_cpu_notifier __cpuinitdata = {
15636+static struct notifier_block mce_cpu_notifier __cpuinitconst = {
15637 .notifier_call = mce_cpu_callback,
15638 };
15639
15640@@ -2445,7 +2448,7 @@ struct dentry *mce_get_debugfs_dir(void)
15641 static void mce_reset(void)
15642 {
15643 cpu_missing = 0;
15644- atomic_set(&mce_fake_paniced, 0);
15645+ atomic_set_unchecked(&mce_fake_paniced, 0);
15646 atomic_set(&mce_executing, 0);
15647 atomic_set(&mce_callin, 0);
15648 atomic_set(&global_nwo, 0);
15649diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
15650index 2d5454c..51987eb 100644
15651--- a/arch/x86/kernel/cpu/mcheck/p5.c
15652+++ b/arch/x86/kernel/cpu/mcheck/p5.c
15653@@ -11,6 +11,7 @@
15654 #include <asm/processor.h>
15655 #include <asm/mce.h>
15656 #include <asm/msr.h>
15657+#include <asm/pgtable.h>
15658
15659 /* By default disabled */
15660 int mce_p5_enabled __read_mostly;
15661@@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
15662 if (!cpu_has(c, X86_FEATURE_MCE))
15663 return;
15664
15665+ pax_open_kernel();
15666 machine_check_vector = pentium_machine_check;
15667+ pax_close_kernel();
15668 /* Make sure the vector pointer is visible before we enable MCEs: */
15669 wmb();
15670
15671diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
15672index 2d7998f..17c9de1 100644
15673--- a/arch/x86/kernel/cpu/mcheck/winchip.c
15674+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
15675@@ -10,6 +10,7 @@
15676 #include <asm/processor.h>
15677 #include <asm/mce.h>
15678 #include <asm/msr.h>
15679+#include <asm/pgtable.h>
15680
15681 /* Machine check handler for WinChip C6: */
15682 static void winchip_machine_check(struct pt_regs *regs, long error_code)
15683@@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
15684 {
15685 u32 lo, hi;
15686
15687+ pax_open_kernel();
15688 machine_check_vector = winchip_machine_check;
15689+ pax_close_kernel();
15690 /* Make sure the vector pointer is visible before we enable MCEs: */
15691 wmb();
15692
15693diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
15694index 6b96110..0da73eb 100644
15695--- a/arch/x86/kernel/cpu/mtrr/main.c
15696+++ b/arch/x86/kernel/cpu/mtrr/main.c
15697@@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
15698 u64 size_or_mask, size_and_mask;
15699 static bool mtrr_aps_delayed_init;
15700
15701-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
15702+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
15703
15704 const struct mtrr_ops *mtrr_if;
15705
15706diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
15707index df5e41f..816c719 100644
15708--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
15709+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
15710@@ -25,7 +25,7 @@ struct mtrr_ops {
15711 int (*validate_add_page)(unsigned long base, unsigned long size,
15712 unsigned int type);
15713 int (*have_wrcomb)(void);
15714-};
15715+} __do_const;
15716
15717 extern int generic_get_free_region(unsigned long base, unsigned long size,
15718 int replace_reg);
15719diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
15720index d18b2b8..d3b834c 100644
15721--- a/arch/x86/kernel/cpu/perf_event.c
15722+++ b/arch/x86/kernel/cpu/perf_event.c
15723@@ -1759,7 +1759,7 @@ static unsigned long get_segment_base(unsigned int segment)
15724 if (idx > GDT_ENTRIES)
15725 return 0;
15726
15727- desc = __this_cpu_ptr(&gdt_page.gdt[0]);
15728+ desc = get_cpu_gdt_table(smp_processor_id());
15729 }
15730
15731 return get_desc_base(desc + idx);
15732@@ -1849,7 +1849,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
15733 break;
15734
15735 perf_callchain_store(entry, frame.return_address);
15736- fp = frame.next_frame;
15737+ fp = (const void __force_user *)frame.next_frame;
15738 }
15739 }
15740
15741diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
15742index 324bb52..1a93d85 100644
15743--- a/arch/x86/kernel/cpu/perf_event_intel.c
15744+++ b/arch/x86/kernel/cpu/perf_event_intel.c
15745@@ -1949,10 +1949,10 @@ __init int intel_pmu_init(void)
15746 * v2 and above have a perf capabilities MSR
15747 */
15748 if (version > 1) {
15749- u64 capabilities;
15750+ u64 capabilities = x86_pmu.intel_cap.capabilities;
15751
15752- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
15753- x86_pmu.intel_cap.capabilities = capabilities;
15754+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
15755+ x86_pmu.intel_cap.capabilities = capabilities;
15756 }
15757
15758 intel_ds_init();
15759diff --git a/arch/x86/kernel/cpu/vmware.c b/arch/x86/kernel/cpu/vmware.c
15760index d22d0c4..088eb6f 100644
15761--- a/arch/x86/kernel/cpu/vmware.c
15762+++ b/arch/x86/kernel/cpu/vmware.c
15763@@ -79,7 +79,7 @@ static void __init vmware_platform_setup(void)
15764 VMWARE_PORT(GETHZ, eax, ebx, ecx, edx);
15765
15766 if (ebx != UINT_MAX)
15767- x86_platform.calibrate_tsc = vmware_get_tsc_khz;
15768+ *(void **)&x86_platform.calibrate_tsc = vmware_get_tsc_khz;
15769 else
15770 printk(KERN_WARNING
15771 "Failed to get TSC freq from the hypervisor\n");
15772diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
15773index 13ad899..f642b9a 100644
15774--- a/arch/x86/kernel/crash.c
15775+++ b/arch/x86/kernel/crash.c
15776@@ -36,10 +36,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
15777 {
15778 #ifdef CONFIG_X86_32
15779 struct pt_regs fixed_regs;
15780-#endif
15781
15782-#ifdef CONFIG_X86_32
15783- if (!user_mode_vm(regs)) {
15784+ if (!user_mode(regs)) {
15785 crash_fixup_ss_esp(&fixed_regs, regs);
15786 regs = &fixed_regs;
15787 }
15788diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
15789index 37250fe..bf2ec74 100644
15790--- a/arch/x86/kernel/doublefault_32.c
15791+++ b/arch/x86/kernel/doublefault_32.c
15792@@ -11,7 +11,7 @@
15793
15794 #define DOUBLEFAULT_STACKSIZE (1024)
15795 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
15796-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
15797+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
15798
15799 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
15800
15801@@ -21,7 +21,7 @@ static void doublefault_fn(void)
15802 unsigned long gdt, tss;
15803
15804 store_gdt(&gdt_desc);
15805- gdt = gdt_desc.address;
15806+ gdt = (unsigned long)gdt_desc.address;
15807
15808 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
15809
15810@@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
15811 /* 0x2 bit is always set */
15812 .flags = X86_EFLAGS_SF | 0x2,
15813 .sp = STACK_START,
15814- .es = __USER_DS,
15815+ .es = __KERNEL_DS,
15816 .cs = __KERNEL_CS,
15817 .ss = __KERNEL_DS,
15818- .ds = __USER_DS,
15819+ .ds = __KERNEL_DS,
15820 .fs = __KERNEL_PERCPU,
15821
15822 .__cr3 = __pa_nodebug(swapper_pg_dir),
15823diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
15824index ae42418b..787c16b 100644
15825--- a/arch/x86/kernel/dumpstack.c
15826+++ b/arch/x86/kernel/dumpstack.c
15827@@ -2,6 +2,9 @@
15828 * Copyright (C) 1991, 1992 Linus Torvalds
15829 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
15830 */
15831+#ifdef CONFIG_GRKERNSEC_HIDESYM
15832+#define __INCLUDED_BY_HIDESYM 1
15833+#endif
15834 #include <linux/kallsyms.h>
15835 #include <linux/kprobes.h>
15836 #include <linux/uaccess.h>
15837@@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
15838 static void
15839 print_ftrace_graph_addr(unsigned long addr, void *data,
15840 const struct stacktrace_ops *ops,
15841- struct thread_info *tinfo, int *graph)
15842+ struct task_struct *task, int *graph)
15843 {
15844- struct task_struct *task;
15845 unsigned long ret_addr;
15846 int index;
15847
15848 if (addr != (unsigned long)return_to_handler)
15849 return;
15850
15851- task = tinfo->task;
15852 index = task->curr_ret_stack;
15853
15854 if (!task->ret_stack || index < *graph)
15855@@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
15856 static inline void
15857 print_ftrace_graph_addr(unsigned long addr, void *data,
15858 const struct stacktrace_ops *ops,
15859- struct thread_info *tinfo, int *graph)
15860+ struct task_struct *task, int *graph)
15861 { }
15862 #endif
15863
15864@@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
15865 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
15866 */
15867
15868-static inline int valid_stack_ptr(struct thread_info *tinfo,
15869- void *p, unsigned int size, void *end)
15870+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
15871 {
15872- void *t = tinfo;
15873 if (end) {
15874 if (p < end && p >= (end-THREAD_SIZE))
15875 return 1;
15876@@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
15877 }
15878
15879 unsigned long
15880-print_context_stack(struct thread_info *tinfo,
15881+print_context_stack(struct task_struct *task, void *stack_start,
15882 unsigned long *stack, unsigned long bp,
15883 const struct stacktrace_ops *ops, void *data,
15884 unsigned long *end, int *graph)
15885 {
15886 struct stack_frame *frame = (struct stack_frame *)bp;
15887
15888- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
15889+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
15890 unsigned long addr;
15891
15892 addr = *stack;
15893@@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
15894 } else {
15895 ops->address(data, addr, 0);
15896 }
15897- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
15898+ print_ftrace_graph_addr(addr, data, ops, task, graph);
15899 }
15900 stack++;
15901 }
15902@@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
15903 EXPORT_SYMBOL_GPL(print_context_stack);
15904
15905 unsigned long
15906-print_context_stack_bp(struct thread_info *tinfo,
15907+print_context_stack_bp(struct task_struct *task, void *stack_start,
15908 unsigned long *stack, unsigned long bp,
15909 const struct stacktrace_ops *ops, void *data,
15910 unsigned long *end, int *graph)
15911@@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
15912 struct stack_frame *frame = (struct stack_frame *)bp;
15913 unsigned long *ret_addr = &frame->return_address;
15914
15915- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
15916+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
15917 unsigned long addr = *ret_addr;
15918
15919 if (!__kernel_text_address(addr))
15920@@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
15921 ops->address(data, addr, 1);
15922 frame = frame->next_frame;
15923 ret_addr = &frame->return_address;
15924- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
15925+ print_ftrace_graph_addr(addr, data, ops, task, graph);
15926 }
15927
15928 return (unsigned long)frame;
15929@@ -189,7 +188,7 @@ void dump_stack(void)
15930
15931 bp = stack_frame(current, NULL);
15932 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
15933- current->pid, current->comm, print_tainted(),
15934+ task_pid_nr(current), current->comm, print_tainted(),
15935 init_utsname()->release,
15936 (int)strcspn(init_utsname()->version, " "),
15937 init_utsname()->version);
15938@@ -225,6 +224,8 @@ unsigned __kprobes long oops_begin(void)
15939 }
15940 EXPORT_SYMBOL_GPL(oops_begin);
15941
15942+extern void gr_handle_kernel_exploit(void);
15943+
15944 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
15945 {
15946 if (regs && kexec_should_crash(current))
15947@@ -246,7 +247,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
15948 panic("Fatal exception in interrupt");
15949 if (panic_on_oops)
15950 panic("Fatal exception");
15951- do_exit(signr);
15952+
15953+ gr_handle_kernel_exploit();
15954+
15955+ do_group_exit(signr);
15956 }
15957
15958 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
15959@@ -274,7 +278,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
15960 print_modules();
15961 show_regs(regs);
15962 #ifdef CONFIG_X86_32
15963- if (user_mode_vm(regs)) {
15964+ if (user_mode(regs)) {
15965 sp = regs->sp;
15966 ss = regs->ss & 0xffff;
15967 } else {
15968@@ -302,7 +306,7 @@ void die(const char *str, struct pt_regs *regs, long err)
15969 unsigned long flags = oops_begin();
15970 int sig = SIGSEGV;
15971
15972- if (!user_mode_vm(regs))
15973+ if (!user_mode(regs))
15974 report_bug(regs->ip, regs);
15975
15976 if (__die(str, regs, err))
15977diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
15978index 1038a41..db2c12b 100644
15979--- a/arch/x86/kernel/dumpstack_32.c
15980+++ b/arch/x86/kernel/dumpstack_32.c
15981@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
15982 bp = stack_frame(task, regs);
15983
15984 for (;;) {
15985- struct thread_info *context;
15986+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
15987
15988- context = (struct thread_info *)
15989- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
15990- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
15991+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
15992
15993- stack = (unsigned long *)context->previous_esp;
15994- if (!stack)
15995+ if (stack_start == task_stack_page(task))
15996 break;
15997+ stack = *(unsigned long **)stack_start;
15998 if (ops->stack(data, "IRQ") < 0)
15999 break;
16000 touch_nmi_watchdog();
16001@@ -86,7 +84,7 @@ void show_regs(struct pt_regs *regs)
16002 {
16003 int i;
16004
16005- __show_regs(regs, !user_mode_vm(regs));
16006+ __show_regs(regs, !user_mode(regs));
16007
16008 pr_emerg("Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
16009 TASK_COMM_LEN, current->comm, task_pid_nr(current),
16010@@ -95,21 +93,22 @@ void show_regs(struct pt_regs *regs)
16011 * When in-kernel, we also print out the stack and code at the
16012 * time of the fault..
16013 */
16014- if (!user_mode_vm(regs)) {
16015+ if (!user_mode(regs)) {
16016 unsigned int code_prologue = code_bytes * 43 / 64;
16017 unsigned int code_len = code_bytes;
16018 unsigned char c;
16019 u8 *ip;
16020+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
16021
16022 pr_emerg("Stack:\n");
16023 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
16024
16025 pr_emerg("Code:");
16026
16027- ip = (u8 *)regs->ip - code_prologue;
16028+ ip = (u8 *)regs->ip - code_prologue + cs_base;
16029 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
16030 /* try starting at IP */
16031- ip = (u8 *)regs->ip;
16032+ ip = (u8 *)regs->ip + cs_base;
16033 code_len = code_len - code_prologue + 1;
16034 }
16035 for (i = 0; i < code_len; i++, ip++) {
16036@@ -118,7 +117,7 @@ void show_regs(struct pt_regs *regs)
16037 pr_cont(" Bad EIP value.");
16038 break;
16039 }
16040- if (ip == (u8 *)regs->ip)
16041+ if (ip == (u8 *)regs->ip + cs_base)
16042 pr_cont(" <%02x>", c);
16043 else
16044 pr_cont(" %02x", c);
16045@@ -131,6 +130,7 @@ int is_valid_bugaddr(unsigned long ip)
16046 {
16047 unsigned short ud2;
16048
16049+ ip = ktla_ktva(ip);
16050 if (ip < PAGE_OFFSET)
16051 return 0;
16052 if (probe_kernel_address((unsigned short *)ip, ud2))
16053@@ -138,3 +138,15 @@ int is_valid_bugaddr(unsigned long ip)
16054
16055 return ud2 == 0x0b0f;
16056 }
16057+
16058+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16059+void pax_check_alloca(unsigned long size)
16060+{
16061+ unsigned long sp = (unsigned long)&sp, stack_left;
16062+
16063+ /* all kernel stacks are of the same size */
16064+ stack_left = sp & (THREAD_SIZE - 1);
16065+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
16066+}
16067+EXPORT_SYMBOL(pax_check_alloca);
16068+#endif
16069diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
16070index b653675..51cc8c0 100644
16071--- a/arch/x86/kernel/dumpstack_64.c
16072+++ b/arch/x86/kernel/dumpstack_64.c
16073@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
16074 unsigned long *irq_stack_end =
16075 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
16076 unsigned used = 0;
16077- struct thread_info *tinfo;
16078 int graph = 0;
16079 unsigned long dummy;
16080+ void *stack_start;
16081
16082 if (!task)
16083 task = current;
16084@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
16085 * current stack address. If the stacks consist of nested
16086 * exceptions
16087 */
16088- tinfo = task_thread_info(task);
16089 for (;;) {
16090 char *id;
16091 unsigned long *estack_end;
16092+
16093 estack_end = in_exception_stack(cpu, (unsigned long)stack,
16094 &used, &id);
16095
16096@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
16097 if (ops->stack(data, id) < 0)
16098 break;
16099
16100- bp = ops->walk_stack(tinfo, stack, bp, ops,
16101+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
16102 data, estack_end, &graph);
16103 ops->stack(data, "<EOE>");
16104 /*
16105@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
16106 * second-to-last pointer (index -2 to end) in the
16107 * exception stack:
16108 */
16109+ if ((u16)estack_end[-1] != __KERNEL_DS)
16110+ goto out;
16111 stack = (unsigned long *) estack_end[-2];
16112 continue;
16113 }
16114@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
16115 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
16116 if (ops->stack(data, "IRQ") < 0)
16117 break;
16118- bp = ops->walk_stack(tinfo, stack, bp,
16119+ bp = ops->walk_stack(task, irq_stack, stack, bp,
16120 ops, data, irq_stack_end, &graph);
16121 /*
16122 * We link to the next stack (which would be
16123@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
16124 /*
16125 * This handles the process stack:
16126 */
16127- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
16128+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
16129+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
16130+out:
16131 put_cpu();
16132 }
16133 EXPORT_SYMBOL(dump_trace);
16134@@ -249,7 +253,7 @@ void show_regs(struct pt_regs *regs)
16135 {
16136 int i;
16137 unsigned long sp;
16138- const int cpu = smp_processor_id();
16139+ const int cpu = raw_smp_processor_id();
16140 struct task_struct *cur = current;
16141
16142 sp = regs->sp;
16143@@ -304,3 +308,50 @@ int is_valid_bugaddr(unsigned long ip)
16144
16145 return ud2 == 0x0b0f;
16146 }
16147+
16148+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16149+void pax_check_alloca(unsigned long size)
16150+{
16151+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
16152+ unsigned cpu, used;
16153+ char *id;
16154+
16155+ /* check the process stack first */
16156+ stack_start = (unsigned long)task_stack_page(current);
16157+ stack_end = stack_start + THREAD_SIZE;
16158+ if (likely(stack_start <= sp && sp < stack_end)) {
16159+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
16160+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
16161+ return;
16162+ }
16163+
16164+ cpu = get_cpu();
16165+
16166+ /* check the irq stacks */
16167+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
16168+ stack_start = stack_end - IRQ_STACK_SIZE;
16169+ if (stack_start <= sp && sp < stack_end) {
16170+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
16171+ put_cpu();
16172+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
16173+ return;
16174+ }
16175+
16176+ /* check the exception stacks */
16177+ used = 0;
16178+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
16179+ stack_start = stack_end - EXCEPTION_STKSZ;
16180+ if (stack_end && stack_start <= sp && sp < stack_end) {
16181+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
16182+ put_cpu();
16183+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
16184+ return;
16185+ }
16186+
16187+ put_cpu();
16188+
16189+ /* unknown stack */
16190+ BUG();
16191+}
16192+EXPORT_SYMBOL(pax_check_alloca);
16193+#endif
16194diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
16195index 9b9f18b..9fcaa04 100644
16196--- a/arch/x86/kernel/early_printk.c
16197+++ b/arch/x86/kernel/early_printk.c
16198@@ -7,6 +7,7 @@
16199 #include <linux/pci_regs.h>
16200 #include <linux/pci_ids.h>
16201 #include <linux/errno.h>
16202+#include <linux/sched.h>
16203 #include <asm/io.h>
16204 #include <asm/processor.h>
16205 #include <asm/fcntl.h>
16206diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
16207index cf8639b..6c6a674 100644
16208--- a/arch/x86/kernel/entry_32.S
16209+++ b/arch/x86/kernel/entry_32.S
16210@@ -177,13 +177,153 @@
16211 /*CFI_REL_OFFSET gs, PT_GS*/
16212 .endm
16213 .macro SET_KERNEL_GS reg
16214+
16215+#ifdef CONFIG_CC_STACKPROTECTOR
16216 movl $(__KERNEL_STACK_CANARY), \reg
16217+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
16218+ movl $(__USER_DS), \reg
16219+#else
16220+ xorl \reg, \reg
16221+#endif
16222+
16223 movl \reg, %gs
16224 .endm
16225
16226 #endif /* CONFIG_X86_32_LAZY_GS */
16227
16228-.macro SAVE_ALL
16229+.macro pax_enter_kernel
16230+#ifdef CONFIG_PAX_KERNEXEC
16231+ call pax_enter_kernel
16232+#endif
16233+.endm
16234+
16235+.macro pax_exit_kernel
16236+#ifdef CONFIG_PAX_KERNEXEC
16237+ call pax_exit_kernel
16238+#endif
16239+.endm
16240+
16241+#ifdef CONFIG_PAX_KERNEXEC
16242+ENTRY(pax_enter_kernel)
16243+#ifdef CONFIG_PARAVIRT
16244+ pushl %eax
16245+ pushl %ecx
16246+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
16247+ mov %eax, %esi
16248+#else
16249+ mov %cr0, %esi
16250+#endif
16251+ bts $16, %esi
16252+ jnc 1f
16253+ mov %cs, %esi
16254+ cmp $__KERNEL_CS, %esi
16255+ jz 3f
16256+ ljmp $__KERNEL_CS, $3f
16257+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
16258+2:
16259+#ifdef CONFIG_PARAVIRT
16260+ mov %esi, %eax
16261+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
16262+#else
16263+ mov %esi, %cr0
16264+#endif
16265+3:
16266+#ifdef CONFIG_PARAVIRT
16267+ popl %ecx
16268+ popl %eax
16269+#endif
16270+ ret
16271+ENDPROC(pax_enter_kernel)
16272+
16273+ENTRY(pax_exit_kernel)
16274+#ifdef CONFIG_PARAVIRT
16275+ pushl %eax
16276+ pushl %ecx
16277+#endif
16278+ mov %cs, %esi
16279+ cmp $__KERNEXEC_KERNEL_CS, %esi
16280+ jnz 2f
16281+#ifdef CONFIG_PARAVIRT
16282+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
16283+ mov %eax, %esi
16284+#else
16285+ mov %cr0, %esi
16286+#endif
16287+ btr $16, %esi
16288+ ljmp $__KERNEL_CS, $1f
16289+1:
16290+#ifdef CONFIG_PARAVIRT
16291+ mov %esi, %eax
16292+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
16293+#else
16294+ mov %esi, %cr0
16295+#endif
16296+2:
16297+#ifdef CONFIG_PARAVIRT
16298+ popl %ecx
16299+ popl %eax
16300+#endif
16301+ ret
16302+ENDPROC(pax_exit_kernel)
16303+#endif
16304+
16305+.macro pax_erase_kstack
16306+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16307+ call pax_erase_kstack
16308+#endif
16309+.endm
16310+
16311+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16312+/*
16313+ * ebp: thread_info
16314+ */
16315+ENTRY(pax_erase_kstack)
16316+ pushl %edi
16317+ pushl %ecx
16318+ pushl %eax
16319+
16320+ mov TI_lowest_stack(%ebp), %edi
16321+ mov $-0xBEEF, %eax
16322+ std
16323+
16324+1: mov %edi, %ecx
16325+ and $THREAD_SIZE_asm - 1, %ecx
16326+ shr $2, %ecx
16327+ repne scasl
16328+ jecxz 2f
16329+
16330+ cmp $2*16, %ecx
16331+ jc 2f
16332+
16333+ mov $2*16, %ecx
16334+ repe scasl
16335+ jecxz 2f
16336+ jne 1b
16337+
16338+2: cld
16339+ mov %esp, %ecx
16340+ sub %edi, %ecx
16341+
16342+ cmp $THREAD_SIZE_asm, %ecx
16343+ jb 3f
16344+ ud2
16345+3:
16346+
16347+ shr $2, %ecx
16348+ rep stosl
16349+
16350+ mov TI_task_thread_sp0(%ebp), %edi
16351+ sub $128, %edi
16352+ mov %edi, TI_lowest_stack(%ebp)
16353+
16354+ popl %eax
16355+ popl %ecx
16356+ popl %edi
16357+ ret
16358+ENDPROC(pax_erase_kstack)
16359+#endif
16360+
16361+.macro __SAVE_ALL _DS
16362 cld
16363 PUSH_GS
16364 pushl_cfi %fs
16365@@ -206,7 +346,7 @@
16366 CFI_REL_OFFSET ecx, 0
16367 pushl_cfi %ebx
16368 CFI_REL_OFFSET ebx, 0
16369- movl $(__USER_DS), %edx
16370+ movl $\_DS, %edx
16371 movl %edx, %ds
16372 movl %edx, %es
16373 movl $(__KERNEL_PERCPU), %edx
16374@@ -214,6 +354,15 @@
16375 SET_KERNEL_GS %edx
16376 .endm
16377
16378+.macro SAVE_ALL
16379+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
16380+ __SAVE_ALL __KERNEL_DS
16381+ pax_enter_kernel
16382+#else
16383+ __SAVE_ALL __USER_DS
16384+#endif
16385+.endm
16386+
16387 .macro RESTORE_INT_REGS
16388 popl_cfi %ebx
16389 CFI_RESTORE ebx
16390@@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
16391 popfl_cfi
16392 jmp syscall_exit
16393 CFI_ENDPROC
16394-END(ret_from_fork)
16395+ENDPROC(ret_from_fork)
16396
16397 ENTRY(ret_from_kernel_thread)
16398 CFI_STARTPROC
16399@@ -344,7 +493,15 @@ ret_from_intr:
16400 andl $SEGMENT_RPL_MASK, %eax
16401 #endif
16402 cmpl $USER_RPL, %eax
16403+
16404+#ifdef CONFIG_PAX_KERNEXEC
16405+ jae resume_userspace
16406+
16407+ pax_exit_kernel
16408+ jmp resume_kernel
16409+#else
16410 jb resume_kernel # not returning to v8086 or userspace
16411+#endif
16412
16413 ENTRY(resume_userspace)
16414 LOCKDEP_SYS_EXIT
16415@@ -356,8 +513,8 @@ ENTRY(resume_userspace)
16416 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
16417 # int/exception return?
16418 jne work_pending
16419- jmp restore_all
16420-END(ret_from_exception)
16421+ jmp restore_all_pax
16422+ENDPROC(ret_from_exception)
16423
16424 #ifdef CONFIG_PREEMPT
16425 ENTRY(resume_kernel)
16426@@ -372,7 +529,7 @@ need_resched:
16427 jz restore_all
16428 call preempt_schedule_irq
16429 jmp need_resched
16430-END(resume_kernel)
16431+ENDPROC(resume_kernel)
16432 #endif
16433 CFI_ENDPROC
16434 /*
16435@@ -406,30 +563,45 @@ sysenter_past_esp:
16436 /*CFI_REL_OFFSET cs, 0*/
16437 /*
16438 * Push current_thread_info()->sysenter_return to the stack.
16439- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
16440- * pushed above; +8 corresponds to copy_thread's esp0 setting.
16441 */
16442- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
16443+ pushl_cfi $0
16444 CFI_REL_OFFSET eip, 0
16445
16446 pushl_cfi %eax
16447 SAVE_ALL
16448+ GET_THREAD_INFO(%ebp)
16449+ movl TI_sysenter_return(%ebp),%ebp
16450+ movl %ebp,PT_EIP(%esp)
16451 ENABLE_INTERRUPTS(CLBR_NONE)
16452
16453 /*
16454 * Load the potential sixth argument from user stack.
16455 * Careful about security.
16456 */
16457+ movl PT_OLDESP(%esp),%ebp
16458+
16459+#ifdef CONFIG_PAX_MEMORY_UDEREF
16460+ mov PT_OLDSS(%esp),%ds
16461+1: movl %ds:(%ebp),%ebp
16462+ push %ss
16463+ pop %ds
16464+#else
16465 cmpl $__PAGE_OFFSET-3,%ebp
16466 jae syscall_fault
16467 ASM_STAC
16468 1: movl (%ebp),%ebp
16469 ASM_CLAC
16470+#endif
16471+
16472 movl %ebp,PT_EBP(%esp)
16473 _ASM_EXTABLE(1b,syscall_fault)
16474
16475 GET_THREAD_INFO(%ebp)
16476
16477+#ifdef CONFIG_PAX_RANDKSTACK
16478+ pax_erase_kstack
16479+#endif
16480+
16481 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
16482 jnz sysenter_audit
16483 sysenter_do_call:
16484@@ -444,12 +616,24 @@ sysenter_do_call:
16485 testl $_TIF_ALLWORK_MASK, %ecx
16486 jne sysexit_audit
16487 sysenter_exit:
16488+
16489+#ifdef CONFIG_PAX_RANDKSTACK
16490+ pushl_cfi %eax
16491+ movl %esp, %eax
16492+ call pax_randomize_kstack
16493+ popl_cfi %eax
16494+#endif
16495+
16496+ pax_erase_kstack
16497+
16498 /* if something modifies registers it must also disable sysexit */
16499 movl PT_EIP(%esp), %edx
16500 movl PT_OLDESP(%esp), %ecx
16501 xorl %ebp,%ebp
16502 TRACE_IRQS_ON
16503 1: mov PT_FS(%esp), %fs
16504+2: mov PT_DS(%esp), %ds
16505+3: mov PT_ES(%esp), %es
16506 PTGS_TO_GS
16507 ENABLE_INTERRUPTS_SYSEXIT
16508
16509@@ -466,6 +650,9 @@ sysenter_audit:
16510 movl %eax,%edx /* 2nd arg: syscall number */
16511 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
16512 call __audit_syscall_entry
16513+
16514+ pax_erase_kstack
16515+
16516 pushl_cfi %ebx
16517 movl PT_EAX(%esp),%eax /* reload syscall number */
16518 jmp sysenter_do_call
16519@@ -491,10 +678,16 @@ sysexit_audit:
16520
16521 CFI_ENDPROC
16522 .pushsection .fixup,"ax"
16523-2: movl $0,PT_FS(%esp)
16524+4: movl $0,PT_FS(%esp)
16525+ jmp 1b
16526+5: movl $0,PT_DS(%esp)
16527+ jmp 1b
16528+6: movl $0,PT_ES(%esp)
16529 jmp 1b
16530 .popsection
16531- _ASM_EXTABLE(1b,2b)
16532+ _ASM_EXTABLE(1b,4b)
16533+ _ASM_EXTABLE(2b,5b)
16534+ _ASM_EXTABLE(3b,6b)
16535 PTGS_TO_GS_EX
16536 ENDPROC(ia32_sysenter_target)
16537
16538@@ -509,6 +702,11 @@ ENTRY(system_call)
16539 pushl_cfi %eax # save orig_eax
16540 SAVE_ALL
16541 GET_THREAD_INFO(%ebp)
16542+
16543+#ifdef CONFIG_PAX_RANDKSTACK
16544+ pax_erase_kstack
16545+#endif
16546+
16547 # system call tracing in operation / emulation
16548 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
16549 jnz syscall_trace_entry
16550@@ -527,6 +725,15 @@ syscall_exit:
16551 testl $_TIF_ALLWORK_MASK, %ecx # current->work
16552 jne syscall_exit_work
16553
16554+restore_all_pax:
16555+
16556+#ifdef CONFIG_PAX_RANDKSTACK
16557+ movl %esp, %eax
16558+ call pax_randomize_kstack
16559+#endif
16560+
16561+ pax_erase_kstack
16562+
16563 restore_all:
16564 TRACE_IRQS_IRET
16565 restore_all_notrace:
16566@@ -583,14 +790,34 @@ ldt_ss:
16567 * compensating for the offset by changing to the ESPFIX segment with
16568 * a base address that matches for the difference.
16569 */
16570-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
16571+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
16572 mov %esp, %edx /* load kernel esp */
16573 mov PT_OLDESP(%esp), %eax /* load userspace esp */
16574 mov %dx, %ax /* eax: new kernel esp */
16575 sub %eax, %edx /* offset (low word is 0) */
16576+#ifdef CONFIG_SMP
16577+ movl PER_CPU_VAR(cpu_number), %ebx
16578+ shll $PAGE_SHIFT_asm, %ebx
16579+ addl $cpu_gdt_table, %ebx
16580+#else
16581+ movl $cpu_gdt_table, %ebx
16582+#endif
16583 shr $16, %edx
16584- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
16585- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
16586+
16587+#ifdef CONFIG_PAX_KERNEXEC
16588+ mov %cr0, %esi
16589+ btr $16, %esi
16590+ mov %esi, %cr0
16591+#endif
16592+
16593+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
16594+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
16595+
16596+#ifdef CONFIG_PAX_KERNEXEC
16597+ bts $16, %esi
16598+ mov %esi, %cr0
16599+#endif
16600+
16601 pushl_cfi $__ESPFIX_SS
16602 pushl_cfi %eax /* new kernel esp */
16603 /* Disable interrupts, but do not irqtrace this section: we
16604@@ -619,20 +846,18 @@ work_resched:
16605 movl TI_flags(%ebp), %ecx
16606 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
16607 # than syscall tracing?
16608- jz restore_all
16609+ jz restore_all_pax
16610 testb $_TIF_NEED_RESCHED, %cl
16611 jnz work_resched
16612
16613 work_notifysig: # deal with pending signals and
16614 # notify-resume requests
16615+ movl %esp, %eax
16616 #ifdef CONFIG_VM86
16617 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
16618- movl %esp, %eax
16619 jne work_notifysig_v86 # returning to kernel-space or
16620 # vm86-space
16621 1:
16622-#else
16623- movl %esp, %eax
16624 #endif
16625 TRACE_IRQS_ON
16626 ENABLE_INTERRUPTS(CLBR_NONE)
16627@@ -653,7 +878,7 @@ work_notifysig_v86:
16628 movl %eax, %esp
16629 jmp 1b
16630 #endif
16631-END(work_pending)
16632+ENDPROC(work_pending)
16633
16634 # perform syscall exit tracing
16635 ALIGN
16636@@ -661,11 +886,14 @@ syscall_trace_entry:
16637 movl $-ENOSYS,PT_EAX(%esp)
16638 movl %esp, %eax
16639 call syscall_trace_enter
16640+
16641+ pax_erase_kstack
16642+
16643 /* What it returned is what we'll actually use. */
16644 cmpl $(NR_syscalls), %eax
16645 jnae syscall_call
16646 jmp syscall_exit
16647-END(syscall_trace_entry)
16648+ENDPROC(syscall_trace_entry)
16649
16650 # perform syscall exit tracing
16651 ALIGN
16652@@ -678,21 +906,25 @@ syscall_exit_work:
16653 movl %esp, %eax
16654 call syscall_trace_leave
16655 jmp resume_userspace
16656-END(syscall_exit_work)
16657+ENDPROC(syscall_exit_work)
16658 CFI_ENDPROC
16659
16660 RING0_INT_FRAME # can't unwind into user space anyway
16661 syscall_fault:
16662+#ifdef CONFIG_PAX_MEMORY_UDEREF
16663+ push %ss
16664+ pop %ds
16665+#endif
16666 ASM_CLAC
16667 GET_THREAD_INFO(%ebp)
16668 movl $-EFAULT,PT_EAX(%esp)
16669 jmp resume_userspace
16670-END(syscall_fault)
16671+ENDPROC(syscall_fault)
16672
16673 syscall_badsys:
16674 movl $-ENOSYS,PT_EAX(%esp)
16675 jmp resume_userspace
16676-END(syscall_badsys)
16677+ENDPROC(syscall_badsys)
16678 CFI_ENDPROC
16679 /*
16680 * End of kprobes section
16681@@ -772,8 +1004,15 @@ ENDPROC(ptregs_clone)
16682 * normal stack and adjusts ESP with the matching offset.
16683 */
16684 /* fixup the stack */
16685- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
16686- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
16687+#ifdef CONFIG_SMP
16688+ movl PER_CPU_VAR(cpu_number), %ebx
16689+ shll $PAGE_SHIFT_asm, %ebx
16690+ addl $cpu_gdt_table, %ebx
16691+#else
16692+ movl $cpu_gdt_table, %ebx
16693+#endif
16694+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
16695+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
16696 shl $16, %eax
16697 addl %esp, %eax /* the adjusted stack pointer */
16698 pushl_cfi $__KERNEL_DS
16699@@ -826,7 +1065,7 @@ vector=vector+1
16700 .endr
16701 2: jmp common_interrupt
16702 .endr
16703-END(irq_entries_start)
16704+ENDPROC(irq_entries_start)
16705
16706 .previous
16707 END(interrupt)
16708@@ -877,7 +1116,7 @@ ENTRY(coprocessor_error)
16709 pushl_cfi $do_coprocessor_error
16710 jmp error_code
16711 CFI_ENDPROC
16712-END(coprocessor_error)
16713+ENDPROC(coprocessor_error)
16714
16715 ENTRY(simd_coprocessor_error)
16716 RING0_INT_FRAME
16717@@ -899,7 +1138,7 @@ ENTRY(simd_coprocessor_error)
16718 #endif
16719 jmp error_code
16720 CFI_ENDPROC
16721-END(simd_coprocessor_error)
16722+ENDPROC(simd_coprocessor_error)
16723
16724 ENTRY(device_not_available)
16725 RING0_INT_FRAME
16726@@ -908,18 +1147,18 @@ ENTRY(device_not_available)
16727 pushl_cfi $do_device_not_available
16728 jmp error_code
16729 CFI_ENDPROC
16730-END(device_not_available)
16731+ENDPROC(device_not_available)
16732
16733 #ifdef CONFIG_PARAVIRT
16734 ENTRY(native_iret)
16735 iret
16736 _ASM_EXTABLE(native_iret, iret_exc)
16737-END(native_iret)
16738+ENDPROC(native_iret)
16739
16740 ENTRY(native_irq_enable_sysexit)
16741 sti
16742 sysexit
16743-END(native_irq_enable_sysexit)
16744+ENDPROC(native_irq_enable_sysexit)
16745 #endif
16746
16747 ENTRY(overflow)
16748@@ -929,7 +1168,7 @@ ENTRY(overflow)
16749 pushl_cfi $do_overflow
16750 jmp error_code
16751 CFI_ENDPROC
16752-END(overflow)
16753+ENDPROC(overflow)
16754
16755 ENTRY(bounds)
16756 RING0_INT_FRAME
16757@@ -938,7 +1177,7 @@ ENTRY(bounds)
16758 pushl_cfi $do_bounds
16759 jmp error_code
16760 CFI_ENDPROC
16761-END(bounds)
16762+ENDPROC(bounds)
16763
16764 ENTRY(invalid_op)
16765 RING0_INT_FRAME
16766@@ -947,7 +1186,7 @@ ENTRY(invalid_op)
16767 pushl_cfi $do_invalid_op
16768 jmp error_code
16769 CFI_ENDPROC
16770-END(invalid_op)
16771+ENDPROC(invalid_op)
16772
16773 ENTRY(coprocessor_segment_overrun)
16774 RING0_INT_FRAME
16775@@ -956,7 +1195,7 @@ ENTRY(coprocessor_segment_overrun)
16776 pushl_cfi $do_coprocessor_segment_overrun
16777 jmp error_code
16778 CFI_ENDPROC
16779-END(coprocessor_segment_overrun)
16780+ENDPROC(coprocessor_segment_overrun)
16781
16782 ENTRY(invalid_TSS)
16783 RING0_EC_FRAME
16784@@ -964,7 +1203,7 @@ ENTRY(invalid_TSS)
16785 pushl_cfi $do_invalid_TSS
16786 jmp error_code
16787 CFI_ENDPROC
16788-END(invalid_TSS)
16789+ENDPROC(invalid_TSS)
16790
16791 ENTRY(segment_not_present)
16792 RING0_EC_FRAME
16793@@ -972,7 +1211,7 @@ ENTRY(segment_not_present)
16794 pushl_cfi $do_segment_not_present
16795 jmp error_code
16796 CFI_ENDPROC
16797-END(segment_not_present)
16798+ENDPROC(segment_not_present)
16799
16800 ENTRY(stack_segment)
16801 RING0_EC_FRAME
16802@@ -980,7 +1219,7 @@ ENTRY(stack_segment)
16803 pushl_cfi $do_stack_segment
16804 jmp error_code
16805 CFI_ENDPROC
16806-END(stack_segment)
16807+ENDPROC(stack_segment)
16808
16809 ENTRY(alignment_check)
16810 RING0_EC_FRAME
16811@@ -988,7 +1227,7 @@ ENTRY(alignment_check)
16812 pushl_cfi $do_alignment_check
16813 jmp error_code
16814 CFI_ENDPROC
16815-END(alignment_check)
16816+ENDPROC(alignment_check)
16817
16818 ENTRY(divide_error)
16819 RING0_INT_FRAME
16820@@ -997,7 +1236,7 @@ ENTRY(divide_error)
16821 pushl_cfi $do_divide_error
16822 jmp error_code
16823 CFI_ENDPROC
16824-END(divide_error)
16825+ENDPROC(divide_error)
16826
16827 #ifdef CONFIG_X86_MCE
16828 ENTRY(machine_check)
16829@@ -1007,7 +1246,7 @@ ENTRY(machine_check)
16830 pushl_cfi machine_check_vector
16831 jmp error_code
16832 CFI_ENDPROC
16833-END(machine_check)
16834+ENDPROC(machine_check)
16835 #endif
16836
16837 ENTRY(spurious_interrupt_bug)
16838@@ -1017,7 +1256,7 @@ ENTRY(spurious_interrupt_bug)
16839 pushl_cfi $do_spurious_interrupt_bug
16840 jmp error_code
16841 CFI_ENDPROC
16842-END(spurious_interrupt_bug)
16843+ENDPROC(spurious_interrupt_bug)
16844 /*
16845 * End of kprobes section
16846 */
16847@@ -1120,7 +1359,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
16848
16849 ENTRY(mcount)
16850 ret
16851-END(mcount)
16852+ENDPROC(mcount)
16853
16854 ENTRY(ftrace_caller)
16855 cmpl $0, function_trace_stop
16856@@ -1153,7 +1392,7 @@ ftrace_graph_call:
16857 .globl ftrace_stub
16858 ftrace_stub:
16859 ret
16860-END(ftrace_caller)
16861+ENDPROC(ftrace_caller)
16862
16863 ENTRY(ftrace_regs_caller)
16864 pushf /* push flags before compare (in cs location) */
16865@@ -1254,7 +1493,7 @@ trace:
16866 popl %ecx
16867 popl %eax
16868 jmp ftrace_stub
16869-END(mcount)
16870+ENDPROC(mcount)
16871 #endif /* CONFIG_DYNAMIC_FTRACE */
16872 #endif /* CONFIG_FUNCTION_TRACER */
16873
16874@@ -1272,7 +1511,7 @@ ENTRY(ftrace_graph_caller)
16875 popl %ecx
16876 popl %eax
16877 ret
16878-END(ftrace_graph_caller)
16879+ENDPROC(ftrace_graph_caller)
16880
16881 .globl return_to_handler
16882 return_to_handler:
16883@@ -1328,15 +1567,18 @@ error_code:
16884 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
16885 REG_TO_PTGS %ecx
16886 SET_KERNEL_GS %ecx
16887- movl $(__USER_DS), %ecx
16888+ movl $(__KERNEL_DS), %ecx
16889 movl %ecx, %ds
16890 movl %ecx, %es
16891+
16892+ pax_enter_kernel
16893+
16894 TRACE_IRQS_OFF
16895 movl %esp,%eax # pt_regs pointer
16896 call *%edi
16897 jmp ret_from_exception
16898 CFI_ENDPROC
16899-END(page_fault)
16900+ENDPROC(page_fault)
16901
16902 /*
16903 * Debug traps and NMI can happen at the one SYSENTER instruction
16904@@ -1379,7 +1621,7 @@ debug_stack_correct:
16905 call do_debug
16906 jmp ret_from_exception
16907 CFI_ENDPROC
16908-END(debug)
16909+ENDPROC(debug)
16910
16911 /*
16912 * NMI is doubly nasty. It can happen _while_ we're handling
16913@@ -1417,6 +1659,9 @@ nmi_stack_correct:
16914 xorl %edx,%edx # zero error code
16915 movl %esp,%eax # pt_regs pointer
16916 call do_nmi
16917+
16918+ pax_exit_kernel
16919+
16920 jmp restore_all_notrace
16921 CFI_ENDPROC
16922
16923@@ -1453,12 +1698,15 @@ nmi_espfix_stack:
16924 FIXUP_ESPFIX_STACK # %eax == %esp
16925 xorl %edx,%edx # zero error code
16926 call do_nmi
16927+
16928+ pax_exit_kernel
16929+
16930 RESTORE_REGS
16931 lss 12+4(%esp), %esp # back to espfix stack
16932 CFI_ADJUST_CFA_OFFSET -24
16933 jmp irq_return
16934 CFI_ENDPROC
16935-END(nmi)
16936+ENDPROC(nmi)
16937
16938 ENTRY(int3)
16939 RING0_INT_FRAME
16940@@ -1471,14 +1719,14 @@ ENTRY(int3)
16941 call do_int3
16942 jmp ret_from_exception
16943 CFI_ENDPROC
16944-END(int3)
16945+ENDPROC(int3)
16946
16947 ENTRY(general_protection)
16948 RING0_EC_FRAME
16949 pushl_cfi $do_general_protection
16950 jmp error_code
16951 CFI_ENDPROC
16952-END(general_protection)
16953+ENDPROC(general_protection)
16954
16955 #ifdef CONFIG_KVM_GUEST
16956 ENTRY(async_page_fault)
16957@@ -1487,7 +1735,7 @@ ENTRY(async_page_fault)
16958 pushl_cfi $do_async_page_fault
16959 jmp error_code
16960 CFI_ENDPROC
16961-END(async_page_fault)
16962+ENDPROC(async_page_fault)
16963 #endif
16964
16965 /*
16966diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
16967index 1328fe4..cb03298 100644
16968--- a/arch/x86/kernel/entry_64.S
16969+++ b/arch/x86/kernel/entry_64.S
16970@@ -59,6 +59,8 @@
16971 #include <asm/rcu.h>
16972 #include <asm/smap.h>
16973 #include <linux/err.h>
16974+#include <asm/pgtable.h>
16975+#include <asm/alternative-asm.h>
16976
16977 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
16978 #include <linux/elf-em.h>
16979@@ -80,8 +82,9 @@
16980 #ifdef CONFIG_DYNAMIC_FTRACE
16981
16982 ENTRY(function_hook)
16983+ pax_force_retaddr
16984 retq
16985-END(function_hook)
16986+ENDPROC(function_hook)
16987
16988 /* skip is set if stack has been adjusted */
16989 .macro ftrace_caller_setup skip=0
16990@@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
16991 #endif
16992
16993 GLOBAL(ftrace_stub)
16994+ pax_force_retaddr
16995 retq
16996-END(ftrace_caller)
16997+ENDPROC(ftrace_caller)
16998
16999 ENTRY(ftrace_regs_caller)
17000 /* Save the current flags before compare (in SS location)*/
17001@@ -191,7 +195,7 @@ ftrace_restore_flags:
17002 popfq
17003 jmp ftrace_stub
17004
17005-END(ftrace_regs_caller)
17006+ENDPROC(ftrace_regs_caller)
17007
17008
17009 #else /* ! CONFIG_DYNAMIC_FTRACE */
17010@@ -212,6 +216,7 @@ ENTRY(function_hook)
17011 #endif
17012
17013 GLOBAL(ftrace_stub)
17014+ pax_force_retaddr
17015 retq
17016
17017 trace:
17018@@ -225,12 +230,13 @@ trace:
17019 #endif
17020 subq $MCOUNT_INSN_SIZE, %rdi
17021
17022+ pax_force_fptr ftrace_trace_function
17023 call *ftrace_trace_function
17024
17025 MCOUNT_RESTORE_FRAME
17026
17027 jmp ftrace_stub
17028-END(function_hook)
17029+ENDPROC(function_hook)
17030 #endif /* CONFIG_DYNAMIC_FTRACE */
17031 #endif /* CONFIG_FUNCTION_TRACER */
17032
17033@@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
17034
17035 MCOUNT_RESTORE_FRAME
17036
17037+ pax_force_retaddr
17038 retq
17039-END(ftrace_graph_caller)
17040+ENDPROC(ftrace_graph_caller)
17041
17042 GLOBAL(return_to_handler)
17043 subq $24, %rsp
17044@@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
17045 movq 8(%rsp), %rdx
17046 movq (%rsp), %rax
17047 addq $24, %rsp
17048+ pax_force_fptr %rdi
17049 jmp *%rdi
17050+ENDPROC(return_to_handler)
17051 #endif
17052
17053
17054@@ -284,6 +293,273 @@ ENTRY(native_usergs_sysret64)
17055 ENDPROC(native_usergs_sysret64)
17056 #endif /* CONFIG_PARAVIRT */
17057
17058+ .macro ljmpq sel, off
17059+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
17060+ .byte 0x48; ljmp *1234f(%rip)
17061+ .pushsection .rodata
17062+ .align 16
17063+ 1234: .quad \off; .word \sel
17064+ .popsection
17065+#else
17066+ pushq $\sel
17067+ pushq $\off
17068+ lretq
17069+#endif
17070+ .endm
17071+
17072+ .macro pax_enter_kernel
17073+ pax_set_fptr_mask
17074+#ifdef CONFIG_PAX_KERNEXEC
17075+ call pax_enter_kernel
17076+#endif
17077+ .endm
17078+
17079+ .macro pax_exit_kernel
17080+#ifdef CONFIG_PAX_KERNEXEC
17081+ call pax_exit_kernel
17082+#endif
17083+ .endm
17084+
17085+#ifdef CONFIG_PAX_KERNEXEC
17086+ENTRY(pax_enter_kernel)
17087+ pushq %rdi
17088+
17089+#ifdef CONFIG_PARAVIRT
17090+ PV_SAVE_REGS(CLBR_RDI)
17091+#endif
17092+
17093+ GET_CR0_INTO_RDI
17094+ bts $16,%rdi
17095+ jnc 3f
17096+ mov %cs,%edi
17097+ cmp $__KERNEL_CS,%edi
17098+ jnz 2f
17099+1:
17100+
17101+#ifdef CONFIG_PARAVIRT
17102+ PV_RESTORE_REGS(CLBR_RDI)
17103+#endif
17104+
17105+ popq %rdi
17106+ pax_force_retaddr
17107+ retq
17108+
17109+2: ljmpq __KERNEL_CS,1f
17110+3: ljmpq __KERNEXEC_KERNEL_CS,4f
17111+4: SET_RDI_INTO_CR0
17112+ jmp 1b
17113+ENDPROC(pax_enter_kernel)
17114+
17115+ENTRY(pax_exit_kernel)
17116+ pushq %rdi
17117+
17118+#ifdef CONFIG_PARAVIRT
17119+ PV_SAVE_REGS(CLBR_RDI)
17120+#endif
17121+
17122+ mov %cs,%rdi
17123+ cmp $__KERNEXEC_KERNEL_CS,%edi
17124+ jz 2f
17125+1:
17126+
17127+#ifdef CONFIG_PARAVIRT
17128+ PV_RESTORE_REGS(CLBR_RDI);
17129+#endif
17130+
17131+ popq %rdi
17132+ pax_force_retaddr
17133+ retq
17134+
17135+2: GET_CR0_INTO_RDI
17136+ btr $16,%rdi
17137+ ljmpq __KERNEL_CS,3f
17138+3: SET_RDI_INTO_CR0
17139+ jmp 1b
17140+ENDPROC(pax_exit_kernel)
17141+#endif
17142+
17143+ .macro pax_enter_kernel_user
17144+ pax_set_fptr_mask
17145+#ifdef CONFIG_PAX_MEMORY_UDEREF
17146+ call pax_enter_kernel_user
17147+#endif
17148+ .endm
17149+
17150+ .macro pax_exit_kernel_user
17151+#ifdef CONFIG_PAX_MEMORY_UDEREF
17152+ call pax_exit_kernel_user
17153+#endif
17154+#ifdef CONFIG_PAX_RANDKSTACK
17155+ pushq %rax
17156+ call pax_randomize_kstack
17157+ popq %rax
17158+#endif
17159+ .endm
17160+
17161+#ifdef CONFIG_PAX_MEMORY_UDEREF
17162+ENTRY(pax_enter_kernel_user)
17163+ pushq %rdi
17164+ pushq %rbx
17165+
17166+#ifdef CONFIG_PARAVIRT
17167+ PV_SAVE_REGS(CLBR_RDI)
17168+#endif
17169+
17170+ GET_CR3_INTO_RDI
17171+ mov %rdi,%rbx
17172+ add $__START_KERNEL_map,%rbx
17173+ sub phys_base(%rip),%rbx
17174+
17175+#ifdef CONFIG_PARAVIRT
17176+ pushq %rdi
17177+ cmpl $0, pv_info+PARAVIRT_enabled
17178+ jz 1f
17179+ i = 0
17180+ .rept USER_PGD_PTRS
17181+ mov i*8(%rbx),%rsi
17182+ mov $0,%sil
17183+ lea i*8(%rbx),%rdi
17184+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
17185+ i = i + 1
17186+ .endr
17187+ jmp 2f
17188+1:
17189+#endif
17190+
17191+ i = 0
17192+ .rept USER_PGD_PTRS
17193+ movb $0,i*8(%rbx)
17194+ i = i + 1
17195+ .endr
17196+
17197+#ifdef CONFIG_PARAVIRT
17198+2: popq %rdi
17199+#endif
17200+ SET_RDI_INTO_CR3
17201+
17202+#ifdef CONFIG_PAX_KERNEXEC
17203+ GET_CR0_INTO_RDI
17204+ bts $16,%rdi
17205+ SET_RDI_INTO_CR0
17206+#endif
17207+
17208+#ifdef CONFIG_PARAVIRT
17209+ PV_RESTORE_REGS(CLBR_RDI)
17210+#endif
17211+
17212+ popq %rbx
17213+ popq %rdi
17214+ pax_force_retaddr
17215+ retq
17216+ENDPROC(pax_enter_kernel_user)
17217+
17218+ENTRY(pax_exit_kernel_user)
17219+ push %rdi
17220+
17221+#ifdef CONFIG_PARAVIRT
17222+ pushq %rbx
17223+ PV_SAVE_REGS(CLBR_RDI)
17224+#endif
17225+
17226+#ifdef CONFIG_PAX_KERNEXEC
17227+ GET_CR0_INTO_RDI
17228+ btr $16,%rdi
17229+ SET_RDI_INTO_CR0
17230+#endif
17231+
17232+ GET_CR3_INTO_RDI
17233+ add $__START_KERNEL_map,%rdi
17234+ sub phys_base(%rip),%rdi
17235+
17236+#ifdef CONFIG_PARAVIRT
17237+ cmpl $0, pv_info+PARAVIRT_enabled
17238+ jz 1f
17239+ mov %rdi,%rbx
17240+ i = 0
17241+ .rept USER_PGD_PTRS
17242+ mov i*8(%rbx),%rsi
17243+ mov $0x67,%sil
17244+ lea i*8(%rbx),%rdi
17245+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
17246+ i = i + 1
17247+ .endr
17248+ jmp 2f
17249+1:
17250+#endif
17251+
17252+ i = 0
17253+ .rept USER_PGD_PTRS
17254+ movb $0x67,i*8(%rdi)
17255+ i = i + 1
17256+ .endr
17257+
17258+#ifdef CONFIG_PARAVIRT
17259+2: PV_RESTORE_REGS(CLBR_RDI)
17260+ popq %rbx
17261+#endif
17262+
17263+ popq %rdi
17264+ pax_force_retaddr
17265+ retq
17266+ENDPROC(pax_exit_kernel_user)
17267+#endif
17268+
17269+.macro pax_erase_kstack
17270+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
17271+ call pax_erase_kstack
17272+#endif
17273+.endm
17274+
17275+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
17276+ENTRY(pax_erase_kstack)
17277+ pushq %rdi
17278+ pushq %rcx
17279+ pushq %rax
17280+ pushq %r11
17281+
17282+ GET_THREAD_INFO(%r11)
17283+ mov TI_lowest_stack(%r11), %rdi
17284+ mov $-0xBEEF, %rax
17285+ std
17286+
17287+1: mov %edi, %ecx
17288+ and $THREAD_SIZE_asm - 1, %ecx
17289+ shr $3, %ecx
17290+ repne scasq
17291+ jecxz 2f
17292+
17293+ cmp $2*8, %ecx
17294+ jc 2f
17295+
17296+ mov $2*8, %ecx
17297+ repe scasq
17298+ jecxz 2f
17299+ jne 1b
17300+
17301+2: cld
17302+ mov %esp, %ecx
17303+ sub %edi, %ecx
17304+
17305+ cmp $THREAD_SIZE_asm, %rcx
17306+ jb 3f
17307+ ud2
17308+3:
17309+
17310+ shr $3, %ecx
17311+ rep stosq
17312+
17313+ mov TI_task_thread_sp0(%r11), %rdi
17314+ sub $256, %rdi
17315+ mov %rdi, TI_lowest_stack(%r11)
17316+
17317+ popq %r11
17318+ popq %rax
17319+ popq %rcx
17320+ popq %rdi
17321+ pax_force_retaddr
17322+ ret
17323+ENDPROC(pax_erase_kstack)
17324+#endif
17325
17326 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
17327 #ifdef CONFIG_TRACE_IRQFLAGS
17328@@ -375,8 +651,8 @@ ENDPROC(native_usergs_sysret64)
17329 .endm
17330
17331 .macro UNFAKE_STACK_FRAME
17332- addq $8*6, %rsp
17333- CFI_ADJUST_CFA_OFFSET -(6*8)
17334+ addq $8*6 + ARG_SKIP, %rsp
17335+ CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
17336 .endm
17337
17338 /*
17339@@ -463,7 +739,7 @@ ENDPROC(native_usergs_sysret64)
17340 movq %rsp, %rsi
17341
17342 leaq -RBP(%rsp),%rdi /* arg1 for handler */
17343- testl $3, CS-RBP(%rsi)
17344+ testb $3, CS-RBP(%rsi)
17345 je 1f
17346 SWAPGS
17347 /*
17348@@ -498,9 +774,10 @@ ENTRY(save_rest)
17349 movq_cfi r15, R15+16
17350 movq %r11, 8(%rsp) /* return address */
17351 FIXUP_TOP_OF_STACK %r11, 16
17352+ pax_force_retaddr
17353 ret
17354 CFI_ENDPROC
17355-END(save_rest)
17356+ENDPROC(save_rest)
17357
17358 /* save complete stack frame */
17359 .pushsection .kprobes.text, "ax"
17360@@ -529,9 +806,10 @@ ENTRY(save_paranoid)
17361 js 1f /* negative -> in kernel */
17362 SWAPGS
17363 xorl %ebx,%ebx
17364-1: ret
17365+1: pax_force_retaddr_bts
17366+ ret
17367 CFI_ENDPROC
17368-END(save_paranoid)
17369+ENDPROC(save_paranoid)
17370 .popsection
17371
17372 /*
17373@@ -553,7 +831,7 @@ ENTRY(ret_from_fork)
17374
17375 RESTORE_REST
17376
17377- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
17378+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
17379 jz 1f
17380
17381 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
17382@@ -571,7 +849,7 @@ ENTRY(ret_from_fork)
17383 RESTORE_REST
17384 jmp int_ret_from_sys_call
17385 CFI_ENDPROC
17386-END(ret_from_fork)
17387+ENDPROC(ret_from_fork)
17388
17389 /*
17390 * System call entry. Up to 6 arguments in registers are supported.
17391@@ -608,7 +886,7 @@ END(ret_from_fork)
17392 ENTRY(system_call)
17393 CFI_STARTPROC simple
17394 CFI_SIGNAL_FRAME
17395- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
17396+ CFI_DEF_CFA rsp,0
17397 CFI_REGISTER rip,rcx
17398 /*CFI_REGISTER rflags,r11*/
17399 SWAPGS_UNSAFE_STACK
17400@@ -621,16 +899,23 @@ GLOBAL(system_call_after_swapgs)
17401
17402 movq %rsp,PER_CPU_VAR(old_rsp)
17403 movq PER_CPU_VAR(kernel_stack),%rsp
17404+ SAVE_ARGS 8*6,0
17405+ pax_enter_kernel_user
17406+
17407+#ifdef CONFIG_PAX_RANDKSTACK
17408+ pax_erase_kstack
17409+#endif
17410+
17411 /*
17412 * No need to follow this irqs off/on section - it's straight
17413 * and short:
17414 */
17415 ENABLE_INTERRUPTS(CLBR_NONE)
17416- SAVE_ARGS 8,0
17417 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
17418 movq %rcx,RIP-ARGOFFSET(%rsp)
17419 CFI_REL_OFFSET rip,RIP-ARGOFFSET
17420- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
17421+ GET_THREAD_INFO(%rcx)
17422+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
17423 jnz tracesys
17424 system_call_fastpath:
17425 #if __SYSCALL_MASK == ~0
17426@@ -640,7 +925,7 @@ system_call_fastpath:
17427 cmpl $__NR_syscall_max,%eax
17428 #endif
17429 ja badsys
17430- movq %r10,%rcx
17431+ movq R10-ARGOFFSET(%rsp),%rcx
17432 call *sys_call_table(,%rax,8) # XXX: rip relative
17433 movq %rax,RAX-ARGOFFSET(%rsp)
17434 /*
17435@@ -654,10 +939,13 @@ sysret_check:
17436 LOCKDEP_SYS_EXIT
17437 DISABLE_INTERRUPTS(CLBR_NONE)
17438 TRACE_IRQS_OFF
17439- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
17440+ GET_THREAD_INFO(%rcx)
17441+ movl TI_flags(%rcx),%edx
17442 andl %edi,%edx
17443 jnz sysret_careful
17444 CFI_REMEMBER_STATE
17445+ pax_exit_kernel_user
17446+ pax_erase_kstack
17447 /*
17448 * sysretq will re-enable interrupts:
17449 */
17450@@ -709,14 +997,18 @@ badsys:
17451 * jump back to the normal fast path.
17452 */
17453 auditsys:
17454- movq %r10,%r9 /* 6th arg: 4th syscall arg */
17455+ movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
17456 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
17457 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
17458 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
17459 movq %rax,%rsi /* 2nd arg: syscall number */
17460 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
17461 call __audit_syscall_entry
17462+
17463+ pax_erase_kstack
17464+
17465 LOAD_ARGS 0 /* reload call-clobbered registers */
17466+ pax_set_fptr_mask
17467 jmp system_call_fastpath
17468
17469 /*
17470@@ -737,7 +1029,7 @@ sysret_audit:
17471 /* Do syscall tracing */
17472 tracesys:
17473 #ifdef CONFIG_AUDITSYSCALL
17474- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
17475+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
17476 jz auditsys
17477 #endif
17478 SAVE_REST
17479@@ -745,12 +1037,16 @@ tracesys:
17480 FIXUP_TOP_OF_STACK %rdi
17481 movq %rsp,%rdi
17482 call syscall_trace_enter
17483+
17484+ pax_erase_kstack
17485+
17486 /*
17487 * Reload arg registers from stack in case ptrace changed them.
17488 * We don't reload %rax because syscall_trace_enter() returned
17489 * the value it wants us to use in the table lookup.
17490 */
17491 LOAD_ARGS ARGOFFSET, 1
17492+ pax_set_fptr_mask
17493 RESTORE_REST
17494 #if __SYSCALL_MASK == ~0
17495 cmpq $__NR_syscall_max,%rax
17496@@ -759,7 +1055,7 @@ tracesys:
17497 cmpl $__NR_syscall_max,%eax
17498 #endif
17499 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
17500- movq %r10,%rcx /* fixup for C */
17501+ movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
17502 call *sys_call_table(,%rax,8)
17503 movq %rax,RAX-ARGOFFSET(%rsp)
17504 /* Use IRET because user could have changed frame */
17505@@ -780,7 +1076,9 @@ GLOBAL(int_with_check)
17506 andl %edi,%edx
17507 jnz int_careful
17508 andl $~TS_COMPAT,TI_status(%rcx)
17509- jmp retint_swapgs
17510+ pax_exit_kernel_user
17511+ pax_erase_kstack
17512+ jmp retint_swapgs_pax
17513
17514 /* Either reschedule or signal or syscall exit tracking needed. */
17515 /* First do a reschedule test. */
17516@@ -826,7 +1124,7 @@ int_restore_rest:
17517 TRACE_IRQS_OFF
17518 jmp int_with_check
17519 CFI_ENDPROC
17520-END(system_call)
17521+ENDPROC(system_call)
17522
17523 /*
17524 * Certain special system calls that need to save a complete full stack frame.
17525@@ -842,7 +1140,7 @@ ENTRY(\label)
17526 call \func
17527 jmp ptregscall_common
17528 CFI_ENDPROC
17529-END(\label)
17530+ENDPROC(\label)
17531 .endm
17532
17533 PTREGSCALL stub_clone, sys_clone, %r8
17534@@ -860,9 +1158,10 @@ ENTRY(ptregscall_common)
17535 movq_cfi_restore R12+8, r12
17536 movq_cfi_restore RBP+8, rbp
17537 movq_cfi_restore RBX+8, rbx
17538+ pax_force_retaddr
17539 ret $REST_SKIP /* pop extended registers */
17540 CFI_ENDPROC
17541-END(ptregscall_common)
17542+ENDPROC(ptregscall_common)
17543
17544 ENTRY(stub_execve)
17545 CFI_STARTPROC
17546@@ -876,7 +1175,7 @@ ENTRY(stub_execve)
17547 RESTORE_REST
17548 jmp int_ret_from_sys_call
17549 CFI_ENDPROC
17550-END(stub_execve)
17551+ENDPROC(stub_execve)
17552
17553 /*
17554 * sigreturn is special because it needs to restore all registers on return.
17555@@ -894,7 +1193,7 @@ ENTRY(stub_rt_sigreturn)
17556 RESTORE_REST
17557 jmp int_ret_from_sys_call
17558 CFI_ENDPROC
17559-END(stub_rt_sigreturn)
17560+ENDPROC(stub_rt_sigreturn)
17561
17562 #ifdef CONFIG_X86_X32_ABI
17563 PTREGSCALL stub_x32_sigaltstack, sys32_sigaltstack, %rdx
17564@@ -962,7 +1261,7 @@ vector=vector+1
17565 2: jmp common_interrupt
17566 .endr
17567 CFI_ENDPROC
17568-END(irq_entries_start)
17569+ENDPROC(irq_entries_start)
17570
17571 .previous
17572 END(interrupt)
17573@@ -982,6 +1281,16 @@ END(interrupt)
17574 subq $ORIG_RAX-RBP, %rsp
17575 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
17576 SAVE_ARGS_IRQ
17577+#ifdef CONFIG_PAX_MEMORY_UDEREF
17578+ testb $3, CS(%rdi)
17579+ jnz 1f
17580+ pax_enter_kernel
17581+ jmp 2f
17582+1: pax_enter_kernel_user
17583+2:
17584+#else
17585+ pax_enter_kernel
17586+#endif
17587 call \func
17588 .endm
17589
17590@@ -1014,7 +1323,7 @@ ret_from_intr:
17591
17592 exit_intr:
17593 GET_THREAD_INFO(%rcx)
17594- testl $3,CS-ARGOFFSET(%rsp)
17595+ testb $3,CS-ARGOFFSET(%rsp)
17596 je retint_kernel
17597
17598 /* Interrupt came from user space */
17599@@ -1036,12 +1345,16 @@ retint_swapgs: /* return to user-space */
17600 * The iretq could re-enable interrupts:
17601 */
17602 DISABLE_INTERRUPTS(CLBR_ANY)
17603+ pax_exit_kernel_user
17604+retint_swapgs_pax:
17605 TRACE_IRQS_IRETQ
17606 SWAPGS
17607 jmp restore_args
17608
17609 retint_restore_args: /* return to kernel space */
17610 DISABLE_INTERRUPTS(CLBR_ANY)
17611+ pax_exit_kernel
17612+ pax_force_retaddr (RIP-ARGOFFSET)
17613 /*
17614 * The iretq could re-enable interrupts:
17615 */
17616@@ -1124,7 +1437,7 @@ ENTRY(retint_kernel)
17617 #endif
17618
17619 CFI_ENDPROC
17620-END(common_interrupt)
17621+ENDPROC(common_interrupt)
17622 /*
17623 * End of kprobes section
17624 */
17625@@ -1142,7 +1455,7 @@ ENTRY(\sym)
17626 interrupt \do_sym
17627 jmp ret_from_intr
17628 CFI_ENDPROC
17629-END(\sym)
17630+ENDPROC(\sym)
17631 .endm
17632
17633 #ifdef CONFIG_SMP
17634@@ -1198,12 +1511,22 @@ ENTRY(\sym)
17635 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
17636 call error_entry
17637 DEFAULT_FRAME 0
17638+#ifdef CONFIG_PAX_MEMORY_UDEREF
17639+ testb $3, CS(%rsp)
17640+ jnz 1f
17641+ pax_enter_kernel
17642+ jmp 2f
17643+1: pax_enter_kernel_user
17644+2:
17645+#else
17646+ pax_enter_kernel
17647+#endif
17648 movq %rsp,%rdi /* pt_regs pointer */
17649 xorl %esi,%esi /* no error code */
17650 call \do_sym
17651 jmp error_exit /* %ebx: no swapgs flag */
17652 CFI_ENDPROC
17653-END(\sym)
17654+ENDPROC(\sym)
17655 .endm
17656
17657 .macro paranoidzeroentry sym do_sym
17658@@ -1216,15 +1539,25 @@ ENTRY(\sym)
17659 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
17660 call save_paranoid
17661 TRACE_IRQS_OFF
17662+#ifdef CONFIG_PAX_MEMORY_UDEREF
17663+ testb $3, CS(%rsp)
17664+ jnz 1f
17665+ pax_enter_kernel
17666+ jmp 2f
17667+1: pax_enter_kernel_user
17668+2:
17669+#else
17670+ pax_enter_kernel
17671+#endif
17672 movq %rsp,%rdi /* pt_regs pointer */
17673 xorl %esi,%esi /* no error code */
17674 call \do_sym
17675 jmp paranoid_exit /* %ebx: no swapgs flag */
17676 CFI_ENDPROC
17677-END(\sym)
17678+ENDPROC(\sym)
17679 .endm
17680
17681-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
17682+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
17683 .macro paranoidzeroentry_ist sym do_sym ist
17684 ENTRY(\sym)
17685 INTR_FRAME
17686@@ -1235,14 +1568,30 @@ ENTRY(\sym)
17687 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
17688 call save_paranoid
17689 TRACE_IRQS_OFF_DEBUG
17690+#ifdef CONFIG_PAX_MEMORY_UDEREF
17691+ testb $3, CS(%rsp)
17692+ jnz 1f
17693+ pax_enter_kernel
17694+ jmp 2f
17695+1: pax_enter_kernel_user
17696+2:
17697+#else
17698+ pax_enter_kernel
17699+#endif
17700 movq %rsp,%rdi /* pt_regs pointer */
17701 xorl %esi,%esi /* no error code */
17702+#ifdef CONFIG_SMP
17703+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
17704+ lea init_tss(%r12), %r12
17705+#else
17706+ lea init_tss(%rip), %r12
17707+#endif
17708 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
17709 call \do_sym
17710 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
17711 jmp paranoid_exit /* %ebx: no swapgs flag */
17712 CFI_ENDPROC
17713-END(\sym)
17714+ENDPROC(\sym)
17715 .endm
17716
17717 .macro errorentry sym do_sym
17718@@ -1254,13 +1603,23 @@ ENTRY(\sym)
17719 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
17720 call error_entry
17721 DEFAULT_FRAME 0
17722+#ifdef CONFIG_PAX_MEMORY_UDEREF
17723+ testb $3, CS(%rsp)
17724+ jnz 1f
17725+ pax_enter_kernel
17726+ jmp 2f
17727+1: pax_enter_kernel_user
17728+2:
17729+#else
17730+ pax_enter_kernel
17731+#endif
17732 movq %rsp,%rdi /* pt_regs pointer */
17733 movq ORIG_RAX(%rsp),%rsi /* get error code */
17734 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
17735 call \do_sym
17736 jmp error_exit /* %ebx: no swapgs flag */
17737 CFI_ENDPROC
17738-END(\sym)
17739+ENDPROC(\sym)
17740 .endm
17741
17742 /* error code is on the stack already */
17743@@ -1274,13 +1633,23 @@ ENTRY(\sym)
17744 call save_paranoid
17745 DEFAULT_FRAME 0
17746 TRACE_IRQS_OFF
17747+#ifdef CONFIG_PAX_MEMORY_UDEREF
17748+ testb $3, CS(%rsp)
17749+ jnz 1f
17750+ pax_enter_kernel
17751+ jmp 2f
17752+1: pax_enter_kernel_user
17753+2:
17754+#else
17755+ pax_enter_kernel
17756+#endif
17757 movq %rsp,%rdi /* pt_regs pointer */
17758 movq ORIG_RAX(%rsp),%rsi /* get error code */
17759 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
17760 call \do_sym
17761 jmp paranoid_exit /* %ebx: no swapgs flag */
17762 CFI_ENDPROC
17763-END(\sym)
17764+ENDPROC(\sym)
17765 .endm
17766
17767 zeroentry divide_error do_divide_error
17768@@ -1310,9 +1679,10 @@ gs_change:
17769 2: mfence /* workaround */
17770 SWAPGS
17771 popfq_cfi
17772+ pax_force_retaddr
17773 ret
17774 CFI_ENDPROC
17775-END(native_load_gs_index)
17776+ENDPROC(native_load_gs_index)
17777
17778 _ASM_EXTABLE(gs_change,bad_gs)
17779 .section .fixup,"ax"
17780@@ -1340,9 +1710,10 @@ ENTRY(call_softirq)
17781 CFI_DEF_CFA_REGISTER rsp
17782 CFI_ADJUST_CFA_OFFSET -8
17783 decl PER_CPU_VAR(irq_count)
17784+ pax_force_retaddr
17785 ret
17786 CFI_ENDPROC
17787-END(call_softirq)
17788+ENDPROC(call_softirq)
17789
17790 #ifdef CONFIG_XEN
17791 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
17792@@ -1380,7 +1751,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
17793 decl PER_CPU_VAR(irq_count)
17794 jmp error_exit
17795 CFI_ENDPROC
17796-END(xen_do_hypervisor_callback)
17797+ENDPROC(xen_do_hypervisor_callback)
17798
17799 /*
17800 * Hypervisor uses this for application faults while it executes.
17801@@ -1439,7 +1810,7 @@ ENTRY(xen_failsafe_callback)
17802 SAVE_ALL
17803 jmp error_exit
17804 CFI_ENDPROC
17805-END(xen_failsafe_callback)
17806+ENDPROC(xen_failsafe_callback)
17807
17808 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
17809 xen_hvm_callback_vector xen_evtchn_do_upcall
17810@@ -1488,16 +1859,31 @@ ENTRY(paranoid_exit)
17811 TRACE_IRQS_OFF_DEBUG
17812 testl %ebx,%ebx /* swapgs needed? */
17813 jnz paranoid_restore
17814- testl $3,CS(%rsp)
17815+ testb $3,CS(%rsp)
17816 jnz paranoid_userspace
17817+#ifdef CONFIG_PAX_MEMORY_UDEREF
17818+ pax_exit_kernel
17819+ TRACE_IRQS_IRETQ 0
17820+ SWAPGS_UNSAFE_STACK
17821+ RESTORE_ALL 8
17822+ pax_force_retaddr_bts
17823+ jmp irq_return
17824+#endif
17825 paranoid_swapgs:
17826+#ifdef CONFIG_PAX_MEMORY_UDEREF
17827+ pax_exit_kernel_user
17828+#else
17829+ pax_exit_kernel
17830+#endif
17831 TRACE_IRQS_IRETQ 0
17832 SWAPGS_UNSAFE_STACK
17833 RESTORE_ALL 8
17834 jmp irq_return
17835 paranoid_restore:
17836+ pax_exit_kernel
17837 TRACE_IRQS_IRETQ_DEBUG 0
17838 RESTORE_ALL 8
17839+ pax_force_retaddr_bts
17840 jmp irq_return
17841 paranoid_userspace:
17842 GET_THREAD_INFO(%rcx)
17843@@ -1526,7 +1912,7 @@ paranoid_schedule:
17844 TRACE_IRQS_OFF
17845 jmp paranoid_userspace
17846 CFI_ENDPROC
17847-END(paranoid_exit)
17848+ENDPROC(paranoid_exit)
17849
17850 /*
17851 * Exception entry point. This expects an error code/orig_rax on the stack.
17852@@ -1553,12 +1939,13 @@ ENTRY(error_entry)
17853 movq_cfi r14, R14+8
17854 movq_cfi r15, R15+8
17855 xorl %ebx,%ebx
17856- testl $3,CS+8(%rsp)
17857+ testb $3,CS+8(%rsp)
17858 je error_kernelspace
17859 error_swapgs:
17860 SWAPGS
17861 error_sti:
17862 TRACE_IRQS_OFF
17863+ pax_force_retaddr_bts
17864 ret
17865
17866 /*
17867@@ -1585,7 +1972,7 @@ bstep_iret:
17868 movq %rcx,RIP+8(%rsp)
17869 jmp error_swapgs
17870 CFI_ENDPROC
17871-END(error_entry)
17872+ENDPROC(error_entry)
17873
17874
17875 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
17876@@ -1605,7 +1992,7 @@ ENTRY(error_exit)
17877 jnz retint_careful
17878 jmp retint_swapgs
17879 CFI_ENDPROC
17880-END(error_exit)
17881+ENDPROC(error_exit)
17882
17883 /*
17884 * Test if a given stack is an NMI stack or not.
17885@@ -1663,9 +2050,11 @@ ENTRY(nmi)
17886 * If %cs was not the kernel segment, then the NMI triggered in user
17887 * space, which means it is definitely not nested.
17888 */
17889+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
17890+ je 1f
17891 cmpl $__KERNEL_CS, 16(%rsp)
17892 jne first_nmi
17893-
17894+1:
17895 /*
17896 * Check the special variable on the stack to see if NMIs are
17897 * executing.
17898@@ -1824,6 +2213,17 @@ end_repeat_nmi:
17899 */
17900 movq %cr2, %r12
17901
17902+#ifdef CONFIG_PAX_MEMORY_UDEREF
17903+ testb $3, CS(%rsp)
17904+ jnz 1f
17905+ pax_enter_kernel
17906+ jmp 2f
17907+1: pax_enter_kernel_user
17908+2:
17909+#else
17910+ pax_enter_kernel
17911+#endif
17912+
17913 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
17914 movq %rsp,%rdi
17915 movq $-1,%rsi
17916@@ -1839,21 +2239,32 @@ end_repeat_nmi:
17917 testl %ebx,%ebx /* swapgs needed? */
17918 jnz nmi_restore
17919 nmi_swapgs:
17920+#ifdef CONFIG_PAX_MEMORY_UDEREF
17921+ pax_exit_kernel_user
17922+#else
17923+ pax_exit_kernel
17924+#endif
17925 SWAPGS_UNSAFE_STACK
17926+ RESTORE_ALL 8
17927+ /* Clear the NMI executing stack variable */
17928+ movq $0, 10*8(%rsp)
17929+ jmp irq_return
17930 nmi_restore:
17931+ pax_exit_kernel
17932 RESTORE_ALL 8
17933+ pax_force_retaddr_bts
17934 /* Clear the NMI executing stack variable */
17935 movq $0, 10*8(%rsp)
17936 jmp irq_return
17937 CFI_ENDPROC
17938-END(nmi)
17939+ENDPROC(nmi)
17940
17941 ENTRY(ignore_sysret)
17942 CFI_STARTPROC
17943 mov $-ENOSYS,%eax
17944 sysret
17945 CFI_ENDPROC
17946-END(ignore_sysret)
17947+ENDPROC(ignore_sysret)
17948
17949 /*
17950 * End of kprobes section
17951diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
17952index 1d41402..af9a46a 100644
17953--- a/arch/x86/kernel/ftrace.c
17954+++ b/arch/x86/kernel/ftrace.c
17955@@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
17956 {
17957 unsigned char replaced[MCOUNT_INSN_SIZE];
17958
17959+ ip = ktla_ktva(ip);
17960+
17961 /*
17962 * Note: Due to modules and __init, code can
17963 * disappear and change, we need to protect against faulting
17964@@ -227,7 +229,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
17965 unsigned char old[MCOUNT_INSN_SIZE], *new;
17966 int ret;
17967
17968- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
17969+ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
17970 new = ftrace_call_replace(ip, (unsigned long)func);
17971
17972 /* See comment above by declaration of modifying_ftrace_code */
17973@@ -238,7 +240,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
17974 /* Also update the regs callback function */
17975 if (!ret) {
17976 ip = (unsigned long)(&ftrace_regs_call);
17977- memcpy(old, &ftrace_regs_call, MCOUNT_INSN_SIZE);
17978+ memcpy(old, ktla_ktva((void *)&ftrace_regs_call), MCOUNT_INSN_SIZE);
17979 new = ftrace_call_replace(ip, (unsigned long)func);
17980 ret = ftrace_modify_code(ip, old, new);
17981 }
17982@@ -279,7 +281,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
17983 * kernel identity mapping to modify code.
17984 */
17985 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
17986- ip = (unsigned long)__va(__pa(ip));
17987+ ip = (unsigned long)__va(__pa(ktla_ktva(ip)));
17988
17989 return probe_kernel_write((void *)ip, val, size);
17990 }
17991@@ -289,7 +291,7 @@ static int add_break(unsigned long ip, const char *old)
17992 unsigned char replaced[MCOUNT_INSN_SIZE];
17993 unsigned char brk = BREAKPOINT_INSTRUCTION;
17994
17995- if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
17996+ if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
17997 return -EFAULT;
17998
17999 /* Make sure it is what we expect it to be */
18000@@ -637,7 +639,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
18001 return ret;
18002
18003 fail_update:
18004- probe_kernel_write((void *)ip, &old_code[0], 1);
18005+ probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
18006 goto out;
18007 }
18008
18009@@ -670,6 +672,8 @@ static int ftrace_mod_jmp(unsigned long ip,
18010 {
18011 unsigned char code[MCOUNT_INSN_SIZE];
18012
18013+ ip = ktla_ktva(ip);
18014+
18015 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
18016 return -EFAULT;
18017
18018diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
18019index c18f59d..69ddbc4 100644
18020--- a/arch/x86/kernel/head32.c
18021+++ b/arch/x86/kernel/head32.c
18022@@ -18,20 +18,20 @@
18023 #include <asm/io_apic.h>
18024 #include <asm/bios_ebda.h>
18025 #include <asm/tlbflush.h>
18026+#include <asm/boot.h>
18027
18028 static void __init i386_default_early_setup(void)
18029 {
18030 /* Initialize 32bit specific setup functions */
18031- x86_init.resources.reserve_resources = i386_reserve_resources;
18032- x86_init.mpparse.setup_ioapic_ids = setup_ioapic_ids_from_mpc;
18033+ *(void **)&x86_init.resources.reserve_resources = i386_reserve_resources;
18034+ *(void **)&x86_init.mpparse.setup_ioapic_ids = setup_ioapic_ids_from_mpc;
18035
18036 reserve_ebda_region();
18037 }
18038
18039 void __init i386_start_kernel(void)
18040 {
18041- memblock_reserve(__pa_symbol(&_text),
18042- __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
18043+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
18044
18045 #ifdef CONFIG_BLK_DEV_INITRD
18046 /* Reserve INITRD */
18047diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
18048index 4dac2f6..bc6a335 100644
18049--- a/arch/x86/kernel/head_32.S
18050+++ b/arch/x86/kernel/head_32.S
18051@@ -26,6 +26,12 @@
18052 /* Physical address */
18053 #define pa(X) ((X) - __PAGE_OFFSET)
18054
18055+#ifdef CONFIG_PAX_KERNEXEC
18056+#define ta(X) (X)
18057+#else
18058+#define ta(X) ((X) - __PAGE_OFFSET)
18059+#endif
18060+
18061 /*
18062 * References to members of the new_cpu_data structure.
18063 */
18064@@ -55,11 +61,7 @@
18065 * and small than max_low_pfn, otherwise will waste some page table entries
18066 */
18067
18068-#if PTRS_PER_PMD > 1
18069-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
18070-#else
18071-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
18072-#endif
18073+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
18074
18075 /* Number of possible pages in the lowmem region */
18076 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
18077@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
18078 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
18079
18080 /*
18081+ * Real beginning of normal "text" segment
18082+ */
18083+ENTRY(stext)
18084+ENTRY(_stext)
18085+
18086+/*
18087 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
18088 * %esi points to the real-mode code as a 32-bit pointer.
18089 * CS and DS must be 4 GB flat segments, but we don't depend on
18090@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
18091 * can.
18092 */
18093 __HEAD
18094+
18095+#ifdef CONFIG_PAX_KERNEXEC
18096+ jmp startup_32
18097+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
18098+.fill PAGE_SIZE-5,1,0xcc
18099+#endif
18100+
18101 ENTRY(startup_32)
18102 movl pa(stack_start),%ecx
18103
18104@@ -106,6 +121,59 @@ ENTRY(startup_32)
18105 2:
18106 leal -__PAGE_OFFSET(%ecx),%esp
18107
18108+#ifdef CONFIG_SMP
18109+ movl $pa(cpu_gdt_table),%edi
18110+ movl $__per_cpu_load,%eax
18111+ movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
18112+ rorl $16,%eax
18113+ movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
18114+ movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
18115+ movl $__per_cpu_end - 1,%eax
18116+ subl $__per_cpu_start,%eax
18117+ movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
18118+#endif
18119+
18120+#ifdef CONFIG_PAX_MEMORY_UDEREF
18121+ movl $NR_CPUS,%ecx
18122+ movl $pa(cpu_gdt_table),%edi
18123+1:
18124+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
18125+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
18126+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
18127+ addl $PAGE_SIZE_asm,%edi
18128+ loop 1b
18129+#endif
18130+
18131+#ifdef CONFIG_PAX_KERNEXEC
18132+ movl $pa(boot_gdt),%edi
18133+ movl $__LOAD_PHYSICAL_ADDR,%eax
18134+ movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
18135+ rorl $16,%eax
18136+ movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
18137+ movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
18138+ rorl $16,%eax
18139+
18140+ ljmp $(__BOOT_CS),$1f
18141+1:
18142+
18143+ movl $NR_CPUS,%ecx
18144+ movl $pa(cpu_gdt_table),%edi
18145+ addl $__PAGE_OFFSET,%eax
18146+1:
18147+ movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
18148+ movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
18149+ movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
18150+ movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
18151+ rorl $16,%eax
18152+ movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
18153+ movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
18154+ movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
18155+ movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
18156+ rorl $16,%eax
18157+ addl $PAGE_SIZE_asm,%edi
18158+ loop 1b
18159+#endif
18160+
18161 /*
18162 * Clear BSS first so that there are no surprises...
18163 */
18164@@ -196,8 +264,11 @@ ENTRY(startup_32)
18165 movl %eax, pa(max_pfn_mapped)
18166
18167 /* Do early initialization of the fixmap area */
18168- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
18169- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
18170+#ifdef CONFIG_COMPAT_VDSO
18171+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
18172+#else
18173+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
18174+#endif
18175 #else /* Not PAE */
18176
18177 page_pde_offset = (__PAGE_OFFSET >> 20);
18178@@ -227,8 +298,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
18179 movl %eax, pa(max_pfn_mapped)
18180
18181 /* Do early initialization of the fixmap area */
18182- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
18183- movl %eax,pa(initial_page_table+0xffc)
18184+#ifdef CONFIG_COMPAT_VDSO
18185+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
18186+#else
18187+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
18188+#endif
18189 #endif
18190
18191 #ifdef CONFIG_PARAVIRT
18192@@ -242,9 +316,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
18193 cmpl $num_subarch_entries, %eax
18194 jae bad_subarch
18195
18196- movl pa(subarch_entries)(,%eax,4), %eax
18197- subl $__PAGE_OFFSET, %eax
18198- jmp *%eax
18199+ jmp *pa(subarch_entries)(,%eax,4)
18200
18201 bad_subarch:
18202 WEAK(lguest_entry)
18203@@ -256,10 +328,10 @@ WEAK(xen_entry)
18204 __INITDATA
18205
18206 subarch_entries:
18207- .long default_entry /* normal x86/PC */
18208- .long lguest_entry /* lguest hypervisor */
18209- .long xen_entry /* Xen hypervisor */
18210- .long default_entry /* Moorestown MID */
18211+ .long ta(default_entry) /* normal x86/PC */
18212+ .long ta(lguest_entry) /* lguest hypervisor */
18213+ .long ta(xen_entry) /* Xen hypervisor */
18214+ .long ta(default_entry) /* Moorestown MID */
18215 num_subarch_entries = (. - subarch_entries) / 4
18216 .previous
18217 #else
18218@@ -316,6 +388,7 @@ default_entry:
18219 movl pa(mmu_cr4_features),%eax
18220 movl %eax,%cr4
18221
18222+#ifdef CONFIG_X86_PAE
18223 testb $X86_CR4_PAE, %al # check if PAE is enabled
18224 jz 6f
18225
18226@@ -344,6 +417,9 @@ default_entry:
18227 /* Make changes effective */
18228 wrmsr
18229
18230+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
18231+#endif
18232+
18233 6:
18234
18235 /*
18236@@ -442,14 +518,20 @@ is386: movl $2,%ecx # set MP
18237 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
18238 movl %eax,%ss # after changing gdt.
18239
18240- movl $(__USER_DS),%eax # DS/ES contains default USER segment
18241+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
18242 movl %eax,%ds
18243 movl %eax,%es
18244
18245 movl $(__KERNEL_PERCPU), %eax
18246 movl %eax,%fs # set this cpu's percpu
18247
18248+#ifdef CONFIG_CC_STACKPROTECTOR
18249 movl $(__KERNEL_STACK_CANARY),%eax
18250+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
18251+ movl $(__USER_DS),%eax
18252+#else
18253+ xorl %eax,%eax
18254+#endif
18255 movl %eax,%gs
18256
18257 xorl %eax,%eax # Clear LDT
18258@@ -526,8 +608,11 @@ setup_once:
18259 * relocation. Manually set base address in stack canary
18260 * segment descriptor.
18261 */
18262- movl $gdt_page,%eax
18263+ movl $cpu_gdt_table,%eax
18264 movl $stack_canary,%ecx
18265+#ifdef CONFIG_SMP
18266+ addl $__per_cpu_load,%ecx
18267+#endif
18268 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
18269 shrl $16, %ecx
18270 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
18271@@ -558,7 +643,7 @@ ENDPROC(early_idt_handlers)
18272 /* This is global to keep gas from relaxing the jumps */
18273 ENTRY(early_idt_handler)
18274 cld
18275- cmpl $2,%ss:early_recursion_flag
18276+ cmpl $1,%ss:early_recursion_flag
18277 je hlt_loop
18278 incl %ss:early_recursion_flag
18279
18280@@ -596,8 +681,8 @@ ENTRY(early_idt_handler)
18281 pushl (20+6*4)(%esp) /* trapno */
18282 pushl $fault_msg
18283 call printk
18284-#endif
18285 call dump_stack
18286+#endif
18287 hlt_loop:
18288 hlt
18289 jmp hlt_loop
18290@@ -616,8 +701,11 @@ ENDPROC(early_idt_handler)
18291 /* This is the default interrupt "handler" :-) */
18292 ALIGN
18293 ignore_int:
18294- cld
18295 #ifdef CONFIG_PRINTK
18296+ cmpl $2,%ss:early_recursion_flag
18297+ je hlt_loop
18298+ incl %ss:early_recursion_flag
18299+ cld
18300 pushl %eax
18301 pushl %ecx
18302 pushl %edx
18303@@ -626,9 +714,6 @@ ignore_int:
18304 movl $(__KERNEL_DS),%eax
18305 movl %eax,%ds
18306 movl %eax,%es
18307- cmpl $2,early_recursion_flag
18308- je hlt_loop
18309- incl early_recursion_flag
18310 pushl 16(%esp)
18311 pushl 24(%esp)
18312 pushl 32(%esp)
18313@@ -662,29 +747,43 @@ ENTRY(setup_once_ref)
18314 /*
18315 * BSS section
18316 */
18317-__PAGE_ALIGNED_BSS
18318- .align PAGE_SIZE
18319 #ifdef CONFIG_X86_PAE
18320+.section .initial_pg_pmd,"a",@progbits
18321 initial_pg_pmd:
18322 .fill 1024*KPMDS,4,0
18323 #else
18324+.section .initial_page_table,"a",@progbits
18325 ENTRY(initial_page_table)
18326 .fill 1024,4,0
18327 #endif
18328+.section .initial_pg_fixmap,"a",@progbits
18329 initial_pg_fixmap:
18330 .fill 1024,4,0
18331+.section .empty_zero_page,"a",@progbits
18332 ENTRY(empty_zero_page)
18333 .fill 4096,1,0
18334+.section .swapper_pg_dir,"a",@progbits
18335 ENTRY(swapper_pg_dir)
18336+#ifdef CONFIG_X86_PAE
18337+ .fill 4,8,0
18338+#else
18339 .fill 1024,4,0
18340+#endif
18341+
18342+/*
18343+ * The IDT has to be page-aligned to simplify the Pentium
18344+ * F0 0F bug workaround.. We have a special link segment
18345+ * for this.
18346+ */
18347+.section .idt,"a",@progbits
18348+ENTRY(idt_table)
18349+ .fill 256,8,0
18350
18351 /*
18352 * This starts the data section.
18353 */
18354 #ifdef CONFIG_X86_PAE
18355-__PAGE_ALIGNED_DATA
18356- /* Page-aligned for the benefit of paravirt? */
18357- .align PAGE_SIZE
18358+.section .initial_page_table,"a",@progbits
18359 ENTRY(initial_page_table)
18360 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
18361 # if KPMDS == 3
18362@@ -703,12 +802,20 @@ ENTRY(initial_page_table)
18363 # error "Kernel PMDs should be 1, 2 or 3"
18364 # endif
18365 .align PAGE_SIZE /* needs to be page-sized too */
18366+
18367+#ifdef CONFIG_PAX_PER_CPU_PGD
18368+ENTRY(cpu_pgd)
18369+ .rept NR_CPUS
18370+ .fill 4,8,0
18371+ .endr
18372+#endif
18373+
18374 #endif
18375
18376 .data
18377 .balign 4
18378 ENTRY(stack_start)
18379- .long init_thread_union+THREAD_SIZE
18380+ .long init_thread_union+THREAD_SIZE-8
18381
18382 __INITRODATA
18383 int_msg:
18384@@ -736,7 +843,7 @@ fault_msg:
18385 * segment size, and 32-bit linear address value:
18386 */
18387
18388- .data
18389+.section .rodata,"a",@progbits
18390 .globl boot_gdt_descr
18391 .globl idt_descr
18392
18393@@ -745,7 +852,7 @@ fault_msg:
18394 .word 0 # 32 bit align gdt_desc.address
18395 boot_gdt_descr:
18396 .word __BOOT_DS+7
18397- .long boot_gdt - __PAGE_OFFSET
18398+ .long pa(boot_gdt)
18399
18400 .word 0 # 32-bit align idt_desc.address
18401 idt_descr:
18402@@ -756,7 +863,7 @@ idt_descr:
18403 .word 0 # 32 bit align gdt_desc.address
18404 ENTRY(early_gdt_descr)
18405 .word GDT_ENTRIES*8-1
18406- .long gdt_page /* Overwritten for secondary CPUs */
18407+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
18408
18409 /*
18410 * The boot_gdt must mirror the equivalent in setup.S and is
18411@@ -765,5 +872,65 @@ ENTRY(early_gdt_descr)
18412 .align L1_CACHE_BYTES
18413 ENTRY(boot_gdt)
18414 .fill GDT_ENTRY_BOOT_CS,8,0
18415- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
18416- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
18417+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
18418+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
18419+
18420+ .align PAGE_SIZE_asm
18421+ENTRY(cpu_gdt_table)
18422+ .rept NR_CPUS
18423+ .quad 0x0000000000000000 /* NULL descriptor */
18424+ .quad 0x0000000000000000 /* 0x0b reserved */
18425+ .quad 0x0000000000000000 /* 0x13 reserved */
18426+ .quad 0x0000000000000000 /* 0x1b reserved */
18427+
18428+#ifdef CONFIG_PAX_KERNEXEC
18429+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
18430+#else
18431+ .quad 0x0000000000000000 /* 0x20 unused */
18432+#endif
18433+
18434+ .quad 0x0000000000000000 /* 0x28 unused */
18435+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
18436+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
18437+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
18438+ .quad 0x0000000000000000 /* 0x4b reserved */
18439+ .quad 0x0000000000000000 /* 0x53 reserved */
18440+ .quad 0x0000000000000000 /* 0x5b reserved */
18441+
18442+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
18443+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
18444+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
18445+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
18446+
18447+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
18448+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
18449+
18450+ /*
18451+ * Segments used for calling PnP BIOS have byte granularity.
18452+ * The code segments and data segments have fixed 64k limits,
18453+ * the transfer segment sizes are set at run time.
18454+ */
18455+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
18456+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
18457+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
18458+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
18459+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
18460+
18461+ /*
18462+ * The APM segments have byte granularity and their bases
18463+ * are set at run time. All have 64k limits.
18464+ */
18465+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
18466+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
18467+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
18468+
18469+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
18470+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
18471+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
18472+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
18473+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
18474+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
18475+
18476+ /* Be sure this is zeroed to avoid false validations in Xen */
18477+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
18478+ .endr
18479diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
18480index 94bf9cc..400455a 100644
18481--- a/arch/x86/kernel/head_64.S
18482+++ b/arch/x86/kernel/head_64.S
18483@@ -20,6 +20,8 @@
18484 #include <asm/processor-flags.h>
18485 #include <asm/percpu.h>
18486 #include <asm/nops.h>
18487+#include <asm/cpufeature.h>
18488+#include <asm/alternative-asm.h>
18489
18490 #ifdef CONFIG_PARAVIRT
18491 #include <asm/asm-offsets.h>
18492@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
18493 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
18494 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
18495 L3_START_KERNEL = pud_index(__START_KERNEL_map)
18496+L4_VMALLOC_START = pgd_index(VMALLOC_START)
18497+L3_VMALLOC_START = pud_index(VMALLOC_START)
18498+L4_VMALLOC_END = pgd_index(VMALLOC_END)
18499+L3_VMALLOC_END = pud_index(VMALLOC_END)
18500+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
18501+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
18502
18503 .text
18504 __HEAD
18505@@ -88,35 +96,23 @@ startup_64:
18506 */
18507 addq %rbp, init_level4_pgt + 0(%rip)
18508 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
18509+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
18510+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
18511+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
18512 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
18513
18514 addq %rbp, level3_ident_pgt + 0(%rip)
18515+#ifndef CONFIG_XEN
18516+ addq %rbp, level3_ident_pgt + 8(%rip)
18517+#endif
18518
18519- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
18520- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
18521+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
18522+
18523+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
18524+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
18525
18526 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
18527-
18528- /* Add an Identity mapping if I am above 1G */
18529- leaq _text(%rip), %rdi
18530- andq $PMD_PAGE_MASK, %rdi
18531-
18532- movq %rdi, %rax
18533- shrq $PUD_SHIFT, %rax
18534- andq $(PTRS_PER_PUD - 1), %rax
18535- jz ident_complete
18536-
18537- leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
18538- leaq level3_ident_pgt(%rip), %rbx
18539- movq %rdx, 0(%rbx, %rax, 8)
18540-
18541- movq %rdi, %rax
18542- shrq $PMD_SHIFT, %rax
18543- andq $(PTRS_PER_PMD - 1), %rax
18544- leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
18545- leaq level2_spare_pgt(%rip), %rbx
18546- movq %rdx, 0(%rbx, %rax, 8)
18547-ident_complete:
18548+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
18549
18550 /*
18551 * Fixup the kernel text+data virtual addresses. Note that
18552@@ -159,8 +155,8 @@ ENTRY(secondary_startup_64)
18553 * after the boot processor executes this code.
18554 */
18555
18556- /* Enable PAE mode and PGE */
18557- movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
18558+ /* Enable PAE mode and PSE/PGE */
18559+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
18560 movq %rax, %cr4
18561
18562 /* Setup early boot stage 4 level pagetables. */
18563@@ -182,9 +178,17 @@ ENTRY(secondary_startup_64)
18564 movl $MSR_EFER, %ecx
18565 rdmsr
18566 btsl $_EFER_SCE, %eax /* Enable System Call */
18567- btl $20,%edi /* No Execute supported? */
18568+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
18569 jnc 1f
18570 btsl $_EFER_NX, %eax
18571+ leaq init_level4_pgt(%rip), %rdi
18572+#ifndef CONFIG_EFI
18573+ btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
18574+#endif
18575+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
18576+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
18577+ btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
18578+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
18579 1: wrmsr /* Make changes effective */
18580
18581 /* Setup cr0 */
18582@@ -246,6 +250,7 @@ ENTRY(secondary_startup_64)
18583 * jump. In addition we need to ensure %cs is set so we make this
18584 * a far return.
18585 */
18586+ pax_set_fptr_mask
18587 movq initial_code(%rip),%rax
18588 pushq $0 # fake return address to stop unwinder
18589 pushq $__KERNEL_CS # set correct cs
18590@@ -268,7 +273,7 @@ ENTRY(secondary_startup_64)
18591 bad_address:
18592 jmp bad_address
18593
18594- .section ".init.text","ax"
18595+ __INIT
18596 .globl early_idt_handlers
18597 early_idt_handlers:
18598 # 104(%rsp) %rflags
18599@@ -347,11 +352,15 @@ ENTRY(early_idt_handler)
18600 addq $16,%rsp # drop vector number and error code
18601 decl early_recursion_flag(%rip)
18602 INTERRUPT_RETURN
18603+ .previous
18604
18605+ __INITDATA
18606 .balign 4
18607 early_recursion_flag:
18608 .long 0
18609+ .previous
18610
18611+ .section .rodata,"a",@progbits
18612 #ifdef CONFIG_EARLY_PRINTK
18613 early_idt_msg:
18614 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
18615@@ -360,6 +369,7 @@ early_idt_ripmsg:
18616 #endif /* CONFIG_EARLY_PRINTK */
18617 .previous
18618
18619+ .section .rodata,"a",@progbits
18620 #define NEXT_PAGE(name) \
18621 .balign PAGE_SIZE; \
18622 ENTRY(name)
18623@@ -372,7 +382,6 @@ ENTRY(name)
18624 i = i + 1 ; \
18625 .endr
18626
18627- .data
18628 /*
18629 * This default setting generates an ident mapping at address 0x100000
18630 * and a mapping for the kernel that precisely maps virtual address
18631@@ -383,13 +392,41 @@ NEXT_PAGE(init_level4_pgt)
18632 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
18633 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
18634 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
18635+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
18636+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
18637+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
18638+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
18639+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
18640+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
18641 .org init_level4_pgt + L4_START_KERNEL*8, 0
18642 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
18643 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
18644
18645+#ifdef CONFIG_PAX_PER_CPU_PGD
18646+NEXT_PAGE(cpu_pgd)
18647+ .rept NR_CPUS
18648+ .fill 512,8,0
18649+ .endr
18650+#endif
18651+
18652 NEXT_PAGE(level3_ident_pgt)
18653 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
18654+#ifdef CONFIG_XEN
18655 .fill 511,8,0
18656+#else
18657+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
18658+ .fill 510,8,0
18659+#endif
18660+
18661+NEXT_PAGE(level3_vmalloc_start_pgt)
18662+ .fill 512,8,0
18663+
18664+NEXT_PAGE(level3_vmalloc_end_pgt)
18665+ .fill 512,8,0
18666+
18667+NEXT_PAGE(level3_vmemmap_pgt)
18668+ .fill L3_VMEMMAP_START,8,0
18669+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
18670
18671 NEXT_PAGE(level3_kernel_pgt)
18672 .fill L3_START_KERNEL,8,0
18673@@ -397,20 +434,23 @@ NEXT_PAGE(level3_kernel_pgt)
18674 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
18675 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
18676
18677+NEXT_PAGE(level2_vmemmap_pgt)
18678+ .fill 512,8,0
18679+
18680 NEXT_PAGE(level2_fixmap_pgt)
18681- .fill 506,8,0
18682- .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
18683- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
18684- .fill 5,8,0
18685+ .fill 507,8,0
18686+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
18687+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
18688+ .fill 4,8,0
18689
18690-NEXT_PAGE(level1_fixmap_pgt)
18691+NEXT_PAGE(level1_vsyscall_pgt)
18692 .fill 512,8,0
18693
18694-NEXT_PAGE(level2_ident_pgt)
18695- /* Since I easily can, map the first 1G.
18696+ /* Since I easily can, map the first 2G.
18697 * Don't set NX because code runs from these pages.
18698 */
18699- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
18700+NEXT_PAGE(level2_ident_pgt)
18701+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
18702
18703 NEXT_PAGE(level2_kernel_pgt)
18704 /*
18705@@ -423,37 +463,59 @@ NEXT_PAGE(level2_kernel_pgt)
18706 * If you want to increase this then increase MODULES_VADDR
18707 * too.)
18708 */
18709- PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
18710- KERNEL_IMAGE_SIZE/PMD_SIZE)
18711-
18712-NEXT_PAGE(level2_spare_pgt)
18713- .fill 512, 8, 0
18714+ PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
18715
18716 #undef PMDS
18717 #undef NEXT_PAGE
18718
18719- .data
18720+ .align PAGE_SIZE
18721+ENTRY(cpu_gdt_table)
18722+ .rept NR_CPUS
18723+ .quad 0x0000000000000000 /* NULL descriptor */
18724+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
18725+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
18726+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
18727+ .quad 0x00cffb000000ffff /* __USER32_CS */
18728+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
18729+ .quad 0x00affb000000ffff /* __USER_CS */
18730+
18731+#ifdef CONFIG_PAX_KERNEXEC
18732+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
18733+#else
18734+ .quad 0x0 /* unused */
18735+#endif
18736+
18737+ .quad 0,0 /* TSS */
18738+ .quad 0,0 /* LDT */
18739+ .quad 0,0,0 /* three TLS descriptors */
18740+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
18741+ /* asm/segment.h:GDT_ENTRIES must match this */
18742+
18743+ /* zero the remaining page */
18744+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
18745+ .endr
18746+
18747 .align 16
18748 .globl early_gdt_descr
18749 early_gdt_descr:
18750 .word GDT_ENTRIES*8-1
18751 early_gdt_descr_base:
18752- .quad INIT_PER_CPU_VAR(gdt_page)
18753+ .quad cpu_gdt_table
18754
18755 ENTRY(phys_base)
18756 /* This must match the first entry in level2_kernel_pgt */
18757 .quad 0x0000000000000000
18758
18759 #include "../../x86/xen/xen-head.S"
18760-
18761- .section .bss, "aw", @nobits
18762+
18763+ .section .rodata,"a",@progbits
18764 .align L1_CACHE_BYTES
18765 ENTRY(idt_table)
18766- .skip IDT_ENTRIES * 16
18767+ .fill 512,8,0
18768
18769 .align L1_CACHE_BYTES
18770 ENTRY(nmi_idt_table)
18771- .skip IDT_ENTRIES * 16
18772+ .fill 512,8,0
18773
18774 __PAGE_ALIGNED_BSS
18775 .align PAGE_SIZE
18776diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
18777index 9c3bd4a..e1d9b35 100644
18778--- a/arch/x86/kernel/i386_ksyms_32.c
18779+++ b/arch/x86/kernel/i386_ksyms_32.c
18780@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
18781 EXPORT_SYMBOL(cmpxchg8b_emu);
18782 #endif
18783
18784+EXPORT_SYMBOL_GPL(cpu_gdt_table);
18785+
18786 /* Networking helper routines. */
18787 EXPORT_SYMBOL(csum_partial_copy_generic);
18788+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
18789+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
18790
18791 EXPORT_SYMBOL(__get_user_1);
18792 EXPORT_SYMBOL(__get_user_2);
18793@@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
18794
18795 EXPORT_SYMBOL(csum_partial);
18796 EXPORT_SYMBOL(empty_zero_page);
18797+
18798+#ifdef CONFIG_PAX_KERNEXEC
18799+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
18800+#endif
18801diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
18802index 675a050..95febfd 100644
18803--- a/arch/x86/kernel/i387.c
18804+++ b/arch/x86/kernel/i387.c
18805@@ -55,7 +55,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
18806 static inline bool interrupted_user_mode(void)
18807 {
18808 struct pt_regs *regs = get_irq_regs();
18809- return regs && user_mode_vm(regs);
18810+ return regs && user_mode(regs);
18811 }
18812
18813 /*
18814diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
18815index 9a5c460..dc4374d 100644
18816--- a/arch/x86/kernel/i8259.c
18817+++ b/arch/x86/kernel/i8259.c
18818@@ -209,7 +209,7 @@ spurious_8259A_irq:
18819 "spurious 8259A interrupt: IRQ%d.\n", irq);
18820 spurious_irq_mask |= irqmask;
18821 }
18822- atomic_inc(&irq_err_count);
18823+ atomic_inc_unchecked(&irq_err_count);
18824 /*
18825 * Theoretically we do not have to handle this IRQ,
18826 * but in Linux this does not cause problems and is
18827diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
18828index 8c96897..be66bfa 100644
18829--- a/arch/x86/kernel/ioport.c
18830+++ b/arch/x86/kernel/ioport.c
18831@@ -6,6 +6,7 @@
18832 #include <linux/sched.h>
18833 #include <linux/kernel.h>
18834 #include <linux/capability.h>
18835+#include <linux/security.h>
18836 #include <linux/errno.h>
18837 #include <linux/types.h>
18838 #include <linux/ioport.h>
18839@@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
18840
18841 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
18842 return -EINVAL;
18843+#ifdef CONFIG_GRKERNSEC_IO
18844+ if (turn_on && grsec_disable_privio) {
18845+ gr_handle_ioperm();
18846+ return -EPERM;
18847+ }
18848+#endif
18849 if (turn_on && !capable(CAP_SYS_RAWIO))
18850 return -EPERM;
18851
18852@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
18853 * because the ->io_bitmap_max value must match the bitmap
18854 * contents:
18855 */
18856- tss = &per_cpu(init_tss, get_cpu());
18857+ tss = init_tss + get_cpu();
18858
18859 if (turn_on)
18860 bitmap_clear(t->io_bitmap_ptr, from, num);
18861@@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
18862 return -EINVAL;
18863 /* Trying to gain more privileges? */
18864 if (level > old) {
18865+#ifdef CONFIG_GRKERNSEC_IO
18866+ if (grsec_disable_privio) {
18867+ gr_handle_iopl();
18868+ return -EPERM;
18869+ }
18870+#endif
18871 if (!capable(CAP_SYS_RAWIO))
18872 return -EPERM;
18873 }
18874diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
18875index e4595f1..ee3bfb8 100644
18876--- a/arch/x86/kernel/irq.c
18877+++ b/arch/x86/kernel/irq.c
18878@@ -18,7 +18,7 @@
18879 #include <asm/mce.h>
18880 #include <asm/hw_irq.h>
18881
18882-atomic_t irq_err_count;
18883+atomic_unchecked_t irq_err_count;
18884
18885 /* Function pointer for generic interrupt vector handling */
18886 void (*x86_platform_ipi_callback)(void) = NULL;
18887@@ -122,9 +122,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
18888 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
18889 seq_printf(p, " Machine check polls\n");
18890 #endif
18891- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
18892+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
18893 #if defined(CONFIG_X86_IO_APIC)
18894- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
18895+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
18896 #endif
18897 return 0;
18898 }
18899@@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
18900
18901 u64 arch_irq_stat(void)
18902 {
18903- u64 sum = atomic_read(&irq_err_count);
18904+ u64 sum = atomic_read_unchecked(&irq_err_count);
18905
18906 #ifdef CONFIG_X86_IO_APIC
18907- sum += atomic_read(&irq_mis_count);
18908+ sum += atomic_read_unchecked(&irq_mis_count);
18909 #endif
18910 return sum;
18911 }
18912diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
18913index 344faf8..355f60d 100644
18914--- a/arch/x86/kernel/irq_32.c
18915+++ b/arch/x86/kernel/irq_32.c
18916@@ -39,7 +39,7 @@ static int check_stack_overflow(void)
18917 __asm__ __volatile__("andl %%esp,%0" :
18918 "=r" (sp) : "0" (THREAD_SIZE - 1));
18919
18920- return sp < (sizeof(struct thread_info) + STACK_WARN);
18921+ return sp < STACK_WARN;
18922 }
18923
18924 static void print_stack_overflow(void)
18925@@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
18926 * per-CPU IRQ handling contexts (thread information and stack)
18927 */
18928 union irq_ctx {
18929- struct thread_info tinfo;
18930- u32 stack[THREAD_SIZE/sizeof(u32)];
18931+ unsigned long previous_esp;
18932+ u32 stack[THREAD_SIZE/sizeof(u32)];
18933 } __attribute__((aligned(THREAD_SIZE)));
18934
18935 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
18936@@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
18937 static inline int
18938 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
18939 {
18940- union irq_ctx *curctx, *irqctx;
18941+ union irq_ctx *irqctx;
18942 u32 *isp, arg1, arg2;
18943
18944- curctx = (union irq_ctx *) current_thread_info();
18945 irqctx = __this_cpu_read(hardirq_ctx);
18946
18947 /*
18948@@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
18949 * handler) we can't do that and just have to keep using the
18950 * current stack (which is the irq stack already after all)
18951 */
18952- if (unlikely(curctx == irqctx))
18953+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
18954 return 0;
18955
18956 /* build the stack frame on the IRQ stack */
18957- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
18958- irqctx->tinfo.task = curctx->tinfo.task;
18959- irqctx->tinfo.previous_esp = current_stack_pointer;
18960+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
18961+ irqctx->previous_esp = current_stack_pointer;
18962
18963- /* Copy the preempt_count so that the [soft]irq checks work. */
18964- irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
18965+#ifdef CONFIG_PAX_MEMORY_UDEREF
18966+ __set_fs(MAKE_MM_SEG(0));
18967+#endif
18968
18969 if (unlikely(overflow))
18970 call_on_stack(print_stack_overflow, isp);
18971@@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
18972 : "0" (irq), "1" (desc), "2" (isp),
18973 "D" (desc->handle_irq)
18974 : "memory", "cc", "ecx");
18975+
18976+#ifdef CONFIG_PAX_MEMORY_UDEREF
18977+ __set_fs(current_thread_info()->addr_limit);
18978+#endif
18979+
18980 return 1;
18981 }
18982
18983@@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
18984 */
18985 void __cpuinit irq_ctx_init(int cpu)
18986 {
18987- union irq_ctx *irqctx;
18988-
18989 if (per_cpu(hardirq_ctx, cpu))
18990 return;
18991
18992- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
18993- THREADINFO_GFP,
18994- THREAD_SIZE_ORDER));
18995- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
18996- irqctx->tinfo.cpu = cpu;
18997- irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
18998- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
18999-
19000- per_cpu(hardirq_ctx, cpu) = irqctx;
19001-
19002- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
19003- THREADINFO_GFP,
19004- THREAD_SIZE_ORDER));
19005- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
19006- irqctx->tinfo.cpu = cpu;
19007- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
19008-
19009- per_cpu(softirq_ctx, cpu) = irqctx;
19010+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
19011+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
19012+
19013+ printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
19014+ cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
19015
19016 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
19017 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
19018@@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
19019 asmlinkage void do_softirq(void)
19020 {
19021 unsigned long flags;
19022- struct thread_info *curctx;
19023 union irq_ctx *irqctx;
19024 u32 *isp;
19025
19026@@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
19027 local_irq_save(flags);
19028
19029 if (local_softirq_pending()) {
19030- curctx = current_thread_info();
19031 irqctx = __this_cpu_read(softirq_ctx);
19032- irqctx->tinfo.task = curctx->task;
19033- irqctx->tinfo.previous_esp = current_stack_pointer;
19034+ irqctx->previous_esp = current_stack_pointer;
19035
19036 /* build the stack frame on the softirq stack */
19037- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
19038+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
19039+
19040+#ifdef CONFIG_PAX_MEMORY_UDEREF
19041+ __set_fs(MAKE_MM_SEG(0));
19042+#endif
19043
19044 call_on_stack(__do_softirq, isp);
19045+
19046+#ifdef CONFIG_PAX_MEMORY_UDEREF
19047+ __set_fs(current_thread_info()->addr_limit);
19048+#endif
19049+
19050 /*
19051 * Shouldn't happen, we returned above if in_interrupt():
19052 */
19053@@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
19054 if (unlikely(!desc))
19055 return false;
19056
19057- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
19058+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
19059 if (unlikely(overflow))
19060 print_stack_overflow();
19061 desc->handle_irq(irq, desc);
19062diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
19063index d04d3ec..ea4b374 100644
19064--- a/arch/x86/kernel/irq_64.c
19065+++ b/arch/x86/kernel/irq_64.c
19066@@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
19067 u64 estack_top, estack_bottom;
19068 u64 curbase = (u64)task_stack_page(current);
19069
19070- if (user_mode_vm(regs))
19071+ if (user_mode(regs))
19072 return;
19073
19074 if (regs->sp >= curbase + sizeof(struct thread_info) +
19075diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
19076index dc1404b..bbc43e7 100644
19077--- a/arch/x86/kernel/kdebugfs.c
19078+++ b/arch/x86/kernel/kdebugfs.c
19079@@ -27,7 +27,7 @@ struct setup_data_node {
19080 u32 len;
19081 };
19082
19083-static ssize_t setup_data_read(struct file *file, char __user *user_buf,
19084+static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
19085 size_t count, loff_t *ppos)
19086 {
19087 struct setup_data_node *node = file->private_data;
19088diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
19089index 836f832..a8bda67 100644
19090--- a/arch/x86/kernel/kgdb.c
19091+++ b/arch/x86/kernel/kgdb.c
19092@@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
19093 #ifdef CONFIG_X86_32
19094 switch (regno) {
19095 case GDB_SS:
19096- if (!user_mode_vm(regs))
19097+ if (!user_mode(regs))
19098 *(unsigned long *)mem = __KERNEL_DS;
19099 break;
19100 case GDB_SP:
19101- if (!user_mode_vm(regs))
19102+ if (!user_mode(regs))
19103 *(unsigned long *)mem = kernel_stack_pointer(regs);
19104 break;
19105 case GDB_GS:
19106@@ -229,7 +229,10 @@ static void kgdb_correct_hw_break(void)
19107 bp->attr.bp_addr = breakinfo[breakno].addr;
19108 bp->attr.bp_len = breakinfo[breakno].len;
19109 bp->attr.bp_type = breakinfo[breakno].type;
19110- info->address = breakinfo[breakno].addr;
19111+ if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
19112+ info->address = ktla_ktva(breakinfo[breakno].addr);
19113+ else
19114+ info->address = breakinfo[breakno].addr;
19115 info->len = breakinfo[breakno].len;
19116 info->type = breakinfo[breakno].type;
19117 val = arch_install_hw_breakpoint(bp);
19118@@ -476,12 +479,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
19119 case 'k':
19120 /* clear the trace bit */
19121 linux_regs->flags &= ~X86_EFLAGS_TF;
19122- atomic_set(&kgdb_cpu_doing_single_step, -1);
19123+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
19124
19125 /* set the trace bit if we're stepping */
19126 if (remcomInBuffer[0] == 's') {
19127 linux_regs->flags |= X86_EFLAGS_TF;
19128- atomic_set(&kgdb_cpu_doing_single_step,
19129+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
19130 raw_smp_processor_id());
19131 }
19132
19133@@ -546,7 +549,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
19134
19135 switch (cmd) {
19136 case DIE_DEBUG:
19137- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
19138+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
19139 if (user_mode(regs))
19140 return single_step_cont(regs, args);
19141 break;
19142@@ -751,11 +754,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
19143 #endif /* CONFIG_DEBUG_RODATA */
19144
19145 bpt->type = BP_BREAKPOINT;
19146- err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
19147+ err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
19148 BREAK_INSTR_SIZE);
19149 if (err)
19150 return err;
19151- err = probe_kernel_write((char *)bpt->bpt_addr,
19152+ err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
19153 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
19154 #ifdef CONFIG_DEBUG_RODATA
19155 if (!err)
19156@@ -768,7 +771,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
19157 return -EBUSY;
19158 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
19159 BREAK_INSTR_SIZE);
19160- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
19161+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
19162 if (err)
19163 return err;
19164 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
19165@@ -793,13 +796,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
19166 if (mutex_is_locked(&text_mutex))
19167 goto knl_write;
19168 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
19169- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
19170+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
19171 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
19172 goto knl_write;
19173 return err;
19174 knl_write:
19175 #endif /* CONFIG_DEBUG_RODATA */
19176- return probe_kernel_write((char *)bpt->bpt_addr,
19177+ return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
19178 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
19179 }
19180
19181diff --git a/arch/x86/kernel/kprobes-opt.c b/arch/x86/kernel/kprobes-opt.c
19182index c5e410e..ed5a7f0 100644
19183--- a/arch/x86/kernel/kprobes-opt.c
19184+++ b/arch/x86/kernel/kprobes-opt.c
19185@@ -338,7 +338,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
19186 * Verify if the address gap is in 2GB range, because this uses
19187 * a relative jump.
19188 */
19189- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
19190+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
19191 if (abs(rel) > 0x7fffffff)
19192 return -ERANGE;
19193
19194@@ -353,16 +353,16 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
19195 op->optinsn.size = ret;
19196
19197 /* Copy arch-dep-instance from template */
19198- memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
19199+ memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
19200
19201 /* Set probe information */
19202 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
19203
19204 /* Set probe function call */
19205- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
19206+ synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
19207
19208 /* Set returning jmp instruction at the tail of out-of-line buffer */
19209- synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
19210+ synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
19211 (u8 *)op->kp.addr + op->optinsn.size);
19212
19213 flush_icache_range((unsigned long) buf,
19214@@ -385,7 +385,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
19215 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
19216
19217 /* Backup instructions which will be replaced by jump address */
19218- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
19219+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
19220 RELATIVE_ADDR_SIZE);
19221
19222 insn_buf[0] = RELATIVEJUMP_OPCODE;
19223@@ -483,7 +483,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
19224 /* This kprobe is really able to run optimized path. */
19225 op = container_of(p, struct optimized_kprobe, kp);
19226 /* Detour through copied instructions */
19227- regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
19228+ regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
19229 if (!reenter)
19230 reset_current_kprobe();
19231 preempt_enable_no_resched();
19232diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
19233index 57916c0..9e0b9d0 100644
19234--- a/arch/x86/kernel/kprobes.c
19235+++ b/arch/x86/kernel/kprobes.c
19236@@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
19237 s32 raddr;
19238 } __attribute__((packed)) *insn;
19239
19240- insn = (struct __arch_relative_insn *)from;
19241+ insn = (struct __arch_relative_insn *)ktla_ktva(from);
19242+
19243+ pax_open_kernel();
19244 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
19245 insn->op = op;
19246+ pax_close_kernel();
19247 }
19248
19249 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
19250@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
19251 kprobe_opcode_t opcode;
19252 kprobe_opcode_t *orig_opcodes = opcodes;
19253
19254- if (search_exception_tables((unsigned long)opcodes))
19255+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
19256 return 0; /* Page fault may occur on this address. */
19257
19258 retry:
19259@@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
19260 * for the first byte, we can recover the original instruction
19261 * from it and kp->opcode.
19262 */
19263- memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
19264+ memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
19265 buf[0] = kp->opcode;
19266- return (unsigned long)buf;
19267+ return ktva_ktla((unsigned long)buf);
19268 }
19269
19270 /*
19271@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
19272 /* Another subsystem puts a breakpoint, failed to recover */
19273 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
19274 return 0;
19275+ pax_open_kernel();
19276 memcpy(dest, insn.kaddr, insn.length);
19277+ pax_close_kernel();
19278
19279 #ifdef CONFIG_X86_64
19280 if (insn_rip_relative(&insn)) {
19281@@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
19282 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
19283 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
19284 disp = (u8 *) dest + insn_offset_displacement(&insn);
19285+ pax_open_kernel();
19286 *(s32 *) disp = (s32) newdisp;
19287+ pax_close_kernel();
19288 }
19289 #endif
19290 return insn.length;
19291@@ -485,7 +492,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
19292 * nor set current_kprobe, because it doesn't use single
19293 * stepping.
19294 */
19295- regs->ip = (unsigned long)p->ainsn.insn;
19296+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
19297 preempt_enable_no_resched();
19298 return;
19299 }
19300@@ -502,9 +509,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
19301 regs->flags &= ~X86_EFLAGS_IF;
19302 /* single step inline if the instruction is an int3 */
19303 if (p->opcode == BREAKPOINT_INSTRUCTION)
19304- regs->ip = (unsigned long)p->addr;
19305+ regs->ip = ktla_ktva((unsigned long)p->addr);
19306 else
19307- regs->ip = (unsigned long)p->ainsn.insn;
19308+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
19309 }
19310
19311 /*
19312@@ -600,7 +607,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
19313 setup_singlestep(p, regs, kcb, 0);
19314 return 1;
19315 }
19316- } else if (*addr != BREAKPOINT_INSTRUCTION) {
19317+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
19318 /*
19319 * The breakpoint instruction was removed right
19320 * after we hit it. Another cpu has removed
19321@@ -651,6 +658,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
19322 " movq %rax, 152(%rsp)\n"
19323 RESTORE_REGS_STRING
19324 " popfq\n"
19325+#ifdef KERNEXEC_PLUGIN
19326+ " btsq $63,(%rsp)\n"
19327+#endif
19328 #else
19329 " pushf\n"
19330 SAVE_REGS_STRING
19331@@ -788,7 +798,7 @@ static void __kprobes
19332 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
19333 {
19334 unsigned long *tos = stack_addr(regs);
19335- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
19336+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
19337 unsigned long orig_ip = (unsigned long)p->addr;
19338 kprobe_opcode_t *insn = p->ainsn.insn;
19339
19340@@ -970,7 +980,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
19341 struct die_args *args = data;
19342 int ret = NOTIFY_DONE;
19343
19344- if (args->regs && user_mode_vm(args->regs))
19345+ if (args->regs && user_mode(args->regs))
19346 return ret;
19347
19348 switch (val) {
19349diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
19350index 4180a87..4678e4f 100644
19351--- a/arch/x86/kernel/kvm.c
19352+++ b/arch/x86/kernel/kvm.c
19353@@ -267,7 +267,7 @@ static void __init paravirt_ops_setup(void)
19354 pv_info.paravirt_enabled = 1;
19355
19356 if (kvm_para_has_feature(KVM_FEATURE_NOP_IO_DELAY))
19357- pv_cpu_ops.io_delay = kvm_io_delay;
19358+ *(void **)&pv_cpu_ops.io_delay = kvm_io_delay;
19359
19360 #ifdef CONFIG_X86_IO_APIC
19361 no_timer_check = 1;
19362@@ -461,18 +461,18 @@ void __init kvm_guest_init(void)
19363 for (i = 0; i < KVM_TASK_SLEEP_HASHSIZE; i++)
19364 spin_lock_init(&async_pf_sleepers[i].lock);
19365 if (kvm_para_has_feature(KVM_FEATURE_ASYNC_PF))
19366- x86_init.irqs.trap_init = kvm_apf_trap_init;
19367+ *(void **)&x86_init.irqs.trap_init = kvm_apf_trap_init;
19368
19369 if (kvm_para_has_feature(KVM_FEATURE_STEAL_TIME)) {
19370 has_steal_clock = 1;
19371- pv_time_ops.steal_clock = kvm_steal_clock;
19372+ *(void **)&pv_time_ops.steal_clock = kvm_steal_clock;
19373 }
19374
19375 if (kvm_para_has_feature(KVM_FEATURE_PV_EOI))
19376 apic_set_eoi_write(kvm_guest_apic_eoi_write);
19377
19378 #ifdef CONFIG_SMP
19379- smp_ops.smp_prepare_boot_cpu = kvm_smp_prepare_boot_cpu;
19380+ *(void **)&smp_ops.smp_prepare_boot_cpu = kvm_smp_prepare_boot_cpu;
19381 register_cpu_notifier(&kvm_cpu_notifier);
19382 #else
19383 kvm_guest_cpu_init();
19384diff --git a/arch/x86/kernel/kvmclock.c b/arch/x86/kernel/kvmclock.c
19385index f1b42b3..27ac4e7 100644
19386--- a/arch/x86/kernel/kvmclock.c
19387+++ b/arch/x86/kernel/kvmclock.c
19388@@ -211,19 +211,19 @@ void __init kvmclock_init(void)
19389
19390 if (kvm_register_clock("boot clock"))
19391 return;
19392- pv_time_ops.sched_clock = kvm_clock_read;
19393- x86_platform.calibrate_tsc = kvm_get_tsc_khz;
19394- x86_platform.get_wallclock = kvm_get_wallclock;
19395- x86_platform.set_wallclock = kvm_set_wallclock;
19396+ *(void **)&pv_time_ops.sched_clock = kvm_clock_read;
19397+ *(void **)&x86_platform.calibrate_tsc = kvm_get_tsc_khz;
19398+ *(void **)&x86_platform.get_wallclock = kvm_get_wallclock;
19399+ *(void **)&x86_platform.set_wallclock = kvm_set_wallclock;
19400 #ifdef CONFIG_X86_LOCAL_APIC
19401- x86_cpuinit.early_percpu_clock_init =
19402+ *(void **)&x86_cpuinit.early_percpu_clock_init =
19403 kvm_setup_secondary_clock;
19404 #endif
19405- x86_platform.save_sched_clock_state = kvm_save_sched_clock_state;
19406- x86_platform.restore_sched_clock_state = kvm_restore_sched_clock_state;
19407- machine_ops.shutdown = kvm_shutdown;
19408+ *(void **)&x86_platform.save_sched_clock_state = kvm_save_sched_clock_state;
19409+ *(void **)&x86_platform.restore_sched_clock_state = kvm_restore_sched_clock_state;
19410+ *(void **)&machine_ops.shutdown = kvm_shutdown;
19411 #ifdef CONFIG_KEXEC
19412- machine_ops.crash_shutdown = kvm_crash_shutdown;
19413+ *(void **)&machine_ops.crash_shutdown = kvm_crash_shutdown;
19414 #endif
19415 kvm_get_preset_lpj();
19416 clocksource_register_hz(&kvm_clock, NSEC_PER_SEC);
19417diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
19418index ebc9873..1b9724b 100644
19419--- a/arch/x86/kernel/ldt.c
19420+++ b/arch/x86/kernel/ldt.c
19421@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
19422 if (reload) {
19423 #ifdef CONFIG_SMP
19424 preempt_disable();
19425- load_LDT(pc);
19426+ load_LDT_nolock(pc);
19427 if (!cpumask_equal(mm_cpumask(current->mm),
19428 cpumask_of(smp_processor_id())))
19429 smp_call_function(flush_ldt, current->mm, 1);
19430 preempt_enable();
19431 #else
19432- load_LDT(pc);
19433+ load_LDT_nolock(pc);
19434 #endif
19435 }
19436 if (oldsize) {
19437@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
19438 return err;
19439
19440 for (i = 0; i < old->size; i++)
19441- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
19442+ write_ldt_entry(new->ldt, i, old->ldt + i);
19443 return 0;
19444 }
19445
19446@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
19447 retval = copy_ldt(&mm->context, &old_mm->context);
19448 mutex_unlock(&old_mm->context.lock);
19449 }
19450+
19451+ if (tsk == current) {
19452+ mm->context.vdso = 0;
19453+
19454+#ifdef CONFIG_X86_32
19455+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
19456+ mm->context.user_cs_base = 0UL;
19457+ mm->context.user_cs_limit = ~0UL;
19458+
19459+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
19460+ cpus_clear(mm->context.cpu_user_cs_mask);
19461+#endif
19462+
19463+#endif
19464+#endif
19465+
19466+ }
19467+
19468 return retval;
19469 }
19470
19471@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
19472 }
19473 }
19474
19475+#ifdef CONFIG_PAX_SEGMEXEC
19476+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
19477+ error = -EINVAL;
19478+ goto out_unlock;
19479+ }
19480+#endif
19481+
19482 fill_ldt(&ldt, &ldt_info);
19483 if (oldmode)
19484 ldt.avl = 0;
19485diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
19486index 5b19e4d..6476a76 100644
19487--- a/arch/x86/kernel/machine_kexec_32.c
19488+++ b/arch/x86/kernel/machine_kexec_32.c
19489@@ -26,7 +26,7 @@
19490 #include <asm/cacheflush.h>
19491 #include <asm/debugreg.h>
19492
19493-static void set_idt(void *newidt, __u16 limit)
19494+static void set_idt(struct desc_struct *newidt, __u16 limit)
19495 {
19496 struct desc_ptr curidt;
19497
19498@@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
19499 }
19500
19501
19502-static void set_gdt(void *newgdt, __u16 limit)
19503+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
19504 {
19505 struct desc_ptr curgdt;
19506
19507@@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
19508 }
19509
19510 control_page = page_address(image->control_code_page);
19511- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
19512+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
19513
19514 relocate_kernel_ptr = control_page;
19515 page_list[PA_CONTROL_PAGE] = __pa(control_page);
19516diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
19517index 3544aed..01ddc1c 100644
19518--- a/arch/x86/kernel/microcode_intel.c
19519+++ b/arch/x86/kernel/microcode_intel.c
19520@@ -431,13 +431,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
19521
19522 static int get_ucode_user(void *to, const void *from, size_t n)
19523 {
19524- return copy_from_user(to, from, n);
19525+ return copy_from_user(to, (const void __force_user *)from, n);
19526 }
19527
19528 static enum ucode_state
19529 request_microcode_user(int cpu, const void __user *buf, size_t size)
19530 {
19531- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
19532+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
19533 }
19534
19535 static void microcode_fini_cpu(int cpu)
19536diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
19537index 216a4d7..b328f09 100644
19538--- a/arch/x86/kernel/module.c
19539+++ b/arch/x86/kernel/module.c
19540@@ -43,15 +43,60 @@ do { \
19541 } while (0)
19542 #endif
19543
19544-void *module_alloc(unsigned long size)
19545+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
19546 {
19547- if (PAGE_ALIGN(size) > MODULES_LEN)
19548+ if (size == 0 || PAGE_ALIGN(size) > MODULES_LEN)
19549 return NULL;
19550 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
19551- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
19552+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
19553 -1, __builtin_return_address(0));
19554 }
19555
19556+void *module_alloc(unsigned long size)
19557+{
19558+
19559+#ifdef CONFIG_PAX_KERNEXEC
19560+ return __module_alloc(size, PAGE_KERNEL);
19561+#else
19562+ return __module_alloc(size, PAGE_KERNEL_EXEC);
19563+#endif
19564+
19565+}
19566+
19567+#ifdef CONFIG_PAX_KERNEXEC
19568+#ifdef CONFIG_X86_32
19569+void *module_alloc_exec(unsigned long size)
19570+{
19571+ struct vm_struct *area;
19572+
19573+ if (size == 0)
19574+ return NULL;
19575+
19576+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
19577+ return area ? area->addr : NULL;
19578+}
19579+EXPORT_SYMBOL(module_alloc_exec);
19580+
19581+void module_free_exec(struct module *mod, void *module_region)
19582+{
19583+ vunmap(module_region);
19584+}
19585+EXPORT_SYMBOL(module_free_exec);
19586+#else
19587+void module_free_exec(struct module *mod, void *module_region)
19588+{
19589+ module_free(mod, module_region);
19590+}
19591+EXPORT_SYMBOL(module_free_exec);
19592+
19593+void *module_alloc_exec(unsigned long size)
19594+{
19595+ return __module_alloc(size, PAGE_KERNEL_RX);
19596+}
19597+EXPORT_SYMBOL(module_alloc_exec);
19598+#endif
19599+#endif
19600+
19601 #ifdef CONFIG_X86_32
19602 int apply_relocate(Elf32_Shdr *sechdrs,
19603 const char *strtab,
19604@@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
19605 unsigned int i;
19606 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
19607 Elf32_Sym *sym;
19608- uint32_t *location;
19609+ uint32_t *plocation, location;
19610
19611 DEBUGP("Applying relocate section %u to %u\n",
19612 relsec, sechdrs[relsec].sh_info);
19613 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
19614 /* This is where to make the change */
19615- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
19616- + rel[i].r_offset;
19617+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
19618+ location = (uint32_t)plocation;
19619+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
19620+ plocation = ktla_ktva((void *)plocation);
19621 /* This is the symbol it is referring to. Note that all
19622 undefined symbols have been resolved. */
19623 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
19624@@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
19625 switch (ELF32_R_TYPE(rel[i].r_info)) {
19626 case R_386_32:
19627 /* We add the value into the location given */
19628- *location += sym->st_value;
19629+ pax_open_kernel();
19630+ *plocation += sym->st_value;
19631+ pax_close_kernel();
19632 break;
19633 case R_386_PC32:
19634 /* Add the value, subtract its position */
19635- *location += sym->st_value - (uint32_t)location;
19636+ pax_open_kernel();
19637+ *plocation += sym->st_value - location;
19638+ pax_close_kernel();
19639 break;
19640 default:
19641 pr_err("%s: Unknown relocation: %u\n",
19642@@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
19643 case R_X86_64_NONE:
19644 break;
19645 case R_X86_64_64:
19646+ pax_open_kernel();
19647 *(u64 *)loc = val;
19648+ pax_close_kernel();
19649 break;
19650 case R_X86_64_32:
19651+ pax_open_kernel();
19652 *(u32 *)loc = val;
19653+ pax_close_kernel();
19654 if (val != *(u32 *)loc)
19655 goto overflow;
19656 break;
19657 case R_X86_64_32S:
19658+ pax_open_kernel();
19659 *(s32 *)loc = val;
19660+ pax_close_kernel();
19661 if ((s64)val != *(s32 *)loc)
19662 goto overflow;
19663 break;
19664 case R_X86_64_PC32:
19665 val -= (u64)loc;
19666+ pax_open_kernel();
19667 *(u32 *)loc = val;
19668+ pax_close_kernel();
19669+
19670 #if 0
19671 if ((s64)val != *(s32 *)loc)
19672 goto overflow;
19673diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
19674index f84f5c5..e27e54b 100644
19675--- a/arch/x86/kernel/nmi.c
19676+++ b/arch/x86/kernel/nmi.c
19677@@ -479,6 +479,17 @@ static inline void nmi_nesting_postprocess(void)
19678 dotraplinkage notrace __kprobes void
19679 do_nmi(struct pt_regs *regs, long error_code)
19680 {
19681+
19682+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19683+ if (!user_mode(regs)) {
19684+ unsigned long cs = regs->cs & 0xFFFF;
19685+ unsigned long ip = ktva_ktla(regs->ip);
19686+
19687+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
19688+ regs->ip = ip;
19689+ }
19690+#endif
19691+
19692 nmi_nesting_preprocess(regs);
19693
19694 nmi_enter();
19695diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
19696index 676b8c7..870ba04 100644
19697--- a/arch/x86/kernel/paravirt-spinlocks.c
19698+++ b/arch/x86/kernel/paravirt-spinlocks.c
19699@@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
19700 arch_spin_lock(lock);
19701 }
19702
19703-struct pv_lock_ops pv_lock_ops = {
19704+struct pv_lock_ops pv_lock_ops __read_only = {
19705 #ifdef CONFIG_SMP
19706 .spin_is_locked = __ticket_spin_is_locked,
19707 .spin_is_contended = __ticket_spin_is_contended,
19708diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
19709index 17fff18..0f5f957 100644
19710--- a/arch/x86/kernel/paravirt.c
19711+++ b/arch/x86/kernel/paravirt.c
19712@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
19713 {
19714 return x;
19715 }
19716+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
19717+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
19718+#endif
19719
19720 void __init default_banner(void)
19721 {
19722@@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
19723 if (opfunc == NULL)
19724 /* If there's no function, patch it with a ud2a (BUG) */
19725 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
19726- else if (opfunc == _paravirt_nop)
19727+ else if (opfunc == (void *)_paravirt_nop)
19728 /* If the operation is a nop, then nop the callsite */
19729 ret = paravirt_patch_nop();
19730
19731 /* identity functions just return their single argument */
19732- else if (opfunc == _paravirt_ident_32)
19733+ else if (opfunc == (void *)_paravirt_ident_32)
19734 ret = paravirt_patch_ident_32(insnbuf, len);
19735- else if (opfunc == _paravirt_ident_64)
19736+ else if (opfunc == (void *)_paravirt_ident_64)
19737 ret = paravirt_patch_ident_64(insnbuf, len);
19738+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
19739+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
19740+ ret = paravirt_patch_ident_64(insnbuf, len);
19741+#endif
19742
19743 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
19744 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
19745@@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
19746 if (insn_len > len || start == NULL)
19747 insn_len = len;
19748 else
19749- memcpy(insnbuf, start, insn_len);
19750+ memcpy(insnbuf, ktla_ktva(start), insn_len);
19751
19752 return insn_len;
19753 }
19754@@ -304,7 +311,7 @@ void arch_flush_lazy_mmu_mode(void)
19755 preempt_enable();
19756 }
19757
19758-struct pv_info pv_info = {
19759+struct pv_info pv_info __read_only = {
19760 .name = "bare hardware",
19761 .paravirt_enabled = 0,
19762 .kernel_rpl = 0,
19763@@ -324,7 +331,7 @@ struct pv_time_ops pv_time_ops = {
19764 .steal_clock = native_steal_clock,
19765 };
19766
19767-struct pv_irq_ops pv_irq_ops = {
19768+struct pv_irq_ops pv_irq_ops __read_only = {
19769 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
19770 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
19771 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
19772@@ -401,15 +408,20 @@ struct pv_apic_ops pv_apic_ops = {
19773 #endif
19774 };
19775
19776-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
19777+#ifdef CONFIG_X86_32
19778+#ifdef CONFIG_X86_PAE
19779+/* 64-bit pagetable entries */
19780+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
19781+#else
19782 /* 32-bit pagetable entries */
19783 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
19784+#endif
19785 #else
19786 /* 64-bit pagetable entries */
19787 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
19788 #endif
19789
19790-struct pv_mmu_ops pv_mmu_ops = {
19791+struct pv_mmu_ops pv_mmu_ops __read_only = {
19792
19793 .read_cr2 = native_read_cr2,
19794 .write_cr2 = native_write_cr2,
19795@@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
19796 .make_pud = PTE_IDENT,
19797
19798 .set_pgd = native_set_pgd,
19799+ .set_pgd_batched = native_set_pgd_batched,
19800 #endif
19801 #endif /* PAGETABLE_LEVELS >= 3 */
19802
19803@@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
19804 },
19805
19806 .set_fixmap = native_set_fixmap,
19807+
19808+#ifdef CONFIG_PAX_KERNEXEC
19809+ .pax_open_kernel = native_pax_open_kernel,
19810+ .pax_close_kernel = native_pax_close_kernel,
19811+#endif
19812+
19813 };
19814
19815 EXPORT_SYMBOL_GPL(pv_time_ops);
19816diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
19817index 299d493..79c13dd 100644
19818--- a/arch/x86/kernel/pci-calgary_64.c
19819+++ b/arch/x86/kernel/pci-calgary_64.c
19820@@ -1461,7 +1461,7 @@ int __init detect_calgary(void)
19821 printk(KERN_INFO "PCI-DMA: Calgary TCE table spec is %d\n",
19822 specified_table_size);
19823
19824- x86_init.iommu.iommu_init = calgary_iommu_init;
19825+ *(void **)&x86_init.iommu.iommu_init = calgary_iommu_init;
19826 }
19827 return calgary_found;
19828
19829diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
19830index 35ccf75..7a15747 100644
19831--- a/arch/x86/kernel/pci-iommu_table.c
19832+++ b/arch/x86/kernel/pci-iommu_table.c
19833@@ -2,7 +2,7 @@
19834 #include <asm/iommu_table.h>
19835 #include <linux/string.h>
19836 #include <linux/kallsyms.h>
19837-
19838+#include <linux/sched.h>
19839
19840 #define DEBUG 1
19841
19842diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
19843index b644e1c..4a6d379 100644
19844--- a/arch/x86/kernel/process.c
19845+++ b/arch/x86/kernel/process.c
19846@@ -36,7 +36,8 @@
19847 * section. Since TSS's are completely CPU-local, we want them
19848 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
19849 */
19850-DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
19851+struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
19852+EXPORT_SYMBOL(init_tss);
19853
19854 #ifdef CONFIG_X86_64
19855 static DEFINE_PER_CPU(unsigned char, is_idle);
19856@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
19857 task_xstate_cachep =
19858 kmem_cache_create("task_xstate", xstate_size,
19859 __alignof__(union thread_xstate),
19860- SLAB_PANIC | SLAB_NOTRACK, NULL);
19861+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
19862 }
19863
19864 /*
19865@@ -105,7 +106,7 @@ void exit_thread(void)
19866 unsigned long *bp = t->io_bitmap_ptr;
19867
19868 if (bp) {
19869- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
19870+ struct tss_struct *tss = init_tss + get_cpu();
19871
19872 t->io_bitmap_ptr = NULL;
19873 clear_thread_flag(TIF_IO_BITMAP);
19874@@ -136,7 +137,7 @@ void show_regs_common(void)
19875 board = dmi_get_system_info(DMI_BOARD_NAME);
19876
19877 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s %s %s%s%s\n",
19878- current->pid, current->comm, print_tainted(),
19879+ task_pid_nr(current), current->comm, print_tainted(),
19880 init_utsname()->release,
19881 (int)strcspn(init_utsname()->version, " "),
19882 init_utsname()->version,
19883@@ -149,6 +150,9 @@ void flush_thread(void)
19884 {
19885 struct task_struct *tsk = current;
19886
19887+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
19888+ loadsegment(gs, 0);
19889+#endif
19890 flush_ptrace_hw_breakpoint(tsk);
19891 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
19892 drop_init_fpu(tsk);
19893@@ -336,7 +340,7 @@ static void __exit_idle(void)
19894 void exit_idle(void)
19895 {
19896 /* idle loop has pid 0 */
19897- if (current->pid)
19898+ if (task_pid_nr(current))
19899 return;
19900 __exit_idle();
19901 }
19902@@ -445,7 +449,7 @@ bool set_pm_idle_to_default(void)
19903
19904 return ret;
19905 }
19906-void stop_this_cpu(void *dummy)
19907+__noreturn void stop_this_cpu(void *dummy)
19908 {
19909 local_irq_disable();
19910 /*
19911@@ -673,16 +677,37 @@ static int __init idle_setup(char *str)
19912 }
19913 early_param("idle", idle_setup);
19914
19915-unsigned long arch_align_stack(unsigned long sp)
19916+#ifdef CONFIG_PAX_RANDKSTACK
19917+void pax_randomize_kstack(struct pt_regs *regs)
19918 {
19919- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
19920- sp -= get_random_int() % 8192;
19921- return sp & ~0xf;
19922-}
19923+ struct thread_struct *thread = &current->thread;
19924+ unsigned long time;
19925
19926-unsigned long arch_randomize_brk(struct mm_struct *mm)
19927-{
19928- unsigned long range_end = mm->brk + 0x02000000;
19929- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
19930-}
19931+ if (!randomize_va_space)
19932+ return;
19933+
19934+ if (v8086_mode(regs))
19935+ return;
19936
19937+ rdtscl(time);
19938+
19939+ /* P4 seems to return a 0 LSB, ignore it */
19940+#ifdef CONFIG_MPENTIUM4
19941+ time &= 0x3EUL;
19942+ time <<= 2;
19943+#elif defined(CONFIG_X86_64)
19944+ time &= 0xFUL;
19945+ time <<= 4;
19946+#else
19947+ time &= 0x1FUL;
19948+ time <<= 3;
19949+#endif
19950+
19951+ thread->sp0 ^= time;
19952+ load_sp0(init_tss + smp_processor_id(), thread);
19953+
19954+#ifdef CONFIG_X86_64
19955+ this_cpu_write(kernel_stack, thread->sp0);
19956+#endif
19957+}
19958+#endif
19959diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
19960index 44e0bff..5ceb99c 100644
19961--- a/arch/x86/kernel/process_32.c
19962+++ b/arch/x86/kernel/process_32.c
19963@@ -65,6 +65,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
19964 unsigned long thread_saved_pc(struct task_struct *tsk)
19965 {
19966 return ((unsigned long *)tsk->thread.sp)[3];
19967+//XXX return tsk->thread.eip;
19968 }
19969
19970 void __show_regs(struct pt_regs *regs, int all)
19971@@ -74,21 +75,20 @@ void __show_regs(struct pt_regs *regs, int all)
19972 unsigned long sp;
19973 unsigned short ss, gs;
19974
19975- if (user_mode_vm(regs)) {
19976+ if (user_mode(regs)) {
19977 sp = regs->sp;
19978 ss = regs->ss & 0xffff;
19979- gs = get_user_gs(regs);
19980 } else {
19981 sp = kernel_stack_pointer(regs);
19982 savesegment(ss, ss);
19983- savesegment(gs, gs);
19984 }
19985+ gs = get_user_gs(regs);
19986
19987 show_regs_common();
19988
19989 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
19990 (u16)regs->cs, regs->ip, regs->flags,
19991- smp_processor_id());
19992+ raw_smp_processor_id());
19993 print_symbol("EIP is at %s\n", regs->ip);
19994
19995 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
19996@@ -131,20 +131,21 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
19997 unsigned long arg,
19998 struct task_struct *p, struct pt_regs *regs)
19999 {
20000- struct pt_regs *childregs = task_pt_regs(p);
20001+ struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
20002 struct task_struct *tsk;
20003 int err;
20004
20005 p->thread.sp = (unsigned long) childregs;
20006 p->thread.sp0 = (unsigned long) (childregs+1);
20007+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
20008
20009 if (unlikely(!regs)) {
20010 /* kernel thread */
20011 memset(childregs, 0, sizeof(struct pt_regs));
20012 p->thread.ip = (unsigned long) ret_from_kernel_thread;
20013- task_user_gs(p) = __KERNEL_STACK_CANARY;
20014- childregs->ds = __USER_DS;
20015- childregs->es = __USER_DS;
20016+ savesegment(gs, childregs->gs);
20017+ childregs->ds = __KERNEL_DS;
20018+ childregs->es = __KERNEL_DS;
20019 childregs->fs = __KERNEL_PERCPU;
20020 childregs->bx = sp; /* function */
20021 childregs->bp = arg;
20022@@ -250,7 +251,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
20023 struct thread_struct *prev = &prev_p->thread,
20024 *next = &next_p->thread;
20025 int cpu = smp_processor_id();
20026- struct tss_struct *tss = &per_cpu(init_tss, cpu);
20027+ struct tss_struct *tss = init_tss + cpu;
20028 fpu_switch_t fpu;
20029
20030 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
20031@@ -274,6 +275,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
20032 */
20033 lazy_save_gs(prev->gs);
20034
20035+#ifdef CONFIG_PAX_MEMORY_UDEREF
20036+ __set_fs(task_thread_info(next_p)->addr_limit);
20037+#endif
20038+
20039 /*
20040 * Load the per-thread Thread-Local Storage descriptor.
20041 */
20042@@ -304,6 +309,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
20043 */
20044 arch_end_context_switch(next_p);
20045
20046+ this_cpu_write(current_task, next_p);
20047+ this_cpu_write(current_tinfo, &next_p->tinfo);
20048+
20049 /*
20050 * Restore %gs if needed (which is common)
20051 */
20052@@ -312,8 +320,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
20053
20054 switch_fpu_finish(next_p, fpu);
20055
20056- this_cpu_write(current_task, next_p);
20057-
20058 return prev_p;
20059 }
20060
20061@@ -343,4 +349,3 @@ unsigned long get_wchan(struct task_struct *p)
20062 } while (count++ < 16);
20063 return 0;
20064 }
20065-
20066diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
20067index 16c6365..5d32218 100644
20068--- a/arch/x86/kernel/process_64.c
20069+++ b/arch/x86/kernel/process_64.c
20070@@ -153,10 +153,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
20071 struct pt_regs *childregs;
20072 struct task_struct *me = current;
20073
20074- p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
20075+ p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
20076 childregs = task_pt_regs(p);
20077 p->thread.sp = (unsigned long) childregs;
20078 p->thread.usersp = me->thread.usersp;
20079+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
20080 set_tsk_thread_flag(p, TIF_FORK);
20081 p->fpu_counter = 0;
20082 p->thread.io_bitmap_ptr = NULL;
20083@@ -274,7 +275,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
20084 struct thread_struct *prev = &prev_p->thread;
20085 struct thread_struct *next = &next_p->thread;
20086 int cpu = smp_processor_id();
20087- struct tss_struct *tss = &per_cpu(init_tss, cpu);
20088+ struct tss_struct *tss = init_tss + cpu;
20089 unsigned fsindex, gsindex;
20090 fpu_switch_t fpu;
20091
20092@@ -356,10 +357,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
20093 prev->usersp = this_cpu_read(old_rsp);
20094 this_cpu_write(old_rsp, next->usersp);
20095 this_cpu_write(current_task, next_p);
20096+ this_cpu_write(current_tinfo, &next_p->tinfo);
20097
20098- this_cpu_write(kernel_stack,
20099- (unsigned long)task_stack_page(next_p) +
20100- THREAD_SIZE - KERNEL_STACK_OFFSET);
20101+ this_cpu_write(kernel_stack, next->sp0);
20102
20103 /*
20104 * Now maybe reload the debug registers and handle I/O bitmaps
20105@@ -428,12 +428,11 @@ unsigned long get_wchan(struct task_struct *p)
20106 if (!p || p == current || p->state == TASK_RUNNING)
20107 return 0;
20108 stack = (unsigned long)task_stack_page(p);
20109- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
20110+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
20111 return 0;
20112 fp = *(u64 *)(p->thread.sp);
20113 do {
20114- if (fp < (unsigned long)stack ||
20115- fp >= (unsigned long)stack+THREAD_SIZE)
20116+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
20117 return 0;
20118 ip = *(u64 *)(fp+8);
20119 if (!in_sched_functions(ip))
20120diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
20121index 974b67e..12cb2b5 100644
20122--- a/arch/x86/kernel/ptrace.c
20123+++ b/arch/x86/kernel/ptrace.c
20124@@ -183,14 +183,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
20125 {
20126 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
20127 unsigned long sp = (unsigned long)&regs->sp;
20128- struct thread_info *tinfo;
20129
20130- if (context == (sp & ~(THREAD_SIZE - 1)))
20131+ if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
20132 return sp;
20133
20134- tinfo = (struct thread_info *)context;
20135- if (tinfo->previous_esp)
20136- return tinfo->previous_esp;
20137+ sp = *(unsigned long *)context;
20138+ if (sp)
20139+ return sp;
20140
20141 return (unsigned long)regs;
20142 }
20143@@ -587,7 +586,7 @@ static void ptrace_triggered(struct perf_event *bp,
20144 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
20145 {
20146 int i;
20147- int dr7 = 0;
20148+ unsigned long dr7 = 0;
20149 struct arch_hw_breakpoint *info;
20150
20151 for (i = 0; i < HBP_NUM; i++) {
20152@@ -855,7 +854,7 @@ long arch_ptrace(struct task_struct *child, long request,
20153 unsigned long addr, unsigned long data)
20154 {
20155 int ret;
20156- unsigned long __user *datap = (unsigned long __user *)data;
20157+ unsigned long __user *datap = (__force unsigned long __user *)data;
20158
20159 switch (request) {
20160 /* read the word at location addr in the USER area. */
20161@@ -940,14 +939,14 @@ long arch_ptrace(struct task_struct *child, long request,
20162 if ((int) addr < 0)
20163 return -EIO;
20164 ret = do_get_thread_area(child, addr,
20165- (struct user_desc __user *)data);
20166+ (__force struct user_desc __user *) data);
20167 break;
20168
20169 case PTRACE_SET_THREAD_AREA:
20170 if ((int) addr < 0)
20171 return -EIO;
20172 ret = do_set_thread_area(child, addr,
20173- (struct user_desc __user *)data, 0);
20174+ (__force struct user_desc __user *) data, 0);
20175 break;
20176 #endif
20177
20178@@ -1325,7 +1324,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
20179
20180 #ifdef CONFIG_X86_64
20181
20182-static struct user_regset x86_64_regsets[] __read_mostly = {
20183+static struct user_regset x86_64_regsets[] = {
20184 [REGSET_GENERAL] = {
20185 .core_note_type = NT_PRSTATUS,
20186 .n = sizeof(struct user_regs_struct) / sizeof(long),
20187@@ -1366,7 +1365,7 @@ static const struct user_regset_view user_x86_64_view = {
20188 #endif /* CONFIG_X86_64 */
20189
20190 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
20191-static struct user_regset x86_32_regsets[] __read_mostly = {
20192+static struct user_regset x86_32_regsets[] = {
20193 [REGSET_GENERAL] = {
20194 .core_note_type = NT_PRSTATUS,
20195 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
20196@@ -1419,13 +1418,13 @@ static const struct user_regset_view user_x86_32_view = {
20197 */
20198 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
20199
20200-void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
20201+void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
20202 {
20203 #ifdef CONFIG_X86_64
20204- x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
20205+ *(unsigned int *)&x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
20206 #endif
20207 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
20208- x86_32_regsets[REGSET_XSTATE].n = size / sizeof(u64);
20209+ *(unsigned int *)&x86_32_regsets[REGSET_XSTATE].n = size / sizeof(u64);
20210 #endif
20211 xstate_fx_sw_bytes[USER_XSTATE_XCR0_WORD] = xstate_mask;
20212 }
20213@@ -1454,7 +1453,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
20214 memset(info, 0, sizeof(*info));
20215 info->si_signo = SIGTRAP;
20216 info->si_code = si_code;
20217- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
20218+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
20219 }
20220
20221 void user_single_step_siginfo(struct task_struct *tsk,
20222@@ -1483,6 +1482,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
20223 # define IS_IA32 0
20224 #endif
20225
20226+#ifdef CONFIG_GRKERNSEC_SETXID
20227+extern void gr_delayed_cred_worker(void);
20228+#endif
20229+
20230 /*
20231 * We must return the syscall number to actually look up in the table.
20232 * This can be -1L to skip running any syscall at all.
20233@@ -1493,6 +1496,11 @@ long syscall_trace_enter(struct pt_regs *regs)
20234
20235 rcu_user_exit();
20236
20237+#ifdef CONFIG_GRKERNSEC_SETXID
20238+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
20239+ gr_delayed_cred_worker();
20240+#endif
20241+
20242 /*
20243 * If we stepped into a sysenter/syscall insn, it trapped in
20244 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
20245@@ -1548,6 +1556,11 @@ void syscall_trace_leave(struct pt_regs *regs)
20246 */
20247 rcu_user_exit();
20248
20249+#ifdef CONFIG_GRKERNSEC_SETXID
20250+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
20251+ gr_delayed_cred_worker();
20252+#endif
20253+
20254 audit_syscall_exit(regs);
20255
20256 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
20257diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
20258index 42eb330..139955c 100644
20259--- a/arch/x86/kernel/pvclock.c
20260+++ b/arch/x86/kernel/pvclock.c
20261@@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
20262 return pv_tsc_khz;
20263 }
20264
20265-static atomic64_t last_value = ATOMIC64_INIT(0);
20266+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
20267
20268 void pvclock_resume(void)
20269 {
20270- atomic64_set(&last_value, 0);
20271+ atomic64_set_unchecked(&last_value, 0);
20272 }
20273
20274 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
20275@@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
20276 * updating at the same time, and one of them could be slightly behind,
20277 * making the assumption that last_value always go forward fail to hold.
20278 */
20279- last = atomic64_read(&last_value);
20280+ last = atomic64_read_unchecked(&last_value);
20281 do {
20282 if (ret < last)
20283 return last;
20284- last = atomic64_cmpxchg(&last_value, last, ret);
20285+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
20286 } while (unlikely(last != ret));
20287
20288 return ret;
20289diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
20290index 76fa1e9..a93c759 100644
20291--- a/arch/x86/kernel/reboot.c
20292+++ b/arch/x86/kernel/reboot.c
20293@@ -36,7 +36,7 @@ void (*pm_power_off)(void);
20294 EXPORT_SYMBOL(pm_power_off);
20295
20296 static const struct desc_ptr no_idt = {};
20297-static int reboot_mode;
20298+static unsigned short reboot_mode;
20299 enum reboot_type reboot_type = BOOT_ACPI;
20300 int reboot_force;
20301
20302@@ -157,6 +157,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
20303
20304 void __noreturn machine_real_restart(unsigned int type)
20305 {
20306+
20307+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
20308+ struct desc_struct *gdt;
20309+#endif
20310+
20311 local_irq_disable();
20312
20313 /*
20314@@ -184,7 +189,29 @@ void __noreturn machine_real_restart(unsigned int type)
20315
20316 /* Jump to the identity-mapped low memory code */
20317 #ifdef CONFIG_X86_32
20318- asm volatile("jmpl *%0" : :
20319+
20320+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
20321+ gdt = get_cpu_gdt_table(smp_processor_id());
20322+ pax_open_kernel();
20323+#ifdef CONFIG_PAX_MEMORY_UDEREF
20324+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
20325+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
20326+ loadsegment(ds, __KERNEL_DS);
20327+ loadsegment(es, __KERNEL_DS);
20328+ loadsegment(ss, __KERNEL_DS);
20329+#endif
20330+#ifdef CONFIG_PAX_KERNEXEC
20331+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
20332+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
20333+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
20334+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
20335+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
20336+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
20337+#endif
20338+ pax_close_kernel();
20339+#endif
20340+
20341+ asm volatile("ljmpl *%0" : :
20342 "rm" (real_mode_header->machine_real_restart_asm),
20343 "a" (type));
20344 #else
20345@@ -531,7 +558,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
20346 * try to force a triple fault and then cycle between hitting the keyboard
20347 * controller and doing that
20348 */
20349-static void native_machine_emergency_restart(void)
20350+static void __noreturn native_machine_emergency_restart(void)
20351 {
20352 int i;
20353 int attempt = 0;
20354@@ -654,13 +681,13 @@ void native_machine_shutdown(void)
20355 #endif
20356 }
20357
20358-static void __machine_emergency_restart(int emergency)
20359+static void __noreturn __machine_emergency_restart(int emergency)
20360 {
20361 reboot_emergency = emergency;
20362 machine_ops.emergency_restart();
20363 }
20364
20365-static void native_machine_restart(char *__unused)
20366+static void __noreturn native_machine_restart(char *__unused)
20367 {
20368 pr_notice("machine restart\n");
20369
20370@@ -669,7 +696,7 @@ static void native_machine_restart(char *__unused)
20371 __machine_emergency_restart(0);
20372 }
20373
20374-static void native_machine_halt(void)
20375+static void __noreturn native_machine_halt(void)
20376 {
20377 /* Stop other cpus and apics */
20378 machine_shutdown();
20379@@ -679,7 +706,7 @@ static void native_machine_halt(void)
20380 stop_this_cpu(NULL);
20381 }
20382
20383-static void native_machine_power_off(void)
20384+static void __noreturn native_machine_power_off(void)
20385 {
20386 if (pm_power_off) {
20387 if (!reboot_force)
20388@@ -688,6 +715,7 @@ static void native_machine_power_off(void)
20389 }
20390 /* A fallback in case there is no PM info available */
20391 tboot_shutdown(TB_SHUTDOWN_HALT);
20392+ unreachable();
20393 }
20394
20395 struct machine_ops machine_ops = {
20396diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
20397index 7a6f3b3..bed145d7 100644
20398--- a/arch/x86/kernel/relocate_kernel_64.S
20399+++ b/arch/x86/kernel/relocate_kernel_64.S
20400@@ -11,6 +11,7 @@
20401 #include <asm/kexec.h>
20402 #include <asm/processor-flags.h>
20403 #include <asm/pgtable_types.h>
20404+#include <asm/alternative-asm.h>
20405
20406 /*
20407 * Must be relocatable PIC code callable as a C function
20408@@ -160,13 +161,14 @@ identity_mapped:
20409 xorq %rbp, %rbp
20410 xorq %r8, %r8
20411 xorq %r9, %r9
20412- xorq %r10, %r9
20413+ xorq %r10, %r10
20414 xorq %r11, %r11
20415 xorq %r12, %r12
20416 xorq %r13, %r13
20417 xorq %r14, %r14
20418 xorq %r15, %r15
20419
20420+ pax_force_retaddr 0, 1
20421 ret
20422
20423 1:
20424diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
20425index aeacb0e..f9d4c02 100644
20426--- a/arch/x86/kernel/setup.c
20427+++ b/arch/x86/kernel/setup.c
20428@@ -441,7 +441,7 @@ static void __init parse_setup_data(void)
20429
20430 switch (data->type) {
20431 case SETUP_E820_EXT:
20432- parse_e820_ext(data);
20433+ parse_e820_ext((struct setup_data __force_kernel *)data);
20434 break;
20435 case SETUP_DTB:
20436 add_dtb(pa_data);
20437@@ -710,7 +710,7 @@ static void __init trim_bios_range(void)
20438 * area (640->1Mb) as ram even though it is not.
20439 * take them out.
20440 */
20441- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
20442+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
20443
20444 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
20445 }
20446@@ -834,14 +834,14 @@ void __init setup_arch(char **cmdline_p)
20447
20448 if (!boot_params.hdr.root_flags)
20449 root_mountflags &= ~MS_RDONLY;
20450- init_mm.start_code = (unsigned long) _text;
20451- init_mm.end_code = (unsigned long) _etext;
20452+ init_mm.start_code = ktla_ktva((unsigned long) _text);
20453+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
20454 init_mm.end_data = (unsigned long) _edata;
20455 init_mm.brk = _brk_end;
20456
20457- code_resource.start = virt_to_phys(_text);
20458- code_resource.end = virt_to_phys(_etext)-1;
20459- data_resource.start = virt_to_phys(_etext);
20460+ code_resource.start = virt_to_phys(ktla_ktva(_text));
20461+ code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
20462+ data_resource.start = virt_to_phys(_sdata);
20463 data_resource.end = virt_to_phys(_edata)-1;
20464 bss_resource.start = virt_to_phys(&__bss_start);
20465 bss_resource.end = virt_to_phys(&__bss_stop)-1;
20466diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
20467index 5cdff03..5810740 100644
20468--- a/arch/x86/kernel/setup_percpu.c
20469+++ b/arch/x86/kernel/setup_percpu.c
20470@@ -21,19 +21,17 @@
20471 #include <asm/cpu.h>
20472 #include <asm/stackprotector.h>
20473
20474-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
20475+#ifdef CONFIG_SMP
20476+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
20477 EXPORT_PER_CPU_SYMBOL(cpu_number);
20478+#endif
20479
20480-#ifdef CONFIG_X86_64
20481 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
20482-#else
20483-#define BOOT_PERCPU_OFFSET 0
20484-#endif
20485
20486 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
20487 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
20488
20489-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
20490+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
20491 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
20492 };
20493 EXPORT_SYMBOL(__per_cpu_offset);
20494@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
20495 {
20496 #ifdef CONFIG_X86_32
20497 struct desc_struct gdt;
20498+ unsigned long base = per_cpu_offset(cpu);
20499
20500- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
20501- 0x2 | DESCTYPE_S, 0x8);
20502- gdt.s = 1;
20503+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
20504+ 0x83 | DESCTYPE_S, 0xC);
20505 write_gdt_entry(get_cpu_gdt_table(cpu),
20506 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
20507 #endif
20508@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
20509 /* alrighty, percpu areas up and running */
20510 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
20511 for_each_possible_cpu(cpu) {
20512+#ifdef CONFIG_CC_STACKPROTECTOR
20513+#ifdef CONFIG_X86_32
20514+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
20515+#endif
20516+#endif
20517 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
20518 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
20519 per_cpu(cpu_number, cpu) = cpu;
20520@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
20521 */
20522 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
20523 #endif
20524+#ifdef CONFIG_CC_STACKPROTECTOR
20525+#ifdef CONFIG_X86_32
20526+ if (!cpu)
20527+ per_cpu(stack_canary.canary, cpu) = canary;
20528+#endif
20529+#endif
20530 /*
20531 * Up to this point, the boot CPU has been using .init.data
20532 * area. Reload any changed state for the boot CPU.
20533diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
20534index 70b27ee..fcf827f 100644
20535--- a/arch/x86/kernel/signal.c
20536+++ b/arch/x86/kernel/signal.c
20537@@ -195,7 +195,7 @@ static unsigned long align_sigframe(unsigned long sp)
20538 * Align the stack pointer according to the i386 ABI,
20539 * i.e. so that on function entry ((sp + 4) & 15) == 0.
20540 */
20541- sp = ((sp + 4) & -16ul) - 4;
20542+ sp = ((sp - 12) & -16ul) - 4;
20543 #else /* !CONFIG_X86_32 */
20544 sp = round_down(sp, 16) - 8;
20545 #endif
20546@@ -303,9 +303,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
20547 }
20548
20549 if (current->mm->context.vdso)
20550- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
20551+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
20552 else
20553- restorer = &frame->retcode;
20554+ restorer = (void __user *)&frame->retcode;
20555 if (ka->sa.sa_flags & SA_RESTORER)
20556 restorer = ka->sa.sa_restorer;
20557
20558@@ -319,7 +319,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
20559 * reasons and because gdb uses it as a signature to notice
20560 * signal handler stack frames.
20561 */
20562- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
20563+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
20564
20565 if (err)
20566 return -EFAULT;
20567@@ -369,7 +369,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
20568 put_user_ex(current->sas_ss_size, &frame->uc.uc_stack.ss_size);
20569
20570 /* Set up to return from userspace. */
20571- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
20572+ if (current->mm->context.vdso)
20573+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
20574+ else
20575+ restorer = (void __user *)&frame->retcode;
20576 if (ka->sa.sa_flags & SA_RESTORER)
20577 restorer = ka->sa.sa_restorer;
20578 put_user_ex(restorer, &frame->pretcode);
20579@@ -381,7 +384,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
20580 * reasons and because gdb uses it as a signature to notice
20581 * signal handler stack frames.
20582 */
20583- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
20584+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
20585 } put_user_catch(err);
20586
20587 err |= copy_siginfo_to_user(&frame->info, info);
20588diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
20589index f3e2ec8..ad5287a 100644
20590--- a/arch/x86/kernel/smpboot.c
20591+++ b/arch/x86/kernel/smpboot.c
20592@@ -673,6 +673,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
20593 idle->thread.sp = (unsigned long) (((struct pt_regs *)
20594 (THREAD_SIZE + task_stack_page(idle))) - 1);
20595 per_cpu(current_task, cpu) = idle;
20596+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
20597
20598 #ifdef CONFIG_X86_32
20599 /* Stack for startup_32 can be just as for start_secondary onwards */
20600@@ -680,11 +681,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
20601 #else
20602 clear_tsk_thread_flag(idle, TIF_FORK);
20603 initial_gs = per_cpu_offset(cpu);
20604- per_cpu(kernel_stack, cpu) =
20605- (unsigned long)task_stack_page(idle) -
20606- KERNEL_STACK_OFFSET + THREAD_SIZE;
20607+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
20608 #endif
20609+
20610+ pax_open_kernel();
20611 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
20612+ pax_close_kernel();
20613+
20614 initial_code = (unsigned long)start_secondary;
20615 stack_start = idle->thread.sp;
20616
20617@@ -823,6 +826,15 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
20618 /* the FPU context is blank, nobody can own it */
20619 __cpu_disable_lazy_restore(cpu);
20620
20621+#ifdef CONFIG_PAX_PER_CPU_PGD
20622+ clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
20623+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
20624+ KERNEL_PGD_PTRS);
20625+#endif
20626+
20627+ /* the FPU context is blank, nobody can own it */
20628+ __cpu_disable_lazy_restore(cpu);
20629+
20630 err = do_boot_cpu(apicid, cpu, tidle);
20631 if (err) {
20632 pr_debug("do_boot_cpu failed %d\n", err);
20633diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
20634index 9b4d51d..5d28b58 100644
20635--- a/arch/x86/kernel/step.c
20636+++ b/arch/x86/kernel/step.c
20637@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
20638 struct desc_struct *desc;
20639 unsigned long base;
20640
20641- seg &= ~7UL;
20642+ seg >>= 3;
20643
20644 mutex_lock(&child->mm->context.lock);
20645- if (unlikely((seg >> 3) >= child->mm->context.size))
20646+ if (unlikely(seg >= child->mm->context.size))
20647 addr = -1L; /* bogus selector, access would fault */
20648 else {
20649 desc = child->mm->context.ldt + seg;
20650@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
20651 addr += base;
20652 }
20653 mutex_unlock(&child->mm->context.lock);
20654- }
20655+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
20656+ addr = ktla_ktva(addr);
20657
20658 return addr;
20659 }
20660@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
20661 unsigned char opcode[15];
20662 unsigned long addr = convert_ip_to_linear(child, regs);
20663
20664+ if (addr == -EINVAL)
20665+ return 0;
20666+
20667 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
20668 for (i = 0; i < copied; i++) {
20669 switch (opcode[i]) {
20670diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
20671new file mode 100644
20672index 0000000..26bb1af
20673--- /dev/null
20674+++ b/arch/x86/kernel/sys_i386_32.c
20675@@ -0,0 +1,249 @@
20676+/*
20677+ * This file contains various random system calls that
20678+ * have a non-standard calling sequence on the Linux/i386
20679+ * platform.
20680+ */
20681+
20682+#include <linux/errno.h>
20683+#include <linux/sched.h>
20684+#include <linux/mm.h>
20685+#include <linux/fs.h>
20686+#include <linux/smp.h>
20687+#include <linux/sem.h>
20688+#include <linux/msg.h>
20689+#include <linux/shm.h>
20690+#include <linux/stat.h>
20691+#include <linux/syscalls.h>
20692+#include <linux/mman.h>
20693+#include <linux/file.h>
20694+#include <linux/utsname.h>
20695+#include <linux/ipc.h>
20696+
20697+#include <linux/uaccess.h>
20698+#include <linux/unistd.h>
20699+
20700+#include <asm/syscalls.h>
20701+
20702+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
20703+{
20704+ unsigned long pax_task_size = TASK_SIZE;
20705+
20706+#ifdef CONFIG_PAX_SEGMEXEC
20707+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
20708+ pax_task_size = SEGMEXEC_TASK_SIZE;
20709+#endif
20710+
20711+ if (len > pax_task_size || addr > pax_task_size - len)
20712+ return -EINVAL;
20713+
20714+ return 0;
20715+}
20716+
20717+unsigned long
20718+arch_get_unmapped_area(struct file *filp, unsigned long addr,
20719+ unsigned long len, unsigned long pgoff, unsigned long flags)
20720+{
20721+ struct mm_struct *mm = current->mm;
20722+ struct vm_area_struct *vma;
20723+ unsigned long start_addr, pax_task_size = TASK_SIZE;
20724+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
20725+
20726+#ifdef CONFIG_PAX_SEGMEXEC
20727+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
20728+ pax_task_size = SEGMEXEC_TASK_SIZE;
20729+#endif
20730+
20731+ pax_task_size -= PAGE_SIZE;
20732+
20733+ if (len > pax_task_size)
20734+ return -ENOMEM;
20735+
20736+ if (flags & MAP_FIXED)
20737+ return addr;
20738+
20739+#ifdef CONFIG_PAX_RANDMMAP
20740+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
20741+#endif
20742+
20743+ if (addr) {
20744+ addr = PAGE_ALIGN(addr);
20745+ if (pax_task_size - len >= addr) {
20746+ vma = find_vma(mm, addr);
20747+ if (check_heap_stack_gap(vma, addr, len, offset))
20748+ return addr;
20749+ }
20750+ }
20751+ if (len > mm->cached_hole_size) {
20752+ start_addr = addr = mm->free_area_cache;
20753+ } else {
20754+ start_addr = addr = mm->mmap_base;
20755+ mm->cached_hole_size = 0;
20756+ }
20757+
20758+#ifdef CONFIG_PAX_PAGEEXEC
20759+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
20760+ start_addr = 0x00110000UL;
20761+
20762+#ifdef CONFIG_PAX_RANDMMAP
20763+ if (mm->pax_flags & MF_PAX_RANDMMAP)
20764+ start_addr += mm->delta_mmap & 0x03FFF000UL;
20765+#endif
20766+
20767+ if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
20768+ start_addr = addr = mm->mmap_base;
20769+ else
20770+ addr = start_addr;
20771+ }
20772+#endif
20773+
20774+full_search:
20775+ for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
20776+ /* At this point: (!vma || addr < vma->vm_end). */
20777+ if (pax_task_size - len < addr) {
20778+ /*
20779+ * Start a new search - just in case we missed
20780+ * some holes.
20781+ */
20782+ if (start_addr != mm->mmap_base) {
20783+ start_addr = addr = mm->mmap_base;
20784+ mm->cached_hole_size = 0;
20785+ goto full_search;
20786+ }
20787+ return -ENOMEM;
20788+ }
20789+ if (check_heap_stack_gap(vma, addr, len, offset))
20790+ break;
20791+ if (addr + mm->cached_hole_size < vma->vm_start)
20792+ mm->cached_hole_size = vma->vm_start - addr;
20793+ addr = vma->vm_end;
20794+ if (mm->start_brk <= addr && addr < mm->mmap_base) {
20795+ start_addr = addr = mm->mmap_base;
20796+ mm->cached_hole_size = 0;
20797+ goto full_search;
20798+ }
20799+ }
20800+
20801+ /*
20802+ * Remember the place where we stopped the search:
20803+ */
20804+ mm->free_area_cache = addr + len;
20805+ return addr;
20806+}
20807+
20808+unsigned long
20809+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
20810+ const unsigned long len, const unsigned long pgoff,
20811+ const unsigned long flags)
20812+{
20813+ struct vm_area_struct *vma;
20814+ struct mm_struct *mm = current->mm;
20815+ unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
20816+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
20817+
20818+#ifdef CONFIG_PAX_SEGMEXEC
20819+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
20820+ pax_task_size = SEGMEXEC_TASK_SIZE;
20821+#endif
20822+
20823+ pax_task_size -= PAGE_SIZE;
20824+
20825+ /* requested length too big for entire address space */
20826+ if (len > pax_task_size)
20827+ return -ENOMEM;
20828+
20829+ if (flags & MAP_FIXED)
20830+ return addr;
20831+
20832+#ifdef CONFIG_PAX_PAGEEXEC
20833+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
20834+ goto bottomup;
20835+#endif
20836+
20837+#ifdef CONFIG_PAX_RANDMMAP
20838+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
20839+#endif
20840+
20841+ /* requesting a specific address */
20842+ if (addr) {
20843+ addr = PAGE_ALIGN(addr);
20844+ if (pax_task_size - len >= addr) {
20845+ vma = find_vma(mm, addr);
20846+ if (check_heap_stack_gap(vma, addr, len, offset))
20847+ return addr;
20848+ }
20849+ }
20850+
20851+ /* check if free_area_cache is useful for us */
20852+ if (len <= mm->cached_hole_size) {
20853+ mm->cached_hole_size = 0;
20854+ mm->free_area_cache = mm->mmap_base;
20855+ }
20856+
20857+ /* either no address requested or can't fit in requested address hole */
20858+ addr = mm->free_area_cache;
20859+
20860+ /* make sure it can fit in the remaining address space */
20861+ if (addr > len) {
20862+ vma = find_vma(mm, addr-len);
20863+ if (check_heap_stack_gap(vma, addr - len, len, offset))
20864+ /* remember the address as a hint for next time */
20865+ return (mm->free_area_cache = addr-len);
20866+ }
20867+
20868+ if (mm->mmap_base < len)
20869+ goto bottomup;
20870+
20871+ addr = mm->mmap_base-len;
20872+
20873+ do {
20874+ /*
20875+ * Lookup failure means no vma is above this address,
20876+ * else if new region fits below vma->vm_start,
20877+ * return with success:
20878+ */
20879+ vma = find_vma(mm, addr);
20880+ if (check_heap_stack_gap(vma, addr, len, offset))
20881+ /* remember the address as a hint for next time */
20882+ return (mm->free_area_cache = addr);
20883+
20884+ /* remember the largest hole we saw so far */
20885+ if (addr + mm->cached_hole_size < vma->vm_start)
20886+ mm->cached_hole_size = vma->vm_start - addr;
20887+
20888+ /* try just below the current vma->vm_start */
20889+ addr = skip_heap_stack_gap(vma, len, offset);
20890+ } while (!IS_ERR_VALUE(addr));
20891+
20892+bottomup:
20893+ /*
20894+ * A failed mmap() very likely causes application failure,
20895+ * so fall back to the bottom-up function here. This scenario
20896+ * can happen with large stack limits and large mmap()
20897+ * allocations.
20898+ */
20899+
20900+#ifdef CONFIG_PAX_SEGMEXEC
20901+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
20902+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
20903+ else
20904+#endif
20905+
20906+ mm->mmap_base = TASK_UNMAPPED_BASE;
20907+
20908+#ifdef CONFIG_PAX_RANDMMAP
20909+ if (mm->pax_flags & MF_PAX_RANDMMAP)
20910+ mm->mmap_base += mm->delta_mmap;
20911+#endif
20912+
20913+ mm->free_area_cache = mm->mmap_base;
20914+ mm->cached_hole_size = ~0UL;
20915+ addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
20916+ /*
20917+ * Restore the topdown base:
20918+ */
20919+ mm->mmap_base = base;
20920+ mm->free_area_cache = base;
20921+ mm->cached_hole_size = ~0UL;
20922+
20923+ return addr;
20924+}
20925diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
20926index b4d3c39..d699d77 100644
20927--- a/arch/x86/kernel/sys_x86_64.c
20928+++ b/arch/x86/kernel/sys_x86_64.c
20929@@ -95,8 +95,8 @@ out:
20930 return error;
20931 }
20932
20933-static void find_start_end(unsigned long flags, unsigned long *begin,
20934- unsigned long *end)
20935+static void find_start_end(struct mm_struct *mm, unsigned long flags,
20936+ unsigned long *begin, unsigned long *end)
20937 {
20938 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
20939 unsigned long new_begin;
20940@@ -115,7 +115,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
20941 *begin = new_begin;
20942 }
20943 } else {
20944- *begin = TASK_UNMAPPED_BASE;
20945+ *begin = mm->mmap_base;
20946 *end = TASK_SIZE;
20947 }
20948 }
20949@@ -128,20 +128,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
20950 struct vm_area_struct *vma;
20951 unsigned long start_addr;
20952 unsigned long begin, end;
20953+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
20954
20955 if (flags & MAP_FIXED)
20956 return addr;
20957
20958- find_start_end(flags, &begin, &end);
20959+ find_start_end(mm, flags, &begin, &end);
20960
20961 if (len > end)
20962 return -ENOMEM;
20963
20964+#ifdef CONFIG_PAX_RANDMMAP
20965+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
20966+#endif
20967+
20968 if (addr) {
20969 addr = PAGE_ALIGN(addr);
20970 vma = find_vma(mm, addr);
20971- if (end - len >= addr &&
20972- (!vma || addr + len <= vma->vm_start))
20973+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
20974 return addr;
20975 }
20976 if (((flags & MAP_32BIT) || test_thread_flag(TIF_ADDR32))
20977@@ -172,7 +176,7 @@ full_search:
20978 }
20979 return -ENOMEM;
20980 }
20981- if (!vma || addr + len <= vma->vm_start) {
20982+ if (check_heap_stack_gap(vma, addr, len, offset)) {
20983 /*
20984 * Remember the place where we stopped the search:
20985 */
20986@@ -195,7 +199,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
20987 {
20988 struct vm_area_struct *vma;
20989 struct mm_struct *mm = current->mm;
20990- unsigned long addr = addr0, start_addr;
20991+ unsigned long base = mm->mmap_base, addr = addr0, start_addr;
20992+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
20993
20994 /* requested length too big for entire address space */
20995 if (len > TASK_SIZE)
20996@@ -208,13 +213,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
20997 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
20998 goto bottomup;
20999
21000+#ifdef CONFIG_PAX_RANDMMAP
21001+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
21002+#endif
21003+
21004 /* requesting a specific address */
21005 if (addr) {
21006 addr = PAGE_ALIGN(addr);
21007- vma = find_vma(mm, addr);
21008- if (TASK_SIZE - len >= addr &&
21009- (!vma || addr + len <= vma->vm_start))
21010- return addr;
21011+ if (TASK_SIZE - len >= addr) {
21012+ vma = find_vma(mm, addr);
21013+ if (check_heap_stack_gap(vma, addr, len, offset))
21014+ return addr;
21015+ }
21016 }
21017
21018 /* check if free_area_cache is useful for us */
21019@@ -240,7 +250,7 @@ try_again:
21020 * return with success:
21021 */
21022 vma = find_vma(mm, addr);
21023- if (!vma || addr+len <= vma->vm_start)
21024+ if (check_heap_stack_gap(vma, addr, len, offset))
21025 /* remember the address as a hint for next time */
21026 return mm->free_area_cache = addr;
21027
21028@@ -249,8 +259,8 @@ try_again:
21029 mm->cached_hole_size = vma->vm_start - addr;
21030
21031 /* try just below the current vma->vm_start */
21032- addr = vma->vm_start-len;
21033- } while (len < vma->vm_start);
21034+ addr = skip_heap_stack_gap(vma, len, offset);
21035+ } while (!IS_ERR_VALUE(addr));
21036
21037 fail:
21038 /*
21039@@ -270,13 +280,21 @@ bottomup:
21040 * can happen with large stack limits and large mmap()
21041 * allocations.
21042 */
21043+ mm->mmap_base = TASK_UNMAPPED_BASE;
21044+
21045+#ifdef CONFIG_PAX_RANDMMAP
21046+ if (mm->pax_flags & MF_PAX_RANDMMAP)
21047+ mm->mmap_base += mm->delta_mmap;
21048+#endif
21049+
21050+ mm->free_area_cache = mm->mmap_base;
21051 mm->cached_hole_size = ~0UL;
21052- mm->free_area_cache = TASK_UNMAPPED_BASE;
21053 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
21054 /*
21055 * Restore the topdown base:
21056 */
21057- mm->free_area_cache = mm->mmap_base;
21058+ mm->mmap_base = base;
21059+ mm->free_area_cache = base;
21060 mm->cached_hole_size = ~0UL;
21061
21062 return addr;
21063diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
21064index f84fe00..93fe08f 100644
21065--- a/arch/x86/kernel/tboot.c
21066+++ b/arch/x86/kernel/tboot.c
21067@@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
21068
21069 void tboot_shutdown(u32 shutdown_type)
21070 {
21071- void (*shutdown)(void);
21072+ void (* __noreturn shutdown)(void);
21073
21074 if (!tboot_enabled())
21075 return;
21076@@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
21077
21078 switch_to_tboot_pt();
21079
21080- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
21081+ shutdown = (void *)tboot->shutdown_entry;
21082 shutdown();
21083
21084 /* should not reach here */
21085@@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
21086 return 0;
21087 }
21088
21089-static atomic_t ap_wfs_count;
21090+static atomic_unchecked_t ap_wfs_count;
21091
21092 static int tboot_wait_for_aps(int num_aps)
21093 {
21094@@ -324,9 +324,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
21095 {
21096 switch (action) {
21097 case CPU_DYING:
21098- atomic_inc(&ap_wfs_count);
21099+ atomic_inc_unchecked(&ap_wfs_count);
21100 if (num_online_cpus() == 1)
21101- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
21102+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
21103 return NOTIFY_BAD;
21104 break;
21105 }
21106@@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
21107
21108 tboot_create_trampoline();
21109
21110- atomic_set(&ap_wfs_count, 0);
21111+ atomic_set_unchecked(&ap_wfs_count, 0);
21112 register_hotcpu_notifier(&tboot_cpu_notifier);
21113
21114 acpi_os_set_prepare_sleep(&tboot_sleep);
21115diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
21116index 24d3c91..d06b473 100644
21117--- a/arch/x86/kernel/time.c
21118+++ b/arch/x86/kernel/time.c
21119@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
21120 {
21121 unsigned long pc = instruction_pointer(regs);
21122
21123- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
21124+ if (!user_mode(regs) && in_lock_functions(pc)) {
21125 #ifdef CONFIG_FRAME_POINTER
21126- return *(unsigned long *)(regs->bp + sizeof(long));
21127+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
21128 #else
21129 unsigned long *sp =
21130 (unsigned long *)kernel_stack_pointer(regs);
21131@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
21132 * or above a saved flags. Eflags has bits 22-31 zero,
21133 * kernel addresses don't.
21134 */
21135+
21136+#ifdef CONFIG_PAX_KERNEXEC
21137+ return ktla_ktva(sp[0]);
21138+#else
21139 if (sp[0] >> 22)
21140 return sp[0];
21141 if (sp[1] >> 22)
21142 return sp[1];
21143 #endif
21144+
21145+#endif
21146 }
21147 return pc;
21148 }
21149diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
21150index 9d9d2f9..cad418a 100644
21151--- a/arch/x86/kernel/tls.c
21152+++ b/arch/x86/kernel/tls.c
21153@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
21154 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
21155 return -EINVAL;
21156
21157+#ifdef CONFIG_PAX_SEGMEXEC
21158+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
21159+ return -EINVAL;
21160+#endif
21161+
21162 set_tls_desc(p, idx, &info, 1);
21163
21164 return 0;
21165@@ -204,7 +209,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
21166
21167 if (kbuf)
21168 info = kbuf;
21169- else if (__copy_from_user(infobuf, ubuf, count))
21170+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
21171 return -EFAULT;
21172 else
21173 info = infobuf;
21174diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
21175index 8276dc6..4ca48a2 100644
21176--- a/arch/x86/kernel/traps.c
21177+++ b/arch/x86/kernel/traps.c
21178@@ -71,12 +71,6 @@ asmlinkage int system_call(void);
21179
21180 /* Do we ignore FPU interrupts ? */
21181 char ignore_fpu_irq;
21182-
21183-/*
21184- * The IDT has to be page-aligned to simplify the Pentium
21185- * F0 0F bug workaround.
21186- */
21187-gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
21188 #endif
21189
21190 DECLARE_BITMAP(used_vectors, NR_VECTORS);
21191@@ -109,11 +103,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
21192 }
21193
21194 static int __kprobes
21195-do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
21196+do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
21197 struct pt_regs *regs, long error_code)
21198 {
21199 #ifdef CONFIG_X86_32
21200- if (regs->flags & X86_VM_MASK) {
21201+ if (v8086_mode(regs)) {
21202 /*
21203 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
21204 * On nmi (interrupt 2), do_trap should not be called.
21205@@ -126,12 +120,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
21206 return -1;
21207 }
21208 #endif
21209- if (!user_mode(regs)) {
21210+ if (!user_mode_novm(regs)) {
21211 if (!fixup_exception(regs)) {
21212 tsk->thread.error_code = error_code;
21213 tsk->thread.trap_nr = trapnr;
21214+
21215+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21216+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
21217+ str = "PAX: suspicious stack segment fault";
21218+#endif
21219+
21220 die(str, regs, error_code);
21221 }
21222+
21223+#ifdef CONFIG_PAX_REFCOUNT
21224+ if (trapnr == 4)
21225+ pax_report_refcount_overflow(regs);
21226+#endif
21227+
21228 return 0;
21229 }
21230
21231@@ -139,7 +145,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
21232 }
21233
21234 static void __kprobes
21235-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
21236+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
21237 long error_code, siginfo_t *info)
21238 {
21239 struct task_struct *tsk = current;
21240@@ -163,7 +169,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
21241 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
21242 printk_ratelimit()) {
21243 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
21244- tsk->comm, tsk->pid, str,
21245+ tsk->comm, task_pid_nr(tsk), str,
21246 regs->ip, regs->sp, error_code);
21247 print_vma_addr(" in ", regs->ip);
21248 pr_cont("\n");
21249@@ -269,7 +275,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
21250 conditional_sti(regs);
21251
21252 #ifdef CONFIG_X86_32
21253- if (regs->flags & X86_VM_MASK) {
21254+ if (v8086_mode(regs)) {
21255 local_irq_enable();
21256 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
21257 goto exit;
21258@@ -277,18 +283,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
21259 #endif
21260
21261 tsk = current;
21262- if (!user_mode(regs)) {
21263+ if (!user_mode_novm(regs)) {
21264 if (fixup_exception(regs))
21265 goto exit;
21266
21267 tsk->thread.error_code = error_code;
21268 tsk->thread.trap_nr = X86_TRAP_GP;
21269 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
21270- X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
21271+ X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
21272+
21273+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21274+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
21275+ die("PAX: suspicious general protection fault", regs, error_code);
21276+ else
21277+#endif
21278+
21279 die("general protection fault", regs, error_code);
21280+ }
21281 goto exit;
21282 }
21283
21284+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
21285+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
21286+ struct mm_struct *mm = tsk->mm;
21287+ unsigned long limit;
21288+
21289+ down_write(&mm->mmap_sem);
21290+ limit = mm->context.user_cs_limit;
21291+ if (limit < TASK_SIZE) {
21292+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
21293+ up_write(&mm->mmap_sem);
21294+ return;
21295+ }
21296+ up_write(&mm->mmap_sem);
21297+ }
21298+#endif
21299+
21300 tsk->thread.error_code = error_code;
21301 tsk->thread.trap_nr = X86_TRAP_GP;
21302
21303@@ -443,7 +473,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
21304 /* It's safe to allow irq's after DR6 has been saved */
21305 preempt_conditional_sti(regs);
21306
21307- if (regs->flags & X86_VM_MASK) {
21308+ if (v8086_mode(regs)) {
21309 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
21310 X86_TRAP_DB);
21311 preempt_conditional_cli(regs);
21312@@ -458,7 +488,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
21313 * We already checked v86 mode above, so we can check for kernel mode
21314 * by just checking the CPL of CS.
21315 */
21316- if ((dr6 & DR_STEP) && !user_mode(regs)) {
21317+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
21318 tsk->thread.debugreg6 &= ~DR_STEP;
21319 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
21320 regs->flags &= ~X86_EFLAGS_TF;
21321@@ -490,7 +520,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
21322 return;
21323 conditional_sti(regs);
21324
21325- if (!user_mode_vm(regs))
21326+ if (!user_mode(regs))
21327 {
21328 if (!fixup_exception(regs)) {
21329 task->thread.error_code = error_code;
21330diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
21331index aafa555..a04691a 100644
21332--- a/arch/x86/kernel/uprobes.c
21333+++ b/arch/x86/kernel/uprobes.c
21334@@ -614,7 +614,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
21335 int ret = NOTIFY_DONE;
21336
21337 /* We are only interested in userspace traps */
21338- if (regs && !user_mode_vm(regs))
21339+ if (regs && !user_mode(regs))
21340 return NOTIFY_DONE;
21341
21342 switch (val) {
21343diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
21344index b9242ba..50c5edd 100644
21345--- a/arch/x86/kernel/verify_cpu.S
21346+++ b/arch/x86/kernel/verify_cpu.S
21347@@ -20,6 +20,7 @@
21348 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
21349 * arch/x86/kernel/trampoline_64.S: secondary processor verification
21350 * arch/x86/kernel/head_32.S: processor startup
21351+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
21352 *
21353 * verify_cpu, returns the status of longmode and SSE in register %eax.
21354 * 0: Success 1: Failure
21355diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
21356index 5c9687b..5f857d3 100644
21357--- a/arch/x86/kernel/vm86_32.c
21358+++ b/arch/x86/kernel/vm86_32.c
21359@@ -43,6 +43,7 @@
21360 #include <linux/ptrace.h>
21361 #include <linux/audit.h>
21362 #include <linux/stddef.h>
21363+#include <linux/grsecurity.h>
21364
21365 #include <asm/uaccess.h>
21366 #include <asm/io.h>
21367@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
21368 do_exit(SIGSEGV);
21369 }
21370
21371- tss = &per_cpu(init_tss, get_cpu());
21372+ tss = init_tss + get_cpu();
21373 current->thread.sp0 = current->thread.saved_sp0;
21374 current->thread.sysenter_cs = __KERNEL_CS;
21375 load_sp0(tss, &current->thread);
21376@@ -212,6 +213,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
21377 struct task_struct *tsk;
21378 int tmp, ret = -EPERM;
21379
21380+#ifdef CONFIG_GRKERNSEC_VM86
21381+ if (!capable(CAP_SYS_RAWIO)) {
21382+ gr_handle_vm86();
21383+ goto out;
21384+ }
21385+#endif
21386+
21387 tsk = current;
21388 if (tsk->thread.saved_sp0)
21389 goto out;
21390@@ -242,6 +250,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
21391 int tmp, ret;
21392 struct vm86plus_struct __user *v86;
21393
21394+#ifdef CONFIG_GRKERNSEC_VM86
21395+ if (!capable(CAP_SYS_RAWIO)) {
21396+ gr_handle_vm86();
21397+ ret = -EPERM;
21398+ goto out;
21399+ }
21400+#endif
21401+
21402 tsk = current;
21403 switch (cmd) {
21404 case VM86_REQUEST_IRQ:
21405@@ -328,7 +344,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
21406 tsk->thread.saved_fs = info->regs32->fs;
21407 tsk->thread.saved_gs = get_user_gs(info->regs32);
21408
21409- tss = &per_cpu(init_tss, get_cpu());
21410+ tss = init_tss + get_cpu();
21411 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
21412 if (cpu_has_sep)
21413 tsk->thread.sysenter_cs = 0;
21414@@ -535,7 +551,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
21415 goto cannot_handle;
21416 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
21417 goto cannot_handle;
21418- intr_ptr = (unsigned long __user *) (i << 2);
21419+ intr_ptr = (__force unsigned long __user *) (i << 2);
21420 if (get_user(segoffs, intr_ptr))
21421 goto cannot_handle;
21422 if ((segoffs >> 16) == BIOSSEG)
21423diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
21424index 22a1530..8fbaaad 100644
21425--- a/arch/x86/kernel/vmlinux.lds.S
21426+++ b/arch/x86/kernel/vmlinux.lds.S
21427@@ -26,6 +26,13 @@
21428 #include <asm/page_types.h>
21429 #include <asm/cache.h>
21430 #include <asm/boot.h>
21431+#include <asm/segment.h>
21432+
21433+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21434+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
21435+#else
21436+#define __KERNEL_TEXT_OFFSET 0
21437+#endif
21438
21439 #undef i386 /* in case the preprocessor is a 32bit one */
21440
21441@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
21442
21443 PHDRS {
21444 text PT_LOAD FLAGS(5); /* R_E */
21445+#ifdef CONFIG_X86_32
21446+ module PT_LOAD FLAGS(5); /* R_E */
21447+#endif
21448+#ifdef CONFIG_XEN
21449+ rodata PT_LOAD FLAGS(5); /* R_E */
21450+#else
21451+ rodata PT_LOAD FLAGS(4); /* R__ */
21452+#endif
21453 data PT_LOAD FLAGS(6); /* RW_ */
21454-#ifdef CONFIG_X86_64
21455+ init.begin PT_LOAD FLAGS(6); /* RW_ */
21456 #ifdef CONFIG_SMP
21457 percpu PT_LOAD FLAGS(6); /* RW_ */
21458 #endif
21459+ text.init PT_LOAD FLAGS(5); /* R_E */
21460+ text.exit PT_LOAD FLAGS(5); /* R_E */
21461 init PT_LOAD FLAGS(7); /* RWE */
21462-#endif
21463 note PT_NOTE FLAGS(0); /* ___ */
21464 }
21465
21466 SECTIONS
21467 {
21468 #ifdef CONFIG_X86_32
21469- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
21470- phys_startup_32 = startup_32 - LOAD_OFFSET;
21471+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
21472 #else
21473- . = __START_KERNEL;
21474- phys_startup_64 = startup_64 - LOAD_OFFSET;
21475+ . = __START_KERNEL;
21476 #endif
21477
21478 /* Text and read-only data */
21479- .text : AT(ADDR(.text) - LOAD_OFFSET) {
21480- _text = .;
21481+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
21482 /* bootstrapping code */
21483+#ifdef CONFIG_X86_32
21484+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
21485+#else
21486+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
21487+#endif
21488+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
21489+ _text = .;
21490 HEAD_TEXT
21491 #ifdef CONFIG_X86_32
21492 . = ALIGN(PAGE_SIZE);
21493@@ -108,13 +128,48 @@ SECTIONS
21494 IRQENTRY_TEXT
21495 *(.fixup)
21496 *(.gnu.warning)
21497- /* End of text section */
21498- _etext = .;
21499 } :text = 0x9090
21500
21501- NOTES :text :note
21502+ . += __KERNEL_TEXT_OFFSET;
21503
21504- EXCEPTION_TABLE(16) :text = 0x9090
21505+#ifdef CONFIG_X86_32
21506+ . = ALIGN(PAGE_SIZE);
21507+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
21508+
21509+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
21510+ MODULES_EXEC_VADDR = .;
21511+ BYTE(0)
21512+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
21513+ . = ALIGN(HPAGE_SIZE) - 1;
21514+ MODULES_EXEC_END = .;
21515+#endif
21516+
21517+ } :module
21518+#endif
21519+
21520+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
21521+ /* End of text section */
21522+ BYTE(0)
21523+ _etext = . - __KERNEL_TEXT_OFFSET;
21524+ }
21525+
21526+#ifdef CONFIG_X86_32
21527+ . = ALIGN(PAGE_SIZE);
21528+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
21529+ *(.idt)
21530+ . = ALIGN(PAGE_SIZE);
21531+ *(.empty_zero_page)
21532+ *(.initial_pg_fixmap)
21533+ *(.initial_pg_pmd)
21534+ *(.initial_page_table)
21535+ *(.swapper_pg_dir)
21536+ } :rodata
21537+#endif
21538+
21539+ . = ALIGN(PAGE_SIZE);
21540+ NOTES :rodata :note
21541+
21542+ EXCEPTION_TABLE(16) :rodata
21543
21544 #if defined(CONFIG_DEBUG_RODATA)
21545 /* .text should occupy whole number of pages */
21546@@ -126,16 +181,20 @@ SECTIONS
21547
21548 /* Data */
21549 .data : AT(ADDR(.data) - LOAD_OFFSET) {
21550+
21551+#ifdef CONFIG_PAX_KERNEXEC
21552+ . = ALIGN(HPAGE_SIZE);
21553+#else
21554+ . = ALIGN(PAGE_SIZE);
21555+#endif
21556+
21557 /* Start of data section */
21558 _sdata = .;
21559
21560 /* init_task */
21561 INIT_TASK_DATA(THREAD_SIZE)
21562
21563-#ifdef CONFIG_X86_32
21564- /* 32 bit has nosave before _edata */
21565 NOSAVE_DATA
21566-#endif
21567
21568 PAGE_ALIGNED_DATA(PAGE_SIZE)
21569
21570@@ -176,12 +235,19 @@ SECTIONS
21571 #endif /* CONFIG_X86_64 */
21572
21573 /* Init code and data - will be freed after init */
21574- . = ALIGN(PAGE_SIZE);
21575 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
21576+ BYTE(0)
21577+
21578+#ifdef CONFIG_PAX_KERNEXEC
21579+ . = ALIGN(HPAGE_SIZE);
21580+#else
21581+ . = ALIGN(PAGE_SIZE);
21582+#endif
21583+
21584 __init_begin = .; /* paired with __init_end */
21585- }
21586+ } :init.begin
21587
21588-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
21589+#ifdef CONFIG_SMP
21590 /*
21591 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
21592 * output PHDR, so the next output section - .init.text - should
21593@@ -190,12 +256,27 @@ SECTIONS
21594 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
21595 #endif
21596
21597- INIT_TEXT_SECTION(PAGE_SIZE)
21598-#ifdef CONFIG_X86_64
21599- :init
21600-#endif
21601+ . = ALIGN(PAGE_SIZE);
21602+ init_begin = .;
21603+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
21604+ VMLINUX_SYMBOL(_sinittext) = .;
21605+ INIT_TEXT
21606+ VMLINUX_SYMBOL(_einittext) = .;
21607+ . = ALIGN(PAGE_SIZE);
21608+ } :text.init
21609
21610- INIT_DATA_SECTION(16)
21611+ /*
21612+ * .exit.text is discard at runtime, not link time, to deal with
21613+ * references from .altinstructions and .eh_frame
21614+ */
21615+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
21616+ EXIT_TEXT
21617+ . = ALIGN(16);
21618+ } :text.exit
21619+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
21620+
21621+ . = ALIGN(PAGE_SIZE);
21622+ INIT_DATA_SECTION(16) :init
21623
21624 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
21625 __x86_cpu_dev_start = .;
21626@@ -257,19 +338,12 @@ SECTIONS
21627 }
21628
21629 . = ALIGN(8);
21630- /*
21631- * .exit.text is discard at runtime, not link time, to deal with
21632- * references from .altinstructions and .eh_frame
21633- */
21634- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
21635- EXIT_TEXT
21636- }
21637
21638 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
21639 EXIT_DATA
21640 }
21641
21642-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
21643+#ifndef CONFIG_SMP
21644 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
21645 #endif
21646
21647@@ -288,16 +362,10 @@ SECTIONS
21648 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
21649 __smp_locks = .;
21650 *(.smp_locks)
21651- . = ALIGN(PAGE_SIZE);
21652 __smp_locks_end = .;
21653+ . = ALIGN(PAGE_SIZE);
21654 }
21655
21656-#ifdef CONFIG_X86_64
21657- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
21658- NOSAVE_DATA
21659- }
21660-#endif
21661-
21662 /* BSS */
21663 . = ALIGN(PAGE_SIZE);
21664 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
21665@@ -313,6 +381,7 @@ SECTIONS
21666 __brk_base = .;
21667 . += 64 * 1024; /* 64k alignment slop space */
21668 *(.brk_reservation) /* areas brk users have reserved */
21669+ . = ALIGN(HPAGE_SIZE);
21670 __brk_limit = .;
21671 }
21672
21673@@ -339,13 +408,12 @@ SECTIONS
21674 * for the boot processor.
21675 */
21676 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
21677-INIT_PER_CPU(gdt_page);
21678 INIT_PER_CPU(irq_stack_union);
21679
21680 /*
21681 * Build-time check on the image size:
21682 */
21683-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
21684+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
21685 "kernel image bigger than KERNEL_IMAGE_SIZE");
21686
21687 #ifdef CONFIG_SMP
21688diff --git a/arch/x86/kernel/vsmp_64.c b/arch/x86/kernel/vsmp_64.c
21689index 992f890..0ab1aae 100644
21690--- a/arch/x86/kernel/vsmp_64.c
21691+++ b/arch/x86/kernel/vsmp_64.c
21692@@ -114,7 +114,7 @@ static void __init set_vsmp_pv_ops(void)
21693 pv_irq_ops.irq_enable = PV_CALLEE_SAVE(vsmp_irq_enable);
21694 pv_irq_ops.save_fl = PV_CALLEE_SAVE(vsmp_save_fl);
21695 pv_irq_ops.restore_fl = PV_CALLEE_SAVE(vsmp_restore_fl);
21696- pv_init_ops.patch = vsmp_patch;
21697+ *(void **)&pv_init_ops.patch = vsmp_patch;
21698 ctl &= ~(1 << 4);
21699 }
21700 writel(ctl, address + 4);
21701@@ -217,8 +217,8 @@ static void fill_vector_allocation_domain(int cpu, struct cpumask *retmask,
21702 static void vsmp_apic_post_init(void)
21703 {
21704 /* need to update phys_pkg_id */
21705- apic->phys_pkg_id = apicid_phys_pkg_id;
21706- apic->vector_allocation_domain = fill_vector_allocation_domain;
21707+ *(void **)&apic->phys_pkg_id = apicid_phys_pkg_id;
21708+ *(void **)&apic->vector_allocation_domain = fill_vector_allocation_domain;
21709 }
21710
21711 void __init vsmp_init(void)
21712@@ -227,7 +227,7 @@ void __init vsmp_init(void)
21713 if (!is_vsmp_box())
21714 return;
21715
21716- x86_platform.apic_post_init = vsmp_apic_post_init;
21717+ *(void **)&x86_platform.apic_post_init = vsmp_apic_post_init;
21718
21719 vsmp_cap_cpus();
21720
21721diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
21722index 3a3e8c9..1af9465 100644
21723--- a/arch/x86/kernel/vsyscall_64.c
21724+++ b/arch/x86/kernel/vsyscall_64.c
21725@@ -56,15 +56,13 @@
21726 DEFINE_VVAR(int, vgetcpu_mode);
21727 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
21728
21729-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
21730+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
21731
21732 static int __init vsyscall_setup(char *str)
21733 {
21734 if (str) {
21735 if (!strcmp("emulate", str))
21736 vsyscall_mode = EMULATE;
21737- else if (!strcmp("native", str))
21738- vsyscall_mode = NATIVE;
21739 else if (!strcmp("none", str))
21740 vsyscall_mode = NONE;
21741 else
21742@@ -315,8 +313,7 @@ done:
21743 return true;
21744
21745 sigsegv:
21746- force_sig(SIGSEGV, current);
21747- return true;
21748+ do_group_exit(SIGKILL);
21749 }
21750
21751 /*
21752@@ -369,10 +366,7 @@ void __init map_vsyscall(void)
21753 extern char __vvar_page;
21754 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
21755
21756- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
21757- vsyscall_mode == NATIVE
21758- ? PAGE_KERNEL_VSYSCALL
21759- : PAGE_KERNEL_VVAR);
21760+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
21761 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
21762 (unsigned long)VSYSCALL_START);
21763
21764diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
21765index 1330dd1..d220b99 100644
21766--- a/arch/x86/kernel/x8664_ksyms_64.c
21767+++ b/arch/x86/kernel/x8664_ksyms_64.c
21768@@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
21769 EXPORT_SYMBOL(copy_user_generic_unrolled);
21770 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
21771 EXPORT_SYMBOL(__copy_user_nocache);
21772-EXPORT_SYMBOL(_copy_from_user);
21773-EXPORT_SYMBOL(_copy_to_user);
21774
21775 EXPORT_SYMBOL(copy_page);
21776 EXPORT_SYMBOL(clear_page);
21777diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
21778index ada87a3..afea76d 100644
21779--- a/arch/x86/kernel/xsave.c
21780+++ b/arch/x86/kernel/xsave.c
21781@@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
21782 {
21783 int err;
21784
21785+ buf = (struct xsave_struct __user *)____m(buf);
21786 if (use_xsave())
21787 err = xsave_user(buf);
21788 else if (use_fxsr())
21789@@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
21790 */
21791 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
21792 {
21793+ buf = (void __user *)____m(buf);
21794 if (use_xsave()) {
21795 if ((unsigned long)buf % 64 || fx_only) {
21796 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
21797diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
21798index ec79e77..420f5cc 100644
21799--- a/arch/x86/kvm/cpuid.c
21800+++ b/arch/x86/kvm/cpuid.c
21801@@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
21802 struct kvm_cpuid2 *cpuid,
21803 struct kvm_cpuid_entry2 __user *entries)
21804 {
21805- int r;
21806+ int r, i;
21807
21808 r = -E2BIG;
21809 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
21810 goto out;
21811 r = -EFAULT;
21812- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
21813- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
21814+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
21815 goto out;
21816+ for (i = 0; i < cpuid->nent; ++i) {
21817+ struct kvm_cpuid_entry2 cpuid_entry;
21818+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
21819+ goto out;
21820+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
21821+ }
21822 vcpu->arch.cpuid_nent = cpuid->nent;
21823 kvm_apic_set_version(vcpu);
21824 kvm_x86_ops->cpuid_update(vcpu);
21825@@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
21826 struct kvm_cpuid2 *cpuid,
21827 struct kvm_cpuid_entry2 __user *entries)
21828 {
21829- int r;
21830+ int r, i;
21831
21832 r = -E2BIG;
21833 if (cpuid->nent < vcpu->arch.cpuid_nent)
21834 goto out;
21835 r = -EFAULT;
21836- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
21837- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
21838+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
21839 goto out;
21840+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
21841+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
21842+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
21843+ goto out;
21844+ }
21845 return 0;
21846
21847 out:
21848diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
21849index bba39bf..296540a 100644
21850--- a/arch/x86/kvm/emulate.c
21851+++ b/arch/x86/kvm/emulate.c
21852@@ -292,6 +292,7 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
21853
21854 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
21855 do { \
21856+ unsigned long _tmp; \
21857 __asm__ __volatile__ ( \
21858 _PRE_EFLAGS("0", "4", "2") \
21859 _op _suffix " %"_x"3,%1; " \
21860@@ -306,8 +307,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
21861 /* Raw emulation: instruction has two explicit operands. */
21862 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
21863 do { \
21864- unsigned long _tmp; \
21865- \
21866 switch ((ctxt)->dst.bytes) { \
21867 case 2: \
21868 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
21869@@ -323,7 +322,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
21870
21871 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
21872 do { \
21873- unsigned long _tmp; \
21874 switch ((ctxt)->dst.bytes) { \
21875 case 1: \
21876 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
21877diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
21878index 43e9fad..3b7c059 100644
21879--- a/arch/x86/kvm/lapic.c
21880+++ b/arch/x86/kvm/lapic.c
21881@@ -55,7 +55,7 @@
21882 #define APIC_BUS_CYCLE_NS 1
21883
21884 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
21885-#define apic_debug(fmt, arg...)
21886+#define apic_debug(fmt, arg...) do {} while (0)
21887
21888 #define APIC_LVT_NUM 6
21889 /* 14 is the version for Xeon and Pentium 8.4.8*/
21890diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
21891index 714e2c0..3f7a086 100644
21892--- a/arch/x86/kvm/paging_tmpl.h
21893+++ b/arch/x86/kvm/paging_tmpl.h
21894@@ -208,7 +208,7 @@ retry_walk:
21895 if (unlikely(kvm_is_error_hva(host_addr)))
21896 goto error;
21897
21898- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
21899+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
21900 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
21901 goto error;
21902 walker->ptep_user[walker->level - 1] = ptep_user;
21903diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
21904index d017df3..61ae42e 100644
21905--- a/arch/x86/kvm/svm.c
21906+++ b/arch/x86/kvm/svm.c
21907@@ -3500,7 +3500,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
21908 int cpu = raw_smp_processor_id();
21909
21910 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
21911+
21912+ pax_open_kernel();
21913 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
21914+ pax_close_kernel();
21915+
21916 load_TR_desc();
21917 }
21918
21919@@ -3874,6 +3878,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
21920 #endif
21921 #endif
21922
21923+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
21924+ __set_fs(current_thread_info()->addr_limit);
21925+#endif
21926+
21927 reload_tss(vcpu);
21928
21929 local_irq_disable();
21930diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
21931index f858159..4ab7dba 100644
21932--- a/arch/x86/kvm/vmx.c
21933+++ b/arch/x86/kvm/vmx.c
21934@@ -1332,7 +1332,11 @@ static void reload_tss(void)
21935 struct desc_struct *descs;
21936
21937 descs = (void *)gdt->address;
21938+
21939+ pax_open_kernel();
21940 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
21941+ pax_close_kernel();
21942+
21943 load_TR_desc();
21944 }
21945
21946@@ -1546,6 +1550,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
21947 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
21948 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
21949
21950+#ifdef CONFIG_PAX_PER_CPU_PGD
21951+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
21952+#endif
21953+
21954 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
21955 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
21956 vmx->loaded_vmcs->cpu = cpu;
21957@@ -2669,8 +2677,11 @@ static __init int hardware_setup(void)
21958 if (!cpu_has_vmx_flexpriority())
21959 flexpriority_enabled = 0;
21960
21961- if (!cpu_has_vmx_tpr_shadow())
21962- kvm_x86_ops->update_cr8_intercept = NULL;
21963+ if (!cpu_has_vmx_tpr_shadow()) {
21964+ pax_open_kernel();
21965+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
21966+ pax_close_kernel();
21967+ }
21968
21969 if (enable_ept && !cpu_has_vmx_ept_2m_page())
21970 kvm_disable_largepages();
21971@@ -3712,7 +3723,10 @@ static void vmx_set_constant_host_state(void)
21972
21973 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
21974 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
21975+
21976+#ifndef CONFIG_PAX_PER_CPU_PGD
21977 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
21978+#endif
21979
21980 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
21981 #ifdef CONFIG_X86_64
21982@@ -3733,7 +3747,7 @@ static void vmx_set_constant_host_state(void)
21983 native_store_idt(&dt);
21984 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
21985
21986- vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
21987+ vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
21988
21989 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
21990 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
21991@@ -6279,6 +6293,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
21992 "jmp 2f \n\t"
21993 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
21994 "2: "
21995+
21996+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21997+ "ljmp %[cs],$3f\n\t"
21998+ "3: "
21999+#endif
22000+
22001 /* Save guest registers, load host registers, keep flags */
22002 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
22003 "pop %0 \n\t"
22004@@ -6331,6 +6351,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
22005 #endif
22006 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
22007 [wordsize]"i"(sizeof(ulong))
22008+
22009+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
22010+ ,[cs]"i"(__KERNEL_CS)
22011+#endif
22012+
22013 : "cc", "memory"
22014 #ifdef CONFIG_X86_64
22015 , "rax", "rbx", "rdi", "rsi"
22016@@ -6344,7 +6369,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
22017 if (debugctlmsr)
22018 update_debugctlmsr(debugctlmsr);
22019
22020-#ifndef CONFIG_X86_64
22021+#ifdef CONFIG_X86_32
22022 /*
22023 * The sysexit path does not restore ds/es, so we must set them to
22024 * a reasonable value ourselves.
22025@@ -6353,8 +6378,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
22026 * may be executed in interrupt context, which saves and restore segments
22027 * around it, nullifying its effect.
22028 */
22029- loadsegment(ds, __USER_DS);
22030- loadsegment(es, __USER_DS);
22031+ loadsegment(ds, __KERNEL_DS);
22032+ loadsegment(es, __KERNEL_DS);
22033+ loadsegment(ss, __KERNEL_DS);
22034+
22035+#ifdef CONFIG_PAX_KERNEXEC
22036+ loadsegment(fs, __KERNEL_PERCPU);
22037+#endif
22038+
22039+#ifdef CONFIG_PAX_MEMORY_UDEREF
22040+ __set_fs(current_thread_info()->addr_limit);
22041+#endif
22042+
22043 #endif
22044
22045 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
22046diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
22047index 4f76417..93429b5 100644
22048--- a/arch/x86/kvm/x86.c
22049+++ b/arch/x86/kvm/x86.c
22050@@ -1390,8 +1390,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
22051 {
22052 struct kvm *kvm = vcpu->kvm;
22053 int lm = is_long_mode(vcpu);
22054- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
22055- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
22056+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
22057+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
22058 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
22059 : kvm->arch.xen_hvm_config.blob_size_32;
22060 u32 page_num = data & ~PAGE_MASK;
22061@@ -2255,6 +2255,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
22062 if (n < msr_list.nmsrs)
22063 goto out;
22064 r = -EFAULT;
22065+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
22066+ goto out;
22067 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
22068 num_msrs_to_save * sizeof(u32)))
22069 goto out;
22070@@ -2379,7 +2381,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
22071 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
22072 struct kvm_interrupt *irq)
22073 {
22074- if (irq->irq < 0 || irq->irq >= KVM_NR_INTERRUPTS)
22075+ if (irq->irq >= KVM_NR_INTERRUPTS)
22076 return -EINVAL;
22077 if (irqchip_in_kernel(vcpu->kvm))
22078 return -ENXIO;
22079@@ -4881,7 +4883,7 @@ static void kvm_set_mmio_spte_mask(void)
22080 kvm_mmu_set_mmio_spte_mask(mask);
22081 }
22082
22083-int kvm_arch_init(void *opaque)
22084+int kvm_arch_init(const void *opaque)
22085 {
22086 int r;
22087 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
22088diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
22089index 642d880..5dd034e 100644
22090--- a/arch/x86/lguest/boot.c
22091+++ b/arch/x86/lguest/boot.c
22092@@ -1116,12 +1116,12 @@ static u32 lguest_apic_safe_wait_icr_idle(void)
22093
22094 static void set_lguest_basic_apic_ops(void)
22095 {
22096- apic->read = lguest_apic_read;
22097- apic->write = lguest_apic_write;
22098- apic->icr_read = lguest_apic_icr_read;
22099- apic->icr_write = lguest_apic_icr_write;
22100- apic->wait_icr_idle = lguest_apic_wait_icr_idle;
22101- apic->safe_wait_icr_idle = lguest_apic_safe_wait_icr_idle;
22102+ *(void **)&apic->read = lguest_apic_read;
22103+ *(void **)&apic->write = lguest_apic_write;
22104+ *(void **)&apic->icr_read = lguest_apic_icr_read;
22105+ *(void **)&apic->icr_write = lguest_apic_icr_write;
22106+ *(void **)&apic->wait_icr_idle = lguest_apic_wait_icr_idle;
22107+ *(void **)&apic->safe_wait_icr_idle = lguest_apic_safe_wait_icr_idle;
22108 };
22109 #endif
22110
22111@@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
22112 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
22113 * Launcher to reboot us.
22114 */
22115-static void lguest_restart(char *reason)
22116+static __noreturn void lguest_restart(char *reason)
22117 {
22118 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
22119+ BUG();
22120 }
22121
22122 /*G:050
22123@@ -1292,28 +1293,28 @@ __init void lguest_init(void)
22124 pv_irq_ops.safe_halt = lguest_safe_halt;
22125
22126 /* Setup operations */
22127- pv_init_ops.patch = lguest_patch;
22128+ *(void **)&pv_init_ops.patch = lguest_patch;
22129
22130 /* Intercepts of various CPU instructions */
22131- pv_cpu_ops.load_gdt = lguest_load_gdt;
22132- pv_cpu_ops.cpuid = lguest_cpuid;
22133- pv_cpu_ops.load_idt = lguest_load_idt;
22134- pv_cpu_ops.iret = lguest_iret;
22135- pv_cpu_ops.load_sp0 = lguest_load_sp0;
22136- pv_cpu_ops.load_tr_desc = lguest_load_tr_desc;
22137- pv_cpu_ops.set_ldt = lguest_set_ldt;
22138- pv_cpu_ops.load_tls = lguest_load_tls;
22139- pv_cpu_ops.set_debugreg = lguest_set_debugreg;
22140- pv_cpu_ops.clts = lguest_clts;
22141- pv_cpu_ops.read_cr0 = lguest_read_cr0;
22142- pv_cpu_ops.write_cr0 = lguest_write_cr0;
22143- pv_cpu_ops.read_cr4 = lguest_read_cr4;
22144- pv_cpu_ops.write_cr4 = lguest_write_cr4;
22145- pv_cpu_ops.write_gdt_entry = lguest_write_gdt_entry;
22146- pv_cpu_ops.write_idt_entry = lguest_write_idt_entry;
22147- pv_cpu_ops.wbinvd = lguest_wbinvd;
22148- pv_cpu_ops.start_context_switch = paravirt_start_context_switch;
22149- pv_cpu_ops.end_context_switch = lguest_end_context_switch;
22150+ *(void **)&pv_cpu_ops.load_gdt = lguest_load_gdt;
22151+ *(void **)&pv_cpu_ops.cpuid = lguest_cpuid;
22152+ *(void **)&pv_cpu_ops.load_idt = lguest_load_idt;
22153+ *(void **)&pv_cpu_ops.iret = lguest_iret;
22154+ *(void **)&pv_cpu_ops.load_sp0 = lguest_load_sp0;
22155+ *(void **)&pv_cpu_ops.load_tr_desc = lguest_load_tr_desc;
22156+ *(void **)&pv_cpu_ops.set_ldt = lguest_set_ldt;
22157+ *(void **)&pv_cpu_ops.load_tls = lguest_load_tls;
22158+ *(void **)&pv_cpu_ops.set_debugreg = lguest_set_debugreg;
22159+ *(void **)&pv_cpu_ops.clts = lguest_clts;
22160+ *(void **)&pv_cpu_ops.read_cr0 = lguest_read_cr0;
22161+ *(void **)&pv_cpu_ops.write_cr0 = lguest_write_cr0;
22162+ *(void **)&pv_cpu_ops.read_cr4 = lguest_read_cr4;
22163+ *(void **)&pv_cpu_ops.write_cr4 = lguest_write_cr4;
22164+ *(void **)&pv_cpu_ops.write_gdt_entry = lguest_write_gdt_entry;
22165+ *(void **)&pv_cpu_ops.write_idt_entry = lguest_write_idt_entry;
22166+ *(void **)&pv_cpu_ops.wbinvd = lguest_wbinvd;
22167+ *(void **)&pv_cpu_ops.start_context_switch = paravirt_start_context_switch;
22168+ *(void **)&pv_cpu_ops.end_context_switch = lguest_end_context_switch;
22169
22170 /* Pagetable management */
22171 pv_mmu_ops.write_cr3 = lguest_write_cr3;
22172@@ -1341,11 +1342,11 @@ __init void lguest_init(void)
22173 set_lguest_basic_apic_ops();
22174 #endif
22175
22176- x86_init.resources.memory_setup = lguest_memory_setup;
22177- x86_init.irqs.intr_init = lguest_init_IRQ;
22178- x86_init.timers.timer_init = lguest_time_init;
22179- x86_platform.calibrate_tsc = lguest_tsc_khz;
22180- x86_platform.get_wallclock = lguest_get_wallclock;
22181+ *(void **)&x86_init.resources.memory_setup = lguest_memory_setup;
22182+ *(void **)&x86_init.irqs.intr_init = lguest_init_IRQ;
22183+ *(void **)&x86_init.timers.timer_init = lguest_time_init;
22184+ *(void **)&x86_platform.calibrate_tsc = lguest_tsc_khz;
22185+ *(void **)&x86_platform.get_wallclock = lguest_get_wallclock;
22186
22187 /*
22188 * Now is a good time to look at the implementations of these functions
22189@@ -1434,7 +1435,7 @@ __init void lguest_init(void)
22190 * routine.
22191 */
22192 pm_power_off = lguest_power_off;
22193- machine_ops.restart = lguest_restart;
22194+ *(void **)&machine_ops.restart = lguest_restart;
22195
22196 /*
22197 * Now we're set up, call i386_start_kernel() in head32.c and we proceed
22198diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
22199index 00933d5..3a64af9 100644
22200--- a/arch/x86/lib/atomic64_386_32.S
22201+++ b/arch/x86/lib/atomic64_386_32.S
22202@@ -48,6 +48,10 @@ BEGIN(read)
22203 movl (v), %eax
22204 movl 4(v), %edx
22205 RET_ENDP
22206+BEGIN(read_unchecked)
22207+ movl (v), %eax
22208+ movl 4(v), %edx
22209+RET_ENDP
22210 #undef v
22211
22212 #define v %esi
22213@@ -55,6 +59,10 @@ BEGIN(set)
22214 movl %ebx, (v)
22215 movl %ecx, 4(v)
22216 RET_ENDP
22217+BEGIN(set_unchecked)
22218+ movl %ebx, (v)
22219+ movl %ecx, 4(v)
22220+RET_ENDP
22221 #undef v
22222
22223 #define v %esi
22224@@ -70,6 +78,20 @@ RET_ENDP
22225 BEGIN(add)
22226 addl %eax, (v)
22227 adcl %edx, 4(v)
22228+
22229+#ifdef CONFIG_PAX_REFCOUNT
22230+ jno 0f
22231+ subl %eax, (v)
22232+ sbbl %edx, 4(v)
22233+ int $4
22234+0:
22235+ _ASM_EXTABLE(0b, 0b)
22236+#endif
22237+
22238+RET_ENDP
22239+BEGIN(add_unchecked)
22240+ addl %eax, (v)
22241+ adcl %edx, 4(v)
22242 RET_ENDP
22243 #undef v
22244
22245@@ -77,6 +99,24 @@ RET_ENDP
22246 BEGIN(add_return)
22247 addl (v), %eax
22248 adcl 4(v), %edx
22249+
22250+#ifdef CONFIG_PAX_REFCOUNT
22251+ into
22252+1234:
22253+ _ASM_EXTABLE(1234b, 2f)
22254+#endif
22255+
22256+ movl %eax, (v)
22257+ movl %edx, 4(v)
22258+
22259+#ifdef CONFIG_PAX_REFCOUNT
22260+2:
22261+#endif
22262+
22263+RET_ENDP
22264+BEGIN(add_return_unchecked)
22265+ addl (v), %eax
22266+ adcl 4(v), %edx
22267 movl %eax, (v)
22268 movl %edx, 4(v)
22269 RET_ENDP
22270@@ -86,6 +126,20 @@ RET_ENDP
22271 BEGIN(sub)
22272 subl %eax, (v)
22273 sbbl %edx, 4(v)
22274+
22275+#ifdef CONFIG_PAX_REFCOUNT
22276+ jno 0f
22277+ addl %eax, (v)
22278+ adcl %edx, 4(v)
22279+ int $4
22280+0:
22281+ _ASM_EXTABLE(0b, 0b)
22282+#endif
22283+
22284+RET_ENDP
22285+BEGIN(sub_unchecked)
22286+ subl %eax, (v)
22287+ sbbl %edx, 4(v)
22288 RET_ENDP
22289 #undef v
22290
22291@@ -96,6 +150,27 @@ BEGIN(sub_return)
22292 sbbl $0, %edx
22293 addl (v), %eax
22294 adcl 4(v), %edx
22295+
22296+#ifdef CONFIG_PAX_REFCOUNT
22297+ into
22298+1234:
22299+ _ASM_EXTABLE(1234b, 2f)
22300+#endif
22301+
22302+ movl %eax, (v)
22303+ movl %edx, 4(v)
22304+
22305+#ifdef CONFIG_PAX_REFCOUNT
22306+2:
22307+#endif
22308+
22309+RET_ENDP
22310+BEGIN(sub_return_unchecked)
22311+ negl %edx
22312+ negl %eax
22313+ sbbl $0, %edx
22314+ addl (v), %eax
22315+ adcl 4(v), %edx
22316 movl %eax, (v)
22317 movl %edx, 4(v)
22318 RET_ENDP
22319@@ -105,6 +180,20 @@ RET_ENDP
22320 BEGIN(inc)
22321 addl $1, (v)
22322 adcl $0, 4(v)
22323+
22324+#ifdef CONFIG_PAX_REFCOUNT
22325+ jno 0f
22326+ subl $1, (v)
22327+ sbbl $0, 4(v)
22328+ int $4
22329+0:
22330+ _ASM_EXTABLE(0b, 0b)
22331+#endif
22332+
22333+RET_ENDP
22334+BEGIN(inc_unchecked)
22335+ addl $1, (v)
22336+ adcl $0, 4(v)
22337 RET_ENDP
22338 #undef v
22339
22340@@ -114,6 +203,26 @@ BEGIN(inc_return)
22341 movl 4(v), %edx
22342 addl $1, %eax
22343 adcl $0, %edx
22344+
22345+#ifdef CONFIG_PAX_REFCOUNT
22346+ into
22347+1234:
22348+ _ASM_EXTABLE(1234b, 2f)
22349+#endif
22350+
22351+ movl %eax, (v)
22352+ movl %edx, 4(v)
22353+
22354+#ifdef CONFIG_PAX_REFCOUNT
22355+2:
22356+#endif
22357+
22358+RET_ENDP
22359+BEGIN(inc_return_unchecked)
22360+ movl (v), %eax
22361+ movl 4(v), %edx
22362+ addl $1, %eax
22363+ adcl $0, %edx
22364 movl %eax, (v)
22365 movl %edx, 4(v)
22366 RET_ENDP
22367@@ -123,6 +232,20 @@ RET_ENDP
22368 BEGIN(dec)
22369 subl $1, (v)
22370 sbbl $0, 4(v)
22371+
22372+#ifdef CONFIG_PAX_REFCOUNT
22373+ jno 0f
22374+ addl $1, (v)
22375+ adcl $0, 4(v)
22376+ int $4
22377+0:
22378+ _ASM_EXTABLE(0b, 0b)
22379+#endif
22380+
22381+RET_ENDP
22382+BEGIN(dec_unchecked)
22383+ subl $1, (v)
22384+ sbbl $0, 4(v)
22385 RET_ENDP
22386 #undef v
22387
22388@@ -132,6 +255,26 @@ BEGIN(dec_return)
22389 movl 4(v), %edx
22390 subl $1, %eax
22391 sbbl $0, %edx
22392+
22393+#ifdef CONFIG_PAX_REFCOUNT
22394+ into
22395+1234:
22396+ _ASM_EXTABLE(1234b, 2f)
22397+#endif
22398+
22399+ movl %eax, (v)
22400+ movl %edx, 4(v)
22401+
22402+#ifdef CONFIG_PAX_REFCOUNT
22403+2:
22404+#endif
22405+
22406+RET_ENDP
22407+BEGIN(dec_return_unchecked)
22408+ movl (v), %eax
22409+ movl 4(v), %edx
22410+ subl $1, %eax
22411+ sbbl $0, %edx
22412 movl %eax, (v)
22413 movl %edx, 4(v)
22414 RET_ENDP
22415@@ -143,6 +286,13 @@ BEGIN(add_unless)
22416 adcl %edx, %edi
22417 addl (v), %eax
22418 adcl 4(v), %edx
22419+
22420+#ifdef CONFIG_PAX_REFCOUNT
22421+ into
22422+1234:
22423+ _ASM_EXTABLE(1234b, 2f)
22424+#endif
22425+
22426 cmpl %eax, %ecx
22427 je 3f
22428 1:
22429@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
22430 1:
22431 addl $1, %eax
22432 adcl $0, %edx
22433+
22434+#ifdef CONFIG_PAX_REFCOUNT
22435+ into
22436+1234:
22437+ _ASM_EXTABLE(1234b, 2f)
22438+#endif
22439+
22440 movl %eax, (v)
22441 movl %edx, 4(v)
22442 movl $1, %eax
22443@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
22444 movl 4(v), %edx
22445 subl $1, %eax
22446 sbbl $0, %edx
22447+
22448+#ifdef CONFIG_PAX_REFCOUNT
22449+ into
22450+1234:
22451+ _ASM_EXTABLE(1234b, 1f)
22452+#endif
22453+
22454 js 1f
22455 movl %eax, (v)
22456 movl %edx, 4(v)
22457diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
22458index f5cc9eb..51fa319 100644
22459--- a/arch/x86/lib/atomic64_cx8_32.S
22460+++ b/arch/x86/lib/atomic64_cx8_32.S
22461@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
22462 CFI_STARTPROC
22463
22464 read64 %ecx
22465+ pax_force_retaddr
22466 ret
22467 CFI_ENDPROC
22468 ENDPROC(atomic64_read_cx8)
22469
22470+ENTRY(atomic64_read_unchecked_cx8)
22471+ CFI_STARTPROC
22472+
22473+ read64 %ecx
22474+ pax_force_retaddr
22475+ ret
22476+ CFI_ENDPROC
22477+ENDPROC(atomic64_read_unchecked_cx8)
22478+
22479 ENTRY(atomic64_set_cx8)
22480 CFI_STARTPROC
22481
22482@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
22483 cmpxchg8b (%esi)
22484 jne 1b
22485
22486+ pax_force_retaddr
22487 ret
22488 CFI_ENDPROC
22489 ENDPROC(atomic64_set_cx8)
22490
22491+ENTRY(atomic64_set_unchecked_cx8)
22492+ CFI_STARTPROC
22493+
22494+1:
22495+/* we don't need LOCK_PREFIX since aligned 64-bit writes
22496+ * are atomic on 586 and newer */
22497+ cmpxchg8b (%esi)
22498+ jne 1b
22499+
22500+ pax_force_retaddr
22501+ ret
22502+ CFI_ENDPROC
22503+ENDPROC(atomic64_set_unchecked_cx8)
22504+
22505 ENTRY(atomic64_xchg_cx8)
22506 CFI_STARTPROC
22507
22508@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
22509 cmpxchg8b (%esi)
22510 jne 1b
22511
22512+ pax_force_retaddr
22513 ret
22514 CFI_ENDPROC
22515 ENDPROC(atomic64_xchg_cx8)
22516
22517-.macro addsub_return func ins insc
22518-ENTRY(atomic64_\func\()_return_cx8)
22519+.macro addsub_return func ins insc unchecked=""
22520+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
22521 CFI_STARTPROC
22522 SAVE ebp
22523 SAVE ebx
22524@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
22525 movl %edx, %ecx
22526 \ins\()l %esi, %ebx
22527 \insc\()l %edi, %ecx
22528+
22529+.ifb \unchecked
22530+#ifdef CONFIG_PAX_REFCOUNT
22531+ into
22532+2:
22533+ _ASM_EXTABLE(2b, 3f)
22534+#endif
22535+.endif
22536+
22537 LOCK_PREFIX
22538 cmpxchg8b (%ebp)
22539 jne 1b
22540-
22541-10:
22542 movl %ebx, %eax
22543 movl %ecx, %edx
22544+
22545+.ifb \unchecked
22546+#ifdef CONFIG_PAX_REFCOUNT
22547+3:
22548+#endif
22549+.endif
22550+
22551 RESTORE edi
22552 RESTORE esi
22553 RESTORE ebx
22554 RESTORE ebp
22555+ pax_force_retaddr
22556 ret
22557 CFI_ENDPROC
22558-ENDPROC(atomic64_\func\()_return_cx8)
22559+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
22560 .endm
22561
22562 addsub_return add add adc
22563 addsub_return sub sub sbb
22564+addsub_return add add adc _unchecked
22565+addsub_return sub sub sbb _unchecked
22566
22567-.macro incdec_return func ins insc
22568-ENTRY(atomic64_\func\()_return_cx8)
22569+.macro incdec_return func ins insc unchecked=""
22570+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
22571 CFI_STARTPROC
22572 SAVE ebx
22573
22574@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
22575 movl %edx, %ecx
22576 \ins\()l $1, %ebx
22577 \insc\()l $0, %ecx
22578+
22579+.ifb \unchecked
22580+#ifdef CONFIG_PAX_REFCOUNT
22581+ into
22582+2:
22583+ _ASM_EXTABLE(2b, 3f)
22584+#endif
22585+.endif
22586+
22587 LOCK_PREFIX
22588 cmpxchg8b (%esi)
22589 jne 1b
22590
22591-10:
22592 movl %ebx, %eax
22593 movl %ecx, %edx
22594+
22595+.ifb \unchecked
22596+#ifdef CONFIG_PAX_REFCOUNT
22597+3:
22598+#endif
22599+.endif
22600+
22601 RESTORE ebx
22602+ pax_force_retaddr
22603 ret
22604 CFI_ENDPROC
22605-ENDPROC(atomic64_\func\()_return_cx8)
22606+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
22607 .endm
22608
22609 incdec_return inc add adc
22610 incdec_return dec sub sbb
22611+incdec_return inc add adc _unchecked
22612+incdec_return dec sub sbb _unchecked
22613
22614 ENTRY(atomic64_dec_if_positive_cx8)
22615 CFI_STARTPROC
22616@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
22617 movl %edx, %ecx
22618 subl $1, %ebx
22619 sbb $0, %ecx
22620+
22621+#ifdef CONFIG_PAX_REFCOUNT
22622+ into
22623+1234:
22624+ _ASM_EXTABLE(1234b, 2f)
22625+#endif
22626+
22627 js 2f
22628 LOCK_PREFIX
22629 cmpxchg8b (%esi)
22630@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
22631 movl %ebx, %eax
22632 movl %ecx, %edx
22633 RESTORE ebx
22634+ pax_force_retaddr
22635 ret
22636 CFI_ENDPROC
22637 ENDPROC(atomic64_dec_if_positive_cx8)
22638@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
22639 movl %edx, %ecx
22640 addl %ebp, %ebx
22641 adcl %edi, %ecx
22642+
22643+#ifdef CONFIG_PAX_REFCOUNT
22644+ into
22645+1234:
22646+ _ASM_EXTABLE(1234b, 3f)
22647+#endif
22648+
22649 LOCK_PREFIX
22650 cmpxchg8b (%esi)
22651 jne 1b
22652@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
22653 CFI_ADJUST_CFA_OFFSET -8
22654 RESTORE ebx
22655 RESTORE ebp
22656+ pax_force_retaddr
22657 ret
22658 4:
22659 cmpl %edx, 4(%esp)
22660@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
22661 xorl %ecx, %ecx
22662 addl $1, %ebx
22663 adcl %edx, %ecx
22664+
22665+#ifdef CONFIG_PAX_REFCOUNT
22666+ into
22667+1234:
22668+ _ASM_EXTABLE(1234b, 3f)
22669+#endif
22670+
22671 LOCK_PREFIX
22672 cmpxchg8b (%esi)
22673 jne 1b
22674@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
22675 movl $1, %eax
22676 3:
22677 RESTORE ebx
22678+ pax_force_retaddr
22679 ret
22680 CFI_ENDPROC
22681 ENDPROC(atomic64_inc_not_zero_cx8)
22682diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
22683index 2af5df3..62b1a5a 100644
22684--- a/arch/x86/lib/checksum_32.S
22685+++ b/arch/x86/lib/checksum_32.S
22686@@ -29,7 +29,8 @@
22687 #include <asm/dwarf2.h>
22688 #include <asm/errno.h>
22689 #include <asm/asm.h>
22690-
22691+#include <asm/segment.h>
22692+
22693 /*
22694 * computes a partial checksum, e.g. for TCP/UDP fragments
22695 */
22696@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
22697
22698 #define ARGBASE 16
22699 #define FP 12
22700-
22701-ENTRY(csum_partial_copy_generic)
22702+
22703+ENTRY(csum_partial_copy_generic_to_user)
22704 CFI_STARTPROC
22705+
22706+#ifdef CONFIG_PAX_MEMORY_UDEREF
22707+ pushl_cfi %gs
22708+ popl_cfi %es
22709+ jmp csum_partial_copy_generic
22710+#endif
22711+
22712+ENTRY(csum_partial_copy_generic_from_user)
22713+
22714+#ifdef CONFIG_PAX_MEMORY_UDEREF
22715+ pushl_cfi %gs
22716+ popl_cfi %ds
22717+#endif
22718+
22719+ENTRY(csum_partial_copy_generic)
22720 subl $4,%esp
22721 CFI_ADJUST_CFA_OFFSET 4
22722 pushl_cfi %edi
22723@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
22724 jmp 4f
22725 SRC(1: movw (%esi), %bx )
22726 addl $2, %esi
22727-DST( movw %bx, (%edi) )
22728+DST( movw %bx, %es:(%edi) )
22729 addl $2, %edi
22730 addw %bx, %ax
22731 adcl $0, %eax
22732@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
22733 SRC(1: movl (%esi), %ebx )
22734 SRC( movl 4(%esi), %edx )
22735 adcl %ebx, %eax
22736-DST( movl %ebx, (%edi) )
22737+DST( movl %ebx, %es:(%edi) )
22738 adcl %edx, %eax
22739-DST( movl %edx, 4(%edi) )
22740+DST( movl %edx, %es:4(%edi) )
22741
22742 SRC( movl 8(%esi), %ebx )
22743 SRC( movl 12(%esi), %edx )
22744 adcl %ebx, %eax
22745-DST( movl %ebx, 8(%edi) )
22746+DST( movl %ebx, %es:8(%edi) )
22747 adcl %edx, %eax
22748-DST( movl %edx, 12(%edi) )
22749+DST( movl %edx, %es:12(%edi) )
22750
22751 SRC( movl 16(%esi), %ebx )
22752 SRC( movl 20(%esi), %edx )
22753 adcl %ebx, %eax
22754-DST( movl %ebx, 16(%edi) )
22755+DST( movl %ebx, %es:16(%edi) )
22756 adcl %edx, %eax
22757-DST( movl %edx, 20(%edi) )
22758+DST( movl %edx, %es:20(%edi) )
22759
22760 SRC( movl 24(%esi), %ebx )
22761 SRC( movl 28(%esi), %edx )
22762 adcl %ebx, %eax
22763-DST( movl %ebx, 24(%edi) )
22764+DST( movl %ebx, %es:24(%edi) )
22765 adcl %edx, %eax
22766-DST( movl %edx, 28(%edi) )
22767+DST( movl %edx, %es:28(%edi) )
22768
22769 lea 32(%esi), %esi
22770 lea 32(%edi), %edi
22771@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
22772 shrl $2, %edx # This clears CF
22773 SRC(3: movl (%esi), %ebx )
22774 adcl %ebx, %eax
22775-DST( movl %ebx, (%edi) )
22776+DST( movl %ebx, %es:(%edi) )
22777 lea 4(%esi), %esi
22778 lea 4(%edi), %edi
22779 dec %edx
22780@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
22781 jb 5f
22782 SRC( movw (%esi), %cx )
22783 leal 2(%esi), %esi
22784-DST( movw %cx, (%edi) )
22785+DST( movw %cx, %es:(%edi) )
22786 leal 2(%edi), %edi
22787 je 6f
22788 shll $16,%ecx
22789 SRC(5: movb (%esi), %cl )
22790-DST( movb %cl, (%edi) )
22791+DST( movb %cl, %es:(%edi) )
22792 6: addl %ecx, %eax
22793 adcl $0, %eax
22794 7:
22795@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
22796
22797 6001:
22798 movl ARGBASE+20(%esp), %ebx # src_err_ptr
22799- movl $-EFAULT, (%ebx)
22800+ movl $-EFAULT, %ss:(%ebx)
22801
22802 # zero the complete destination - computing the rest
22803 # is too much work
22804@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
22805
22806 6002:
22807 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
22808- movl $-EFAULT,(%ebx)
22809+ movl $-EFAULT,%ss:(%ebx)
22810 jmp 5000b
22811
22812 .previous
22813
22814+ pushl_cfi %ss
22815+ popl_cfi %ds
22816+ pushl_cfi %ss
22817+ popl_cfi %es
22818 popl_cfi %ebx
22819 CFI_RESTORE ebx
22820 popl_cfi %esi
22821@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
22822 popl_cfi %ecx # equivalent to addl $4,%esp
22823 ret
22824 CFI_ENDPROC
22825-ENDPROC(csum_partial_copy_generic)
22826+ENDPROC(csum_partial_copy_generic_to_user)
22827
22828 #else
22829
22830 /* Version for PentiumII/PPro */
22831
22832 #define ROUND1(x) \
22833+ nop; nop; nop; \
22834 SRC(movl x(%esi), %ebx ) ; \
22835 addl %ebx, %eax ; \
22836- DST(movl %ebx, x(%edi) ) ;
22837+ DST(movl %ebx, %es:x(%edi)) ;
22838
22839 #define ROUND(x) \
22840+ nop; nop; nop; \
22841 SRC(movl x(%esi), %ebx ) ; \
22842 adcl %ebx, %eax ; \
22843- DST(movl %ebx, x(%edi) ) ;
22844+ DST(movl %ebx, %es:x(%edi)) ;
22845
22846 #define ARGBASE 12
22847-
22848-ENTRY(csum_partial_copy_generic)
22849+
22850+ENTRY(csum_partial_copy_generic_to_user)
22851 CFI_STARTPROC
22852+
22853+#ifdef CONFIG_PAX_MEMORY_UDEREF
22854+ pushl_cfi %gs
22855+ popl_cfi %es
22856+ jmp csum_partial_copy_generic
22857+#endif
22858+
22859+ENTRY(csum_partial_copy_generic_from_user)
22860+
22861+#ifdef CONFIG_PAX_MEMORY_UDEREF
22862+ pushl_cfi %gs
22863+ popl_cfi %ds
22864+#endif
22865+
22866+ENTRY(csum_partial_copy_generic)
22867 pushl_cfi %ebx
22868 CFI_REL_OFFSET ebx, 0
22869 pushl_cfi %edi
22870@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
22871 subl %ebx, %edi
22872 lea -1(%esi),%edx
22873 andl $-32,%edx
22874- lea 3f(%ebx,%ebx), %ebx
22875+ lea 3f(%ebx,%ebx,2), %ebx
22876 testl %esi, %esi
22877 jmp *%ebx
22878 1: addl $64,%esi
22879@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
22880 jb 5f
22881 SRC( movw (%esi), %dx )
22882 leal 2(%esi), %esi
22883-DST( movw %dx, (%edi) )
22884+DST( movw %dx, %es:(%edi) )
22885 leal 2(%edi), %edi
22886 je 6f
22887 shll $16,%edx
22888 5:
22889 SRC( movb (%esi), %dl )
22890-DST( movb %dl, (%edi) )
22891+DST( movb %dl, %es:(%edi) )
22892 6: addl %edx, %eax
22893 adcl $0, %eax
22894 7:
22895 .section .fixup, "ax"
22896 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
22897- movl $-EFAULT, (%ebx)
22898+ movl $-EFAULT, %ss:(%ebx)
22899 # zero the complete destination (computing the rest is too much work)
22900 movl ARGBASE+8(%esp),%edi # dst
22901 movl ARGBASE+12(%esp),%ecx # len
22902@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
22903 rep; stosb
22904 jmp 7b
22905 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
22906- movl $-EFAULT, (%ebx)
22907+ movl $-EFAULT, %ss:(%ebx)
22908 jmp 7b
22909 .previous
22910
22911+#ifdef CONFIG_PAX_MEMORY_UDEREF
22912+ pushl_cfi %ss
22913+ popl_cfi %ds
22914+ pushl_cfi %ss
22915+ popl_cfi %es
22916+#endif
22917+
22918 popl_cfi %esi
22919 CFI_RESTORE esi
22920 popl_cfi %edi
22921@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
22922 CFI_RESTORE ebx
22923 ret
22924 CFI_ENDPROC
22925-ENDPROC(csum_partial_copy_generic)
22926+ENDPROC(csum_partial_copy_generic_to_user)
22927
22928 #undef ROUND
22929 #undef ROUND1
22930diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
22931index f2145cf..cea889d 100644
22932--- a/arch/x86/lib/clear_page_64.S
22933+++ b/arch/x86/lib/clear_page_64.S
22934@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
22935 movl $4096/8,%ecx
22936 xorl %eax,%eax
22937 rep stosq
22938+ pax_force_retaddr
22939 ret
22940 CFI_ENDPROC
22941 ENDPROC(clear_page_c)
22942@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
22943 movl $4096,%ecx
22944 xorl %eax,%eax
22945 rep stosb
22946+ pax_force_retaddr
22947 ret
22948 CFI_ENDPROC
22949 ENDPROC(clear_page_c_e)
22950@@ -43,6 +45,7 @@ ENTRY(clear_page)
22951 leaq 64(%rdi),%rdi
22952 jnz .Lloop
22953 nop
22954+ pax_force_retaddr
22955 ret
22956 CFI_ENDPROC
22957 .Lclear_page_end:
22958@@ -58,7 +61,7 @@ ENDPROC(clear_page)
22959
22960 #include <asm/cpufeature.h>
22961
22962- .section .altinstr_replacement,"ax"
22963+ .section .altinstr_replacement,"a"
22964 1: .byte 0xeb /* jmp <disp8> */
22965 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
22966 2: .byte 0xeb /* jmp <disp8> */
22967diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
22968index 1e572c5..2a162cd 100644
22969--- a/arch/x86/lib/cmpxchg16b_emu.S
22970+++ b/arch/x86/lib/cmpxchg16b_emu.S
22971@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
22972
22973 popf
22974 mov $1, %al
22975+ pax_force_retaddr
22976 ret
22977
22978 not_same:
22979 popf
22980 xor %al,%al
22981+ pax_force_retaddr
22982 ret
22983
22984 CFI_ENDPROC
22985diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
22986index 6b34d04..dccb07f 100644
22987--- a/arch/x86/lib/copy_page_64.S
22988+++ b/arch/x86/lib/copy_page_64.S
22989@@ -9,6 +9,7 @@ copy_page_c:
22990 CFI_STARTPROC
22991 movl $4096/8,%ecx
22992 rep movsq
22993+ pax_force_retaddr
22994 ret
22995 CFI_ENDPROC
22996 ENDPROC(copy_page_c)
22997@@ -20,12 +21,14 @@ ENDPROC(copy_page_c)
22998
22999 ENTRY(copy_page)
23000 CFI_STARTPROC
23001- subq $2*8,%rsp
23002- CFI_ADJUST_CFA_OFFSET 2*8
23003+ subq $3*8,%rsp
23004+ CFI_ADJUST_CFA_OFFSET 3*8
23005 movq %rbx,(%rsp)
23006 CFI_REL_OFFSET rbx, 0
23007 movq %r12,1*8(%rsp)
23008 CFI_REL_OFFSET r12, 1*8
23009+ movq %r13,2*8(%rsp)
23010+ CFI_REL_OFFSET r13, 2*8
23011
23012 movl $(4096/64)-5,%ecx
23013 .p2align 4
23014@@ -37,7 +40,7 @@ ENTRY(copy_page)
23015 movq 16 (%rsi), %rdx
23016 movq 24 (%rsi), %r8
23017 movq 32 (%rsi), %r9
23018- movq 40 (%rsi), %r10
23019+ movq 40 (%rsi), %r13
23020 movq 48 (%rsi), %r11
23021 movq 56 (%rsi), %r12
23022
23023@@ -48,7 +51,7 @@ ENTRY(copy_page)
23024 movq %rdx, 16 (%rdi)
23025 movq %r8, 24 (%rdi)
23026 movq %r9, 32 (%rdi)
23027- movq %r10, 40 (%rdi)
23028+ movq %r13, 40 (%rdi)
23029 movq %r11, 48 (%rdi)
23030 movq %r12, 56 (%rdi)
23031
23032@@ -67,7 +70,7 @@ ENTRY(copy_page)
23033 movq 16 (%rsi), %rdx
23034 movq 24 (%rsi), %r8
23035 movq 32 (%rsi), %r9
23036- movq 40 (%rsi), %r10
23037+ movq 40 (%rsi), %r13
23038 movq 48 (%rsi), %r11
23039 movq 56 (%rsi), %r12
23040
23041@@ -76,7 +79,7 @@ ENTRY(copy_page)
23042 movq %rdx, 16 (%rdi)
23043 movq %r8, 24 (%rdi)
23044 movq %r9, 32 (%rdi)
23045- movq %r10, 40 (%rdi)
23046+ movq %r13, 40 (%rdi)
23047 movq %r11, 48 (%rdi)
23048 movq %r12, 56 (%rdi)
23049
23050@@ -89,8 +92,11 @@ ENTRY(copy_page)
23051 CFI_RESTORE rbx
23052 movq 1*8(%rsp),%r12
23053 CFI_RESTORE r12
23054- addq $2*8,%rsp
23055- CFI_ADJUST_CFA_OFFSET -2*8
23056+ movq 2*8(%rsp),%r13
23057+ CFI_RESTORE r13
23058+ addq $3*8,%rsp
23059+ CFI_ADJUST_CFA_OFFSET -3*8
23060+ pax_force_retaddr
23061 ret
23062 .Lcopy_page_end:
23063 CFI_ENDPROC
23064@@ -101,7 +107,7 @@ ENDPROC(copy_page)
23065
23066 #include <asm/cpufeature.h>
23067
23068- .section .altinstr_replacement,"ax"
23069+ .section .altinstr_replacement,"a"
23070 1: .byte 0xeb /* jmp <disp8> */
23071 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
23072 2:
23073diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
23074index a30ca15..d25fab6 100644
23075--- a/arch/x86/lib/copy_user_64.S
23076+++ b/arch/x86/lib/copy_user_64.S
23077@@ -18,6 +18,7 @@
23078 #include <asm/alternative-asm.h>
23079 #include <asm/asm.h>
23080 #include <asm/smap.h>
23081+#include <asm/pgtable.h>
23082
23083 /*
23084 * By placing feature2 after feature1 in altinstructions section, we logically
23085@@ -31,7 +32,7 @@
23086 .byte 0xe9 /* 32bit jump */
23087 .long \orig-1f /* by default jump to orig */
23088 1:
23089- .section .altinstr_replacement,"ax"
23090+ .section .altinstr_replacement,"a"
23091 2: .byte 0xe9 /* near jump with 32bit immediate */
23092 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
23093 3: .byte 0xe9 /* near jump with 32bit immediate */
23094@@ -70,47 +71,20 @@
23095 #endif
23096 .endm
23097
23098-/* Standard copy_to_user with segment limit checking */
23099-ENTRY(_copy_to_user)
23100- CFI_STARTPROC
23101- GET_THREAD_INFO(%rax)
23102- movq %rdi,%rcx
23103- addq %rdx,%rcx
23104- jc bad_to_user
23105- cmpq TI_addr_limit(%rax),%rcx
23106- ja bad_to_user
23107- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
23108- copy_user_generic_unrolled,copy_user_generic_string, \
23109- copy_user_enhanced_fast_string
23110- CFI_ENDPROC
23111-ENDPROC(_copy_to_user)
23112-
23113-/* Standard copy_from_user with segment limit checking */
23114-ENTRY(_copy_from_user)
23115- CFI_STARTPROC
23116- GET_THREAD_INFO(%rax)
23117- movq %rsi,%rcx
23118- addq %rdx,%rcx
23119- jc bad_from_user
23120- cmpq TI_addr_limit(%rax),%rcx
23121- ja bad_from_user
23122- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
23123- copy_user_generic_unrolled,copy_user_generic_string, \
23124- copy_user_enhanced_fast_string
23125- CFI_ENDPROC
23126-ENDPROC(_copy_from_user)
23127-
23128 .section .fixup,"ax"
23129 /* must zero dest */
23130 ENTRY(bad_from_user)
23131 bad_from_user:
23132 CFI_STARTPROC
23133+ testl %edx,%edx
23134+ js bad_to_user
23135 movl %edx,%ecx
23136 xorl %eax,%eax
23137 rep
23138 stosb
23139 bad_to_user:
23140 movl %edx,%eax
23141+ pax_force_retaddr
23142 ret
23143 CFI_ENDPROC
23144 ENDPROC(bad_from_user)
23145@@ -141,19 +115,19 @@ ENTRY(copy_user_generic_unrolled)
23146 jz 17f
23147 1: movq (%rsi),%r8
23148 2: movq 1*8(%rsi),%r9
23149-3: movq 2*8(%rsi),%r10
23150+3: movq 2*8(%rsi),%rax
23151 4: movq 3*8(%rsi),%r11
23152 5: movq %r8,(%rdi)
23153 6: movq %r9,1*8(%rdi)
23154-7: movq %r10,2*8(%rdi)
23155+7: movq %rax,2*8(%rdi)
23156 8: movq %r11,3*8(%rdi)
23157 9: movq 4*8(%rsi),%r8
23158 10: movq 5*8(%rsi),%r9
23159-11: movq 6*8(%rsi),%r10
23160+11: movq 6*8(%rsi),%rax
23161 12: movq 7*8(%rsi),%r11
23162 13: movq %r8,4*8(%rdi)
23163 14: movq %r9,5*8(%rdi)
23164-15: movq %r10,6*8(%rdi)
23165+15: movq %rax,6*8(%rdi)
23166 16: movq %r11,7*8(%rdi)
23167 leaq 64(%rsi),%rsi
23168 leaq 64(%rdi),%rdi
23169@@ -180,6 +154,7 @@ ENTRY(copy_user_generic_unrolled)
23170 jnz 21b
23171 23: xor %eax,%eax
23172 ASM_CLAC
23173+ pax_force_retaddr
23174 ret
23175
23176 .section .fixup,"ax"
23177@@ -251,6 +226,7 @@ ENTRY(copy_user_generic_string)
23178 movsb
23179 4: xorl %eax,%eax
23180 ASM_CLAC
23181+ pax_force_retaddr
23182 ret
23183
23184 .section .fixup,"ax"
23185@@ -286,6 +262,7 @@ ENTRY(copy_user_enhanced_fast_string)
23186 movsb
23187 2: xorl %eax,%eax
23188 ASM_CLAC
23189+ pax_force_retaddr
23190 ret
23191
23192 .section .fixup,"ax"
23193diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
23194index 6a4f43c..f5f9e26 100644
23195--- a/arch/x86/lib/copy_user_nocache_64.S
23196+++ b/arch/x86/lib/copy_user_nocache_64.S
23197@@ -8,6 +8,7 @@
23198
23199 #include <linux/linkage.h>
23200 #include <asm/dwarf2.h>
23201+#include <asm/alternative-asm.h>
23202
23203 #define FIX_ALIGNMENT 1
23204
23205@@ -16,6 +17,7 @@
23206 #include <asm/thread_info.h>
23207 #include <asm/asm.h>
23208 #include <asm/smap.h>
23209+#include <asm/pgtable.h>
23210
23211 .macro ALIGN_DESTINATION
23212 #ifdef FIX_ALIGNMENT
23213@@ -49,6 +51,15 @@
23214 */
23215 ENTRY(__copy_user_nocache)
23216 CFI_STARTPROC
23217+
23218+#ifdef CONFIG_PAX_MEMORY_UDEREF
23219+ mov $PAX_USER_SHADOW_BASE,%rcx
23220+ cmp %rcx,%rsi
23221+ jae 1f
23222+ add %rcx,%rsi
23223+1:
23224+#endif
23225+
23226 ASM_STAC
23227 cmpl $8,%edx
23228 jb 20f /* less then 8 bytes, go to byte copy loop */
23229@@ -59,19 +70,19 @@ ENTRY(__copy_user_nocache)
23230 jz 17f
23231 1: movq (%rsi),%r8
23232 2: movq 1*8(%rsi),%r9
23233-3: movq 2*8(%rsi),%r10
23234+3: movq 2*8(%rsi),%rax
23235 4: movq 3*8(%rsi),%r11
23236 5: movnti %r8,(%rdi)
23237 6: movnti %r9,1*8(%rdi)
23238-7: movnti %r10,2*8(%rdi)
23239+7: movnti %rax,2*8(%rdi)
23240 8: movnti %r11,3*8(%rdi)
23241 9: movq 4*8(%rsi),%r8
23242 10: movq 5*8(%rsi),%r9
23243-11: movq 6*8(%rsi),%r10
23244+11: movq 6*8(%rsi),%rax
23245 12: movq 7*8(%rsi),%r11
23246 13: movnti %r8,4*8(%rdi)
23247 14: movnti %r9,5*8(%rdi)
23248-15: movnti %r10,6*8(%rdi)
23249+15: movnti %rax,6*8(%rdi)
23250 16: movnti %r11,7*8(%rdi)
23251 leaq 64(%rsi),%rsi
23252 leaq 64(%rdi),%rdi
23253@@ -99,6 +110,7 @@ ENTRY(__copy_user_nocache)
23254 23: xorl %eax,%eax
23255 ASM_CLAC
23256 sfence
23257+ pax_force_retaddr
23258 ret
23259
23260 .section .fixup,"ax"
23261diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
23262index 2419d5f..953ee51 100644
23263--- a/arch/x86/lib/csum-copy_64.S
23264+++ b/arch/x86/lib/csum-copy_64.S
23265@@ -9,6 +9,7 @@
23266 #include <asm/dwarf2.h>
23267 #include <asm/errno.h>
23268 #include <asm/asm.h>
23269+#include <asm/alternative-asm.h>
23270
23271 /*
23272 * Checksum copy with exception handling.
23273@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
23274 CFI_RESTORE rbp
23275 addq $7*8, %rsp
23276 CFI_ADJUST_CFA_OFFSET -7*8
23277+ pax_force_retaddr 0, 1
23278 ret
23279 CFI_RESTORE_STATE
23280
23281diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
23282index 25b7ae8..169fafc 100644
23283--- a/arch/x86/lib/csum-wrappers_64.c
23284+++ b/arch/x86/lib/csum-wrappers_64.c
23285@@ -52,7 +52,7 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
23286 len -= 2;
23287 }
23288 }
23289- isum = csum_partial_copy_generic((__force const void *)src,
23290+ isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
23291 dst, len, isum, errp, NULL);
23292 if (unlikely(*errp))
23293 goto out_err;
23294@@ -105,7 +105,7 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
23295 }
23296
23297 *errp = 0;
23298- return csum_partial_copy_generic(src, (void __force *)dst,
23299+ return csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
23300 len, isum, NULL, errp);
23301 }
23302 EXPORT_SYMBOL(csum_partial_copy_to_user);
23303diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
23304index 156b9c8..b144132 100644
23305--- a/arch/x86/lib/getuser.S
23306+++ b/arch/x86/lib/getuser.S
23307@@ -34,17 +34,40 @@
23308 #include <asm/thread_info.h>
23309 #include <asm/asm.h>
23310 #include <asm/smap.h>
23311+#include <asm/segment.h>
23312+#include <asm/pgtable.h>
23313+#include <asm/alternative-asm.h>
23314+
23315+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
23316+#define __copyuser_seg gs;
23317+#else
23318+#define __copyuser_seg
23319+#endif
23320
23321 .text
23322 ENTRY(__get_user_1)
23323 CFI_STARTPROC
23324+
23325+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
23326 GET_THREAD_INFO(%_ASM_DX)
23327 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
23328 jae bad_get_user
23329 ASM_STAC
23330-1: movzb (%_ASM_AX),%edx
23331+
23332+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23333+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
23334+ cmp %_ASM_DX,%_ASM_AX
23335+ jae 1234f
23336+ add %_ASM_DX,%_ASM_AX
23337+1234:
23338+#endif
23339+
23340+#endif
23341+
23342+1: __copyuser_seg movzb (%_ASM_AX),%edx
23343 xor %eax,%eax
23344 ASM_CLAC
23345+ pax_force_retaddr
23346 ret
23347 CFI_ENDPROC
23348 ENDPROC(__get_user_1)
23349@@ -52,14 +75,28 @@ ENDPROC(__get_user_1)
23350 ENTRY(__get_user_2)
23351 CFI_STARTPROC
23352 add $1,%_ASM_AX
23353+
23354+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
23355 jc bad_get_user
23356 GET_THREAD_INFO(%_ASM_DX)
23357 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
23358 jae bad_get_user
23359 ASM_STAC
23360-2: movzwl -1(%_ASM_AX),%edx
23361+
23362+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23363+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
23364+ cmp %_ASM_DX,%_ASM_AX
23365+ jae 1234f
23366+ add %_ASM_DX,%_ASM_AX
23367+1234:
23368+#endif
23369+
23370+#endif
23371+
23372+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
23373 xor %eax,%eax
23374 ASM_CLAC
23375+ pax_force_retaddr
23376 ret
23377 CFI_ENDPROC
23378 ENDPROC(__get_user_2)
23379@@ -67,14 +104,28 @@ ENDPROC(__get_user_2)
23380 ENTRY(__get_user_4)
23381 CFI_STARTPROC
23382 add $3,%_ASM_AX
23383+
23384+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
23385 jc bad_get_user
23386 GET_THREAD_INFO(%_ASM_DX)
23387 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
23388 jae bad_get_user
23389 ASM_STAC
23390-3: mov -3(%_ASM_AX),%edx
23391+
23392+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23393+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
23394+ cmp %_ASM_DX,%_ASM_AX
23395+ jae 1234f
23396+ add %_ASM_DX,%_ASM_AX
23397+1234:
23398+#endif
23399+
23400+#endif
23401+
23402+3: __copyuser_seg mov -3(%_ASM_AX),%edx
23403 xor %eax,%eax
23404 ASM_CLAC
23405+ pax_force_retaddr
23406 ret
23407 CFI_ENDPROC
23408 ENDPROC(__get_user_4)
23409@@ -87,10 +138,20 @@ ENTRY(__get_user_8)
23410 GET_THREAD_INFO(%_ASM_DX)
23411 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
23412 jae bad_get_user
23413+
23414+#ifdef CONFIG_PAX_MEMORY_UDEREF
23415+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
23416+ cmp %_ASM_DX,%_ASM_AX
23417+ jae 1234f
23418+ add %_ASM_DX,%_ASM_AX
23419+1234:
23420+#endif
23421+
23422 ASM_STAC
23423 4: movq -7(%_ASM_AX),%_ASM_DX
23424 xor %eax,%eax
23425 ASM_CLAC
23426+ pax_force_retaddr
23427 ret
23428 CFI_ENDPROC
23429 ENDPROC(__get_user_8)
23430@@ -101,6 +162,7 @@ bad_get_user:
23431 xor %edx,%edx
23432 mov $(-EFAULT),%_ASM_AX
23433 ASM_CLAC
23434+ pax_force_retaddr
23435 ret
23436 CFI_ENDPROC
23437 END(bad_get_user)
23438diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
23439index 54fcffe..7be149e 100644
23440--- a/arch/x86/lib/insn.c
23441+++ b/arch/x86/lib/insn.c
23442@@ -20,8 +20,10 @@
23443
23444 #ifdef __KERNEL__
23445 #include <linux/string.h>
23446+#include <asm/pgtable_types.h>
23447 #else
23448 #include <string.h>
23449+#define ktla_ktva(addr) addr
23450 #endif
23451 #include <asm/inat.h>
23452 #include <asm/insn.h>
23453@@ -53,8 +55,8 @@
23454 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
23455 {
23456 memset(insn, 0, sizeof(*insn));
23457- insn->kaddr = kaddr;
23458- insn->next_byte = kaddr;
23459+ insn->kaddr = ktla_ktva(kaddr);
23460+ insn->next_byte = ktla_ktva(kaddr);
23461 insn->x86_64 = x86_64 ? 1 : 0;
23462 insn->opnd_bytes = 4;
23463 if (x86_64)
23464diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
23465index 05a95e7..326f2fa 100644
23466--- a/arch/x86/lib/iomap_copy_64.S
23467+++ b/arch/x86/lib/iomap_copy_64.S
23468@@ -17,6 +17,7 @@
23469
23470 #include <linux/linkage.h>
23471 #include <asm/dwarf2.h>
23472+#include <asm/alternative-asm.h>
23473
23474 /*
23475 * override generic version in lib/iomap_copy.c
23476@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
23477 CFI_STARTPROC
23478 movl %edx,%ecx
23479 rep movsd
23480+ pax_force_retaddr
23481 ret
23482 CFI_ENDPROC
23483 ENDPROC(__iowrite32_copy)
23484diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
23485index 1c273be..da9cc0e 100644
23486--- a/arch/x86/lib/memcpy_64.S
23487+++ b/arch/x86/lib/memcpy_64.S
23488@@ -33,6 +33,7 @@
23489 rep movsq
23490 movl %edx, %ecx
23491 rep movsb
23492+ pax_force_retaddr
23493 ret
23494 .Lmemcpy_e:
23495 .previous
23496@@ -49,6 +50,7 @@
23497 movq %rdi, %rax
23498 movq %rdx, %rcx
23499 rep movsb
23500+ pax_force_retaddr
23501 ret
23502 .Lmemcpy_e_e:
23503 .previous
23504@@ -76,13 +78,13 @@ ENTRY(memcpy)
23505 */
23506 movq 0*8(%rsi), %r8
23507 movq 1*8(%rsi), %r9
23508- movq 2*8(%rsi), %r10
23509+ movq 2*8(%rsi), %rcx
23510 movq 3*8(%rsi), %r11
23511 leaq 4*8(%rsi), %rsi
23512
23513 movq %r8, 0*8(%rdi)
23514 movq %r9, 1*8(%rdi)
23515- movq %r10, 2*8(%rdi)
23516+ movq %rcx, 2*8(%rdi)
23517 movq %r11, 3*8(%rdi)
23518 leaq 4*8(%rdi), %rdi
23519 jae .Lcopy_forward_loop
23520@@ -105,12 +107,12 @@ ENTRY(memcpy)
23521 subq $0x20, %rdx
23522 movq -1*8(%rsi), %r8
23523 movq -2*8(%rsi), %r9
23524- movq -3*8(%rsi), %r10
23525+ movq -3*8(%rsi), %rcx
23526 movq -4*8(%rsi), %r11
23527 leaq -4*8(%rsi), %rsi
23528 movq %r8, -1*8(%rdi)
23529 movq %r9, -2*8(%rdi)
23530- movq %r10, -3*8(%rdi)
23531+ movq %rcx, -3*8(%rdi)
23532 movq %r11, -4*8(%rdi)
23533 leaq -4*8(%rdi), %rdi
23534 jae .Lcopy_backward_loop
23535@@ -130,12 +132,13 @@ ENTRY(memcpy)
23536 */
23537 movq 0*8(%rsi), %r8
23538 movq 1*8(%rsi), %r9
23539- movq -2*8(%rsi, %rdx), %r10
23540+ movq -2*8(%rsi, %rdx), %rcx
23541 movq -1*8(%rsi, %rdx), %r11
23542 movq %r8, 0*8(%rdi)
23543 movq %r9, 1*8(%rdi)
23544- movq %r10, -2*8(%rdi, %rdx)
23545+ movq %rcx, -2*8(%rdi, %rdx)
23546 movq %r11, -1*8(%rdi, %rdx)
23547+ pax_force_retaddr
23548 retq
23549 .p2align 4
23550 .Lless_16bytes:
23551@@ -148,6 +151,7 @@ ENTRY(memcpy)
23552 movq -1*8(%rsi, %rdx), %r9
23553 movq %r8, 0*8(%rdi)
23554 movq %r9, -1*8(%rdi, %rdx)
23555+ pax_force_retaddr
23556 retq
23557 .p2align 4
23558 .Lless_8bytes:
23559@@ -161,6 +165,7 @@ ENTRY(memcpy)
23560 movl -4(%rsi, %rdx), %r8d
23561 movl %ecx, (%rdi)
23562 movl %r8d, -4(%rdi, %rdx)
23563+ pax_force_retaddr
23564 retq
23565 .p2align 4
23566 .Lless_3bytes:
23567@@ -179,6 +184,7 @@ ENTRY(memcpy)
23568 movb %cl, (%rdi)
23569
23570 .Lend:
23571+ pax_force_retaddr
23572 retq
23573 CFI_ENDPROC
23574 ENDPROC(memcpy)
23575diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
23576index ee16461..c39c199 100644
23577--- a/arch/x86/lib/memmove_64.S
23578+++ b/arch/x86/lib/memmove_64.S
23579@@ -61,13 +61,13 @@ ENTRY(memmove)
23580 5:
23581 sub $0x20, %rdx
23582 movq 0*8(%rsi), %r11
23583- movq 1*8(%rsi), %r10
23584+ movq 1*8(%rsi), %rcx
23585 movq 2*8(%rsi), %r9
23586 movq 3*8(%rsi), %r8
23587 leaq 4*8(%rsi), %rsi
23588
23589 movq %r11, 0*8(%rdi)
23590- movq %r10, 1*8(%rdi)
23591+ movq %rcx, 1*8(%rdi)
23592 movq %r9, 2*8(%rdi)
23593 movq %r8, 3*8(%rdi)
23594 leaq 4*8(%rdi), %rdi
23595@@ -81,10 +81,10 @@ ENTRY(memmove)
23596 4:
23597 movq %rdx, %rcx
23598 movq -8(%rsi, %rdx), %r11
23599- lea -8(%rdi, %rdx), %r10
23600+ lea -8(%rdi, %rdx), %r9
23601 shrq $3, %rcx
23602 rep movsq
23603- movq %r11, (%r10)
23604+ movq %r11, (%r9)
23605 jmp 13f
23606 .Lmemmove_end_forward:
23607
23608@@ -95,14 +95,14 @@ ENTRY(memmove)
23609 7:
23610 movq %rdx, %rcx
23611 movq (%rsi), %r11
23612- movq %rdi, %r10
23613+ movq %rdi, %r9
23614 leaq -8(%rsi, %rdx), %rsi
23615 leaq -8(%rdi, %rdx), %rdi
23616 shrq $3, %rcx
23617 std
23618 rep movsq
23619 cld
23620- movq %r11, (%r10)
23621+ movq %r11, (%r9)
23622 jmp 13f
23623
23624 /*
23625@@ -127,13 +127,13 @@ ENTRY(memmove)
23626 8:
23627 subq $0x20, %rdx
23628 movq -1*8(%rsi), %r11
23629- movq -2*8(%rsi), %r10
23630+ movq -2*8(%rsi), %rcx
23631 movq -3*8(%rsi), %r9
23632 movq -4*8(%rsi), %r8
23633 leaq -4*8(%rsi), %rsi
23634
23635 movq %r11, -1*8(%rdi)
23636- movq %r10, -2*8(%rdi)
23637+ movq %rcx, -2*8(%rdi)
23638 movq %r9, -3*8(%rdi)
23639 movq %r8, -4*8(%rdi)
23640 leaq -4*8(%rdi), %rdi
23641@@ -151,11 +151,11 @@ ENTRY(memmove)
23642 * Move data from 16 bytes to 31 bytes.
23643 */
23644 movq 0*8(%rsi), %r11
23645- movq 1*8(%rsi), %r10
23646+ movq 1*8(%rsi), %rcx
23647 movq -2*8(%rsi, %rdx), %r9
23648 movq -1*8(%rsi, %rdx), %r8
23649 movq %r11, 0*8(%rdi)
23650- movq %r10, 1*8(%rdi)
23651+ movq %rcx, 1*8(%rdi)
23652 movq %r9, -2*8(%rdi, %rdx)
23653 movq %r8, -1*8(%rdi, %rdx)
23654 jmp 13f
23655@@ -167,9 +167,9 @@ ENTRY(memmove)
23656 * Move data from 8 bytes to 15 bytes.
23657 */
23658 movq 0*8(%rsi), %r11
23659- movq -1*8(%rsi, %rdx), %r10
23660+ movq -1*8(%rsi, %rdx), %r9
23661 movq %r11, 0*8(%rdi)
23662- movq %r10, -1*8(%rdi, %rdx)
23663+ movq %r9, -1*8(%rdi, %rdx)
23664 jmp 13f
23665 10:
23666 cmpq $4, %rdx
23667@@ -178,9 +178,9 @@ ENTRY(memmove)
23668 * Move data from 4 bytes to 7 bytes.
23669 */
23670 movl (%rsi), %r11d
23671- movl -4(%rsi, %rdx), %r10d
23672+ movl -4(%rsi, %rdx), %r9d
23673 movl %r11d, (%rdi)
23674- movl %r10d, -4(%rdi, %rdx)
23675+ movl %r9d, -4(%rdi, %rdx)
23676 jmp 13f
23677 11:
23678 cmp $2, %rdx
23679@@ -189,9 +189,9 @@ ENTRY(memmove)
23680 * Move data from 2 bytes to 3 bytes.
23681 */
23682 movw (%rsi), %r11w
23683- movw -2(%rsi, %rdx), %r10w
23684+ movw -2(%rsi, %rdx), %r9w
23685 movw %r11w, (%rdi)
23686- movw %r10w, -2(%rdi, %rdx)
23687+ movw %r9w, -2(%rdi, %rdx)
23688 jmp 13f
23689 12:
23690 cmp $1, %rdx
23691@@ -202,6 +202,7 @@ ENTRY(memmove)
23692 movb (%rsi), %r11b
23693 movb %r11b, (%rdi)
23694 13:
23695+ pax_force_retaddr
23696 retq
23697 CFI_ENDPROC
23698
23699@@ -210,6 +211,7 @@ ENTRY(memmove)
23700 /* Forward moving data. */
23701 movq %rdx, %rcx
23702 rep movsb
23703+ pax_force_retaddr
23704 retq
23705 .Lmemmove_end_forward_efs:
23706 .previous
23707diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
23708index 2dcb380..963660a 100644
23709--- a/arch/x86/lib/memset_64.S
23710+++ b/arch/x86/lib/memset_64.S
23711@@ -30,6 +30,7 @@
23712 movl %edx,%ecx
23713 rep stosb
23714 movq %r9,%rax
23715+ pax_force_retaddr
23716 ret
23717 .Lmemset_e:
23718 .previous
23719@@ -52,6 +53,7 @@
23720 movq %rdx,%rcx
23721 rep stosb
23722 movq %r9,%rax
23723+ pax_force_retaddr
23724 ret
23725 .Lmemset_e_e:
23726 .previous
23727@@ -59,7 +61,7 @@
23728 ENTRY(memset)
23729 ENTRY(__memset)
23730 CFI_STARTPROC
23731- movq %rdi,%r10
23732+ movq %rdi,%r11
23733
23734 /* expand byte value */
23735 movzbl %sil,%ecx
23736@@ -117,7 +119,8 @@ ENTRY(__memset)
23737 jnz .Lloop_1
23738
23739 .Lende:
23740- movq %r10,%rax
23741+ movq %r11,%rax
23742+ pax_force_retaddr
23743 ret
23744
23745 CFI_RESTORE_STATE
23746diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
23747index c9f2d9b..e7fd2c0 100644
23748--- a/arch/x86/lib/mmx_32.c
23749+++ b/arch/x86/lib/mmx_32.c
23750@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
23751 {
23752 void *p;
23753 int i;
23754+ unsigned long cr0;
23755
23756 if (unlikely(in_interrupt()))
23757 return __memcpy(to, from, len);
23758@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
23759 kernel_fpu_begin();
23760
23761 __asm__ __volatile__ (
23762- "1: prefetch (%0)\n" /* This set is 28 bytes */
23763- " prefetch 64(%0)\n"
23764- " prefetch 128(%0)\n"
23765- " prefetch 192(%0)\n"
23766- " prefetch 256(%0)\n"
23767+ "1: prefetch (%1)\n" /* This set is 28 bytes */
23768+ " prefetch 64(%1)\n"
23769+ " prefetch 128(%1)\n"
23770+ " prefetch 192(%1)\n"
23771+ " prefetch 256(%1)\n"
23772 "2: \n"
23773 ".section .fixup, \"ax\"\n"
23774- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
23775+ "3: \n"
23776+
23777+#ifdef CONFIG_PAX_KERNEXEC
23778+ " movl %%cr0, %0\n"
23779+ " movl %0, %%eax\n"
23780+ " andl $0xFFFEFFFF, %%eax\n"
23781+ " movl %%eax, %%cr0\n"
23782+#endif
23783+
23784+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
23785+
23786+#ifdef CONFIG_PAX_KERNEXEC
23787+ " movl %0, %%cr0\n"
23788+#endif
23789+
23790 " jmp 2b\n"
23791 ".previous\n"
23792 _ASM_EXTABLE(1b, 3b)
23793- : : "r" (from));
23794+ : "=&r" (cr0) : "r" (from) : "ax");
23795
23796 for ( ; i > 5; i--) {
23797 __asm__ __volatile__ (
23798- "1: prefetch 320(%0)\n"
23799- "2: movq (%0), %%mm0\n"
23800- " movq 8(%0), %%mm1\n"
23801- " movq 16(%0), %%mm2\n"
23802- " movq 24(%0), %%mm3\n"
23803- " movq %%mm0, (%1)\n"
23804- " movq %%mm1, 8(%1)\n"
23805- " movq %%mm2, 16(%1)\n"
23806- " movq %%mm3, 24(%1)\n"
23807- " movq 32(%0), %%mm0\n"
23808- " movq 40(%0), %%mm1\n"
23809- " movq 48(%0), %%mm2\n"
23810- " movq 56(%0), %%mm3\n"
23811- " movq %%mm0, 32(%1)\n"
23812- " movq %%mm1, 40(%1)\n"
23813- " movq %%mm2, 48(%1)\n"
23814- " movq %%mm3, 56(%1)\n"
23815+ "1: prefetch 320(%1)\n"
23816+ "2: movq (%1), %%mm0\n"
23817+ " movq 8(%1), %%mm1\n"
23818+ " movq 16(%1), %%mm2\n"
23819+ " movq 24(%1), %%mm3\n"
23820+ " movq %%mm0, (%2)\n"
23821+ " movq %%mm1, 8(%2)\n"
23822+ " movq %%mm2, 16(%2)\n"
23823+ " movq %%mm3, 24(%2)\n"
23824+ " movq 32(%1), %%mm0\n"
23825+ " movq 40(%1), %%mm1\n"
23826+ " movq 48(%1), %%mm2\n"
23827+ " movq 56(%1), %%mm3\n"
23828+ " movq %%mm0, 32(%2)\n"
23829+ " movq %%mm1, 40(%2)\n"
23830+ " movq %%mm2, 48(%2)\n"
23831+ " movq %%mm3, 56(%2)\n"
23832 ".section .fixup, \"ax\"\n"
23833- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
23834+ "3:\n"
23835+
23836+#ifdef CONFIG_PAX_KERNEXEC
23837+ " movl %%cr0, %0\n"
23838+ " movl %0, %%eax\n"
23839+ " andl $0xFFFEFFFF, %%eax\n"
23840+ " movl %%eax, %%cr0\n"
23841+#endif
23842+
23843+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
23844+
23845+#ifdef CONFIG_PAX_KERNEXEC
23846+ " movl %0, %%cr0\n"
23847+#endif
23848+
23849 " jmp 2b\n"
23850 ".previous\n"
23851 _ASM_EXTABLE(1b, 3b)
23852- : : "r" (from), "r" (to) : "memory");
23853+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
23854
23855 from += 64;
23856 to += 64;
23857@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
23858 static void fast_copy_page(void *to, void *from)
23859 {
23860 int i;
23861+ unsigned long cr0;
23862
23863 kernel_fpu_begin();
23864
23865@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
23866 * but that is for later. -AV
23867 */
23868 __asm__ __volatile__(
23869- "1: prefetch (%0)\n"
23870- " prefetch 64(%0)\n"
23871- " prefetch 128(%0)\n"
23872- " prefetch 192(%0)\n"
23873- " prefetch 256(%0)\n"
23874+ "1: prefetch (%1)\n"
23875+ " prefetch 64(%1)\n"
23876+ " prefetch 128(%1)\n"
23877+ " prefetch 192(%1)\n"
23878+ " prefetch 256(%1)\n"
23879 "2: \n"
23880 ".section .fixup, \"ax\"\n"
23881- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
23882+ "3: \n"
23883+
23884+#ifdef CONFIG_PAX_KERNEXEC
23885+ " movl %%cr0, %0\n"
23886+ " movl %0, %%eax\n"
23887+ " andl $0xFFFEFFFF, %%eax\n"
23888+ " movl %%eax, %%cr0\n"
23889+#endif
23890+
23891+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
23892+
23893+#ifdef CONFIG_PAX_KERNEXEC
23894+ " movl %0, %%cr0\n"
23895+#endif
23896+
23897 " jmp 2b\n"
23898 ".previous\n"
23899- _ASM_EXTABLE(1b, 3b) : : "r" (from));
23900+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
23901
23902 for (i = 0; i < (4096-320)/64; i++) {
23903 __asm__ __volatile__ (
23904- "1: prefetch 320(%0)\n"
23905- "2: movq (%0), %%mm0\n"
23906- " movntq %%mm0, (%1)\n"
23907- " movq 8(%0), %%mm1\n"
23908- " movntq %%mm1, 8(%1)\n"
23909- " movq 16(%0), %%mm2\n"
23910- " movntq %%mm2, 16(%1)\n"
23911- " movq 24(%0), %%mm3\n"
23912- " movntq %%mm3, 24(%1)\n"
23913- " movq 32(%0), %%mm4\n"
23914- " movntq %%mm4, 32(%1)\n"
23915- " movq 40(%0), %%mm5\n"
23916- " movntq %%mm5, 40(%1)\n"
23917- " movq 48(%0), %%mm6\n"
23918- " movntq %%mm6, 48(%1)\n"
23919- " movq 56(%0), %%mm7\n"
23920- " movntq %%mm7, 56(%1)\n"
23921+ "1: prefetch 320(%1)\n"
23922+ "2: movq (%1), %%mm0\n"
23923+ " movntq %%mm0, (%2)\n"
23924+ " movq 8(%1), %%mm1\n"
23925+ " movntq %%mm1, 8(%2)\n"
23926+ " movq 16(%1), %%mm2\n"
23927+ " movntq %%mm2, 16(%2)\n"
23928+ " movq 24(%1), %%mm3\n"
23929+ " movntq %%mm3, 24(%2)\n"
23930+ " movq 32(%1), %%mm4\n"
23931+ " movntq %%mm4, 32(%2)\n"
23932+ " movq 40(%1), %%mm5\n"
23933+ " movntq %%mm5, 40(%2)\n"
23934+ " movq 48(%1), %%mm6\n"
23935+ " movntq %%mm6, 48(%2)\n"
23936+ " movq 56(%1), %%mm7\n"
23937+ " movntq %%mm7, 56(%2)\n"
23938 ".section .fixup, \"ax\"\n"
23939- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
23940+ "3:\n"
23941+
23942+#ifdef CONFIG_PAX_KERNEXEC
23943+ " movl %%cr0, %0\n"
23944+ " movl %0, %%eax\n"
23945+ " andl $0xFFFEFFFF, %%eax\n"
23946+ " movl %%eax, %%cr0\n"
23947+#endif
23948+
23949+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
23950+
23951+#ifdef CONFIG_PAX_KERNEXEC
23952+ " movl %0, %%cr0\n"
23953+#endif
23954+
23955 " jmp 2b\n"
23956 ".previous\n"
23957- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
23958+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
23959
23960 from += 64;
23961 to += 64;
23962@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
23963 static void fast_copy_page(void *to, void *from)
23964 {
23965 int i;
23966+ unsigned long cr0;
23967
23968 kernel_fpu_begin();
23969
23970 __asm__ __volatile__ (
23971- "1: prefetch (%0)\n"
23972- " prefetch 64(%0)\n"
23973- " prefetch 128(%0)\n"
23974- " prefetch 192(%0)\n"
23975- " prefetch 256(%0)\n"
23976+ "1: prefetch (%1)\n"
23977+ " prefetch 64(%1)\n"
23978+ " prefetch 128(%1)\n"
23979+ " prefetch 192(%1)\n"
23980+ " prefetch 256(%1)\n"
23981 "2: \n"
23982 ".section .fixup, \"ax\"\n"
23983- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
23984+ "3: \n"
23985+
23986+#ifdef CONFIG_PAX_KERNEXEC
23987+ " movl %%cr0, %0\n"
23988+ " movl %0, %%eax\n"
23989+ " andl $0xFFFEFFFF, %%eax\n"
23990+ " movl %%eax, %%cr0\n"
23991+#endif
23992+
23993+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
23994+
23995+#ifdef CONFIG_PAX_KERNEXEC
23996+ " movl %0, %%cr0\n"
23997+#endif
23998+
23999 " jmp 2b\n"
24000 ".previous\n"
24001- _ASM_EXTABLE(1b, 3b) : : "r" (from));
24002+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
24003
24004 for (i = 0; i < 4096/64; i++) {
24005 __asm__ __volatile__ (
24006- "1: prefetch 320(%0)\n"
24007- "2: movq (%0), %%mm0\n"
24008- " movq 8(%0), %%mm1\n"
24009- " movq 16(%0), %%mm2\n"
24010- " movq 24(%0), %%mm3\n"
24011- " movq %%mm0, (%1)\n"
24012- " movq %%mm1, 8(%1)\n"
24013- " movq %%mm2, 16(%1)\n"
24014- " movq %%mm3, 24(%1)\n"
24015- " movq 32(%0), %%mm0\n"
24016- " movq 40(%0), %%mm1\n"
24017- " movq 48(%0), %%mm2\n"
24018- " movq 56(%0), %%mm3\n"
24019- " movq %%mm0, 32(%1)\n"
24020- " movq %%mm1, 40(%1)\n"
24021- " movq %%mm2, 48(%1)\n"
24022- " movq %%mm3, 56(%1)\n"
24023+ "1: prefetch 320(%1)\n"
24024+ "2: movq (%1), %%mm0\n"
24025+ " movq 8(%1), %%mm1\n"
24026+ " movq 16(%1), %%mm2\n"
24027+ " movq 24(%1), %%mm3\n"
24028+ " movq %%mm0, (%2)\n"
24029+ " movq %%mm1, 8(%2)\n"
24030+ " movq %%mm2, 16(%2)\n"
24031+ " movq %%mm3, 24(%2)\n"
24032+ " movq 32(%1), %%mm0\n"
24033+ " movq 40(%1), %%mm1\n"
24034+ " movq 48(%1), %%mm2\n"
24035+ " movq 56(%1), %%mm3\n"
24036+ " movq %%mm0, 32(%2)\n"
24037+ " movq %%mm1, 40(%2)\n"
24038+ " movq %%mm2, 48(%2)\n"
24039+ " movq %%mm3, 56(%2)\n"
24040 ".section .fixup, \"ax\"\n"
24041- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
24042+ "3:\n"
24043+
24044+#ifdef CONFIG_PAX_KERNEXEC
24045+ " movl %%cr0, %0\n"
24046+ " movl %0, %%eax\n"
24047+ " andl $0xFFFEFFFF, %%eax\n"
24048+ " movl %%eax, %%cr0\n"
24049+#endif
24050+
24051+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
24052+
24053+#ifdef CONFIG_PAX_KERNEXEC
24054+ " movl %0, %%cr0\n"
24055+#endif
24056+
24057 " jmp 2b\n"
24058 ".previous\n"
24059 _ASM_EXTABLE(1b, 3b)
24060- : : "r" (from), "r" (to) : "memory");
24061+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
24062
24063 from += 64;
24064 to += 64;
24065diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
24066index f6d13ee..aca5f0b 100644
24067--- a/arch/x86/lib/msr-reg.S
24068+++ b/arch/x86/lib/msr-reg.S
24069@@ -3,6 +3,7 @@
24070 #include <asm/dwarf2.h>
24071 #include <asm/asm.h>
24072 #include <asm/msr.h>
24073+#include <asm/alternative-asm.h>
24074
24075 #ifdef CONFIG_X86_64
24076 /*
24077@@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
24078 CFI_STARTPROC
24079 pushq_cfi %rbx
24080 pushq_cfi %rbp
24081- movq %rdi, %r10 /* Save pointer */
24082+ movq %rdi, %r9 /* Save pointer */
24083 xorl %r11d, %r11d /* Return value */
24084 movl (%rdi), %eax
24085 movl 4(%rdi), %ecx
24086@@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
24087 movl 28(%rdi), %edi
24088 CFI_REMEMBER_STATE
24089 1: \op
24090-2: movl %eax, (%r10)
24091+2: movl %eax, (%r9)
24092 movl %r11d, %eax /* Return value */
24093- movl %ecx, 4(%r10)
24094- movl %edx, 8(%r10)
24095- movl %ebx, 12(%r10)
24096- movl %ebp, 20(%r10)
24097- movl %esi, 24(%r10)
24098- movl %edi, 28(%r10)
24099+ movl %ecx, 4(%r9)
24100+ movl %edx, 8(%r9)
24101+ movl %ebx, 12(%r9)
24102+ movl %ebp, 20(%r9)
24103+ movl %esi, 24(%r9)
24104+ movl %edi, 28(%r9)
24105 popq_cfi %rbp
24106 popq_cfi %rbx
24107+ pax_force_retaddr
24108 ret
24109 3:
24110 CFI_RESTORE_STATE
24111diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
24112index fc6ba17..04471c5 100644
24113--- a/arch/x86/lib/putuser.S
24114+++ b/arch/x86/lib/putuser.S
24115@@ -16,7 +16,9 @@
24116 #include <asm/errno.h>
24117 #include <asm/asm.h>
24118 #include <asm/smap.h>
24119-
24120+#include <asm/segment.h>
24121+#include <asm/pgtable.h>
24122+#include <asm/alternative-asm.h>
24123
24124 /*
24125 * __put_user_X
24126@@ -30,57 +32,125 @@
24127 * as they get called from within inline assembly.
24128 */
24129
24130-#define ENTER CFI_STARTPROC ; \
24131- GET_THREAD_INFO(%_ASM_BX)
24132-#define EXIT ASM_CLAC ; \
24133- ret ; \
24134+#define ENTER CFI_STARTPROC
24135+#define EXIT ASM_CLAC ; \
24136+ pax_force_retaddr ; \
24137+ ret ; \
24138 CFI_ENDPROC
24139
24140+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24141+#define _DEST %_ASM_CX,%_ASM_BX
24142+#else
24143+#define _DEST %_ASM_CX
24144+#endif
24145+
24146+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
24147+#define __copyuser_seg gs;
24148+#else
24149+#define __copyuser_seg
24150+#endif
24151+
24152 .text
24153 ENTRY(__put_user_1)
24154 ENTER
24155+
24156+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
24157+ GET_THREAD_INFO(%_ASM_BX)
24158 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
24159 jae bad_put_user
24160 ASM_STAC
24161-1: movb %al,(%_ASM_CX)
24162+
24163+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24164+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
24165+ cmp %_ASM_BX,%_ASM_CX
24166+ jb 1234f
24167+ xor %ebx,%ebx
24168+1234:
24169+#endif
24170+
24171+#endif
24172+
24173+1: __copyuser_seg movb %al,(_DEST)
24174 xor %eax,%eax
24175 EXIT
24176 ENDPROC(__put_user_1)
24177
24178 ENTRY(__put_user_2)
24179 ENTER
24180+
24181+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
24182+ GET_THREAD_INFO(%_ASM_BX)
24183 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
24184 sub $1,%_ASM_BX
24185 cmp %_ASM_BX,%_ASM_CX
24186 jae bad_put_user
24187 ASM_STAC
24188-2: movw %ax,(%_ASM_CX)
24189+
24190+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24191+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
24192+ cmp %_ASM_BX,%_ASM_CX
24193+ jb 1234f
24194+ xor %ebx,%ebx
24195+1234:
24196+#endif
24197+
24198+#endif
24199+
24200+2: __copyuser_seg movw %ax,(_DEST)
24201 xor %eax,%eax
24202 EXIT
24203 ENDPROC(__put_user_2)
24204
24205 ENTRY(__put_user_4)
24206 ENTER
24207+
24208+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
24209+ GET_THREAD_INFO(%_ASM_BX)
24210 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
24211 sub $3,%_ASM_BX
24212 cmp %_ASM_BX,%_ASM_CX
24213 jae bad_put_user
24214 ASM_STAC
24215-3: movl %eax,(%_ASM_CX)
24216+
24217+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24218+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
24219+ cmp %_ASM_BX,%_ASM_CX
24220+ jb 1234f
24221+ xor %ebx,%ebx
24222+1234:
24223+#endif
24224+
24225+#endif
24226+
24227+3: __copyuser_seg movl %eax,(_DEST)
24228 xor %eax,%eax
24229 EXIT
24230 ENDPROC(__put_user_4)
24231
24232 ENTRY(__put_user_8)
24233 ENTER
24234+
24235+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
24236+ GET_THREAD_INFO(%_ASM_BX)
24237 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
24238 sub $7,%_ASM_BX
24239 cmp %_ASM_BX,%_ASM_CX
24240 jae bad_put_user
24241 ASM_STAC
24242-4: mov %_ASM_AX,(%_ASM_CX)
24243+
24244+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24245+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
24246+ cmp %_ASM_BX,%_ASM_CX
24247+ jb 1234f
24248+ xor %ebx,%ebx
24249+1234:
24250+#endif
24251+
24252+#endif
24253+
24254+4: __copyuser_seg mov %_ASM_AX,(_DEST)
24255 #ifdef CONFIG_X86_32
24256-5: movl %edx,4(%_ASM_CX)
24257+5: __copyuser_seg movl %edx,4(_DEST)
24258 #endif
24259 xor %eax,%eax
24260 EXIT
24261diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
24262index 1cad221..de671ee 100644
24263--- a/arch/x86/lib/rwlock.S
24264+++ b/arch/x86/lib/rwlock.S
24265@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
24266 FRAME
24267 0: LOCK_PREFIX
24268 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
24269+
24270+#ifdef CONFIG_PAX_REFCOUNT
24271+ jno 1234f
24272+ LOCK_PREFIX
24273+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
24274+ int $4
24275+1234:
24276+ _ASM_EXTABLE(1234b, 1234b)
24277+#endif
24278+
24279 1: rep; nop
24280 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
24281 jne 1b
24282 LOCK_PREFIX
24283 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
24284+
24285+#ifdef CONFIG_PAX_REFCOUNT
24286+ jno 1234f
24287+ LOCK_PREFIX
24288+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
24289+ int $4
24290+1234:
24291+ _ASM_EXTABLE(1234b, 1234b)
24292+#endif
24293+
24294 jnz 0b
24295 ENDFRAME
24296+ pax_force_retaddr
24297 ret
24298 CFI_ENDPROC
24299 END(__write_lock_failed)
24300@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
24301 FRAME
24302 0: LOCK_PREFIX
24303 READ_LOCK_SIZE(inc) (%__lock_ptr)
24304+
24305+#ifdef CONFIG_PAX_REFCOUNT
24306+ jno 1234f
24307+ LOCK_PREFIX
24308+ READ_LOCK_SIZE(dec) (%__lock_ptr)
24309+ int $4
24310+1234:
24311+ _ASM_EXTABLE(1234b, 1234b)
24312+#endif
24313+
24314 1: rep; nop
24315 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
24316 js 1b
24317 LOCK_PREFIX
24318 READ_LOCK_SIZE(dec) (%__lock_ptr)
24319+
24320+#ifdef CONFIG_PAX_REFCOUNT
24321+ jno 1234f
24322+ LOCK_PREFIX
24323+ READ_LOCK_SIZE(inc) (%__lock_ptr)
24324+ int $4
24325+1234:
24326+ _ASM_EXTABLE(1234b, 1234b)
24327+#endif
24328+
24329 js 0b
24330 ENDFRAME
24331+ pax_force_retaddr
24332 ret
24333 CFI_ENDPROC
24334 END(__read_lock_failed)
24335diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
24336index 5dff5f0..cadebf4 100644
24337--- a/arch/x86/lib/rwsem.S
24338+++ b/arch/x86/lib/rwsem.S
24339@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
24340 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
24341 CFI_RESTORE __ASM_REG(dx)
24342 restore_common_regs
24343+ pax_force_retaddr
24344 ret
24345 CFI_ENDPROC
24346 ENDPROC(call_rwsem_down_read_failed)
24347@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
24348 movq %rax,%rdi
24349 call rwsem_down_write_failed
24350 restore_common_regs
24351+ pax_force_retaddr
24352 ret
24353 CFI_ENDPROC
24354 ENDPROC(call_rwsem_down_write_failed)
24355@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
24356 movq %rax,%rdi
24357 call rwsem_wake
24358 restore_common_regs
24359-1: ret
24360+1: pax_force_retaddr
24361+ ret
24362 CFI_ENDPROC
24363 ENDPROC(call_rwsem_wake)
24364
24365@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
24366 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
24367 CFI_RESTORE __ASM_REG(dx)
24368 restore_common_regs
24369+ pax_force_retaddr
24370 ret
24371 CFI_ENDPROC
24372 ENDPROC(call_rwsem_downgrade_wake)
24373diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
24374index a63efd6..ccecad8 100644
24375--- a/arch/x86/lib/thunk_64.S
24376+++ b/arch/x86/lib/thunk_64.S
24377@@ -8,6 +8,7 @@
24378 #include <linux/linkage.h>
24379 #include <asm/dwarf2.h>
24380 #include <asm/calling.h>
24381+#include <asm/alternative-asm.h>
24382
24383 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
24384 .macro THUNK name, func, put_ret_addr_in_rdi=0
24385@@ -41,5 +42,6 @@
24386 SAVE_ARGS
24387 restore:
24388 RESTORE_ARGS
24389+ pax_force_retaddr
24390 ret
24391 CFI_ENDPROC
24392diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
24393index 98f6d6b6..d27f045 100644
24394--- a/arch/x86/lib/usercopy_32.c
24395+++ b/arch/x86/lib/usercopy_32.c
24396@@ -42,11 +42,13 @@ do { \
24397 int __d0; \
24398 might_fault(); \
24399 __asm__ __volatile__( \
24400+ __COPYUSER_SET_ES \
24401 ASM_STAC "\n" \
24402 "0: rep; stosl\n" \
24403 " movl %2,%0\n" \
24404 "1: rep; stosb\n" \
24405 "2: " ASM_CLAC "\n" \
24406+ __COPYUSER_RESTORE_ES \
24407 ".section .fixup,\"ax\"\n" \
24408 "3: lea 0(%2,%0,4),%0\n" \
24409 " jmp 2b\n" \
24410@@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
24411
24412 #ifdef CONFIG_X86_INTEL_USERCOPY
24413 static unsigned long
24414-__copy_user_intel(void __user *to, const void *from, unsigned long size)
24415+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
24416 {
24417 int d0, d1;
24418 __asm__ __volatile__(
24419@@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
24420 " .align 2,0x90\n"
24421 "3: movl 0(%4), %%eax\n"
24422 "4: movl 4(%4), %%edx\n"
24423- "5: movl %%eax, 0(%3)\n"
24424- "6: movl %%edx, 4(%3)\n"
24425+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
24426+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
24427 "7: movl 8(%4), %%eax\n"
24428 "8: movl 12(%4),%%edx\n"
24429- "9: movl %%eax, 8(%3)\n"
24430- "10: movl %%edx, 12(%3)\n"
24431+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
24432+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
24433 "11: movl 16(%4), %%eax\n"
24434 "12: movl 20(%4), %%edx\n"
24435- "13: movl %%eax, 16(%3)\n"
24436- "14: movl %%edx, 20(%3)\n"
24437+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
24438+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
24439 "15: movl 24(%4), %%eax\n"
24440 "16: movl 28(%4), %%edx\n"
24441- "17: movl %%eax, 24(%3)\n"
24442- "18: movl %%edx, 28(%3)\n"
24443+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
24444+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
24445 "19: movl 32(%4), %%eax\n"
24446 "20: movl 36(%4), %%edx\n"
24447- "21: movl %%eax, 32(%3)\n"
24448- "22: movl %%edx, 36(%3)\n"
24449+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
24450+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
24451 "23: movl 40(%4), %%eax\n"
24452 "24: movl 44(%4), %%edx\n"
24453- "25: movl %%eax, 40(%3)\n"
24454- "26: movl %%edx, 44(%3)\n"
24455+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
24456+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
24457 "27: movl 48(%4), %%eax\n"
24458 "28: movl 52(%4), %%edx\n"
24459- "29: movl %%eax, 48(%3)\n"
24460- "30: movl %%edx, 52(%3)\n"
24461+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
24462+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
24463 "31: movl 56(%4), %%eax\n"
24464 "32: movl 60(%4), %%edx\n"
24465- "33: movl %%eax, 56(%3)\n"
24466- "34: movl %%edx, 60(%3)\n"
24467+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
24468+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
24469 " addl $-64, %0\n"
24470 " addl $64, %4\n"
24471 " addl $64, %3\n"
24472@@ -149,10 +151,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
24473 " shrl $2, %0\n"
24474 " andl $3, %%eax\n"
24475 " cld\n"
24476+ __COPYUSER_SET_ES
24477 "99: rep; movsl\n"
24478 "36: movl %%eax, %0\n"
24479 "37: rep; movsb\n"
24480 "100:\n"
24481+ __COPYUSER_RESTORE_ES
24482 ".section .fixup,\"ax\"\n"
24483 "101: lea 0(%%eax,%0,4),%0\n"
24484 " jmp 100b\n"
24485@@ -202,46 +206,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
24486 }
24487
24488 static unsigned long
24489+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
24490+{
24491+ int d0, d1;
24492+ __asm__ __volatile__(
24493+ " .align 2,0x90\n"
24494+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
24495+ " cmpl $67, %0\n"
24496+ " jbe 3f\n"
24497+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
24498+ " .align 2,0x90\n"
24499+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
24500+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
24501+ "5: movl %%eax, 0(%3)\n"
24502+ "6: movl %%edx, 4(%3)\n"
24503+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
24504+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
24505+ "9: movl %%eax, 8(%3)\n"
24506+ "10: movl %%edx, 12(%3)\n"
24507+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
24508+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
24509+ "13: movl %%eax, 16(%3)\n"
24510+ "14: movl %%edx, 20(%3)\n"
24511+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
24512+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
24513+ "17: movl %%eax, 24(%3)\n"
24514+ "18: movl %%edx, 28(%3)\n"
24515+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
24516+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
24517+ "21: movl %%eax, 32(%3)\n"
24518+ "22: movl %%edx, 36(%3)\n"
24519+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
24520+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
24521+ "25: movl %%eax, 40(%3)\n"
24522+ "26: movl %%edx, 44(%3)\n"
24523+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
24524+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
24525+ "29: movl %%eax, 48(%3)\n"
24526+ "30: movl %%edx, 52(%3)\n"
24527+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
24528+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
24529+ "33: movl %%eax, 56(%3)\n"
24530+ "34: movl %%edx, 60(%3)\n"
24531+ " addl $-64, %0\n"
24532+ " addl $64, %4\n"
24533+ " addl $64, %3\n"
24534+ " cmpl $63, %0\n"
24535+ " ja 1b\n"
24536+ "35: movl %0, %%eax\n"
24537+ " shrl $2, %0\n"
24538+ " andl $3, %%eax\n"
24539+ " cld\n"
24540+ "99: rep; "__copyuser_seg" movsl\n"
24541+ "36: movl %%eax, %0\n"
24542+ "37: rep; "__copyuser_seg" movsb\n"
24543+ "100:\n"
24544+ ".section .fixup,\"ax\"\n"
24545+ "101: lea 0(%%eax,%0,4),%0\n"
24546+ " jmp 100b\n"
24547+ ".previous\n"
24548+ _ASM_EXTABLE(1b,100b)
24549+ _ASM_EXTABLE(2b,100b)
24550+ _ASM_EXTABLE(3b,100b)
24551+ _ASM_EXTABLE(4b,100b)
24552+ _ASM_EXTABLE(5b,100b)
24553+ _ASM_EXTABLE(6b,100b)
24554+ _ASM_EXTABLE(7b,100b)
24555+ _ASM_EXTABLE(8b,100b)
24556+ _ASM_EXTABLE(9b,100b)
24557+ _ASM_EXTABLE(10b,100b)
24558+ _ASM_EXTABLE(11b,100b)
24559+ _ASM_EXTABLE(12b,100b)
24560+ _ASM_EXTABLE(13b,100b)
24561+ _ASM_EXTABLE(14b,100b)
24562+ _ASM_EXTABLE(15b,100b)
24563+ _ASM_EXTABLE(16b,100b)
24564+ _ASM_EXTABLE(17b,100b)
24565+ _ASM_EXTABLE(18b,100b)
24566+ _ASM_EXTABLE(19b,100b)
24567+ _ASM_EXTABLE(20b,100b)
24568+ _ASM_EXTABLE(21b,100b)
24569+ _ASM_EXTABLE(22b,100b)
24570+ _ASM_EXTABLE(23b,100b)
24571+ _ASM_EXTABLE(24b,100b)
24572+ _ASM_EXTABLE(25b,100b)
24573+ _ASM_EXTABLE(26b,100b)
24574+ _ASM_EXTABLE(27b,100b)
24575+ _ASM_EXTABLE(28b,100b)
24576+ _ASM_EXTABLE(29b,100b)
24577+ _ASM_EXTABLE(30b,100b)
24578+ _ASM_EXTABLE(31b,100b)
24579+ _ASM_EXTABLE(32b,100b)
24580+ _ASM_EXTABLE(33b,100b)
24581+ _ASM_EXTABLE(34b,100b)
24582+ _ASM_EXTABLE(35b,100b)
24583+ _ASM_EXTABLE(36b,100b)
24584+ _ASM_EXTABLE(37b,100b)
24585+ _ASM_EXTABLE(99b,101b)
24586+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
24587+ : "1"(to), "2"(from), "0"(size)
24588+ : "eax", "edx", "memory");
24589+ return size;
24590+}
24591+
24592+static unsigned long __size_overflow(3)
24593 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
24594 {
24595 int d0, d1;
24596 __asm__ __volatile__(
24597 " .align 2,0x90\n"
24598- "0: movl 32(%4), %%eax\n"
24599+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
24600 " cmpl $67, %0\n"
24601 " jbe 2f\n"
24602- "1: movl 64(%4), %%eax\n"
24603+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
24604 " .align 2,0x90\n"
24605- "2: movl 0(%4), %%eax\n"
24606- "21: movl 4(%4), %%edx\n"
24607+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
24608+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
24609 " movl %%eax, 0(%3)\n"
24610 " movl %%edx, 4(%3)\n"
24611- "3: movl 8(%4), %%eax\n"
24612- "31: movl 12(%4),%%edx\n"
24613+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
24614+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
24615 " movl %%eax, 8(%3)\n"
24616 " movl %%edx, 12(%3)\n"
24617- "4: movl 16(%4), %%eax\n"
24618- "41: movl 20(%4), %%edx\n"
24619+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
24620+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
24621 " movl %%eax, 16(%3)\n"
24622 " movl %%edx, 20(%3)\n"
24623- "10: movl 24(%4), %%eax\n"
24624- "51: movl 28(%4), %%edx\n"
24625+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
24626+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
24627 " movl %%eax, 24(%3)\n"
24628 " movl %%edx, 28(%3)\n"
24629- "11: movl 32(%4), %%eax\n"
24630- "61: movl 36(%4), %%edx\n"
24631+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
24632+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
24633 " movl %%eax, 32(%3)\n"
24634 " movl %%edx, 36(%3)\n"
24635- "12: movl 40(%4), %%eax\n"
24636- "71: movl 44(%4), %%edx\n"
24637+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
24638+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
24639 " movl %%eax, 40(%3)\n"
24640 " movl %%edx, 44(%3)\n"
24641- "13: movl 48(%4), %%eax\n"
24642- "81: movl 52(%4), %%edx\n"
24643+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
24644+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
24645 " movl %%eax, 48(%3)\n"
24646 " movl %%edx, 52(%3)\n"
24647- "14: movl 56(%4), %%eax\n"
24648- "91: movl 60(%4), %%edx\n"
24649+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
24650+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
24651 " movl %%eax, 56(%3)\n"
24652 " movl %%edx, 60(%3)\n"
24653 " addl $-64, %0\n"
24654@@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
24655 " shrl $2, %0\n"
24656 " andl $3, %%eax\n"
24657 " cld\n"
24658- "6: rep; movsl\n"
24659+ "6: rep; "__copyuser_seg" movsl\n"
24660 " movl %%eax,%0\n"
24661- "7: rep; movsb\n"
24662+ "7: rep; "__copyuser_seg" movsb\n"
24663 "8:\n"
24664 ".section .fixup,\"ax\"\n"
24665 "9: lea 0(%%eax,%0,4),%0\n"
24666@@ -298,48 +406,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
24667 * hyoshiok@miraclelinux.com
24668 */
24669
24670-static unsigned long __copy_user_zeroing_intel_nocache(void *to,
24671+static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
24672 const void __user *from, unsigned long size)
24673 {
24674 int d0, d1;
24675
24676 __asm__ __volatile__(
24677 " .align 2,0x90\n"
24678- "0: movl 32(%4), %%eax\n"
24679+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
24680 " cmpl $67, %0\n"
24681 " jbe 2f\n"
24682- "1: movl 64(%4), %%eax\n"
24683+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
24684 " .align 2,0x90\n"
24685- "2: movl 0(%4), %%eax\n"
24686- "21: movl 4(%4), %%edx\n"
24687+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
24688+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
24689 " movnti %%eax, 0(%3)\n"
24690 " movnti %%edx, 4(%3)\n"
24691- "3: movl 8(%4), %%eax\n"
24692- "31: movl 12(%4),%%edx\n"
24693+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
24694+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
24695 " movnti %%eax, 8(%3)\n"
24696 " movnti %%edx, 12(%3)\n"
24697- "4: movl 16(%4), %%eax\n"
24698- "41: movl 20(%4), %%edx\n"
24699+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
24700+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
24701 " movnti %%eax, 16(%3)\n"
24702 " movnti %%edx, 20(%3)\n"
24703- "10: movl 24(%4), %%eax\n"
24704- "51: movl 28(%4), %%edx\n"
24705+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
24706+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
24707 " movnti %%eax, 24(%3)\n"
24708 " movnti %%edx, 28(%3)\n"
24709- "11: movl 32(%4), %%eax\n"
24710- "61: movl 36(%4), %%edx\n"
24711+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
24712+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
24713 " movnti %%eax, 32(%3)\n"
24714 " movnti %%edx, 36(%3)\n"
24715- "12: movl 40(%4), %%eax\n"
24716- "71: movl 44(%4), %%edx\n"
24717+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
24718+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
24719 " movnti %%eax, 40(%3)\n"
24720 " movnti %%edx, 44(%3)\n"
24721- "13: movl 48(%4), %%eax\n"
24722- "81: movl 52(%4), %%edx\n"
24723+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
24724+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
24725 " movnti %%eax, 48(%3)\n"
24726 " movnti %%edx, 52(%3)\n"
24727- "14: movl 56(%4), %%eax\n"
24728- "91: movl 60(%4), %%edx\n"
24729+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
24730+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
24731 " movnti %%eax, 56(%3)\n"
24732 " movnti %%edx, 60(%3)\n"
24733 " addl $-64, %0\n"
24734@@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
24735 " shrl $2, %0\n"
24736 " andl $3, %%eax\n"
24737 " cld\n"
24738- "6: rep; movsl\n"
24739+ "6: rep; "__copyuser_seg" movsl\n"
24740 " movl %%eax,%0\n"
24741- "7: rep; movsb\n"
24742+ "7: rep; "__copyuser_seg" movsb\n"
24743 "8:\n"
24744 ".section .fixup,\"ax\"\n"
24745 "9: lea 0(%%eax,%0,4),%0\n"
24746@@ -392,48 +500,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
24747 return size;
24748 }
24749
24750-static unsigned long __copy_user_intel_nocache(void *to,
24751+static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
24752 const void __user *from, unsigned long size)
24753 {
24754 int d0, d1;
24755
24756 __asm__ __volatile__(
24757 " .align 2,0x90\n"
24758- "0: movl 32(%4), %%eax\n"
24759+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
24760 " cmpl $67, %0\n"
24761 " jbe 2f\n"
24762- "1: movl 64(%4), %%eax\n"
24763+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
24764 " .align 2,0x90\n"
24765- "2: movl 0(%4), %%eax\n"
24766- "21: movl 4(%4), %%edx\n"
24767+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
24768+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
24769 " movnti %%eax, 0(%3)\n"
24770 " movnti %%edx, 4(%3)\n"
24771- "3: movl 8(%4), %%eax\n"
24772- "31: movl 12(%4),%%edx\n"
24773+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
24774+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
24775 " movnti %%eax, 8(%3)\n"
24776 " movnti %%edx, 12(%3)\n"
24777- "4: movl 16(%4), %%eax\n"
24778- "41: movl 20(%4), %%edx\n"
24779+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
24780+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
24781 " movnti %%eax, 16(%3)\n"
24782 " movnti %%edx, 20(%3)\n"
24783- "10: movl 24(%4), %%eax\n"
24784- "51: movl 28(%4), %%edx\n"
24785+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
24786+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
24787 " movnti %%eax, 24(%3)\n"
24788 " movnti %%edx, 28(%3)\n"
24789- "11: movl 32(%4), %%eax\n"
24790- "61: movl 36(%4), %%edx\n"
24791+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
24792+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
24793 " movnti %%eax, 32(%3)\n"
24794 " movnti %%edx, 36(%3)\n"
24795- "12: movl 40(%4), %%eax\n"
24796- "71: movl 44(%4), %%edx\n"
24797+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
24798+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
24799 " movnti %%eax, 40(%3)\n"
24800 " movnti %%edx, 44(%3)\n"
24801- "13: movl 48(%4), %%eax\n"
24802- "81: movl 52(%4), %%edx\n"
24803+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
24804+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
24805 " movnti %%eax, 48(%3)\n"
24806 " movnti %%edx, 52(%3)\n"
24807- "14: movl 56(%4), %%eax\n"
24808- "91: movl 60(%4), %%edx\n"
24809+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
24810+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
24811 " movnti %%eax, 56(%3)\n"
24812 " movnti %%edx, 60(%3)\n"
24813 " addl $-64, %0\n"
24814@@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
24815 " shrl $2, %0\n"
24816 " andl $3, %%eax\n"
24817 " cld\n"
24818- "6: rep; movsl\n"
24819+ "6: rep; "__copyuser_seg" movsl\n"
24820 " movl %%eax,%0\n"
24821- "7: rep; movsb\n"
24822+ "7: rep; "__copyuser_seg" movsb\n"
24823 "8:\n"
24824 ".section .fixup,\"ax\"\n"
24825 "9: lea 0(%%eax,%0,4),%0\n"
24826@@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
24827 */
24828 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
24829 unsigned long size);
24830-unsigned long __copy_user_intel(void __user *to, const void *from,
24831+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
24832+ unsigned long size);
24833+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
24834 unsigned long size);
24835 unsigned long __copy_user_zeroing_intel_nocache(void *to,
24836 const void __user *from, unsigned long size);
24837 #endif /* CONFIG_X86_INTEL_USERCOPY */
24838
24839 /* Generic arbitrary sized copy. */
24840-#define __copy_user(to, from, size) \
24841+#define __copy_user(to, from, size, prefix, set, restore) \
24842 do { \
24843 int __d0, __d1, __d2; \
24844 __asm__ __volatile__( \
24845+ set \
24846 " cmp $7,%0\n" \
24847 " jbe 1f\n" \
24848 " movl %1,%0\n" \
24849 " negl %0\n" \
24850 " andl $7,%0\n" \
24851 " subl %0,%3\n" \
24852- "4: rep; movsb\n" \
24853+ "4: rep; "prefix"movsb\n" \
24854 " movl %3,%0\n" \
24855 " shrl $2,%0\n" \
24856 " andl $3,%3\n" \
24857 " .align 2,0x90\n" \
24858- "0: rep; movsl\n" \
24859+ "0: rep; "prefix"movsl\n" \
24860 " movl %3,%0\n" \
24861- "1: rep; movsb\n" \
24862+ "1: rep; "prefix"movsb\n" \
24863 "2:\n" \
24864+ restore \
24865 ".section .fixup,\"ax\"\n" \
24866 "5: addl %3,%0\n" \
24867 " jmp 2b\n" \
24868@@ -538,14 +650,14 @@ do { \
24869 " negl %0\n" \
24870 " andl $7,%0\n" \
24871 " subl %0,%3\n" \
24872- "4: rep; movsb\n" \
24873+ "4: rep; "__copyuser_seg"movsb\n" \
24874 " movl %3,%0\n" \
24875 " shrl $2,%0\n" \
24876 " andl $3,%3\n" \
24877 " .align 2,0x90\n" \
24878- "0: rep; movsl\n" \
24879+ "0: rep; "__copyuser_seg"movsl\n" \
24880 " movl %3,%0\n" \
24881- "1: rep; movsb\n" \
24882+ "1: rep; "__copyuser_seg"movsb\n" \
24883 "2:\n" \
24884 ".section .fixup,\"ax\"\n" \
24885 "5: addl %3,%0\n" \
24886@@ -629,9 +741,9 @@ survive:
24887 #endif
24888 stac();
24889 if (movsl_is_ok(to, from, n))
24890- __copy_user(to, from, n);
24891+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
24892 else
24893- n = __copy_user_intel(to, from, n);
24894+ n = __generic_copy_to_user_intel(to, from, n);
24895 clac();
24896 return n;
24897 }
24898@@ -655,10 +767,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
24899 {
24900 stac();
24901 if (movsl_is_ok(to, from, n))
24902- __copy_user(to, from, n);
24903+ __copy_user(to, from, n, __copyuser_seg, "", "");
24904 else
24905- n = __copy_user_intel((void __user *)to,
24906- (const void *)from, n);
24907+ n = __generic_copy_from_user_intel(to, from, n);
24908 clac();
24909 return n;
24910 }
24911@@ -689,66 +800,51 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
24912 if (n > 64 && cpu_has_xmm2)
24913 n = __copy_user_intel_nocache(to, from, n);
24914 else
24915- __copy_user(to, from, n);
24916+ __copy_user(to, from, n, __copyuser_seg, "", "");
24917 #else
24918- __copy_user(to, from, n);
24919+ __copy_user(to, from, n, __copyuser_seg, "", "");
24920 #endif
24921 clac();
24922 return n;
24923 }
24924 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
24925
24926-/**
24927- * copy_to_user: - Copy a block of data into user space.
24928- * @to: Destination address, in user space.
24929- * @from: Source address, in kernel space.
24930- * @n: Number of bytes to copy.
24931- *
24932- * Context: User context only. This function may sleep.
24933- *
24934- * Copy data from kernel space to user space.
24935- *
24936- * Returns number of bytes that could not be copied.
24937- * On success, this will be zero.
24938- */
24939-unsigned long
24940-copy_to_user(void __user *to, const void *from, unsigned long n)
24941-{
24942- if (access_ok(VERIFY_WRITE, to, n))
24943- n = __copy_to_user(to, from, n);
24944- return n;
24945-}
24946-EXPORT_SYMBOL(copy_to_user);
24947-
24948-/**
24949- * copy_from_user: - Copy a block of data from user space.
24950- * @to: Destination address, in kernel space.
24951- * @from: Source address, in user space.
24952- * @n: Number of bytes to copy.
24953- *
24954- * Context: User context only. This function may sleep.
24955- *
24956- * Copy data from user space to kernel space.
24957- *
24958- * Returns number of bytes that could not be copied.
24959- * On success, this will be zero.
24960- *
24961- * If some data could not be copied, this function will pad the copied
24962- * data to the requested size using zero bytes.
24963- */
24964-unsigned long
24965-_copy_from_user(void *to, const void __user *from, unsigned long n)
24966-{
24967- if (access_ok(VERIFY_READ, from, n))
24968- n = __copy_from_user(to, from, n);
24969- else
24970- memset(to, 0, n);
24971- return n;
24972-}
24973-EXPORT_SYMBOL(_copy_from_user);
24974-
24975 void copy_from_user_overflow(void)
24976 {
24977 WARN(1, "Buffer overflow detected!\n");
24978 }
24979 EXPORT_SYMBOL(copy_from_user_overflow);
24980+
24981+void copy_to_user_overflow(void)
24982+{
24983+ WARN(1, "Buffer overflow detected!\n");
24984+}
24985+EXPORT_SYMBOL(copy_to_user_overflow);
24986+
24987+#ifdef CONFIG_PAX_MEMORY_UDEREF
24988+void __set_fs(mm_segment_t x)
24989+{
24990+ switch (x.seg) {
24991+ case 0:
24992+ loadsegment(gs, 0);
24993+ break;
24994+ case TASK_SIZE_MAX:
24995+ loadsegment(gs, __USER_DS);
24996+ break;
24997+ case -1UL:
24998+ loadsegment(gs, __KERNEL_DS);
24999+ break;
25000+ default:
25001+ BUG();
25002+ }
25003+ return;
25004+}
25005+EXPORT_SYMBOL(__set_fs);
25006+
25007+void set_fs(mm_segment_t x)
25008+{
25009+ current_thread_info()->addr_limit = x;
25010+ __set_fs(x);
25011+}
25012+EXPORT_SYMBOL(set_fs);
25013+#endif
25014diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
25015index 05928aa..b33dea1 100644
25016--- a/arch/x86/lib/usercopy_64.c
25017+++ b/arch/x86/lib/usercopy_64.c
25018@@ -39,7 +39,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
25019 _ASM_EXTABLE(0b,3b)
25020 _ASM_EXTABLE(1b,2b)
25021 : [size8] "=&c"(size), [dst] "=&D" (__d0)
25022- : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
25023+ : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
25024 [zero] "r" (0UL), [eight] "r" (8UL));
25025 clac();
25026 return size;
25027@@ -54,12 +54,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
25028 }
25029 EXPORT_SYMBOL(clear_user);
25030
25031-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
25032+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
25033 {
25034- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
25035- return copy_user_generic((__force void *)to, (__force void *)from, len);
25036- }
25037- return len;
25038+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
25039+ return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
25040+ return len;
25041 }
25042 EXPORT_SYMBOL(copy_in_user);
25043
25044@@ -69,7 +68,7 @@ EXPORT_SYMBOL(copy_in_user);
25045 * it is not necessary to optimize tail handling.
25046 */
25047 unsigned long
25048-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
25049+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
25050 {
25051 char c;
25052 unsigned zero_len;
25053@@ -87,3 +86,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
25054 clac();
25055 return len;
25056 }
25057+
25058+void copy_from_user_overflow(void)
25059+{
25060+ WARN(1, "Buffer overflow detected!\n");
25061+}
25062+EXPORT_SYMBOL(copy_from_user_overflow);
25063+
25064+void copy_to_user_overflow(void)
25065+{
25066+ WARN(1, "Buffer overflow detected!\n");
25067+}
25068+EXPORT_SYMBOL(copy_to_user_overflow);
25069diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
25070index 903ec1e..c4166b2 100644
25071--- a/arch/x86/mm/extable.c
25072+++ b/arch/x86/mm/extable.c
25073@@ -6,12 +6,24 @@
25074 static inline unsigned long
25075 ex_insn_addr(const struct exception_table_entry *x)
25076 {
25077- return (unsigned long)&x->insn + x->insn;
25078+ unsigned long reloc = 0;
25079+
25080+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25081+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
25082+#endif
25083+
25084+ return (unsigned long)&x->insn + x->insn + reloc;
25085 }
25086 static inline unsigned long
25087 ex_fixup_addr(const struct exception_table_entry *x)
25088 {
25089- return (unsigned long)&x->fixup + x->fixup;
25090+ unsigned long reloc = 0;
25091+
25092+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25093+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
25094+#endif
25095+
25096+ return (unsigned long)&x->fixup + x->fixup + reloc;
25097 }
25098
25099 int fixup_exception(struct pt_regs *regs)
25100@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
25101 unsigned long new_ip;
25102
25103 #ifdef CONFIG_PNPBIOS
25104- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
25105+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
25106 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
25107 extern u32 pnp_bios_is_utter_crap;
25108 pnp_bios_is_utter_crap = 1;
25109@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
25110 i += 4;
25111 p->fixup -= i;
25112 i += 4;
25113+
25114+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25115+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
25116+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
25117+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
25118+#endif
25119+
25120 }
25121 }
25122
25123diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
25124index 8e13ecb..60bf506 100644
25125--- a/arch/x86/mm/fault.c
25126+++ b/arch/x86/mm/fault.c
25127@@ -13,12 +13,19 @@
25128 #include <linux/perf_event.h> /* perf_sw_event */
25129 #include <linux/hugetlb.h> /* hstate_index_to_shift */
25130 #include <linux/prefetch.h> /* prefetchw */
25131+#include <linux/unistd.h>
25132+#include <linux/compiler.h>
25133
25134 #include <asm/traps.h> /* dotraplinkage, ... */
25135 #include <asm/pgalloc.h> /* pgd_*(), ... */
25136 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
25137 #include <asm/fixmap.h> /* VSYSCALL_START */
25138 #include <asm/rcu.h> /* exception_enter(), ... */
25139+#include <asm/tlbflush.h>
25140+
25141+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25142+#include <asm/stacktrace.h>
25143+#endif
25144
25145 /*
25146 * Page fault error code bits:
25147@@ -56,7 +63,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
25148 int ret = 0;
25149
25150 /* kprobe_running() needs smp_processor_id() */
25151- if (kprobes_built_in() && !user_mode_vm(regs)) {
25152+ if (kprobes_built_in() && !user_mode(regs)) {
25153 preempt_disable();
25154 if (kprobe_running() && kprobe_fault_handler(regs, 14))
25155 ret = 1;
25156@@ -117,7 +124,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
25157 return !instr_lo || (instr_lo>>1) == 1;
25158 case 0x00:
25159 /* Prefetch instruction is 0x0F0D or 0x0F18 */
25160- if (probe_kernel_address(instr, opcode))
25161+ if (user_mode(regs)) {
25162+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
25163+ return 0;
25164+ } else if (probe_kernel_address(instr, opcode))
25165 return 0;
25166
25167 *prefetch = (instr_lo == 0xF) &&
25168@@ -151,7 +161,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
25169 while (instr < max_instr) {
25170 unsigned char opcode;
25171
25172- if (probe_kernel_address(instr, opcode))
25173+ if (user_mode(regs)) {
25174+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
25175+ break;
25176+ } else if (probe_kernel_address(instr, opcode))
25177 break;
25178
25179 instr++;
25180@@ -182,6 +195,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
25181 force_sig_info(si_signo, &info, tsk);
25182 }
25183
25184+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25185+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
25186+#endif
25187+
25188+#ifdef CONFIG_PAX_EMUTRAMP
25189+static int pax_handle_fetch_fault(struct pt_regs *regs);
25190+#endif
25191+
25192+#ifdef CONFIG_PAX_PAGEEXEC
25193+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
25194+{
25195+ pgd_t *pgd;
25196+ pud_t *pud;
25197+ pmd_t *pmd;
25198+
25199+ pgd = pgd_offset(mm, address);
25200+ if (!pgd_present(*pgd))
25201+ return NULL;
25202+ pud = pud_offset(pgd, address);
25203+ if (!pud_present(*pud))
25204+ return NULL;
25205+ pmd = pmd_offset(pud, address);
25206+ if (!pmd_present(*pmd))
25207+ return NULL;
25208+ return pmd;
25209+}
25210+#endif
25211+
25212 DEFINE_SPINLOCK(pgd_lock);
25213 LIST_HEAD(pgd_list);
25214
25215@@ -232,10 +273,22 @@ void vmalloc_sync_all(void)
25216 for (address = VMALLOC_START & PMD_MASK;
25217 address >= TASK_SIZE && address < FIXADDR_TOP;
25218 address += PMD_SIZE) {
25219+
25220+#ifdef CONFIG_PAX_PER_CPU_PGD
25221+ unsigned long cpu;
25222+#else
25223 struct page *page;
25224+#endif
25225
25226 spin_lock(&pgd_lock);
25227+
25228+#ifdef CONFIG_PAX_PER_CPU_PGD
25229+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25230+ pgd_t *pgd = get_cpu_pgd(cpu);
25231+ pmd_t *ret;
25232+#else
25233 list_for_each_entry(page, &pgd_list, lru) {
25234+ pgd_t *pgd = page_address(page);
25235 spinlock_t *pgt_lock;
25236 pmd_t *ret;
25237
25238@@ -243,8 +296,13 @@ void vmalloc_sync_all(void)
25239 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
25240
25241 spin_lock(pgt_lock);
25242- ret = vmalloc_sync_one(page_address(page), address);
25243+#endif
25244+
25245+ ret = vmalloc_sync_one(pgd, address);
25246+
25247+#ifndef CONFIG_PAX_PER_CPU_PGD
25248 spin_unlock(pgt_lock);
25249+#endif
25250
25251 if (!ret)
25252 break;
25253@@ -278,6 +336,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
25254 * an interrupt in the middle of a task switch..
25255 */
25256 pgd_paddr = read_cr3();
25257+
25258+#ifdef CONFIG_PAX_PER_CPU_PGD
25259+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
25260+#endif
25261+
25262 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
25263 if (!pmd_k)
25264 return -1;
25265@@ -373,7 +436,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
25266 * happen within a race in page table update. In the later
25267 * case just flush:
25268 */
25269+
25270+#ifdef CONFIG_PAX_PER_CPU_PGD
25271+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
25272+ pgd = pgd_offset_cpu(smp_processor_id(), address);
25273+#else
25274 pgd = pgd_offset(current->active_mm, address);
25275+#endif
25276+
25277 pgd_ref = pgd_offset_k(address);
25278 if (pgd_none(*pgd_ref))
25279 return -1;
25280@@ -541,7 +611,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
25281 static int is_errata100(struct pt_regs *regs, unsigned long address)
25282 {
25283 #ifdef CONFIG_X86_64
25284- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
25285+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
25286 return 1;
25287 #endif
25288 return 0;
25289@@ -568,7 +638,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
25290 }
25291
25292 static const char nx_warning[] = KERN_CRIT
25293-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
25294+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
25295
25296 static void
25297 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
25298@@ -577,15 +647,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
25299 if (!oops_may_print())
25300 return;
25301
25302- if (error_code & PF_INSTR) {
25303+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
25304 unsigned int level;
25305
25306 pte_t *pte = lookup_address(address, &level);
25307
25308 if (pte && pte_present(*pte) && !pte_exec(*pte))
25309- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
25310+ printk(nx_warning, from_kuid(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
25311 }
25312
25313+#ifdef CONFIG_PAX_KERNEXEC
25314+ if (init_mm.start_code <= address && address < init_mm.end_code) {
25315+ if (current->signal->curr_ip)
25316+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
25317+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
25318+ from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
25319+ else
25320+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
25321+ from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
25322+ }
25323+#endif
25324+
25325 printk(KERN_ALERT "BUG: unable to handle kernel ");
25326 if (address < PAGE_SIZE)
25327 printk(KERN_CONT "NULL pointer dereference");
25328@@ -749,12 +831,30 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
25329 }
25330 #endif
25331
25332- if (unlikely(show_unhandled_signals))
25333- show_signal_msg(regs, error_code, address, tsk);
25334+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25335+ if (pax_is_fetch_fault(regs, error_code, address)) {
25336+
25337+#ifdef CONFIG_PAX_EMUTRAMP
25338+ switch (pax_handle_fetch_fault(regs)) {
25339+ case 2:
25340+ return;
25341+ }
25342+#endif
25343+
25344+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
25345+ do_group_exit(SIGKILL);
25346+ }
25347+#endif
25348
25349 /* Kernel addresses are always protection faults: */
25350+ if (address >= TASK_SIZE)
25351+ error_code |= PF_PROT;
25352+
25353+ if (show_unhandled_signals)
25354+ show_signal_msg(regs, error_code, address, tsk);
25355+
25356 tsk->thread.cr2 = address;
25357- tsk->thread.error_code = error_code | (address >= TASK_SIZE);
25358+ tsk->thread.error_code = error_code;
25359 tsk->thread.trap_nr = X86_TRAP_PF;
25360
25361 force_sig_info_fault(SIGSEGV, si_code, address, tsk, 0);
25362@@ -845,7 +945,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
25363 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
25364 printk(KERN_ERR
25365 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
25366- tsk->comm, tsk->pid, address);
25367+ tsk->comm, task_pid_nr(tsk), address);
25368 code = BUS_MCEERR_AR;
25369 }
25370 #endif
25371@@ -901,6 +1001,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
25372 return 1;
25373 }
25374
25375+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
25376+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
25377+{
25378+ pte_t *pte;
25379+ pmd_t *pmd;
25380+ spinlock_t *ptl;
25381+ unsigned char pte_mask;
25382+
25383+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
25384+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
25385+ return 0;
25386+
25387+ /* PaX: it's our fault, let's handle it if we can */
25388+
25389+ /* PaX: take a look at read faults before acquiring any locks */
25390+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
25391+ /* instruction fetch attempt from a protected page in user mode */
25392+ up_read(&mm->mmap_sem);
25393+
25394+#ifdef CONFIG_PAX_EMUTRAMP
25395+ switch (pax_handle_fetch_fault(regs)) {
25396+ case 2:
25397+ return 1;
25398+ }
25399+#endif
25400+
25401+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
25402+ do_group_exit(SIGKILL);
25403+ }
25404+
25405+ pmd = pax_get_pmd(mm, address);
25406+ if (unlikely(!pmd))
25407+ return 0;
25408+
25409+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
25410+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
25411+ pte_unmap_unlock(pte, ptl);
25412+ return 0;
25413+ }
25414+
25415+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
25416+ /* write attempt to a protected page in user mode */
25417+ pte_unmap_unlock(pte, ptl);
25418+ return 0;
25419+ }
25420+
25421+#ifdef CONFIG_SMP
25422+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
25423+#else
25424+ if (likely(address > get_limit(regs->cs)))
25425+#endif
25426+ {
25427+ set_pte(pte, pte_mkread(*pte));
25428+ __flush_tlb_one(address);
25429+ pte_unmap_unlock(pte, ptl);
25430+ up_read(&mm->mmap_sem);
25431+ return 1;
25432+ }
25433+
25434+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
25435+
25436+ /*
25437+ * PaX: fill DTLB with user rights and retry
25438+ */
25439+ __asm__ __volatile__ (
25440+ "orb %2,(%1)\n"
25441+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
25442+/*
25443+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
25444+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
25445+ * page fault when examined during a TLB load attempt. this is true not only
25446+ * for PTEs holding a non-present entry but also present entries that will
25447+ * raise a page fault (such as those set up by PaX, or the copy-on-write
25448+ * mechanism). in effect it means that we do *not* need to flush the TLBs
25449+ * for our target pages since their PTEs are simply not in the TLBs at all.
25450+
25451+ * the best thing in omitting it is that we gain around 15-20% speed in the
25452+ * fast path of the page fault handler and can get rid of tracing since we
25453+ * can no longer flush unintended entries.
25454+ */
25455+ "invlpg (%0)\n"
25456+#endif
25457+ __copyuser_seg"testb $0,(%0)\n"
25458+ "xorb %3,(%1)\n"
25459+ :
25460+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
25461+ : "memory", "cc");
25462+ pte_unmap_unlock(pte, ptl);
25463+ up_read(&mm->mmap_sem);
25464+ return 1;
25465+}
25466+#endif
25467+
25468 /*
25469 * Handle a spurious fault caused by a stale TLB entry.
25470 *
25471@@ -973,6 +1166,9 @@ int show_unhandled_signals = 1;
25472 static inline int
25473 access_error(unsigned long error_code, struct vm_area_struct *vma)
25474 {
25475+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
25476+ return 1;
25477+
25478 if (error_code & PF_WRITE) {
25479 /* write, present and write, not present: */
25480 if (unlikely(!(vma->vm_flags & VM_WRITE)))
25481@@ -1001,7 +1197,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
25482 if (error_code & PF_USER)
25483 return false;
25484
25485- if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
25486+ if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
25487 return false;
25488
25489 return true;
25490@@ -1017,18 +1213,33 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
25491 {
25492 struct vm_area_struct *vma;
25493 struct task_struct *tsk;
25494- unsigned long address;
25495 struct mm_struct *mm;
25496 int fault;
25497 int write = error_code & PF_WRITE;
25498 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
25499 (write ? FAULT_FLAG_WRITE : 0);
25500
25501- tsk = current;
25502- mm = tsk->mm;
25503-
25504 /* Get the faulting address: */
25505- address = read_cr2();
25506+ unsigned long address = read_cr2();
25507+
25508+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25509+ if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
25510+ if (!search_exception_tables(regs->ip)) {
25511+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
25512+ bad_area_nosemaphore(regs, error_code, address);
25513+ return;
25514+ }
25515+ if (address < PAX_USER_SHADOW_BASE) {
25516+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
25517+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
25518+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
25519+ } else
25520+ address -= PAX_USER_SHADOW_BASE;
25521+ }
25522+#endif
25523+
25524+ tsk = current;
25525+ mm = tsk->mm;
25526
25527 /*
25528 * Detect and handle instructions that would cause a page fault for
25529@@ -1089,7 +1300,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
25530 * User-mode registers count as a user access even for any
25531 * potential system fault or CPU buglet:
25532 */
25533- if (user_mode_vm(regs)) {
25534+ if (user_mode(regs)) {
25535 local_irq_enable();
25536 error_code |= PF_USER;
25537 } else {
25538@@ -1151,6 +1362,11 @@ retry:
25539 might_sleep();
25540 }
25541
25542+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
25543+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
25544+ return;
25545+#endif
25546+
25547 vma = find_vma(mm, address);
25548 if (unlikely(!vma)) {
25549 bad_area(regs, error_code, address);
25550@@ -1162,18 +1378,24 @@ retry:
25551 bad_area(regs, error_code, address);
25552 return;
25553 }
25554- if (error_code & PF_USER) {
25555- /*
25556- * Accessing the stack below %sp is always a bug.
25557- * The large cushion allows instructions like enter
25558- * and pusha to work. ("enter $65535, $31" pushes
25559- * 32 pointers and then decrements %sp by 65535.)
25560- */
25561- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
25562- bad_area(regs, error_code, address);
25563- return;
25564- }
25565+ /*
25566+ * Accessing the stack below %sp is always a bug.
25567+ * The large cushion allows instructions like enter
25568+ * and pusha to work. ("enter $65535, $31" pushes
25569+ * 32 pointers and then decrements %sp by 65535.)
25570+ */
25571+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
25572+ bad_area(regs, error_code, address);
25573+ return;
25574 }
25575+
25576+#ifdef CONFIG_PAX_SEGMEXEC
25577+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
25578+ bad_area(regs, error_code, address);
25579+ return;
25580+ }
25581+#endif
25582+
25583 if (unlikely(expand_stack(vma, address))) {
25584 bad_area(regs, error_code, address);
25585 return;
25586@@ -1237,3 +1459,292 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
25587 __do_page_fault(regs, error_code);
25588 exception_exit(regs);
25589 }
25590+
25591+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25592+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
25593+{
25594+ struct mm_struct *mm = current->mm;
25595+ unsigned long ip = regs->ip;
25596+
25597+ if (v8086_mode(regs))
25598+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
25599+
25600+#ifdef CONFIG_PAX_PAGEEXEC
25601+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
25602+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
25603+ return true;
25604+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
25605+ return true;
25606+ return false;
25607+ }
25608+#endif
25609+
25610+#ifdef CONFIG_PAX_SEGMEXEC
25611+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
25612+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
25613+ return true;
25614+ return false;
25615+ }
25616+#endif
25617+
25618+ return false;
25619+}
25620+#endif
25621+
25622+#ifdef CONFIG_PAX_EMUTRAMP
25623+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
25624+{
25625+ int err;
25626+
25627+ do { /* PaX: libffi trampoline emulation */
25628+ unsigned char mov, jmp;
25629+ unsigned int addr1, addr2;
25630+
25631+#ifdef CONFIG_X86_64
25632+ if ((regs->ip + 9) >> 32)
25633+ break;
25634+#endif
25635+
25636+ err = get_user(mov, (unsigned char __user *)regs->ip);
25637+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
25638+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
25639+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
25640+
25641+ if (err)
25642+ break;
25643+
25644+ if (mov == 0xB8 && jmp == 0xE9) {
25645+ regs->ax = addr1;
25646+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
25647+ return 2;
25648+ }
25649+ } while (0);
25650+
25651+ do { /* PaX: gcc trampoline emulation #1 */
25652+ unsigned char mov1, mov2;
25653+ unsigned short jmp;
25654+ unsigned int addr1, addr2;
25655+
25656+#ifdef CONFIG_X86_64
25657+ if ((regs->ip + 11) >> 32)
25658+ break;
25659+#endif
25660+
25661+ err = get_user(mov1, (unsigned char __user *)regs->ip);
25662+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
25663+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
25664+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
25665+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
25666+
25667+ if (err)
25668+ break;
25669+
25670+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
25671+ regs->cx = addr1;
25672+ regs->ax = addr2;
25673+ regs->ip = addr2;
25674+ return 2;
25675+ }
25676+ } while (0);
25677+
25678+ do { /* PaX: gcc trampoline emulation #2 */
25679+ unsigned char mov, jmp;
25680+ unsigned int addr1, addr2;
25681+
25682+#ifdef CONFIG_X86_64
25683+ if ((regs->ip + 9) >> 32)
25684+ break;
25685+#endif
25686+
25687+ err = get_user(mov, (unsigned char __user *)regs->ip);
25688+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
25689+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
25690+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
25691+
25692+ if (err)
25693+ break;
25694+
25695+ if (mov == 0xB9 && jmp == 0xE9) {
25696+ regs->cx = addr1;
25697+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
25698+ return 2;
25699+ }
25700+ } while (0);
25701+
25702+ return 1; /* PaX in action */
25703+}
25704+
25705+#ifdef CONFIG_X86_64
25706+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
25707+{
25708+ int err;
25709+
25710+ do { /* PaX: libffi trampoline emulation */
25711+ unsigned short mov1, mov2, jmp1;
25712+ unsigned char stcclc, jmp2;
25713+ unsigned long addr1, addr2;
25714+
25715+ err = get_user(mov1, (unsigned short __user *)regs->ip);
25716+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
25717+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
25718+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
25719+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
25720+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
25721+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
25722+
25723+ if (err)
25724+ break;
25725+
25726+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
25727+ regs->r11 = addr1;
25728+ regs->r10 = addr2;
25729+ if (stcclc == 0xF8)
25730+ regs->flags &= ~X86_EFLAGS_CF;
25731+ else
25732+ regs->flags |= X86_EFLAGS_CF;
25733+ regs->ip = addr1;
25734+ return 2;
25735+ }
25736+ } while (0);
25737+
25738+ do { /* PaX: gcc trampoline emulation #1 */
25739+ unsigned short mov1, mov2, jmp1;
25740+ unsigned char jmp2;
25741+ unsigned int addr1;
25742+ unsigned long addr2;
25743+
25744+ err = get_user(mov1, (unsigned short __user *)regs->ip);
25745+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
25746+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
25747+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
25748+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
25749+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
25750+
25751+ if (err)
25752+ break;
25753+
25754+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
25755+ regs->r11 = addr1;
25756+ regs->r10 = addr2;
25757+ regs->ip = addr1;
25758+ return 2;
25759+ }
25760+ } while (0);
25761+
25762+ do { /* PaX: gcc trampoline emulation #2 */
25763+ unsigned short mov1, mov2, jmp1;
25764+ unsigned char jmp2;
25765+ unsigned long addr1, addr2;
25766+
25767+ err = get_user(mov1, (unsigned short __user *)regs->ip);
25768+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
25769+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
25770+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
25771+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
25772+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
25773+
25774+ if (err)
25775+ break;
25776+
25777+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
25778+ regs->r11 = addr1;
25779+ regs->r10 = addr2;
25780+ regs->ip = addr1;
25781+ return 2;
25782+ }
25783+ } while (0);
25784+
25785+ return 1; /* PaX in action */
25786+}
25787+#endif
25788+
25789+/*
25790+ * PaX: decide what to do with offenders (regs->ip = fault address)
25791+ *
25792+ * returns 1 when task should be killed
25793+ * 2 when gcc trampoline was detected
25794+ */
25795+static int pax_handle_fetch_fault(struct pt_regs *regs)
25796+{
25797+ if (v8086_mode(regs))
25798+ return 1;
25799+
25800+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
25801+ return 1;
25802+
25803+#ifdef CONFIG_X86_32
25804+ return pax_handle_fetch_fault_32(regs);
25805+#else
25806+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
25807+ return pax_handle_fetch_fault_32(regs);
25808+ else
25809+ return pax_handle_fetch_fault_64(regs);
25810+#endif
25811+}
25812+#endif
25813+
25814+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25815+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
25816+{
25817+ long i;
25818+
25819+ printk(KERN_ERR "PAX: bytes at PC: ");
25820+ for (i = 0; i < 20; i++) {
25821+ unsigned char c;
25822+ if (get_user(c, (unsigned char __force_user *)pc+i))
25823+ printk(KERN_CONT "?? ");
25824+ else
25825+ printk(KERN_CONT "%02x ", c);
25826+ }
25827+ printk("\n");
25828+
25829+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
25830+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
25831+ unsigned long c;
25832+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
25833+#ifdef CONFIG_X86_32
25834+ printk(KERN_CONT "???????? ");
25835+#else
25836+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
25837+ printk(KERN_CONT "???????? ???????? ");
25838+ else
25839+ printk(KERN_CONT "???????????????? ");
25840+#endif
25841+ } else {
25842+#ifdef CONFIG_X86_64
25843+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
25844+ printk(KERN_CONT "%08x ", (unsigned int)c);
25845+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
25846+ } else
25847+#endif
25848+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
25849+ }
25850+ }
25851+ printk("\n");
25852+}
25853+#endif
25854+
25855+/**
25856+ * probe_kernel_write(): safely attempt to write to a location
25857+ * @dst: address to write to
25858+ * @src: pointer to the data that shall be written
25859+ * @size: size of the data chunk
25860+ *
25861+ * Safely write to address @dst from the buffer at @src. If a kernel fault
25862+ * happens, handle that and return -EFAULT.
25863+ */
25864+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
25865+{
25866+ long ret;
25867+ mm_segment_t old_fs = get_fs();
25868+
25869+ set_fs(KERNEL_DS);
25870+ pagefault_disable();
25871+ pax_open_kernel();
25872+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
25873+ pax_close_kernel();
25874+ pagefault_enable();
25875+ set_fs(old_fs);
25876+
25877+ return ret ? -EFAULT : 0;
25878+}
25879diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
25880index dd74e46..7d26398 100644
25881--- a/arch/x86/mm/gup.c
25882+++ b/arch/x86/mm/gup.c
25883@@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
25884 addr = start;
25885 len = (unsigned long) nr_pages << PAGE_SHIFT;
25886 end = start + len;
25887- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
25888+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
25889 (void __user *)start, len)))
25890 return 0;
25891
25892diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
25893index 6f31ee5..8ee4164 100644
25894--- a/arch/x86/mm/highmem_32.c
25895+++ b/arch/x86/mm/highmem_32.c
25896@@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
25897 idx = type + KM_TYPE_NR*smp_processor_id();
25898 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
25899 BUG_ON(!pte_none(*(kmap_pte-idx)));
25900+
25901+ pax_open_kernel();
25902 set_pte(kmap_pte-idx, mk_pte(page, prot));
25903+ pax_close_kernel();
25904+
25905 arch_flush_lazy_mmu_mode();
25906
25907 return (void *)vaddr;
25908diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
25909index 937bff5..dce75ff 100644
25910--- a/arch/x86/mm/hugetlbpage.c
25911+++ b/arch/x86/mm/hugetlbpage.c
25912@@ -276,13 +276,21 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
25913 struct hstate *h = hstate_file(file);
25914 struct mm_struct *mm = current->mm;
25915 struct vm_area_struct *vma;
25916- unsigned long start_addr;
25917+ unsigned long start_addr, pax_task_size = TASK_SIZE;
25918+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
25919+
25920+#ifdef CONFIG_PAX_SEGMEXEC
25921+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25922+ pax_task_size = SEGMEXEC_TASK_SIZE;
25923+#endif
25924+
25925+ pax_task_size -= PAGE_SIZE;
25926
25927 if (len > mm->cached_hole_size) {
25928- start_addr = mm->free_area_cache;
25929+ start_addr = mm->free_area_cache;
25930 } else {
25931- start_addr = TASK_UNMAPPED_BASE;
25932- mm->cached_hole_size = 0;
25933+ start_addr = mm->mmap_base;
25934+ mm->cached_hole_size = 0;
25935 }
25936
25937 full_search:
25938@@ -290,26 +298,27 @@ full_search:
25939
25940 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
25941 /* At this point: (!vma || addr < vma->vm_end). */
25942- if (TASK_SIZE - len < addr) {
25943+ if (pax_task_size - len < addr) {
25944 /*
25945 * Start a new search - just in case we missed
25946 * some holes.
25947 */
25948- if (start_addr != TASK_UNMAPPED_BASE) {
25949- start_addr = TASK_UNMAPPED_BASE;
25950+ if (start_addr != mm->mmap_base) {
25951+ start_addr = mm->mmap_base;
25952 mm->cached_hole_size = 0;
25953 goto full_search;
25954 }
25955 return -ENOMEM;
25956 }
25957- if (!vma || addr + len <= vma->vm_start) {
25958- mm->free_area_cache = addr + len;
25959- return addr;
25960- }
25961+ if (check_heap_stack_gap(vma, addr, len, offset))
25962+ break;
25963 if (addr + mm->cached_hole_size < vma->vm_start)
25964 mm->cached_hole_size = vma->vm_start - addr;
25965 addr = ALIGN(vma->vm_end, huge_page_size(h));
25966 }
25967+
25968+ mm->free_area_cache = addr + len;
25969+ return addr;
25970 }
25971
25972 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
25973@@ -320,9 +329,9 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
25974 struct mm_struct *mm = current->mm;
25975 struct vm_area_struct *vma;
25976 unsigned long base = mm->mmap_base;
25977- unsigned long addr = addr0;
25978+ unsigned long addr;
25979 unsigned long largest_hole = mm->cached_hole_size;
25980- unsigned long start_addr;
25981+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
25982
25983 /* don't allow allocations above current base */
25984 if (mm->free_area_cache > base)
25985@@ -332,16 +341,15 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
25986 largest_hole = 0;
25987 mm->free_area_cache = base;
25988 }
25989-try_again:
25990- start_addr = mm->free_area_cache;
25991
25992 /* make sure it can fit in the remaining address space */
25993 if (mm->free_area_cache < len)
25994 goto fail;
25995
25996 /* either no address requested or can't fit in requested address hole */
25997- addr = (mm->free_area_cache - len) & huge_page_mask(h);
25998+ addr = mm->free_area_cache - len;
25999 do {
26000+ addr &= huge_page_mask(h);
26001 /*
26002 * Lookup failure means no vma is above this address,
26003 * i.e. return with success:
26004@@ -350,10 +358,10 @@ try_again:
26005 if (!vma)
26006 return addr;
26007
26008- if (addr + len <= vma->vm_start) {
26009+ if (check_heap_stack_gap(vma, addr, len, offset)) {
26010 /* remember the address as a hint for next time */
26011- mm->cached_hole_size = largest_hole;
26012- return (mm->free_area_cache = addr);
26013+ mm->cached_hole_size = largest_hole;
26014+ return (mm->free_area_cache = addr);
26015 } else if (mm->free_area_cache == vma->vm_end) {
26016 /* pull free_area_cache down to the first hole */
26017 mm->free_area_cache = vma->vm_start;
26018@@ -362,29 +370,34 @@ try_again:
26019
26020 /* remember the largest hole we saw so far */
26021 if (addr + largest_hole < vma->vm_start)
26022- largest_hole = vma->vm_start - addr;
26023+ largest_hole = vma->vm_start - addr;
26024
26025 /* try just below the current vma->vm_start */
26026- addr = (vma->vm_start - len) & huge_page_mask(h);
26027- } while (len <= vma->vm_start);
26028+ addr = skip_heap_stack_gap(vma, len, offset);
26029+ } while (!IS_ERR_VALUE(addr));
26030
26031 fail:
26032 /*
26033- * if hint left us with no space for the requested
26034- * mapping then try again:
26035- */
26036- if (start_addr != base) {
26037- mm->free_area_cache = base;
26038- largest_hole = 0;
26039- goto try_again;
26040- }
26041- /*
26042 * A failed mmap() very likely causes application failure,
26043 * so fall back to the bottom-up function here. This scenario
26044 * can happen with large stack limits and large mmap()
26045 * allocations.
26046 */
26047- mm->free_area_cache = TASK_UNMAPPED_BASE;
26048+
26049+#ifdef CONFIG_PAX_SEGMEXEC
26050+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
26051+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
26052+ else
26053+#endif
26054+
26055+ mm->mmap_base = TASK_UNMAPPED_BASE;
26056+
26057+#ifdef CONFIG_PAX_RANDMMAP
26058+ if (mm->pax_flags & MF_PAX_RANDMMAP)
26059+ mm->mmap_base += mm->delta_mmap;
26060+#endif
26061+
26062+ mm->free_area_cache = mm->mmap_base;
26063 mm->cached_hole_size = ~0UL;
26064 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
26065 len, pgoff, flags);
26066@@ -392,6 +405,7 @@ fail:
26067 /*
26068 * Restore the topdown base:
26069 */
26070+ mm->mmap_base = base;
26071 mm->free_area_cache = base;
26072 mm->cached_hole_size = ~0UL;
26073
26074@@ -405,10 +419,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
26075 struct hstate *h = hstate_file(file);
26076 struct mm_struct *mm = current->mm;
26077 struct vm_area_struct *vma;
26078+ unsigned long pax_task_size = TASK_SIZE;
26079+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
26080
26081 if (len & ~huge_page_mask(h))
26082 return -EINVAL;
26083- if (len > TASK_SIZE)
26084+
26085+#ifdef CONFIG_PAX_SEGMEXEC
26086+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
26087+ pax_task_size = SEGMEXEC_TASK_SIZE;
26088+#endif
26089+
26090+ pax_task_size -= PAGE_SIZE;
26091+
26092+ if (len > pax_task_size)
26093 return -ENOMEM;
26094
26095 if (flags & MAP_FIXED) {
26096@@ -417,11 +441,14 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
26097 return addr;
26098 }
26099
26100+#ifdef CONFIG_PAX_RANDMMAP
26101+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
26102+#endif
26103+
26104 if (addr) {
26105 addr = ALIGN(addr, huge_page_size(h));
26106 vma = find_vma(mm, addr);
26107- if (TASK_SIZE - len >= addr &&
26108- (!vma || addr + len <= vma->vm_start))
26109+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
26110 return addr;
26111 }
26112 if (mm->get_unmapped_area == arch_get_unmapped_area)
26113diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
26114index d7aea41..0fc945b 100644
26115--- a/arch/x86/mm/init.c
26116+++ b/arch/x86/mm/init.c
26117@@ -4,6 +4,7 @@
26118 #include <linux/swap.h>
26119 #include <linux/memblock.h>
26120 #include <linux/bootmem.h> /* for max_low_pfn */
26121+#include <linux/tboot.h>
26122
26123 #include <asm/cacheflush.h>
26124 #include <asm/e820.h>
26125@@ -16,6 +17,8 @@
26126 #include <asm/tlb.h>
26127 #include <asm/proto.h>
26128 #include <asm/dma.h> /* for MAX_DMA_PFN */
26129+#include <asm/desc.h>
26130+#include <asm/bios_ebda.h>
26131
26132 unsigned long __initdata pgt_buf_start;
26133 unsigned long __meminitdata pgt_buf_end;
26134@@ -44,7 +47,7 @@ static void __init find_early_table_space(struct map_range *mr, int nr_range)
26135 {
26136 int i;
26137 unsigned long puds = 0, pmds = 0, ptes = 0, tables;
26138- unsigned long start = 0, good_end;
26139+ unsigned long start = 0x100000, good_end;
26140 phys_addr_t base;
26141
26142 for (i = 0; i < nr_range; i++) {
26143@@ -321,10 +324,40 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
26144 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
26145 * mmio resources as well as potential bios/acpi data regions.
26146 */
26147+
26148+#ifdef CONFIG_GRKERNSEC_KMEM
26149+static unsigned int ebda_start __read_only;
26150+static unsigned int ebda_end __read_only;
26151+#endif
26152+
26153 int devmem_is_allowed(unsigned long pagenr)
26154 {
26155- if (pagenr < 256)
26156+#ifdef CONFIG_GRKERNSEC_KMEM
26157+ /* allow BDA */
26158+ if (!pagenr)
26159 return 1;
26160+ /* allow EBDA */
26161+ if (pagenr >= ebda_start && pagenr < ebda_end)
26162+ return 1;
26163+ /* if tboot is in use, allow access to its hardcoded serial log range */
26164+ if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
26165+ return 1;
26166+#else
26167+ if (!pagenr)
26168+ return 1;
26169+#ifdef CONFIG_VM86
26170+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
26171+ return 1;
26172+#endif
26173+#endif
26174+
26175+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
26176+ return 1;
26177+#ifdef CONFIG_GRKERNSEC_KMEM
26178+ /* throw out everything else below 1MB */
26179+ if (pagenr <= 256)
26180+ return 0;
26181+#endif
26182 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
26183 return 0;
26184 if (!page_is_ram(pagenr))
26185@@ -381,8 +414,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
26186 #endif
26187 }
26188
26189+#ifdef CONFIG_GRKERNSEC_KMEM
26190+static inline void gr_init_ebda(void)
26191+{
26192+ unsigned int ebda_addr;
26193+ unsigned int ebda_size = 0;
26194+
26195+ ebda_addr = get_bios_ebda();
26196+ if (ebda_addr) {
26197+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
26198+ ebda_size <<= 10;
26199+ }
26200+ if (ebda_addr && ebda_size) {
26201+ ebda_start = ebda_addr >> PAGE_SHIFT;
26202+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
26203+ } else {
26204+ ebda_start = 0x9f000 >> PAGE_SHIFT;
26205+ ebda_end = 0xa0000 >> PAGE_SHIFT;
26206+ }
26207+}
26208+#else
26209+static inline void gr_init_ebda(void) { }
26210+#endif
26211+
26212 void free_initmem(void)
26213 {
26214+#ifdef CONFIG_PAX_KERNEXEC
26215+#ifdef CONFIG_X86_32
26216+ /* PaX: limit KERNEL_CS to actual size */
26217+ unsigned long addr, limit;
26218+ struct desc_struct d;
26219+ int cpu;
26220+#else
26221+ pgd_t *pgd;
26222+ pud_t *pud;
26223+ pmd_t *pmd;
26224+ unsigned long addr, end;
26225+#endif
26226+#endif
26227+
26228+ gr_init_ebda();
26229+
26230+#ifdef CONFIG_PAX_KERNEXEC
26231+#ifdef CONFIG_X86_32
26232+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
26233+ limit = (limit - 1UL) >> PAGE_SHIFT;
26234+
26235+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
26236+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
26237+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
26238+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
26239+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
26240+ }
26241+
26242+ /* PaX: make KERNEL_CS read-only */
26243+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
26244+ if (!paravirt_enabled())
26245+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
26246+/*
26247+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
26248+ pgd = pgd_offset_k(addr);
26249+ pud = pud_offset(pgd, addr);
26250+ pmd = pmd_offset(pud, addr);
26251+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
26252+ }
26253+*/
26254+#ifdef CONFIG_X86_PAE
26255+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
26256+/*
26257+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
26258+ pgd = pgd_offset_k(addr);
26259+ pud = pud_offset(pgd, addr);
26260+ pmd = pmd_offset(pud, addr);
26261+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
26262+ }
26263+*/
26264+#endif
26265+
26266+#ifdef CONFIG_MODULES
26267+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
26268+#endif
26269+
26270+#else
26271+ /* PaX: make kernel code/rodata read-only, rest non-executable */
26272+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
26273+ pgd = pgd_offset_k(addr);
26274+ pud = pud_offset(pgd, addr);
26275+ pmd = pmd_offset(pud, addr);
26276+ if (!pmd_present(*pmd))
26277+ continue;
26278+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
26279+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
26280+ else
26281+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
26282+ }
26283+
26284+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
26285+ end = addr + KERNEL_IMAGE_SIZE;
26286+ for (; addr < end; addr += PMD_SIZE) {
26287+ pgd = pgd_offset_k(addr);
26288+ pud = pud_offset(pgd, addr);
26289+ pmd = pmd_offset(pud, addr);
26290+ if (!pmd_present(*pmd))
26291+ continue;
26292+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
26293+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
26294+ }
26295+#endif
26296+
26297+ flush_tlb_all();
26298+#endif
26299+
26300 free_init_pages("unused kernel memory",
26301 (unsigned long)(&__init_begin),
26302 (unsigned long)(&__init_end));
26303diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
26304index 11a5800..4bd9977 100644
26305--- a/arch/x86/mm/init_32.c
26306+++ b/arch/x86/mm/init_32.c
26307@@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
26308 }
26309
26310 /*
26311- * Creates a middle page table and puts a pointer to it in the
26312- * given global directory entry. This only returns the gd entry
26313- * in non-PAE compilation mode, since the middle layer is folded.
26314- */
26315-static pmd_t * __init one_md_table_init(pgd_t *pgd)
26316-{
26317- pud_t *pud;
26318- pmd_t *pmd_table;
26319-
26320-#ifdef CONFIG_X86_PAE
26321- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
26322- if (after_bootmem)
26323- pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
26324- else
26325- pmd_table = (pmd_t *)alloc_low_page();
26326- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
26327- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
26328- pud = pud_offset(pgd, 0);
26329- BUG_ON(pmd_table != pmd_offset(pud, 0));
26330-
26331- return pmd_table;
26332- }
26333-#endif
26334- pud = pud_offset(pgd, 0);
26335- pmd_table = pmd_offset(pud, 0);
26336-
26337- return pmd_table;
26338-}
26339-
26340-/*
26341 * Create a page table and place a pointer to it in a middle page
26342 * directory entry:
26343 */
26344@@ -122,13 +92,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
26345 page_table = (pte_t *)alloc_low_page();
26346
26347 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
26348+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
26349+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
26350+#else
26351 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
26352+#endif
26353 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
26354 }
26355
26356 return pte_offset_kernel(pmd, 0);
26357 }
26358
26359+static pmd_t * __init one_md_table_init(pgd_t *pgd)
26360+{
26361+ pud_t *pud;
26362+ pmd_t *pmd_table;
26363+
26364+ pud = pud_offset(pgd, 0);
26365+ pmd_table = pmd_offset(pud, 0);
26366+
26367+ return pmd_table;
26368+}
26369+
26370 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
26371 {
26372 int pgd_idx = pgd_index(vaddr);
26373@@ -202,6 +187,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
26374 int pgd_idx, pmd_idx;
26375 unsigned long vaddr;
26376 pgd_t *pgd;
26377+ pud_t *pud;
26378 pmd_t *pmd;
26379 pte_t *pte = NULL;
26380
26381@@ -211,8 +197,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
26382 pgd = pgd_base + pgd_idx;
26383
26384 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
26385- pmd = one_md_table_init(pgd);
26386- pmd = pmd + pmd_index(vaddr);
26387+ pud = pud_offset(pgd, vaddr);
26388+ pmd = pmd_offset(pud, vaddr);
26389+
26390+#ifdef CONFIG_X86_PAE
26391+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
26392+#endif
26393+
26394 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
26395 pmd++, pmd_idx++) {
26396 pte = page_table_kmap_check(one_page_table_init(pmd),
26397@@ -224,11 +215,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
26398 }
26399 }
26400
26401-static inline int is_kernel_text(unsigned long addr)
26402+static inline int is_kernel_text(unsigned long start, unsigned long end)
26403 {
26404- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
26405- return 1;
26406- return 0;
26407+ if ((start > ktla_ktva((unsigned long)_etext) ||
26408+ end <= ktla_ktva((unsigned long)_stext)) &&
26409+ (start > ktla_ktva((unsigned long)_einittext) ||
26410+ end <= ktla_ktva((unsigned long)_sinittext)) &&
26411+
26412+#ifdef CONFIG_ACPI_SLEEP
26413+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
26414+#endif
26415+
26416+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
26417+ return 0;
26418+ return 1;
26419 }
26420
26421 /*
26422@@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned long start,
26423 unsigned long last_map_addr = end;
26424 unsigned long start_pfn, end_pfn;
26425 pgd_t *pgd_base = swapper_pg_dir;
26426- int pgd_idx, pmd_idx, pte_ofs;
26427+ unsigned int pgd_idx, pmd_idx, pte_ofs;
26428 unsigned long pfn;
26429 pgd_t *pgd;
26430+ pud_t *pud;
26431 pmd_t *pmd;
26432 pte_t *pte;
26433 unsigned pages_2m, pages_4k;
26434@@ -280,8 +281,13 @@ repeat:
26435 pfn = start_pfn;
26436 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
26437 pgd = pgd_base + pgd_idx;
26438- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
26439- pmd = one_md_table_init(pgd);
26440+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
26441+ pud = pud_offset(pgd, 0);
26442+ pmd = pmd_offset(pud, 0);
26443+
26444+#ifdef CONFIG_X86_PAE
26445+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
26446+#endif
26447
26448 if (pfn >= end_pfn)
26449 continue;
26450@@ -293,14 +299,13 @@ repeat:
26451 #endif
26452 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
26453 pmd++, pmd_idx++) {
26454- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
26455+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
26456
26457 /*
26458 * Map with big pages if possible, otherwise
26459 * create normal page tables:
26460 */
26461 if (use_pse) {
26462- unsigned int addr2;
26463 pgprot_t prot = PAGE_KERNEL_LARGE;
26464 /*
26465 * first pass will use the same initial
26466@@ -310,11 +315,7 @@ repeat:
26467 __pgprot(PTE_IDENT_ATTR |
26468 _PAGE_PSE);
26469
26470- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
26471- PAGE_OFFSET + PAGE_SIZE-1;
26472-
26473- if (is_kernel_text(addr) ||
26474- is_kernel_text(addr2))
26475+ if (is_kernel_text(address, address + PMD_SIZE))
26476 prot = PAGE_KERNEL_LARGE_EXEC;
26477
26478 pages_2m++;
26479@@ -331,7 +332,7 @@ repeat:
26480 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
26481 pte += pte_ofs;
26482 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
26483- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
26484+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
26485 pgprot_t prot = PAGE_KERNEL;
26486 /*
26487 * first pass will use the same initial
26488@@ -339,7 +340,7 @@ repeat:
26489 */
26490 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
26491
26492- if (is_kernel_text(addr))
26493+ if (is_kernel_text(address, address + PAGE_SIZE))
26494 prot = PAGE_KERNEL_EXEC;
26495
26496 pages_4k++;
26497@@ -465,7 +466,7 @@ void __init native_pagetable_init(void)
26498
26499 pud = pud_offset(pgd, va);
26500 pmd = pmd_offset(pud, va);
26501- if (!pmd_present(*pmd))
26502+ if (!pmd_present(*pmd) || pmd_huge(*pmd))
26503 break;
26504
26505 pte = pte_offset_kernel(pmd, va);
26506@@ -514,12 +515,10 @@ void __init early_ioremap_page_table_range_init(void)
26507
26508 static void __init pagetable_init(void)
26509 {
26510- pgd_t *pgd_base = swapper_pg_dir;
26511-
26512- permanent_kmaps_init(pgd_base);
26513+ permanent_kmaps_init(swapper_pg_dir);
26514 }
26515
26516-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
26517+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
26518 EXPORT_SYMBOL_GPL(__supported_pte_mask);
26519
26520 /* user-defined highmem size */
26521@@ -731,6 +730,12 @@ void __init mem_init(void)
26522
26523 pci_iommu_alloc();
26524
26525+#ifdef CONFIG_PAX_PER_CPU_PGD
26526+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
26527+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
26528+ KERNEL_PGD_PTRS);
26529+#endif
26530+
26531 #ifdef CONFIG_FLATMEM
26532 BUG_ON(!mem_map);
26533 #endif
26534@@ -757,7 +762,7 @@ void __init mem_init(void)
26535 reservedpages++;
26536
26537 codesize = (unsigned long) &_etext - (unsigned long) &_text;
26538- datasize = (unsigned long) &_edata - (unsigned long) &_etext;
26539+ datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
26540 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
26541
26542 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
26543@@ -798,10 +803,10 @@ void __init mem_init(void)
26544 ((unsigned long)&__init_end -
26545 (unsigned long)&__init_begin) >> 10,
26546
26547- (unsigned long)&_etext, (unsigned long)&_edata,
26548- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
26549+ (unsigned long)&_sdata, (unsigned long)&_edata,
26550+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
26551
26552- (unsigned long)&_text, (unsigned long)&_etext,
26553+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
26554 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
26555
26556 /*
26557@@ -879,6 +884,7 @@ void set_kernel_text_rw(void)
26558 if (!kernel_set_to_readonly)
26559 return;
26560
26561+ start = ktla_ktva(start);
26562 pr_debug("Set kernel text: %lx - %lx for read write\n",
26563 start, start+size);
26564
26565@@ -893,6 +899,7 @@ void set_kernel_text_ro(void)
26566 if (!kernel_set_to_readonly)
26567 return;
26568
26569+ start = ktla_ktva(start);
26570 pr_debug("Set kernel text: %lx - %lx for read only\n",
26571 start, start+size);
26572
26573@@ -921,6 +928,7 @@ void mark_rodata_ro(void)
26574 unsigned long start = PFN_ALIGN(_text);
26575 unsigned long size = PFN_ALIGN(_etext) - start;
26576
26577+ start = ktla_ktva(start);
26578 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
26579 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
26580 size >> 10);
26581diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
26582index 3baff25..8b37564 100644
26583--- a/arch/x86/mm/init_64.c
26584+++ b/arch/x86/mm/init_64.c
26585@@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpages_on);
26586 * around without checking the pgd every time.
26587 */
26588
26589-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
26590+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
26591 EXPORT_SYMBOL_GPL(__supported_pte_mask);
26592
26593 int force_personality32;
26594@@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
26595
26596 for (address = start; address <= end; address += PGDIR_SIZE) {
26597 const pgd_t *pgd_ref = pgd_offset_k(address);
26598+
26599+#ifdef CONFIG_PAX_PER_CPU_PGD
26600+ unsigned long cpu;
26601+#else
26602 struct page *page;
26603+#endif
26604
26605 if (pgd_none(*pgd_ref))
26606 continue;
26607
26608 spin_lock(&pgd_lock);
26609+
26610+#ifdef CONFIG_PAX_PER_CPU_PGD
26611+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
26612+ pgd_t *pgd = pgd_offset_cpu(cpu, address);
26613+#else
26614 list_for_each_entry(page, &pgd_list, lru) {
26615 pgd_t *pgd;
26616 spinlock_t *pgt_lock;
26617@@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
26618 /* the pgt_lock only for Xen */
26619 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
26620 spin_lock(pgt_lock);
26621+#endif
26622
26623 if (pgd_none(*pgd))
26624 set_pgd(pgd, *pgd_ref);
26625@@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
26626 BUG_ON(pgd_page_vaddr(*pgd)
26627 != pgd_page_vaddr(*pgd_ref));
26628
26629+#ifndef CONFIG_PAX_PER_CPU_PGD
26630 spin_unlock(pgt_lock);
26631+#endif
26632+
26633 }
26634 spin_unlock(&pgd_lock);
26635 }
26636@@ -161,7 +175,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
26637 {
26638 if (pgd_none(*pgd)) {
26639 pud_t *pud = (pud_t *)spp_getpage();
26640- pgd_populate(&init_mm, pgd, pud);
26641+ pgd_populate_kernel(&init_mm, pgd, pud);
26642 if (pud != pud_offset(pgd, 0))
26643 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
26644 pud, pud_offset(pgd, 0));
26645@@ -173,7 +187,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
26646 {
26647 if (pud_none(*pud)) {
26648 pmd_t *pmd = (pmd_t *) spp_getpage();
26649- pud_populate(&init_mm, pud, pmd);
26650+ pud_populate_kernel(&init_mm, pud, pmd);
26651 if (pmd != pmd_offset(pud, 0))
26652 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
26653 pmd, pmd_offset(pud, 0));
26654@@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
26655 pmd = fill_pmd(pud, vaddr);
26656 pte = fill_pte(pmd, vaddr);
26657
26658+ pax_open_kernel();
26659 set_pte(pte, new_pte);
26660+ pax_close_kernel();
26661
26662 /*
26663 * It's enough to flush this one mapping.
26664@@ -261,14 +277,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
26665 pgd = pgd_offset_k((unsigned long)__va(phys));
26666 if (pgd_none(*pgd)) {
26667 pud = (pud_t *) spp_getpage();
26668- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
26669- _PAGE_USER));
26670+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
26671 }
26672 pud = pud_offset(pgd, (unsigned long)__va(phys));
26673 if (pud_none(*pud)) {
26674 pmd = (pmd_t *) spp_getpage();
26675- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
26676- _PAGE_USER));
26677+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
26678 }
26679 pmd = pmd_offset(pud, phys);
26680 BUG_ON(!pmd_none(*pmd));
26681@@ -329,7 +343,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
26682 if (pfn >= pgt_buf_top)
26683 panic("alloc_low_page: ran out of memory");
26684
26685- adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
26686+ adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
26687 clear_page(adr);
26688 *phys = pfn * PAGE_SIZE;
26689 return adr;
26690@@ -345,7 +359,7 @@ static __ref void *map_low_page(void *virt)
26691
26692 phys = __pa(virt);
26693 left = phys & (PAGE_SIZE - 1);
26694- adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
26695+ adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
26696 adr = (void *)(((unsigned long)adr) | left);
26697
26698 return adr;
26699@@ -553,7 +567,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
26700 unmap_low_page(pmd);
26701
26702 spin_lock(&init_mm.page_table_lock);
26703- pud_populate(&init_mm, pud, __va(pmd_phys));
26704+ pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
26705 spin_unlock(&init_mm.page_table_lock);
26706 }
26707 __flush_tlb_all();
26708@@ -599,7 +613,7 @@ kernel_physical_mapping_init(unsigned long start,
26709 unmap_low_page(pud);
26710
26711 spin_lock(&init_mm.page_table_lock);
26712- pgd_populate(&init_mm, pgd, __va(pud_phys));
26713+ pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
26714 spin_unlock(&init_mm.page_table_lock);
26715 pgd_changed = true;
26716 }
26717@@ -691,6 +705,12 @@ void __init mem_init(void)
26718
26719 pci_iommu_alloc();
26720
26721+#ifdef CONFIG_PAX_PER_CPU_PGD
26722+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
26723+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
26724+ KERNEL_PGD_PTRS);
26725+#endif
26726+
26727 /* clear_bss() already clear the empty_zero_page */
26728
26729 reservedpages = 0;
26730@@ -851,8 +871,8 @@ int kern_addr_valid(unsigned long addr)
26731 static struct vm_area_struct gate_vma = {
26732 .vm_start = VSYSCALL_START,
26733 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
26734- .vm_page_prot = PAGE_READONLY_EXEC,
26735- .vm_flags = VM_READ | VM_EXEC
26736+ .vm_page_prot = PAGE_READONLY,
26737+ .vm_flags = VM_READ
26738 };
26739
26740 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
26741@@ -886,7 +906,7 @@ int in_gate_area_no_mm(unsigned long addr)
26742
26743 const char *arch_vma_name(struct vm_area_struct *vma)
26744 {
26745- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
26746+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
26747 return "[vdso]";
26748 if (vma == &gate_vma)
26749 return "[vsyscall]";
26750diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
26751index 7b179b4..6bd1777 100644
26752--- a/arch/x86/mm/iomap_32.c
26753+++ b/arch/x86/mm/iomap_32.c
26754@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
26755 type = kmap_atomic_idx_push();
26756 idx = type + KM_TYPE_NR * smp_processor_id();
26757 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
26758+
26759+ pax_open_kernel();
26760 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
26761+ pax_close_kernel();
26762+
26763 arch_flush_lazy_mmu_mode();
26764
26765 return (void *)vaddr;
26766diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
26767index 78fe3f1..2f9433c 100644
26768--- a/arch/x86/mm/ioremap.c
26769+++ b/arch/x86/mm/ioremap.c
26770@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
26771 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
26772 int is_ram = page_is_ram(pfn);
26773
26774- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
26775+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
26776 return NULL;
26777 WARN_ON_ONCE(is_ram);
26778 }
26779@@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
26780 *
26781 * Caller must ensure there is only one unmapping for the same pointer.
26782 */
26783-void iounmap(volatile void __iomem *addr)
26784+void iounmap(const volatile void __iomem *addr)
26785 {
26786 struct vm_struct *p, *o;
26787
26788@@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
26789
26790 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
26791 if (page_is_ram(start >> PAGE_SHIFT))
26792+#ifdef CONFIG_HIGHMEM
26793+ if ((start >> PAGE_SHIFT) < max_low_pfn)
26794+#endif
26795 return __va(phys);
26796
26797 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
26798@@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
26799 early_param("early_ioremap_debug", early_ioremap_debug_setup);
26800
26801 static __initdata int after_paging_init;
26802-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
26803+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
26804
26805 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
26806 {
26807@@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
26808 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
26809
26810 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
26811- memset(bm_pte, 0, sizeof(bm_pte));
26812- pmd_populate_kernel(&init_mm, pmd, bm_pte);
26813+ pmd_populate_user(&init_mm, pmd, bm_pte);
26814
26815 /*
26816 * The boot-ioremap range spans multiple pmds, for which
26817diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
26818index d87dd6d..bf3fa66 100644
26819--- a/arch/x86/mm/kmemcheck/kmemcheck.c
26820+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
26821@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
26822 * memory (e.g. tracked pages)? For now, we need this to avoid
26823 * invoking kmemcheck for PnP BIOS calls.
26824 */
26825- if (regs->flags & X86_VM_MASK)
26826+ if (v8086_mode(regs))
26827 return false;
26828- if (regs->cs != __KERNEL_CS)
26829+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
26830 return false;
26831
26832 pte = kmemcheck_pte_lookup(address);
26833diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
26834index 845df68..1d8d29f 100644
26835--- a/arch/x86/mm/mmap.c
26836+++ b/arch/x86/mm/mmap.c
26837@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
26838 * Leave an at least ~128 MB hole with possible stack randomization.
26839 */
26840 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
26841-#define MAX_GAP (TASK_SIZE/6*5)
26842+#define MAX_GAP (pax_task_size/6*5)
26843
26844 static int mmap_is_legacy(void)
26845 {
26846@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
26847 return rnd << PAGE_SHIFT;
26848 }
26849
26850-static unsigned long mmap_base(void)
26851+static unsigned long mmap_base(struct mm_struct *mm)
26852 {
26853 unsigned long gap = rlimit(RLIMIT_STACK);
26854+ unsigned long pax_task_size = TASK_SIZE;
26855+
26856+#ifdef CONFIG_PAX_SEGMEXEC
26857+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
26858+ pax_task_size = SEGMEXEC_TASK_SIZE;
26859+#endif
26860
26861 if (gap < MIN_GAP)
26862 gap = MIN_GAP;
26863 else if (gap > MAX_GAP)
26864 gap = MAX_GAP;
26865
26866- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
26867+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
26868 }
26869
26870 /*
26871 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
26872 * does, but not when emulating X86_32
26873 */
26874-static unsigned long mmap_legacy_base(void)
26875+static unsigned long mmap_legacy_base(struct mm_struct *mm)
26876 {
26877- if (mmap_is_ia32())
26878+ if (mmap_is_ia32()) {
26879+
26880+#ifdef CONFIG_PAX_SEGMEXEC
26881+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
26882+ return SEGMEXEC_TASK_UNMAPPED_BASE;
26883+ else
26884+#endif
26885+
26886 return TASK_UNMAPPED_BASE;
26887- else
26888+ } else
26889 return TASK_UNMAPPED_BASE + mmap_rnd();
26890 }
26891
26892@@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
26893 void arch_pick_mmap_layout(struct mm_struct *mm)
26894 {
26895 if (mmap_is_legacy()) {
26896- mm->mmap_base = mmap_legacy_base();
26897+ mm->mmap_base = mmap_legacy_base(mm);
26898+
26899+#ifdef CONFIG_PAX_RANDMMAP
26900+ if (mm->pax_flags & MF_PAX_RANDMMAP)
26901+ mm->mmap_base += mm->delta_mmap;
26902+#endif
26903+
26904 mm->get_unmapped_area = arch_get_unmapped_area;
26905 mm->unmap_area = arch_unmap_area;
26906 } else {
26907- mm->mmap_base = mmap_base();
26908+ mm->mmap_base = mmap_base(mm);
26909+
26910+#ifdef CONFIG_PAX_RANDMMAP
26911+ if (mm->pax_flags & MF_PAX_RANDMMAP)
26912+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
26913+#endif
26914+
26915 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
26916 mm->unmap_area = arch_unmap_area_topdown;
26917 }
26918diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
26919index dc0b727..f612039 100644
26920--- a/arch/x86/mm/mmio-mod.c
26921+++ b/arch/x86/mm/mmio-mod.c
26922@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
26923 break;
26924 default:
26925 {
26926- unsigned char *ip = (unsigned char *)instptr;
26927+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
26928 my_trace->opcode = MMIO_UNKNOWN_OP;
26929 my_trace->width = 0;
26930 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
26931@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
26932 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
26933 void __iomem *addr)
26934 {
26935- static atomic_t next_id;
26936+ static atomic_unchecked_t next_id;
26937 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
26938 /* These are page-unaligned. */
26939 struct mmiotrace_map map = {
26940@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
26941 .private = trace
26942 },
26943 .phys = offset,
26944- .id = atomic_inc_return(&next_id)
26945+ .id = atomic_inc_return_unchecked(&next_id)
26946 };
26947 map.map_id = trace->id;
26948
26949@@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
26950 ioremap_trace_core(offset, size, addr);
26951 }
26952
26953-static void iounmap_trace_core(volatile void __iomem *addr)
26954+static void iounmap_trace_core(const volatile void __iomem *addr)
26955 {
26956 struct mmiotrace_map map = {
26957 .phys = 0,
26958@@ -328,7 +328,7 @@ not_enabled:
26959 }
26960 }
26961
26962-void mmiotrace_iounmap(volatile void __iomem *addr)
26963+void mmiotrace_iounmap(const volatile void __iomem *addr)
26964 {
26965 might_sleep();
26966 if (is_enabled()) /* recheck and proper locking in *_core() */
26967diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
26968index b008656..773eac2 100644
26969--- a/arch/x86/mm/pageattr-test.c
26970+++ b/arch/x86/mm/pageattr-test.c
26971@@ -36,7 +36,7 @@ enum {
26972
26973 static int pte_testbit(pte_t pte)
26974 {
26975- return pte_flags(pte) & _PAGE_UNUSED1;
26976+ return pte_flags(pte) & _PAGE_CPA_TEST;
26977 }
26978
26979 struct split_state {
26980diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
26981index a718e0d..77419bc 100644
26982--- a/arch/x86/mm/pageattr.c
26983+++ b/arch/x86/mm/pageattr.c
26984@@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
26985 */
26986 #ifdef CONFIG_PCI_BIOS
26987 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
26988- pgprot_val(forbidden) |= _PAGE_NX;
26989+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
26990 #endif
26991
26992 /*
26993@@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
26994 * Does not cover __inittext since that is gone later on. On
26995 * 64bit we do not enforce !NX on the low mapping
26996 */
26997- if (within(address, (unsigned long)_text, (unsigned long)_etext))
26998- pgprot_val(forbidden) |= _PAGE_NX;
26999+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
27000+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
27001
27002+#ifdef CONFIG_DEBUG_RODATA
27003 /*
27004 * The .rodata section needs to be read-only. Using the pfn
27005 * catches all aliases.
27006@@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
27007 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
27008 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
27009 pgprot_val(forbidden) |= _PAGE_RW;
27010+#endif
27011
27012 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
27013 /*
27014@@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
27015 }
27016 #endif
27017
27018+#ifdef CONFIG_PAX_KERNEXEC
27019+ if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
27020+ pgprot_val(forbidden) |= _PAGE_RW;
27021+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
27022+ }
27023+#endif
27024+
27025 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
27026
27027 return prot;
27028@@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
27029 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
27030 {
27031 /* change init_mm */
27032+ pax_open_kernel();
27033 set_pte_atomic(kpte, pte);
27034+
27035 #ifdef CONFIG_X86_32
27036 if (!SHARED_KERNEL_PMD) {
27037+
27038+#ifdef CONFIG_PAX_PER_CPU_PGD
27039+ unsigned long cpu;
27040+#else
27041 struct page *page;
27042+#endif
27043
27044+#ifdef CONFIG_PAX_PER_CPU_PGD
27045+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
27046+ pgd_t *pgd = get_cpu_pgd(cpu);
27047+#else
27048 list_for_each_entry(page, &pgd_list, lru) {
27049- pgd_t *pgd;
27050+ pgd_t *pgd = (pgd_t *)page_address(page);
27051+#endif
27052+
27053 pud_t *pud;
27054 pmd_t *pmd;
27055
27056- pgd = (pgd_t *)page_address(page) + pgd_index(address);
27057+ pgd += pgd_index(address);
27058 pud = pud_offset(pgd, address);
27059 pmd = pmd_offset(pud, address);
27060 set_pte_atomic((pte_t *)pmd, pte);
27061 }
27062 }
27063 #endif
27064+ pax_close_kernel();
27065 }
27066
27067 static int
27068diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
27069index 0eb572e..92f5c1e 100644
27070--- a/arch/x86/mm/pat.c
27071+++ b/arch/x86/mm/pat.c
27072@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
27073
27074 if (!entry) {
27075 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
27076- current->comm, current->pid, start, end - 1);
27077+ current->comm, task_pid_nr(current), start, end - 1);
27078 return -EINVAL;
27079 }
27080
27081@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
27082
27083 while (cursor < to) {
27084 if (!devmem_is_allowed(pfn)) {
27085- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
27086- current->comm, from, to - 1);
27087+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
27088+ current->comm, from, to - 1, cursor);
27089 return 0;
27090 }
27091 cursor += PAGE_SIZE;
27092@@ -570,7 +570,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
27093 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
27094 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
27095 "for [mem %#010Lx-%#010Lx]\n",
27096- current->comm, current->pid,
27097+ current->comm, task_pid_nr(current),
27098 cattr_name(flags),
27099 base, (unsigned long long)(base + size-1));
27100 return -EINVAL;
27101@@ -605,7 +605,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
27102 flags = lookup_memtype(paddr);
27103 if (want_flags != flags) {
27104 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
27105- current->comm, current->pid,
27106+ current->comm, task_pid_nr(current),
27107 cattr_name(want_flags),
27108 (unsigned long long)paddr,
27109 (unsigned long long)(paddr + size - 1),
27110@@ -627,7 +627,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
27111 free_memtype(paddr, paddr + size);
27112 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
27113 " for [mem %#010Lx-%#010Lx], got %s\n",
27114- current->comm, current->pid,
27115+ current->comm, task_pid_nr(current),
27116 cattr_name(want_flags),
27117 (unsigned long long)paddr,
27118 (unsigned long long)(paddr + size - 1),
27119diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
27120index 9f0614d..92ae64a 100644
27121--- a/arch/x86/mm/pf_in.c
27122+++ b/arch/x86/mm/pf_in.c
27123@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
27124 int i;
27125 enum reason_type rv = OTHERS;
27126
27127- p = (unsigned char *)ins_addr;
27128+ p = (unsigned char *)ktla_ktva(ins_addr);
27129 p += skip_prefix(p, &prf);
27130 p += get_opcode(p, &opcode);
27131
27132@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
27133 struct prefix_bits prf;
27134 int i;
27135
27136- p = (unsigned char *)ins_addr;
27137+ p = (unsigned char *)ktla_ktva(ins_addr);
27138 p += skip_prefix(p, &prf);
27139 p += get_opcode(p, &opcode);
27140
27141@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
27142 struct prefix_bits prf;
27143 int i;
27144
27145- p = (unsigned char *)ins_addr;
27146+ p = (unsigned char *)ktla_ktva(ins_addr);
27147 p += skip_prefix(p, &prf);
27148 p += get_opcode(p, &opcode);
27149
27150@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
27151 struct prefix_bits prf;
27152 int i;
27153
27154- p = (unsigned char *)ins_addr;
27155+ p = (unsigned char *)ktla_ktva(ins_addr);
27156 p += skip_prefix(p, &prf);
27157 p += get_opcode(p, &opcode);
27158 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
27159@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
27160 struct prefix_bits prf;
27161 int i;
27162
27163- p = (unsigned char *)ins_addr;
27164+ p = (unsigned char *)ktla_ktva(ins_addr);
27165 p += skip_prefix(p, &prf);
27166 p += get_opcode(p, &opcode);
27167 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
27168diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
27169index 8573b83..4f3ed7e 100644
27170--- a/arch/x86/mm/pgtable.c
27171+++ b/arch/x86/mm/pgtable.c
27172@@ -84,10 +84,64 @@ static inline void pgd_list_del(pgd_t *pgd)
27173 list_del(&page->lru);
27174 }
27175
27176-#define UNSHARED_PTRS_PER_PGD \
27177- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
27178+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
27179+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
27180
27181+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
27182+{
27183+ unsigned int count = USER_PGD_PTRS;
27184
27185+ while (count--)
27186+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
27187+}
27188+#endif
27189+
27190+#ifdef CONFIG_PAX_PER_CPU_PGD
27191+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
27192+{
27193+ unsigned int count = USER_PGD_PTRS;
27194+
27195+ while (count--) {
27196+ pgd_t pgd;
27197+
27198+#ifdef CONFIG_X86_64
27199+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
27200+#else
27201+ pgd = *src++;
27202+#endif
27203+
27204+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
27205+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
27206+#endif
27207+
27208+ *dst++ = pgd;
27209+ }
27210+
27211+}
27212+#endif
27213+
27214+#ifdef CONFIG_X86_64
27215+#define pxd_t pud_t
27216+#define pyd_t pgd_t
27217+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
27218+#define pxd_free(mm, pud) pud_free((mm), (pud))
27219+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
27220+#define pyd_offset(mm, address) pgd_offset((mm), (address))
27221+#define PYD_SIZE PGDIR_SIZE
27222+#else
27223+#define pxd_t pmd_t
27224+#define pyd_t pud_t
27225+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
27226+#define pxd_free(mm, pud) pmd_free((mm), (pud))
27227+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
27228+#define pyd_offset(mm, address) pud_offset((mm), (address))
27229+#define PYD_SIZE PUD_SIZE
27230+#endif
27231+
27232+#ifdef CONFIG_PAX_PER_CPU_PGD
27233+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
27234+static inline void pgd_dtor(pgd_t *pgd) {}
27235+#else
27236 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
27237 {
27238 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
27239@@ -128,6 +182,7 @@ static void pgd_dtor(pgd_t *pgd)
27240 pgd_list_del(pgd);
27241 spin_unlock(&pgd_lock);
27242 }
27243+#endif
27244
27245 /*
27246 * List of all pgd's needed for non-PAE so it can invalidate entries
27247@@ -140,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
27248 * -- wli
27249 */
27250
27251-#ifdef CONFIG_X86_PAE
27252+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
27253 /*
27254 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
27255 * updating the top-level pagetable entries to guarantee the
27256@@ -152,7 +207,7 @@ static void pgd_dtor(pgd_t *pgd)
27257 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
27258 * and initialize the kernel pmds here.
27259 */
27260-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
27261+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
27262
27263 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
27264 {
27265@@ -170,36 +225,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
27266 */
27267 flush_tlb_mm(mm);
27268 }
27269+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
27270+#define PREALLOCATED_PXDS USER_PGD_PTRS
27271 #else /* !CONFIG_X86_PAE */
27272
27273 /* No need to prepopulate any pagetable entries in non-PAE modes. */
27274-#define PREALLOCATED_PMDS 0
27275+#define PREALLOCATED_PXDS 0
27276
27277 #endif /* CONFIG_X86_PAE */
27278
27279-static void free_pmds(pmd_t *pmds[])
27280+static void free_pxds(pxd_t *pxds[])
27281 {
27282 int i;
27283
27284- for(i = 0; i < PREALLOCATED_PMDS; i++)
27285- if (pmds[i])
27286- free_page((unsigned long)pmds[i]);
27287+ for(i = 0; i < PREALLOCATED_PXDS; i++)
27288+ if (pxds[i])
27289+ free_page((unsigned long)pxds[i]);
27290 }
27291
27292-static int preallocate_pmds(pmd_t *pmds[])
27293+static int preallocate_pxds(pxd_t *pxds[])
27294 {
27295 int i;
27296 bool failed = false;
27297
27298- for(i = 0; i < PREALLOCATED_PMDS; i++) {
27299- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
27300- if (pmd == NULL)
27301+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
27302+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
27303+ if (pxd == NULL)
27304 failed = true;
27305- pmds[i] = pmd;
27306+ pxds[i] = pxd;
27307 }
27308
27309 if (failed) {
27310- free_pmds(pmds);
27311+ free_pxds(pxds);
27312 return -ENOMEM;
27313 }
27314
27315@@ -212,51 +269,55 @@ static int preallocate_pmds(pmd_t *pmds[])
27316 * preallocate which never got a corresponding vma will need to be
27317 * freed manually.
27318 */
27319-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
27320+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
27321 {
27322 int i;
27323
27324- for(i = 0; i < PREALLOCATED_PMDS; i++) {
27325+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
27326 pgd_t pgd = pgdp[i];
27327
27328 if (pgd_val(pgd) != 0) {
27329- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
27330+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
27331
27332- pgdp[i] = native_make_pgd(0);
27333+ set_pgd(pgdp + i, native_make_pgd(0));
27334
27335- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
27336- pmd_free(mm, pmd);
27337+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
27338+ pxd_free(mm, pxd);
27339 }
27340 }
27341 }
27342
27343-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
27344+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
27345 {
27346- pud_t *pud;
27347+ pyd_t *pyd;
27348 unsigned long addr;
27349 int i;
27350
27351- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
27352+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
27353 return;
27354
27355- pud = pud_offset(pgd, 0);
27356+#ifdef CONFIG_X86_64
27357+ pyd = pyd_offset(mm, 0L);
27358+#else
27359+ pyd = pyd_offset(pgd, 0L);
27360+#endif
27361
27362- for (addr = i = 0; i < PREALLOCATED_PMDS;
27363- i++, pud++, addr += PUD_SIZE) {
27364- pmd_t *pmd = pmds[i];
27365+ for (addr = i = 0; i < PREALLOCATED_PXDS;
27366+ i++, pyd++, addr += PYD_SIZE) {
27367+ pxd_t *pxd = pxds[i];
27368
27369 if (i >= KERNEL_PGD_BOUNDARY)
27370- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
27371- sizeof(pmd_t) * PTRS_PER_PMD);
27372+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
27373+ sizeof(pxd_t) * PTRS_PER_PMD);
27374
27375- pud_populate(mm, pud, pmd);
27376+ pyd_populate(mm, pyd, pxd);
27377 }
27378 }
27379
27380 pgd_t *pgd_alloc(struct mm_struct *mm)
27381 {
27382 pgd_t *pgd;
27383- pmd_t *pmds[PREALLOCATED_PMDS];
27384+ pxd_t *pxds[PREALLOCATED_PXDS];
27385
27386 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
27387
27388@@ -265,11 +326,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
27389
27390 mm->pgd = pgd;
27391
27392- if (preallocate_pmds(pmds) != 0)
27393+ if (preallocate_pxds(pxds) != 0)
27394 goto out_free_pgd;
27395
27396 if (paravirt_pgd_alloc(mm) != 0)
27397- goto out_free_pmds;
27398+ goto out_free_pxds;
27399
27400 /*
27401 * Make sure that pre-populating the pmds is atomic with
27402@@ -279,14 +340,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
27403 spin_lock(&pgd_lock);
27404
27405 pgd_ctor(mm, pgd);
27406- pgd_prepopulate_pmd(mm, pgd, pmds);
27407+ pgd_prepopulate_pxd(mm, pgd, pxds);
27408
27409 spin_unlock(&pgd_lock);
27410
27411 return pgd;
27412
27413-out_free_pmds:
27414- free_pmds(pmds);
27415+out_free_pxds:
27416+ free_pxds(pxds);
27417 out_free_pgd:
27418 free_page((unsigned long)pgd);
27419 out:
27420@@ -295,7 +356,7 @@ out:
27421
27422 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
27423 {
27424- pgd_mop_up_pmds(mm, pgd);
27425+ pgd_mop_up_pxds(mm, pgd);
27426 pgd_dtor(pgd);
27427 paravirt_pgd_free(mm, pgd);
27428 free_page((unsigned long)pgd);
27429diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
27430index a69bcb8..19068ab 100644
27431--- a/arch/x86/mm/pgtable_32.c
27432+++ b/arch/x86/mm/pgtable_32.c
27433@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
27434 return;
27435 }
27436 pte = pte_offset_kernel(pmd, vaddr);
27437+
27438+ pax_open_kernel();
27439 if (pte_val(pteval))
27440 set_pte_at(&init_mm, vaddr, pte, pteval);
27441 else
27442 pte_clear(&init_mm, vaddr, pte);
27443+ pax_close_kernel();
27444
27445 /*
27446 * It's enough to flush this one mapping.
27447diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
27448index 410531d..0f16030 100644
27449--- a/arch/x86/mm/setup_nx.c
27450+++ b/arch/x86/mm/setup_nx.c
27451@@ -5,8 +5,10 @@
27452 #include <asm/pgtable.h>
27453 #include <asm/proto.h>
27454
27455+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
27456 static int disable_nx __cpuinitdata;
27457
27458+#ifndef CONFIG_PAX_PAGEEXEC
27459 /*
27460 * noexec = on|off
27461 *
27462@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
27463 return 0;
27464 }
27465 early_param("noexec", noexec_setup);
27466+#endif
27467+
27468+#endif
27469
27470 void __cpuinit x86_configure_nx(void)
27471 {
27472+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
27473 if (cpu_has_nx && !disable_nx)
27474 __supported_pte_mask |= _PAGE_NX;
27475 else
27476+#endif
27477 __supported_pte_mask &= ~_PAGE_NX;
27478 }
27479
27480diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
27481index 60f926c..a710970 100644
27482--- a/arch/x86/mm/tlb.c
27483+++ b/arch/x86/mm/tlb.c
27484@@ -48,7 +48,11 @@ void leave_mm(int cpu)
27485 BUG();
27486 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
27487 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
27488+
27489+#ifndef CONFIG_PAX_PER_CPU_PGD
27490 load_cr3(swapper_pg_dir);
27491+#endif
27492+
27493 }
27494 }
27495 EXPORT_SYMBOL_GPL(leave_mm);
27496diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
27497index 877b9a1..a8ecf42 100644
27498--- a/arch/x86/net/bpf_jit.S
27499+++ b/arch/x86/net/bpf_jit.S
27500@@ -9,6 +9,7 @@
27501 */
27502 #include <linux/linkage.h>
27503 #include <asm/dwarf2.h>
27504+#include <asm/alternative-asm.h>
27505
27506 /*
27507 * Calling convention :
27508@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
27509 jle bpf_slow_path_word
27510 mov (SKBDATA,%rsi),%eax
27511 bswap %eax /* ntohl() */
27512+ pax_force_retaddr
27513 ret
27514
27515 sk_load_half:
27516@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
27517 jle bpf_slow_path_half
27518 movzwl (SKBDATA,%rsi),%eax
27519 rol $8,%ax # ntohs()
27520+ pax_force_retaddr
27521 ret
27522
27523 sk_load_byte:
27524@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
27525 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
27526 jle bpf_slow_path_byte
27527 movzbl (SKBDATA,%rsi),%eax
27528+ pax_force_retaddr
27529 ret
27530
27531 /**
27532@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
27533 movzbl (SKBDATA,%rsi),%ebx
27534 and $15,%bl
27535 shl $2,%bl
27536+ pax_force_retaddr
27537 ret
27538
27539 /* rsi contains offset and can be scratched */
27540@@ -109,6 +114,7 @@ bpf_slow_path_word:
27541 js bpf_error
27542 mov -12(%rbp),%eax
27543 bswap %eax
27544+ pax_force_retaddr
27545 ret
27546
27547 bpf_slow_path_half:
27548@@ -117,12 +123,14 @@ bpf_slow_path_half:
27549 mov -12(%rbp),%ax
27550 rol $8,%ax
27551 movzwl %ax,%eax
27552+ pax_force_retaddr
27553 ret
27554
27555 bpf_slow_path_byte:
27556 bpf_slow_path_common(1)
27557 js bpf_error
27558 movzbl -12(%rbp),%eax
27559+ pax_force_retaddr
27560 ret
27561
27562 bpf_slow_path_byte_msh:
27563@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
27564 and $15,%al
27565 shl $2,%al
27566 xchg %eax,%ebx
27567+ pax_force_retaddr
27568 ret
27569
27570 #define sk_negative_common(SIZE) \
27571@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
27572 sk_negative_common(4)
27573 mov (%rax), %eax
27574 bswap %eax
27575+ pax_force_retaddr
27576 ret
27577
27578 bpf_slow_path_half_neg:
27579@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
27580 mov (%rax),%ax
27581 rol $8,%ax
27582 movzwl %ax,%eax
27583+ pax_force_retaddr
27584 ret
27585
27586 bpf_slow_path_byte_neg:
27587@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
27588 .globl sk_load_byte_negative_offset
27589 sk_negative_common(1)
27590 movzbl (%rax), %eax
27591+ pax_force_retaddr
27592 ret
27593
27594 bpf_slow_path_byte_msh_neg:
27595@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
27596 and $15,%al
27597 shl $2,%al
27598 xchg %eax,%ebx
27599+ pax_force_retaddr
27600 ret
27601
27602 bpf_error:
27603@@ -197,4 +210,5 @@ bpf_error:
27604 xor %eax,%eax
27605 mov -8(%rbp),%rbx
27606 leaveq
27607+ pax_force_retaddr
27608 ret
27609diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
27610index 520d2bd..b895ef4 100644
27611--- a/arch/x86/net/bpf_jit_comp.c
27612+++ b/arch/x86/net/bpf_jit_comp.c
27613@@ -11,6 +11,7 @@
27614 #include <asm/cacheflush.h>
27615 #include <linux/netdevice.h>
27616 #include <linux/filter.h>
27617+#include <linux/random.h>
27618
27619 /*
27620 * Conventions :
27621@@ -48,13 +49,87 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
27622 return ptr + len;
27623 }
27624
27625+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27626+#define MAX_INSTR_CODE_SIZE 96
27627+#else
27628+#define MAX_INSTR_CODE_SIZE 64
27629+#endif
27630+
27631 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
27632
27633 #define EMIT1(b1) EMIT(b1, 1)
27634 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
27635 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
27636 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
27637+
27638+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27639+/* original constant will appear in ecx */
27640+#define DILUTE_CONST_SEQUENCE(_off, _key) \
27641+do { \
27642+ /* mov ecx, randkey */ \
27643+ EMIT1(0xb9); \
27644+ EMIT(_key, 4); \
27645+ /* xor ecx, randkey ^ off */ \
27646+ EMIT2(0x81, 0xf1); \
27647+ EMIT((_key) ^ (_off), 4); \
27648+} while (0)
27649+
27650+#define EMIT1_off32(b1, _off) \
27651+do { \
27652+ switch (b1) { \
27653+ case 0x05: /* add eax, imm32 */ \
27654+ case 0x2d: /* sub eax, imm32 */ \
27655+ case 0x25: /* and eax, imm32 */ \
27656+ case 0x0d: /* or eax, imm32 */ \
27657+ case 0xb8: /* mov eax, imm32 */ \
27658+ case 0x3d: /* cmp eax, imm32 */ \
27659+ case 0xa9: /* test eax, imm32 */ \
27660+ DILUTE_CONST_SEQUENCE(_off, randkey); \
27661+ EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
27662+ break; \
27663+ case 0xbb: /* mov ebx, imm32 */ \
27664+ DILUTE_CONST_SEQUENCE(_off, randkey); \
27665+ /* mov ebx, ecx */ \
27666+ EMIT2(0x89, 0xcb); \
27667+ break; \
27668+ case 0xbe: /* mov esi, imm32 */ \
27669+ DILUTE_CONST_SEQUENCE(_off, randkey); \
27670+ /* mov esi, ecx */ \
27671+ EMIT2(0x89, 0xce); \
27672+ break; \
27673+ case 0xe9: /* jmp rel imm32 */ \
27674+ EMIT1(b1); \
27675+ EMIT(_off, 4); \
27676+ /* prevent fall-through, we're not called if off = 0 */ \
27677+ EMIT(0xcccccccc, 4); \
27678+ EMIT(0xcccccccc, 4); \
27679+ break; \
27680+ default: \
27681+ EMIT1(b1); \
27682+ EMIT(_off, 4); \
27683+ } \
27684+} while (0)
27685+
27686+#define EMIT2_off32(b1, b2, _off) \
27687+do { \
27688+ if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
27689+ EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
27690+ EMIT(randkey, 4); \
27691+ EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
27692+ EMIT((_off) - randkey, 4); \
27693+ } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
27694+ DILUTE_CONST_SEQUENCE(_off, randkey); \
27695+ /* imul eax, ecx */ \
27696+ EMIT3(0x0f, 0xaf, 0xc1); \
27697+ } else { \
27698+ EMIT2(b1, b2); \
27699+ EMIT(_off, 4); \
27700+ } \
27701+} while (0)
27702+#else
27703 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
27704+#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
27705+#endif
27706
27707 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
27708 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
27709@@ -89,6 +164,24 @@ do { \
27710 #define X86_JBE 0x76
27711 #define X86_JA 0x77
27712
27713+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27714+#define APPEND_FLOW_VERIFY() \
27715+do { \
27716+ /* mov ecx, randkey */ \
27717+ EMIT1(0xb9); \
27718+ EMIT(randkey, 4); \
27719+ /* cmp ecx, randkey */ \
27720+ EMIT2(0x81, 0xf9); \
27721+ EMIT(randkey, 4); \
27722+ /* jz after 8 int 3s */ \
27723+ EMIT2(0x74, 0x08); \
27724+ EMIT(0xcccccccc, 4); \
27725+ EMIT(0xcccccccc, 4); \
27726+} while (0)
27727+#else
27728+#define APPEND_FLOW_VERIFY() do { } while (0)
27729+#endif
27730+
27731 #define EMIT_COND_JMP(op, offset) \
27732 do { \
27733 if (is_near(offset)) \
27734@@ -96,6 +189,7 @@ do { \
27735 else { \
27736 EMIT2(0x0f, op + 0x10); \
27737 EMIT(offset, 4); /* jxx .+off32 */ \
27738+ APPEND_FLOW_VERIFY(); \
27739 } \
27740 } while (0)
27741
27742@@ -120,12 +214,17 @@ static inline void bpf_flush_icache(void *start, void *end)
27743 set_fs(old_fs);
27744 }
27745
27746+struct bpf_jit_work {
27747+ struct work_struct work;
27748+ void *image;
27749+};
27750+
27751 #define CHOOSE_LOAD_FUNC(K, func) \
27752 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
27753
27754 void bpf_jit_compile(struct sk_filter *fp)
27755 {
27756- u8 temp[64];
27757+ u8 temp[MAX_INSTR_CODE_SIZE];
27758 u8 *prog;
27759 unsigned int proglen, oldproglen = 0;
27760 int ilen, i;
27761@@ -138,6 +237,9 @@ void bpf_jit_compile(struct sk_filter *fp)
27762 unsigned int *addrs;
27763 const struct sock_filter *filter = fp->insns;
27764 int flen = fp->len;
27765+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27766+ unsigned int randkey;
27767+#endif
27768
27769 if (!bpf_jit_enable)
27770 return;
27771@@ -146,11 +248,19 @@ void bpf_jit_compile(struct sk_filter *fp)
27772 if (addrs == NULL)
27773 return;
27774
27775+ fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
27776+ if (!fp->work)
27777+ goto out;
27778+
27779+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27780+ randkey = get_random_int();
27781+#endif
27782+
27783 /* Before first pass, make a rough estimation of addrs[]
27784- * each bpf instruction is translated to less than 64 bytes
27785+ * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
27786 */
27787 for (proglen = 0, i = 0; i < flen; i++) {
27788- proglen += 64;
27789+ proglen += MAX_INSTR_CODE_SIZE;
27790 addrs[i] = proglen;
27791 }
27792 cleanup_addr = proglen; /* epilogue address */
27793@@ -258,10 +368,8 @@ void bpf_jit_compile(struct sk_filter *fp)
27794 case BPF_S_ALU_MUL_K: /* A *= K */
27795 if (is_imm8(K))
27796 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
27797- else {
27798- EMIT2(0x69, 0xc0); /* imul imm32,%eax */
27799- EMIT(K, 4);
27800- }
27801+ else
27802+ EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
27803 break;
27804 case BPF_S_ALU_DIV_X: /* A /= X; */
27805 seen |= SEEN_XREG;
27806@@ -301,13 +409,23 @@ void bpf_jit_compile(struct sk_filter *fp)
27807 break;
27808 case BPF_S_ALU_MOD_K: /* A %= K; */
27809 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
27810+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27811+ DILUTE_CONST_SEQUENCE(K, randkey);
27812+#else
27813 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
27814+#endif
27815 EMIT2(0xf7, 0xf1); /* div %ecx */
27816 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
27817 break;
27818 case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */
27819+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27820+ DILUTE_CONST_SEQUENCE(K, randkey);
27821+ // imul rax, rcx
27822+ EMIT4(0x48, 0x0f, 0xaf, 0xc1);
27823+#else
27824 EMIT3(0x48, 0x69, 0xc0); /* imul imm32,%rax,%rax */
27825 EMIT(K, 4);
27826+#endif
27827 EMIT4(0x48, 0xc1, 0xe8, 0x20); /* shr $0x20,%rax */
27828 break;
27829 case BPF_S_ALU_AND_X:
27830@@ -543,8 +661,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
27831 if (is_imm8(K)) {
27832 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
27833 } else {
27834- EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
27835- EMIT(K, 4);
27836+ EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
27837 }
27838 } else {
27839 EMIT2(0x89,0xde); /* mov %ebx,%esi */
27840@@ -627,17 +744,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
27841 break;
27842 default:
27843 /* hmm, too complex filter, give up with jit compiler */
27844- goto out;
27845+ goto error;
27846 }
27847 ilen = prog - temp;
27848 if (image) {
27849 if (unlikely(proglen + ilen > oldproglen)) {
27850 pr_err("bpb_jit_compile fatal error\n");
27851- kfree(addrs);
27852- module_free(NULL, image);
27853- return;
27854+ module_free_exec(NULL, image);
27855+ goto error;
27856 }
27857+ pax_open_kernel();
27858 memcpy(image + proglen, temp, ilen);
27859+ pax_close_kernel();
27860 }
27861 proglen += ilen;
27862 addrs[i] = proglen;
27863@@ -658,11 +776,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
27864 break;
27865 }
27866 if (proglen == oldproglen) {
27867- image = module_alloc(max_t(unsigned int,
27868- proglen,
27869- sizeof(struct work_struct)));
27870+ image = module_alloc_exec(proglen);
27871 if (!image)
27872- goto out;
27873+ goto error;
27874 }
27875 oldproglen = proglen;
27876 }
27877@@ -678,7 +794,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
27878 bpf_flush_icache(image, image + proglen);
27879
27880 fp->bpf_func = (void *)image;
27881- }
27882+ } else
27883+error:
27884+ kfree(fp->work);
27885+
27886 out:
27887 kfree(addrs);
27888 return;
27889@@ -686,18 +805,20 @@ out:
27890
27891 static void jit_free_defer(struct work_struct *arg)
27892 {
27893- module_free(NULL, arg);
27894+ module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
27895+ kfree(arg);
27896 }
27897
27898 /* run from softirq, we must use a work_struct to call
27899- * module_free() from process context
27900+ * module_free_exec() from process context
27901 */
27902 void bpf_jit_free(struct sk_filter *fp)
27903 {
27904 if (fp->bpf_func != sk_run_filter) {
27905- struct work_struct *work = (struct work_struct *)fp->bpf_func;
27906+ struct work_struct *work = &fp->work->work;
27907
27908 INIT_WORK(work, jit_free_defer);
27909+ fp->work->image = fp->bpf_func;
27910 schedule_work(work);
27911 }
27912 }
27913diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
27914index d6aa6e8..266395a 100644
27915--- a/arch/x86/oprofile/backtrace.c
27916+++ b/arch/x86/oprofile/backtrace.c
27917@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
27918 struct stack_frame_ia32 *fp;
27919 unsigned long bytes;
27920
27921- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
27922+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
27923 if (bytes != sizeof(bufhead))
27924 return NULL;
27925
27926- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
27927+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
27928
27929 oprofile_add_trace(bufhead[0].return_address);
27930
27931@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
27932 struct stack_frame bufhead[2];
27933 unsigned long bytes;
27934
27935- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
27936+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
27937 if (bytes != sizeof(bufhead))
27938 return NULL;
27939
27940@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
27941 {
27942 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
27943
27944- if (!user_mode_vm(regs)) {
27945+ if (!user_mode(regs)) {
27946 unsigned long stack = kernel_stack_pointer(regs);
27947 if (depth)
27948 dump_trace(NULL, regs, (unsigned long *)stack, 0,
27949diff --git a/arch/x86/pci/acpi.c b/arch/x86/pci/acpi.c
27950index 192397c..5ba6f9e 100644
27951--- a/arch/x86/pci/acpi.c
27952+++ b/arch/x86/pci/acpi.c
27953@@ -568,7 +568,7 @@ int __init pci_acpi_init(void)
27954 acpi_irq_penalty_init();
27955 pcibios_enable_irq = acpi_pci_irq_enable;
27956 pcibios_disable_irq = acpi_pci_irq_disable;
27957- x86_init.pci.init_irq = x86_init_noop;
27958+ *(void **)&x86_init.pci.init_irq = x86_init_noop;
27959
27960 if (pci_routeirq) {
27961 /*
27962diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
27963index e14a2ff..3fd6b58 100644
27964--- a/arch/x86/pci/mrst.c
27965+++ b/arch/x86/pci/mrst.c
27966@@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
27967 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
27968 pci_mmcfg_late_init();
27969 pcibios_enable_irq = mrst_pci_irq_enable;
27970- pci_root_ops = pci_mrst_ops;
27971+ pax_open_kernel();
27972+ memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
27973+ pax_close_kernel();
27974 pci_soc_mode = 1;
27975 /* Continue with standard init */
27976 return 1;
27977diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
27978index da8fe05..7ee6704 100644
27979--- a/arch/x86/pci/pcbios.c
27980+++ b/arch/x86/pci/pcbios.c
27981@@ -79,50 +79,93 @@ union bios32 {
27982 static struct {
27983 unsigned long address;
27984 unsigned short segment;
27985-} bios32_indirect = { 0, __KERNEL_CS };
27986+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
27987
27988 /*
27989 * Returns the entry point for the given service, NULL on error
27990 */
27991
27992-static unsigned long bios32_service(unsigned long service)
27993+static unsigned long __devinit bios32_service(unsigned long service)
27994 {
27995 unsigned char return_code; /* %al */
27996 unsigned long address; /* %ebx */
27997 unsigned long length; /* %ecx */
27998 unsigned long entry; /* %edx */
27999 unsigned long flags;
28000+ struct desc_struct d, *gdt;
28001
28002 local_irq_save(flags);
28003- __asm__("lcall *(%%edi); cld"
28004+
28005+ gdt = get_cpu_gdt_table(smp_processor_id());
28006+
28007+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
28008+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
28009+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
28010+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
28011+
28012+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
28013 : "=a" (return_code),
28014 "=b" (address),
28015 "=c" (length),
28016 "=d" (entry)
28017 : "0" (service),
28018 "1" (0),
28019- "D" (&bios32_indirect));
28020+ "D" (&bios32_indirect),
28021+ "r"(__PCIBIOS_DS)
28022+ : "memory");
28023+
28024+ pax_open_kernel();
28025+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
28026+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
28027+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
28028+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
28029+ pax_close_kernel();
28030+
28031 local_irq_restore(flags);
28032
28033 switch (return_code) {
28034- case 0:
28035- return address + entry;
28036- case 0x80: /* Not present */
28037- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
28038- return 0;
28039- default: /* Shouldn't happen */
28040- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
28041- service, return_code);
28042+ case 0: {
28043+ int cpu;
28044+ unsigned char flags;
28045+
28046+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
28047+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
28048+ printk(KERN_WARNING "bios32_service: not valid\n");
28049 return 0;
28050+ }
28051+ address = address + PAGE_OFFSET;
28052+ length += 16UL; /* some BIOSs underreport this... */
28053+ flags = 4;
28054+ if (length >= 64*1024*1024) {
28055+ length >>= PAGE_SHIFT;
28056+ flags |= 8;
28057+ }
28058+
28059+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
28060+ gdt = get_cpu_gdt_table(cpu);
28061+ pack_descriptor(&d, address, length, 0x9b, flags);
28062+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
28063+ pack_descriptor(&d, address, length, 0x93, flags);
28064+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
28065+ }
28066+ return entry;
28067+ }
28068+ case 0x80: /* Not present */
28069+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
28070+ return 0;
28071+ default: /* Shouldn't happen */
28072+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
28073+ service, return_code);
28074+ return 0;
28075 }
28076 }
28077
28078 static struct {
28079 unsigned long address;
28080 unsigned short segment;
28081-} pci_indirect = { 0, __KERNEL_CS };
28082+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
28083
28084-static int pci_bios_present;
28085+static int pci_bios_present __read_only;
28086
28087 static int __devinit check_pcibios(void)
28088 {
28089@@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
28090 unsigned long flags, pcibios_entry;
28091
28092 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
28093- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
28094+ pci_indirect.address = pcibios_entry;
28095
28096 local_irq_save(flags);
28097- __asm__(
28098- "lcall *(%%edi); cld\n\t"
28099+ __asm__("movw %w6, %%ds\n\t"
28100+ "lcall *%%ss:(%%edi); 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@@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
28107 "=b" (ebx),
28108 "=c" (ecx)
28109 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
28110- "D" (&pci_indirect)
28111+ "D" (&pci_indirect),
28112+ "r" (__PCIBIOS_DS)
28113 : "memory");
28114 local_irq_restore(flags);
28115
28116@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
28117
28118 switch (len) {
28119 case 1:
28120- __asm__("lcall *(%%esi); cld\n\t"
28121+ __asm__("movw %w6, %%ds\n\t"
28122+ "lcall *%%ss:(%%esi); cld\n\t"
28123+ "push %%ss\n\t"
28124+ "pop %%ds\n\t"
28125 "jc 1f\n\t"
28126 "xor %%ah, %%ah\n"
28127 "1:"
28128@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
28129 : "1" (PCIBIOS_READ_CONFIG_BYTE),
28130 "b" (bx),
28131 "D" ((long)reg),
28132- "S" (&pci_indirect));
28133+ "S" (&pci_indirect),
28134+ "r" (__PCIBIOS_DS));
28135 /*
28136 * Zero-extend the result beyond 8 bits, do not trust the
28137 * BIOS having done it:
28138@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
28139 *value &= 0xff;
28140 break;
28141 case 2:
28142- __asm__("lcall *(%%esi); cld\n\t"
28143+ __asm__("movw %w6, %%ds\n\t"
28144+ "lcall *%%ss:(%%esi); cld\n\t"
28145+ "push %%ss\n\t"
28146+ "pop %%ds\n\t"
28147 "jc 1f\n\t"
28148 "xor %%ah, %%ah\n"
28149 "1:"
28150@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
28151 : "1" (PCIBIOS_READ_CONFIG_WORD),
28152 "b" (bx),
28153 "D" ((long)reg),
28154- "S" (&pci_indirect));
28155+ "S" (&pci_indirect),
28156+ "r" (__PCIBIOS_DS));
28157 /*
28158 * Zero-extend the result beyond 16 bits, do not trust the
28159 * BIOS having done it:
28160@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
28161 *value &= 0xffff;
28162 break;
28163 case 4:
28164- __asm__("lcall *(%%esi); cld\n\t"
28165+ __asm__("movw %w6, %%ds\n\t"
28166+ "lcall *%%ss:(%%esi); cld\n\t"
28167+ "push %%ss\n\t"
28168+ "pop %%ds\n\t"
28169 "jc 1f\n\t"
28170 "xor %%ah, %%ah\n"
28171 "1:"
28172@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
28173 : "1" (PCIBIOS_READ_CONFIG_DWORD),
28174 "b" (bx),
28175 "D" ((long)reg),
28176- "S" (&pci_indirect));
28177+ "S" (&pci_indirect),
28178+ "r" (__PCIBIOS_DS));
28179 break;
28180 }
28181
28182@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
28183
28184 switch (len) {
28185 case 1:
28186- __asm__("lcall *(%%esi); cld\n\t"
28187+ __asm__("movw %w6, %%ds\n\t"
28188+ "lcall *%%ss:(%%esi); cld\n\t"
28189+ "push %%ss\n\t"
28190+ "pop %%ds\n\t"
28191 "jc 1f\n\t"
28192 "xor %%ah, %%ah\n"
28193 "1:"
28194@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
28195 "c" (value),
28196 "b" (bx),
28197 "D" ((long)reg),
28198- "S" (&pci_indirect));
28199+ "S" (&pci_indirect),
28200+ "r" (__PCIBIOS_DS));
28201 break;
28202 case 2:
28203- __asm__("lcall *(%%esi); cld\n\t"
28204+ __asm__("movw %w6, %%ds\n\t"
28205+ "lcall *%%ss:(%%esi); cld\n\t"
28206+ "push %%ss\n\t"
28207+ "pop %%ds\n\t"
28208 "jc 1f\n\t"
28209 "xor %%ah, %%ah\n"
28210 "1:"
28211@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
28212 "c" (value),
28213 "b" (bx),
28214 "D" ((long)reg),
28215- "S" (&pci_indirect));
28216+ "S" (&pci_indirect),
28217+ "r" (__PCIBIOS_DS));
28218 break;
28219 case 4:
28220- __asm__("lcall *(%%esi); cld\n\t"
28221+ __asm__("movw %w6, %%ds\n\t"
28222+ "lcall *%%ss:(%%esi); cld\n\t"
28223+ "push %%ss\n\t"
28224+ "pop %%ds\n\t"
28225 "jc 1f\n\t"
28226 "xor %%ah, %%ah\n"
28227 "1:"
28228@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
28229 "c" (value),
28230 "b" (bx),
28231 "D" ((long)reg),
28232- "S" (&pci_indirect));
28233+ "S" (&pci_indirect),
28234+ "r" (__PCIBIOS_DS));
28235 break;
28236 }
28237
28238@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
28239
28240 DBG("PCI: Fetching IRQ routing table... ");
28241 __asm__("push %%es\n\t"
28242+ "movw %w8, %%ds\n\t"
28243 "push %%ds\n\t"
28244 "pop %%es\n\t"
28245- "lcall *(%%esi); cld\n\t"
28246+ "lcall *%%ss:(%%esi); cld\n\t"
28247 "pop %%es\n\t"
28248+ "push %%ss\n\t"
28249+ "pop %%ds\n"
28250 "jc 1f\n\t"
28251 "xor %%ah, %%ah\n"
28252 "1:"
28253@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
28254 "1" (0),
28255 "D" ((long) &opt),
28256 "S" (&pci_indirect),
28257- "m" (opt)
28258+ "m" (opt),
28259+ "r" (__PCIBIOS_DS)
28260 : "memory");
28261 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
28262 if (ret & 0xff00)
28263@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
28264 {
28265 int ret;
28266
28267- __asm__("lcall *(%%esi); cld\n\t"
28268+ __asm__("movw %w5, %%ds\n\t"
28269+ "lcall *%%ss:(%%esi); cld\n\t"
28270+ "push %%ss\n\t"
28271+ "pop %%ds\n"
28272 "jc 1f\n\t"
28273 "xor %%ah, %%ah\n"
28274 "1:"
28275@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
28276 : "0" (PCIBIOS_SET_PCI_HW_INT),
28277 "b" ((dev->bus->number << 8) | dev->devfn),
28278 "c" ((irq << 8) | (pin + 10)),
28279- "S" (&pci_indirect));
28280+ "S" (&pci_indirect),
28281+ "r" (__PCIBIOS_DS));
28282 return !(ret & 0xff00);
28283 }
28284 EXPORT_SYMBOL(pcibios_set_irq_routing);
28285diff --git a/arch/x86/pci/xen.c b/arch/x86/pci/xen.c
28286index 56ab749..3cb792a 100644
28287--- a/arch/x86/pci/xen.c
28288+++ b/arch/x86/pci/xen.c
28289@@ -395,9 +395,9 @@ int __init pci_xen_init(void)
28290 #endif
28291
28292 #ifdef CONFIG_PCI_MSI
28293- x86_msi.setup_msi_irqs = xen_setup_msi_irqs;
28294- x86_msi.teardown_msi_irq = xen_teardown_msi_irq;
28295- x86_msi.teardown_msi_irqs = xen_teardown_msi_irqs;
28296+ *(void **)&x86_msi.setup_msi_irqs = xen_setup_msi_irqs;
28297+ *(void **)&x86_msi.teardown_msi_irq = xen_teardown_msi_irq;
28298+ *(void **)&x86_msi.teardown_msi_irqs = xen_teardown_msi_irqs;
28299 #endif
28300 return 0;
28301 }
28302@@ -416,8 +416,8 @@ int __init pci_xen_hvm_init(void)
28303 #endif
28304
28305 #ifdef CONFIG_PCI_MSI
28306- x86_msi.setup_msi_irqs = xen_hvm_setup_msi_irqs;
28307- x86_msi.teardown_msi_irq = xen_teardown_msi_irq;
28308+ *(void **)&x86_msi.setup_msi_irqs = xen_hvm_setup_msi_irqs;
28309+ *(void **)&x86_msi.teardown_msi_irq = xen_teardown_msi_irq;
28310 #endif
28311 return 0;
28312 }
28313@@ -474,9 +474,9 @@ int __init pci_xen_initial_domain(void)
28314 int irq;
28315
28316 #ifdef CONFIG_PCI_MSI
28317- x86_msi.setup_msi_irqs = xen_initdom_setup_msi_irqs;
28318- x86_msi.teardown_msi_irq = xen_teardown_msi_irq;
28319- x86_msi.restore_msi_irqs = xen_initdom_restore_msi_irqs;
28320+ *(void **)&x86_msi.setup_msi_irqs = xen_initdom_setup_msi_irqs;
28321+ *(void **)&x86_msi.teardown_msi_irq = xen_teardown_msi_irq;
28322+ *(void **)&x86_msi.restore_msi_irqs = xen_initdom_restore_msi_irqs;
28323 #endif
28324 xen_setup_acpi_sci();
28325 __acpi_register_gsi = acpi_register_gsi_xen;
28326diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c
28327index 77cf009..7fe44c8 100644
28328--- a/arch/x86/platform/efi/efi.c
28329+++ b/arch/x86/platform/efi/efi.c
28330@@ -746,8 +746,8 @@ void __init efi_init(void)
28331
28332 #ifdef CONFIG_X86_32
28333 if (efi_is_native()) {
28334- x86_platform.get_wallclock = efi_get_time;
28335- x86_platform.set_wallclock = efi_set_rtc_mmss;
28336+ *(void **)&x86_platform.get_wallclock = efi_get_time;
28337+ *(void **)&x86_platform.set_wallclock = efi_set_rtc_mmss;
28338 }
28339 #endif
28340
28341diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
28342index 40e4469..1ab536e 100644
28343--- a/arch/x86/platform/efi/efi_32.c
28344+++ b/arch/x86/platform/efi/efi_32.c
28345@@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
28346 {
28347 struct desc_ptr gdt_descr;
28348
28349+#ifdef CONFIG_PAX_KERNEXEC
28350+ struct desc_struct d;
28351+#endif
28352+
28353 local_irq_save(efi_rt_eflags);
28354
28355 load_cr3(initial_page_table);
28356 __flush_tlb_all();
28357
28358+#ifdef CONFIG_PAX_KERNEXEC
28359+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
28360+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
28361+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
28362+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
28363+#endif
28364+
28365 gdt_descr.address = __pa(get_cpu_gdt_table(0));
28366 gdt_descr.size = GDT_SIZE - 1;
28367 load_gdt(&gdt_descr);
28368@@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
28369 {
28370 struct desc_ptr gdt_descr;
28371
28372+#ifdef CONFIG_PAX_KERNEXEC
28373+ struct desc_struct d;
28374+
28375+ memset(&d, 0, sizeof d);
28376+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
28377+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
28378+#endif
28379+
28380 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
28381 gdt_descr.size = GDT_SIZE - 1;
28382 load_gdt(&gdt_descr);
28383diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
28384index fbe66e6..eae5e38 100644
28385--- a/arch/x86/platform/efi/efi_stub_32.S
28386+++ b/arch/x86/platform/efi/efi_stub_32.S
28387@@ -6,7 +6,9 @@
28388 */
28389
28390 #include <linux/linkage.h>
28391+#include <linux/init.h>
28392 #include <asm/page_types.h>
28393+#include <asm/segment.h>
28394
28395 /*
28396 * efi_call_phys(void *, ...) is a function with variable parameters.
28397@@ -20,7 +22,7 @@
28398 * service functions will comply with gcc calling convention, too.
28399 */
28400
28401-.text
28402+__INIT
28403 ENTRY(efi_call_phys)
28404 /*
28405 * 0. The function can only be called in Linux kernel. So CS has been
28406@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
28407 * The mapping of lower virtual memory has been created in prelog and
28408 * epilog.
28409 */
28410- movl $1f, %edx
28411- subl $__PAGE_OFFSET, %edx
28412- jmp *%edx
28413+#ifdef CONFIG_PAX_KERNEXEC
28414+ movl $(__KERNEXEC_EFI_DS), %edx
28415+ mov %edx, %ds
28416+ mov %edx, %es
28417+ mov %edx, %ss
28418+ addl $2f,(1f)
28419+ ljmp *(1f)
28420+
28421+__INITDATA
28422+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
28423+.previous
28424+
28425+2:
28426+ subl $2b,(1b)
28427+#else
28428+ jmp 1f-__PAGE_OFFSET
28429 1:
28430+#endif
28431
28432 /*
28433 * 2. Now on the top of stack is the return
28434@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
28435 * parameter 2, ..., param n. To make things easy, we save the return
28436 * address of efi_call_phys in a global variable.
28437 */
28438- popl %edx
28439- movl %edx, saved_return_addr
28440- /* get the function pointer into ECX*/
28441- popl %ecx
28442- movl %ecx, efi_rt_function_ptr
28443- movl $2f, %edx
28444- subl $__PAGE_OFFSET, %edx
28445- pushl %edx
28446+ popl (saved_return_addr)
28447+ popl (efi_rt_function_ptr)
28448
28449 /*
28450 * 3. Clear PG bit in %CR0.
28451@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
28452 /*
28453 * 5. Call the physical function.
28454 */
28455- jmp *%ecx
28456+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
28457
28458-2:
28459 /*
28460 * 6. After EFI runtime service returns, control will return to
28461 * following instruction. We'd better readjust stack pointer first.
28462@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
28463 movl %cr0, %edx
28464 orl $0x80000000, %edx
28465 movl %edx, %cr0
28466- jmp 1f
28467-1:
28468+
28469 /*
28470 * 8. Now restore the virtual mode from flat mode by
28471 * adding EIP with PAGE_OFFSET.
28472 */
28473- movl $1f, %edx
28474- jmp *%edx
28475+#ifdef CONFIG_PAX_KERNEXEC
28476+ movl $(__KERNEL_DS), %edx
28477+ mov %edx, %ds
28478+ mov %edx, %es
28479+ mov %edx, %ss
28480+ ljmp $(__KERNEL_CS),$1f
28481+#else
28482+ jmp 1f+__PAGE_OFFSET
28483+#endif
28484 1:
28485
28486 /*
28487 * 9. Balance the stack. And because EAX contain the return value,
28488 * we'd better not clobber it.
28489 */
28490- leal efi_rt_function_ptr, %edx
28491- movl (%edx), %ecx
28492- pushl %ecx
28493+ pushl (efi_rt_function_ptr)
28494
28495 /*
28496- * 10. Push the saved return address onto the stack and return.
28497+ * 10. Return to the saved return address.
28498 */
28499- leal saved_return_addr, %edx
28500- movl (%edx), %ecx
28501- pushl %ecx
28502- ret
28503+ jmpl *(saved_return_addr)
28504 ENDPROC(efi_call_phys)
28505 .previous
28506
28507-.data
28508+__INITDATA
28509 saved_return_addr:
28510 .long 0
28511 efi_rt_function_ptr:
28512diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
28513index 4c07cca..2c8427d 100644
28514--- a/arch/x86/platform/efi/efi_stub_64.S
28515+++ b/arch/x86/platform/efi/efi_stub_64.S
28516@@ -7,6 +7,7 @@
28517 */
28518
28519 #include <linux/linkage.h>
28520+#include <asm/alternative-asm.h>
28521
28522 #define SAVE_XMM \
28523 mov %rsp, %rax; \
28524@@ -40,6 +41,7 @@ ENTRY(efi_call0)
28525 call *%rdi
28526 addq $32, %rsp
28527 RESTORE_XMM
28528+ pax_force_retaddr 0, 1
28529 ret
28530 ENDPROC(efi_call0)
28531
28532@@ -50,6 +52,7 @@ ENTRY(efi_call1)
28533 call *%rdi
28534 addq $32, %rsp
28535 RESTORE_XMM
28536+ pax_force_retaddr 0, 1
28537 ret
28538 ENDPROC(efi_call1)
28539
28540@@ -60,6 +63,7 @@ ENTRY(efi_call2)
28541 call *%rdi
28542 addq $32, %rsp
28543 RESTORE_XMM
28544+ pax_force_retaddr 0, 1
28545 ret
28546 ENDPROC(efi_call2)
28547
28548@@ -71,6 +75,7 @@ ENTRY(efi_call3)
28549 call *%rdi
28550 addq $32, %rsp
28551 RESTORE_XMM
28552+ pax_force_retaddr 0, 1
28553 ret
28554 ENDPROC(efi_call3)
28555
28556@@ -83,6 +88,7 @@ ENTRY(efi_call4)
28557 call *%rdi
28558 addq $32, %rsp
28559 RESTORE_XMM
28560+ pax_force_retaddr 0, 1
28561 ret
28562 ENDPROC(efi_call4)
28563
28564@@ -96,6 +102,7 @@ ENTRY(efi_call5)
28565 call *%rdi
28566 addq $48, %rsp
28567 RESTORE_XMM
28568+ pax_force_retaddr 0, 1
28569 ret
28570 ENDPROC(efi_call5)
28571
28572@@ -112,5 +119,6 @@ ENTRY(efi_call6)
28573 call *%rdi
28574 addq $48, %rsp
28575 RESTORE_XMM
28576+ pax_force_retaddr 0, 1
28577 ret
28578 ENDPROC(efi_call6)
28579diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
28580index fd41a92..bc8091d 100644
28581--- a/arch/x86/platform/mrst/mrst.c
28582+++ b/arch/x86/platform/mrst/mrst.c
28583@@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
28584 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
28585 int sfi_mrtc_num;
28586
28587-static void mrst_power_off(void)
28588+static __noreturn void mrst_power_off(void)
28589 {
28590+ BUG();
28591 }
28592
28593-static void mrst_reboot(void)
28594+static __noreturn void mrst_reboot(void)
28595 {
28596 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
28597+ BUG();
28598 }
28599
28600 /* parse all the mtimer info to a static mtimer array */
28601@@ -233,14 +235,14 @@ static void __init mrst_time_init(void)
28602 case MRST_TIMER_APBT_ONLY:
28603 break;
28604 case MRST_TIMER_LAPIC_APBT:
28605- x86_init.timers.setup_percpu_clockev = setup_boot_APIC_clock;
28606- x86_cpuinit.setup_percpu_clockev = setup_secondary_APIC_clock;
28607+ *(void **)&x86_init.timers.setup_percpu_clockev = setup_boot_APIC_clock;
28608+ *(void **)&x86_cpuinit.setup_percpu_clockev = setup_secondary_APIC_clock;
28609 break;
28610 default:
28611 if (!boot_cpu_has(X86_FEATURE_ARAT))
28612 break;
28613- x86_init.timers.setup_percpu_clockev = setup_boot_APIC_clock;
28614- x86_cpuinit.setup_percpu_clockev = setup_secondary_APIC_clock;
28615+ *(void **)&x86_init.timers.setup_percpu_clockev = setup_boot_APIC_clock;
28616+ *(void **)&x86_cpuinit.setup_percpu_clockev = setup_secondary_APIC_clock;
28617 return;
28618 }
28619 /* we need at least one APB timer */
28620@@ -282,35 +284,35 @@ static unsigned char mrst_get_nmi_reason(void)
28621 */
28622 void __init x86_mrst_early_setup(void)
28623 {
28624- x86_init.resources.probe_roms = x86_init_noop;
28625- x86_init.resources.reserve_resources = x86_init_noop;
28626+ *(void **)&x86_init.resources.probe_roms = x86_init_noop;
28627+ *(void **)&x86_init.resources.reserve_resources = x86_init_noop;
28628
28629- x86_init.timers.timer_init = mrst_time_init;
28630- x86_init.timers.setup_percpu_clockev = x86_init_noop;
28631+ *(void **)&x86_init.timers.timer_init = mrst_time_init;
28632+ *(void **)&x86_init.timers.setup_percpu_clockev = x86_init_noop;
28633
28634- x86_init.irqs.pre_vector_init = x86_init_noop;
28635+ *(void **)&x86_init.irqs.pre_vector_init = x86_init_noop;
28636
28637- x86_init.oem.arch_setup = mrst_arch_setup;
28638+ *(void **)&x86_init.oem.arch_setup = mrst_arch_setup;
28639
28640- x86_cpuinit.setup_percpu_clockev = apbt_setup_secondary_clock;
28641+ *(void **)&x86_cpuinit.setup_percpu_clockev = apbt_setup_secondary_clock;
28642
28643- x86_platform.calibrate_tsc = mrst_calibrate_tsc;
28644- x86_platform.i8042_detect = mrst_i8042_detect;
28645- x86_init.timers.wallclock_init = mrst_rtc_init;
28646- x86_platform.get_nmi_reason = mrst_get_nmi_reason;
28647+ *(void **)&x86_platform.calibrate_tsc = mrst_calibrate_tsc;
28648+ *(void **)&x86_platform.i8042_detect = mrst_i8042_detect;
28649+ *(void **)&x86_init.timers.wallclock_init = mrst_rtc_init;
28650+ *(void **)&x86_platform.get_nmi_reason = mrst_get_nmi_reason;
28651
28652- x86_init.pci.init = pci_mrst_init;
28653- x86_init.pci.fixup_irqs = x86_init_noop;
28654+ *(void **)&x86_init.pci.init = pci_mrst_init;
28655+ *(void **)&x86_init.pci.fixup_irqs = x86_init_noop;
28656
28657 legacy_pic = &null_legacy_pic;
28658
28659 /* Moorestown specific power_off/restart method */
28660 pm_power_off = mrst_power_off;
28661- machine_ops.emergency_restart = mrst_reboot;
28662+ *(void **)&machine_ops.emergency_restart = mrst_reboot;
28663
28664 /* Avoid searching for BIOS MP tables */
28665- x86_init.mpparse.find_smp_config = x86_init_noop;
28666- x86_init.mpparse.get_smp_config = x86_init_uint_noop;
28667+ *(void **)&x86_init.mpparse.find_smp_config = x86_init_noop;
28668+ *(void **)&x86_init.mpparse.get_smp_config = x86_init_uint_noop;
28669 set_bit(MP_BUS_ISA, mp_bus_not_pci);
28670 }
28671
28672diff --git a/arch/x86/platform/mrst/vrtc.c b/arch/x86/platform/mrst/vrtc.c
28673index 225bd0f..22e8086 100644
28674--- a/arch/x86/platform/mrst/vrtc.c
28675+++ b/arch/x86/platform/mrst/vrtc.c
28676@@ -120,8 +120,8 @@ void __init mrst_rtc_init(void)
28677
28678 vrtc_virt_base = (void __iomem *)set_fixmap_offset_nocache(FIX_LNW_VRTC,
28679 vrtc_paddr);
28680- x86_platform.get_wallclock = vrtc_get_time;
28681- x86_platform.set_wallclock = vrtc_set_mmss;
28682+ *(void **)&x86_platform.get_wallclock = vrtc_get_time;
28683+ *(void **)&x86_platform.set_wallclock = vrtc_set_mmss;
28684 }
28685
28686 /*
28687diff --git a/arch/x86/platform/olpc/olpc.c b/arch/x86/platform/olpc/olpc.c
28688index 2737608..0d62cc2 100644
28689--- a/arch/x86/platform/olpc/olpc.c
28690+++ b/arch/x86/platform/olpc/olpc.c
28691@@ -395,7 +395,7 @@ static int __init olpc_init(void)
28692 * XO-1 only. */
28693 if (olpc_platform_info.boardrev < olpc_board_pre(0xd0) &&
28694 !cs5535_has_vsa2())
28695- x86_init.pci.arch_init = pci_olpc_init;
28696+ *(void **)&x86_init.pci.arch_init = pci_olpc_init;
28697 #endif
28698
28699 if (olpc_platform_info.boardrev < olpc_board_pre(0xd0)) { /* XO-1 */
28700diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
28701index d6ee929..3637cb5 100644
28702--- a/arch/x86/platform/olpc/olpc_dt.c
28703+++ b/arch/x86/platform/olpc/olpc_dt.c
28704@@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
28705 return res;
28706 }
28707
28708-static struct of_pdt_ops prom_olpc_ops __initdata = {
28709+static struct of_pdt_ops prom_olpc_ops __initconst = {
28710 .nextprop = olpc_dt_nextprop,
28711 .getproplen = olpc_dt_getproplen,
28712 .getproperty = olpc_dt_getproperty,
28713diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
28714index 218cdb1..c1178eb 100644
28715--- a/arch/x86/power/cpu.c
28716+++ b/arch/x86/power/cpu.c
28717@@ -132,7 +132,7 @@ static void do_fpu_end(void)
28718 static void fix_processor_context(void)
28719 {
28720 int cpu = smp_processor_id();
28721- struct tss_struct *t = &per_cpu(init_tss, cpu);
28722+ struct tss_struct *t = init_tss + cpu;
28723
28724 set_tss_desc(cpu, t); /*
28725 * This just modifies memory; should not be
28726@@ -142,8 +142,6 @@ static void fix_processor_context(void)
28727 */
28728
28729 #ifdef CONFIG_X86_64
28730- get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
28731-
28732 syscall_init(); /* This sets MSR_*STAR and related */
28733 #endif
28734 load_TR_desc(); /* This does ltr */
28735diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
28736index cbca565..bae7133 100644
28737--- a/arch/x86/realmode/init.c
28738+++ b/arch/x86/realmode/init.c
28739@@ -62,7 +62,13 @@ void __init setup_real_mode(void)
28740 __va(real_mode_header->trampoline_header);
28741
28742 #ifdef CONFIG_X86_32
28743- trampoline_header->start = __pa(startup_32_smp);
28744+ trampoline_header->start = __pa(ktla_ktva(startup_32_smp));
28745+
28746+#ifdef CONFIG_PAX_KERNEXEC
28747+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
28748+#endif
28749+
28750+ trampoline_header->boot_cs = __BOOT_CS;
28751 trampoline_header->gdt_limit = __BOOT_DS + 7;
28752 trampoline_header->gdt_base = __pa(boot_gdt);
28753 #else
28754diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
28755index 8869287..d577672 100644
28756--- a/arch/x86/realmode/rm/Makefile
28757+++ b/arch/x86/realmode/rm/Makefile
28758@@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
28759 $(call cc-option, -fno-unit-at-a-time)) \
28760 $(call cc-option, -fno-stack-protector) \
28761 $(call cc-option, -mpreferred-stack-boundary=2)
28762+ifdef CONSTIFY_PLUGIN
28763+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
28764+endif
28765 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
28766 GCOV_PROFILE := n
28767diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
28768index a28221d..93c40f1 100644
28769--- a/arch/x86/realmode/rm/header.S
28770+++ b/arch/x86/realmode/rm/header.S
28771@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
28772 #endif
28773 /* APM/BIOS reboot */
28774 .long pa_machine_real_restart_asm
28775-#ifdef CONFIG_X86_64
28776+#ifdef CONFIG_X86_32
28777+ .long __KERNEL_CS
28778+#else
28779 .long __KERNEL32_CS
28780 #endif
28781 END(real_mode_header)
28782diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
28783index c1b2791..f9e31c7 100644
28784--- a/arch/x86/realmode/rm/trampoline_32.S
28785+++ b/arch/x86/realmode/rm/trampoline_32.S
28786@@ -25,6 +25,12 @@
28787 #include <asm/page_types.h>
28788 #include "realmode.h"
28789
28790+#ifdef CONFIG_PAX_KERNEXEC
28791+#define ta(X) (X)
28792+#else
28793+#define ta(X) (pa_ ## X)
28794+#endif
28795+
28796 .text
28797 .code16
28798
28799@@ -39,8 +45,6 @@ ENTRY(trampoline_start)
28800
28801 cli # We should be safe anyway
28802
28803- movl tr_start, %eax # where we need to go
28804-
28805 movl $0xA5A5A5A5, trampoline_status
28806 # write marker for master knows we're running
28807
28808@@ -56,7 +60,7 @@ ENTRY(trampoline_start)
28809 movw $1, %dx # protected mode (PE) bit
28810 lmsw %dx # into protected mode
28811
28812- ljmpl $__BOOT_CS, $pa_startup_32
28813+ ljmpl *(trampoline_header)
28814
28815 .section ".text32","ax"
28816 .code32
28817@@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
28818 .balign 8
28819 GLOBAL(trampoline_header)
28820 tr_start: .space 4
28821- tr_gdt_pad: .space 2
28822+ tr_boot_cs: .space 2
28823 tr_gdt: .space 6
28824 END(trampoline_header)
28825
28826diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
28827index bb360dc..3e5945f 100644
28828--- a/arch/x86/realmode/rm/trampoline_64.S
28829+++ b/arch/x86/realmode/rm/trampoline_64.S
28830@@ -107,7 +107,7 @@ ENTRY(startup_32)
28831 wrmsr
28832
28833 # Enable paging and in turn activate Long Mode
28834- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
28835+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
28836 movl %eax, %cr0
28837
28838 /*
28839diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
28840index 5a1847d..deccb30 100644
28841--- a/arch/x86/tools/relocs.c
28842+++ b/arch/x86/tools/relocs.c
28843@@ -12,10 +12,13 @@
28844 #include <regex.h>
28845 #include <tools/le_byteshift.h>
28846
28847+#include "../../../include/generated/autoconf.h"
28848+
28849 static void die(char *fmt, ...);
28850
28851 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
28852 static Elf32_Ehdr ehdr;
28853+static Elf32_Phdr *phdr;
28854 static unsigned long reloc_count, reloc_idx;
28855 static unsigned long *relocs;
28856 static unsigned long reloc16_count, reloc16_idx;
28857@@ -330,9 +333,39 @@ static void read_ehdr(FILE *fp)
28858 }
28859 }
28860
28861+static void read_phdrs(FILE *fp)
28862+{
28863+ unsigned int i;
28864+
28865+ phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
28866+ if (!phdr) {
28867+ die("Unable to allocate %d program headers\n",
28868+ ehdr.e_phnum);
28869+ }
28870+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
28871+ die("Seek to %d failed: %s\n",
28872+ ehdr.e_phoff, strerror(errno));
28873+ }
28874+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
28875+ die("Cannot read ELF program headers: %s\n",
28876+ strerror(errno));
28877+ }
28878+ for(i = 0; i < ehdr.e_phnum; i++) {
28879+ phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
28880+ phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
28881+ phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
28882+ phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
28883+ phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
28884+ phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
28885+ phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
28886+ phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
28887+ }
28888+
28889+}
28890+
28891 static void read_shdrs(FILE *fp)
28892 {
28893- int i;
28894+ unsigned int i;
28895 Elf32_Shdr shdr;
28896
28897 secs = calloc(ehdr.e_shnum, sizeof(struct section));
28898@@ -367,7 +400,7 @@ static void read_shdrs(FILE *fp)
28899
28900 static void read_strtabs(FILE *fp)
28901 {
28902- int i;
28903+ unsigned int i;
28904 for (i = 0; i < ehdr.e_shnum; i++) {
28905 struct section *sec = &secs[i];
28906 if (sec->shdr.sh_type != SHT_STRTAB) {
28907@@ -392,7 +425,7 @@ static void read_strtabs(FILE *fp)
28908
28909 static void read_symtabs(FILE *fp)
28910 {
28911- int i,j;
28912+ unsigned int i,j;
28913 for (i = 0; i < ehdr.e_shnum; i++) {
28914 struct section *sec = &secs[i];
28915 if (sec->shdr.sh_type != SHT_SYMTAB) {
28916@@ -423,9 +456,11 @@ static void read_symtabs(FILE *fp)
28917 }
28918
28919
28920-static void read_relocs(FILE *fp)
28921+static void read_relocs(FILE *fp, int use_real_mode)
28922 {
28923- int i,j;
28924+ unsigned int i,j;
28925+ uint32_t base;
28926+
28927 for (i = 0; i < ehdr.e_shnum; i++) {
28928 struct section *sec = &secs[i];
28929 if (sec->shdr.sh_type != SHT_REL) {
28930@@ -445,9 +480,22 @@ static void read_relocs(FILE *fp)
28931 die("Cannot read symbol table: %s\n",
28932 strerror(errno));
28933 }
28934+ base = 0;
28935+
28936+#ifdef CONFIG_X86_32
28937+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
28938+ if (phdr[j].p_type != PT_LOAD )
28939+ continue;
28940+ 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)
28941+ continue;
28942+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
28943+ break;
28944+ }
28945+#endif
28946+
28947 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
28948 Elf32_Rel *rel = &sec->reltab[j];
28949- rel->r_offset = elf32_to_cpu(rel->r_offset);
28950+ rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
28951 rel->r_info = elf32_to_cpu(rel->r_info);
28952 }
28953 }
28954@@ -456,13 +504,13 @@ static void read_relocs(FILE *fp)
28955
28956 static void print_absolute_symbols(void)
28957 {
28958- int i;
28959+ unsigned int i;
28960 printf("Absolute symbols\n");
28961 printf(" Num: Value Size Type Bind Visibility Name\n");
28962 for (i = 0; i < ehdr.e_shnum; i++) {
28963 struct section *sec = &secs[i];
28964 char *sym_strtab;
28965- int j;
28966+ unsigned int j;
28967
28968 if (sec->shdr.sh_type != SHT_SYMTAB) {
28969 continue;
28970@@ -489,14 +537,14 @@ static void print_absolute_symbols(void)
28971
28972 static void print_absolute_relocs(void)
28973 {
28974- int i, printed = 0;
28975+ unsigned int i, printed = 0;
28976
28977 for (i = 0; i < ehdr.e_shnum; i++) {
28978 struct section *sec = &secs[i];
28979 struct section *sec_applies, *sec_symtab;
28980 char *sym_strtab;
28981 Elf32_Sym *sh_symtab;
28982- int j;
28983+ unsigned int j;
28984 if (sec->shdr.sh_type != SHT_REL) {
28985 continue;
28986 }
28987@@ -558,13 +606,13 @@ static void print_absolute_relocs(void)
28988 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
28989 int use_real_mode)
28990 {
28991- int i;
28992+ unsigned int i;
28993 /* Walk through the relocations */
28994 for (i = 0; i < ehdr.e_shnum; i++) {
28995 char *sym_strtab;
28996 Elf32_Sym *sh_symtab;
28997 struct section *sec_applies, *sec_symtab;
28998- int j;
28999+ unsigned int j;
29000 struct section *sec = &secs[i];
29001
29002 if (sec->shdr.sh_type != SHT_REL) {
29003@@ -588,6 +636,24 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
29004 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
29005 r_type = ELF32_R_TYPE(rel->r_info);
29006
29007+ if (!use_real_mode) {
29008+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
29009+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
29010+ continue;
29011+
29012+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
29013+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
29014+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
29015+ continue;
29016+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
29017+ continue;
29018+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
29019+ continue;
29020+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
29021+ continue;
29022+#endif
29023+ }
29024+
29025 shn_abs = sym->st_shndx == SHN_ABS;
29026
29027 switch (r_type) {
29028@@ -681,7 +747,7 @@ static int write32(unsigned int v, FILE *f)
29029
29030 static void emit_relocs(int as_text, int use_real_mode)
29031 {
29032- int i;
29033+ unsigned int i;
29034 /* Count how many relocations I have and allocate space for them. */
29035 reloc_count = 0;
29036 walk_relocs(count_reloc, use_real_mode);
29037@@ -808,10 +874,11 @@ int main(int argc, char **argv)
29038 fname, strerror(errno));
29039 }
29040 read_ehdr(fp);
29041+ read_phdrs(fp);
29042 read_shdrs(fp);
29043 read_strtabs(fp);
29044 read_symtabs(fp);
29045- read_relocs(fp);
29046+ read_relocs(fp, use_real_mode);
29047 if (show_absolute_syms) {
29048 print_absolute_symbols();
29049 return 0;
29050diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
29051index fd14be1..e3c79c0 100644
29052--- a/arch/x86/vdso/Makefile
29053+++ b/arch/x86/vdso/Makefile
29054@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
29055 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
29056 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
29057
29058-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
29059+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
29060 GCOV_PROFILE := n
29061
29062 #
29063diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
29064index 0faad64..39ef157 100644
29065--- a/arch/x86/vdso/vdso32-setup.c
29066+++ b/arch/x86/vdso/vdso32-setup.c
29067@@ -25,6 +25,7 @@
29068 #include <asm/tlbflush.h>
29069 #include <asm/vdso.h>
29070 #include <asm/proto.h>
29071+#include <asm/mman.h>
29072
29073 enum {
29074 VDSO_DISABLED = 0,
29075@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
29076 void enable_sep_cpu(void)
29077 {
29078 int cpu = get_cpu();
29079- struct tss_struct *tss = &per_cpu(init_tss, cpu);
29080+ struct tss_struct *tss = init_tss + cpu;
29081
29082 if (!boot_cpu_has(X86_FEATURE_SEP)) {
29083 put_cpu();
29084@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
29085 gate_vma.vm_start = FIXADDR_USER_START;
29086 gate_vma.vm_end = FIXADDR_USER_END;
29087 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
29088- gate_vma.vm_page_prot = __P101;
29089+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
29090
29091 return 0;
29092 }
29093@@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
29094 if (compat)
29095 addr = VDSO_HIGH_BASE;
29096 else {
29097- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
29098+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
29099 if (IS_ERR_VALUE(addr)) {
29100 ret = addr;
29101 goto up_fail;
29102 }
29103 }
29104
29105- current->mm->context.vdso = (void *)addr;
29106+ current->mm->context.vdso = addr;
29107
29108 if (compat_uses_vma || !compat) {
29109 /*
29110@@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
29111 }
29112
29113 current_thread_info()->sysenter_return =
29114- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
29115+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
29116
29117 up_fail:
29118 if (ret)
29119- current->mm->context.vdso = NULL;
29120+ current->mm->context.vdso = 0;
29121
29122 up_write(&mm->mmap_sem);
29123
29124@@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
29125
29126 const char *arch_vma_name(struct vm_area_struct *vma)
29127 {
29128- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
29129+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
29130 return "[vdso]";
29131+
29132+#ifdef CONFIG_PAX_SEGMEXEC
29133+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
29134+ return "[vdso]";
29135+#endif
29136+
29137 return NULL;
29138 }
29139
29140@@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
29141 * Check to see if the corresponding task was created in compat vdso
29142 * mode.
29143 */
29144- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
29145+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
29146 return &gate_vma;
29147 return NULL;
29148 }
29149diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
29150index 00aaf04..4a26505 100644
29151--- a/arch/x86/vdso/vma.c
29152+++ b/arch/x86/vdso/vma.c
29153@@ -16,8 +16,6 @@
29154 #include <asm/vdso.h>
29155 #include <asm/page.h>
29156
29157-unsigned int __read_mostly vdso_enabled = 1;
29158-
29159 extern char vdso_start[], vdso_end[];
29160 extern unsigned short vdso_sync_cpuid;
29161
29162@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
29163 * unaligned here as a result of stack start randomization.
29164 */
29165 addr = PAGE_ALIGN(addr);
29166- addr = align_addr(addr, NULL, ALIGN_VDSO);
29167
29168 return addr;
29169 }
29170@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
29171 unsigned size)
29172 {
29173 struct mm_struct *mm = current->mm;
29174- unsigned long addr;
29175+ unsigned long addr = 0;
29176 int ret;
29177
29178- if (!vdso_enabled)
29179- return 0;
29180-
29181 down_write(&mm->mmap_sem);
29182+
29183+#ifdef CONFIG_PAX_RANDMMAP
29184+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
29185+#endif
29186+
29187 addr = vdso_addr(mm->start_stack, size);
29188+ addr = align_addr(addr, NULL, ALIGN_VDSO);
29189 addr = get_unmapped_area(NULL, addr, size, 0, 0);
29190 if (IS_ERR_VALUE(addr)) {
29191 ret = addr;
29192 goto up_fail;
29193 }
29194
29195- current->mm->context.vdso = (void *)addr;
29196+ mm->context.vdso = addr;
29197
29198 ret = install_special_mapping(mm, addr, size,
29199 VM_READ|VM_EXEC|
29200 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
29201 pages);
29202- if (ret) {
29203- current->mm->context.vdso = NULL;
29204- goto up_fail;
29205- }
29206+ if (ret)
29207+ mm->context.vdso = 0;
29208
29209 up_fail:
29210 up_write(&mm->mmap_sem);
29211@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
29212 vdsox32_size);
29213 }
29214 #endif
29215-
29216-static __init int vdso_setup(char *s)
29217-{
29218- vdso_enabled = simple_strtoul(s, NULL, 0);
29219- return 0;
29220-}
29221-__setup("vdso=", vdso_setup);
29222diff --git a/arch/x86/xen/apic.c b/arch/x86/xen/apic.c
29223index 7005ced..530d6eb 100644
29224--- a/arch/x86/xen/apic.c
29225+++ b/arch/x86/xen/apic.c
29226@@ -30,5 +30,5 @@ static unsigned int xen_io_apic_read(unsigned apic, unsigned reg)
29227
29228 void __init xen_init_apic(void)
29229 {
29230- x86_io_apic_ops.read = xen_io_apic_read;
29231+ *(void **)&x86_io_apic_ops.read = xen_io_apic_read;
29232 }
29233diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
29234index 586d838..9181904 100644
29235--- a/arch/x86/xen/enlighten.c
29236+++ b/arch/x86/xen/enlighten.c
29237@@ -99,8 +99,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
29238
29239 struct shared_info xen_dummy_shared_info;
29240
29241-void *xen_initial_gdt;
29242-
29243 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
29244 __read_mostly int xen_have_vector_callback;
29245 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
29246@@ -473,8 +471,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
29247 {
29248 unsigned long va = dtr->address;
29249 unsigned int size = dtr->size + 1;
29250- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
29251- unsigned long frames[pages];
29252+ unsigned long frames[65536 / PAGE_SIZE];
29253 int f;
29254
29255 /*
29256@@ -522,8 +519,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
29257 {
29258 unsigned long va = dtr->address;
29259 unsigned int size = dtr->size + 1;
29260- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
29261- unsigned long frames[pages];
29262+ unsigned long frames[65536 / PAGE_SIZE];
29263 int f;
29264
29265 /*
29266@@ -918,21 +914,21 @@ static u32 xen_safe_apic_wait_icr_idle(void)
29267
29268 static void set_xen_basic_apic_ops(void)
29269 {
29270- apic->read = xen_apic_read;
29271- apic->write = xen_apic_write;
29272- apic->icr_read = xen_apic_icr_read;
29273- apic->icr_write = xen_apic_icr_write;
29274- apic->wait_icr_idle = xen_apic_wait_icr_idle;
29275- apic->safe_wait_icr_idle = xen_safe_apic_wait_icr_idle;
29276- apic->set_apic_id = xen_set_apic_id;
29277- apic->get_apic_id = xen_get_apic_id;
29278+ *(void **)&apic->read = xen_apic_read;
29279+ *(void **)&apic->write = xen_apic_write;
29280+ *(void **)&apic->icr_read = xen_apic_icr_read;
29281+ *(void **)&apic->icr_write = xen_apic_icr_write;
29282+ *(void **)&apic->wait_icr_idle = xen_apic_wait_icr_idle;
29283+ *(void **)&apic->safe_wait_icr_idle = xen_safe_apic_wait_icr_idle;
29284+ *(void **)&apic->set_apic_id = xen_set_apic_id;
29285+ *(void **)&apic->get_apic_id = xen_get_apic_id;
29286
29287 #ifdef CONFIG_SMP
29288- apic->send_IPI_allbutself = xen_send_IPI_allbutself;
29289- apic->send_IPI_mask_allbutself = xen_send_IPI_mask_allbutself;
29290- apic->send_IPI_mask = xen_send_IPI_mask;
29291- apic->send_IPI_all = xen_send_IPI_all;
29292- apic->send_IPI_self = xen_send_IPI_self;
29293+ *(void **)&apic->send_IPI_allbutself = xen_send_IPI_allbutself;
29294+ *(void **)&apic->send_IPI_mask_allbutself = xen_send_IPI_mask_allbutself;
29295+ *(void **)&apic->send_IPI_mask = xen_send_IPI_mask;
29296+ *(void **)&apic->send_IPI_all = xen_send_IPI_all;
29297+ *(void **)&apic->send_IPI_self = xen_send_IPI_self;
29298 #endif
29299 }
29300
29301@@ -1222,30 +1218,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
29302 #endif
29303 };
29304
29305-static void xen_reboot(int reason)
29306+static __noreturn void xen_reboot(int reason)
29307 {
29308 struct sched_shutdown r = { .reason = reason };
29309
29310- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
29311- BUG();
29312+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
29313+ BUG();
29314 }
29315
29316-static void xen_restart(char *msg)
29317+static __noreturn void xen_restart(char *msg)
29318 {
29319 xen_reboot(SHUTDOWN_reboot);
29320 }
29321
29322-static void xen_emergency_restart(void)
29323+static __noreturn void xen_emergency_restart(void)
29324 {
29325 xen_reboot(SHUTDOWN_reboot);
29326 }
29327
29328-static void xen_machine_halt(void)
29329+static __noreturn void xen_machine_halt(void)
29330 {
29331 xen_reboot(SHUTDOWN_poweroff);
29332 }
29333
29334-static void xen_machine_power_off(void)
29335+static __noreturn void xen_machine_power_off(void)
29336 {
29337 if (pm_power_off)
29338 pm_power_off();
29339@@ -1290,14 +1286,14 @@ static const struct machine_ops xen_machine_ops __initconst = {
29340 */
29341 static void __init xen_setup_stackprotector(void)
29342 {
29343- pv_cpu_ops.write_gdt_entry = xen_write_gdt_entry_boot;
29344- pv_cpu_ops.load_gdt = xen_load_gdt_boot;
29345+ *(void **)&pv_cpu_ops.write_gdt_entry = xen_write_gdt_entry_boot;
29346+ *(void **)&pv_cpu_ops.load_gdt = xen_load_gdt_boot;
29347
29348 setup_stack_canary_segment(0);
29349 switch_to_new_gdt(0);
29350
29351- pv_cpu_ops.write_gdt_entry = xen_write_gdt_entry;
29352- pv_cpu_ops.load_gdt = xen_load_gdt;
29353+ *(void **)&pv_cpu_ops.write_gdt_entry = xen_write_gdt_entry;
29354+ *(void **)&pv_cpu_ops.load_gdt = xen_load_gdt;
29355 }
29356
29357 /* First C function to be called on Xen boot */
29358@@ -1315,13 +1311,13 @@ asmlinkage void __init xen_start_kernel(void)
29359
29360 /* Install Xen paravirt ops */
29361 pv_info = xen_info;
29362- pv_init_ops = xen_init_ops;
29363- pv_cpu_ops = xen_cpu_ops;
29364- pv_apic_ops = xen_apic_ops;
29365+ memcpy((void *)&pv_init_ops, &xen_init_ops, sizeof pv_init_ops);
29366+ memcpy((void *)&pv_cpu_ops, &xen_cpu_ops, sizeof pv_cpu_ops);
29367+ memcpy((void *)&pv_apic_ops, &xen_apic_ops, sizeof pv_apic_ops);
29368
29369- x86_init.resources.memory_setup = xen_memory_setup;
29370- x86_init.oem.arch_setup = xen_arch_setup;
29371- x86_init.oem.banner = xen_banner;
29372+ *(void **)&x86_init.resources.memory_setup = xen_memory_setup;
29373+ *(void **)&x86_init.oem.arch_setup = xen_arch_setup;
29374+ *(void **)&x86_init.oem.banner = xen_banner;
29375
29376 xen_init_time_ops();
29377
29378@@ -1347,7 +1343,17 @@ asmlinkage void __init xen_start_kernel(void)
29379 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
29380
29381 /* Work out if we support NX */
29382- x86_configure_nx();
29383+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
29384+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
29385+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
29386+ unsigned l, h;
29387+
29388+ __supported_pte_mask |= _PAGE_NX;
29389+ rdmsr(MSR_EFER, l, h);
29390+ l |= EFER_NX;
29391+ wrmsr(MSR_EFER, l, h);
29392+ }
29393+#endif
29394
29395 xen_setup_features();
29396
29397@@ -1376,14 +1382,7 @@ asmlinkage void __init xen_start_kernel(void)
29398 pv_mmu_ops.ptep_modify_prot_commit = xen_ptep_modify_prot_commit;
29399 }
29400
29401- machine_ops = xen_machine_ops;
29402-
29403- /*
29404- * The only reliable way to retain the initial address of the
29405- * percpu gdt_page is to remember it here, so we can go and
29406- * mark it RW later, when the initial percpu area is freed.
29407- */
29408- xen_initial_gdt = &per_cpu(gdt_page, 0);
29409+ memcpy((void *)&machine_ops, &xen_machine_ops, sizeof machine_ops);
29410
29411 xen_smp_init();
29412
29413@@ -1450,7 +1449,7 @@ asmlinkage void __init xen_start_kernel(void)
29414 add_preferred_console("tty", 0, NULL);
29415 add_preferred_console("hvc", 0, NULL);
29416 if (pci_xen)
29417- x86_init.pci.arch_init = pci_xen_init;
29418+ *(void **)&x86_init.pci.arch_init = pci_xen_init;
29419 } else {
29420 const struct dom0_vga_console_info *info =
29421 (void *)((char *)xen_start_info +
29422@@ -1476,8 +1475,8 @@ asmlinkage void __init xen_start_kernel(void)
29423 xen_acpi_sleep_register();
29424
29425 /* Avoid searching for BIOS MP tables */
29426- x86_init.mpparse.find_smp_config = x86_init_noop;
29427- x86_init.mpparse.get_smp_config = x86_init_uint_noop;
29428+ *(void **)&x86_init.mpparse.find_smp_config = x86_init_noop;
29429+ *(void **)&x86_init.mpparse.get_smp_config = x86_init_uint_noop;
29430 }
29431 #ifdef CONFIG_PCI
29432 /* PCI BIOS service won't work from a PV guest. */
29433@@ -1583,7 +1582,7 @@ static void __init xen_hvm_guest_init(void)
29434 xen_hvm_smp_init();
29435 register_cpu_notifier(&xen_hvm_cpu_notifier);
29436 xen_unplug_emulated_devices();
29437- x86_init.irqs.intr_init = xen_init_IRQ;
29438+ *(void **)&x86_init.irqs.intr_init = xen_init_IRQ;
29439 xen_hvm_init_time_ops();
29440 xen_hvm_init_mmu_ops();
29441 }
29442diff --git a/arch/x86/xen/irq.c b/arch/x86/xen/irq.c
29443index 01a4dc0..3ca0cc9 100644
29444--- a/arch/x86/xen/irq.c
29445+++ b/arch/x86/xen/irq.c
29446@@ -130,5 +130,5 @@ static const struct pv_irq_ops xen_irq_ops __initconst = {
29447 void __init xen_init_irq_ops(void)
29448 {
29449 pv_irq_ops = xen_irq_ops;
29450- x86_init.irqs.intr_init = xen_init_IRQ;
29451+ *(void **)&x86_init.irqs.intr_init = xen_init_IRQ;
29452 }
29453diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
29454index dcf5f2d..5f72fe7 100644
29455--- a/arch/x86/xen/mmu.c
29456+++ b/arch/x86/xen/mmu.c
29457@@ -1881,6 +1881,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
29458 /* L3_k[510] -> level2_kernel_pgt
29459 * L3_i[511] -> level2_fixmap_pgt */
29460 convert_pfn_mfn(level3_kernel_pgt);
29461+ convert_pfn_mfn(level3_vmalloc_start_pgt);
29462+ convert_pfn_mfn(level3_vmalloc_end_pgt);
29463+ convert_pfn_mfn(level3_vmemmap_pgt);
29464
29465 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
29466 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
29467@@ -1910,8 +1913,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
29468 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
29469 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
29470 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
29471+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
29472+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
29473+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
29474 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
29475 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
29476+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
29477 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
29478 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
29479
29480@@ -2097,6 +2104,7 @@ static void __init xen_post_allocator_init(void)
29481 pv_mmu_ops.set_pud = xen_set_pud;
29482 #if PAGETABLE_LEVELS == 4
29483 pv_mmu_ops.set_pgd = xen_set_pgd;
29484+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
29485 #endif
29486
29487 /* This will work as long as patching hasn't happened yet
29488@@ -2178,6 +2186,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
29489 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
29490 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
29491 .set_pgd = xen_set_pgd_hyper,
29492+ .set_pgd_batched = xen_set_pgd_hyper,
29493
29494 .alloc_pud = xen_alloc_pmd_init,
29495 .release_pud = xen_release_pmd_init,
29496@@ -2197,8 +2206,8 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
29497
29498 void __init xen_init_mmu_ops(void)
29499 {
29500- x86_init.mapping.pagetable_reserve = xen_mapping_pagetable_reserve;
29501- x86_init.paging.pagetable_init = xen_pagetable_init;
29502+ *(void **)&x86_init.mapping.pagetable_reserve = xen_mapping_pagetable_reserve;
29503+ *(void **)&x86_init.paging.pagetable_init = xen_pagetable_init;
29504 pv_mmu_ops = xen_mmu_ops;
29505
29506 memset(dummy_mapping, 0xff, PAGE_SIZE);
29507diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
29508index 353c50f..a0b9b0d 100644
29509--- a/arch/x86/xen/smp.c
29510+++ b/arch/x86/xen/smp.c
29511@@ -229,11 +229,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
29512 {
29513 BUG_ON(smp_processor_id() != 0);
29514 native_smp_prepare_boot_cpu();
29515-
29516- /* We've switched to the "real" per-cpu gdt, so make sure the
29517- old memory can be recycled */
29518- make_lowmem_page_readwrite(xen_initial_gdt);
29519-
29520 xen_filter_cpu_maps();
29521 xen_setup_vcpu_info_placement();
29522 }
29523@@ -300,12 +295,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
29524 gdt = get_cpu_gdt_table(cpu);
29525
29526 ctxt->flags = VGCF_IN_KERNEL;
29527- ctxt->user_regs.ds = __USER_DS;
29528- ctxt->user_regs.es = __USER_DS;
29529+ ctxt->user_regs.ds = __KERNEL_DS;
29530+ ctxt->user_regs.es = __KERNEL_DS;
29531 ctxt->user_regs.ss = __KERNEL_DS;
29532 #ifdef CONFIG_X86_32
29533 ctxt->user_regs.fs = __KERNEL_PERCPU;
29534- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
29535+ savesegment(gs, ctxt->user_regs.gs);
29536 #else
29537 ctxt->gs_base_kernel = per_cpu_offset(cpu);
29538 #endif
29539@@ -355,13 +350,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
29540 int rc;
29541
29542 per_cpu(current_task, cpu) = idle;
29543+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
29544 #ifdef CONFIG_X86_32
29545 irq_ctx_init(cpu);
29546 #else
29547 clear_tsk_thread_flag(idle, TIF_FORK);
29548- per_cpu(kernel_stack, cpu) =
29549- (unsigned long)task_stack_page(idle) -
29550- KERNEL_STACK_OFFSET + THREAD_SIZE;
29551+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
29552 #endif
29553 xen_setup_runstate_info(cpu);
29554 xen_setup_timer(cpu);
29555@@ -637,7 +631,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
29556
29557 void __init xen_smp_init(void)
29558 {
29559- smp_ops = xen_smp_ops;
29560+ memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
29561 xen_fill_possible_map();
29562 xen_init_spinlocks();
29563 }
29564@@ -672,10 +666,10 @@ void __init xen_hvm_smp_init(void)
29565 {
29566 if (!xen_have_vector_callback)
29567 return;
29568- smp_ops.smp_prepare_cpus = xen_hvm_smp_prepare_cpus;
29569- smp_ops.smp_send_reschedule = xen_smp_send_reschedule;
29570- smp_ops.cpu_up = xen_hvm_cpu_up;
29571- smp_ops.cpu_die = xen_hvm_cpu_die;
29572- smp_ops.send_call_func_ipi = xen_smp_send_call_function_ipi;
29573- smp_ops.send_call_func_single_ipi = xen_smp_send_call_function_single_ipi;
29574+ *(void **)&smp_ops.smp_prepare_cpus = xen_hvm_smp_prepare_cpus;
29575+ *(void **)&smp_ops.smp_send_reschedule = xen_smp_send_reschedule;
29576+ *(void **)&smp_ops.cpu_up = xen_hvm_cpu_up;
29577+ *(void **)&smp_ops.cpu_die = xen_hvm_cpu_die;
29578+ *(void **)&smp_ops.send_call_func_ipi = xen_smp_send_call_function_ipi;
29579+ *(void **)&smp_ops.send_call_func_single_ipi = xen_smp_send_call_function_single_ipi;
29580 }
29581diff --git a/arch/x86/xen/spinlock.c b/arch/x86/xen/spinlock.c
29582index 83e866d..ef60385 100644
29583--- a/arch/x86/xen/spinlock.c
29584+++ b/arch/x86/xen/spinlock.c
29585@@ -390,12 +390,12 @@ void __init xen_init_spinlocks(void)
29586 {
29587 BUILD_BUG_ON(sizeof(struct xen_spinlock) > sizeof(arch_spinlock_t));
29588
29589- pv_lock_ops.spin_is_locked = xen_spin_is_locked;
29590- pv_lock_ops.spin_is_contended = xen_spin_is_contended;
29591- pv_lock_ops.spin_lock = xen_spin_lock;
29592- pv_lock_ops.spin_lock_flags = xen_spin_lock_flags;
29593- pv_lock_ops.spin_trylock = xen_spin_trylock;
29594- pv_lock_ops.spin_unlock = xen_spin_unlock;
29595+ *(void **)&pv_lock_ops.spin_is_locked = xen_spin_is_locked;
29596+ *(void **)&pv_lock_ops.spin_is_contended = xen_spin_is_contended;
29597+ *(void **)&pv_lock_ops.spin_lock = xen_spin_lock;
29598+ *(void **)&pv_lock_ops.spin_lock_flags = xen_spin_lock_flags;
29599+ *(void **)&pv_lock_ops.spin_trylock = xen_spin_trylock;
29600+ *(void **)&pv_lock_ops.spin_unlock = xen_spin_unlock;
29601 }
29602
29603 #ifdef CONFIG_XEN_DEBUG_FS
29604diff --git a/arch/x86/xen/time.c b/arch/x86/xen/time.c
29605index 0296a95..3c51a2d 100644
29606--- a/arch/x86/xen/time.c
29607+++ b/arch/x86/xen/time.c
29608@@ -481,15 +481,15 @@ static void __init xen_time_init(void)
29609
29610 void __init xen_init_time_ops(void)
29611 {
29612- pv_time_ops = xen_time_ops;
29613+ memcpy((void *)&pv_time_ops, &xen_time_ops, sizeof pv_time_ops);
29614
29615- x86_init.timers.timer_init = xen_time_init;
29616- x86_init.timers.setup_percpu_clockev = x86_init_noop;
29617- x86_cpuinit.setup_percpu_clockev = x86_init_noop;
29618+ *(void **)&x86_init.timers.timer_init = xen_time_init;
29619+ *(void **)&x86_init.timers.setup_percpu_clockev = x86_init_noop;
29620+ *(void **)&x86_cpuinit.setup_percpu_clockev = x86_init_noop;
29621
29622- x86_platform.calibrate_tsc = xen_tsc_khz;
29623- x86_platform.get_wallclock = xen_get_wallclock;
29624- x86_platform.set_wallclock = xen_set_wallclock;
29625+ *(void **)&x86_platform.calibrate_tsc = xen_tsc_khz;
29626+ *(void **)&x86_platform.get_wallclock = xen_get_wallclock;
29627+ *(void **)&x86_platform.set_wallclock = xen_set_wallclock;
29628 }
29629
29630 #ifdef CONFIG_XEN_PVHVM
29631@@ -514,12 +514,12 @@ void __init xen_hvm_init_time_ops(void)
29632 return;
29633 }
29634
29635- pv_time_ops = xen_time_ops;
29636- x86_init.timers.setup_percpu_clockev = xen_time_init;
29637- x86_cpuinit.setup_percpu_clockev = xen_hvm_setup_cpu_clockevents;
29638+ memcpy((void *)&pv_time_ops, &xen_time_ops, sizeof pv_time_ops);
29639+ *(void **)&x86_init.timers.setup_percpu_clockev = xen_time_init;
29640+ *(void **)&x86_cpuinit.setup_percpu_clockev = xen_hvm_setup_cpu_clockevents;
29641
29642- x86_platform.calibrate_tsc = xen_tsc_khz;
29643- x86_platform.get_wallclock = xen_get_wallclock;
29644- x86_platform.set_wallclock = xen_set_wallclock;
29645+ *(void **)&x86_platform.calibrate_tsc = xen_tsc_khz;
29646+ *(void **)&x86_platform.get_wallclock = xen_get_wallclock;
29647+ *(void **)&x86_platform.set_wallclock = xen_set_wallclock;
29648 }
29649 #endif
29650diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
29651index f9643fc..602e8af 100644
29652--- a/arch/x86/xen/xen-asm_32.S
29653+++ b/arch/x86/xen/xen-asm_32.S
29654@@ -84,14 +84,14 @@ ENTRY(xen_iret)
29655 ESP_OFFSET=4 # bytes pushed onto stack
29656
29657 /*
29658- * Store vcpu_info pointer for easy access. Do it this way to
29659- * avoid having to reload %fs
29660+ * Store vcpu_info pointer for easy access.
29661 */
29662 #ifdef CONFIG_SMP
29663- GET_THREAD_INFO(%eax)
29664- movl TI_cpu(%eax), %eax
29665- movl __per_cpu_offset(,%eax,4), %eax
29666- mov xen_vcpu(%eax), %eax
29667+ push %fs
29668+ mov $(__KERNEL_PERCPU), %eax
29669+ mov %eax, %fs
29670+ mov PER_CPU_VAR(xen_vcpu), %eax
29671+ pop %fs
29672 #else
29673 movl xen_vcpu, %eax
29674 #endif
29675diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
29676index 7faed58..ba4427c 100644
29677--- a/arch/x86/xen/xen-head.S
29678+++ b/arch/x86/xen/xen-head.S
29679@@ -19,6 +19,17 @@ ENTRY(startup_xen)
29680 #ifdef CONFIG_X86_32
29681 mov %esi,xen_start_info
29682 mov $init_thread_union+THREAD_SIZE,%esp
29683+#ifdef CONFIG_SMP
29684+ movl $cpu_gdt_table,%edi
29685+ movl $__per_cpu_load,%eax
29686+ movw %ax,__KERNEL_PERCPU + 2(%edi)
29687+ rorl $16,%eax
29688+ movb %al,__KERNEL_PERCPU + 4(%edi)
29689+ movb %ah,__KERNEL_PERCPU + 7(%edi)
29690+ movl $__per_cpu_end - 1,%eax
29691+ subl $__per_cpu_start,%eax
29692+ movw %ax,__KERNEL_PERCPU + 0(%edi)
29693+#endif
29694 #else
29695 mov %rsi,xen_start_info
29696 mov $init_thread_union+THREAD_SIZE,%rsp
29697diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
29698index a95b417..b6dbd0b 100644
29699--- a/arch/x86/xen/xen-ops.h
29700+++ b/arch/x86/xen/xen-ops.h
29701@@ -10,8 +10,6 @@
29702 extern const char xen_hypervisor_callback[];
29703 extern const char xen_failsafe_callback[];
29704
29705-extern void *xen_initial_gdt;
29706-
29707 struct trap_info;
29708 void xen_copy_trap_info(struct trap_info *traps);
29709
29710diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
29711index 525bd3d..ef888b1 100644
29712--- a/arch/xtensa/variants/dc232b/include/variant/core.h
29713+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
29714@@ -119,9 +119,9 @@
29715 ----------------------------------------------------------------------*/
29716
29717 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
29718-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
29719 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
29720 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
29721+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
29722
29723 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
29724 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
29725diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
29726index 2f33760..835e50a 100644
29727--- a/arch/xtensa/variants/fsf/include/variant/core.h
29728+++ b/arch/xtensa/variants/fsf/include/variant/core.h
29729@@ -11,6 +11,7 @@
29730 #ifndef _XTENSA_CORE_H
29731 #define _XTENSA_CORE_H
29732
29733+#include <linux/const.h>
29734
29735 /****************************************************************************
29736 Parameters Useful for Any Code, USER or PRIVILEGED
29737@@ -112,9 +113,9 @@
29738 ----------------------------------------------------------------------*/
29739
29740 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
29741-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
29742 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
29743 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
29744+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
29745
29746 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
29747 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
29748diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
29749index af00795..2bb8105 100644
29750--- a/arch/xtensa/variants/s6000/include/variant/core.h
29751+++ b/arch/xtensa/variants/s6000/include/variant/core.h
29752@@ -11,6 +11,7 @@
29753 #ifndef _XTENSA_CORE_CONFIGURATION_H
29754 #define _XTENSA_CORE_CONFIGURATION_H
29755
29756+#include <linux/const.h>
29757
29758 /****************************************************************************
29759 Parameters Useful for Any Code, USER or PRIVILEGED
29760@@ -118,9 +119,9 @@
29761 ----------------------------------------------------------------------*/
29762
29763 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
29764-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
29765 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
29766 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
29767+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
29768
29769 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
29770 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
29771diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
29772index 58916af..9cb880b 100644
29773--- a/block/blk-iopoll.c
29774+++ b/block/blk-iopoll.c
29775@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
29776 }
29777 EXPORT_SYMBOL(blk_iopoll_complete);
29778
29779-static void blk_iopoll_softirq(struct softirq_action *h)
29780+static void blk_iopoll_softirq(void)
29781 {
29782 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
29783 int rearm = 0, budget = blk_iopoll_budget;
29784diff --git a/block/blk-map.c b/block/blk-map.c
29785index 623e1cd..ca1e109 100644
29786--- a/block/blk-map.c
29787+++ b/block/blk-map.c
29788@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
29789 if (!len || !kbuf)
29790 return -EINVAL;
29791
29792- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
29793+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
29794 if (do_copy)
29795 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
29796 else
29797diff --git a/block/blk-softirq.c b/block/blk-softirq.c
29798index 467c8de..4bddc6d 100644
29799--- a/block/blk-softirq.c
29800+++ b/block/blk-softirq.c
29801@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
29802 * Softirq action handler - move entries to local list and loop over them
29803 * while passing them to the queue registered handler.
29804 */
29805-static void blk_done_softirq(struct softirq_action *h)
29806+static void blk_done_softirq(void)
29807 {
29808 struct list_head *cpu_list, local_list;
29809
29810diff --git a/block/bsg.c b/block/bsg.c
29811index ff64ae3..593560c 100644
29812--- a/block/bsg.c
29813+++ b/block/bsg.c
29814@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
29815 struct sg_io_v4 *hdr, struct bsg_device *bd,
29816 fmode_t has_write_perm)
29817 {
29818+ unsigned char tmpcmd[sizeof(rq->__cmd)];
29819+ unsigned char *cmdptr;
29820+
29821 if (hdr->request_len > BLK_MAX_CDB) {
29822 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
29823 if (!rq->cmd)
29824 return -ENOMEM;
29825- }
29826+ cmdptr = rq->cmd;
29827+ } else
29828+ cmdptr = tmpcmd;
29829
29830- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
29831+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
29832 hdr->request_len))
29833 return -EFAULT;
29834
29835+ if (cmdptr != rq->cmd)
29836+ memcpy(rq->cmd, cmdptr, hdr->request_len);
29837+
29838 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
29839 if (blk_verify_command(rq->cmd, has_write_perm))
29840 return -EPERM;
29841diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
29842index 7c668c8..db3521c 100644
29843--- a/block/compat_ioctl.c
29844+++ b/block/compat_ioctl.c
29845@@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
29846 err |= __get_user(f->spec1, &uf->spec1);
29847 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
29848 err |= __get_user(name, &uf->name);
29849- f->name = compat_ptr(name);
29850+ f->name = (void __force_kernel *)compat_ptr(name);
29851 if (err) {
29852 err = -EFAULT;
29853 goto out;
29854diff --git a/block/partitions/efi.c b/block/partitions/efi.c
29855index 6296b40..417c00f 100644
29856--- a/block/partitions/efi.c
29857+++ b/block/partitions/efi.c
29858@@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
29859 if (!gpt)
29860 return NULL;
29861
29862+ if (!le32_to_cpu(gpt->num_partition_entries))
29863+ return NULL;
29864+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
29865+ if (!pte)
29866+ return NULL;
29867+
29868 count = le32_to_cpu(gpt->num_partition_entries) *
29869 le32_to_cpu(gpt->sizeof_partition_entry);
29870- if (!count)
29871- return NULL;
29872- pte = kzalloc(count, GFP_KERNEL);
29873- if (!pte)
29874- return NULL;
29875-
29876 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
29877 (u8 *) pte,
29878 count) < count) {
29879diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
29880index 9a87daa..fb17486 100644
29881--- a/block/scsi_ioctl.c
29882+++ b/block/scsi_ioctl.c
29883@@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
29884 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
29885 struct sg_io_hdr *hdr, fmode_t mode)
29886 {
29887- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
29888+ unsigned char tmpcmd[sizeof(rq->__cmd)];
29889+ unsigned char *cmdptr;
29890+
29891+ if (rq->cmd != rq->__cmd)
29892+ cmdptr = rq->cmd;
29893+ else
29894+ cmdptr = tmpcmd;
29895+
29896+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
29897 return -EFAULT;
29898+
29899+ if (cmdptr != rq->cmd)
29900+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
29901+
29902 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
29903 return -EPERM;
29904
29905@@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
29906 int err;
29907 unsigned int in_len, out_len, bytes, opcode, cmdlen;
29908 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
29909+ unsigned char tmpcmd[sizeof(rq->__cmd)];
29910+ unsigned char *cmdptr;
29911
29912 if (!sic)
29913 return -EINVAL;
29914@@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
29915 */
29916 err = -EFAULT;
29917 rq->cmd_len = cmdlen;
29918- if (copy_from_user(rq->cmd, sic->data, cmdlen))
29919+
29920+ if (rq->cmd != rq->__cmd)
29921+ cmdptr = rq->cmd;
29922+ else
29923+ cmdptr = tmpcmd;
29924+
29925+ if (copy_from_user(cmdptr, sic->data, cmdlen))
29926 goto error;
29927
29928+ if (rq->cmd != cmdptr)
29929+ memcpy(rq->cmd, cmdptr, cmdlen);
29930+
29931 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
29932 goto error;
29933
29934diff --git a/crypto/cryptd.c b/crypto/cryptd.c
29935index 7bdd61b..afec999 100644
29936--- a/crypto/cryptd.c
29937+++ b/crypto/cryptd.c
29938@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
29939
29940 struct cryptd_blkcipher_request_ctx {
29941 crypto_completion_t complete;
29942-};
29943+} __no_const;
29944
29945 struct cryptd_hash_ctx {
29946 struct crypto_shash *child;
29947@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
29948
29949 struct cryptd_aead_request_ctx {
29950 crypto_completion_t complete;
29951-};
29952+} __no_const;
29953
29954 static void cryptd_queue_worker(struct work_struct *work);
29955
29956diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
29957index e6defd8..c26a225 100644
29958--- a/drivers/acpi/apei/cper.c
29959+++ b/drivers/acpi/apei/cper.c
29960@@ -38,12 +38,12 @@
29961 */
29962 u64 cper_next_record_id(void)
29963 {
29964- static atomic64_t seq;
29965+ static atomic64_unchecked_t seq;
29966
29967- if (!atomic64_read(&seq))
29968- atomic64_set(&seq, ((u64)get_seconds()) << 32);
29969+ if (!atomic64_read_unchecked(&seq))
29970+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
29971
29972- return atomic64_inc_return(&seq);
29973+ return atomic64_inc_return_unchecked(&seq);
29974 }
29975 EXPORT_SYMBOL_GPL(cper_next_record_id);
29976
29977diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
29978index 7586544..636a2f0 100644
29979--- a/drivers/acpi/ec_sys.c
29980+++ b/drivers/acpi/ec_sys.c
29981@@ -12,6 +12,7 @@
29982 #include <linux/acpi.h>
29983 #include <linux/debugfs.h>
29984 #include <linux/module.h>
29985+#include <linux/uaccess.h>
29986 #include "internal.h"
29987
29988 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
29989@@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
29990 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
29991 */
29992 unsigned int size = EC_SPACE_SIZE;
29993- u8 *data = (u8 *) buf;
29994+ u8 data;
29995 loff_t init_off = *off;
29996 int err = 0;
29997
29998@@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
29999 size = count;
30000
30001 while (size) {
30002- err = ec_read(*off, &data[*off - init_off]);
30003+ err = ec_read(*off, &data);
30004 if (err)
30005 return err;
30006+ if (put_user(data, &buf[*off - init_off]))
30007+ return -EFAULT;
30008 *off += 1;
30009 size--;
30010 }
30011@@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
30012
30013 unsigned int size = count;
30014 loff_t init_off = *off;
30015- u8 *data = (u8 *) buf;
30016 int err = 0;
30017
30018 if (*off >= EC_SPACE_SIZE)
30019@@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
30020 }
30021
30022 while (size) {
30023- u8 byte_write = data[*off - init_off];
30024+ u8 byte_write;
30025+ if (get_user(byte_write, &buf[*off - init_off]))
30026+ return -EFAULT;
30027 err = ec_write(*off, byte_write);
30028 if (err)
30029 return err;
30030diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
30031index 27adb09..ef98796b 100644
30032--- a/drivers/acpi/proc.c
30033+++ b/drivers/acpi/proc.c
30034@@ -362,16 +362,13 @@ acpi_system_write_wakeup_device(struct file *file,
30035 struct list_head *node, *next;
30036 char strbuf[5];
30037 char str[5] = "";
30038- unsigned int len = count;
30039
30040- if (len > 4)
30041- len = 4;
30042- if (len < 0)
30043- return -EFAULT;
30044+ if (count > 4)
30045+ count = 4;
30046
30047- if (copy_from_user(strbuf, buffer, len))
30048+ if (copy_from_user(strbuf, buffer, count))
30049 return -EFAULT;
30050- strbuf[len] = '\0';
30051+ strbuf[count] = '\0';
30052 sscanf(strbuf, "%s", str);
30053
30054 mutex_lock(&acpi_device_lock);
30055diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
30056index bd4e5dc..0497b66 100644
30057--- a/drivers/acpi/processor_driver.c
30058+++ b/drivers/acpi/processor_driver.c
30059@@ -552,7 +552,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
30060 return 0;
30061 #endif
30062
30063- BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
30064+ BUG_ON(pr->id >= nr_cpu_ids);
30065
30066 /*
30067 * Buggy BIOS check
30068diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
30069index c8ac4fe..631818e 100644
30070--- a/drivers/ata/libata-core.c
30071+++ b/drivers/ata/libata-core.c
30072@@ -4779,7 +4779,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
30073 struct ata_port *ap;
30074 unsigned int tag;
30075
30076- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
30077+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
30078 ap = qc->ap;
30079
30080 qc->flags = 0;
30081@@ -4795,7 +4795,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
30082 struct ata_port *ap;
30083 struct ata_link *link;
30084
30085- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
30086+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
30087 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
30088 ap = qc->ap;
30089 link = qc->dev->link;
30090@@ -5891,6 +5891,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
30091 return;
30092
30093 spin_lock(&lock);
30094+ pax_open_kernel();
30095
30096 for (cur = ops->inherits; cur; cur = cur->inherits) {
30097 void **inherit = (void **)cur;
30098@@ -5904,8 +5905,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
30099 if (IS_ERR(*pp))
30100 *pp = NULL;
30101
30102- ops->inherits = NULL;
30103+ *(struct ata_port_operations **)&ops->inherits = NULL;
30104
30105+ pax_close_kernel();
30106 spin_unlock(&lock);
30107 }
30108
30109diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
30110index 371fd2c..0836c78 100644
30111--- a/drivers/ata/pata_arasan_cf.c
30112+++ b/drivers/ata/pata_arasan_cf.c
30113@@ -861,7 +861,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
30114 /* Handle platform specific quirks */
30115 if (pdata->quirk) {
30116 if (pdata->quirk & CF_BROKEN_PIO) {
30117- ap->ops->set_piomode = NULL;
30118+ pax_open_kernel();
30119+ *(void **)&ap->ops->set_piomode = NULL;
30120+ pax_close_kernel();
30121 ap->pio_mask = 0;
30122 }
30123 if (pdata->quirk & CF_BROKEN_MWDMA)
30124diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
30125index f9b983a..887b9d8 100644
30126--- a/drivers/atm/adummy.c
30127+++ b/drivers/atm/adummy.c
30128@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
30129 vcc->pop(vcc, skb);
30130 else
30131 dev_kfree_skb_any(skb);
30132- atomic_inc(&vcc->stats->tx);
30133+ atomic_inc_unchecked(&vcc->stats->tx);
30134
30135 return 0;
30136 }
30137diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
30138index ff7bb8a..568fc0b 100644
30139--- a/drivers/atm/ambassador.c
30140+++ b/drivers/atm/ambassador.c
30141@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
30142 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
30143
30144 // VC layer stats
30145- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
30146+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
30147
30148 // free the descriptor
30149 kfree (tx_descr);
30150@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
30151 dump_skb ("<<<", vc, skb);
30152
30153 // VC layer stats
30154- atomic_inc(&atm_vcc->stats->rx);
30155+ atomic_inc_unchecked(&atm_vcc->stats->rx);
30156 __net_timestamp(skb);
30157 // end of our responsibility
30158 atm_vcc->push (atm_vcc, skb);
30159@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
30160 } else {
30161 PRINTK (KERN_INFO, "dropped over-size frame");
30162 // should we count this?
30163- atomic_inc(&atm_vcc->stats->rx_drop);
30164+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
30165 }
30166
30167 } else {
30168@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
30169 }
30170
30171 if (check_area (skb->data, skb->len)) {
30172- atomic_inc(&atm_vcc->stats->tx_err);
30173+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
30174 return -ENOMEM; // ?
30175 }
30176
30177diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
30178index b22d71c..d6e1049 100644
30179--- a/drivers/atm/atmtcp.c
30180+++ b/drivers/atm/atmtcp.c
30181@@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
30182 if (vcc->pop) vcc->pop(vcc,skb);
30183 else dev_kfree_skb(skb);
30184 if (dev_data) return 0;
30185- atomic_inc(&vcc->stats->tx_err);
30186+ atomic_inc_unchecked(&vcc->stats->tx_err);
30187 return -ENOLINK;
30188 }
30189 size = skb->len+sizeof(struct atmtcp_hdr);
30190@@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
30191 if (!new_skb) {
30192 if (vcc->pop) vcc->pop(vcc,skb);
30193 else dev_kfree_skb(skb);
30194- atomic_inc(&vcc->stats->tx_err);
30195+ atomic_inc_unchecked(&vcc->stats->tx_err);
30196 return -ENOBUFS;
30197 }
30198 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
30199@@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
30200 if (vcc->pop) vcc->pop(vcc,skb);
30201 else dev_kfree_skb(skb);
30202 out_vcc->push(out_vcc,new_skb);
30203- atomic_inc(&vcc->stats->tx);
30204- atomic_inc(&out_vcc->stats->rx);
30205+ atomic_inc_unchecked(&vcc->stats->tx);
30206+ atomic_inc_unchecked(&out_vcc->stats->rx);
30207 return 0;
30208 }
30209
30210@@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
30211 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
30212 read_unlock(&vcc_sklist_lock);
30213 if (!out_vcc) {
30214- atomic_inc(&vcc->stats->tx_err);
30215+ atomic_inc_unchecked(&vcc->stats->tx_err);
30216 goto done;
30217 }
30218 skb_pull(skb,sizeof(struct atmtcp_hdr));
30219@@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
30220 __net_timestamp(new_skb);
30221 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
30222 out_vcc->push(out_vcc,new_skb);
30223- atomic_inc(&vcc->stats->tx);
30224- atomic_inc(&out_vcc->stats->rx);
30225+ atomic_inc_unchecked(&vcc->stats->tx);
30226+ atomic_inc_unchecked(&out_vcc->stats->rx);
30227 done:
30228 if (vcc->pop) vcc->pop(vcc,skb);
30229 else dev_kfree_skb(skb);
30230diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
30231index 81e44f7..498ea36 100644
30232--- a/drivers/atm/eni.c
30233+++ b/drivers/atm/eni.c
30234@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
30235 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
30236 vcc->dev->number);
30237 length = 0;
30238- atomic_inc(&vcc->stats->rx_err);
30239+ atomic_inc_unchecked(&vcc->stats->rx_err);
30240 }
30241 else {
30242 length = ATM_CELL_SIZE-1; /* no HEC */
30243@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
30244 size);
30245 }
30246 eff = length = 0;
30247- atomic_inc(&vcc->stats->rx_err);
30248+ atomic_inc_unchecked(&vcc->stats->rx_err);
30249 }
30250 else {
30251 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
30252@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
30253 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
30254 vcc->dev->number,vcc->vci,length,size << 2,descr);
30255 length = eff = 0;
30256- atomic_inc(&vcc->stats->rx_err);
30257+ atomic_inc_unchecked(&vcc->stats->rx_err);
30258 }
30259 }
30260 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
30261@@ -767,7 +767,7 @@ rx_dequeued++;
30262 vcc->push(vcc,skb);
30263 pushed++;
30264 }
30265- atomic_inc(&vcc->stats->rx);
30266+ atomic_inc_unchecked(&vcc->stats->rx);
30267 }
30268 wake_up(&eni_dev->rx_wait);
30269 }
30270@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
30271 PCI_DMA_TODEVICE);
30272 if (vcc->pop) vcc->pop(vcc,skb);
30273 else dev_kfree_skb_irq(skb);
30274- atomic_inc(&vcc->stats->tx);
30275+ atomic_inc_unchecked(&vcc->stats->tx);
30276 wake_up(&eni_dev->tx_wait);
30277 dma_complete++;
30278 }
30279diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
30280index 86fed1b..6dc4721 100644
30281--- a/drivers/atm/firestream.c
30282+++ b/drivers/atm/firestream.c
30283@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
30284 }
30285 }
30286
30287- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
30288+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
30289
30290 fs_dprintk (FS_DEBUG_TXMEM, "i");
30291 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
30292@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
30293 #endif
30294 skb_put (skb, qe->p1 & 0xffff);
30295 ATM_SKB(skb)->vcc = atm_vcc;
30296- atomic_inc(&atm_vcc->stats->rx);
30297+ atomic_inc_unchecked(&atm_vcc->stats->rx);
30298 __net_timestamp(skb);
30299 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
30300 atm_vcc->push (atm_vcc, skb);
30301@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
30302 kfree (pe);
30303 }
30304 if (atm_vcc)
30305- atomic_inc(&atm_vcc->stats->rx_drop);
30306+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
30307 break;
30308 case 0x1f: /* Reassembly abort: no buffers. */
30309 /* Silently increment error counter. */
30310 if (atm_vcc)
30311- atomic_inc(&atm_vcc->stats->rx_drop);
30312+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
30313 break;
30314 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
30315 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
30316diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
30317index 361f5ae..7fc552d 100644
30318--- a/drivers/atm/fore200e.c
30319+++ b/drivers/atm/fore200e.c
30320@@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
30321 #endif
30322 /* check error condition */
30323 if (*entry->status & STATUS_ERROR)
30324- atomic_inc(&vcc->stats->tx_err);
30325+ atomic_inc_unchecked(&vcc->stats->tx_err);
30326 else
30327- atomic_inc(&vcc->stats->tx);
30328+ atomic_inc_unchecked(&vcc->stats->tx);
30329 }
30330 }
30331
30332@@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
30333 if (skb == NULL) {
30334 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
30335
30336- atomic_inc(&vcc->stats->rx_drop);
30337+ atomic_inc_unchecked(&vcc->stats->rx_drop);
30338 return -ENOMEM;
30339 }
30340
30341@@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
30342
30343 dev_kfree_skb_any(skb);
30344
30345- atomic_inc(&vcc->stats->rx_drop);
30346+ atomic_inc_unchecked(&vcc->stats->rx_drop);
30347 return -ENOMEM;
30348 }
30349
30350 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
30351
30352 vcc->push(vcc, skb);
30353- atomic_inc(&vcc->stats->rx);
30354+ atomic_inc_unchecked(&vcc->stats->rx);
30355
30356 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
30357
30358@@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
30359 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
30360 fore200e->atm_dev->number,
30361 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
30362- atomic_inc(&vcc->stats->rx_err);
30363+ atomic_inc_unchecked(&vcc->stats->rx_err);
30364 }
30365 }
30366
30367@@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
30368 goto retry_here;
30369 }
30370
30371- atomic_inc(&vcc->stats->tx_err);
30372+ atomic_inc_unchecked(&vcc->stats->tx_err);
30373
30374 fore200e->tx_sat++;
30375 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
30376diff --git a/drivers/atm/he.c b/drivers/atm/he.c
30377index b182c2f..1c6fa8a 100644
30378--- a/drivers/atm/he.c
30379+++ b/drivers/atm/he.c
30380@@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
30381
30382 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
30383 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
30384- atomic_inc(&vcc->stats->rx_drop);
30385+ atomic_inc_unchecked(&vcc->stats->rx_drop);
30386 goto return_host_buffers;
30387 }
30388
30389@@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
30390 RBRQ_LEN_ERR(he_dev->rbrq_head)
30391 ? "LEN_ERR" : "",
30392 vcc->vpi, vcc->vci);
30393- atomic_inc(&vcc->stats->rx_err);
30394+ atomic_inc_unchecked(&vcc->stats->rx_err);
30395 goto return_host_buffers;
30396 }
30397
30398@@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
30399 vcc->push(vcc, skb);
30400 spin_lock(&he_dev->global_lock);
30401
30402- atomic_inc(&vcc->stats->rx);
30403+ atomic_inc_unchecked(&vcc->stats->rx);
30404
30405 return_host_buffers:
30406 ++pdus_assembled;
30407@@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
30408 tpd->vcc->pop(tpd->vcc, tpd->skb);
30409 else
30410 dev_kfree_skb_any(tpd->skb);
30411- atomic_inc(&tpd->vcc->stats->tx_err);
30412+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
30413 }
30414 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
30415 return;
30416@@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
30417 vcc->pop(vcc, skb);
30418 else
30419 dev_kfree_skb_any(skb);
30420- atomic_inc(&vcc->stats->tx_err);
30421+ atomic_inc_unchecked(&vcc->stats->tx_err);
30422 return -EINVAL;
30423 }
30424
30425@@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
30426 vcc->pop(vcc, skb);
30427 else
30428 dev_kfree_skb_any(skb);
30429- atomic_inc(&vcc->stats->tx_err);
30430+ atomic_inc_unchecked(&vcc->stats->tx_err);
30431 return -EINVAL;
30432 }
30433 #endif
30434@@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
30435 vcc->pop(vcc, skb);
30436 else
30437 dev_kfree_skb_any(skb);
30438- atomic_inc(&vcc->stats->tx_err);
30439+ atomic_inc_unchecked(&vcc->stats->tx_err);
30440 spin_unlock_irqrestore(&he_dev->global_lock, flags);
30441 return -ENOMEM;
30442 }
30443@@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
30444 vcc->pop(vcc, skb);
30445 else
30446 dev_kfree_skb_any(skb);
30447- atomic_inc(&vcc->stats->tx_err);
30448+ atomic_inc_unchecked(&vcc->stats->tx_err);
30449 spin_unlock_irqrestore(&he_dev->global_lock, flags);
30450 return -ENOMEM;
30451 }
30452@@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
30453 __enqueue_tpd(he_dev, tpd, cid);
30454 spin_unlock_irqrestore(&he_dev->global_lock, flags);
30455
30456- atomic_inc(&vcc->stats->tx);
30457+ atomic_inc_unchecked(&vcc->stats->tx);
30458
30459 return 0;
30460 }
30461diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
30462index 7d01c2a..4e3ac01 100644
30463--- a/drivers/atm/horizon.c
30464+++ b/drivers/atm/horizon.c
30465@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
30466 {
30467 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
30468 // VC layer stats
30469- atomic_inc(&vcc->stats->rx);
30470+ atomic_inc_unchecked(&vcc->stats->rx);
30471 __net_timestamp(skb);
30472 // end of our responsibility
30473 vcc->push (vcc, skb);
30474@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
30475 dev->tx_iovec = NULL;
30476
30477 // VC layer stats
30478- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
30479+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
30480
30481 // free the skb
30482 hrz_kfree_skb (skb);
30483diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
30484index 8974bd2..b856f85 100644
30485--- a/drivers/atm/idt77252.c
30486+++ b/drivers/atm/idt77252.c
30487@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
30488 else
30489 dev_kfree_skb(skb);
30490
30491- atomic_inc(&vcc->stats->tx);
30492+ atomic_inc_unchecked(&vcc->stats->tx);
30493 }
30494
30495 atomic_dec(&scq->used);
30496@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
30497 if ((sb = dev_alloc_skb(64)) == NULL) {
30498 printk("%s: Can't allocate buffers for aal0.\n",
30499 card->name);
30500- atomic_add(i, &vcc->stats->rx_drop);
30501+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
30502 break;
30503 }
30504 if (!atm_charge(vcc, sb->truesize)) {
30505 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
30506 card->name);
30507- atomic_add(i - 1, &vcc->stats->rx_drop);
30508+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
30509 dev_kfree_skb(sb);
30510 break;
30511 }
30512@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
30513 ATM_SKB(sb)->vcc = vcc;
30514 __net_timestamp(sb);
30515 vcc->push(vcc, sb);
30516- atomic_inc(&vcc->stats->rx);
30517+ atomic_inc_unchecked(&vcc->stats->rx);
30518
30519 cell += ATM_CELL_PAYLOAD;
30520 }
30521@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
30522 "(CDC: %08x)\n",
30523 card->name, len, rpp->len, readl(SAR_REG_CDC));
30524 recycle_rx_pool_skb(card, rpp);
30525- atomic_inc(&vcc->stats->rx_err);
30526+ atomic_inc_unchecked(&vcc->stats->rx_err);
30527 return;
30528 }
30529 if (stat & SAR_RSQE_CRC) {
30530 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
30531 recycle_rx_pool_skb(card, rpp);
30532- atomic_inc(&vcc->stats->rx_err);
30533+ atomic_inc_unchecked(&vcc->stats->rx_err);
30534 return;
30535 }
30536 if (skb_queue_len(&rpp->queue) > 1) {
30537@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
30538 RXPRINTK("%s: Can't alloc RX skb.\n",
30539 card->name);
30540 recycle_rx_pool_skb(card, rpp);
30541- atomic_inc(&vcc->stats->rx_err);
30542+ atomic_inc_unchecked(&vcc->stats->rx_err);
30543 return;
30544 }
30545 if (!atm_charge(vcc, skb->truesize)) {
30546@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
30547 __net_timestamp(skb);
30548
30549 vcc->push(vcc, skb);
30550- atomic_inc(&vcc->stats->rx);
30551+ atomic_inc_unchecked(&vcc->stats->rx);
30552
30553 return;
30554 }
30555@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
30556 __net_timestamp(skb);
30557
30558 vcc->push(vcc, skb);
30559- atomic_inc(&vcc->stats->rx);
30560+ atomic_inc_unchecked(&vcc->stats->rx);
30561
30562 if (skb->truesize > SAR_FB_SIZE_3)
30563 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
30564@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
30565 if (vcc->qos.aal != ATM_AAL0) {
30566 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
30567 card->name, vpi, vci);
30568- atomic_inc(&vcc->stats->rx_drop);
30569+ atomic_inc_unchecked(&vcc->stats->rx_drop);
30570 goto drop;
30571 }
30572
30573 if ((sb = dev_alloc_skb(64)) == NULL) {
30574 printk("%s: Can't allocate buffers for AAL0.\n",
30575 card->name);
30576- atomic_inc(&vcc->stats->rx_err);
30577+ atomic_inc_unchecked(&vcc->stats->rx_err);
30578 goto drop;
30579 }
30580
30581@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
30582 ATM_SKB(sb)->vcc = vcc;
30583 __net_timestamp(sb);
30584 vcc->push(vcc, sb);
30585- atomic_inc(&vcc->stats->rx);
30586+ atomic_inc_unchecked(&vcc->stats->rx);
30587
30588 drop:
30589 skb_pull(queue, 64);
30590@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
30591
30592 if (vc == NULL) {
30593 printk("%s: NULL connection in send().\n", card->name);
30594- atomic_inc(&vcc->stats->tx_err);
30595+ atomic_inc_unchecked(&vcc->stats->tx_err);
30596 dev_kfree_skb(skb);
30597 return -EINVAL;
30598 }
30599 if (!test_bit(VCF_TX, &vc->flags)) {
30600 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
30601- atomic_inc(&vcc->stats->tx_err);
30602+ atomic_inc_unchecked(&vcc->stats->tx_err);
30603 dev_kfree_skb(skb);
30604 return -EINVAL;
30605 }
30606@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
30607 break;
30608 default:
30609 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
30610- atomic_inc(&vcc->stats->tx_err);
30611+ atomic_inc_unchecked(&vcc->stats->tx_err);
30612 dev_kfree_skb(skb);
30613 return -EINVAL;
30614 }
30615
30616 if (skb_shinfo(skb)->nr_frags != 0) {
30617 printk("%s: No scatter-gather yet.\n", card->name);
30618- atomic_inc(&vcc->stats->tx_err);
30619+ atomic_inc_unchecked(&vcc->stats->tx_err);
30620 dev_kfree_skb(skb);
30621 return -EINVAL;
30622 }
30623@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
30624
30625 err = queue_skb(card, vc, skb, oam);
30626 if (err) {
30627- atomic_inc(&vcc->stats->tx_err);
30628+ atomic_inc_unchecked(&vcc->stats->tx_err);
30629 dev_kfree_skb(skb);
30630 return err;
30631 }
30632@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
30633 skb = dev_alloc_skb(64);
30634 if (!skb) {
30635 printk("%s: Out of memory in send_oam().\n", card->name);
30636- atomic_inc(&vcc->stats->tx_err);
30637+ atomic_inc_unchecked(&vcc->stats->tx_err);
30638 return -ENOMEM;
30639 }
30640 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
30641diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
30642index 96cce6d..62c3ec5 100644
30643--- a/drivers/atm/iphase.c
30644+++ b/drivers/atm/iphase.c
30645@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
30646 status = (u_short) (buf_desc_ptr->desc_mode);
30647 if (status & (RX_CER | RX_PTE | RX_OFL))
30648 {
30649- atomic_inc(&vcc->stats->rx_err);
30650+ atomic_inc_unchecked(&vcc->stats->rx_err);
30651 IF_ERR(printk("IA: bad packet, dropping it");)
30652 if (status & RX_CER) {
30653 IF_ERR(printk(" cause: packet CRC error\n");)
30654@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
30655 len = dma_addr - buf_addr;
30656 if (len > iadev->rx_buf_sz) {
30657 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
30658- atomic_inc(&vcc->stats->rx_err);
30659+ atomic_inc_unchecked(&vcc->stats->rx_err);
30660 goto out_free_desc;
30661 }
30662
30663@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
30664 ia_vcc = INPH_IA_VCC(vcc);
30665 if (ia_vcc == NULL)
30666 {
30667- atomic_inc(&vcc->stats->rx_err);
30668+ atomic_inc_unchecked(&vcc->stats->rx_err);
30669 atm_return(vcc, skb->truesize);
30670 dev_kfree_skb_any(skb);
30671 goto INCR_DLE;
30672@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
30673 if ((length > iadev->rx_buf_sz) || (length >
30674 (skb->len - sizeof(struct cpcs_trailer))))
30675 {
30676- atomic_inc(&vcc->stats->rx_err);
30677+ atomic_inc_unchecked(&vcc->stats->rx_err);
30678 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
30679 length, skb->len);)
30680 atm_return(vcc, skb->truesize);
30681@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
30682
30683 IF_RX(printk("rx_dle_intr: skb push");)
30684 vcc->push(vcc,skb);
30685- atomic_inc(&vcc->stats->rx);
30686+ atomic_inc_unchecked(&vcc->stats->rx);
30687 iadev->rx_pkt_cnt++;
30688 }
30689 INCR_DLE:
30690@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
30691 {
30692 struct k_sonet_stats *stats;
30693 stats = &PRIV(_ia_dev[board])->sonet_stats;
30694- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
30695- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
30696- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
30697- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
30698- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
30699- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
30700- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
30701- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
30702- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
30703+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
30704+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
30705+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
30706+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
30707+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
30708+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
30709+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
30710+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
30711+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
30712 }
30713 ia_cmds.status = 0;
30714 break;
30715@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
30716 if ((desc == 0) || (desc > iadev->num_tx_desc))
30717 {
30718 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
30719- atomic_inc(&vcc->stats->tx);
30720+ atomic_inc_unchecked(&vcc->stats->tx);
30721 if (vcc->pop)
30722 vcc->pop(vcc, skb);
30723 else
30724@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
30725 ATM_DESC(skb) = vcc->vci;
30726 skb_queue_tail(&iadev->tx_dma_q, skb);
30727
30728- atomic_inc(&vcc->stats->tx);
30729+ atomic_inc_unchecked(&vcc->stats->tx);
30730 iadev->tx_pkt_cnt++;
30731 /* Increment transaction counter */
30732 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
30733
30734 #if 0
30735 /* add flow control logic */
30736- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
30737+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
30738 if (iavcc->vc_desc_cnt > 10) {
30739 vcc->tx_quota = vcc->tx_quota * 3 / 4;
30740 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
30741diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
30742index 68c7588..7036683 100644
30743--- a/drivers/atm/lanai.c
30744+++ b/drivers/atm/lanai.c
30745@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
30746 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
30747 lanai_endtx(lanai, lvcc);
30748 lanai_free_skb(lvcc->tx.atmvcc, skb);
30749- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
30750+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
30751 }
30752
30753 /* Try to fill the buffer - don't call unless there is backlog */
30754@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
30755 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
30756 __net_timestamp(skb);
30757 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
30758- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
30759+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
30760 out:
30761 lvcc->rx.buf.ptr = end;
30762 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
30763@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
30764 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
30765 "vcc %d\n", lanai->number, (unsigned int) s, vci);
30766 lanai->stats.service_rxnotaal5++;
30767- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
30768+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
30769 return 0;
30770 }
30771 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
30772@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
30773 int bytes;
30774 read_unlock(&vcc_sklist_lock);
30775 DPRINTK("got trashed rx pdu on vci %d\n", vci);
30776- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
30777+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
30778 lvcc->stats.x.aal5.service_trash++;
30779 bytes = (SERVICE_GET_END(s) * 16) -
30780 (((unsigned long) lvcc->rx.buf.ptr) -
30781@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
30782 }
30783 if (s & SERVICE_STREAM) {
30784 read_unlock(&vcc_sklist_lock);
30785- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
30786+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
30787 lvcc->stats.x.aal5.service_stream++;
30788 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
30789 "PDU on VCI %d!\n", lanai->number, vci);
30790@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
30791 return 0;
30792 }
30793 DPRINTK("got rx crc error on vci %d\n", vci);
30794- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
30795+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
30796 lvcc->stats.x.aal5.service_rxcrc++;
30797 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
30798 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
30799diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
30800index 1c70c45..300718d 100644
30801--- a/drivers/atm/nicstar.c
30802+++ b/drivers/atm/nicstar.c
30803@@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
30804 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
30805 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
30806 card->index);
30807- atomic_inc(&vcc->stats->tx_err);
30808+ atomic_inc_unchecked(&vcc->stats->tx_err);
30809 dev_kfree_skb_any(skb);
30810 return -EINVAL;
30811 }
30812@@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
30813 if (!vc->tx) {
30814 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
30815 card->index);
30816- atomic_inc(&vcc->stats->tx_err);
30817+ atomic_inc_unchecked(&vcc->stats->tx_err);
30818 dev_kfree_skb_any(skb);
30819 return -EINVAL;
30820 }
30821@@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
30822 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
30823 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
30824 card->index);
30825- atomic_inc(&vcc->stats->tx_err);
30826+ atomic_inc_unchecked(&vcc->stats->tx_err);
30827 dev_kfree_skb_any(skb);
30828 return -EINVAL;
30829 }
30830
30831 if (skb_shinfo(skb)->nr_frags != 0) {
30832 printk("nicstar%d: No scatter-gather yet.\n", card->index);
30833- atomic_inc(&vcc->stats->tx_err);
30834+ atomic_inc_unchecked(&vcc->stats->tx_err);
30835 dev_kfree_skb_any(skb);
30836 return -EINVAL;
30837 }
30838@@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
30839 }
30840
30841 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
30842- atomic_inc(&vcc->stats->tx_err);
30843+ atomic_inc_unchecked(&vcc->stats->tx_err);
30844 dev_kfree_skb_any(skb);
30845 return -EIO;
30846 }
30847- atomic_inc(&vcc->stats->tx);
30848+ atomic_inc_unchecked(&vcc->stats->tx);
30849
30850 return 0;
30851 }
30852@@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30853 printk
30854 ("nicstar%d: Can't allocate buffers for aal0.\n",
30855 card->index);
30856- atomic_add(i, &vcc->stats->rx_drop);
30857+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
30858 break;
30859 }
30860 if (!atm_charge(vcc, sb->truesize)) {
30861 RXPRINTK
30862 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
30863 card->index);
30864- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
30865+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
30866 dev_kfree_skb_any(sb);
30867 break;
30868 }
30869@@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30870 ATM_SKB(sb)->vcc = vcc;
30871 __net_timestamp(sb);
30872 vcc->push(vcc, sb);
30873- atomic_inc(&vcc->stats->rx);
30874+ atomic_inc_unchecked(&vcc->stats->rx);
30875 cell += ATM_CELL_PAYLOAD;
30876 }
30877
30878@@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30879 if (iovb == NULL) {
30880 printk("nicstar%d: Out of iovec buffers.\n",
30881 card->index);
30882- atomic_inc(&vcc->stats->rx_drop);
30883+ atomic_inc_unchecked(&vcc->stats->rx_drop);
30884 recycle_rx_buf(card, skb);
30885 return;
30886 }
30887@@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30888 small or large buffer itself. */
30889 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
30890 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
30891- atomic_inc(&vcc->stats->rx_err);
30892+ atomic_inc_unchecked(&vcc->stats->rx_err);
30893 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
30894 NS_MAX_IOVECS);
30895 NS_PRV_IOVCNT(iovb) = 0;
30896@@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30897 ("nicstar%d: Expected a small buffer, and this is not one.\n",
30898 card->index);
30899 which_list(card, skb);
30900- atomic_inc(&vcc->stats->rx_err);
30901+ atomic_inc_unchecked(&vcc->stats->rx_err);
30902 recycle_rx_buf(card, skb);
30903 vc->rx_iov = NULL;
30904 recycle_iov_buf(card, iovb);
30905@@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30906 ("nicstar%d: Expected a large buffer, and this is not one.\n",
30907 card->index);
30908 which_list(card, skb);
30909- atomic_inc(&vcc->stats->rx_err);
30910+ atomic_inc_unchecked(&vcc->stats->rx_err);
30911 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
30912 NS_PRV_IOVCNT(iovb));
30913 vc->rx_iov = NULL;
30914@@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30915 printk(" - PDU size mismatch.\n");
30916 else
30917 printk(".\n");
30918- atomic_inc(&vcc->stats->rx_err);
30919+ atomic_inc_unchecked(&vcc->stats->rx_err);
30920 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
30921 NS_PRV_IOVCNT(iovb));
30922 vc->rx_iov = NULL;
30923@@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30924 /* skb points to a small buffer */
30925 if (!atm_charge(vcc, skb->truesize)) {
30926 push_rxbufs(card, skb);
30927- atomic_inc(&vcc->stats->rx_drop);
30928+ atomic_inc_unchecked(&vcc->stats->rx_drop);
30929 } else {
30930 skb_put(skb, len);
30931 dequeue_sm_buf(card, skb);
30932@@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30933 ATM_SKB(skb)->vcc = vcc;
30934 __net_timestamp(skb);
30935 vcc->push(vcc, skb);
30936- atomic_inc(&vcc->stats->rx);
30937+ atomic_inc_unchecked(&vcc->stats->rx);
30938 }
30939 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
30940 struct sk_buff *sb;
30941@@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30942 if (len <= NS_SMBUFSIZE) {
30943 if (!atm_charge(vcc, sb->truesize)) {
30944 push_rxbufs(card, sb);
30945- atomic_inc(&vcc->stats->rx_drop);
30946+ atomic_inc_unchecked(&vcc->stats->rx_drop);
30947 } else {
30948 skb_put(sb, len);
30949 dequeue_sm_buf(card, sb);
30950@@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30951 ATM_SKB(sb)->vcc = vcc;
30952 __net_timestamp(sb);
30953 vcc->push(vcc, sb);
30954- atomic_inc(&vcc->stats->rx);
30955+ atomic_inc_unchecked(&vcc->stats->rx);
30956 }
30957
30958 push_rxbufs(card, skb);
30959@@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30960
30961 if (!atm_charge(vcc, skb->truesize)) {
30962 push_rxbufs(card, skb);
30963- atomic_inc(&vcc->stats->rx_drop);
30964+ atomic_inc_unchecked(&vcc->stats->rx_drop);
30965 } else {
30966 dequeue_lg_buf(card, skb);
30967 #ifdef NS_USE_DESTRUCTORS
30968@@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30969 ATM_SKB(skb)->vcc = vcc;
30970 __net_timestamp(skb);
30971 vcc->push(vcc, skb);
30972- atomic_inc(&vcc->stats->rx);
30973+ atomic_inc_unchecked(&vcc->stats->rx);
30974 }
30975
30976 push_rxbufs(card, sb);
30977@@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30978 printk
30979 ("nicstar%d: Out of huge buffers.\n",
30980 card->index);
30981- atomic_inc(&vcc->stats->rx_drop);
30982+ atomic_inc_unchecked(&vcc->stats->rx_drop);
30983 recycle_iovec_rx_bufs(card,
30984 (struct iovec *)
30985 iovb->data,
30986@@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30987 card->hbpool.count++;
30988 } else
30989 dev_kfree_skb_any(hb);
30990- atomic_inc(&vcc->stats->rx_drop);
30991+ atomic_inc_unchecked(&vcc->stats->rx_drop);
30992 } else {
30993 /* Copy the small buffer to the huge buffer */
30994 sb = (struct sk_buff *)iov->iov_base;
30995@@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30996 #endif /* NS_USE_DESTRUCTORS */
30997 __net_timestamp(hb);
30998 vcc->push(vcc, hb);
30999- atomic_inc(&vcc->stats->rx);
31000+ atomic_inc_unchecked(&vcc->stats->rx);
31001 }
31002 }
31003
31004diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
31005index 1853a45..cf2426d 100644
31006--- a/drivers/atm/solos-pci.c
31007+++ b/drivers/atm/solos-pci.c
31008@@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
31009 }
31010 atm_charge(vcc, skb->truesize);
31011 vcc->push(vcc, skb);
31012- atomic_inc(&vcc->stats->rx);
31013+ atomic_inc_unchecked(&vcc->stats->rx);
31014 break;
31015
31016 case PKT_STATUS:
31017@@ -1010,7 +1010,7 @@ static uint32_t fpga_tx(struct solos_card *card)
31018 vcc = SKB_CB(oldskb)->vcc;
31019
31020 if (vcc) {
31021- atomic_inc(&vcc->stats->tx);
31022+ atomic_inc_unchecked(&vcc->stats->tx);
31023 solos_pop(vcc, oldskb);
31024 } else
31025 dev_kfree_skb_irq(oldskb);
31026diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
31027index 0215934..ce9f5b1 100644
31028--- a/drivers/atm/suni.c
31029+++ b/drivers/atm/suni.c
31030@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
31031
31032
31033 #define ADD_LIMITED(s,v) \
31034- atomic_add((v),&stats->s); \
31035- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
31036+ atomic_add_unchecked((v),&stats->s); \
31037+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
31038
31039
31040 static void suni_hz(unsigned long from_timer)
31041diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
31042index 5120a96..e2572bd 100644
31043--- a/drivers/atm/uPD98402.c
31044+++ b/drivers/atm/uPD98402.c
31045@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
31046 struct sonet_stats tmp;
31047 int error = 0;
31048
31049- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
31050+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
31051 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
31052 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
31053 if (zero && !error) {
31054@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
31055
31056
31057 #define ADD_LIMITED(s,v) \
31058- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
31059- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
31060- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
31061+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
31062+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
31063+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
31064
31065
31066 static void stat_event(struct atm_dev *dev)
31067@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
31068 if (reason & uPD98402_INT_PFM) stat_event(dev);
31069 if (reason & uPD98402_INT_PCO) {
31070 (void) GET(PCOCR); /* clear interrupt cause */
31071- atomic_add(GET(HECCT),
31072+ atomic_add_unchecked(GET(HECCT),
31073 &PRIV(dev)->sonet_stats.uncorr_hcs);
31074 }
31075 if ((reason & uPD98402_INT_RFO) &&
31076@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
31077 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
31078 uPD98402_INT_LOS),PIMR); /* enable them */
31079 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
31080- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
31081- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
31082- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
31083+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
31084+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
31085+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
31086 return 0;
31087 }
31088
31089diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
31090index abe4e20..83c4727 100644
31091--- a/drivers/atm/zatm.c
31092+++ b/drivers/atm/zatm.c
31093@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
31094 }
31095 if (!size) {
31096 dev_kfree_skb_irq(skb);
31097- if (vcc) atomic_inc(&vcc->stats->rx_err);
31098+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
31099 continue;
31100 }
31101 if (!atm_charge(vcc,skb->truesize)) {
31102@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
31103 skb->len = size;
31104 ATM_SKB(skb)->vcc = vcc;
31105 vcc->push(vcc,skb);
31106- atomic_inc(&vcc->stats->rx);
31107+ atomic_inc_unchecked(&vcc->stats->rx);
31108 }
31109 zout(pos & 0xffff,MTA(mbx));
31110 #if 0 /* probably a stupid idea */
31111@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
31112 skb_queue_head(&zatm_vcc->backlog,skb);
31113 break;
31114 }
31115- atomic_inc(&vcc->stats->tx);
31116+ atomic_inc_unchecked(&vcc->stats->tx);
31117 wake_up(&zatm_vcc->tx_wait);
31118 }
31119
31120diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
31121index 147d1a4..d0fd4b0 100644
31122--- a/drivers/base/devtmpfs.c
31123+++ b/drivers/base/devtmpfs.c
31124@@ -347,7 +347,7 @@ int devtmpfs_mount(const char *mntdir)
31125 if (!thread)
31126 return 0;
31127
31128- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
31129+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
31130 if (err)
31131 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
31132 else
31133diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
31134index e6ee5e8..98ad7fc 100644
31135--- a/drivers/base/power/wakeup.c
31136+++ b/drivers/base/power/wakeup.c
31137@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
31138 * They need to be modified together atomically, so it's better to use one
31139 * atomic variable to hold them both.
31140 */
31141-static atomic_t combined_event_count = ATOMIC_INIT(0);
31142+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
31143
31144 #define IN_PROGRESS_BITS (sizeof(int) * 4)
31145 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
31146
31147 static void split_counters(unsigned int *cnt, unsigned int *inpr)
31148 {
31149- unsigned int comb = atomic_read(&combined_event_count);
31150+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
31151
31152 *cnt = (comb >> IN_PROGRESS_BITS);
31153 *inpr = comb & MAX_IN_PROGRESS;
31154@@ -389,7 +389,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
31155 ws->start_prevent_time = ws->last_time;
31156
31157 /* Increment the counter of events in progress. */
31158- cec = atomic_inc_return(&combined_event_count);
31159+ cec = atomic_inc_return_unchecked(&combined_event_count);
31160
31161 trace_wakeup_source_activate(ws->name, cec);
31162 }
31163@@ -515,7 +515,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
31164 * Increment the counter of registered wakeup events and decrement the
31165 * couter of wakeup events in progress simultaneously.
31166 */
31167- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
31168+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
31169 trace_wakeup_source_deactivate(ws->name, cec);
31170
31171 split_counters(&cnt, &inpr);
31172diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
31173index ca83f96..69d4ea9 100644
31174--- a/drivers/block/cciss.c
31175+++ b/drivers/block/cciss.c
31176@@ -1198,6 +1198,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
31177 int err;
31178 u32 cp;
31179
31180+ memset(&arg64, 0, sizeof(arg64));
31181+
31182 err = 0;
31183 err |=
31184 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
31185@@ -3007,7 +3009,7 @@ static void start_io(ctlr_info_t *h)
31186 while (!list_empty(&h->reqQ)) {
31187 c = list_entry(h->reqQ.next, CommandList_struct, list);
31188 /* can't do anything if fifo is full */
31189- if ((h->access.fifo_full(h))) {
31190+ if ((h->access->fifo_full(h))) {
31191 dev_warn(&h->pdev->dev, "fifo full\n");
31192 break;
31193 }
31194@@ -3017,7 +3019,7 @@ static void start_io(ctlr_info_t *h)
31195 h->Qdepth--;
31196
31197 /* Tell the controller execute command */
31198- h->access.submit_command(h, c);
31199+ h->access->submit_command(h, c);
31200
31201 /* Put job onto the completed Q */
31202 addQ(&h->cmpQ, c);
31203@@ -3443,17 +3445,17 @@ startio:
31204
31205 static inline unsigned long get_next_completion(ctlr_info_t *h)
31206 {
31207- return h->access.command_completed(h);
31208+ return h->access->command_completed(h);
31209 }
31210
31211 static inline int interrupt_pending(ctlr_info_t *h)
31212 {
31213- return h->access.intr_pending(h);
31214+ return h->access->intr_pending(h);
31215 }
31216
31217 static inline long interrupt_not_for_us(ctlr_info_t *h)
31218 {
31219- return ((h->access.intr_pending(h) == 0) ||
31220+ return ((h->access->intr_pending(h) == 0) ||
31221 (h->interrupts_enabled == 0));
31222 }
31223
31224@@ -3486,7 +3488,7 @@ static inline u32 next_command(ctlr_info_t *h)
31225 u32 a;
31226
31227 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
31228- return h->access.command_completed(h);
31229+ return h->access->command_completed(h);
31230
31231 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
31232 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
31233@@ -4044,7 +4046,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
31234 trans_support & CFGTBL_Trans_use_short_tags);
31235
31236 /* Change the access methods to the performant access methods */
31237- h->access = SA5_performant_access;
31238+ h->access = &SA5_performant_access;
31239 h->transMethod = CFGTBL_Trans_Performant;
31240
31241 return;
31242@@ -4316,7 +4318,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
31243 if (prod_index < 0)
31244 return -ENODEV;
31245 h->product_name = products[prod_index].product_name;
31246- h->access = *(products[prod_index].access);
31247+ h->access = products[prod_index].access;
31248
31249 if (cciss_board_disabled(h)) {
31250 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
31251@@ -5041,7 +5043,7 @@ reinit_after_soft_reset:
31252 }
31253
31254 /* make sure the board interrupts are off */
31255- h->access.set_intr_mask(h, CCISS_INTR_OFF);
31256+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
31257 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
31258 if (rc)
31259 goto clean2;
31260@@ -5093,7 +5095,7 @@ reinit_after_soft_reset:
31261 * fake ones to scoop up any residual completions.
31262 */
31263 spin_lock_irqsave(&h->lock, flags);
31264- h->access.set_intr_mask(h, CCISS_INTR_OFF);
31265+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
31266 spin_unlock_irqrestore(&h->lock, flags);
31267 free_irq(h->intr[h->intr_mode], h);
31268 rc = cciss_request_irq(h, cciss_msix_discard_completions,
31269@@ -5113,9 +5115,9 @@ reinit_after_soft_reset:
31270 dev_info(&h->pdev->dev, "Board READY.\n");
31271 dev_info(&h->pdev->dev,
31272 "Waiting for stale completions to drain.\n");
31273- h->access.set_intr_mask(h, CCISS_INTR_ON);
31274+ h->access->set_intr_mask(h, CCISS_INTR_ON);
31275 msleep(10000);
31276- h->access.set_intr_mask(h, CCISS_INTR_OFF);
31277+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
31278
31279 rc = controller_reset_failed(h->cfgtable);
31280 if (rc)
31281@@ -5138,7 +5140,7 @@ reinit_after_soft_reset:
31282 cciss_scsi_setup(h);
31283
31284 /* Turn the interrupts on so we can service requests */
31285- h->access.set_intr_mask(h, CCISS_INTR_ON);
31286+ h->access->set_intr_mask(h, CCISS_INTR_ON);
31287
31288 /* Get the firmware version */
31289 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
31290@@ -5210,7 +5212,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
31291 kfree(flush_buf);
31292 if (return_code != IO_OK)
31293 dev_warn(&h->pdev->dev, "Error flushing cache\n");
31294- h->access.set_intr_mask(h, CCISS_INTR_OFF);
31295+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
31296 free_irq(h->intr[h->intr_mode], h);
31297 }
31298
31299diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
31300index 7fda30e..eb5dfe0 100644
31301--- a/drivers/block/cciss.h
31302+++ b/drivers/block/cciss.h
31303@@ -101,7 +101,7 @@ struct ctlr_info
31304 /* information about each logical volume */
31305 drive_info_struct *drv[CISS_MAX_LUN];
31306
31307- struct access_method access;
31308+ struct access_method *access;
31309
31310 /* queue and queue Info */
31311 struct list_head reqQ;
31312diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
31313index 9125bbe..eede5c8 100644
31314--- a/drivers/block/cpqarray.c
31315+++ b/drivers/block/cpqarray.c
31316@@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
31317 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
31318 goto Enomem4;
31319 }
31320- hba[i]->access.set_intr_mask(hba[i], 0);
31321+ hba[i]->access->set_intr_mask(hba[i], 0);
31322 if (request_irq(hba[i]->intr, do_ida_intr,
31323 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
31324 {
31325@@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
31326 add_timer(&hba[i]->timer);
31327
31328 /* Enable IRQ now that spinlock and rate limit timer are set up */
31329- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
31330+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
31331
31332 for(j=0; j<NWD; j++) {
31333 struct gendisk *disk = ida_gendisk[i][j];
31334@@ -694,7 +694,7 @@ DBGINFO(
31335 for(i=0; i<NR_PRODUCTS; i++) {
31336 if (board_id == products[i].board_id) {
31337 c->product_name = products[i].product_name;
31338- c->access = *(products[i].access);
31339+ c->access = products[i].access;
31340 break;
31341 }
31342 }
31343@@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
31344 hba[ctlr]->intr = intr;
31345 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
31346 hba[ctlr]->product_name = products[j].product_name;
31347- hba[ctlr]->access = *(products[j].access);
31348+ hba[ctlr]->access = products[j].access;
31349 hba[ctlr]->ctlr = ctlr;
31350 hba[ctlr]->board_id = board_id;
31351 hba[ctlr]->pci_dev = NULL; /* not PCI */
31352@@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
31353
31354 while((c = h->reqQ) != NULL) {
31355 /* Can't do anything if we're busy */
31356- if (h->access.fifo_full(h) == 0)
31357+ if (h->access->fifo_full(h) == 0)
31358 return;
31359
31360 /* Get the first entry from the request Q */
31361@@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
31362 h->Qdepth--;
31363
31364 /* Tell the controller to do our bidding */
31365- h->access.submit_command(h, c);
31366+ h->access->submit_command(h, c);
31367
31368 /* Get onto the completion Q */
31369 addQ(&h->cmpQ, c);
31370@@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
31371 unsigned long flags;
31372 __u32 a,a1;
31373
31374- istat = h->access.intr_pending(h);
31375+ istat = h->access->intr_pending(h);
31376 /* Is this interrupt for us? */
31377 if (istat == 0)
31378 return IRQ_NONE;
31379@@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
31380 */
31381 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
31382 if (istat & FIFO_NOT_EMPTY) {
31383- while((a = h->access.command_completed(h))) {
31384+ while((a = h->access->command_completed(h))) {
31385 a1 = a; a &= ~3;
31386 if ((c = h->cmpQ) == NULL)
31387 {
31388@@ -1449,11 +1449,11 @@ static int sendcmd(
31389 /*
31390 * Disable interrupt
31391 */
31392- info_p->access.set_intr_mask(info_p, 0);
31393+ info_p->access->set_intr_mask(info_p, 0);
31394 /* Make sure there is room in the command FIFO */
31395 /* Actually it should be completely empty at this time. */
31396 for (i = 200000; i > 0; i--) {
31397- temp = info_p->access.fifo_full(info_p);
31398+ temp = info_p->access->fifo_full(info_p);
31399 if (temp != 0) {
31400 break;
31401 }
31402@@ -1466,7 +1466,7 @@ DBG(
31403 /*
31404 * Send the cmd
31405 */
31406- info_p->access.submit_command(info_p, c);
31407+ info_p->access->submit_command(info_p, c);
31408 complete = pollcomplete(ctlr);
31409
31410 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
31411@@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
31412 * we check the new geometry. Then turn interrupts back on when
31413 * we're done.
31414 */
31415- host->access.set_intr_mask(host, 0);
31416+ host->access->set_intr_mask(host, 0);
31417 getgeometry(ctlr);
31418- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
31419+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
31420
31421 for(i=0; i<NWD; i++) {
31422 struct gendisk *disk = ida_gendisk[ctlr][i];
31423@@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
31424 /* Wait (up to 2 seconds) for a command to complete */
31425
31426 for (i = 200000; i > 0; i--) {
31427- done = hba[ctlr]->access.command_completed(hba[ctlr]);
31428+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
31429 if (done == 0) {
31430 udelay(10); /* a short fixed delay */
31431 } else
31432diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
31433index be73e9d..7fbf140 100644
31434--- a/drivers/block/cpqarray.h
31435+++ b/drivers/block/cpqarray.h
31436@@ -99,7 +99,7 @@ struct ctlr_info {
31437 drv_info_t drv[NWD];
31438 struct proc_dir_entry *proc;
31439
31440- struct access_method access;
31441+ struct access_method *access;
31442
31443 cmdlist_t *reqQ;
31444 cmdlist_t *cmpQ;
31445diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
31446index b953cc7..e3dc580 100644
31447--- a/drivers/block/drbd/drbd_int.h
31448+++ b/drivers/block/drbd/drbd_int.h
31449@@ -735,7 +735,7 @@ struct drbd_request;
31450 struct drbd_epoch {
31451 struct list_head list;
31452 unsigned int barrier_nr;
31453- atomic_t epoch_size; /* increased on every request added. */
31454+ atomic_unchecked_t epoch_size; /* increased on every request added. */
31455 atomic_t active; /* increased on every req. added, and dec on every finished. */
31456 unsigned long flags;
31457 };
31458@@ -1116,7 +1116,7 @@ struct drbd_conf {
31459 void *int_dig_in;
31460 void *int_dig_vv;
31461 wait_queue_head_t seq_wait;
31462- atomic_t packet_seq;
31463+ atomic_unchecked_t packet_seq;
31464 unsigned int peer_seq;
31465 spinlock_t peer_seq_lock;
31466 unsigned int minor;
31467@@ -1658,30 +1658,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
31468
31469 static inline void drbd_tcp_cork(struct socket *sock)
31470 {
31471- int __user val = 1;
31472+ int val = 1;
31473 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
31474- (char __user *)&val, sizeof(val));
31475+ (char __force_user *)&val, sizeof(val));
31476 }
31477
31478 static inline void drbd_tcp_uncork(struct socket *sock)
31479 {
31480- int __user val = 0;
31481+ int val = 0;
31482 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
31483- (char __user *)&val, sizeof(val));
31484+ (char __force_user *)&val, sizeof(val));
31485 }
31486
31487 static inline void drbd_tcp_nodelay(struct socket *sock)
31488 {
31489- int __user val = 1;
31490+ int val = 1;
31491 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
31492- (char __user *)&val, sizeof(val));
31493+ (char __force_user *)&val, sizeof(val));
31494 }
31495
31496 static inline void drbd_tcp_quickack(struct socket *sock)
31497 {
31498- int __user val = 2;
31499+ int val = 2;
31500 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
31501- (char __user *)&val, sizeof(val));
31502+ (char __force_user *)&val, sizeof(val));
31503 }
31504
31505 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
31506diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
31507index f55683a..2101b96 100644
31508--- a/drivers/block/drbd/drbd_main.c
31509+++ b/drivers/block/drbd/drbd_main.c
31510@@ -2556,7 +2556,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
31511 p.sector = sector;
31512 p.block_id = block_id;
31513 p.blksize = blksize;
31514- p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
31515+ p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
31516
31517 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
31518 return false;
31519@@ -2854,7 +2854,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
31520
31521 p.sector = cpu_to_be64(req->sector);
31522 p.block_id = (unsigned long)req;
31523- p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
31524+ p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
31525
31526 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
31527
31528@@ -3139,7 +3139,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
31529 atomic_set(&mdev->unacked_cnt, 0);
31530 atomic_set(&mdev->local_cnt, 0);
31531 atomic_set(&mdev->net_cnt, 0);
31532- atomic_set(&mdev->packet_seq, 0);
31533+ atomic_set_unchecked(&mdev->packet_seq, 0);
31534 atomic_set(&mdev->pp_in_use, 0);
31535 atomic_set(&mdev->pp_in_use_by_net, 0);
31536 atomic_set(&mdev->rs_sect_in, 0);
31537@@ -3221,8 +3221,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
31538 mdev->receiver.t_state);
31539
31540 /* no need to lock it, I'm the only thread alive */
31541- if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
31542- dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
31543+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
31544+ dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
31545 mdev->al_writ_cnt =
31546 mdev->bm_writ_cnt =
31547 mdev->read_cnt =
31548diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
31549index edb490a..ecd69da 100644
31550--- a/drivers/block/drbd/drbd_nl.c
31551+++ b/drivers/block/drbd/drbd_nl.c
31552@@ -2407,7 +2407,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
31553 module_put(THIS_MODULE);
31554 }
31555
31556-static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
31557+static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
31558
31559 static unsigned short *
31560 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
31561@@ -2478,7 +2478,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
31562 cn_reply->id.idx = CN_IDX_DRBD;
31563 cn_reply->id.val = CN_VAL_DRBD;
31564
31565- cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
31566+ cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
31567 cn_reply->ack = 0; /* not used here. */
31568 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
31569 (int)((char *)tl - (char *)reply->tag_list);
31570@@ -2510,7 +2510,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
31571 cn_reply->id.idx = CN_IDX_DRBD;
31572 cn_reply->id.val = CN_VAL_DRBD;
31573
31574- cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
31575+ cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
31576 cn_reply->ack = 0; /* not used here. */
31577 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
31578 (int)((char *)tl - (char *)reply->tag_list);
31579@@ -2588,7 +2588,7 @@ void drbd_bcast_ee(struct drbd_conf *mdev,
31580 cn_reply->id.idx = CN_IDX_DRBD;
31581 cn_reply->id.val = CN_VAL_DRBD;
31582
31583- cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
31584+ cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
31585 cn_reply->ack = 0; // not used here.
31586 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
31587 (int)((char*)tl - (char*)reply->tag_list);
31588@@ -2627,7 +2627,7 @@ void drbd_bcast_sync_progress(struct drbd_conf *mdev)
31589 cn_reply->id.idx = CN_IDX_DRBD;
31590 cn_reply->id.val = CN_VAL_DRBD;
31591
31592- cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
31593+ cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
31594 cn_reply->ack = 0; /* not used here. */
31595 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
31596 (int)((char *)tl - (char *)reply->tag_list);
31597diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
31598index c74ca2d..860c819 100644
31599--- a/drivers/block/drbd/drbd_receiver.c
31600+++ b/drivers/block/drbd/drbd_receiver.c
31601@@ -898,7 +898,7 @@ retry:
31602 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
31603 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
31604
31605- atomic_set(&mdev->packet_seq, 0);
31606+ atomic_set_unchecked(&mdev->packet_seq, 0);
31607 mdev->peer_seq = 0;
31608
31609 if (drbd_send_protocol(mdev) == -1)
31610@@ -999,7 +999,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
31611 do {
31612 next_epoch = NULL;
31613
31614- epoch_size = atomic_read(&epoch->epoch_size);
31615+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
31616
31617 switch (ev & ~EV_CLEANUP) {
31618 case EV_PUT:
31619@@ -1035,7 +1035,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
31620 rv = FE_DESTROYED;
31621 } else {
31622 epoch->flags = 0;
31623- atomic_set(&epoch->epoch_size, 0);
31624+ atomic_set_unchecked(&epoch->epoch_size, 0);
31625 /* atomic_set(&epoch->active, 0); is already zero */
31626 if (rv == FE_STILL_LIVE)
31627 rv = FE_RECYCLED;
31628@@ -1210,14 +1210,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
31629 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
31630 drbd_flush(mdev);
31631
31632- if (atomic_read(&mdev->current_epoch->epoch_size)) {
31633+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
31634 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
31635 if (epoch)
31636 break;
31637 }
31638
31639 epoch = mdev->current_epoch;
31640- wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
31641+ wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
31642
31643 D_ASSERT(atomic_read(&epoch->active) == 0);
31644 D_ASSERT(epoch->flags == 0);
31645@@ -1229,11 +1229,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
31646 }
31647
31648 epoch->flags = 0;
31649- atomic_set(&epoch->epoch_size, 0);
31650+ atomic_set_unchecked(&epoch->epoch_size, 0);
31651 atomic_set(&epoch->active, 0);
31652
31653 spin_lock(&mdev->epoch_lock);
31654- if (atomic_read(&mdev->current_epoch->epoch_size)) {
31655+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
31656 list_add(&epoch->list, &mdev->current_epoch->list);
31657 mdev->current_epoch = epoch;
31658 mdev->epochs++;
31659@@ -1702,7 +1702,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
31660 spin_unlock(&mdev->peer_seq_lock);
31661
31662 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
31663- atomic_inc(&mdev->current_epoch->epoch_size);
31664+ atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
31665 return drbd_drain_block(mdev, data_size);
31666 }
31667
31668@@ -1732,7 +1732,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
31669
31670 spin_lock(&mdev->epoch_lock);
31671 e->epoch = mdev->current_epoch;
31672- atomic_inc(&e->epoch->epoch_size);
31673+ atomic_inc_unchecked(&e->epoch->epoch_size);
31674 atomic_inc(&e->epoch->active);
31675 spin_unlock(&mdev->epoch_lock);
31676
31677@@ -3954,7 +3954,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
31678 D_ASSERT(list_empty(&mdev->done_ee));
31679
31680 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
31681- atomic_set(&mdev->current_epoch->epoch_size, 0);
31682+ atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
31683 D_ASSERT(list_empty(&mdev->current_epoch->list));
31684 }
31685
31686diff --git a/drivers/block/loop.c b/drivers/block/loop.c
31687index 54046e5..7759c55 100644
31688--- a/drivers/block/loop.c
31689+++ b/drivers/block/loop.c
31690@@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
31691 mm_segment_t old_fs = get_fs();
31692
31693 set_fs(get_ds());
31694- bw = file->f_op->write(file, buf, len, &pos);
31695+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
31696 set_fs(old_fs);
31697 if (likely(bw == len))
31698 return 0;
31699diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
31700index d620b44..587561e 100644
31701--- a/drivers/cdrom/cdrom.c
31702+++ b/drivers/cdrom/cdrom.c
31703@@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
31704 ENSURE(reset, CDC_RESET);
31705 ENSURE(generic_packet, CDC_GENERIC_PACKET);
31706 cdi->mc_flags = 0;
31707- cdo->n_minors = 0;
31708 cdi->options = CDO_USE_FFLAGS;
31709
31710 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
31711@@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
31712 else
31713 cdi->cdda_method = CDDA_OLD;
31714
31715- if (!cdo->generic_packet)
31716- cdo->generic_packet = cdrom_dummy_generic_packet;
31717+ if (!cdo->generic_packet) {
31718+ pax_open_kernel();
31719+ *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
31720+ pax_close_kernel();
31721+ }
31722
31723 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
31724 mutex_lock(&cdrom_mutex);
31725@@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
31726 if (cdi->exit)
31727 cdi->exit(cdi);
31728
31729- cdi->ops->n_minors--;
31730 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
31731 }
31732
31733diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
31734index 75d485a..2809958 100644
31735--- a/drivers/cdrom/gdrom.c
31736+++ b/drivers/cdrom/gdrom.c
31737@@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
31738 .audio_ioctl = gdrom_audio_ioctl,
31739 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
31740 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
31741- .n_minors = 1,
31742 };
31743
31744 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
31745diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
31746index 72bedad..8181ce1 100644
31747--- a/drivers/char/Kconfig
31748+++ b/drivers/char/Kconfig
31749@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
31750
31751 config DEVKMEM
31752 bool "/dev/kmem virtual device support"
31753- default y
31754+ default n
31755+ depends on !GRKERNSEC_KMEM
31756 help
31757 Say Y here if you want to support the /dev/kmem device. The
31758 /dev/kmem device is rarely used, but can be used for certain
31759@@ -581,6 +582,7 @@ config DEVPORT
31760 bool
31761 depends on !M68K
31762 depends on ISA || PCI
31763+ depends on !GRKERNSEC_KMEM
31764 default y
31765
31766 source "drivers/s390/char/Kconfig"
31767diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
31768index 2e04433..22afc64 100644
31769--- a/drivers/char/agp/frontend.c
31770+++ b/drivers/char/agp/frontend.c
31771@@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
31772 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
31773 return -EFAULT;
31774
31775- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
31776+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
31777 return -EFAULT;
31778
31779 client = agp_find_client_by_pid(reserve.pid);
31780diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
31781index 21cb980..f15107c 100644
31782--- a/drivers/char/genrtc.c
31783+++ b/drivers/char/genrtc.c
31784@@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
31785 switch (cmd) {
31786
31787 case RTC_PLL_GET:
31788+ memset(&pll, 0, sizeof(pll));
31789 if (get_rtc_pll(&pll))
31790 return -EINVAL;
31791 else
31792diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
31793index dfd7876..c0b0885 100644
31794--- a/drivers/char/hpet.c
31795+++ b/drivers/char/hpet.c
31796@@ -571,7 +571,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
31797 }
31798
31799 static int
31800-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
31801+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
31802 struct hpet_info *info)
31803 {
31804 struct hpet_timer __iomem *timer;
31805diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
31806index a0c84bb..9edcf60 100644
31807--- a/drivers/char/ipmi/ipmi_msghandler.c
31808+++ b/drivers/char/ipmi/ipmi_msghandler.c
31809@@ -420,7 +420,7 @@ struct ipmi_smi {
31810 struct proc_dir_entry *proc_dir;
31811 char proc_dir_name[10];
31812
31813- atomic_t stats[IPMI_NUM_STATS];
31814+ atomic_unchecked_t stats[IPMI_NUM_STATS];
31815
31816 /*
31817 * run_to_completion duplicate of smb_info, smi_info
31818@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
31819
31820
31821 #define ipmi_inc_stat(intf, stat) \
31822- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
31823+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
31824 #define ipmi_get_stat(intf, stat) \
31825- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
31826+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
31827
31828 static int is_lan_addr(struct ipmi_addr *addr)
31829 {
31830@@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
31831 INIT_LIST_HEAD(&intf->cmd_rcvrs);
31832 init_waitqueue_head(&intf->waitq);
31833 for (i = 0; i < IPMI_NUM_STATS; i++)
31834- atomic_set(&intf->stats[i], 0);
31835+ atomic_set_unchecked(&intf->stats[i], 0);
31836
31837 intf->proc_dir = NULL;
31838
31839diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
31840index 32a6c7e..f6966a9 100644
31841--- a/drivers/char/ipmi/ipmi_si_intf.c
31842+++ b/drivers/char/ipmi/ipmi_si_intf.c
31843@@ -275,7 +275,7 @@ struct smi_info {
31844 unsigned char slave_addr;
31845
31846 /* Counters and things for the proc filesystem. */
31847- atomic_t stats[SI_NUM_STATS];
31848+ atomic_unchecked_t stats[SI_NUM_STATS];
31849
31850 struct task_struct *thread;
31851
31852@@ -284,9 +284,9 @@ struct smi_info {
31853 };
31854
31855 #define smi_inc_stat(smi, stat) \
31856- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
31857+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
31858 #define smi_get_stat(smi, stat) \
31859- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
31860+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
31861
31862 #define SI_MAX_PARMS 4
31863
31864@@ -3225,7 +3225,7 @@ static int try_smi_init(struct smi_info *new_smi)
31865 atomic_set(&new_smi->req_events, 0);
31866 new_smi->run_to_completion = 0;
31867 for (i = 0; i < SI_NUM_STATS; i++)
31868- atomic_set(&new_smi->stats[i], 0);
31869+ atomic_set_unchecked(&new_smi->stats[i], 0);
31870
31871 new_smi->interrupt_disabled = 1;
31872 atomic_set(&new_smi->stop_operation, 0);
31873diff --git a/drivers/char/mem.c b/drivers/char/mem.c
31874index 0537903..121c699 100644
31875--- a/drivers/char/mem.c
31876+++ b/drivers/char/mem.c
31877@@ -18,6 +18,7 @@
31878 #include <linux/raw.h>
31879 #include <linux/tty.h>
31880 #include <linux/capability.h>
31881+#include <linux/security.h>
31882 #include <linux/ptrace.h>
31883 #include <linux/device.h>
31884 #include <linux/highmem.h>
31885@@ -37,6 +38,10 @@
31886
31887 #define DEVPORT_MINOR 4
31888
31889+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
31890+extern const struct file_operations grsec_fops;
31891+#endif
31892+
31893 static inline unsigned long size_inside_page(unsigned long start,
31894 unsigned long size)
31895 {
31896@@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31897
31898 while (cursor < to) {
31899 if (!devmem_is_allowed(pfn)) {
31900+#ifdef CONFIG_GRKERNSEC_KMEM
31901+ gr_handle_mem_readwrite(from, to);
31902+#else
31903 printk(KERN_INFO
31904 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
31905 current->comm, from, to);
31906+#endif
31907 return 0;
31908 }
31909 cursor += PAGE_SIZE;
31910@@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31911 }
31912 return 1;
31913 }
31914+#elif defined(CONFIG_GRKERNSEC_KMEM)
31915+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31916+{
31917+ return 0;
31918+}
31919 #else
31920 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31921 {
31922@@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
31923
31924 while (count > 0) {
31925 unsigned long remaining;
31926+ char *temp;
31927
31928 sz = size_inside_page(p, count);
31929
31930@@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
31931 if (!ptr)
31932 return -EFAULT;
31933
31934- remaining = copy_to_user(buf, ptr, sz);
31935+#ifdef CONFIG_PAX_USERCOPY
31936+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
31937+ if (!temp) {
31938+ unxlate_dev_mem_ptr(p, ptr);
31939+ return -ENOMEM;
31940+ }
31941+ memcpy(temp, ptr, sz);
31942+#else
31943+ temp = ptr;
31944+#endif
31945+
31946+ remaining = copy_to_user(buf, temp, sz);
31947+
31948+#ifdef CONFIG_PAX_USERCOPY
31949+ kfree(temp);
31950+#endif
31951+
31952 unxlate_dev_mem_ptr(p, ptr);
31953 if (remaining)
31954 return -EFAULT;
31955@@ -398,9 +429,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
31956 size_t count, loff_t *ppos)
31957 {
31958 unsigned long p = *ppos;
31959- ssize_t low_count, read, sz;
31960+ ssize_t low_count, read, sz, err = 0;
31961 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
31962- int err = 0;
31963
31964 read = 0;
31965 if (p < (unsigned long) high_memory) {
31966@@ -422,6 +452,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
31967 }
31968 #endif
31969 while (low_count > 0) {
31970+ char *temp;
31971+
31972 sz = size_inside_page(p, low_count);
31973
31974 /*
31975@@ -431,7 +463,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
31976 */
31977 kbuf = xlate_dev_kmem_ptr((char *)p);
31978
31979- if (copy_to_user(buf, kbuf, sz))
31980+#ifdef CONFIG_PAX_USERCOPY
31981+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
31982+ if (!temp)
31983+ return -ENOMEM;
31984+ memcpy(temp, kbuf, sz);
31985+#else
31986+ temp = kbuf;
31987+#endif
31988+
31989+ err = copy_to_user(buf, temp, sz);
31990+
31991+#ifdef CONFIG_PAX_USERCOPY
31992+ kfree(temp);
31993+#endif
31994+
31995+ if (err)
31996 return -EFAULT;
31997 buf += sz;
31998 p += sz;
31999@@ -833,6 +880,9 @@ static const struct memdev {
32000 #ifdef CONFIG_CRASH_DUMP
32001 [12] = { "oldmem", 0, &oldmem_fops, NULL },
32002 #endif
32003+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
32004+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
32005+#endif
32006 };
32007
32008 static int memory_open(struct inode *inode, struct file *filp)
32009diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
32010index 9df78e2..01ba9ae 100644
32011--- a/drivers/char/nvram.c
32012+++ b/drivers/char/nvram.c
32013@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
32014
32015 spin_unlock_irq(&rtc_lock);
32016
32017- if (copy_to_user(buf, contents, tmp - contents))
32018+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
32019 return -EFAULT;
32020
32021 *ppos = i;
32022diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
32023index 21721d2..4e98777 100644
32024--- a/drivers/char/pcmcia/synclink_cs.c
32025+++ b/drivers/char/pcmcia/synclink_cs.c
32026@@ -2346,9 +2346,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
32027
32028 if (debug_level >= DEBUG_LEVEL_INFO)
32029 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
32030- __FILE__,__LINE__, info->device_name, port->count);
32031+ __FILE__,__LINE__, info->device_name, atomic_read(&port->count));
32032
32033- WARN_ON(!port->count);
32034+ WARN_ON(!atomic_read(&port->count));
32035
32036 if (tty_port_close_start(port, tty, filp) == 0)
32037 goto cleanup;
32038@@ -2366,7 +2366,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
32039 cleanup:
32040 if (debug_level >= DEBUG_LEVEL_INFO)
32041 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__,
32042- tty->driver->name, port->count);
32043+ tty->driver->name, atomic_read(&port->count));
32044 }
32045
32046 /* Wait until the transmitter is empty.
32047@@ -2508,7 +2508,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
32048
32049 if (debug_level >= DEBUG_LEVEL_INFO)
32050 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
32051- __FILE__,__LINE__,tty->driver->name, port->count);
32052+ __FILE__,__LINE__,tty->driver->name, atomic_read(&port->count));
32053
32054 /* If port is closing, signal caller to try again */
32055 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
32056@@ -2528,11 +2528,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
32057 goto cleanup;
32058 }
32059 spin_lock(&port->lock);
32060- port->count++;
32061+ atomic_inc(&port->count);
32062 spin_unlock(&port->lock);
32063 spin_unlock_irqrestore(&info->netlock, flags);
32064
32065- if (port->count == 1) {
32066+ if (atomic_read(&port->count) == 1) {
32067 /* 1st open on this device, init hardware */
32068 retval = startup(info, tty);
32069 if (retval < 0)
32070@@ -3886,7 +3886,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
32071 unsigned short new_crctype;
32072
32073 /* return error if TTY interface open */
32074- if (info->port.count)
32075+ if (atomic_read(&info->port.count))
32076 return -EBUSY;
32077
32078 switch (encoding)
32079@@ -3989,7 +3989,7 @@ static int hdlcdev_open(struct net_device *dev)
32080
32081 /* arbitrate between network and tty opens */
32082 spin_lock_irqsave(&info->netlock, flags);
32083- if (info->port.count != 0 || info->netcount != 0) {
32084+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
32085 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
32086 spin_unlock_irqrestore(&info->netlock, flags);
32087 return -EBUSY;
32088@@ -4078,7 +4078,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
32089 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
32090
32091 /* return error if TTY interface open */
32092- if (info->port.count)
32093+ if (atomic_read(&info->port.count))
32094 return -EBUSY;
32095
32096 if (cmd != SIOCWANDEV)
32097diff --git a/drivers/char/random.c b/drivers/char/random.c
32098index b86eae9..b9c2ed7 100644
32099--- a/drivers/char/random.c
32100+++ b/drivers/char/random.c
32101@@ -272,8 +272,13 @@
32102 /*
32103 * Configuration information
32104 */
32105+#ifdef CONFIG_GRKERNSEC_RANDNET
32106+#define INPUT_POOL_WORDS 512
32107+#define OUTPUT_POOL_WORDS 128
32108+#else
32109 #define INPUT_POOL_WORDS 128
32110 #define OUTPUT_POOL_WORDS 32
32111+#endif
32112 #define SEC_XFER_SIZE 512
32113 #define EXTRACT_SIZE 10
32114
32115@@ -313,10 +318,17 @@ static struct poolinfo {
32116 int poolwords;
32117 int tap1, tap2, tap3, tap4, tap5;
32118 } poolinfo_table[] = {
32119+#ifdef CONFIG_GRKERNSEC_RANDNET
32120+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
32121+ { 512, 411, 308, 208, 104, 1 },
32122+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
32123+ { 128, 103, 76, 51, 25, 1 },
32124+#else
32125 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
32126 { 128, 103, 76, 51, 25, 1 },
32127 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
32128 { 32, 26, 20, 14, 7, 1 },
32129+#endif
32130 #if 0
32131 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
32132 { 2048, 1638, 1231, 819, 411, 1 },
32133@@ -437,6 +449,7 @@ struct entropy_store {
32134 int entropy_count;
32135 int entropy_total;
32136 unsigned int initialized:1;
32137+ bool last_data_init;
32138 __u8 last_data[EXTRACT_SIZE];
32139 };
32140
32141@@ -527,8 +540,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
32142 input_rotate += i ? 7 : 14;
32143 }
32144
32145- ACCESS_ONCE(r->input_rotate) = input_rotate;
32146- ACCESS_ONCE(r->add_ptr) = i;
32147+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
32148+ ACCESS_ONCE_RW(r->add_ptr) = i;
32149 smp_wmb();
32150
32151 if (out)
32152@@ -957,6 +970,10 @@ static ssize_t extract_entropy(struct entropy_store *r, void *buf,
32153 ssize_t ret = 0, i;
32154 __u8 tmp[EXTRACT_SIZE];
32155
32156+ /* if last_data isn't primed, we need EXTRACT_SIZE extra bytes */
32157+ if (fips_enabled && !r->last_data_init)
32158+ nbytes += EXTRACT_SIZE;
32159+
32160 trace_extract_entropy(r->name, nbytes, r->entropy_count, _RET_IP_);
32161 xfer_secondary_pool(r, nbytes);
32162 nbytes = account(r, nbytes, min, reserved);
32163@@ -967,6 +984,17 @@ static ssize_t extract_entropy(struct entropy_store *r, void *buf,
32164 if (fips_enabled) {
32165 unsigned long flags;
32166
32167+
32168+ /* prime last_data value if need be, per fips 140-2 */
32169+ if (!r->last_data_init) {
32170+ spin_lock_irqsave(&r->lock, flags);
32171+ memcpy(r->last_data, tmp, EXTRACT_SIZE);
32172+ r->last_data_init = true;
32173+ nbytes -= EXTRACT_SIZE;
32174+ spin_unlock_irqrestore(&r->lock, flags);
32175+ extract_buf(r, tmp);
32176+ }
32177+
32178 spin_lock_irqsave(&r->lock, flags);
32179 if (!memcmp(tmp, r->last_data, EXTRACT_SIZE))
32180 panic("Hardware RNG duplicated output!\n");
32181@@ -1008,7 +1036,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
32182
32183 extract_buf(r, tmp);
32184 i = min_t(int, nbytes, EXTRACT_SIZE);
32185- if (copy_to_user(buf, tmp, i)) {
32186+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
32187 ret = -EFAULT;
32188 break;
32189 }
32190@@ -1086,6 +1114,7 @@ static void init_std_data(struct entropy_store *r)
32191
32192 r->entropy_count = 0;
32193 r->entropy_total = 0;
32194+ r->last_data_init = false;
32195 mix_pool_bytes(r, &now, sizeof(now), NULL);
32196 for (i = r->poolinfo->POOLBYTES; i > 0; i -= sizeof(rv)) {
32197 if (!arch_get_random_long(&rv))
32198@@ -1342,7 +1371,7 @@ EXPORT_SYMBOL(generate_random_uuid);
32199 #include <linux/sysctl.h>
32200
32201 static int min_read_thresh = 8, min_write_thresh;
32202-static int max_read_thresh = INPUT_POOL_WORDS * 32;
32203+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
32204 static int max_write_thresh = INPUT_POOL_WORDS * 32;
32205 static char sysctl_bootid[16];
32206
32207diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
32208index 9b4f011..b7e0a1a 100644
32209--- a/drivers/char/sonypi.c
32210+++ b/drivers/char/sonypi.c
32211@@ -54,6 +54,7 @@
32212
32213 #include <asm/uaccess.h>
32214 #include <asm/io.h>
32215+#include <asm/local.h>
32216
32217 #include <linux/sonypi.h>
32218
32219@@ -490,7 +491,7 @@ static struct sonypi_device {
32220 spinlock_t fifo_lock;
32221 wait_queue_head_t fifo_proc_list;
32222 struct fasync_struct *fifo_async;
32223- int open_count;
32224+ local_t open_count;
32225 int model;
32226 struct input_dev *input_jog_dev;
32227 struct input_dev *input_key_dev;
32228@@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
32229 static int sonypi_misc_release(struct inode *inode, struct file *file)
32230 {
32231 mutex_lock(&sonypi_device.lock);
32232- sonypi_device.open_count--;
32233+ local_dec(&sonypi_device.open_count);
32234 mutex_unlock(&sonypi_device.lock);
32235 return 0;
32236 }
32237@@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
32238 {
32239 mutex_lock(&sonypi_device.lock);
32240 /* Flush input queue on first open */
32241- if (!sonypi_device.open_count)
32242+ if (!local_read(&sonypi_device.open_count))
32243 kfifo_reset(&sonypi_device.fifo);
32244- sonypi_device.open_count++;
32245+ local_inc(&sonypi_device.open_count);
32246 mutex_unlock(&sonypi_device.lock);
32247
32248 return 0;
32249diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
32250index 93211df..c7805f7 100644
32251--- a/drivers/char/tpm/tpm.c
32252+++ b/drivers/char/tpm/tpm.c
32253@@ -410,7 +410,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
32254 chip->vendor.req_complete_val)
32255 goto out_recv;
32256
32257- if ((status == chip->vendor.req_canceled)) {
32258+ if (status == chip->vendor.req_canceled) {
32259 dev_err(chip->dev, "Operation Canceled\n");
32260 rc = -ECANCELED;
32261 goto out;
32262diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
32263index 56051d0..11cf3b7 100644
32264--- a/drivers/char/tpm/tpm_acpi.c
32265+++ b/drivers/char/tpm/tpm_acpi.c
32266@@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
32267 virt = acpi_os_map_memory(start, len);
32268 if (!virt) {
32269 kfree(log->bios_event_log);
32270+ log->bios_event_log = NULL;
32271 printk("%s: ERROR - Unable to map memory\n", __func__);
32272 return -EIO;
32273 }
32274
32275- memcpy_fromio(log->bios_event_log, virt, len);
32276+ memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
32277
32278 acpi_os_unmap_memory(virt, len);
32279 return 0;
32280diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
32281index 84ddc55..1d32f1e 100644
32282--- a/drivers/char/tpm/tpm_eventlog.c
32283+++ b/drivers/char/tpm/tpm_eventlog.c
32284@@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
32285 event = addr;
32286
32287 if ((event->event_type == 0 && event->event_size == 0) ||
32288- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
32289+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
32290 return NULL;
32291
32292 return addr;
32293@@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
32294 return NULL;
32295
32296 if ((event->event_type == 0 && event->event_size == 0) ||
32297- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
32298+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
32299 return NULL;
32300
32301 (*pos)++;
32302@@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
32303 int i;
32304
32305 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
32306- seq_putc(m, data[i]);
32307+ if (!seq_putc(m, data[i]))
32308+ return -EFAULT;
32309
32310 return 0;
32311 }
32312diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
32313index 8ab9c3d..c3e65d3 100644
32314--- a/drivers/char/virtio_console.c
32315+++ b/drivers/char/virtio_console.c
32316@@ -622,7 +622,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
32317 if (to_user) {
32318 ssize_t ret;
32319
32320- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
32321+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
32322 if (ret)
32323 return -EFAULT;
32324 } else {
32325@@ -721,7 +721,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
32326 if (!port_has_data(port) && !port->host_connected)
32327 return 0;
32328
32329- return fill_readbuf(port, ubuf, count, true);
32330+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
32331 }
32332
32333 static int wait_port_writable(struct port *port, bool nonblock)
32334diff --git a/drivers/edac/edac_mc.c b/drivers/edac/edac_mc.c
32335index 75c0a1a..96ba8f6 100644
32336--- a/drivers/edac/edac_mc.c
32337+++ b/drivers/edac/edac_mc.c
32338@@ -340,7 +340,7 @@ struct mem_ctl_info *edac_mc_alloc(unsigned mc_num,
32339 /*
32340 * Alocate and fill the csrow/channels structs
32341 */
32342- mci->csrows = kcalloc(sizeof(*mci->csrows), tot_csrows, GFP_KERNEL);
32343+ mci->csrows = kcalloc(tot_csrows, sizeof(*mci->csrows), GFP_KERNEL);
32344 if (!mci->csrows)
32345 goto error;
32346 for (row = 0; row < tot_csrows; row++) {
32347@@ -351,7 +351,7 @@ struct mem_ctl_info *edac_mc_alloc(unsigned mc_num,
32348 csr->csrow_idx = row;
32349 csr->mci = mci;
32350 csr->nr_channels = tot_channels;
32351- csr->channels = kcalloc(sizeof(*csr->channels), tot_channels,
32352+ csr->channels = kcalloc(tot_channels, sizeof(*csr->channels),
32353 GFP_KERNEL);
32354 if (!csr->channels)
32355 goto error;
32356@@ -369,7 +369,7 @@ struct mem_ctl_info *edac_mc_alloc(unsigned mc_num,
32357 /*
32358 * Allocate and fill the dimm structs
32359 */
32360- mci->dimms = kcalloc(sizeof(*mci->dimms), tot_dimms, GFP_KERNEL);
32361+ mci->dimms = kcalloc(tot_dimms, sizeof(*mci->dimms), GFP_KERNEL);
32362 if (!mci->dimms)
32363 goto error;
32364
32365diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
32366index 1bfb207..0d059c2 100644
32367--- a/drivers/edac/edac_pci_sysfs.c
32368+++ b/drivers/edac/edac_pci_sysfs.c
32369@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
32370 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
32371 static int edac_pci_poll_msec = 1000; /* one second workq period */
32372
32373-static atomic_t pci_parity_count = ATOMIC_INIT(0);
32374-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
32375+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
32376+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
32377
32378 static struct kobject *edac_pci_top_main_kobj;
32379 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
32380@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32381 edac_printk(KERN_CRIT, EDAC_PCI,
32382 "Signaled System Error on %s\n",
32383 pci_name(dev));
32384- atomic_inc(&pci_nonparity_count);
32385+ atomic_inc_unchecked(&pci_nonparity_count);
32386 }
32387
32388 if (status & (PCI_STATUS_PARITY)) {
32389@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32390 "Master Data Parity Error on %s\n",
32391 pci_name(dev));
32392
32393- atomic_inc(&pci_parity_count);
32394+ atomic_inc_unchecked(&pci_parity_count);
32395 }
32396
32397 if (status & (PCI_STATUS_DETECTED_PARITY)) {
32398@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32399 "Detected Parity Error on %s\n",
32400 pci_name(dev));
32401
32402- atomic_inc(&pci_parity_count);
32403+ atomic_inc_unchecked(&pci_parity_count);
32404 }
32405 }
32406
32407@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32408 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
32409 "Signaled System Error on %s\n",
32410 pci_name(dev));
32411- atomic_inc(&pci_nonparity_count);
32412+ atomic_inc_unchecked(&pci_nonparity_count);
32413 }
32414
32415 if (status & (PCI_STATUS_PARITY)) {
32416@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32417 "Master Data Parity Error on "
32418 "%s\n", pci_name(dev));
32419
32420- atomic_inc(&pci_parity_count);
32421+ atomic_inc_unchecked(&pci_parity_count);
32422 }
32423
32424 if (status & (PCI_STATUS_DETECTED_PARITY)) {
32425@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32426 "Detected Parity Error on %s\n",
32427 pci_name(dev));
32428
32429- atomic_inc(&pci_parity_count);
32430+ atomic_inc_unchecked(&pci_parity_count);
32431 }
32432 }
32433 }
32434@@ -676,7 +676,7 @@ void edac_pci_do_parity_check(void)
32435 if (!check_pci_errors)
32436 return;
32437
32438- before_count = atomic_read(&pci_parity_count);
32439+ before_count = atomic_read_unchecked(&pci_parity_count);
32440
32441 /* scan all PCI devices looking for a Parity Error on devices and
32442 * bridges.
32443@@ -688,7 +688,7 @@ void edac_pci_do_parity_check(void)
32444 /* Only if operator has selected panic on PCI Error */
32445 if (edac_pci_get_panic_on_pe()) {
32446 /* If the count is different 'after' from 'before' */
32447- if (before_count != atomic_read(&pci_parity_count))
32448+ if (before_count != atomic_read_unchecked(&pci_parity_count))
32449 panic("EDAC: PCI Parity Error");
32450 }
32451 }
32452diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
32453index 8c87a5e..a19cbd7 100644
32454--- a/drivers/edac/mce_amd.h
32455+++ b/drivers/edac/mce_amd.h
32456@@ -80,7 +80,7 @@ extern const char * const ii_msgs[];
32457 struct amd_decoder_ops {
32458 bool (*dc_mce)(u16, u8);
32459 bool (*ic_mce)(u16, u8);
32460-};
32461+} __no_const;
32462
32463 void amd_report_gart_errors(bool);
32464 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
32465diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
32466index 57ea7f4..789e3c3 100644
32467--- a/drivers/firewire/core-card.c
32468+++ b/drivers/firewire/core-card.c
32469@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
32470
32471 void fw_core_remove_card(struct fw_card *card)
32472 {
32473- struct fw_card_driver dummy_driver = dummy_driver_template;
32474+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
32475
32476 card->driver->update_phy_reg(card, 4,
32477 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
32478diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
32479index f8d2287..5aaf4db 100644
32480--- a/drivers/firewire/core-cdev.c
32481+++ b/drivers/firewire/core-cdev.c
32482@@ -1365,8 +1365,7 @@ static int init_iso_resource(struct client *client,
32483 int ret;
32484
32485 if ((request->channels == 0 && request->bandwidth == 0) ||
32486- request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
32487- request->bandwidth < 0)
32488+ request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
32489 return -EINVAL;
32490
32491 r = kmalloc(sizeof(*r), GFP_KERNEL);
32492diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
32493index 28a94c7..58da63a 100644
32494--- a/drivers/firewire/core-transaction.c
32495+++ b/drivers/firewire/core-transaction.c
32496@@ -38,6 +38,7 @@
32497 #include <linux/timer.h>
32498 #include <linux/types.h>
32499 #include <linux/workqueue.h>
32500+#include <linux/sched.h>
32501
32502 #include <asm/byteorder.h>
32503
32504diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
32505index 515a42c..5ecf3ba 100644
32506--- a/drivers/firewire/core.h
32507+++ b/drivers/firewire/core.h
32508@@ -111,6 +111,7 @@ struct fw_card_driver {
32509
32510 int (*stop_iso)(struct fw_iso_context *ctx);
32511 };
32512+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
32513
32514 void fw_card_initialize(struct fw_card *card,
32515 const struct fw_card_driver *driver, struct device *device);
32516diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
32517index 982f1f5..d21e5da 100644
32518--- a/drivers/firmware/dmi_scan.c
32519+++ b/drivers/firmware/dmi_scan.c
32520@@ -491,11 +491,6 @@ void __init dmi_scan_machine(void)
32521 }
32522 }
32523 else {
32524- /*
32525- * no iounmap() for that ioremap(); it would be a no-op, but
32526- * it's so early in setup that sucker gets confused into doing
32527- * what it shouldn't if we actually call it.
32528- */
32529 p = dmi_ioremap(0xF0000, 0x10000);
32530 if (p == NULL)
32531 goto error;
32532@@ -770,7 +765,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
32533 if (buf == NULL)
32534 return -1;
32535
32536- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
32537+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
32538
32539 iounmap(buf);
32540 return 0;
32541diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c
32542index bfd8f43..133189c 100644
32543--- a/drivers/firmware/efivars.c
32544+++ b/drivers/firmware/efivars.c
32545@@ -1234,9 +1234,9 @@ efivars_init(void)
32546 return -ENOMEM;
32547 }
32548
32549- ops.get_variable = efi.get_variable;
32550- ops.set_variable = efi.set_variable;
32551- ops.get_next_variable = efi.get_next_variable;
32552+ *(void **)&ops.get_variable = efi.get_variable;
32553+ *(void **)&ops.set_variable = efi.set_variable;
32554+ *(void **)&ops.get_next_variable = efi.get_next_variable;
32555 error = register_efivars(&__efivars, &ops, efi_kobj);
32556 if (error)
32557 goto err_put;
32558diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
32559index 82d5c20..44a7177 100644
32560--- a/drivers/gpio/gpio-vr41xx.c
32561+++ b/drivers/gpio/gpio-vr41xx.c
32562@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
32563 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
32564 maskl, pendl, maskh, pendh);
32565
32566- atomic_inc(&irq_err_count);
32567+ atomic_inc_unchecked(&irq_err_count);
32568
32569 return -EINVAL;
32570 }
32571diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
32572index 1227adf..f2301c2 100644
32573--- a/drivers/gpu/drm/drm_crtc_helper.c
32574+++ b/drivers/gpu/drm/drm_crtc_helper.c
32575@@ -286,7 +286,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
32576 struct drm_crtc *tmp;
32577 int crtc_mask = 1;
32578
32579- WARN(!crtc, "checking null crtc?\n");
32580+ BUG_ON(!crtc);
32581
32582 dev = crtc->dev;
32583
32584diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
32585index be174ca..0bcbb71 100644
32586--- a/drivers/gpu/drm/drm_drv.c
32587+++ b/drivers/gpu/drm/drm_drv.c
32588@@ -307,7 +307,7 @@ module_exit(drm_core_exit);
32589 /**
32590 * Copy and IOCTL return string to user space
32591 */
32592-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
32593+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
32594 {
32595 int len;
32596
32597@@ -390,7 +390,7 @@ long drm_ioctl(struct file *filp,
32598 return -ENODEV;
32599
32600 atomic_inc(&dev->ioctl_count);
32601- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
32602+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
32603 ++file_priv->ioctl_count;
32604
32605 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
32606diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
32607index 133b413..fd68225 100644
32608--- a/drivers/gpu/drm/drm_fops.c
32609+++ b/drivers/gpu/drm/drm_fops.c
32610@@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
32611 }
32612
32613 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
32614- atomic_set(&dev->counts[i], 0);
32615+ atomic_set_unchecked(&dev->counts[i], 0);
32616
32617 dev->sigdata.lock = NULL;
32618
32619@@ -134,7 +134,7 @@ int drm_open(struct inode *inode, struct file *filp)
32620 if (drm_device_is_unplugged(dev))
32621 return -ENODEV;
32622
32623- if (!dev->open_count++)
32624+ if (local_inc_return(&dev->open_count) == 1)
32625 need_setup = 1;
32626 mutex_lock(&dev->struct_mutex);
32627 old_mapping = dev->dev_mapping;
32628@@ -149,7 +149,7 @@ int drm_open(struct inode *inode, struct file *filp)
32629 retcode = drm_open_helper(inode, filp, dev);
32630 if (retcode)
32631 goto err_undo;
32632- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
32633+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
32634 if (need_setup) {
32635 retcode = drm_setup(dev);
32636 if (retcode)
32637@@ -164,7 +164,7 @@ err_undo:
32638 iput(container_of(dev->dev_mapping, struct inode, i_data));
32639 dev->dev_mapping = old_mapping;
32640 mutex_unlock(&dev->struct_mutex);
32641- dev->open_count--;
32642+ local_dec(&dev->open_count);
32643 return retcode;
32644 }
32645 EXPORT_SYMBOL(drm_open);
32646@@ -438,7 +438,7 @@ int drm_release(struct inode *inode, struct file *filp)
32647
32648 mutex_lock(&drm_global_mutex);
32649
32650- DRM_DEBUG("open_count = %d\n", dev->open_count);
32651+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
32652
32653 if (dev->driver->preclose)
32654 dev->driver->preclose(dev, file_priv);
32655@@ -447,10 +447,10 @@ int drm_release(struct inode *inode, struct file *filp)
32656 * Begin inline drm_release
32657 */
32658
32659- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
32660+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
32661 task_pid_nr(current),
32662 (long)old_encode_dev(file_priv->minor->device),
32663- dev->open_count);
32664+ local_read(&dev->open_count));
32665
32666 /* Release any auth tokens that might point to this file_priv,
32667 (do that under the drm_global_mutex) */
32668@@ -547,8 +547,8 @@ int drm_release(struct inode *inode, struct file *filp)
32669 * End inline drm_release
32670 */
32671
32672- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
32673- if (!--dev->open_count) {
32674+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
32675+ if (local_dec_and_test(&dev->open_count)) {
32676 if (atomic_read(&dev->ioctl_count)) {
32677 DRM_ERROR("Device busy: %d\n",
32678 atomic_read(&dev->ioctl_count));
32679diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
32680index f731116..629842c 100644
32681--- a/drivers/gpu/drm/drm_global.c
32682+++ b/drivers/gpu/drm/drm_global.c
32683@@ -36,7 +36,7 @@
32684 struct drm_global_item {
32685 struct mutex mutex;
32686 void *object;
32687- int refcount;
32688+ atomic_t refcount;
32689 };
32690
32691 static struct drm_global_item glob[DRM_GLOBAL_NUM];
32692@@ -49,7 +49,7 @@ void drm_global_init(void)
32693 struct drm_global_item *item = &glob[i];
32694 mutex_init(&item->mutex);
32695 item->object = NULL;
32696- item->refcount = 0;
32697+ atomic_set(&item->refcount, 0);
32698 }
32699 }
32700
32701@@ -59,7 +59,7 @@ void drm_global_release(void)
32702 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
32703 struct drm_global_item *item = &glob[i];
32704 BUG_ON(item->object != NULL);
32705- BUG_ON(item->refcount != 0);
32706+ BUG_ON(atomic_read(&item->refcount) != 0);
32707 }
32708 }
32709
32710@@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
32711 void *object;
32712
32713 mutex_lock(&item->mutex);
32714- if (item->refcount == 0) {
32715+ if (atomic_read(&item->refcount) == 0) {
32716 item->object = kzalloc(ref->size, GFP_KERNEL);
32717 if (unlikely(item->object == NULL)) {
32718 ret = -ENOMEM;
32719@@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
32720 goto out_err;
32721
32722 }
32723- ++item->refcount;
32724+ atomic_inc(&item->refcount);
32725 ref->object = item->object;
32726 object = item->object;
32727 mutex_unlock(&item->mutex);
32728@@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
32729 struct drm_global_item *item = &glob[ref->global_type];
32730
32731 mutex_lock(&item->mutex);
32732- BUG_ON(item->refcount == 0);
32733+ BUG_ON(atomic_read(&item->refcount) == 0);
32734 BUG_ON(ref->object != item->object);
32735- if (--item->refcount == 0) {
32736+ if (atomic_dec_and_test(&item->refcount)) {
32737 ref->release(ref);
32738 item->object = NULL;
32739 }
32740diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
32741index d4b20ce..77a8d41 100644
32742--- a/drivers/gpu/drm/drm_info.c
32743+++ b/drivers/gpu/drm/drm_info.c
32744@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
32745 struct drm_local_map *map;
32746 struct drm_map_list *r_list;
32747
32748- /* Hardcoded from _DRM_FRAME_BUFFER,
32749- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
32750- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
32751- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
32752+ static const char * const types[] = {
32753+ [_DRM_FRAME_BUFFER] = "FB",
32754+ [_DRM_REGISTERS] = "REG",
32755+ [_DRM_SHM] = "SHM",
32756+ [_DRM_AGP] = "AGP",
32757+ [_DRM_SCATTER_GATHER] = "SG",
32758+ [_DRM_CONSISTENT] = "PCI",
32759+ [_DRM_GEM] = "GEM" };
32760 const char *type;
32761 int i;
32762
32763@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
32764 map = r_list->map;
32765 if (!map)
32766 continue;
32767- if (map->type < 0 || map->type > 5)
32768+ if (map->type >= ARRAY_SIZE(types))
32769 type = "??";
32770 else
32771 type = types[map->type];
32772@@ -253,7 +257,11 @@ int drm_vma_info(struct seq_file *m, void *data)
32773 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
32774 vma->vm_flags & VM_LOCKED ? 'l' : '-',
32775 vma->vm_flags & VM_IO ? 'i' : '-',
32776+#ifdef CONFIG_GRKERNSEC_HIDESYM
32777+ 0);
32778+#else
32779 vma->vm_pgoff);
32780+#endif
32781
32782 #if defined(__i386__)
32783 pgprot = pgprot_val(vma->vm_page_prot);
32784diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
32785index 2f4c434..764794b 100644
32786--- a/drivers/gpu/drm/drm_ioc32.c
32787+++ b/drivers/gpu/drm/drm_ioc32.c
32788@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
32789 request = compat_alloc_user_space(nbytes);
32790 if (!access_ok(VERIFY_WRITE, request, nbytes))
32791 return -EFAULT;
32792- list = (struct drm_buf_desc *) (request + 1);
32793+ list = (struct drm_buf_desc __user *) (request + 1);
32794
32795 if (__put_user(count, &request->count)
32796 || __put_user(list, &request->list))
32797@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
32798 request = compat_alloc_user_space(nbytes);
32799 if (!access_ok(VERIFY_WRITE, request, nbytes))
32800 return -EFAULT;
32801- list = (struct drm_buf_pub *) (request + 1);
32802+ list = (struct drm_buf_pub __user *) (request + 1);
32803
32804 if (__put_user(count, &request->count)
32805 || __put_user(list, &request->list))
32806diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
32807index 23dd975..63e9801 100644
32808--- a/drivers/gpu/drm/drm_ioctl.c
32809+++ b/drivers/gpu/drm/drm_ioctl.c
32810@@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
32811 stats->data[i].value =
32812 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
32813 else
32814- stats->data[i].value = atomic_read(&dev->counts[i]);
32815+ stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
32816 stats->data[i].type = dev->types[i];
32817 }
32818
32819diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
32820index d752c96..fe08455 100644
32821--- a/drivers/gpu/drm/drm_lock.c
32822+++ b/drivers/gpu/drm/drm_lock.c
32823@@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
32824 if (drm_lock_take(&master->lock, lock->context)) {
32825 master->lock.file_priv = file_priv;
32826 master->lock.lock_time = jiffies;
32827- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
32828+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
32829 break; /* Got lock */
32830 }
32831
32832@@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
32833 return -EINVAL;
32834 }
32835
32836- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
32837+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
32838
32839 if (drm_lock_free(&master->lock, lock->context)) {
32840 /* FIXME: Should really bail out here. */
32841diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
32842index c236fd2..6b5f2e7 100644
32843--- a/drivers/gpu/drm/drm_stub.c
32844+++ b/drivers/gpu/drm/drm_stub.c
32845@@ -511,7 +511,7 @@ void drm_unplug_dev(struct drm_device *dev)
32846
32847 drm_device_set_unplugged(dev);
32848
32849- if (dev->open_count == 0) {
32850+ if (local_read(&dev->open_count) == 0) {
32851 drm_put_dev(dev);
32852 }
32853 mutex_unlock(&drm_global_mutex);
32854diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
32855index 004ecdf..db1f6e0 100644
32856--- a/drivers/gpu/drm/i810/i810_dma.c
32857+++ b/drivers/gpu/drm/i810/i810_dma.c
32858@@ -945,8 +945,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
32859 dma->buflist[vertex->idx],
32860 vertex->discard, vertex->used);
32861
32862- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
32863- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
32864+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
32865+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
32866 sarea_priv->last_enqueue = dev_priv->counter - 1;
32867 sarea_priv->last_dispatch = (int)hw_status[5];
32868
32869@@ -1106,8 +1106,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
32870 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
32871 mc->last_render);
32872
32873- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
32874- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
32875+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
32876+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
32877 sarea_priv->last_enqueue = dev_priv->counter - 1;
32878 sarea_priv->last_dispatch = (int)hw_status[5];
32879
32880diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
32881index 6e0acad..93c8289 100644
32882--- a/drivers/gpu/drm/i810/i810_drv.h
32883+++ b/drivers/gpu/drm/i810/i810_drv.h
32884@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
32885 int page_flipping;
32886
32887 wait_queue_head_t irq_queue;
32888- atomic_t irq_received;
32889- atomic_t irq_emitted;
32890+ atomic_unchecked_t irq_received;
32891+ atomic_unchecked_t irq_emitted;
32892
32893 int front_offset;
32894 } drm_i810_private_t;
32895diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
32896index 3a1a495..995c093 100644
32897--- a/drivers/gpu/drm/i915/i915_debugfs.c
32898+++ b/drivers/gpu/drm/i915/i915_debugfs.c
32899@@ -496,7 +496,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
32900 I915_READ(GTIMR));
32901 }
32902 seq_printf(m, "Interrupts received: %d\n",
32903- atomic_read(&dev_priv->irq_received));
32904+ atomic_read_unchecked(&dev_priv->irq_received));
32905 for_each_ring(ring, dev_priv, i) {
32906 if (IS_GEN6(dev) || IS_GEN7(dev)) {
32907 seq_printf(m,
32908diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
32909index 61ae104..f8a4bc1 100644
32910--- a/drivers/gpu/drm/i915/i915_dma.c
32911+++ b/drivers/gpu/drm/i915/i915_dma.c
32912@@ -1274,7 +1274,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
32913 bool can_switch;
32914
32915 spin_lock(&dev->count_lock);
32916- can_switch = (dev->open_count == 0);
32917+ can_switch = (local_read(&dev->open_count) == 0);
32918 spin_unlock(&dev->count_lock);
32919 return can_switch;
32920 }
32921diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
32922index 92f1750..3beba74 100644
32923--- a/drivers/gpu/drm/i915/i915_drv.h
32924+++ b/drivers/gpu/drm/i915/i915_drv.h
32925@@ -430,7 +430,7 @@ typedef struct drm_i915_private {
32926
32927 struct resource mch_res;
32928
32929- atomic_t irq_received;
32930+ atomic_unchecked_t irq_received;
32931
32932 /* protects the irq masks */
32933 spinlock_t irq_lock;
32934@@ -1055,7 +1055,7 @@ struct drm_i915_gem_object {
32935 * will be page flipped away on the next vblank. When it
32936 * reaches 0, dev_priv->pending_flip_queue will be woken up.
32937 */
32938- atomic_t pending_flip;
32939+ atomic_unchecked_t pending_flip;
32940 };
32941
32942 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
32943@@ -1558,7 +1558,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
32944 struct drm_i915_private *dev_priv, unsigned port);
32945 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
32946 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
32947-extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
32948+static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
32949 {
32950 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
32951 }
32952diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
32953index 67036e9..b9f1357 100644
32954--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
32955+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
32956@@ -681,7 +681,7 @@ i915_gem_execbuffer_move_to_gpu(struct intel_ring_buffer *ring,
32957 i915_gem_clflush_object(obj);
32958
32959 if (obj->base.pending_write_domain)
32960- flips |= atomic_read(&obj->pending_flip);
32961+ flips |= atomic_read_unchecked(&obj->pending_flip);
32962
32963 flush_domains |= obj->base.write_domain;
32964 }
32965@@ -712,9 +712,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
32966
32967 static int
32968 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
32969- int count)
32970+ unsigned int count)
32971 {
32972- int i;
32973+ unsigned int i;
32974
32975 for (i = 0; i < count; i++) {
32976 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
32977diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
32978index dc29ace..137d83a 100644
32979--- a/drivers/gpu/drm/i915/i915_irq.c
32980+++ b/drivers/gpu/drm/i915/i915_irq.c
32981@@ -531,7 +531,7 @@ static irqreturn_t valleyview_irq_handler(DRM_IRQ_ARGS)
32982 u32 pipe_stats[I915_MAX_PIPES];
32983 bool blc_event;
32984
32985- atomic_inc(&dev_priv->irq_received);
32986+ atomic_inc_unchecked(&dev_priv->irq_received);
32987
32988 while (true) {
32989 iir = I915_READ(VLV_IIR);
32990@@ -678,7 +678,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
32991 irqreturn_t ret = IRQ_NONE;
32992 int i;
32993
32994- atomic_inc(&dev_priv->irq_received);
32995+ atomic_inc_unchecked(&dev_priv->irq_received);
32996
32997 /* disable master interrupt before clearing iir */
32998 de_ier = I915_READ(DEIER);
32999@@ -753,7 +753,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
33000 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
33001 u32 hotplug_mask;
33002
33003- atomic_inc(&dev_priv->irq_received);
33004+ atomic_inc_unchecked(&dev_priv->irq_received);
33005
33006 /* disable master interrupt before clearing iir */
33007 de_ier = I915_READ(DEIER);
33008@@ -1762,7 +1762,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
33009 {
33010 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
33011
33012- atomic_set(&dev_priv->irq_received, 0);
33013+ atomic_set_unchecked(&dev_priv->irq_received, 0);
33014
33015 I915_WRITE(HWSTAM, 0xeffe);
33016
33017@@ -1788,7 +1788,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
33018 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
33019 int pipe;
33020
33021- atomic_set(&dev_priv->irq_received, 0);
33022+ atomic_set_unchecked(&dev_priv->irq_received, 0);
33023
33024 /* VLV magic */
33025 I915_WRITE(VLV_IMR, 0);
33026@@ -2093,7 +2093,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
33027 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
33028 int pipe;
33029
33030- atomic_set(&dev_priv->irq_received, 0);
33031+ atomic_set_unchecked(&dev_priv->irq_received, 0);
33032
33033 for_each_pipe(pipe)
33034 I915_WRITE(PIPESTAT(pipe), 0);
33035@@ -2144,7 +2144,7 @@ static irqreturn_t i8xx_irq_handler(DRM_IRQ_ARGS)
33036 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
33037 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
33038
33039- atomic_inc(&dev_priv->irq_received);
33040+ atomic_inc_unchecked(&dev_priv->irq_received);
33041
33042 iir = I915_READ16(IIR);
33043 if (iir == 0)
33044@@ -2229,7 +2229,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
33045 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
33046 int pipe;
33047
33048- atomic_set(&dev_priv->irq_received, 0);
33049+ atomic_set_unchecked(&dev_priv->irq_received, 0);
33050
33051 if (I915_HAS_HOTPLUG(dev)) {
33052 I915_WRITE(PORT_HOTPLUG_EN, 0);
33053@@ -2324,7 +2324,7 @@ static irqreturn_t i915_irq_handler(DRM_IRQ_ARGS)
33054 };
33055 int pipe, ret = IRQ_NONE;
33056
33057- atomic_inc(&dev_priv->irq_received);
33058+ atomic_inc_unchecked(&dev_priv->irq_received);
33059
33060 iir = I915_READ(IIR);
33061 do {
33062@@ -2450,7 +2450,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
33063 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
33064 int pipe;
33065
33066- atomic_set(&dev_priv->irq_received, 0);
33067+ atomic_set_unchecked(&dev_priv->irq_received, 0);
33068
33069 I915_WRITE(PORT_HOTPLUG_EN, 0);
33070 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
33071@@ -2557,7 +2557,7 @@ static irqreturn_t i965_irq_handler(DRM_IRQ_ARGS)
33072 int irq_received;
33073 int ret = IRQ_NONE, pipe;
33074
33075- atomic_inc(&dev_priv->irq_received);
33076+ atomic_inc_unchecked(&dev_priv->irq_received);
33077
33078 iir = I915_READ(IIR);
33079
33080diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
33081index 4d3c7c6..eaac87b 100644
33082--- a/drivers/gpu/drm/i915/intel_display.c
33083+++ b/drivers/gpu/drm/i915/intel_display.c
33084@@ -2131,7 +2131,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
33085
33086 wait_event(dev_priv->pending_flip_queue,
33087 atomic_read(&dev_priv->mm.wedged) ||
33088- atomic_read(&obj->pending_flip) == 0);
33089+ atomic_read_unchecked(&obj->pending_flip) == 0);
33090
33091 /* Big Hammer, we also need to ensure that any pending
33092 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
33093@@ -6221,8 +6221,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
33094
33095 obj = work->old_fb_obj;
33096
33097- atomic_clear_mask(1 << intel_crtc->plane,
33098- &obj->pending_flip.counter);
33099+ atomic_clear_mask_unchecked(1 << intel_crtc->plane, &obj->pending_flip);
33100 wake_up(&dev_priv->pending_flip_queue);
33101
33102 queue_work(dev_priv->wq, &work->work);
33103@@ -6589,7 +6588,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
33104 /* Block clients from rendering to the new back buffer until
33105 * the flip occurs and the object is no longer visible.
33106 */
33107- atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
33108+ atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
33109 atomic_inc(&intel_crtc->unpin_work_count);
33110
33111 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
33112@@ -6606,7 +6605,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
33113
33114 cleanup_pending:
33115 atomic_dec(&intel_crtc->unpin_work_count);
33116- atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
33117+ atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
33118 drm_gem_object_unreference(&work->old_fb_obj->base);
33119 drm_gem_object_unreference(&obj->base);
33120 mutex_unlock(&dev->struct_mutex);
33121diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
33122index 54558a0..2d97005 100644
33123--- a/drivers/gpu/drm/mga/mga_drv.h
33124+++ b/drivers/gpu/drm/mga/mga_drv.h
33125@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
33126 u32 clear_cmd;
33127 u32 maccess;
33128
33129- atomic_t vbl_received; /**< Number of vblanks received. */
33130+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
33131 wait_queue_head_t fence_queue;
33132- atomic_t last_fence_retired;
33133+ atomic_unchecked_t last_fence_retired;
33134 u32 next_fence_to_post;
33135
33136 unsigned int fb_cpp;
33137diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
33138index 598c281..60d590e 100644
33139--- a/drivers/gpu/drm/mga/mga_irq.c
33140+++ b/drivers/gpu/drm/mga/mga_irq.c
33141@@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
33142 if (crtc != 0)
33143 return 0;
33144
33145- return atomic_read(&dev_priv->vbl_received);
33146+ return atomic_read_unchecked(&dev_priv->vbl_received);
33147 }
33148
33149
33150@@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
33151 /* VBLANK interrupt */
33152 if (status & MGA_VLINEPEN) {
33153 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
33154- atomic_inc(&dev_priv->vbl_received);
33155+ atomic_inc_unchecked(&dev_priv->vbl_received);
33156 drm_handle_vblank(dev, 0);
33157 handled = 1;
33158 }
33159@@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
33160 if ((prim_start & ~0x03) != (prim_end & ~0x03))
33161 MGA_WRITE(MGA_PRIMEND, prim_end);
33162
33163- atomic_inc(&dev_priv->last_fence_retired);
33164+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
33165 DRM_WAKEUP(&dev_priv->fence_queue);
33166 handled = 1;
33167 }
33168@@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
33169 * using fences.
33170 */
33171 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
33172- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
33173+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
33174 - *sequence) <= (1 << 23)));
33175
33176 *sequence = cur_fence;
33177diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
33178index 09fdef2..57f5c3b 100644
33179--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
33180+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
33181@@ -1240,7 +1240,7 @@ parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
33182 struct bit_table {
33183 const char id;
33184 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
33185-};
33186+} __no_const;
33187
33188 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
33189
33190diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
33191index a101699..a163f0a 100644
33192--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
33193+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
33194@@ -80,7 +80,7 @@ struct nouveau_drm {
33195 struct drm_global_reference mem_global_ref;
33196 struct ttm_bo_global_ref bo_global_ref;
33197 struct ttm_bo_device bdev;
33198- atomic_t validate_sequence;
33199+ atomic_unchecked_t validate_sequence;
33200 int (*move)(struct nouveau_channel *,
33201 struct ttm_buffer_object *,
33202 struct ttm_mem_reg *, struct ttm_mem_reg *);
33203diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.h b/drivers/gpu/drm/nouveau/nouveau_fence.h
33204index cdb83ac..27f0a16 100644
33205--- a/drivers/gpu/drm/nouveau/nouveau_fence.h
33206+++ b/drivers/gpu/drm/nouveau/nouveau_fence.h
33207@@ -43,7 +43,7 @@ struct nouveau_fence_priv {
33208 int (*sync)(struct nouveau_fence *, struct nouveau_channel *,
33209 struct nouveau_channel *);
33210 u32 (*read)(struct nouveau_channel *);
33211-};
33212+} __no_const;
33213
33214 #define nouveau_fence(drm) ((struct nouveau_fence_priv *)(drm)->fence)
33215
33216diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
33217index 5e2f521..0d21436 100644
33218--- a/drivers/gpu/drm/nouveau/nouveau_gem.c
33219+++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
33220@@ -321,7 +321,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
33221 int trycnt = 0;
33222 int ret, i;
33223
33224- sequence = atomic_add_return(1, &drm->ttm.validate_sequence);
33225+ sequence = atomic_add_return_unchecked(1, &drm->ttm.validate_sequence);
33226 retry:
33227 if (++trycnt > 100000) {
33228 NV_ERROR(drm, "%s failed and gave up.\n", __func__);
33229diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
33230index 6f0ac64..9c2dfb4 100644
33231--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
33232+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
33233@@ -63,7 +63,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
33234 bool can_switch;
33235
33236 spin_lock(&dev->count_lock);
33237- can_switch = (dev->open_count == 0);
33238+ can_switch = (local_read(&dev->open_count) == 0);
33239 spin_unlock(&dev->count_lock);
33240 return can_switch;
33241 }
33242diff --git a/drivers/gpu/drm/nouveau/nv50_evo.c b/drivers/gpu/drm/nouveau/nv50_evo.c
33243index 9f6f55c..30e3a29 100644
33244--- a/drivers/gpu/drm/nouveau/nv50_evo.c
33245+++ b/drivers/gpu/drm/nouveau/nv50_evo.c
33246@@ -152,9 +152,9 @@ nv50_evo_channel_new(struct drm_device *dev, int chid,
33247 kzalloc(sizeof(*evo->object->oclass), GFP_KERNEL);
33248 evo->object->oclass->ofuncs =
33249 kzalloc(sizeof(*evo->object->oclass->ofuncs), GFP_KERNEL);
33250- evo->object->oclass->ofuncs->rd32 = nv50_evo_rd32;
33251- evo->object->oclass->ofuncs->wr32 = nv50_evo_wr32;
33252- evo->object->oclass->ofuncs->rd08 =
33253+ *(void**)&evo->object->oclass->ofuncs->rd32 = nv50_evo_rd32;
33254+ *(void**)&evo->object->oclass->ofuncs->wr32 = nv50_evo_wr32;
33255+ *(void**)&evo->object->oclass->ofuncs->rd08 =
33256 ioremap(pci_resource_start(dev->pdev, 0) +
33257 NV50_PDISPLAY_USER(evo->handle), PAGE_SIZE);
33258 return 0;
33259diff --git a/drivers/gpu/drm/nouveau/nv50_sor.c b/drivers/gpu/drm/nouveau/nv50_sor.c
33260index b562b59..9d725a8 100644
33261--- a/drivers/gpu/drm/nouveau/nv50_sor.c
33262+++ b/drivers/gpu/drm/nouveau/nv50_sor.c
33263@@ -317,7 +317,7 @@ nv50_sor_dpms(struct drm_encoder *encoder, int mode)
33264 }
33265
33266 if (nv_encoder->dcb->type == DCB_OUTPUT_DP) {
33267- struct dp_train_func func = {
33268+ static struct dp_train_func func = {
33269 .link_set = nv50_sor_dp_link_set,
33270 .train_set = nv50_sor_dp_train_set,
33271 .train_adj = nv50_sor_dp_train_adj
33272diff --git a/drivers/gpu/drm/nouveau/nvd0_display.c b/drivers/gpu/drm/nouveau/nvd0_display.c
33273index c402fca..f1d694b 100644
33274--- a/drivers/gpu/drm/nouveau/nvd0_display.c
33275+++ b/drivers/gpu/drm/nouveau/nvd0_display.c
33276@@ -1389,7 +1389,7 @@ nvd0_sor_dpms(struct drm_encoder *encoder, int mode)
33277 nv_wait(device, 0x61c030 + (or * 0x0800), 0x10000000, 0x00000000);
33278
33279 if (nv_encoder->dcb->type == DCB_OUTPUT_DP) {
33280- struct dp_train_func func = {
33281+ static struct dp_train_func func = {
33282 .link_set = nvd0_sor_dp_link_set,
33283 .train_set = nvd0_sor_dp_train_set,
33284 .train_adj = nvd0_sor_dp_train_adj
33285diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
33286index d4660cf..70dbe65 100644
33287--- a/drivers/gpu/drm/r128/r128_cce.c
33288+++ b/drivers/gpu/drm/r128/r128_cce.c
33289@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
33290
33291 /* GH: Simple idle check.
33292 */
33293- atomic_set(&dev_priv->idle_count, 0);
33294+ atomic_set_unchecked(&dev_priv->idle_count, 0);
33295
33296 /* We don't support anything other than bus-mastering ring mode,
33297 * but the ring can be in either AGP or PCI space for the ring
33298diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
33299index 930c71b..499aded 100644
33300--- a/drivers/gpu/drm/r128/r128_drv.h
33301+++ b/drivers/gpu/drm/r128/r128_drv.h
33302@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
33303 int is_pci;
33304 unsigned long cce_buffers_offset;
33305
33306- atomic_t idle_count;
33307+ atomic_unchecked_t idle_count;
33308
33309 int page_flipping;
33310 int current_page;
33311 u32 crtc_offset;
33312 u32 crtc_offset_cntl;
33313
33314- atomic_t vbl_received;
33315+ atomic_unchecked_t vbl_received;
33316
33317 u32 color_fmt;
33318 unsigned int front_offset;
33319diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
33320index 2ea4f09..d391371 100644
33321--- a/drivers/gpu/drm/r128/r128_irq.c
33322+++ b/drivers/gpu/drm/r128/r128_irq.c
33323@@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
33324 if (crtc != 0)
33325 return 0;
33326
33327- return atomic_read(&dev_priv->vbl_received);
33328+ return atomic_read_unchecked(&dev_priv->vbl_received);
33329 }
33330
33331 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
33332@@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
33333 /* VBLANK interrupt */
33334 if (status & R128_CRTC_VBLANK_INT) {
33335 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
33336- atomic_inc(&dev_priv->vbl_received);
33337+ atomic_inc_unchecked(&dev_priv->vbl_received);
33338 drm_handle_vblank(dev, 0);
33339 return IRQ_HANDLED;
33340 }
33341diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
33342index 19bb7e6..de7e2a2 100644
33343--- a/drivers/gpu/drm/r128/r128_state.c
33344+++ b/drivers/gpu/drm/r128/r128_state.c
33345@@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
33346
33347 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
33348 {
33349- if (atomic_read(&dev_priv->idle_count) == 0)
33350+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
33351 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
33352 else
33353- atomic_set(&dev_priv->idle_count, 0);
33354+ atomic_set_unchecked(&dev_priv->idle_count, 0);
33355 }
33356
33357 #endif
33358diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
33359index 5a82b6b..9e69c73 100644
33360--- a/drivers/gpu/drm/radeon/mkregtable.c
33361+++ b/drivers/gpu/drm/radeon/mkregtable.c
33362@@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
33363 regex_t mask_rex;
33364 regmatch_t match[4];
33365 char buf[1024];
33366- size_t end;
33367+ long end;
33368 int len;
33369 int done = 0;
33370 int r;
33371 unsigned o;
33372 struct offset *offset;
33373 char last_reg_s[10];
33374- int last_reg;
33375+ unsigned long last_reg;
33376
33377 if (regcomp
33378 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
33379diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
33380index 008d645..de03849 100644
33381--- a/drivers/gpu/drm/radeon/radeon_device.c
33382+++ b/drivers/gpu/drm/radeon/radeon_device.c
33383@@ -941,7 +941,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
33384 bool can_switch;
33385
33386 spin_lock(&dev->count_lock);
33387- can_switch = (dev->open_count == 0);
33388+ can_switch = (local_read(&dev->open_count) == 0);
33389 spin_unlock(&dev->count_lock);
33390 return can_switch;
33391 }
33392diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
33393index a1b59ca..86f2d44 100644
33394--- a/drivers/gpu/drm/radeon/radeon_drv.h
33395+++ b/drivers/gpu/drm/radeon/radeon_drv.h
33396@@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
33397
33398 /* SW interrupt */
33399 wait_queue_head_t swi_queue;
33400- atomic_t swi_emitted;
33401+ atomic_unchecked_t swi_emitted;
33402 int vblank_crtc;
33403 uint32_t irq_enable_reg;
33404 uint32_t r500_disp_irq_reg;
33405diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
33406index c180df8..cd80dd2d 100644
33407--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
33408+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
33409@@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
33410 request = compat_alloc_user_space(sizeof(*request));
33411 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
33412 || __put_user(req32.param, &request->param)
33413- || __put_user((void __user *)(unsigned long)req32.value,
33414+ || __put_user((unsigned long)req32.value,
33415 &request->value))
33416 return -EFAULT;
33417
33418diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
33419index e771033..a0bc6b3 100644
33420--- a/drivers/gpu/drm/radeon/radeon_irq.c
33421+++ b/drivers/gpu/drm/radeon/radeon_irq.c
33422@@ -224,8 +224,8 @@ static int radeon_emit_irq(struct drm_device * dev)
33423 unsigned int ret;
33424 RING_LOCALS;
33425
33426- atomic_inc(&dev_priv->swi_emitted);
33427- ret = atomic_read(&dev_priv->swi_emitted);
33428+ atomic_inc_unchecked(&dev_priv->swi_emitted);
33429+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
33430
33431 BEGIN_RING(4);
33432 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
33433@@ -351,7 +351,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
33434 drm_radeon_private_t *dev_priv =
33435 (drm_radeon_private_t *) dev->dev_private;
33436
33437- atomic_set(&dev_priv->swi_emitted, 0);
33438+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
33439 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
33440
33441 dev->max_vblank_count = 0x001fffff;
33442diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
33443index 8e9057b..af6dacb 100644
33444--- a/drivers/gpu/drm/radeon/radeon_state.c
33445+++ b/drivers/gpu/drm/radeon/radeon_state.c
33446@@ -2166,7 +2166,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
33447 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
33448 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
33449
33450- if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
33451+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
33452 sarea_priv->nbox * sizeof(depth_boxes[0])))
33453 return -EFAULT;
33454
33455@@ -3029,7 +3029,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
33456 {
33457 drm_radeon_private_t *dev_priv = dev->dev_private;
33458 drm_radeon_getparam_t *param = data;
33459- int value;
33460+ int value = 0;
33461
33462 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
33463
33464diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
33465index 5ebe1b3..1ed9426 100644
33466--- a/drivers/gpu/drm/radeon/radeon_ttm.c
33467+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
33468@@ -822,8 +822,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
33469 }
33470 if (unlikely(ttm_vm_ops == NULL)) {
33471 ttm_vm_ops = vma->vm_ops;
33472- radeon_ttm_vm_ops = *ttm_vm_ops;
33473- radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
33474+ pax_open_kernel();
33475+ memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
33476+ *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
33477+ pax_close_kernel();
33478 }
33479 vma->vm_ops = &radeon_ttm_vm_ops;
33480 return 0;
33481diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
33482index 5706d2a..17aedaa 100644
33483--- a/drivers/gpu/drm/radeon/rs690.c
33484+++ b/drivers/gpu/drm/radeon/rs690.c
33485@@ -304,9 +304,11 @@ static void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
33486 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
33487 rdev->pm.sideport_bandwidth.full)
33488 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
33489- read_delay_latency.full = dfixed_const(370 * 800 * 1000);
33490+ read_delay_latency.full = dfixed_const(800 * 1000);
33491 read_delay_latency.full = dfixed_div(read_delay_latency,
33492 rdev->pm.igp_sideport_mclk);
33493+ a.full = dfixed_const(370);
33494+ read_delay_latency.full = dfixed_mul(read_delay_latency, a);
33495 } else {
33496 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
33497 rdev->pm.k8_bandwidth.full)
33498diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
33499index bd2a3b4..122d9ad 100644
33500--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
33501+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
33502@@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
33503 static int ttm_pool_mm_shrink(struct shrinker *shrink,
33504 struct shrink_control *sc)
33505 {
33506- static atomic_t start_pool = ATOMIC_INIT(0);
33507+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
33508 unsigned i;
33509- unsigned pool_offset = atomic_add_return(1, &start_pool);
33510+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
33511 struct ttm_page_pool *pool;
33512 int shrink_pages = sc->nr_to_scan;
33513
33514diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
33515index 893a650..6190d3b 100644
33516--- a/drivers/gpu/drm/via/via_drv.h
33517+++ b/drivers/gpu/drm/via/via_drv.h
33518@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
33519 typedef uint32_t maskarray_t[5];
33520
33521 typedef struct drm_via_irq {
33522- atomic_t irq_received;
33523+ atomic_unchecked_t irq_received;
33524 uint32_t pending_mask;
33525 uint32_t enable_mask;
33526 wait_queue_head_t irq_queue;
33527@@ -75,7 +75,7 @@ typedef struct drm_via_private {
33528 struct timeval last_vblank;
33529 int last_vblank_valid;
33530 unsigned usec_per_vblank;
33531- atomic_t vbl_received;
33532+ atomic_unchecked_t vbl_received;
33533 drm_via_state_t hc_state;
33534 char pci_buf[VIA_PCI_BUF_SIZE];
33535 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
33536diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
33537index ac98964..5dbf512 100644
33538--- a/drivers/gpu/drm/via/via_irq.c
33539+++ b/drivers/gpu/drm/via/via_irq.c
33540@@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
33541 if (crtc != 0)
33542 return 0;
33543
33544- return atomic_read(&dev_priv->vbl_received);
33545+ return atomic_read_unchecked(&dev_priv->vbl_received);
33546 }
33547
33548 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
33549@@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
33550
33551 status = VIA_READ(VIA_REG_INTERRUPT);
33552 if (status & VIA_IRQ_VBLANK_PENDING) {
33553- atomic_inc(&dev_priv->vbl_received);
33554- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
33555+ atomic_inc_unchecked(&dev_priv->vbl_received);
33556+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
33557 do_gettimeofday(&cur_vblank);
33558 if (dev_priv->last_vblank_valid) {
33559 dev_priv->usec_per_vblank =
33560@@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
33561 dev_priv->last_vblank = cur_vblank;
33562 dev_priv->last_vblank_valid = 1;
33563 }
33564- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
33565+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
33566 DRM_DEBUG("US per vblank is: %u\n",
33567 dev_priv->usec_per_vblank);
33568 }
33569@@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
33570
33571 for (i = 0; i < dev_priv->num_irqs; ++i) {
33572 if (status & cur_irq->pending_mask) {
33573- atomic_inc(&cur_irq->irq_received);
33574+ atomic_inc_unchecked(&cur_irq->irq_received);
33575 DRM_WAKEUP(&cur_irq->irq_queue);
33576 handled = 1;
33577 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
33578@@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
33579 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
33580 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
33581 masks[irq][4]));
33582- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
33583+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
33584 } else {
33585 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
33586 (((cur_irq_sequence =
33587- atomic_read(&cur_irq->irq_received)) -
33588+ atomic_read_unchecked(&cur_irq->irq_received)) -
33589 *sequence) <= (1 << 23)));
33590 }
33591 *sequence = cur_irq_sequence;
33592@@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
33593 }
33594
33595 for (i = 0; i < dev_priv->num_irqs; ++i) {
33596- atomic_set(&cur_irq->irq_received, 0);
33597+ atomic_set_unchecked(&cur_irq->irq_received, 0);
33598 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
33599 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
33600 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
33601@@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
33602 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
33603 case VIA_IRQ_RELATIVE:
33604 irqwait->request.sequence +=
33605- atomic_read(&cur_irq->irq_received);
33606+ atomic_read_unchecked(&cur_irq->irq_received);
33607 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
33608 case VIA_IRQ_ABSOLUTE:
33609 break;
33610diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
33611index 88a179e..57fe50481c 100644
33612--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
33613+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
33614@@ -263,7 +263,7 @@ struct vmw_private {
33615 * Fencing and IRQs.
33616 */
33617
33618- atomic_t marker_seq;
33619+ atomic_unchecked_t marker_seq;
33620 wait_queue_head_t fence_queue;
33621 wait_queue_head_t fifo_queue;
33622 int fence_queue_waiters; /* Protected by hw_mutex */
33623diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
33624index 3eb1486..0a47ee9 100644
33625--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
33626+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
33627@@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
33628 (unsigned int) min,
33629 (unsigned int) fifo->capabilities);
33630
33631- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
33632+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
33633 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
33634 vmw_marker_queue_init(&fifo->marker_queue);
33635 return vmw_fifo_send_fence(dev_priv, &dummy);
33636@@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
33637 if (reserveable)
33638 iowrite32(bytes, fifo_mem +
33639 SVGA_FIFO_RESERVED);
33640- return fifo_mem + (next_cmd >> 2);
33641+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
33642 } else {
33643 need_bounce = true;
33644 }
33645@@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
33646
33647 fm = vmw_fifo_reserve(dev_priv, bytes);
33648 if (unlikely(fm == NULL)) {
33649- *seqno = atomic_read(&dev_priv->marker_seq);
33650+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
33651 ret = -ENOMEM;
33652 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
33653 false, 3*HZ);
33654@@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
33655 }
33656
33657 do {
33658- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
33659+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
33660 } while (*seqno == 0);
33661
33662 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
33663diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
33664index 4640adb..e1384ed 100644
33665--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
33666+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
33667@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
33668 * emitted. Then the fence is stale and signaled.
33669 */
33670
33671- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
33672+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
33673 > VMW_FENCE_WRAP);
33674
33675 return ret;
33676@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
33677
33678 if (fifo_idle)
33679 down_read(&fifo_state->rwsem);
33680- signal_seq = atomic_read(&dev_priv->marker_seq);
33681+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
33682 ret = 0;
33683
33684 for (;;) {
33685diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
33686index 8a8725c..afed796 100644
33687--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
33688+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
33689@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
33690 while (!vmw_lag_lt(queue, us)) {
33691 spin_lock(&queue->lock);
33692 if (list_empty(&queue->head))
33693- seqno = atomic_read(&dev_priv->marker_seq);
33694+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
33695 else {
33696 marker = list_first_entry(&queue->head,
33697 struct vmw_marker, head);
33698diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
33699index 52146db..ae33762 100644
33700--- a/drivers/hid/hid-core.c
33701+++ b/drivers/hid/hid-core.c
33702@@ -2201,7 +2201,7 @@ static bool hid_ignore(struct hid_device *hdev)
33703
33704 int hid_add_device(struct hid_device *hdev)
33705 {
33706- static atomic_t id = ATOMIC_INIT(0);
33707+ static atomic_unchecked_t id = ATOMIC_INIT(0);
33708 int ret;
33709
33710 if (WARN_ON(hdev->status & HID_STAT_ADDED))
33711@@ -2236,7 +2236,7 @@ int hid_add_device(struct hid_device *hdev)
33712 /* XXX hack, any other cleaner solution after the driver core
33713 * is converted to allow more than 20 bytes as the device name? */
33714 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
33715- hdev->vendor, hdev->product, atomic_inc_return(&id));
33716+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
33717
33718 hid_debug_register(hdev, dev_name(&hdev->dev));
33719 ret = device_add(&hdev->dev);
33720diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
33721index eec3291..8ed706b 100644
33722--- a/drivers/hid/hid-wiimote-debug.c
33723+++ b/drivers/hid/hid-wiimote-debug.c
33724@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
33725 else if (size == 0)
33726 return -EIO;
33727
33728- if (copy_to_user(u, buf, size))
33729+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
33730 return -EFAULT;
33731
33732 *off += size;
33733diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
33734index 14599e2..711c965 100644
33735--- a/drivers/hid/usbhid/hiddev.c
33736+++ b/drivers/hid/usbhid/hiddev.c
33737@@ -625,7 +625,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
33738 break;
33739
33740 case HIDIOCAPPLICATION:
33741- if (arg < 0 || arg >= hid->maxapplication)
33742+ if (arg >= hid->maxapplication)
33743 break;
33744
33745 for (i = 0; i < hid->maxcollection; i++)
33746diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
33747index f4c3d28..82f45a9 100644
33748--- a/drivers/hv/channel.c
33749+++ b/drivers/hv/channel.c
33750@@ -402,8 +402,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
33751 int ret = 0;
33752 int t;
33753
33754- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
33755- atomic_inc(&vmbus_connection.next_gpadl_handle);
33756+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
33757+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
33758
33759 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
33760 if (ret)
33761diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
33762index 3648f8f..30ef30d 100644
33763--- a/drivers/hv/hv.c
33764+++ b/drivers/hv/hv.c
33765@@ -111,7 +111,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
33766 u64 output_address = (output) ? virt_to_phys(output) : 0;
33767 u32 output_address_hi = output_address >> 32;
33768 u32 output_address_lo = output_address & 0xFFFFFFFF;
33769- void *hypercall_page = hv_context.hypercall_page;
33770+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
33771
33772 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
33773 "=a"(hv_status_lo) : "d" (control_hi),
33774diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
33775index d8d1fad..b91caf7 100644
33776--- a/drivers/hv/hyperv_vmbus.h
33777+++ b/drivers/hv/hyperv_vmbus.h
33778@@ -594,7 +594,7 @@ enum vmbus_connect_state {
33779 struct vmbus_connection {
33780 enum vmbus_connect_state conn_state;
33781
33782- atomic_t next_gpadl_handle;
33783+ atomic_unchecked_t next_gpadl_handle;
33784
33785 /*
33786 * Represents channel interrupts. Each bit position represents a
33787diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
33788index 8e1a9ec..4687821 100644
33789--- a/drivers/hv/vmbus_drv.c
33790+++ b/drivers/hv/vmbus_drv.c
33791@@ -629,10 +629,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
33792 {
33793 int ret = 0;
33794
33795- static atomic_t device_num = ATOMIC_INIT(0);
33796+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
33797
33798 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
33799- atomic_inc_return(&device_num));
33800+ atomic_inc_return_unchecked(&device_num));
33801
33802 child_device_obj->device.bus = &hv_bus;
33803 child_device_obj->device.parent = &hv_acpi_dev->dev;
33804diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
33805index 07a0c1a..0cac334 100644
33806--- a/drivers/hwmon/sht15.c
33807+++ b/drivers/hwmon/sht15.c
33808@@ -169,7 +169,7 @@ struct sht15_data {
33809 int supply_uV;
33810 bool supply_uV_valid;
33811 struct work_struct update_supply_work;
33812- atomic_t interrupt_handled;
33813+ atomic_unchecked_t interrupt_handled;
33814 };
33815
33816 /**
33817@@ -512,13 +512,13 @@ static int sht15_measurement(struct sht15_data *data,
33818 return ret;
33819
33820 gpio_direction_input(data->pdata->gpio_data);
33821- atomic_set(&data->interrupt_handled, 0);
33822+ atomic_set_unchecked(&data->interrupt_handled, 0);
33823
33824 enable_irq(gpio_to_irq(data->pdata->gpio_data));
33825 if (gpio_get_value(data->pdata->gpio_data) == 0) {
33826 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
33827 /* Only relevant if the interrupt hasn't occurred. */
33828- if (!atomic_read(&data->interrupt_handled))
33829+ if (!atomic_read_unchecked(&data->interrupt_handled))
33830 schedule_work(&data->read_work);
33831 }
33832 ret = wait_event_timeout(data->wait_queue,
33833@@ -785,7 +785,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
33834
33835 /* First disable the interrupt */
33836 disable_irq_nosync(irq);
33837- atomic_inc(&data->interrupt_handled);
33838+ atomic_inc_unchecked(&data->interrupt_handled);
33839 /* Then schedule a reading work struct */
33840 if (data->state != SHT15_READING_NOTHING)
33841 schedule_work(&data->read_work);
33842@@ -807,11 +807,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
33843 * If not, then start the interrupt again - care here as could
33844 * have gone low in meantime so verify it hasn't!
33845 */
33846- atomic_set(&data->interrupt_handled, 0);
33847+ atomic_set_unchecked(&data->interrupt_handled, 0);
33848 enable_irq(gpio_to_irq(data->pdata->gpio_data));
33849 /* If still not occurred or another handler was scheduled */
33850 if (gpio_get_value(data->pdata->gpio_data)
33851- || atomic_read(&data->interrupt_handled))
33852+ || atomic_read_unchecked(&data->interrupt_handled))
33853 return;
33854 }
33855
33856diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
33857index 378fcb5..5e91fa8 100644
33858--- a/drivers/i2c/busses/i2c-amd756-s4882.c
33859+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
33860@@ -43,7 +43,7 @@
33861 extern struct i2c_adapter amd756_smbus;
33862
33863 static struct i2c_adapter *s4882_adapter;
33864-static struct i2c_algorithm *s4882_algo;
33865+static i2c_algorithm_no_const *s4882_algo;
33866
33867 /* Wrapper access functions for multiplexed SMBus */
33868 static DEFINE_MUTEX(amd756_lock);
33869diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
33870index 29015eb..af2d8e9 100644
33871--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
33872+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
33873@@ -41,7 +41,7 @@
33874 extern struct i2c_adapter *nforce2_smbus;
33875
33876 static struct i2c_adapter *s4985_adapter;
33877-static struct i2c_algorithm *s4985_algo;
33878+static i2c_algorithm_no_const *s4985_algo;
33879
33880 /* Wrapper access functions for multiplexed SMBus */
33881 static DEFINE_MUTEX(nforce2_lock);
33882diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
33883index 8126824..55a2798 100644
33884--- a/drivers/ide/ide-cd.c
33885+++ b/drivers/ide/ide-cd.c
33886@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
33887 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
33888 if ((unsigned long)buf & alignment
33889 || blk_rq_bytes(rq) & q->dma_pad_mask
33890- || object_is_on_stack(buf))
33891+ || object_starts_on_stack(buf))
33892 drive->dma = 0;
33893 }
33894 }
33895diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
33896index 394fea2..c833880 100644
33897--- a/drivers/infiniband/core/cm.c
33898+++ b/drivers/infiniband/core/cm.c
33899@@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
33900
33901 struct cm_counter_group {
33902 struct kobject obj;
33903- atomic_long_t counter[CM_ATTR_COUNT];
33904+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
33905 };
33906
33907 struct cm_counter_attribute {
33908@@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
33909 struct ib_mad_send_buf *msg = NULL;
33910 int ret;
33911
33912- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33913+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33914 counter[CM_REQ_COUNTER]);
33915
33916 /* Quick state check to discard duplicate REQs. */
33917@@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
33918 if (!cm_id_priv)
33919 return;
33920
33921- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33922+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33923 counter[CM_REP_COUNTER]);
33924 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
33925 if (ret)
33926@@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
33927 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
33928 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
33929 spin_unlock_irq(&cm_id_priv->lock);
33930- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33931+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33932 counter[CM_RTU_COUNTER]);
33933 goto out;
33934 }
33935@@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
33936 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
33937 dreq_msg->local_comm_id);
33938 if (!cm_id_priv) {
33939- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33940+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33941 counter[CM_DREQ_COUNTER]);
33942 cm_issue_drep(work->port, work->mad_recv_wc);
33943 return -EINVAL;
33944@@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
33945 case IB_CM_MRA_REP_RCVD:
33946 break;
33947 case IB_CM_TIMEWAIT:
33948- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33949+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33950 counter[CM_DREQ_COUNTER]);
33951 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
33952 goto unlock;
33953@@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
33954 cm_free_msg(msg);
33955 goto deref;
33956 case IB_CM_DREQ_RCVD:
33957- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33958+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33959 counter[CM_DREQ_COUNTER]);
33960 goto unlock;
33961 default:
33962@@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
33963 ib_modify_mad(cm_id_priv->av.port->mad_agent,
33964 cm_id_priv->msg, timeout)) {
33965 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
33966- atomic_long_inc(&work->port->
33967+ atomic_long_inc_unchecked(&work->port->
33968 counter_group[CM_RECV_DUPLICATES].
33969 counter[CM_MRA_COUNTER]);
33970 goto out;
33971@@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
33972 break;
33973 case IB_CM_MRA_REQ_RCVD:
33974 case IB_CM_MRA_REP_RCVD:
33975- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33976+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33977 counter[CM_MRA_COUNTER]);
33978 /* fall through */
33979 default:
33980@@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
33981 case IB_CM_LAP_IDLE:
33982 break;
33983 case IB_CM_MRA_LAP_SENT:
33984- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33985+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33986 counter[CM_LAP_COUNTER]);
33987 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
33988 goto unlock;
33989@@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
33990 cm_free_msg(msg);
33991 goto deref;
33992 case IB_CM_LAP_RCVD:
33993- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33994+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33995 counter[CM_LAP_COUNTER]);
33996 goto unlock;
33997 default:
33998@@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
33999 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
34000 if (cur_cm_id_priv) {
34001 spin_unlock_irq(&cm.lock);
34002- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34003+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34004 counter[CM_SIDR_REQ_COUNTER]);
34005 goto out; /* Duplicate message. */
34006 }
34007@@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
34008 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
34009 msg->retries = 1;
34010
34011- atomic_long_add(1 + msg->retries,
34012+ atomic_long_add_unchecked(1 + msg->retries,
34013 &port->counter_group[CM_XMIT].counter[attr_index]);
34014 if (msg->retries)
34015- atomic_long_add(msg->retries,
34016+ atomic_long_add_unchecked(msg->retries,
34017 &port->counter_group[CM_XMIT_RETRIES].
34018 counter[attr_index]);
34019
34020@@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
34021 }
34022
34023 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
34024- atomic_long_inc(&port->counter_group[CM_RECV].
34025+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
34026 counter[attr_id - CM_ATTR_ID_OFFSET]);
34027
34028 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
34029@@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
34030 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
34031
34032 return sprintf(buf, "%ld\n",
34033- atomic_long_read(&group->counter[cm_attr->index]));
34034+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
34035 }
34036
34037 static const struct sysfs_ops cm_counter_ops = {
34038diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
34039index 176c8f9..2627b62 100644
34040--- a/drivers/infiniband/core/fmr_pool.c
34041+++ b/drivers/infiniband/core/fmr_pool.c
34042@@ -98,8 +98,8 @@ struct ib_fmr_pool {
34043
34044 struct task_struct *thread;
34045
34046- atomic_t req_ser;
34047- atomic_t flush_ser;
34048+ atomic_unchecked_t req_ser;
34049+ atomic_unchecked_t flush_ser;
34050
34051 wait_queue_head_t force_wait;
34052 };
34053@@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
34054 struct ib_fmr_pool *pool = pool_ptr;
34055
34056 do {
34057- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
34058+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
34059 ib_fmr_batch_release(pool);
34060
34061- atomic_inc(&pool->flush_ser);
34062+ atomic_inc_unchecked(&pool->flush_ser);
34063 wake_up_interruptible(&pool->force_wait);
34064
34065 if (pool->flush_function)
34066@@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
34067 }
34068
34069 set_current_state(TASK_INTERRUPTIBLE);
34070- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
34071+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
34072 !kthread_should_stop())
34073 schedule();
34074 __set_current_state(TASK_RUNNING);
34075@@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
34076 pool->dirty_watermark = params->dirty_watermark;
34077 pool->dirty_len = 0;
34078 spin_lock_init(&pool->pool_lock);
34079- atomic_set(&pool->req_ser, 0);
34080- atomic_set(&pool->flush_ser, 0);
34081+ atomic_set_unchecked(&pool->req_ser, 0);
34082+ atomic_set_unchecked(&pool->flush_ser, 0);
34083 init_waitqueue_head(&pool->force_wait);
34084
34085 pool->thread = kthread_run(ib_fmr_cleanup_thread,
34086@@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
34087 }
34088 spin_unlock_irq(&pool->pool_lock);
34089
34090- serial = atomic_inc_return(&pool->req_ser);
34091+ serial = atomic_inc_return_unchecked(&pool->req_ser);
34092 wake_up_process(pool->thread);
34093
34094 if (wait_event_interruptible(pool->force_wait,
34095- atomic_read(&pool->flush_ser) - serial >= 0))
34096+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
34097 return -EINTR;
34098
34099 return 0;
34100@@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
34101 } else {
34102 list_add_tail(&fmr->list, &pool->dirty_list);
34103 if (++pool->dirty_len >= pool->dirty_watermark) {
34104- atomic_inc(&pool->req_ser);
34105+ atomic_inc_unchecked(&pool->req_ser);
34106 wake_up_process(pool->thread);
34107 }
34108 }
34109diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
34110index afd8179..598063f 100644
34111--- a/drivers/infiniband/hw/cxgb4/mem.c
34112+++ b/drivers/infiniband/hw/cxgb4/mem.c
34113@@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
34114 int err;
34115 struct fw_ri_tpte tpt;
34116 u32 stag_idx;
34117- static atomic_t key;
34118+ static atomic_unchecked_t key;
34119
34120 if (c4iw_fatal_error(rdev))
34121 return -EIO;
34122@@ -139,7 +139,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
34123 if (rdev->stats.stag.cur > rdev->stats.stag.max)
34124 rdev->stats.stag.max = rdev->stats.stag.cur;
34125 mutex_unlock(&rdev->stats.lock);
34126- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
34127+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
34128 }
34129 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
34130 __func__, stag_state, type, pdid, stag_idx);
34131diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
34132index 79b3dbc..96e5fcc 100644
34133--- a/drivers/infiniband/hw/ipath/ipath_rc.c
34134+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
34135@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
34136 struct ib_atomic_eth *ateth;
34137 struct ipath_ack_entry *e;
34138 u64 vaddr;
34139- atomic64_t *maddr;
34140+ atomic64_unchecked_t *maddr;
34141 u64 sdata;
34142 u32 rkey;
34143 u8 next;
34144@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
34145 IB_ACCESS_REMOTE_ATOMIC)))
34146 goto nack_acc_unlck;
34147 /* Perform atomic OP and save result. */
34148- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
34149+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
34150 sdata = be64_to_cpu(ateth->swap_data);
34151 e = &qp->s_ack_queue[qp->r_head_ack_queue];
34152 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
34153- (u64) atomic64_add_return(sdata, maddr) - sdata :
34154+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
34155 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
34156 be64_to_cpu(ateth->compare_data),
34157 sdata);
34158diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
34159index 1f95bba..9530f87 100644
34160--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
34161+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
34162@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
34163 unsigned long flags;
34164 struct ib_wc wc;
34165 u64 sdata;
34166- atomic64_t *maddr;
34167+ atomic64_unchecked_t *maddr;
34168 enum ib_wc_status send_status;
34169
34170 /*
34171@@ -382,11 +382,11 @@ again:
34172 IB_ACCESS_REMOTE_ATOMIC)))
34173 goto acc_err;
34174 /* Perform atomic OP and save result. */
34175- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
34176+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
34177 sdata = wqe->wr.wr.atomic.compare_add;
34178 *(u64 *) sqp->s_sge.sge.vaddr =
34179 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
34180- (u64) atomic64_add_return(sdata, maddr) - sdata :
34181+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
34182 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
34183 sdata, wqe->wr.wr.atomic.swap);
34184 goto send_comp;
34185diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
34186index 748db2d..5f75cc3 100644
34187--- a/drivers/infiniband/hw/nes/nes.c
34188+++ b/drivers/infiniband/hw/nes/nes.c
34189@@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
34190 LIST_HEAD(nes_adapter_list);
34191 static LIST_HEAD(nes_dev_list);
34192
34193-atomic_t qps_destroyed;
34194+atomic_unchecked_t qps_destroyed;
34195
34196 static unsigned int ee_flsh_adapter;
34197 static unsigned int sysfs_nonidx_addr;
34198@@ -267,7 +267,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
34199 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
34200 struct nes_adapter *nesadapter = nesdev->nesadapter;
34201
34202- atomic_inc(&qps_destroyed);
34203+ atomic_inc_unchecked(&qps_destroyed);
34204
34205 /* Free the control structures */
34206
34207diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
34208index 33cc589..3bd6538 100644
34209--- a/drivers/infiniband/hw/nes/nes.h
34210+++ b/drivers/infiniband/hw/nes/nes.h
34211@@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
34212 extern unsigned int wqm_quanta;
34213 extern struct list_head nes_adapter_list;
34214
34215-extern atomic_t cm_connects;
34216-extern atomic_t cm_accepts;
34217-extern atomic_t cm_disconnects;
34218-extern atomic_t cm_closes;
34219-extern atomic_t cm_connecteds;
34220-extern atomic_t cm_connect_reqs;
34221-extern atomic_t cm_rejects;
34222-extern atomic_t mod_qp_timouts;
34223-extern atomic_t qps_created;
34224-extern atomic_t qps_destroyed;
34225-extern atomic_t sw_qps_destroyed;
34226+extern atomic_unchecked_t cm_connects;
34227+extern atomic_unchecked_t cm_accepts;
34228+extern atomic_unchecked_t cm_disconnects;
34229+extern atomic_unchecked_t cm_closes;
34230+extern atomic_unchecked_t cm_connecteds;
34231+extern atomic_unchecked_t cm_connect_reqs;
34232+extern atomic_unchecked_t cm_rejects;
34233+extern atomic_unchecked_t mod_qp_timouts;
34234+extern atomic_unchecked_t qps_created;
34235+extern atomic_unchecked_t qps_destroyed;
34236+extern atomic_unchecked_t sw_qps_destroyed;
34237 extern u32 mh_detected;
34238 extern u32 mh_pauses_sent;
34239 extern u32 cm_packets_sent;
34240@@ -196,16 +196,16 @@ extern u32 cm_packets_created;
34241 extern u32 cm_packets_received;
34242 extern u32 cm_packets_dropped;
34243 extern u32 cm_packets_retrans;
34244-extern atomic_t cm_listens_created;
34245-extern atomic_t cm_listens_destroyed;
34246+extern atomic_unchecked_t cm_listens_created;
34247+extern atomic_unchecked_t cm_listens_destroyed;
34248 extern u32 cm_backlog_drops;
34249-extern atomic_t cm_loopbacks;
34250-extern atomic_t cm_nodes_created;
34251-extern atomic_t cm_nodes_destroyed;
34252-extern atomic_t cm_accel_dropped_pkts;
34253-extern atomic_t cm_resets_recvd;
34254-extern atomic_t pau_qps_created;
34255-extern atomic_t pau_qps_destroyed;
34256+extern atomic_unchecked_t cm_loopbacks;
34257+extern atomic_unchecked_t cm_nodes_created;
34258+extern atomic_unchecked_t cm_nodes_destroyed;
34259+extern atomic_unchecked_t cm_accel_dropped_pkts;
34260+extern atomic_unchecked_t cm_resets_recvd;
34261+extern atomic_unchecked_t pau_qps_created;
34262+extern atomic_unchecked_t pau_qps_destroyed;
34263
34264 extern u32 int_mod_timer_init;
34265 extern u32 int_mod_cq_depth_256;
34266diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
34267index cfaacaf..fa0722e 100644
34268--- a/drivers/infiniband/hw/nes/nes_cm.c
34269+++ b/drivers/infiniband/hw/nes/nes_cm.c
34270@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
34271 u32 cm_packets_retrans;
34272 u32 cm_packets_created;
34273 u32 cm_packets_received;
34274-atomic_t cm_listens_created;
34275-atomic_t cm_listens_destroyed;
34276+atomic_unchecked_t cm_listens_created;
34277+atomic_unchecked_t cm_listens_destroyed;
34278 u32 cm_backlog_drops;
34279-atomic_t cm_loopbacks;
34280-atomic_t cm_nodes_created;
34281-atomic_t cm_nodes_destroyed;
34282-atomic_t cm_accel_dropped_pkts;
34283-atomic_t cm_resets_recvd;
34284+atomic_unchecked_t cm_loopbacks;
34285+atomic_unchecked_t cm_nodes_created;
34286+atomic_unchecked_t cm_nodes_destroyed;
34287+atomic_unchecked_t cm_accel_dropped_pkts;
34288+atomic_unchecked_t cm_resets_recvd;
34289
34290 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
34291 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
34292@@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
34293
34294 static struct nes_cm_core *g_cm_core;
34295
34296-atomic_t cm_connects;
34297-atomic_t cm_accepts;
34298-atomic_t cm_disconnects;
34299-atomic_t cm_closes;
34300-atomic_t cm_connecteds;
34301-atomic_t cm_connect_reqs;
34302-atomic_t cm_rejects;
34303+atomic_unchecked_t cm_connects;
34304+atomic_unchecked_t cm_accepts;
34305+atomic_unchecked_t cm_disconnects;
34306+atomic_unchecked_t cm_closes;
34307+atomic_unchecked_t cm_connecteds;
34308+atomic_unchecked_t cm_connect_reqs;
34309+atomic_unchecked_t cm_rejects;
34310
34311 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
34312 {
34313@@ -1281,7 +1281,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
34314 kfree(listener);
34315 listener = NULL;
34316 ret = 0;
34317- atomic_inc(&cm_listens_destroyed);
34318+ atomic_inc_unchecked(&cm_listens_destroyed);
34319 } else {
34320 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
34321 }
34322@@ -1480,7 +1480,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
34323 cm_node->rem_mac);
34324
34325 add_hte_node(cm_core, cm_node);
34326- atomic_inc(&cm_nodes_created);
34327+ atomic_inc_unchecked(&cm_nodes_created);
34328
34329 return cm_node;
34330 }
34331@@ -1538,7 +1538,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
34332 }
34333
34334 atomic_dec(&cm_core->node_cnt);
34335- atomic_inc(&cm_nodes_destroyed);
34336+ atomic_inc_unchecked(&cm_nodes_destroyed);
34337 nesqp = cm_node->nesqp;
34338 if (nesqp) {
34339 nesqp->cm_node = NULL;
34340@@ -1602,7 +1602,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
34341
34342 static void drop_packet(struct sk_buff *skb)
34343 {
34344- atomic_inc(&cm_accel_dropped_pkts);
34345+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
34346 dev_kfree_skb_any(skb);
34347 }
34348
34349@@ -1665,7 +1665,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
34350 {
34351
34352 int reset = 0; /* whether to send reset in case of err.. */
34353- atomic_inc(&cm_resets_recvd);
34354+ atomic_inc_unchecked(&cm_resets_recvd);
34355 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
34356 " refcnt=%d\n", cm_node, cm_node->state,
34357 atomic_read(&cm_node->ref_count));
34358@@ -2306,7 +2306,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
34359 rem_ref_cm_node(cm_node->cm_core, cm_node);
34360 return NULL;
34361 }
34362- atomic_inc(&cm_loopbacks);
34363+ atomic_inc_unchecked(&cm_loopbacks);
34364 loopbackremotenode->loopbackpartner = cm_node;
34365 loopbackremotenode->tcp_cntxt.rcv_wscale =
34366 NES_CM_DEFAULT_RCV_WND_SCALE;
34367@@ -2581,7 +2581,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
34368 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
34369 else {
34370 rem_ref_cm_node(cm_core, cm_node);
34371- atomic_inc(&cm_accel_dropped_pkts);
34372+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
34373 dev_kfree_skb_any(skb);
34374 }
34375 break;
34376@@ -2889,7 +2889,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
34377
34378 if ((cm_id) && (cm_id->event_handler)) {
34379 if (issue_disconn) {
34380- atomic_inc(&cm_disconnects);
34381+ atomic_inc_unchecked(&cm_disconnects);
34382 cm_event.event = IW_CM_EVENT_DISCONNECT;
34383 cm_event.status = disconn_status;
34384 cm_event.local_addr = cm_id->local_addr;
34385@@ -2911,7 +2911,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
34386 }
34387
34388 if (issue_close) {
34389- atomic_inc(&cm_closes);
34390+ atomic_inc_unchecked(&cm_closes);
34391 nes_disconnect(nesqp, 1);
34392
34393 cm_id->provider_data = nesqp;
34394@@ -3047,7 +3047,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
34395
34396 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
34397 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
34398- atomic_inc(&cm_accepts);
34399+ atomic_inc_unchecked(&cm_accepts);
34400
34401 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
34402 netdev_refcnt_read(nesvnic->netdev));
34403@@ -3242,7 +3242,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
34404 struct nes_cm_core *cm_core;
34405 u8 *start_buff;
34406
34407- atomic_inc(&cm_rejects);
34408+ atomic_inc_unchecked(&cm_rejects);
34409 cm_node = (struct nes_cm_node *)cm_id->provider_data;
34410 loopback = cm_node->loopbackpartner;
34411 cm_core = cm_node->cm_core;
34412@@ -3302,7 +3302,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
34413 ntohl(cm_id->local_addr.sin_addr.s_addr),
34414 ntohs(cm_id->local_addr.sin_port));
34415
34416- atomic_inc(&cm_connects);
34417+ atomic_inc_unchecked(&cm_connects);
34418 nesqp->active_conn = 1;
34419
34420 /* cache the cm_id in the qp */
34421@@ -3412,7 +3412,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
34422 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
34423 return err;
34424 }
34425- atomic_inc(&cm_listens_created);
34426+ atomic_inc_unchecked(&cm_listens_created);
34427 }
34428
34429 cm_id->add_ref(cm_id);
34430@@ -3513,7 +3513,7 @@ static void cm_event_connected(struct nes_cm_event *event)
34431
34432 if (nesqp->destroyed)
34433 return;
34434- atomic_inc(&cm_connecteds);
34435+ atomic_inc_unchecked(&cm_connecteds);
34436 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
34437 " local port 0x%04X. jiffies = %lu.\n",
34438 nesqp->hwqp.qp_id,
34439@@ -3693,7 +3693,7 @@ static void cm_event_reset(struct nes_cm_event *event)
34440
34441 cm_id->add_ref(cm_id);
34442 ret = cm_id->event_handler(cm_id, &cm_event);
34443- atomic_inc(&cm_closes);
34444+ atomic_inc_unchecked(&cm_closes);
34445 cm_event.event = IW_CM_EVENT_CLOSE;
34446 cm_event.status = 0;
34447 cm_event.provider_data = cm_id->provider_data;
34448@@ -3729,7 +3729,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
34449 return;
34450 cm_id = cm_node->cm_id;
34451
34452- atomic_inc(&cm_connect_reqs);
34453+ atomic_inc_unchecked(&cm_connect_reqs);
34454 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
34455 cm_node, cm_id, jiffies);
34456
34457@@ -3769,7 +3769,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
34458 return;
34459 cm_id = cm_node->cm_id;
34460
34461- atomic_inc(&cm_connect_reqs);
34462+ atomic_inc_unchecked(&cm_connect_reqs);
34463 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
34464 cm_node, cm_id, jiffies);
34465
34466diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
34467index 3ba7be3..c81f6ff 100644
34468--- a/drivers/infiniband/hw/nes/nes_mgt.c
34469+++ b/drivers/infiniband/hw/nes/nes_mgt.c
34470@@ -40,8 +40,8 @@
34471 #include "nes.h"
34472 #include "nes_mgt.h"
34473
34474-atomic_t pau_qps_created;
34475-atomic_t pau_qps_destroyed;
34476+atomic_unchecked_t pau_qps_created;
34477+atomic_unchecked_t pau_qps_destroyed;
34478
34479 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
34480 {
34481@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
34482 {
34483 struct sk_buff *skb;
34484 unsigned long flags;
34485- atomic_inc(&pau_qps_destroyed);
34486+ atomic_inc_unchecked(&pau_qps_destroyed);
34487
34488 /* Free packets that have not yet been forwarded */
34489 /* Lock is acquired by skb_dequeue when removing the skb */
34490@@ -812,7 +812,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
34491 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
34492 skb_queue_head_init(&nesqp->pau_list);
34493 spin_lock_init(&nesqp->pau_lock);
34494- atomic_inc(&pau_qps_created);
34495+ atomic_inc_unchecked(&pau_qps_created);
34496 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
34497 }
34498
34499diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
34500index 0564be7..f68b0f1 100644
34501--- a/drivers/infiniband/hw/nes/nes_nic.c
34502+++ b/drivers/infiniband/hw/nes/nes_nic.c
34503@@ -1272,39 +1272,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
34504 target_stat_values[++index] = mh_detected;
34505 target_stat_values[++index] = mh_pauses_sent;
34506 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
34507- target_stat_values[++index] = atomic_read(&cm_connects);
34508- target_stat_values[++index] = atomic_read(&cm_accepts);
34509- target_stat_values[++index] = atomic_read(&cm_disconnects);
34510- target_stat_values[++index] = atomic_read(&cm_connecteds);
34511- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
34512- target_stat_values[++index] = atomic_read(&cm_rejects);
34513- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
34514- target_stat_values[++index] = atomic_read(&qps_created);
34515- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
34516- target_stat_values[++index] = atomic_read(&qps_destroyed);
34517- target_stat_values[++index] = atomic_read(&cm_closes);
34518+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
34519+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
34520+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
34521+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
34522+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
34523+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
34524+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
34525+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
34526+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
34527+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
34528+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
34529 target_stat_values[++index] = cm_packets_sent;
34530 target_stat_values[++index] = cm_packets_bounced;
34531 target_stat_values[++index] = cm_packets_created;
34532 target_stat_values[++index] = cm_packets_received;
34533 target_stat_values[++index] = cm_packets_dropped;
34534 target_stat_values[++index] = cm_packets_retrans;
34535- target_stat_values[++index] = atomic_read(&cm_listens_created);
34536- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
34537+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
34538+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
34539 target_stat_values[++index] = cm_backlog_drops;
34540- target_stat_values[++index] = atomic_read(&cm_loopbacks);
34541- target_stat_values[++index] = atomic_read(&cm_nodes_created);
34542- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
34543- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
34544- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
34545+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
34546+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
34547+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
34548+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
34549+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
34550 target_stat_values[++index] = nesadapter->free_4kpbl;
34551 target_stat_values[++index] = nesadapter->free_256pbl;
34552 target_stat_values[++index] = int_mod_timer_init;
34553 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
34554 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
34555 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
34556- target_stat_values[++index] = atomic_read(&pau_qps_created);
34557- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
34558+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
34559+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
34560 }
34561
34562 /**
34563diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
34564index 07e4fba..685f041 100644
34565--- a/drivers/infiniband/hw/nes/nes_verbs.c
34566+++ b/drivers/infiniband/hw/nes/nes_verbs.c
34567@@ -46,9 +46,9 @@
34568
34569 #include <rdma/ib_umem.h>
34570
34571-atomic_t mod_qp_timouts;
34572-atomic_t qps_created;
34573-atomic_t sw_qps_destroyed;
34574+atomic_unchecked_t mod_qp_timouts;
34575+atomic_unchecked_t qps_created;
34576+atomic_unchecked_t sw_qps_destroyed;
34577
34578 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
34579
34580@@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
34581 if (init_attr->create_flags)
34582 return ERR_PTR(-EINVAL);
34583
34584- atomic_inc(&qps_created);
34585+ atomic_inc_unchecked(&qps_created);
34586 switch (init_attr->qp_type) {
34587 case IB_QPT_RC:
34588 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
34589@@ -1462,7 +1462,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
34590 struct iw_cm_event cm_event;
34591 int ret = 0;
34592
34593- atomic_inc(&sw_qps_destroyed);
34594+ atomic_inc_unchecked(&sw_qps_destroyed);
34595 nesqp->destroyed = 1;
34596
34597 /* Blow away the connection if it exists. */
34598diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
34599index 4d11575..3e890e5 100644
34600--- a/drivers/infiniband/hw/qib/qib.h
34601+++ b/drivers/infiniband/hw/qib/qib.h
34602@@ -51,6 +51,7 @@
34603 #include <linux/completion.h>
34604 #include <linux/kref.h>
34605 #include <linux/sched.h>
34606+#include <linux/slab.h>
34607
34608 #include "qib_common.h"
34609 #include "qib_verbs.h"
34610diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
34611index da739d9..da1c7f4 100644
34612--- a/drivers/input/gameport/gameport.c
34613+++ b/drivers/input/gameport/gameport.c
34614@@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
34615 */
34616 static void gameport_init_port(struct gameport *gameport)
34617 {
34618- static atomic_t gameport_no = ATOMIC_INIT(0);
34619+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
34620
34621 __module_get(THIS_MODULE);
34622
34623 mutex_init(&gameport->drv_mutex);
34624 device_initialize(&gameport->dev);
34625 dev_set_name(&gameport->dev, "gameport%lu",
34626- (unsigned long)atomic_inc_return(&gameport_no) - 1);
34627+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
34628 gameport->dev.bus = &gameport_bus;
34629 gameport->dev.release = gameport_release_port;
34630 if (gameport->parent)
34631diff --git a/drivers/input/input.c b/drivers/input/input.c
34632index 53a0dde..abffda7 100644
34633--- a/drivers/input/input.c
34634+++ b/drivers/input/input.c
34635@@ -1902,7 +1902,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
34636 */
34637 int input_register_device(struct input_dev *dev)
34638 {
34639- static atomic_t input_no = ATOMIC_INIT(0);
34640+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
34641 struct input_handler *handler;
34642 unsigned int packet_size;
34643 const char *path;
34644@@ -1945,7 +1945,7 @@ int input_register_device(struct input_dev *dev)
34645 dev->setkeycode = input_default_setkeycode;
34646
34647 dev_set_name(&dev->dev, "input%ld",
34648- (unsigned long) atomic_inc_return(&input_no) - 1);
34649+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
34650
34651 error = device_add(&dev->dev);
34652 if (error)
34653diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
34654index 04c69af..5f92d00 100644
34655--- a/drivers/input/joystick/sidewinder.c
34656+++ b/drivers/input/joystick/sidewinder.c
34657@@ -30,6 +30,7 @@
34658 #include <linux/kernel.h>
34659 #include <linux/module.h>
34660 #include <linux/slab.h>
34661+#include <linux/sched.h>
34662 #include <linux/init.h>
34663 #include <linux/input.h>
34664 #include <linux/gameport.h>
34665diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
34666index 83811e4..0822b90 100644
34667--- a/drivers/input/joystick/xpad.c
34668+++ b/drivers/input/joystick/xpad.c
34669@@ -726,7 +726,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
34670
34671 static int xpad_led_probe(struct usb_xpad *xpad)
34672 {
34673- static atomic_t led_seq = ATOMIC_INIT(0);
34674+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
34675 long led_no;
34676 struct xpad_led *led;
34677 struct led_classdev *led_cdev;
34678@@ -739,7 +739,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
34679 if (!led)
34680 return -ENOMEM;
34681
34682- led_no = (long)atomic_inc_return(&led_seq) - 1;
34683+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
34684
34685 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
34686 led->xpad = xpad;
34687diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
34688index 4c842c3..590b0bf 100644
34689--- a/drivers/input/mousedev.c
34690+++ b/drivers/input/mousedev.c
34691@@ -738,7 +738,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
34692
34693 spin_unlock_irq(&client->packet_lock);
34694
34695- if (copy_to_user(buffer, data, count))
34696+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
34697 return -EFAULT;
34698
34699 return count;
34700diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
34701index d0f7533..fb8215b 100644
34702--- a/drivers/input/serio/serio.c
34703+++ b/drivers/input/serio/serio.c
34704@@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
34705 */
34706 static void serio_init_port(struct serio *serio)
34707 {
34708- static atomic_t serio_no = ATOMIC_INIT(0);
34709+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
34710
34711 __module_get(THIS_MODULE);
34712
34713@@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
34714 mutex_init(&serio->drv_mutex);
34715 device_initialize(&serio->dev);
34716 dev_set_name(&serio->dev, "serio%ld",
34717- (long)atomic_inc_return(&serio_no) - 1);
34718+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
34719 serio->dev.bus = &serio_bus;
34720 serio->dev.release = serio_release_port;
34721 serio->dev.groups = serio_device_attr_groups;
34722diff --git a/drivers/iommu/amd_iommu_init.c b/drivers/iommu/amd_iommu_init.c
34723index faf10ba..7cfaba9 100644
34724--- a/drivers/iommu/amd_iommu_init.c
34725+++ b/drivers/iommu/amd_iommu_init.c
34726@@ -1922,7 +1922,7 @@ static int __init state_next(void)
34727 case IOMMU_ACPI_FINISHED:
34728 early_enable_iommus();
34729 register_syscore_ops(&amd_iommu_syscore_ops);
34730- x86_platform.iommu_shutdown = disable_iommus;
34731+ *(void **)&x86_platform.iommu_shutdown = disable_iommus;
34732 init_state = IOMMU_ENABLED;
34733 break;
34734 case IOMMU_ENABLED:
34735@@ -2064,7 +2064,7 @@ int __init amd_iommu_detect(void)
34736
34737 amd_iommu_detected = true;
34738 iommu_detected = 1;
34739- x86_init.iommu.iommu_init = amd_iommu_init;
34740+ *(void **)&x86_init.iommu.iommu_init = amd_iommu_init;
34741
34742 return 0;
34743 }
34744diff --git a/drivers/iommu/dmar.c b/drivers/iommu/dmar.c
34745index 86e2f4a..d1cec5d 100644
34746--- a/drivers/iommu/dmar.c
34747+++ b/drivers/iommu/dmar.c
34748@@ -555,7 +555,7 @@ int __init detect_intel_iommu(void)
34749
34750 #ifdef CONFIG_X86
34751 if (ret)
34752- x86_init.iommu.iommu_init = intel_iommu_init;
34753+ *(void **)&x86_init.iommu.iommu_init = intel_iommu_init;
34754 #endif
34755 }
34756 early_acpi_os_unmap_memory(dmar_tbl, dmar_tbl_size);
34757diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
34758index c679867..6e2e34d 100644
34759--- a/drivers/isdn/capi/capi.c
34760+++ b/drivers/isdn/capi/capi.c
34761@@ -83,8 +83,8 @@ struct capiminor {
34762
34763 struct capi20_appl *ap;
34764 u32 ncci;
34765- atomic_t datahandle;
34766- atomic_t msgid;
34767+ atomic_unchecked_t datahandle;
34768+ atomic_unchecked_t msgid;
34769
34770 struct tty_port port;
34771 int ttyinstop;
34772@@ -393,7 +393,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
34773 capimsg_setu16(s, 2, mp->ap->applid);
34774 capimsg_setu8 (s, 4, CAPI_DATA_B3);
34775 capimsg_setu8 (s, 5, CAPI_RESP);
34776- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
34777+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
34778 capimsg_setu32(s, 8, mp->ncci);
34779 capimsg_setu16(s, 12, datahandle);
34780 }
34781@@ -514,14 +514,14 @@ static void handle_minor_send(struct capiminor *mp)
34782 mp->outbytes -= len;
34783 spin_unlock_bh(&mp->outlock);
34784
34785- datahandle = atomic_inc_return(&mp->datahandle);
34786+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
34787 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
34788 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
34789 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
34790 capimsg_setu16(skb->data, 2, mp->ap->applid);
34791 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
34792 capimsg_setu8 (skb->data, 5, CAPI_REQ);
34793- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
34794+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
34795 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
34796 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
34797 capimsg_setu16(skb->data, 16, len); /* Data length */
34798diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
34799index 67abf3f..076b3a6 100644
34800--- a/drivers/isdn/gigaset/interface.c
34801+++ b/drivers/isdn/gigaset/interface.c
34802@@ -160,9 +160,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
34803 }
34804 tty->driver_data = cs;
34805
34806- ++cs->port.count;
34807+ atomic_inc(&cs->port.count);
34808
34809- if (cs->port.count == 1) {
34810+ if (atomic_read(&cs->port.count) == 1) {
34811 tty_port_tty_set(&cs->port, tty);
34812 tty->low_latency = 1;
34813 }
34814@@ -186,9 +186,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
34815
34816 if (!cs->connected)
34817 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
34818- else if (!cs->port.count)
34819+ else if (!atomic_read(&cs->port.count))
34820 dev_warn(cs->dev, "%s: device not opened\n", __func__);
34821- else if (!--cs->port.count)
34822+ else if (!atomic_dec_return(&cs->port.count))
34823 tty_port_tty_set(&cs->port, NULL);
34824
34825 mutex_unlock(&cs->mutex);
34826diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
34827index 821f7ac..28d4030 100644
34828--- a/drivers/isdn/hardware/avm/b1.c
34829+++ b/drivers/isdn/hardware/avm/b1.c
34830@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
34831 }
34832 if (left) {
34833 if (t4file->user) {
34834- if (copy_from_user(buf, dp, left))
34835+ if (left > sizeof buf || copy_from_user(buf, dp, left))
34836 return -EFAULT;
34837 } else {
34838 memcpy(buf, dp, left);
34839@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
34840 }
34841 if (left) {
34842 if (config->user) {
34843- if (copy_from_user(buf, dp, left))
34844+ if (left > sizeof buf || copy_from_user(buf, dp, left))
34845 return -EFAULT;
34846 } else {
34847 memcpy(buf, dp, left);
34848diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
34849index b817809..409caff 100644
34850--- a/drivers/isdn/i4l/isdn_tty.c
34851+++ b/drivers/isdn/i4l/isdn_tty.c
34852@@ -1513,9 +1513,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
34853
34854 #ifdef ISDN_DEBUG_MODEM_OPEN
34855 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
34856- port->count);
34857+ atomic_read(&port->count));
34858 #endif
34859- port->count++;
34860+ atomic_inc(&port->count);
34861 port->tty = tty;
34862 /*
34863 * Start up serial port
34864@@ -1559,7 +1559,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
34865 #endif
34866 return;
34867 }
34868- if ((tty->count == 1) && (port->count != 1)) {
34869+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
34870 /*
34871 * Uh, oh. tty->count is 1, which means that the tty
34872 * structure will be freed. Info->count should always
34873@@ -1568,15 +1568,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
34874 * serial port won't be shutdown.
34875 */
34876 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
34877- "info->count is %d\n", port->count);
34878- port->count = 1;
34879+ "info->count is %d\n", atomic_read(&port->count));
34880+ atomic_set(&port->count, 1);
34881 }
34882- if (--port->count < 0) {
34883+ if (atomic_dec_return(&port->count) < 0) {
34884 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
34885- info->line, port->count);
34886- port->count = 0;
34887+ info->line, atomic_read(&port->count));
34888+ atomic_set(&port->count, 0);
34889 }
34890- if (port->count) {
34891+ if (atomic_read(&port->count)) {
34892 #ifdef ISDN_DEBUG_MODEM_OPEN
34893 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
34894 #endif
34895@@ -1630,7 +1630,7 @@ isdn_tty_hangup(struct tty_struct *tty)
34896 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
34897 return;
34898 isdn_tty_shutdown(info);
34899- port->count = 0;
34900+ atomic_set(&port->count, 0);
34901 port->flags &= ~ASYNC_NORMAL_ACTIVE;
34902 port->tty = NULL;
34903 wake_up_interruptible(&port->open_wait);
34904@@ -1971,7 +1971,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
34905 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
34906 modem_info *info = &dev->mdm.info[i];
34907
34908- if (info->port.count == 0)
34909+ if (atomic_read(&info->port.count) == 0)
34910 continue;
34911 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
34912 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
34913diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
34914index e74df7c..03a03ba 100644
34915--- a/drivers/isdn/icn/icn.c
34916+++ b/drivers/isdn/icn/icn.c
34917@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
34918 if (count > len)
34919 count = len;
34920 if (user) {
34921- if (copy_from_user(msg, buf, count))
34922+ if (count > sizeof msg || copy_from_user(msg, buf, count))
34923 return -EFAULT;
34924 } else
34925 memcpy(msg, buf, count);
34926diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
34927index b5fdcb7..5b6c59f 100644
34928--- a/drivers/lguest/core.c
34929+++ b/drivers/lguest/core.c
34930@@ -92,9 +92,17 @@ static __init int map_switcher(void)
34931 * it's worked so far. The end address needs +1 because __get_vm_area
34932 * allocates an extra guard page, so we need space for that.
34933 */
34934+
34935+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
34936+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
34937+ VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
34938+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
34939+#else
34940 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
34941 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
34942 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
34943+#endif
34944+
34945 if (!switcher_vma) {
34946 err = -ENOMEM;
34947 printk("lguest: could not map switcher pages high\n");
34948@@ -119,7 +127,7 @@ static __init int map_switcher(void)
34949 * Now the Switcher is mapped at the right address, we can't fail!
34950 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
34951 */
34952- memcpy(switcher_vma->addr, start_switcher_text,
34953+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
34954 end_switcher_text - start_switcher_text);
34955
34956 printk(KERN_INFO "lguest: mapped switcher at %p\n",
34957diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
34958index 4af12e1..0e89afe 100644
34959--- a/drivers/lguest/x86/core.c
34960+++ b/drivers/lguest/x86/core.c
34961@@ -59,7 +59,7 @@ static struct {
34962 /* Offset from where switcher.S was compiled to where we've copied it */
34963 static unsigned long switcher_offset(void)
34964 {
34965- return SWITCHER_ADDR - (unsigned long)start_switcher_text;
34966+ return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
34967 }
34968
34969 /* This cpu's struct lguest_pages. */
34970@@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
34971 * These copies are pretty cheap, so we do them unconditionally: */
34972 /* Save the current Host top-level page directory.
34973 */
34974+
34975+#ifdef CONFIG_PAX_PER_CPU_PGD
34976+ pages->state.host_cr3 = read_cr3();
34977+#else
34978 pages->state.host_cr3 = __pa(current->mm->pgd);
34979+#endif
34980+
34981 /*
34982 * Set up the Guest's page tables to see this CPU's pages (and no
34983 * other CPU's pages).
34984@@ -476,7 +482,7 @@ void __init lguest_arch_host_init(void)
34985 * compiled-in switcher code and the high-mapped copy we just made.
34986 */
34987 for (i = 0; i < IDT_ENTRIES; i++)
34988- default_idt_entries[i] += switcher_offset();
34989+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
34990
34991 /*
34992 * Set up the Switcher's per-cpu areas.
34993@@ -559,7 +565,7 @@ void __init lguest_arch_host_init(void)
34994 * it will be undisturbed when we switch. To change %cs and jump we
34995 * need this structure to feed to Intel's "lcall" instruction.
34996 */
34997- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
34998+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
34999 lguest_entry.segment = LGUEST_CS;
35000
35001 /*
35002diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
35003index 40634b0..4f5855e 100644
35004--- a/drivers/lguest/x86/switcher_32.S
35005+++ b/drivers/lguest/x86/switcher_32.S
35006@@ -87,6 +87,7 @@
35007 #include <asm/page.h>
35008 #include <asm/segment.h>
35009 #include <asm/lguest.h>
35010+#include <asm/processor-flags.h>
35011
35012 // We mark the start of the code to copy
35013 // It's placed in .text tho it's never run here
35014@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
35015 // Changes type when we load it: damn Intel!
35016 // For after we switch over our page tables
35017 // That entry will be read-only: we'd crash.
35018+
35019+#ifdef CONFIG_PAX_KERNEXEC
35020+ mov %cr0, %edx
35021+ xor $X86_CR0_WP, %edx
35022+ mov %edx, %cr0
35023+#endif
35024+
35025 movl $(GDT_ENTRY_TSS*8), %edx
35026 ltr %dx
35027
35028@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
35029 // Let's clear it again for our return.
35030 // The GDT descriptor of the Host
35031 // Points to the table after two "size" bytes
35032- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
35033+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
35034 // Clear "used" from type field (byte 5, bit 2)
35035- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
35036+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
35037+
35038+#ifdef CONFIG_PAX_KERNEXEC
35039+ mov %cr0, %eax
35040+ xor $X86_CR0_WP, %eax
35041+ mov %eax, %cr0
35042+#endif
35043
35044 // Once our page table's switched, the Guest is live!
35045 // The Host fades as we run this final step.
35046@@ -295,13 +309,12 @@ deliver_to_host:
35047 // I consulted gcc, and it gave
35048 // These instructions, which I gladly credit:
35049 leal (%edx,%ebx,8), %eax
35050- movzwl (%eax),%edx
35051- movl 4(%eax), %eax
35052- xorw %ax, %ax
35053- orl %eax, %edx
35054+ movl 4(%eax), %edx
35055+ movw (%eax), %dx
35056 // Now the address of the handler's in %edx
35057 // We call it now: its "iret" drops us home.
35058- jmp *%edx
35059+ ljmp $__KERNEL_CS, $1f
35060+1: jmp *%edx
35061
35062 // Every interrupt can come to us here
35063 // But we must truly tell each apart.
35064diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
35065index 7155945..4bcc562 100644
35066--- a/drivers/md/bitmap.c
35067+++ b/drivers/md/bitmap.c
35068@@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
35069 chunk_kb ? "KB" : "B");
35070 if (bitmap->storage.file) {
35071 seq_printf(seq, ", file: ");
35072- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
35073+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
35074 }
35075
35076 seq_printf(seq, "\n");
35077diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
35078index a651d52..82f8a95 100644
35079--- a/drivers/md/dm-ioctl.c
35080+++ b/drivers/md/dm-ioctl.c
35081@@ -1601,7 +1601,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
35082 cmd == DM_LIST_VERSIONS_CMD)
35083 return 0;
35084
35085- if ((cmd == DM_DEV_CREATE_CMD)) {
35086+ if (cmd == DM_DEV_CREATE_CMD) {
35087 if (!*param->name) {
35088 DMWARN("name not supplied when creating device");
35089 return -EINVAL;
35090diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
35091index fd61f98..8050783 100644
35092--- a/drivers/md/dm-raid1.c
35093+++ b/drivers/md/dm-raid1.c
35094@@ -40,7 +40,7 @@ enum dm_raid1_error {
35095
35096 struct mirror {
35097 struct mirror_set *ms;
35098- atomic_t error_count;
35099+ atomic_unchecked_t error_count;
35100 unsigned long error_type;
35101 struct dm_dev *dev;
35102 sector_t offset;
35103@@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
35104 struct mirror *m;
35105
35106 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
35107- if (!atomic_read(&m->error_count))
35108+ if (!atomic_read_unchecked(&m->error_count))
35109 return m;
35110
35111 return NULL;
35112@@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
35113 * simple way to tell if a device has encountered
35114 * errors.
35115 */
35116- atomic_inc(&m->error_count);
35117+ atomic_inc_unchecked(&m->error_count);
35118
35119 if (test_and_set_bit(error_type, &m->error_type))
35120 return;
35121@@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
35122 struct mirror *m = get_default_mirror(ms);
35123
35124 do {
35125- if (likely(!atomic_read(&m->error_count)))
35126+ if (likely(!atomic_read_unchecked(&m->error_count)))
35127 return m;
35128
35129 if (m-- == ms->mirror)
35130@@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
35131 {
35132 struct mirror *default_mirror = get_default_mirror(m->ms);
35133
35134- return !atomic_read(&default_mirror->error_count);
35135+ return !atomic_read_unchecked(&default_mirror->error_count);
35136 }
35137
35138 static int mirror_available(struct mirror_set *ms, struct bio *bio)
35139@@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
35140 */
35141 if (likely(region_in_sync(ms, region, 1)))
35142 m = choose_mirror(ms, bio->bi_sector);
35143- else if (m && atomic_read(&m->error_count))
35144+ else if (m && atomic_read_unchecked(&m->error_count))
35145 m = NULL;
35146
35147 if (likely(m))
35148@@ -938,7 +938,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
35149 }
35150
35151 ms->mirror[mirror].ms = ms;
35152- atomic_set(&(ms->mirror[mirror].error_count), 0);
35153+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
35154 ms->mirror[mirror].error_type = 0;
35155 ms->mirror[mirror].offset = offset;
35156
35157@@ -1356,7 +1356,7 @@ static void mirror_resume(struct dm_target *ti)
35158 */
35159 static char device_status_char(struct mirror *m)
35160 {
35161- if (!atomic_read(&(m->error_count)))
35162+ if (!atomic_read_unchecked(&(m->error_count)))
35163 return 'A';
35164
35165 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
35166diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
35167index e2f87653..f279abe 100644
35168--- a/drivers/md/dm-stripe.c
35169+++ b/drivers/md/dm-stripe.c
35170@@ -20,7 +20,7 @@ struct stripe {
35171 struct dm_dev *dev;
35172 sector_t physical_start;
35173
35174- atomic_t error_count;
35175+ atomic_unchecked_t error_count;
35176 };
35177
35178 struct stripe_c {
35179@@ -183,7 +183,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
35180 kfree(sc);
35181 return r;
35182 }
35183- atomic_set(&(sc->stripe[i].error_count), 0);
35184+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
35185 }
35186
35187 ti->private = sc;
35188@@ -324,7 +324,7 @@ static int stripe_status(struct dm_target *ti, status_type_t type,
35189 DMEMIT("%d ", sc->stripes);
35190 for (i = 0; i < sc->stripes; i++) {
35191 DMEMIT("%s ", sc->stripe[i].dev->name);
35192- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
35193+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
35194 'D' : 'A';
35195 }
35196 buffer[i] = '\0';
35197@@ -371,8 +371,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
35198 */
35199 for (i = 0; i < sc->stripes; i++)
35200 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
35201- atomic_inc(&(sc->stripe[i].error_count));
35202- if (atomic_read(&(sc->stripe[i].error_count)) <
35203+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
35204+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
35205 DM_IO_ERROR_THRESHOLD)
35206 schedule_work(&sc->trigger_event);
35207 }
35208diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
35209index fa29557..d24a5b7 100644
35210--- a/drivers/md/dm-table.c
35211+++ b/drivers/md/dm-table.c
35212@@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
35213 if (!dev_size)
35214 return 0;
35215
35216- if ((start >= dev_size) || (start + len > dev_size)) {
35217+ if ((start >= dev_size) || (len > dev_size - start)) {
35218 DMWARN("%s: %s too small for target: "
35219 "start=%llu, len=%llu, dev_size=%llu",
35220 dm_device_name(ti->table->md), bdevname(bdev, b),
35221diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
35222index 693e149..b7e0fde 100644
35223--- a/drivers/md/dm-thin-metadata.c
35224+++ b/drivers/md/dm-thin-metadata.c
35225@@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
35226 {
35227 pmd->info.tm = pmd->tm;
35228 pmd->info.levels = 2;
35229- pmd->info.value_type.context = pmd->data_sm;
35230+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
35231 pmd->info.value_type.size = sizeof(__le64);
35232 pmd->info.value_type.inc = data_block_inc;
35233 pmd->info.value_type.dec = data_block_dec;
35234@@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
35235
35236 pmd->bl_info.tm = pmd->tm;
35237 pmd->bl_info.levels = 1;
35238- pmd->bl_info.value_type.context = pmd->data_sm;
35239+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
35240 pmd->bl_info.value_type.size = sizeof(__le64);
35241 pmd->bl_info.value_type.inc = data_block_inc;
35242 pmd->bl_info.value_type.dec = data_block_dec;
35243diff --git a/drivers/md/dm.c b/drivers/md/dm.c
35244index 77e6eff..913d695 100644
35245--- a/drivers/md/dm.c
35246+++ b/drivers/md/dm.c
35247@@ -182,9 +182,9 @@ struct mapped_device {
35248 /*
35249 * Event handling.
35250 */
35251- atomic_t event_nr;
35252+ atomic_unchecked_t event_nr;
35253 wait_queue_head_t eventq;
35254- atomic_t uevent_seq;
35255+ atomic_unchecked_t uevent_seq;
35256 struct list_head uevent_list;
35257 spinlock_t uevent_lock; /* Protect access to uevent_list */
35258
35259@@ -1847,8 +1847,8 @@ static struct mapped_device *alloc_dev(int minor)
35260 rwlock_init(&md->map_lock);
35261 atomic_set(&md->holders, 1);
35262 atomic_set(&md->open_count, 0);
35263- atomic_set(&md->event_nr, 0);
35264- atomic_set(&md->uevent_seq, 0);
35265+ atomic_set_unchecked(&md->event_nr, 0);
35266+ atomic_set_unchecked(&md->uevent_seq, 0);
35267 INIT_LIST_HEAD(&md->uevent_list);
35268 spin_lock_init(&md->uevent_lock);
35269
35270@@ -1982,7 +1982,7 @@ static void event_callback(void *context)
35271
35272 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
35273
35274- atomic_inc(&md->event_nr);
35275+ atomic_inc_unchecked(&md->event_nr);
35276 wake_up(&md->eventq);
35277 }
35278
35279@@ -2637,18 +2637,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
35280
35281 uint32_t dm_next_uevent_seq(struct mapped_device *md)
35282 {
35283- return atomic_add_return(1, &md->uevent_seq);
35284+ return atomic_add_return_unchecked(1, &md->uevent_seq);
35285 }
35286
35287 uint32_t dm_get_event_nr(struct mapped_device *md)
35288 {
35289- return atomic_read(&md->event_nr);
35290+ return atomic_read_unchecked(&md->event_nr);
35291 }
35292
35293 int dm_wait_event(struct mapped_device *md, int event_nr)
35294 {
35295 return wait_event_interruptible(md->eventq,
35296- (event_nr != atomic_read(&md->event_nr)));
35297+ (event_nr != atomic_read_unchecked(&md->event_nr)));
35298 }
35299
35300 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
35301diff --git a/drivers/md/md.c b/drivers/md/md.c
35302index 6120071..31d9be2 100644
35303--- a/drivers/md/md.c
35304+++ b/drivers/md/md.c
35305@@ -240,10 +240,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
35306 * start build, activate spare
35307 */
35308 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
35309-static atomic_t md_event_count;
35310+static atomic_unchecked_t md_event_count;
35311 void md_new_event(struct mddev *mddev)
35312 {
35313- atomic_inc(&md_event_count);
35314+ atomic_inc_unchecked(&md_event_count);
35315 wake_up(&md_event_waiters);
35316 }
35317 EXPORT_SYMBOL_GPL(md_new_event);
35318@@ -253,7 +253,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
35319 */
35320 static void md_new_event_inintr(struct mddev *mddev)
35321 {
35322- atomic_inc(&md_event_count);
35323+ atomic_inc_unchecked(&md_event_count);
35324 wake_up(&md_event_waiters);
35325 }
35326
35327@@ -1504,7 +1504,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
35328 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
35329 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
35330 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
35331- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
35332+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
35333
35334 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
35335 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
35336@@ -1748,7 +1748,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
35337 else
35338 sb->resync_offset = cpu_to_le64(0);
35339
35340- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
35341+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
35342
35343 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
35344 sb->size = cpu_to_le64(mddev->dev_sectors);
35345@@ -2748,7 +2748,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
35346 static ssize_t
35347 errors_show(struct md_rdev *rdev, char *page)
35348 {
35349- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
35350+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
35351 }
35352
35353 static ssize_t
35354@@ -2757,7 +2757,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
35355 char *e;
35356 unsigned long n = simple_strtoul(buf, &e, 10);
35357 if (*buf && (*e == 0 || *e == '\n')) {
35358- atomic_set(&rdev->corrected_errors, n);
35359+ atomic_set_unchecked(&rdev->corrected_errors, n);
35360 return len;
35361 }
35362 return -EINVAL;
35363@@ -3204,8 +3204,8 @@ int md_rdev_init(struct md_rdev *rdev)
35364 rdev->sb_loaded = 0;
35365 rdev->bb_page = NULL;
35366 atomic_set(&rdev->nr_pending, 0);
35367- atomic_set(&rdev->read_errors, 0);
35368- atomic_set(&rdev->corrected_errors, 0);
35369+ atomic_set_unchecked(&rdev->read_errors, 0);
35370+ atomic_set_unchecked(&rdev->corrected_errors, 0);
35371
35372 INIT_LIST_HEAD(&rdev->same_set);
35373 init_waitqueue_head(&rdev->blocked_wait);
35374@@ -6984,7 +6984,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
35375
35376 spin_unlock(&pers_lock);
35377 seq_printf(seq, "\n");
35378- seq->poll_event = atomic_read(&md_event_count);
35379+ seq->poll_event = atomic_read_unchecked(&md_event_count);
35380 return 0;
35381 }
35382 if (v == (void*)2) {
35383@@ -7087,7 +7087,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
35384 return error;
35385
35386 seq = file->private_data;
35387- seq->poll_event = atomic_read(&md_event_count);
35388+ seq->poll_event = atomic_read_unchecked(&md_event_count);
35389 return error;
35390 }
35391
35392@@ -7101,7 +7101,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
35393 /* always allow read */
35394 mask = POLLIN | POLLRDNORM;
35395
35396- if (seq->poll_event != atomic_read(&md_event_count))
35397+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
35398 mask |= POLLERR | POLLPRI;
35399 return mask;
35400 }
35401@@ -7145,7 +7145,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
35402 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
35403 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
35404 (int)part_stat_read(&disk->part0, sectors[1]) -
35405- atomic_read(&disk->sync_io);
35406+ atomic_read_unchecked(&disk->sync_io);
35407 /* sync IO will cause sync_io to increase before the disk_stats
35408 * as sync_io is counted when a request starts, and
35409 * disk_stats is counted when it completes.
35410diff --git a/drivers/md/md.h b/drivers/md/md.h
35411index af443ab..0f93be3 100644
35412--- a/drivers/md/md.h
35413+++ b/drivers/md/md.h
35414@@ -94,13 +94,13 @@ struct md_rdev {
35415 * only maintained for arrays that
35416 * support hot removal
35417 */
35418- atomic_t read_errors; /* number of consecutive read errors that
35419+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
35420 * we have tried to ignore.
35421 */
35422 struct timespec last_read_error; /* monotonic time since our
35423 * last read error
35424 */
35425- atomic_t corrected_errors; /* number of corrected read errors,
35426+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
35427 * for reporting to userspace and storing
35428 * in superblock.
35429 */
35430@@ -432,7 +432,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
35431
35432 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
35433 {
35434- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
35435+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
35436 }
35437
35438 struct md_personality
35439diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
35440index 1cbfc6b..56e1dbb 100644
35441--- a/drivers/md/persistent-data/dm-space-map.h
35442+++ b/drivers/md/persistent-data/dm-space-map.h
35443@@ -60,6 +60,7 @@ struct dm_space_map {
35444 int (*root_size)(struct dm_space_map *sm, size_t *result);
35445 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
35446 };
35447+typedef struct dm_space_map __no_const dm_space_map_no_const;
35448
35449 /*----------------------------------------------------------------*/
35450
35451diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
35452index a0f7309..5599dbc 100644
35453--- a/drivers/md/raid1.c
35454+++ b/drivers/md/raid1.c
35455@@ -1819,7 +1819,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
35456 if (r1_sync_page_io(rdev, sect, s,
35457 bio->bi_io_vec[idx].bv_page,
35458 READ) != 0)
35459- atomic_add(s, &rdev->corrected_errors);
35460+ atomic_add_unchecked(s, &rdev->corrected_errors);
35461 }
35462 sectors -= s;
35463 sect += s;
35464@@ -2041,7 +2041,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
35465 test_bit(In_sync, &rdev->flags)) {
35466 if (r1_sync_page_io(rdev, sect, s,
35467 conf->tmppage, READ)) {
35468- atomic_add(s, &rdev->corrected_errors);
35469+ atomic_add_unchecked(s, &rdev->corrected_errors);
35470 printk(KERN_INFO
35471 "md/raid1:%s: read error corrected "
35472 "(%d sectors at %llu on %s)\n",
35473diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
35474index c9acbd7..386cd3e 100644
35475--- a/drivers/md/raid10.c
35476+++ b/drivers/md/raid10.c
35477@@ -1878,7 +1878,7 @@ static void end_sync_read(struct bio *bio, int error)
35478 /* The write handler will notice the lack of
35479 * R10BIO_Uptodate and record any errors etc
35480 */
35481- atomic_add(r10_bio->sectors,
35482+ atomic_add_unchecked(r10_bio->sectors,
35483 &conf->mirrors[d].rdev->corrected_errors);
35484
35485 /* for reconstruct, we always reschedule after a read.
35486@@ -2227,7 +2227,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
35487 {
35488 struct timespec cur_time_mon;
35489 unsigned long hours_since_last;
35490- unsigned int read_errors = atomic_read(&rdev->read_errors);
35491+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
35492
35493 ktime_get_ts(&cur_time_mon);
35494
35495@@ -2249,9 +2249,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
35496 * overflowing the shift of read_errors by hours_since_last.
35497 */
35498 if (hours_since_last >= 8 * sizeof(read_errors))
35499- atomic_set(&rdev->read_errors, 0);
35500+ atomic_set_unchecked(&rdev->read_errors, 0);
35501 else
35502- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
35503+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
35504 }
35505
35506 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
35507@@ -2305,8 +2305,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
35508 return;
35509
35510 check_decay_read_errors(mddev, rdev);
35511- atomic_inc(&rdev->read_errors);
35512- if (atomic_read(&rdev->read_errors) > max_read_errors) {
35513+ atomic_inc_unchecked(&rdev->read_errors);
35514+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
35515 char b[BDEVNAME_SIZE];
35516 bdevname(rdev->bdev, b);
35517
35518@@ -2314,7 +2314,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
35519 "md/raid10:%s: %s: Raid device exceeded "
35520 "read_error threshold [cur %d:max %d]\n",
35521 mdname(mddev), b,
35522- atomic_read(&rdev->read_errors), max_read_errors);
35523+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
35524 printk(KERN_NOTICE
35525 "md/raid10:%s: %s: Failing raid device\n",
35526 mdname(mddev), b);
35527@@ -2469,7 +2469,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
35528 sect +
35529 choose_data_offset(r10_bio, rdev)),
35530 bdevname(rdev->bdev, b));
35531- atomic_add(s, &rdev->corrected_errors);
35532+ atomic_add_unchecked(s, &rdev->corrected_errors);
35533 }
35534
35535 rdev_dec_pending(rdev, mddev);
35536diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
35537index a450268..c4168a9 100644
35538--- a/drivers/md/raid5.c
35539+++ b/drivers/md/raid5.c
35540@@ -1789,21 +1789,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
35541 mdname(conf->mddev), STRIPE_SECTORS,
35542 (unsigned long long)s,
35543 bdevname(rdev->bdev, b));
35544- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
35545+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
35546 clear_bit(R5_ReadError, &sh->dev[i].flags);
35547 clear_bit(R5_ReWrite, &sh->dev[i].flags);
35548 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
35549 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
35550
35551- if (atomic_read(&rdev->read_errors))
35552- atomic_set(&rdev->read_errors, 0);
35553+ if (atomic_read_unchecked(&rdev->read_errors))
35554+ atomic_set_unchecked(&rdev->read_errors, 0);
35555 } else {
35556 const char *bdn = bdevname(rdev->bdev, b);
35557 int retry = 0;
35558 int set_bad = 0;
35559
35560 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
35561- atomic_inc(&rdev->read_errors);
35562+ atomic_inc_unchecked(&rdev->read_errors);
35563 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
35564 printk_ratelimited(
35565 KERN_WARNING
35566@@ -1831,7 +1831,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
35567 mdname(conf->mddev),
35568 (unsigned long long)s,
35569 bdn);
35570- } else if (atomic_read(&rdev->read_errors)
35571+ } else if (atomic_read_unchecked(&rdev->read_errors)
35572 > conf->max_nr_stripes)
35573 printk(KERN_WARNING
35574 "md/raid:%s: Too many read errors, failing device %s.\n",
35575diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
35576index d33101a..6b13069 100644
35577--- a/drivers/media/dvb-core/dvbdev.c
35578+++ b/drivers/media/dvb-core/dvbdev.c
35579@@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
35580 const struct dvb_device *template, void *priv, int type)
35581 {
35582 struct dvb_device *dvbdev;
35583- struct file_operations *dvbdevfops;
35584+ file_operations_no_const *dvbdevfops;
35585 struct device *clsdev;
35586 int minor;
35587 int id;
35588diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
35589index 404f63a..4796533 100644
35590--- a/drivers/media/dvb-frontends/dib3000.h
35591+++ b/drivers/media/dvb-frontends/dib3000.h
35592@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
35593 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
35594 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
35595 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
35596-};
35597+} __no_const;
35598
35599 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
35600 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
35601diff --git a/drivers/media/pci/cx88/cx88-alsa.c b/drivers/media/pci/cx88/cx88-alsa.c
35602index 3aa6856..435ad25 100644
35603--- a/drivers/media/pci/cx88/cx88-alsa.c
35604+++ b/drivers/media/pci/cx88/cx88-alsa.c
35605@@ -749,7 +749,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
35606 * Only boards with eeprom and byte 1 at eeprom=1 have it
35607 */
35608
35609-static const struct pci_device_id cx88_audio_pci_tbl[] __devinitdata = {
35610+static const struct pci_device_id cx88_audio_pci_tbl[] __devinitconst = {
35611 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
35612 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
35613 {0, }
35614diff --git a/drivers/media/pci/ddbridge/ddbridge-core.c b/drivers/media/pci/ddbridge/ddbridge-core.c
35615index feff57e..66a2c67 100644
35616--- a/drivers/media/pci/ddbridge/ddbridge-core.c
35617+++ b/drivers/media/pci/ddbridge/ddbridge-core.c
35618@@ -1679,7 +1679,7 @@ static struct ddb_info ddb_v6 = {
35619 .subvendor = _subvend, .subdevice = _subdev, \
35620 .driver_data = (unsigned long)&_driverdata }
35621
35622-static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
35623+static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
35624 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
35625 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
35626 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
35627diff --git a/drivers/media/pci/ngene/ngene-cards.c b/drivers/media/pci/ngene/ngene-cards.c
35628index 96a13ed..6df45b4 100644
35629--- a/drivers/media/pci/ngene/ngene-cards.c
35630+++ b/drivers/media/pci/ngene/ngene-cards.c
35631@@ -741,7 +741,7 @@ static struct ngene_info ngene_info_terratec = {
35632
35633 /****************************************************************************/
35634
35635-static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
35636+static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
35637 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
35638 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
35639 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
35640diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
35641index a3b1a34..71ce0e3 100644
35642--- a/drivers/media/platform/omap/omap_vout.c
35643+++ b/drivers/media/platform/omap/omap_vout.c
35644@@ -65,7 +65,6 @@ enum omap_vout_channels {
35645 OMAP_VIDEO2,
35646 };
35647
35648-static struct videobuf_queue_ops video_vbq_ops;
35649 /* Variables configurable through module params*/
35650 static u32 video1_numbuffers = 3;
35651 static u32 video2_numbuffers = 3;
35652@@ -1012,6 +1011,12 @@ static int omap_vout_open(struct file *file)
35653 {
35654 struct videobuf_queue *q;
35655 struct omap_vout_device *vout = NULL;
35656+ static struct videobuf_queue_ops video_vbq_ops = {
35657+ .buf_setup = omap_vout_buffer_setup,
35658+ .buf_prepare = omap_vout_buffer_prepare,
35659+ .buf_release = omap_vout_buffer_release,
35660+ .buf_queue = omap_vout_buffer_queue,
35661+ };
35662
35663 vout = video_drvdata(file);
35664 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
35665@@ -1029,10 +1034,6 @@ static int omap_vout_open(struct file *file)
35666 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
35667
35668 q = &vout->vbq;
35669- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
35670- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
35671- video_vbq_ops.buf_release = omap_vout_buffer_release;
35672- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
35673 spin_lock_init(&vout->vbq_lock);
35674
35675 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
35676diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
35677index ddb422e..8cf008e 100644
35678--- a/drivers/media/platform/s5p-tv/mixer.h
35679+++ b/drivers/media/platform/s5p-tv/mixer.h
35680@@ -155,7 +155,7 @@ struct mxr_layer {
35681 /** layer index (unique identifier) */
35682 int idx;
35683 /** callbacks for layer methods */
35684- struct mxr_layer_ops ops;
35685+ struct mxr_layer_ops *ops;
35686 /** format array */
35687 const struct mxr_format **fmt_array;
35688 /** size of format array */
35689diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
35690index b93a21f..2535195 100644
35691--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
35692+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
35693@@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
35694 {
35695 struct mxr_layer *layer;
35696 int ret;
35697- struct mxr_layer_ops ops = {
35698+ static struct mxr_layer_ops ops = {
35699 .release = mxr_graph_layer_release,
35700 .buffer_set = mxr_graph_buffer_set,
35701 .stream_set = mxr_graph_stream_set,
35702diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
35703index 3b1670a..595c939 100644
35704--- a/drivers/media/platform/s5p-tv/mixer_reg.c
35705+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
35706@@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
35707 layer->update_buf = next;
35708 }
35709
35710- layer->ops.buffer_set(layer, layer->update_buf);
35711+ layer->ops->buffer_set(layer, layer->update_buf);
35712
35713 if (done && done != layer->shadow_buf)
35714 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
35715diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
35716index 0c1cd89..6574647 100644
35717--- a/drivers/media/platform/s5p-tv/mixer_video.c
35718+++ b/drivers/media/platform/s5p-tv/mixer_video.c
35719@@ -209,7 +209,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
35720 layer->geo.src.height = layer->geo.src.full_height;
35721
35722 mxr_geometry_dump(mdev, &layer->geo);
35723- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
35724+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
35725 mxr_geometry_dump(mdev, &layer->geo);
35726 }
35727
35728@@ -227,7 +227,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
35729 layer->geo.dst.full_width = mbus_fmt.width;
35730 layer->geo.dst.full_height = mbus_fmt.height;
35731 layer->geo.dst.field = mbus_fmt.field;
35732- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
35733+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
35734
35735 mxr_geometry_dump(mdev, &layer->geo);
35736 }
35737@@ -333,7 +333,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
35738 /* set source size to highest accepted value */
35739 geo->src.full_width = max(geo->dst.full_width, pix->width);
35740 geo->src.full_height = max(geo->dst.full_height, pix->height);
35741- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
35742+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
35743 mxr_geometry_dump(mdev, &layer->geo);
35744 /* set cropping to total visible screen */
35745 geo->src.width = pix->width;
35746@@ -341,12 +341,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
35747 geo->src.x_offset = 0;
35748 geo->src.y_offset = 0;
35749 /* assure consistency of geometry */
35750- layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
35751+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
35752 mxr_geometry_dump(mdev, &layer->geo);
35753 /* set full size to lowest possible value */
35754 geo->src.full_width = 0;
35755 geo->src.full_height = 0;
35756- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
35757+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
35758 mxr_geometry_dump(mdev, &layer->geo);
35759
35760 /* returning results */
35761@@ -473,7 +473,7 @@ static int mxr_s_selection(struct file *file, void *fh,
35762 target->width = s->r.width;
35763 target->height = s->r.height;
35764
35765- layer->ops.fix_geometry(layer, stage, s->flags);
35766+ layer->ops->fix_geometry(layer, stage, s->flags);
35767
35768 /* retrieve update selection rectangle */
35769 res.left = target->x_offset;
35770@@ -928,13 +928,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
35771 mxr_output_get(mdev);
35772
35773 mxr_layer_update_output(layer);
35774- layer->ops.format_set(layer);
35775+ layer->ops->format_set(layer);
35776 /* enabling layer in hardware */
35777 spin_lock_irqsave(&layer->enq_slock, flags);
35778 layer->state = MXR_LAYER_STREAMING;
35779 spin_unlock_irqrestore(&layer->enq_slock, flags);
35780
35781- layer->ops.stream_set(layer, MXR_ENABLE);
35782+ layer->ops->stream_set(layer, MXR_ENABLE);
35783 mxr_streamer_get(mdev);
35784
35785 return 0;
35786@@ -1004,7 +1004,7 @@ static int stop_streaming(struct vb2_queue *vq)
35787 spin_unlock_irqrestore(&layer->enq_slock, flags);
35788
35789 /* disabling layer in hardware */
35790- layer->ops.stream_set(layer, MXR_DISABLE);
35791+ layer->ops->stream_set(layer, MXR_DISABLE);
35792 /* remove one streamer */
35793 mxr_streamer_put(mdev);
35794 /* allow changes in output configuration */
35795@@ -1043,8 +1043,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
35796
35797 void mxr_layer_release(struct mxr_layer *layer)
35798 {
35799- if (layer->ops.release)
35800- layer->ops.release(layer);
35801+ if (layer->ops->release)
35802+ layer->ops->release(layer);
35803 }
35804
35805 void mxr_base_layer_release(struct mxr_layer *layer)
35806@@ -1070,7 +1070,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
35807
35808 layer->mdev = mdev;
35809 layer->idx = idx;
35810- layer->ops = *ops;
35811+ layer->ops = ops;
35812
35813 spin_lock_init(&layer->enq_slock);
35814 INIT_LIST_HEAD(&layer->enq_list);
35815diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
35816index 3d13a63..da31bf1 100644
35817--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
35818+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
35819@@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
35820 {
35821 struct mxr_layer *layer;
35822 int ret;
35823- struct mxr_layer_ops ops = {
35824+ static struct mxr_layer_ops ops = {
35825 .release = mxr_vp_layer_release,
35826 .buffer_set = mxr_vp_buffer_set,
35827 .stream_set = mxr_vp_stream_set,
35828diff --git a/drivers/media/platform/timblogiw.c b/drivers/media/platform/timblogiw.c
35829index 02194c0..36d69c1 100644
35830--- a/drivers/media/platform/timblogiw.c
35831+++ b/drivers/media/platform/timblogiw.c
35832@@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
35833
35834 /* Platform device functions */
35835
35836-static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
35837+static struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
35838 .vidioc_querycap = timblogiw_querycap,
35839 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
35840 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
35841@@ -767,7 +767,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
35842 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
35843 };
35844
35845-static __devinitconst struct v4l2_file_operations timblogiw_fops = {
35846+static struct v4l2_file_operations timblogiw_fops = {
35847 .owner = THIS_MODULE,
35848 .open = timblogiw_open,
35849 .release = timblogiw_close,
35850diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
35851index 697a421..16c5a5f 100644
35852--- a/drivers/media/radio/radio-cadet.c
35853+++ b/drivers/media/radio/radio-cadet.c
35854@@ -302,6 +302,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
35855 unsigned char readbuf[RDS_BUFFER];
35856 int i = 0;
35857
35858+ if (count > RDS_BUFFER)
35859+ return -EFAULT;
35860 mutex_lock(&dev->lock);
35861 if (dev->rdsstat == 0)
35862 cadet_start_rds(dev);
35863@@ -317,7 +319,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
35864 while (i < count && dev->rdsin != dev->rdsout)
35865 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
35866
35867- if (i && copy_to_user(data, readbuf, i))
35868+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
35869 i = -EFAULT;
35870 unlock:
35871 mutex_unlock(&dev->lock);
35872diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
35873index 3940bb0..fb3952a 100644
35874--- a/drivers/media/usb/dvb-usb/cxusb.c
35875+++ b/drivers/media/usb/dvb-usb/cxusb.c
35876@@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
35877
35878 struct dib0700_adapter_state {
35879 int (*set_param_save) (struct dvb_frontend *);
35880-};
35881+} __no_const;
35882
35883 static int dib7070_set_param_override(struct dvb_frontend *fe)
35884 {
35885diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
35886index 9382895..ac8093c 100644
35887--- a/drivers/media/usb/dvb-usb/dw2102.c
35888+++ b/drivers/media/usb/dvb-usb/dw2102.c
35889@@ -95,7 +95,7 @@ struct su3000_state {
35890
35891 struct s6x0_state {
35892 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
35893-};
35894+} __no_const;
35895
35896 /* debug */
35897 static int dvb_usb_dw2102_debug;
35898diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
35899index fb69baa..cf7ad22 100644
35900--- a/drivers/message/fusion/mptbase.c
35901+++ b/drivers/message/fusion/mptbase.c
35902@@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
35903 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
35904 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
35905
35906+#ifdef CONFIG_GRKERNSEC_HIDESYM
35907+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
35908+#else
35909 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
35910 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
35911+#endif
35912+
35913 /*
35914 * Rounding UP to nearest 4-kB boundary here...
35915 */
35916diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
35917index 551262e..7551198 100644
35918--- a/drivers/message/fusion/mptsas.c
35919+++ b/drivers/message/fusion/mptsas.c
35920@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
35921 return 0;
35922 }
35923
35924+static inline void
35925+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
35926+{
35927+ if (phy_info->port_details) {
35928+ phy_info->port_details->rphy = rphy;
35929+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
35930+ ioc->name, rphy));
35931+ }
35932+
35933+ if (rphy) {
35934+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
35935+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
35936+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
35937+ ioc->name, rphy, rphy->dev.release));
35938+ }
35939+}
35940+
35941 /* no mutex */
35942 static void
35943 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
35944@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
35945 return NULL;
35946 }
35947
35948-static inline void
35949-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
35950-{
35951- if (phy_info->port_details) {
35952- phy_info->port_details->rphy = rphy;
35953- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
35954- ioc->name, rphy));
35955- }
35956-
35957- if (rphy) {
35958- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
35959- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
35960- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
35961- ioc->name, rphy, rphy->dev.release));
35962- }
35963-}
35964-
35965 static inline struct sas_port *
35966 mptsas_get_port(struct mptsas_phyinfo *phy_info)
35967 {
35968diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
35969index 0c3ced7..1fe34ec 100644
35970--- a/drivers/message/fusion/mptscsih.c
35971+++ b/drivers/message/fusion/mptscsih.c
35972@@ -1270,15 +1270,16 @@ mptscsih_info(struct Scsi_Host *SChost)
35973
35974 h = shost_priv(SChost);
35975
35976- if (h) {
35977- if (h->info_kbuf == NULL)
35978- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
35979- return h->info_kbuf;
35980- h->info_kbuf[0] = '\0';
35981+ if (!h)
35982+ return NULL;
35983
35984- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
35985- h->info_kbuf[size-1] = '\0';
35986- }
35987+ if (h->info_kbuf == NULL)
35988+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
35989+ return h->info_kbuf;
35990+ h->info_kbuf[0] = '\0';
35991+
35992+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
35993+ h->info_kbuf[size-1] = '\0';
35994
35995 return h->info_kbuf;
35996 }
35997diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
35998index 8001aa6..b137580 100644
35999--- a/drivers/message/i2o/i2o_proc.c
36000+++ b/drivers/message/i2o/i2o_proc.c
36001@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
36002 "Array Controller Device"
36003 };
36004
36005-static char *chtostr(char *tmp, u8 *chars, int n)
36006-{
36007- tmp[0] = 0;
36008- return strncat(tmp, (char *)chars, n);
36009-}
36010-
36011 static int i2o_report_query_status(struct seq_file *seq, int block_status,
36012 char *group)
36013 {
36014@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
36015 } *result;
36016
36017 i2o_exec_execute_ddm_table ddm_table;
36018- char tmp[28 + 1];
36019
36020 result = kmalloc(sizeof(*result), GFP_KERNEL);
36021 if (!result)
36022@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
36023
36024 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
36025 seq_printf(seq, "%-#8x", ddm_table.module_id);
36026- seq_printf(seq, "%-29s",
36027- chtostr(tmp, ddm_table.module_name_version, 28));
36028+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
36029 seq_printf(seq, "%9d ", ddm_table.data_size);
36030 seq_printf(seq, "%8d", ddm_table.code_size);
36031
36032@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
36033
36034 i2o_driver_result_table *result;
36035 i2o_driver_store_table *dst;
36036- char tmp[28 + 1];
36037
36038 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
36039 if (result == NULL)
36040@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
36041
36042 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
36043 seq_printf(seq, "%-#8x", dst->module_id);
36044- seq_printf(seq, "%-29s",
36045- chtostr(tmp, dst->module_name_version, 28));
36046- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
36047+ seq_printf(seq, "%-.28s", dst->module_name_version);
36048+ seq_printf(seq, "%-.8s", dst->date);
36049 seq_printf(seq, "%8d ", dst->module_size);
36050 seq_printf(seq, "%8d ", dst->mpb_size);
36051 seq_printf(seq, "0x%04x", dst->module_flags);
36052@@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
36053 // == (allow) 512d bytes (max)
36054 static u16 *work16 = (u16 *) work32;
36055 int token;
36056- char tmp[16 + 1];
36057
36058 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
36059
36060@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
36061 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
36062 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
36063 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
36064- seq_printf(seq, "Vendor info : %s\n",
36065- chtostr(tmp, (u8 *) (work32 + 2), 16));
36066- seq_printf(seq, "Product info : %s\n",
36067- chtostr(tmp, (u8 *) (work32 + 6), 16));
36068- seq_printf(seq, "Description : %s\n",
36069- chtostr(tmp, (u8 *) (work32 + 10), 16));
36070- seq_printf(seq, "Product rev. : %s\n",
36071- chtostr(tmp, (u8 *) (work32 + 14), 8));
36072+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
36073+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
36074+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
36075+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
36076
36077 seq_printf(seq, "Serial number : ");
36078 print_serial_number(seq, (u8 *) (work32 + 16),
36079@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
36080 u8 pad[256]; // allow up to 256 byte (max) serial number
36081 } result;
36082
36083- char tmp[24 + 1];
36084-
36085 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
36086
36087 if (token < 0) {
36088@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
36089 }
36090
36091 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
36092- seq_printf(seq, "Module name : %s\n",
36093- chtostr(tmp, result.module_name, 24));
36094- seq_printf(seq, "Module revision : %s\n",
36095- chtostr(tmp, result.module_rev, 8));
36096+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
36097+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
36098
36099 seq_printf(seq, "Serial number : ");
36100 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
36101@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
36102 u8 instance_number[4];
36103 } result;
36104
36105- char tmp[64 + 1];
36106-
36107 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
36108
36109 if (token < 0) {
36110@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
36111 return 0;
36112 }
36113
36114- seq_printf(seq, "Device name : %s\n",
36115- chtostr(tmp, result.device_name, 64));
36116- seq_printf(seq, "Service name : %s\n",
36117- chtostr(tmp, result.service_name, 64));
36118- seq_printf(seq, "Physical name : %s\n",
36119- chtostr(tmp, result.physical_location, 64));
36120- seq_printf(seq, "Instance number : %s\n",
36121- chtostr(tmp, result.instance_number, 4));
36122+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
36123+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
36124+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
36125+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
36126
36127 return 0;
36128 }
36129diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
36130index a8c08f3..155fe3d 100644
36131--- a/drivers/message/i2o/iop.c
36132+++ b/drivers/message/i2o/iop.c
36133@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
36134
36135 spin_lock_irqsave(&c->context_list_lock, flags);
36136
36137- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
36138- atomic_inc(&c->context_list_counter);
36139+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
36140+ atomic_inc_unchecked(&c->context_list_counter);
36141
36142- entry->context = atomic_read(&c->context_list_counter);
36143+ entry->context = atomic_read_unchecked(&c->context_list_counter);
36144
36145 list_add(&entry->list, &c->context_list);
36146
36147@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
36148
36149 #if BITS_PER_LONG == 64
36150 spin_lock_init(&c->context_list_lock);
36151- atomic_set(&c->context_list_counter, 0);
36152+ atomic_set_unchecked(&c->context_list_counter, 0);
36153 INIT_LIST_HEAD(&c->context_list);
36154 #endif
36155
36156diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
36157index 965c480..71f2db9 100644
36158--- a/drivers/mfd/janz-cmodio.c
36159+++ b/drivers/mfd/janz-cmodio.c
36160@@ -13,6 +13,7 @@
36161
36162 #include <linux/kernel.h>
36163 #include <linux/module.h>
36164+#include <linux/slab.h>
36165 #include <linux/init.h>
36166 #include <linux/pci.h>
36167 #include <linux/interrupt.h>
36168diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
36169index 3aa9a96..59cf685 100644
36170--- a/drivers/misc/kgdbts.c
36171+++ b/drivers/misc/kgdbts.c
36172@@ -832,7 +832,7 @@ static void run_plant_and_detach_test(int is_early)
36173 char before[BREAK_INSTR_SIZE];
36174 char after[BREAK_INSTR_SIZE];
36175
36176- probe_kernel_read(before, (char *)kgdbts_break_test,
36177+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
36178 BREAK_INSTR_SIZE);
36179 init_simple_test();
36180 ts.tst = plant_and_detach_test;
36181@@ -840,7 +840,7 @@ static void run_plant_and_detach_test(int is_early)
36182 /* Activate test with initial breakpoint */
36183 if (!is_early)
36184 kgdb_breakpoint();
36185- probe_kernel_read(after, (char *)kgdbts_break_test,
36186+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
36187 BREAK_INSTR_SIZE);
36188 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
36189 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
36190diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
36191index 4a87e5c..76bdf5c 100644
36192--- a/drivers/misc/lis3lv02d/lis3lv02d.c
36193+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
36194@@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
36195 * the lid is closed. This leads to interrupts as soon as a little move
36196 * is done.
36197 */
36198- atomic_inc(&lis3->count);
36199+ atomic_inc_unchecked(&lis3->count);
36200
36201 wake_up_interruptible(&lis3->misc_wait);
36202 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
36203@@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
36204 if (lis3->pm_dev)
36205 pm_runtime_get_sync(lis3->pm_dev);
36206
36207- atomic_set(&lis3->count, 0);
36208+ atomic_set_unchecked(&lis3->count, 0);
36209 return 0;
36210 }
36211
36212@@ -617,7 +617,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
36213 add_wait_queue(&lis3->misc_wait, &wait);
36214 while (true) {
36215 set_current_state(TASK_INTERRUPTIBLE);
36216- data = atomic_xchg(&lis3->count, 0);
36217+ data = atomic_xchg_unchecked(&lis3->count, 0);
36218 if (data)
36219 break;
36220
36221@@ -658,7 +658,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
36222 struct lis3lv02d, miscdev);
36223
36224 poll_wait(file, &lis3->misc_wait, wait);
36225- if (atomic_read(&lis3->count))
36226+ if (atomic_read_unchecked(&lis3->count))
36227 return POLLIN | POLLRDNORM;
36228 return 0;
36229 }
36230diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
36231index c439c82..1f20f57 100644
36232--- a/drivers/misc/lis3lv02d/lis3lv02d.h
36233+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
36234@@ -297,7 +297,7 @@ struct lis3lv02d {
36235 struct input_polled_dev *idev; /* input device */
36236 struct platform_device *pdev; /* platform device */
36237 struct regulator_bulk_data regulators[2];
36238- atomic_t count; /* interrupt count after last read */
36239+ atomic_unchecked_t count; /* interrupt count after last read */
36240 union axis_conversion ac; /* hw -> logical axis */
36241 int mapped_btns[3];
36242
36243diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
36244index 2f30bad..c4c13d0 100644
36245--- a/drivers/misc/sgi-gru/gruhandles.c
36246+++ b/drivers/misc/sgi-gru/gruhandles.c
36247@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
36248 unsigned long nsec;
36249
36250 nsec = CLKS2NSEC(clks);
36251- atomic_long_inc(&mcs_op_statistics[op].count);
36252- atomic_long_add(nsec, &mcs_op_statistics[op].total);
36253+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
36254+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
36255 if (mcs_op_statistics[op].max < nsec)
36256 mcs_op_statistics[op].max = nsec;
36257 }
36258diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
36259index 950dbe9..eeef0f8 100644
36260--- a/drivers/misc/sgi-gru/gruprocfs.c
36261+++ b/drivers/misc/sgi-gru/gruprocfs.c
36262@@ -32,9 +32,9 @@
36263
36264 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
36265
36266-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
36267+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
36268 {
36269- unsigned long val = atomic_long_read(v);
36270+ unsigned long val = atomic_long_read_unchecked(v);
36271
36272 seq_printf(s, "%16lu %s\n", val, id);
36273 }
36274@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
36275
36276 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
36277 for (op = 0; op < mcsop_last; op++) {
36278- count = atomic_long_read(&mcs_op_statistics[op].count);
36279- total = atomic_long_read(&mcs_op_statistics[op].total);
36280+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
36281+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
36282 max = mcs_op_statistics[op].max;
36283 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
36284 count ? total / count : 0, max);
36285diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
36286index 5c3ce24..4915ccb 100644
36287--- a/drivers/misc/sgi-gru/grutables.h
36288+++ b/drivers/misc/sgi-gru/grutables.h
36289@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
36290 * GRU statistics.
36291 */
36292 struct gru_stats_s {
36293- atomic_long_t vdata_alloc;
36294- atomic_long_t vdata_free;
36295- atomic_long_t gts_alloc;
36296- atomic_long_t gts_free;
36297- atomic_long_t gms_alloc;
36298- atomic_long_t gms_free;
36299- atomic_long_t gts_double_allocate;
36300- atomic_long_t assign_context;
36301- atomic_long_t assign_context_failed;
36302- atomic_long_t free_context;
36303- atomic_long_t load_user_context;
36304- atomic_long_t load_kernel_context;
36305- atomic_long_t lock_kernel_context;
36306- atomic_long_t unlock_kernel_context;
36307- atomic_long_t steal_user_context;
36308- atomic_long_t steal_kernel_context;
36309- atomic_long_t steal_context_failed;
36310- atomic_long_t nopfn;
36311- atomic_long_t asid_new;
36312- atomic_long_t asid_next;
36313- atomic_long_t asid_wrap;
36314- atomic_long_t asid_reuse;
36315- atomic_long_t intr;
36316- atomic_long_t intr_cbr;
36317- atomic_long_t intr_tfh;
36318- atomic_long_t intr_spurious;
36319- atomic_long_t intr_mm_lock_failed;
36320- atomic_long_t call_os;
36321- atomic_long_t call_os_wait_queue;
36322- atomic_long_t user_flush_tlb;
36323- atomic_long_t user_unload_context;
36324- atomic_long_t user_exception;
36325- atomic_long_t set_context_option;
36326- atomic_long_t check_context_retarget_intr;
36327- atomic_long_t check_context_unload;
36328- atomic_long_t tlb_dropin;
36329- atomic_long_t tlb_preload_page;
36330- atomic_long_t tlb_dropin_fail_no_asid;
36331- atomic_long_t tlb_dropin_fail_upm;
36332- atomic_long_t tlb_dropin_fail_invalid;
36333- atomic_long_t tlb_dropin_fail_range_active;
36334- atomic_long_t tlb_dropin_fail_idle;
36335- atomic_long_t tlb_dropin_fail_fmm;
36336- atomic_long_t tlb_dropin_fail_no_exception;
36337- atomic_long_t tfh_stale_on_fault;
36338- atomic_long_t mmu_invalidate_range;
36339- atomic_long_t mmu_invalidate_page;
36340- atomic_long_t flush_tlb;
36341- atomic_long_t flush_tlb_gru;
36342- atomic_long_t flush_tlb_gru_tgh;
36343- atomic_long_t flush_tlb_gru_zero_asid;
36344+ atomic_long_unchecked_t vdata_alloc;
36345+ atomic_long_unchecked_t vdata_free;
36346+ atomic_long_unchecked_t gts_alloc;
36347+ atomic_long_unchecked_t gts_free;
36348+ atomic_long_unchecked_t gms_alloc;
36349+ atomic_long_unchecked_t gms_free;
36350+ atomic_long_unchecked_t gts_double_allocate;
36351+ atomic_long_unchecked_t assign_context;
36352+ atomic_long_unchecked_t assign_context_failed;
36353+ atomic_long_unchecked_t free_context;
36354+ atomic_long_unchecked_t load_user_context;
36355+ atomic_long_unchecked_t load_kernel_context;
36356+ atomic_long_unchecked_t lock_kernel_context;
36357+ atomic_long_unchecked_t unlock_kernel_context;
36358+ atomic_long_unchecked_t steal_user_context;
36359+ atomic_long_unchecked_t steal_kernel_context;
36360+ atomic_long_unchecked_t steal_context_failed;
36361+ atomic_long_unchecked_t nopfn;
36362+ atomic_long_unchecked_t asid_new;
36363+ atomic_long_unchecked_t asid_next;
36364+ atomic_long_unchecked_t asid_wrap;
36365+ atomic_long_unchecked_t asid_reuse;
36366+ atomic_long_unchecked_t intr;
36367+ atomic_long_unchecked_t intr_cbr;
36368+ atomic_long_unchecked_t intr_tfh;
36369+ atomic_long_unchecked_t intr_spurious;
36370+ atomic_long_unchecked_t intr_mm_lock_failed;
36371+ atomic_long_unchecked_t call_os;
36372+ atomic_long_unchecked_t call_os_wait_queue;
36373+ atomic_long_unchecked_t user_flush_tlb;
36374+ atomic_long_unchecked_t user_unload_context;
36375+ atomic_long_unchecked_t user_exception;
36376+ atomic_long_unchecked_t set_context_option;
36377+ atomic_long_unchecked_t check_context_retarget_intr;
36378+ atomic_long_unchecked_t check_context_unload;
36379+ atomic_long_unchecked_t tlb_dropin;
36380+ atomic_long_unchecked_t tlb_preload_page;
36381+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
36382+ atomic_long_unchecked_t tlb_dropin_fail_upm;
36383+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
36384+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
36385+ atomic_long_unchecked_t tlb_dropin_fail_idle;
36386+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
36387+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
36388+ atomic_long_unchecked_t tfh_stale_on_fault;
36389+ atomic_long_unchecked_t mmu_invalidate_range;
36390+ atomic_long_unchecked_t mmu_invalidate_page;
36391+ atomic_long_unchecked_t flush_tlb;
36392+ atomic_long_unchecked_t flush_tlb_gru;
36393+ atomic_long_unchecked_t flush_tlb_gru_tgh;
36394+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
36395
36396- atomic_long_t copy_gpa;
36397- atomic_long_t read_gpa;
36398+ atomic_long_unchecked_t copy_gpa;
36399+ atomic_long_unchecked_t read_gpa;
36400
36401- atomic_long_t mesq_receive;
36402- atomic_long_t mesq_receive_none;
36403- atomic_long_t mesq_send;
36404- atomic_long_t mesq_send_failed;
36405- atomic_long_t mesq_noop;
36406- atomic_long_t mesq_send_unexpected_error;
36407- atomic_long_t mesq_send_lb_overflow;
36408- atomic_long_t mesq_send_qlimit_reached;
36409- atomic_long_t mesq_send_amo_nacked;
36410- atomic_long_t mesq_send_put_nacked;
36411- atomic_long_t mesq_page_overflow;
36412- atomic_long_t mesq_qf_locked;
36413- atomic_long_t mesq_qf_noop_not_full;
36414- atomic_long_t mesq_qf_switch_head_failed;
36415- atomic_long_t mesq_qf_unexpected_error;
36416- atomic_long_t mesq_noop_unexpected_error;
36417- atomic_long_t mesq_noop_lb_overflow;
36418- atomic_long_t mesq_noop_qlimit_reached;
36419- atomic_long_t mesq_noop_amo_nacked;
36420- atomic_long_t mesq_noop_put_nacked;
36421- atomic_long_t mesq_noop_page_overflow;
36422+ atomic_long_unchecked_t mesq_receive;
36423+ atomic_long_unchecked_t mesq_receive_none;
36424+ atomic_long_unchecked_t mesq_send;
36425+ atomic_long_unchecked_t mesq_send_failed;
36426+ atomic_long_unchecked_t mesq_noop;
36427+ atomic_long_unchecked_t mesq_send_unexpected_error;
36428+ atomic_long_unchecked_t mesq_send_lb_overflow;
36429+ atomic_long_unchecked_t mesq_send_qlimit_reached;
36430+ atomic_long_unchecked_t mesq_send_amo_nacked;
36431+ atomic_long_unchecked_t mesq_send_put_nacked;
36432+ atomic_long_unchecked_t mesq_page_overflow;
36433+ atomic_long_unchecked_t mesq_qf_locked;
36434+ atomic_long_unchecked_t mesq_qf_noop_not_full;
36435+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
36436+ atomic_long_unchecked_t mesq_qf_unexpected_error;
36437+ atomic_long_unchecked_t mesq_noop_unexpected_error;
36438+ atomic_long_unchecked_t mesq_noop_lb_overflow;
36439+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
36440+ atomic_long_unchecked_t mesq_noop_amo_nacked;
36441+ atomic_long_unchecked_t mesq_noop_put_nacked;
36442+ atomic_long_unchecked_t mesq_noop_page_overflow;
36443
36444 };
36445
36446@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
36447 tghop_invalidate, mcsop_last};
36448
36449 struct mcs_op_statistic {
36450- atomic_long_t count;
36451- atomic_long_t total;
36452+ atomic_long_unchecked_t count;
36453+ atomic_long_unchecked_t total;
36454 unsigned long max;
36455 };
36456
36457@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
36458
36459 #define STAT(id) do { \
36460 if (gru_options & OPT_STATS) \
36461- atomic_long_inc(&gru_stats.id); \
36462+ atomic_long_inc_unchecked(&gru_stats.id); \
36463 } while (0)
36464
36465 #ifdef CONFIG_SGI_GRU_DEBUG
36466diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
36467index c862cd4..0d176fe 100644
36468--- a/drivers/misc/sgi-xp/xp.h
36469+++ b/drivers/misc/sgi-xp/xp.h
36470@@ -288,7 +288,7 @@ struct xpc_interface {
36471 xpc_notify_func, void *);
36472 void (*received) (short, int, void *);
36473 enum xp_retval (*partid_to_nasids) (short, void *);
36474-};
36475+} __no_const;
36476
36477 extern struct xpc_interface xpc_interface;
36478
36479diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
36480index b94d5f7..7f494c5 100644
36481--- a/drivers/misc/sgi-xp/xpc.h
36482+++ b/drivers/misc/sgi-xp/xpc.h
36483@@ -835,6 +835,7 @@ struct xpc_arch_operations {
36484 void (*received_payload) (struct xpc_channel *, void *);
36485 void (*notify_senders_of_disconnect) (struct xpc_channel *);
36486 };
36487+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
36488
36489 /* struct xpc_partition act_state values (for XPC HB) */
36490
36491@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
36492 /* found in xpc_main.c */
36493 extern struct device *xpc_part;
36494 extern struct device *xpc_chan;
36495-extern struct xpc_arch_operations xpc_arch_ops;
36496+extern xpc_arch_operations_no_const xpc_arch_ops;
36497 extern int xpc_disengage_timelimit;
36498 extern int xpc_disengage_timedout;
36499 extern int xpc_activate_IRQ_rcvd;
36500diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
36501index d971817..33bdca5 100644
36502--- a/drivers/misc/sgi-xp/xpc_main.c
36503+++ b/drivers/misc/sgi-xp/xpc_main.c
36504@@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
36505 .notifier_call = xpc_system_die,
36506 };
36507
36508-struct xpc_arch_operations xpc_arch_ops;
36509+xpc_arch_operations_no_const xpc_arch_ops;
36510
36511 /*
36512 * Timer function to enforce the timelimit on the partition disengage.
36513@@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
36514
36515 if (((die_args->trapnr == X86_TRAP_MF) ||
36516 (die_args->trapnr == X86_TRAP_XF)) &&
36517- !user_mode_vm(die_args->regs))
36518+ !user_mode(die_args->regs))
36519 xpc_die_deactivate();
36520
36521 break;
36522diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
36523index a0e1720..ee63d0b 100644
36524--- a/drivers/mmc/core/mmc_ops.c
36525+++ b/drivers/mmc/core/mmc_ops.c
36526@@ -245,7 +245,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
36527 void *data_buf;
36528 int is_on_stack;
36529
36530- is_on_stack = object_is_on_stack(buf);
36531+ is_on_stack = object_starts_on_stack(buf);
36532 if (is_on_stack) {
36533 /*
36534 * dma onto stack is unsafe/nonportable, but callers to this
36535diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
36536index 53b8fd9..615b462 100644
36537--- a/drivers/mmc/host/dw_mmc.h
36538+++ b/drivers/mmc/host/dw_mmc.h
36539@@ -205,5 +205,5 @@ struct dw_mci_drv_data {
36540 int (*parse_dt)(struct dw_mci *host);
36541 int (*setup_bus)(struct dw_mci *host,
36542 struct device_node *slot_np, u8 bus_width);
36543-};
36544+} __do_const;
36545 #endif /* _DW_MMC_H_ */
36546diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
36547index c9ec725..178e79a 100644
36548--- a/drivers/mmc/host/sdhci-s3c.c
36549+++ b/drivers/mmc/host/sdhci-s3c.c
36550@@ -719,9 +719,11 @@ static int __devinit sdhci_s3c_probe(struct platform_device *pdev)
36551 * we can use overriding functions instead of default.
36552 */
36553 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
36554- sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
36555- sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
36556- sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
36557+ pax_open_kernel();
36558+ *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
36559+ *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
36560+ *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
36561+ pax_close_kernel();
36562 }
36563
36564 /* It supports additional host capabilities if needed */
36565diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
36566index a4eb8b5..8c0628f 100644
36567--- a/drivers/mtd/devices/doc2000.c
36568+++ b/drivers/mtd/devices/doc2000.c
36569@@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
36570
36571 /* The ECC will not be calculated correctly if less than 512 is written */
36572 /* DBB-
36573- if (len != 0x200 && eccbuf)
36574+ if (len != 0x200)
36575 printk(KERN_WARNING
36576 "ECC needs a full sector write (adr: %lx size %lx)\n",
36577 (long) to, (long) len);
36578diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
36579index e706a23..b3d262f 100644
36580--- a/drivers/mtd/nand/denali.c
36581+++ b/drivers/mtd/nand/denali.c
36582@@ -26,6 +26,7 @@
36583 #include <linux/pci.h>
36584 #include <linux/mtd/mtd.h>
36585 #include <linux/module.h>
36586+#include <linux/slab.h>
36587
36588 #include "denali.h"
36589
36590diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
36591index 51b9d6a..52af9a7 100644
36592--- a/drivers/mtd/nftlmount.c
36593+++ b/drivers/mtd/nftlmount.c
36594@@ -24,6 +24,7 @@
36595 #include <asm/errno.h>
36596 #include <linux/delay.h>
36597 #include <linux/slab.h>
36598+#include <linux/sched.h>
36599 #include <linux/mtd/mtd.h>
36600 #include <linux/mtd/nand.h>
36601 #include <linux/mtd/nftl.h>
36602diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
36603index 203ff9d..0968ca8 100644
36604--- a/drivers/net/ethernet/8390/ax88796.c
36605+++ b/drivers/net/ethernet/8390/ax88796.c
36606@@ -872,9 +872,11 @@ static int ax_probe(struct platform_device *pdev)
36607 if (ax->plat->reg_offsets)
36608 ei_local->reg_offset = ax->plat->reg_offsets;
36609 else {
36610+ resource_size_t _mem_size = mem_size;
36611+ do_div(_mem_size, 0x18);
36612 ei_local->reg_offset = ax->reg_offsets;
36613 for (ret = 0; ret < 0x18; ret++)
36614- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
36615+ ax->reg_offsets[ret] = _mem_size * ret;
36616 }
36617
36618 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
36619diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
36620index 9c5ea6c..eaad276 100644
36621--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
36622+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
36623@@ -1046,7 +1046,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
36624 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
36625 {
36626 /* RX_MODE controlling object */
36627- bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
36628+ bnx2x_init_rx_mode_obj(bp);
36629
36630 /* multicast configuration controlling object */
36631 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
36632diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
36633index 614981c..11216c7 100644
36634--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
36635+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
36636@@ -2375,15 +2375,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
36637 return rc;
36638 }
36639
36640-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
36641- struct bnx2x_rx_mode_obj *o)
36642+void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
36643 {
36644 if (CHIP_IS_E1x(bp)) {
36645- o->wait_comp = bnx2x_empty_rx_mode_wait;
36646- o->config_rx_mode = bnx2x_set_rx_mode_e1x;
36647+ bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
36648+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
36649 } else {
36650- o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
36651- o->config_rx_mode = bnx2x_set_rx_mode_e2;
36652+ bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
36653+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
36654 }
36655 }
36656
36657diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
36658index acf2fe4..efb96df 100644
36659--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
36660+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
36661@@ -1281,8 +1281,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
36662
36663 /********************* RX MODE ****************/
36664
36665-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
36666- struct bnx2x_rx_mode_obj *o);
36667+void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
36668
36669 /**
36670 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
36671diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
36672index d9308c32..d87b824 100644
36673--- a/drivers/net/ethernet/broadcom/tg3.h
36674+++ b/drivers/net/ethernet/broadcom/tg3.h
36675@@ -140,6 +140,7 @@
36676 #define CHIPREV_ID_5750_A0 0x4000
36677 #define CHIPREV_ID_5750_A1 0x4001
36678 #define CHIPREV_ID_5750_A3 0x4003
36679+#define CHIPREV_ID_5750_C1 0x4201
36680 #define CHIPREV_ID_5750_C2 0x4202
36681 #define CHIPREV_ID_5752_A0_HW 0x5000
36682 #define CHIPREV_ID_5752_A0 0x6000
36683diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
36684index 8cffcdf..aadf043 100644
36685--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
36686+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
36687@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
36688 */
36689 struct l2t_skb_cb {
36690 arp_failure_handler_func arp_failure_handler;
36691-};
36692+} __no_const;
36693
36694 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
36695
36696diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
36697index f879e92..726f20f 100644
36698--- a/drivers/net/ethernet/dec/tulip/de4x5.c
36699+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
36700@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
36701 for (i=0; i<ETH_ALEN; i++) {
36702 tmp.addr[i] = dev->dev_addr[i];
36703 }
36704- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
36705+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
36706 break;
36707
36708 case DE4X5_SET_HWADDR: /* Set the hardware address */
36709@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
36710 spin_lock_irqsave(&lp->lock, flags);
36711 memcpy(&statbuf, &lp->pktStats, ioc->len);
36712 spin_unlock_irqrestore(&lp->lock, flags);
36713- if (copy_to_user(ioc->data, &statbuf, ioc->len))
36714+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
36715 return -EFAULT;
36716 break;
36717 }
36718diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
36719index d1b6cc5..cde0d97 100644
36720--- a/drivers/net/ethernet/emulex/benet/be_main.c
36721+++ b/drivers/net/ethernet/emulex/benet/be_main.c
36722@@ -403,7 +403,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
36723
36724 if (wrapped)
36725 newacc += 65536;
36726- ACCESS_ONCE(*acc) = newacc;
36727+ ACCESS_ONCE_RW(*acc) = newacc;
36728 }
36729
36730 void be_parse_stats(struct be_adapter *adapter)
36731diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
36732index 74d749e..eefb1bd 100644
36733--- a/drivers/net/ethernet/faraday/ftgmac100.c
36734+++ b/drivers/net/ethernet/faraday/ftgmac100.c
36735@@ -31,6 +31,8 @@
36736 #include <linux/netdevice.h>
36737 #include <linux/phy.h>
36738 #include <linux/platform_device.h>
36739+#include <linux/interrupt.h>
36740+#include <linux/irqreturn.h>
36741 #include <net/ip.h>
36742
36743 #include "ftgmac100.h"
36744diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
36745index b901a01..1ff32ee 100644
36746--- a/drivers/net/ethernet/faraday/ftmac100.c
36747+++ b/drivers/net/ethernet/faraday/ftmac100.c
36748@@ -31,6 +31,8 @@
36749 #include <linux/module.h>
36750 #include <linux/netdevice.h>
36751 #include <linux/platform_device.h>
36752+#include <linux/interrupt.h>
36753+#include <linux/irqreturn.h>
36754
36755 #include "ftmac100.h"
36756
36757diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
36758index d929131..aed108f 100644
36759--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
36760+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
36761@@ -865,7 +865,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
36762 /* store the new cycle speed */
36763 adapter->cycle_speed = cycle_speed;
36764
36765- ACCESS_ONCE(adapter->base_incval) = incval;
36766+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
36767 smp_mb();
36768
36769 /* grab the ptp lock */
36770diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
36771index c2e420a..26a75e0 100644
36772--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
36773+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
36774@@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
36775 struct __vxge_hw_fifo *fifo;
36776 struct vxge_hw_fifo_config *config;
36777 u32 txdl_size, txdl_per_memblock;
36778- struct vxge_hw_mempool_cbs fifo_mp_callback;
36779+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
36780+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
36781+ };
36782+
36783 struct __vxge_hw_virtualpath *vpath;
36784
36785 if ((vp == NULL) || (attr == NULL)) {
36786@@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
36787 goto exit;
36788 }
36789
36790- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
36791-
36792 fifo->mempool =
36793 __vxge_hw_mempool_create(vpath->hldev,
36794 fifo->config->memblock_size,
36795diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
36796index 927aa33..a6c2518 100644
36797--- a/drivers/net/ethernet/realtek/r8169.c
36798+++ b/drivers/net/ethernet/realtek/r8169.c
36799@@ -747,22 +747,22 @@ struct rtl8169_private {
36800 struct mdio_ops {
36801 void (*write)(struct rtl8169_private *, int, int);
36802 int (*read)(struct rtl8169_private *, int);
36803- } mdio_ops;
36804+ } __no_const mdio_ops;
36805
36806 struct pll_power_ops {
36807 void (*down)(struct rtl8169_private *);
36808 void (*up)(struct rtl8169_private *);
36809- } pll_power_ops;
36810+ } __no_const pll_power_ops;
36811
36812 struct jumbo_ops {
36813 void (*enable)(struct rtl8169_private *);
36814 void (*disable)(struct rtl8169_private *);
36815- } jumbo_ops;
36816+ } __no_const jumbo_ops;
36817
36818 struct csi_ops {
36819 void (*write)(struct rtl8169_private *, int, int);
36820 u32 (*read)(struct rtl8169_private *, int);
36821- } csi_ops;
36822+ } __no_const csi_ops;
36823
36824 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
36825 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
36826diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
36827index 0767043f..08c2553 100644
36828--- a/drivers/net/ethernet/sfc/ptp.c
36829+++ b/drivers/net/ethernet/sfc/ptp.c
36830@@ -553,7 +553,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
36831 (u32)((u64)ptp->start.dma_addr >> 32));
36832
36833 /* Clear flag that signals MC ready */
36834- ACCESS_ONCE(*start) = 0;
36835+ ACCESS_ONCE_RW(*start) = 0;
36836 efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
36837 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
36838
36839diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
36840index 0c74a70..3bc6f68 100644
36841--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
36842+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
36843@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
36844
36845 writel(value, ioaddr + MMC_CNTRL);
36846
36847- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
36848- MMC_CNTRL, value);
36849+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
36850+// MMC_CNTRL, value);
36851 }
36852
36853 /* To mask all all interrupts.*/
36854diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
36855index 5fd6f46..ee1f265 100644
36856--- a/drivers/net/hyperv/hyperv_net.h
36857+++ b/drivers/net/hyperv/hyperv_net.h
36858@@ -101,7 +101,7 @@ struct rndis_device {
36859
36860 enum rndis_device_state state;
36861 bool link_state;
36862- atomic_t new_req_id;
36863+ atomic_unchecked_t new_req_id;
36864
36865 spinlock_t request_lock;
36866 struct list_head req_list;
36867diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
36868index 928148c..d83298e 100644
36869--- a/drivers/net/hyperv/rndis_filter.c
36870+++ b/drivers/net/hyperv/rndis_filter.c
36871@@ -107,7 +107,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
36872 * template
36873 */
36874 set = &rndis_msg->msg.set_req;
36875- set->req_id = atomic_inc_return(&dev->new_req_id);
36876+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
36877
36878 /* Add to the request list */
36879 spin_lock_irqsave(&dev->request_lock, flags);
36880@@ -760,7 +760,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
36881
36882 /* Setup the rndis set */
36883 halt = &request->request_msg.msg.halt_req;
36884- halt->req_id = atomic_inc_return(&dev->new_req_id);
36885+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
36886
36887 /* Ignore return since this msg is optional. */
36888 rndis_filter_send_request(dev, request);
36889diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
36890index 7d39add..037e1da 100644
36891--- a/drivers/net/ieee802154/fakehard.c
36892+++ b/drivers/net/ieee802154/fakehard.c
36893@@ -386,7 +386,7 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
36894 phy->transmit_power = 0xbf;
36895
36896 dev->netdev_ops = &fake_ops;
36897- dev->ml_priv = &fake_mlme;
36898+ dev->ml_priv = (void *)&fake_mlme;
36899
36900 priv = netdev_priv(dev);
36901 priv->phy = phy;
36902diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
36903index 0f0f9ce..0ca5819 100644
36904--- a/drivers/net/macvtap.c
36905+++ b/drivers/net/macvtap.c
36906@@ -1100,7 +1100,7 @@ static int macvtap_device_event(struct notifier_block *unused,
36907 return NOTIFY_DONE;
36908 }
36909
36910-static struct notifier_block macvtap_notifier_block __read_mostly = {
36911+static struct notifier_block macvtap_notifier_block = {
36912 .notifier_call = macvtap_device_event,
36913 };
36914
36915diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
36916index daec9b0..6428fcb 100644
36917--- a/drivers/net/phy/mdio-bitbang.c
36918+++ b/drivers/net/phy/mdio-bitbang.c
36919@@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
36920 struct mdiobb_ctrl *ctrl = bus->priv;
36921
36922 module_put(ctrl->ops->owner);
36923+ mdiobus_unregister(bus);
36924 mdiobus_free(bus);
36925 }
36926 EXPORT_SYMBOL(free_mdio_bitbang);
36927diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
36928index eb3f5ce..d773730 100644
36929--- a/drivers/net/ppp/ppp_generic.c
36930+++ b/drivers/net/ppp/ppp_generic.c
36931@@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
36932 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
36933 struct ppp_stats stats;
36934 struct ppp_comp_stats cstats;
36935- char *vers;
36936
36937 switch (cmd) {
36938 case SIOCGPPPSTATS:
36939@@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
36940 break;
36941
36942 case SIOCGPPPVER:
36943- vers = PPP_VERSION;
36944- if (copy_to_user(addr, vers, strlen(vers) + 1))
36945+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
36946 break;
36947 err = 0;
36948 break;
36949diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
36950index ad86660..9fd0884 100644
36951--- a/drivers/net/team/team.c
36952+++ b/drivers/net/team/team.c
36953@@ -2601,7 +2601,7 @@ static int team_device_event(struct notifier_block *unused,
36954 return NOTIFY_DONE;
36955 }
36956
36957-static struct notifier_block team_notifier_block __read_mostly = {
36958+static struct notifier_block team_notifier_block = {
36959 .notifier_call = team_device_event,
36960 };
36961
36962diff --git a/drivers/net/tun.c b/drivers/net/tun.c
36963index 0873cdc..ddb178e 100644
36964--- a/drivers/net/tun.c
36965+++ b/drivers/net/tun.c
36966@@ -1374,7 +1374,7 @@ static int set_offload(struct tun_struct *tun, unsigned long arg)
36967 }
36968
36969 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
36970- unsigned long arg, int ifreq_len)
36971+ unsigned long arg, size_t ifreq_len)
36972 {
36973 struct tun_file *tfile = file->private_data;
36974 struct tun_struct *tun;
36975@@ -1387,6 +1387,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
36976 int vnet_hdr_sz;
36977 int ret;
36978
36979+ if (ifreq_len > sizeof ifr)
36980+ return -EFAULT;
36981+
36982 if (cmd == TUNSETIFF || _IOC_TYPE(cmd) == 0x89) {
36983 if (copy_from_user(&ifr, argp, ifreq_len))
36984 return -EFAULT;
36985diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
36986index 605a4ba..a883dd1 100644
36987--- a/drivers/net/usb/hso.c
36988+++ b/drivers/net/usb/hso.c
36989@@ -71,7 +71,7 @@
36990 #include <asm/byteorder.h>
36991 #include <linux/serial_core.h>
36992 #include <linux/serial.h>
36993-
36994+#include <asm/local.h>
36995
36996 #define MOD_AUTHOR "Option Wireless"
36997 #define MOD_DESCRIPTION "USB High Speed Option driver"
36998@@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
36999 struct urb *urb;
37000
37001 urb = serial->rx_urb[0];
37002- if (serial->port.count > 0) {
37003+ if (atomic_read(&serial->port.count) > 0) {
37004 count = put_rxbuf_data(urb, serial);
37005 if (count == -1)
37006 return;
37007@@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
37008 DUMP1(urb->transfer_buffer, urb->actual_length);
37009
37010 /* Anyone listening? */
37011- if (serial->port.count == 0)
37012+ if (atomic_read(&serial->port.count) == 0)
37013 return;
37014
37015 if (status == 0) {
37016@@ -1298,8 +1298,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
37017 tty_port_tty_set(&serial->port, tty);
37018
37019 /* check for port already opened, if not set the termios */
37020- serial->port.count++;
37021- if (serial->port.count == 1) {
37022+ if (atomic_inc_return(&serial->port.count) == 1) {
37023 serial->rx_state = RX_IDLE;
37024 /* Force default termio settings */
37025 _hso_serial_set_termios(tty, NULL);
37026@@ -1311,7 +1310,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
37027 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
37028 if (result) {
37029 hso_stop_serial_device(serial->parent);
37030- serial->port.count--;
37031+ atomic_dec(&serial->port.count);
37032 kref_put(&serial->parent->ref, hso_serial_ref_free);
37033 }
37034 } else {
37035@@ -1348,10 +1347,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
37036
37037 /* reset the rts and dtr */
37038 /* do the actual close */
37039- serial->port.count--;
37040+ atomic_dec(&serial->port.count);
37041
37042- if (serial->port.count <= 0) {
37043- serial->port.count = 0;
37044+ if (atomic_read(&serial->port.count) <= 0) {
37045+ atomic_set(&serial->port.count, 0);
37046 tty_port_tty_set(&serial->port, NULL);
37047 if (!usb_gone)
37048 hso_stop_serial_device(serial->parent);
37049@@ -1427,7 +1426,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
37050
37051 /* the actual setup */
37052 spin_lock_irqsave(&serial->serial_lock, flags);
37053- if (serial->port.count)
37054+ if (atomic_read(&serial->port.count))
37055 _hso_serial_set_termios(tty, old);
37056 else
37057 tty->termios = *old;
37058@@ -1886,7 +1885,7 @@ static void intr_callback(struct urb *urb)
37059 D1("Pending read interrupt on port %d\n", i);
37060 spin_lock(&serial->serial_lock);
37061 if (serial->rx_state == RX_IDLE &&
37062- serial->port.count > 0) {
37063+ atomic_read(&serial->port.count) > 0) {
37064 /* Setup and send a ctrl req read on
37065 * port i */
37066 if (!serial->rx_urb_filled[0]) {
37067@@ -3078,7 +3077,7 @@ static int hso_resume(struct usb_interface *iface)
37068 /* Start all serial ports */
37069 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
37070 if (serial_table[i] && (serial_table[i]->interface == iface)) {
37071- if (dev2ser(serial_table[i])->port.count) {
37072+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
37073 result =
37074 hso_start_serial_device(serial_table[i], GFP_NOIO);
37075 hso_kick_transmit(dev2ser(serial_table[i]));
37076diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
37077index 8d78253..bebbb68 100644
37078--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
37079+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
37080@@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37081 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
37082 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
37083
37084- ACCESS_ONCE(ads->ds_link) = i->link;
37085- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
37086+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
37087+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
37088
37089 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
37090 ctl6 = SM(i->keytype, AR_EncrType);
37091@@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37092
37093 if ((i->is_first || i->is_last) &&
37094 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
37095- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
37096+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
37097 | set11nTries(i->rates, 1)
37098 | set11nTries(i->rates, 2)
37099 | set11nTries(i->rates, 3)
37100 | (i->dur_update ? AR_DurUpdateEna : 0)
37101 | SM(0, AR_BurstDur);
37102
37103- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
37104+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
37105 | set11nRate(i->rates, 1)
37106 | set11nRate(i->rates, 2)
37107 | set11nRate(i->rates, 3);
37108 } else {
37109- ACCESS_ONCE(ads->ds_ctl2) = 0;
37110- ACCESS_ONCE(ads->ds_ctl3) = 0;
37111+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
37112+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
37113 }
37114
37115 if (!i->is_first) {
37116- ACCESS_ONCE(ads->ds_ctl0) = 0;
37117- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
37118- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
37119+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
37120+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
37121+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
37122 return;
37123 }
37124
37125@@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37126 break;
37127 }
37128
37129- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
37130+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
37131 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
37132 | SM(i->txpower, AR_XmitPower)
37133 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
37134@@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37135 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
37136 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
37137
37138- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
37139- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
37140+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
37141+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
37142
37143 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
37144 return;
37145
37146- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
37147+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
37148 | set11nPktDurRTSCTS(i->rates, 1);
37149
37150- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
37151+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
37152 | set11nPktDurRTSCTS(i->rates, 3);
37153
37154- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
37155+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
37156 | set11nRateFlags(i->rates, 1)
37157 | set11nRateFlags(i->rates, 2)
37158 | set11nRateFlags(i->rates, 3)
37159diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
37160index 301bf72..3f5654f 100644
37161--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
37162+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
37163@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37164 (i->qcu << AR_TxQcuNum_S) | desc_len;
37165
37166 checksum += val;
37167- ACCESS_ONCE(ads->info) = val;
37168+ ACCESS_ONCE_RW(ads->info) = val;
37169
37170 checksum += i->link;
37171- ACCESS_ONCE(ads->link) = i->link;
37172+ ACCESS_ONCE_RW(ads->link) = i->link;
37173
37174 checksum += i->buf_addr[0];
37175- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
37176+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
37177 checksum += i->buf_addr[1];
37178- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
37179+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
37180 checksum += i->buf_addr[2];
37181- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
37182+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
37183 checksum += i->buf_addr[3];
37184- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
37185+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
37186
37187 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
37188- ACCESS_ONCE(ads->ctl3) = val;
37189+ ACCESS_ONCE_RW(ads->ctl3) = val;
37190 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
37191- ACCESS_ONCE(ads->ctl5) = val;
37192+ ACCESS_ONCE_RW(ads->ctl5) = val;
37193 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
37194- ACCESS_ONCE(ads->ctl7) = val;
37195+ ACCESS_ONCE_RW(ads->ctl7) = val;
37196 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
37197- ACCESS_ONCE(ads->ctl9) = val;
37198+ ACCESS_ONCE_RW(ads->ctl9) = val;
37199
37200 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
37201- ACCESS_ONCE(ads->ctl10) = checksum;
37202+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
37203
37204 if (i->is_first || i->is_last) {
37205- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
37206+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
37207 | set11nTries(i->rates, 1)
37208 | set11nTries(i->rates, 2)
37209 | set11nTries(i->rates, 3)
37210 | (i->dur_update ? AR_DurUpdateEna : 0)
37211 | SM(0, AR_BurstDur);
37212
37213- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
37214+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
37215 | set11nRate(i->rates, 1)
37216 | set11nRate(i->rates, 2)
37217 | set11nRate(i->rates, 3);
37218 } else {
37219- ACCESS_ONCE(ads->ctl13) = 0;
37220- ACCESS_ONCE(ads->ctl14) = 0;
37221+ ACCESS_ONCE_RW(ads->ctl13) = 0;
37222+ ACCESS_ONCE_RW(ads->ctl14) = 0;
37223 }
37224
37225 ads->ctl20 = 0;
37226@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37227
37228 ctl17 = SM(i->keytype, AR_EncrType);
37229 if (!i->is_first) {
37230- ACCESS_ONCE(ads->ctl11) = 0;
37231- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
37232- ACCESS_ONCE(ads->ctl15) = 0;
37233- ACCESS_ONCE(ads->ctl16) = 0;
37234- ACCESS_ONCE(ads->ctl17) = ctl17;
37235- ACCESS_ONCE(ads->ctl18) = 0;
37236- ACCESS_ONCE(ads->ctl19) = 0;
37237+ ACCESS_ONCE_RW(ads->ctl11) = 0;
37238+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
37239+ ACCESS_ONCE_RW(ads->ctl15) = 0;
37240+ ACCESS_ONCE_RW(ads->ctl16) = 0;
37241+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
37242+ ACCESS_ONCE_RW(ads->ctl18) = 0;
37243+ ACCESS_ONCE_RW(ads->ctl19) = 0;
37244 return;
37245 }
37246
37247- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
37248+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
37249 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
37250 | SM(i->txpower, AR_XmitPower)
37251 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
37252@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37253 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
37254 ctl12 |= SM(val, AR_PAPRDChainMask);
37255
37256- ACCESS_ONCE(ads->ctl12) = ctl12;
37257- ACCESS_ONCE(ads->ctl17) = ctl17;
37258+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
37259+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
37260
37261- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
37262+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
37263 | set11nPktDurRTSCTS(i->rates, 1);
37264
37265- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
37266+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
37267 | set11nPktDurRTSCTS(i->rates, 3);
37268
37269- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
37270+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
37271 | set11nRateFlags(i->rates, 1)
37272 | set11nRateFlags(i->rates, 2)
37273 | set11nRateFlags(i->rates, 3)
37274 | SM(i->rtscts_rate, AR_RTSCTSRate);
37275
37276- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
37277+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
37278 }
37279
37280 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
37281diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
37282index dbc1b7a..67e2ca2 100644
37283--- a/drivers/net/wireless/ath/ath9k/hw.h
37284+++ b/drivers/net/wireless/ath/ath9k/hw.h
37285@@ -657,7 +657,7 @@ struct ath_hw_private_ops {
37286
37287 /* ANI */
37288 void (*ani_cache_ini_regs)(struct ath_hw *ah);
37289-};
37290+} __no_const;
37291
37292 /**
37293 * struct ath_hw_ops - callbacks used by hardware code and driver code
37294@@ -687,7 +687,7 @@ struct ath_hw_ops {
37295 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
37296 struct ath_hw_antcomb_conf *antconf);
37297 void (*antctrl_shared_chain_lnadiv)(struct ath_hw *hw, bool enable);
37298-};
37299+} __no_const;
37300
37301 struct ath_nf_limits {
37302 s16 max;
37303diff --git a/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.h b/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.h
37304index 71ced17..cd82b12 100644
37305--- a/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.h
37306+++ b/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.h
37307@@ -184,7 +184,7 @@ struct brcmf_cfg80211_event_loop {
37308 struct net_device *ndev,
37309 const struct brcmf_event_msg *e,
37310 void *data);
37311-};
37312+} __no_const;
37313
37314 /* basic structure of scan request */
37315 struct brcmf_cfg80211_scan_req {
37316@@ -239,7 +239,7 @@ struct brcmf_cfg80211_profile {
37317 struct brcmf_cfg80211_iscan_eloop {
37318 s32 (*handler[WL_SCAN_ERSULTS_LAST])
37319 (struct brcmf_cfg80211_info *cfg);
37320-};
37321+} __no_const;
37322
37323 /* dongle iscan controller */
37324 struct brcmf_cfg80211_iscan_ctrl {
37325diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
37326index e252acb..6ad1e65 100644
37327--- a/drivers/net/wireless/iwlegacy/3945-mac.c
37328+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
37329@@ -3615,7 +3615,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
37330 */
37331 if (il3945_mod_params.disable_hw_scan) {
37332 D_INFO("Disabling hw_scan\n");
37333- il3945_mac_ops.hw_scan = NULL;
37334+ pax_open_kernel();
37335+ *(void **)&il3945_mac_ops.hw_scan = NULL;
37336+ pax_close_kernel();
37337 }
37338
37339 D_INFO("*** LOAD DRIVER ***\n");
37340diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
37341index 1a98fa3..51e6661 100644
37342--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
37343+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
37344@@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
37345 {
37346 struct iwl_priv *priv = file->private_data;
37347 char buf[64];
37348- int buf_size;
37349+ size_t buf_size;
37350 u32 offset, len;
37351
37352 memset(buf, 0, sizeof(buf));
37353@@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
37354 struct iwl_priv *priv = file->private_data;
37355
37356 char buf[8];
37357- int buf_size;
37358+ size_t buf_size;
37359 u32 reset_flag;
37360
37361 memset(buf, 0, sizeof(buf));
37362@@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
37363 {
37364 struct iwl_priv *priv = file->private_data;
37365 char buf[8];
37366- int buf_size;
37367+ size_t buf_size;
37368 int ht40;
37369
37370 memset(buf, 0, sizeof(buf));
37371@@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
37372 {
37373 struct iwl_priv *priv = file->private_data;
37374 char buf[8];
37375- int buf_size;
37376+ size_t buf_size;
37377 int value;
37378
37379 memset(buf, 0, sizeof(buf));
37380@@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
37381 {
37382 struct iwl_priv *priv = file->private_data;
37383 char buf[8];
37384- int buf_size;
37385+ size_t buf_size;
37386 int clear;
37387
37388 memset(buf, 0, sizeof(buf));
37389@@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
37390 {
37391 struct iwl_priv *priv = file->private_data;
37392 char buf[8];
37393- int buf_size;
37394+ size_t buf_size;
37395 int trace;
37396
37397 memset(buf, 0, sizeof(buf));
37398@@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
37399 {
37400 struct iwl_priv *priv = file->private_data;
37401 char buf[8];
37402- int buf_size;
37403+ size_t buf_size;
37404 int missed;
37405
37406 memset(buf, 0, sizeof(buf));
37407@@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
37408
37409 struct iwl_priv *priv = file->private_data;
37410 char buf[8];
37411- int buf_size;
37412+ size_t buf_size;
37413 int plcp;
37414
37415 memset(buf, 0, sizeof(buf));
37416@@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
37417
37418 struct iwl_priv *priv = file->private_data;
37419 char buf[8];
37420- int buf_size;
37421+ size_t buf_size;
37422 int flush;
37423
37424 memset(buf, 0, sizeof(buf));
37425@@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
37426
37427 struct iwl_priv *priv = file->private_data;
37428 char buf[8];
37429- int buf_size;
37430+ size_t buf_size;
37431 int rts;
37432
37433 if (!priv->cfg->ht_params)
37434@@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
37435 {
37436 struct iwl_priv *priv = file->private_data;
37437 char buf[8];
37438- int buf_size;
37439+ size_t buf_size;
37440
37441 memset(buf, 0, sizeof(buf));
37442 buf_size = min(count, sizeof(buf) - 1);
37443@@ -2256,7 +2256,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
37444 struct iwl_priv *priv = file->private_data;
37445 u32 event_log_flag;
37446 char buf[8];
37447- int buf_size;
37448+ size_t buf_size;
37449
37450 /* check that the interface is up */
37451 if (!iwl_is_ready(priv))
37452@@ -2310,7 +2310,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
37453 struct iwl_priv *priv = file->private_data;
37454 char buf[8];
37455 u32 calib_disabled;
37456- int buf_size;
37457+ size_t buf_size;
37458
37459 memset(buf, 0, sizeof(buf));
37460 buf_size = min(count, sizeof(buf) - 1);
37461diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
37462index fe0fffd..b4c5724 100644
37463--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
37464+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
37465@@ -1967,7 +1967,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
37466 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
37467
37468 char buf[8];
37469- int buf_size;
37470+ size_t buf_size;
37471 u32 reset_flag;
37472
37473 memset(buf, 0, sizeof(buf));
37474@@ -1988,7 +1988,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
37475 {
37476 struct iwl_trans *trans = file->private_data;
37477 char buf[8];
37478- int buf_size;
37479+ size_t buf_size;
37480 int csr;
37481
37482 memset(buf, 0, sizeof(buf));
37483diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
37484index 429ca32..f86236b 100644
37485--- a/drivers/net/wireless/mac80211_hwsim.c
37486+++ b/drivers/net/wireless/mac80211_hwsim.c
37487@@ -1751,9 +1751,11 @@ static int __init init_mac80211_hwsim(void)
37488 return -EINVAL;
37489
37490 if (fake_hw_scan) {
37491- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
37492- mac80211_hwsim_ops.sw_scan_start = NULL;
37493- mac80211_hwsim_ops.sw_scan_complete = NULL;
37494+ pax_open_kernel();
37495+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
37496+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
37497+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
37498+ pax_close_kernel();
37499 }
37500
37501 spin_lock_init(&hwsim_radio_lock);
37502diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
37503index bd1f0cb..db85ab0 100644
37504--- a/drivers/net/wireless/rndis_wlan.c
37505+++ b/drivers/net/wireless/rndis_wlan.c
37506@@ -1235,7 +1235,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
37507
37508 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
37509
37510- if (rts_threshold < 0 || rts_threshold > 2347)
37511+ if (rts_threshold > 2347)
37512 rts_threshold = 2347;
37513
37514 tmp = cpu_to_le32(rts_threshold);
37515diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
37516index 0751b35..246ba3e 100644
37517--- a/drivers/net/wireless/rt2x00/rt2x00.h
37518+++ b/drivers/net/wireless/rt2x00/rt2x00.h
37519@@ -398,7 +398,7 @@ struct rt2x00_intf {
37520 * for hardware which doesn't support hardware
37521 * sequence counting.
37522 */
37523- atomic_t seqno;
37524+ atomic_unchecked_t seqno;
37525 };
37526
37527 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
37528diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
37529index e488b94..14b6a0c 100644
37530--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
37531+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
37532@@ -240,9 +240,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
37533 * sequence counter given by mac80211.
37534 */
37535 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
37536- seqno = atomic_add_return(0x10, &intf->seqno);
37537+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
37538 else
37539- seqno = atomic_read(&intf->seqno);
37540+ seqno = atomic_read_unchecked(&intf->seqno);
37541
37542 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
37543 hdr->seq_ctrl |= cpu_to_le16(seqno);
37544diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
37545index e2750a1..797e179 100644
37546--- a/drivers/net/wireless/ti/wl1251/sdio.c
37547+++ b/drivers/net/wireless/ti/wl1251/sdio.c
37548@@ -269,13 +269,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
37549
37550 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
37551
37552- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
37553- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
37554+ pax_open_kernel();
37555+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
37556+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
37557+ pax_close_kernel();
37558
37559 wl1251_info("using dedicated interrupt line");
37560 } else {
37561- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
37562- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
37563+ pax_open_kernel();
37564+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
37565+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
37566+ pax_close_kernel();
37567
37568 wl1251_info("using SDIO interrupt");
37569 }
37570diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
37571index dadf1db..d9db7a7 100644
37572--- a/drivers/net/wireless/ti/wl12xx/main.c
37573+++ b/drivers/net/wireless/ti/wl12xx/main.c
37574@@ -644,7 +644,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
37575 sizeof(wl->conf.mem));
37576
37577 /* read data preparation is only needed by wl127x */
37578- wl->ops->prepare_read = wl127x_prepare_read;
37579+ pax_open_kernel();
37580+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
37581+ pax_close_kernel();
37582
37583 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER, WL127X_IFTYPE_VER,
37584 WL127X_MAJOR_VER, WL127X_SUBTYPE_VER,
37585@@ -665,7 +667,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
37586 sizeof(wl->conf.mem));
37587
37588 /* read data preparation is only needed by wl127x */
37589- wl->ops->prepare_read = wl127x_prepare_read;
37590+ pax_open_kernel();
37591+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
37592+ pax_close_kernel();
37593
37594 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER, WL127X_IFTYPE_VER,
37595 WL127X_MAJOR_VER, WL127X_SUBTYPE_VER,
37596diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
37597index a39682a..1e8220c 100644
37598--- a/drivers/net/wireless/ti/wl18xx/main.c
37599+++ b/drivers/net/wireless/ti/wl18xx/main.c
37600@@ -1489,8 +1489,10 @@ static int wl18xx_setup(struct wl1271 *wl)
37601 }
37602
37603 if (!checksum_param) {
37604- wl18xx_ops.set_rx_csum = NULL;
37605- wl18xx_ops.init_vif = NULL;
37606+ pax_open_kernel();
37607+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
37608+ *(void **)&wl18xx_ops.init_vif = NULL;
37609+ pax_close_kernel();
37610 }
37611
37612 /* Enable 11a Band only if we have 5G antennas */
37613diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
37614index d93b2b6..ae50401 100644
37615--- a/drivers/oprofile/buffer_sync.c
37616+++ b/drivers/oprofile/buffer_sync.c
37617@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
37618 if (cookie == NO_COOKIE)
37619 offset = pc;
37620 if (cookie == INVALID_COOKIE) {
37621- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
37622+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
37623 offset = pc;
37624 }
37625 if (cookie != last_cookie) {
37626@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
37627 /* add userspace sample */
37628
37629 if (!mm) {
37630- atomic_inc(&oprofile_stats.sample_lost_no_mm);
37631+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
37632 return 0;
37633 }
37634
37635 cookie = lookup_dcookie(mm, s->eip, &offset);
37636
37637 if (cookie == INVALID_COOKIE) {
37638- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
37639+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
37640 return 0;
37641 }
37642
37643@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
37644 /* ignore backtraces if failed to add a sample */
37645 if (state == sb_bt_start) {
37646 state = sb_bt_ignore;
37647- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
37648+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
37649 }
37650 }
37651 release_mm(mm);
37652diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
37653index c0cc4e7..44d4e54 100644
37654--- a/drivers/oprofile/event_buffer.c
37655+++ b/drivers/oprofile/event_buffer.c
37656@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
37657 }
37658
37659 if (buffer_pos == buffer_size) {
37660- atomic_inc(&oprofile_stats.event_lost_overflow);
37661+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
37662 return;
37663 }
37664
37665diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
37666index ed2c3ec..deda85a 100644
37667--- a/drivers/oprofile/oprof.c
37668+++ b/drivers/oprofile/oprof.c
37669@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
37670 if (oprofile_ops.switch_events())
37671 return;
37672
37673- atomic_inc(&oprofile_stats.multiplex_counter);
37674+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
37675 start_switch_worker();
37676 }
37677
37678diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
37679index 917d28e..d62d981 100644
37680--- a/drivers/oprofile/oprofile_stats.c
37681+++ b/drivers/oprofile/oprofile_stats.c
37682@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
37683 cpu_buf->sample_invalid_eip = 0;
37684 }
37685
37686- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
37687- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
37688- atomic_set(&oprofile_stats.event_lost_overflow, 0);
37689- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
37690- atomic_set(&oprofile_stats.multiplex_counter, 0);
37691+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
37692+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
37693+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
37694+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
37695+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
37696 }
37697
37698
37699diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
37700index 38b6fc0..b5cbfce 100644
37701--- a/drivers/oprofile/oprofile_stats.h
37702+++ b/drivers/oprofile/oprofile_stats.h
37703@@ -13,11 +13,11 @@
37704 #include <linux/atomic.h>
37705
37706 struct oprofile_stat_struct {
37707- atomic_t sample_lost_no_mm;
37708- atomic_t sample_lost_no_mapping;
37709- atomic_t bt_lost_no_mapping;
37710- atomic_t event_lost_overflow;
37711- atomic_t multiplex_counter;
37712+ atomic_unchecked_t sample_lost_no_mm;
37713+ atomic_unchecked_t sample_lost_no_mapping;
37714+ atomic_unchecked_t bt_lost_no_mapping;
37715+ atomic_unchecked_t event_lost_overflow;
37716+ atomic_unchecked_t multiplex_counter;
37717 };
37718
37719 extern struct oprofile_stat_struct oprofile_stats;
37720diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
37721index 849357c..b83c1e0 100644
37722--- a/drivers/oprofile/oprofilefs.c
37723+++ b/drivers/oprofile/oprofilefs.c
37724@@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
37725
37726
37727 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
37728- char const *name, atomic_t *val)
37729+ char const *name, atomic_unchecked_t *val)
37730 {
37731 return __oprofilefs_create_file(sb, root, name,
37732 &atomic_ro_fops, 0444, val);
37733diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
37734index 3f56bc0..707d642 100644
37735--- a/drivers/parport/procfs.c
37736+++ b/drivers/parport/procfs.c
37737@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
37738
37739 *ppos += len;
37740
37741- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
37742+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
37743 }
37744
37745 #ifdef CONFIG_PARPORT_1284
37746@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
37747
37748 *ppos += len;
37749
37750- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
37751+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
37752 }
37753 #endif /* IEEE1284.3 support. */
37754
37755diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
37756index a6a71c4..c91097b 100644
37757--- a/drivers/pci/hotplug/cpcihp_generic.c
37758+++ b/drivers/pci/hotplug/cpcihp_generic.c
37759@@ -73,7 +73,6 @@ static u16 port;
37760 static unsigned int enum_bit;
37761 static u8 enum_mask;
37762
37763-static struct cpci_hp_controller_ops generic_hpc_ops;
37764 static struct cpci_hp_controller generic_hpc;
37765
37766 static int __init validate_parameters(void)
37767@@ -139,6 +138,10 @@ static int query_enum(void)
37768 return ((value & enum_mask) == enum_mask);
37769 }
37770
37771+static struct cpci_hp_controller_ops generic_hpc_ops = {
37772+ .query_enum = query_enum,
37773+};
37774+
37775 static int __init cpcihp_generic_init(void)
37776 {
37777 int status;
37778@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
37779 pci_dev_put(dev);
37780
37781 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
37782- generic_hpc_ops.query_enum = query_enum;
37783 generic_hpc.ops = &generic_hpc_ops;
37784
37785 status = cpci_hp_register_controller(&generic_hpc);
37786diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
37787index 6bf8d2a..9711ce0 100644
37788--- a/drivers/pci/hotplug/cpcihp_zt5550.c
37789+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
37790@@ -59,7 +59,6 @@
37791 /* local variables */
37792 static bool debug;
37793 static bool poll;
37794-static struct cpci_hp_controller_ops zt5550_hpc_ops;
37795 static struct cpci_hp_controller zt5550_hpc;
37796
37797 /* Primary cPCI bus bridge device */
37798@@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
37799 return 0;
37800 }
37801
37802+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
37803+ .query_enum = zt5550_hc_query_enum,
37804+};
37805+
37806 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
37807 {
37808 int status;
37809@@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
37810 dbg("returned from zt5550_hc_config");
37811
37812 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
37813- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
37814 zt5550_hpc.ops = &zt5550_hpc_ops;
37815 if(!poll) {
37816 zt5550_hpc.irq = hc_dev->irq;
37817 zt5550_hpc.irq_flags = IRQF_SHARED;
37818 zt5550_hpc.dev_id = hc_dev;
37819
37820- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
37821- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
37822- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
37823+ pax_open_kernel();
37824+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
37825+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
37826+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
37827+ pax_open_kernel();
37828 } else {
37829 info("using ENUM# polling mode");
37830 }
37831diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
37832index 76ba8a1..20ca857 100644
37833--- a/drivers/pci/hotplug/cpqphp_nvram.c
37834+++ b/drivers/pci/hotplug/cpqphp_nvram.c
37835@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
37836
37837 void compaq_nvram_init (void __iomem *rom_start)
37838 {
37839+
37840+#ifndef CONFIG_PAX_KERNEXEC
37841 if (rom_start) {
37842 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
37843 }
37844+#endif
37845+
37846 dbg("int15 entry = %p\n", compaq_int15_entry_point);
37847
37848 /* initialize our int15 lock */
37849diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
37850index 449f257..0731e96 100644
37851--- a/drivers/pci/pcie/aspm.c
37852+++ b/drivers/pci/pcie/aspm.c
37853@@ -27,9 +27,9 @@
37854 #define MODULE_PARAM_PREFIX "pcie_aspm."
37855
37856 /* Note: those are not register definitions */
37857-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
37858-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
37859-#define ASPM_STATE_L1 (4) /* L1 state */
37860+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
37861+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
37862+#define ASPM_STATE_L1 (4U) /* L1 state */
37863 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
37864 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
37865
37866diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
37867index ec909af..e7517f3 100644
37868--- a/drivers/pci/probe.c
37869+++ b/drivers/pci/probe.c
37870@@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
37871 struct pci_bus_region region;
37872 bool bar_too_big = false, bar_disabled = false;
37873
37874- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
37875+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
37876
37877 /* No printks while decoding is disabled! */
37878 if (!dev->mmio_always_on) {
37879diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
37880index 9b8505c..f00870a 100644
37881--- a/drivers/pci/proc.c
37882+++ b/drivers/pci/proc.c
37883@@ -465,7 +465,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
37884 static int __init pci_proc_init(void)
37885 {
37886 struct pci_dev *dev = NULL;
37887+
37888+#ifdef CONFIG_GRKERNSEC_PROC_ADD
37889+#ifdef CONFIG_GRKERNSEC_PROC_USER
37890+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
37891+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
37892+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
37893+#endif
37894+#else
37895 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
37896+#endif
37897 proc_create("devices", 0, proc_bus_pci_dir,
37898 &proc_bus_pci_dev_operations);
37899 proc_initialized = 1;
37900diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
37901index 75dd651..2af4c9a 100644
37902--- a/drivers/platform/x86/thinkpad_acpi.c
37903+++ b/drivers/platform/x86/thinkpad_acpi.c
37904@@ -2097,7 +2097,7 @@ static int hotkey_mask_get(void)
37905 return 0;
37906 }
37907
37908-void static hotkey_mask_warn_incomplete_mask(void)
37909+static void hotkey_mask_warn_incomplete_mask(void)
37910 {
37911 /* log only what the user can fix... */
37912 const u32 wantedmask = hotkey_driver_mask &
37913@@ -2328,11 +2328,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
37914 }
37915 }
37916
37917-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
37918- struct tp_nvram_state *newn,
37919- const u32 event_mask)
37920-{
37921-
37922 #define TPACPI_COMPARE_KEY(__scancode, __member) \
37923 do { \
37924 if ((event_mask & (1 << __scancode)) && \
37925@@ -2346,36 +2341,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
37926 tpacpi_hotkey_send_key(__scancode); \
37927 } while (0)
37928
37929- void issue_volchange(const unsigned int oldvol,
37930- const unsigned int newvol)
37931- {
37932- unsigned int i = oldvol;
37933+static void issue_volchange(const unsigned int oldvol,
37934+ const unsigned int newvol,
37935+ const u32 event_mask)
37936+{
37937+ unsigned int i = oldvol;
37938
37939- while (i > newvol) {
37940- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
37941- i--;
37942- }
37943- while (i < newvol) {
37944- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
37945- i++;
37946- }
37947+ while (i > newvol) {
37948+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
37949+ i--;
37950 }
37951+ while (i < newvol) {
37952+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
37953+ i++;
37954+ }
37955+}
37956
37957- void issue_brightnesschange(const unsigned int oldbrt,
37958- const unsigned int newbrt)
37959- {
37960- unsigned int i = oldbrt;
37961+static void issue_brightnesschange(const unsigned int oldbrt,
37962+ const unsigned int newbrt,
37963+ const u32 event_mask)
37964+{
37965+ unsigned int i = oldbrt;
37966
37967- while (i > newbrt) {
37968- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
37969- i--;
37970- }
37971- while (i < newbrt) {
37972- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
37973- i++;
37974- }
37975+ while (i > newbrt) {
37976+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
37977+ i--;
37978+ }
37979+ while (i < newbrt) {
37980+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
37981+ i++;
37982 }
37983+}
37984
37985+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
37986+ struct tp_nvram_state *newn,
37987+ const u32 event_mask)
37988+{
37989 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
37990 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
37991 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
37992@@ -2409,7 +2410,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
37993 oldn->volume_level != newn->volume_level) {
37994 /* recently muted, or repeated mute keypress, or
37995 * multiple presses ending in mute */
37996- issue_volchange(oldn->volume_level, newn->volume_level);
37997+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
37998 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
37999 }
38000 } else {
38001@@ -2419,7 +2420,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
38002 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
38003 }
38004 if (oldn->volume_level != newn->volume_level) {
38005- issue_volchange(oldn->volume_level, newn->volume_level);
38006+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
38007 } else if (oldn->volume_toggle != newn->volume_toggle) {
38008 /* repeated vol up/down keypress at end of scale ? */
38009 if (newn->volume_level == 0)
38010@@ -2432,7 +2433,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
38011 /* handle brightness */
38012 if (oldn->brightness_level != newn->brightness_level) {
38013 issue_brightnesschange(oldn->brightness_level,
38014- newn->brightness_level);
38015+ newn->brightness_level,
38016+ event_mask);
38017 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
38018 /* repeated key presses that didn't change state */
38019 if (newn->brightness_level == 0)
38020@@ -2441,10 +2443,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
38021 && !tp_features.bright_unkfw)
38022 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
38023 }
38024+}
38025
38026 #undef TPACPI_COMPARE_KEY
38027 #undef TPACPI_MAY_SEND_KEY
38028-}
38029
38030 /*
38031 * Polling driver
38032diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
38033index 769d265..a3a05ca 100644
38034--- a/drivers/pnp/pnpbios/bioscalls.c
38035+++ b/drivers/pnp/pnpbios/bioscalls.c
38036@@ -58,7 +58,7 @@ do { \
38037 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
38038 } while(0)
38039
38040-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
38041+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
38042 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
38043
38044 /*
38045@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
38046
38047 cpu = get_cpu();
38048 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
38049+
38050+ pax_open_kernel();
38051 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
38052+ pax_close_kernel();
38053
38054 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
38055 spin_lock_irqsave(&pnp_bios_lock, flags);
38056@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
38057 :"memory");
38058 spin_unlock_irqrestore(&pnp_bios_lock, flags);
38059
38060+ pax_open_kernel();
38061 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
38062+ pax_close_kernel();
38063+
38064 put_cpu();
38065
38066 /* If we get here and this is set then the PnP BIOS faulted on us. */
38067@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
38068 return status;
38069 }
38070
38071-void pnpbios_calls_init(union pnp_bios_install_struct *header)
38072+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
38073 {
38074 int i;
38075
38076@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
38077 pnp_bios_callpoint.offset = header->fields.pm16offset;
38078 pnp_bios_callpoint.segment = PNP_CS16;
38079
38080+ pax_open_kernel();
38081+
38082 for_each_possible_cpu(i) {
38083 struct desc_struct *gdt = get_cpu_gdt_table(i);
38084 if (!gdt)
38085@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
38086 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
38087 (unsigned long)__va(header->fields.pm16dseg));
38088 }
38089+
38090+ pax_close_kernel();
38091 }
38092diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
38093index b0ecacb..7c9da2e 100644
38094--- a/drivers/pnp/resource.c
38095+++ b/drivers/pnp/resource.c
38096@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
38097 return 1;
38098
38099 /* check if the resource is valid */
38100- if (*irq < 0 || *irq > 15)
38101+ if (*irq > 15)
38102 return 0;
38103
38104 /* check if the resource is reserved */
38105@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
38106 return 1;
38107
38108 /* check if the resource is valid */
38109- if (*dma < 0 || *dma == 4 || *dma > 7)
38110+ if (*dma == 4 || *dma > 7)
38111 return 0;
38112
38113 /* check if the resource is reserved */
38114diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
38115index 7df7c5f..bd48c47 100644
38116--- a/drivers/power/pda_power.c
38117+++ b/drivers/power/pda_power.c
38118@@ -37,7 +37,11 @@ static int polling;
38119
38120 #ifdef CONFIG_USB_OTG_UTILS
38121 static struct usb_phy *transceiver;
38122-static struct notifier_block otg_nb;
38123+static int otg_handle_notification(struct notifier_block *nb,
38124+ unsigned long event, void *unused);
38125+static struct notifier_block otg_nb = {
38126+ .notifier_call = otg_handle_notification
38127+};
38128 #endif
38129
38130 static struct regulator *ac_draw;
38131@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
38132
38133 #ifdef CONFIG_USB_OTG_UTILS
38134 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
38135- otg_nb.notifier_call = otg_handle_notification;
38136 ret = usb_register_notifier(transceiver, &otg_nb);
38137 if (ret) {
38138 dev_err(dev, "failure to register otg notifier\n");
38139diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
38140index 8d53174..04c65de 100644
38141--- a/drivers/regulator/max8660.c
38142+++ b/drivers/regulator/max8660.c
38143@@ -333,8 +333,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
38144 max8660->shadow_regs[MAX8660_OVER1] = 5;
38145 } else {
38146 /* Otherwise devices can be toggled via software */
38147- max8660_dcdc_ops.enable = max8660_dcdc_enable;
38148- max8660_dcdc_ops.disable = max8660_dcdc_disable;
38149+ pax_open_kernel();
38150+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
38151+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
38152+ pax_close_kernel();
38153 }
38154
38155 /*
38156diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
38157index 1fa6381..f58834e 100644
38158--- a/drivers/regulator/mc13892-regulator.c
38159+++ b/drivers/regulator/mc13892-regulator.c
38160@@ -540,10 +540,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
38161 }
38162 mc13xxx_unlock(mc13892);
38163
38164- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
38165+ pax_open_kernel();
38166+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
38167 = mc13892_vcam_set_mode;
38168- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
38169+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
38170 = mc13892_vcam_get_mode;
38171+ pax_close_kernel();
38172
38173 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
38174 ARRAY_SIZE(mc13892_regulators));
38175diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
38176index cace6d3..f623fda 100644
38177--- a/drivers/rtc/rtc-dev.c
38178+++ b/drivers/rtc/rtc-dev.c
38179@@ -14,6 +14,7 @@
38180 #include <linux/module.h>
38181 #include <linux/rtc.h>
38182 #include <linux/sched.h>
38183+#include <linux/grsecurity.h>
38184 #include "rtc-core.h"
38185
38186 static dev_t rtc_devt;
38187@@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
38188 if (copy_from_user(&tm, uarg, sizeof(tm)))
38189 return -EFAULT;
38190
38191+ gr_log_timechange();
38192+
38193 return rtc_set_time(rtc, &tm);
38194
38195 case RTC_PIE_ON:
38196diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
38197index 4ad7e36..d004679 100644
38198--- a/drivers/scsi/bfa/bfa.h
38199+++ b/drivers/scsi/bfa/bfa.h
38200@@ -196,7 +196,7 @@ struct bfa_hwif_s {
38201 u32 *end);
38202 int cpe_vec_q0;
38203 int rme_vec_q0;
38204-};
38205+} __no_const;
38206 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
38207
38208 struct bfa_faa_cbfn_s {
38209diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
38210index e693af6..2e525b6 100644
38211--- a/drivers/scsi/bfa/bfa_fcpim.h
38212+++ b/drivers/scsi/bfa/bfa_fcpim.h
38213@@ -36,7 +36,7 @@ struct bfa_iotag_s {
38214
38215 struct bfa_itn_s {
38216 bfa_isr_func_t isr;
38217-};
38218+} __no_const;
38219
38220 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
38221 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
38222diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
38223index 23a90e7..9cf04ee 100644
38224--- a/drivers/scsi/bfa/bfa_ioc.h
38225+++ b/drivers/scsi/bfa/bfa_ioc.h
38226@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
38227 bfa_ioc_disable_cbfn_t disable_cbfn;
38228 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
38229 bfa_ioc_reset_cbfn_t reset_cbfn;
38230-};
38231+} __no_const;
38232
38233 /*
38234 * IOC event notification mechanism.
38235@@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
38236 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
38237 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
38238 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
38239-};
38240+} __no_const;
38241
38242 /*
38243 * Queue element to wait for room in request queue. FIFO order is
38244diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
38245index 593085a..47aa999 100644
38246--- a/drivers/scsi/hosts.c
38247+++ b/drivers/scsi/hosts.c
38248@@ -42,7 +42,7 @@
38249 #include "scsi_logging.h"
38250
38251
38252-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
38253+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
38254
38255
38256 static void scsi_host_cls_release(struct device *dev)
38257@@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
38258 * subtract one because we increment first then return, but we need to
38259 * know what the next host number was before increment
38260 */
38261- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
38262+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
38263 shost->dma_channel = 0xff;
38264
38265 /* These three are default values which can be overridden */
38266diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
38267index 4217e49..9c77e3e 100644
38268--- a/drivers/scsi/hpsa.c
38269+++ b/drivers/scsi/hpsa.c
38270@@ -554,7 +554,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
38271 unsigned long flags;
38272
38273 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
38274- return h->access.command_completed(h, q);
38275+ return h->access->command_completed(h, q);
38276
38277 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
38278 a = rq->head[rq->current_entry];
38279@@ -3374,7 +3374,7 @@ static void start_io(struct ctlr_info *h)
38280 while (!list_empty(&h->reqQ)) {
38281 c = list_entry(h->reqQ.next, struct CommandList, list);
38282 /* can't do anything if fifo is full */
38283- if ((h->access.fifo_full(h))) {
38284+ if ((h->access->fifo_full(h))) {
38285 dev_warn(&h->pdev->dev, "fifo full\n");
38286 break;
38287 }
38288@@ -3396,7 +3396,7 @@ static void start_io(struct ctlr_info *h)
38289
38290 /* Tell the controller execute command */
38291 spin_unlock_irqrestore(&h->lock, flags);
38292- h->access.submit_command(h, c);
38293+ h->access->submit_command(h, c);
38294 spin_lock_irqsave(&h->lock, flags);
38295 }
38296 spin_unlock_irqrestore(&h->lock, flags);
38297@@ -3404,17 +3404,17 @@ static void start_io(struct ctlr_info *h)
38298
38299 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
38300 {
38301- return h->access.command_completed(h, q);
38302+ return h->access->command_completed(h, q);
38303 }
38304
38305 static inline bool interrupt_pending(struct ctlr_info *h)
38306 {
38307- return h->access.intr_pending(h);
38308+ return h->access->intr_pending(h);
38309 }
38310
38311 static inline long interrupt_not_for_us(struct ctlr_info *h)
38312 {
38313- return (h->access.intr_pending(h) == 0) ||
38314+ return (h->access->intr_pending(h) == 0) ||
38315 (h->interrupts_enabled == 0);
38316 }
38317
38318@@ -4318,7 +4318,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
38319 if (prod_index < 0)
38320 return -ENODEV;
38321 h->product_name = products[prod_index].product_name;
38322- h->access = *(products[prod_index].access);
38323+ h->access = products[prod_index].access;
38324
38325 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
38326 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
38327@@ -4600,7 +4600,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
38328
38329 assert_spin_locked(&lockup_detector_lock);
38330 remove_ctlr_from_lockup_detector_list(h);
38331- h->access.set_intr_mask(h, HPSA_INTR_OFF);
38332+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
38333 spin_lock_irqsave(&h->lock, flags);
38334 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
38335 spin_unlock_irqrestore(&h->lock, flags);
38336@@ -4778,7 +4778,7 @@ reinit_after_soft_reset:
38337 }
38338
38339 /* make sure the board interrupts are off */
38340- h->access.set_intr_mask(h, HPSA_INTR_OFF);
38341+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
38342
38343 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
38344 goto clean2;
38345@@ -4812,7 +4812,7 @@ reinit_after_soft_reset:
38346 * fake ones to scoop up any residual completions.
38347 */
38348 spin_lock_irqsave(&h->lock, flags);
38349- h->access.set_intr_mask(h, HPSA_INTR_OFF);
38350+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
38351 spin_unlock_irqrestore(&h->lock, flags);
38352 free_irqs(h);
38353 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
38354@@ -4831,9 +4831,9 @@ reinit_after_soft_reset:
38355 dev_info(&h->pdev->dev, "Board READY.\n");
38356 dev_info(&h->pdev->dev,
38357 "Waiting for stale completions to drain.\n");
38358- h->access.set_intr_mask(h, HPSA_INTR_ON);
38359+ h->access->set_intr_mask(h, HPSA_INTR_ON);
38360 msleep(10000);
38361- h->access.set_intr_mask(h, HPSA_INTR_OFF);
38362+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
38363
38364 rc = controller_reset_failed(h->cfgtable);
38365 if (rc)
38366@@ -4854,7 +4854,7 @@ reinit_after_soft_reset:
38367 }
38368
38369 /* Turn the interrupts on so we can service requests */
38370- h->access.set_intr_mask(h, HPSA_INTR_ON);
38371+ h->access->set_intr_mask(h, HPSA_INTR_ON);
38372
38373 hpsa_hba_inquiry(h);
38374 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
38375@@ -4906,7 +4906,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
38376 * To write all data in the battery backed cache to disks
38377 */
38378 hpsa_flush_cache(h);
38379- h->access.set_intr_mask(h, HPSA_INTR_OFF);
38380+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
38381 hpsa_free_irqs_and_disable_msix(h);
38382 }
38383
38384@@ -5075,7 +5075,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
38385 return;
38386 }
38387 /* Change the access methods to the performant access methods */
38388- h->access = SA5_performant_access;
38389+ h->access = &SA5_performant_access;
38390 h->transMethod = CFGTBL_Trans_Performant;
38391 }
38392
38393diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
38394index 9816479..c5d4e97 100644
38395--- a/drivers/scsi/hpsa.h
38396+++ b/drivers/scsi/hpsa.h
38397@@ -79,7 +79,7 @@ struct ctlr_info {
38398 unsigned int msix_vector;
38399 unsigned int msi_vector;
38400 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
38401- struct access_method access;
38402+ struct access_method *access;
38403
38404 /* queue and queue Info */
38405 struct list_head reqQ;
38406diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
38407index c772d8d..35c362c 100644
38408--- a/drivers/scsi/libfc/fc_exch.c
38409+++ b/drivers/scsi/libfc/fc_exch.c
38410@@ -100,12 +100,12 @@ struct fc_exch_mgr {
38411 u16 pool_max_index;
38412
38413 struct {
38414- atomic_t no_free_exch;
38415- atomic_t no_free_exch_xid;
38416- atomic_t xid_not_found;
38417- atomic_t xid_busy;
38418- atomic_t seq_not_found;
38419- atomic_t non_bls_resp;
38420+ atomic_unchecked_t no_free_exch;
38421+ atomic_unchecked_t no_free_exch_xid;
38422+ atomic_unchecked_t xid_not_found;
38423+ atomic_unchecked_t xid_busy;
38424+ atomic_unchecked_t seq_not_found;
38425+ atomic_unchecked_t non_bls_resp;
38426 } stats;
38427 };
38428
38429@@ -725,7 +725,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
38430 /* allocate memory for exchange */
38431 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
38432 if (!ep) {
38433- atomic_inc(&mp->stats.no_free_exch);
38434+ atomic_inc_unchecked(&mp->stats.no_free_exch);
38435 goto out;
38436 }
38437 memset(ep, 0, sizeof(*ep));
38438@@ -786,7 +786,7 @@ out:
38439 return ep;
38440 err:
38441 spin_unlock_bh(&pool->lock);
38442- atomic_inc(&mp->stats.no_free_exch_xid);
38443+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
38444 mempool_free(ep, mp->ep_pool);
38445 return NULL;
38446 }
38447@@ -929,7 +929,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
38448 xid = ntohs(fh->fh_ox_id); /* we originated exch */
38449 ep = fc_exch_find(mp, xid);
38450 if (!ep) {
38451- atomic_inc(&mp->stats.xid_not_found);
38452+ atomic_inc_unchecked(&mp->stats.xid_not_found);
38453 reject = FC_RJT_OX_ID;
38454 goto out;
38455 }
38456@@ -959,7 +959,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
38457 ep = fc_exch_find(mp, xid);
38458 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
38459 if (ep) {
38460- atomic_inc(&mp->stats.xid_busy);
38461+ atomic_inc_unchecked(&mp->stats.xid_busy);
38462 reject = FC_RJT_RX_ID;
38463 goto rel;
38464 }
38465@@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
38466 }
38467 xid = ep->xid; /* get our XID */
38468 } else if (!ep) {
38469- atomic_inc(&mp->stats.xid_not_found);
38470+ atomic_inc_unchecked(&mp->stats.xid_not_found);
38471 reject = FC_RJT_RX_ID; /* XID not found */
38472 goto out;
38473 }
38474@@ -987,7 +987,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
38475 } else {
38476 sp = &ep->seq;
38477 if (sp->id != fh->fh_seq_id) {
38478- atomic_inc(&mp->stats.seq_not_found);
38479+ atomic_inc_unchecked(&mp->stats.seq_not_found);
38480 if (f_ctl & FC_FC_END_SEQ) {
38481 /*
38482 * Update sequence_id based on incoming last
38483@@ -1437,22 +1437,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
38484
38485 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
38486 if (!ep) {
38487- atomic_inc(&mp->stats.xid_not_found);
38488+ atomic_inc_unchecked(&mp->stats.xid_not_found);
38489 goto out;
38490 }
38491 if (ep->esb_stat & ESB_ST_COMPLETE) {
38492- atomic_inc(&mp->stats.xid_not_found);
38493+ atomic_inc_unchecked(&mp->stats.xid_not_found);
38494 goto rel;
38495 }
38496 if (ep->rxid == FC_XID_UNKNOWN)
38497 ep->rxid = ntohs(fh->fh_rx_id);
38498 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
38499- atomic_inc(&mp->stats.xid_not_found);
38500+ atomic_inc_unchecked(&mp->stats.xid_not_found);
38501 goto rel;
38502 }
38503 if (ep->did != ntoh24(fh->fh_s_id) &&
38504 ep->did != FC_FID_FLOGI) {
38505- atomic_inc(&mp->stats.xid_not_found);
38506+ atomic_inc_unchecked(&mp->stats.xid_not_found);
38507 goto rel;
38508 }
38509 sof = fr_sof(fp);
38510@@ -1461,7 +1461,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
38511 sp->ssb_stat |= SSB_ST_RESP;
38512 sp->id = fh->fh_seq_id;
38513 } else if (sp->id != fh->fh_seq_id) {
38514- atomic_inc(&mp->stats.seq_not_found);
38515+ atomic_inc_unchecked(&mp->stats.seq_not_found);
38516 goto rel;
38517 }
38518
38519@@ -1525,9 +1525,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
38520 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
38521
38522 if (!sp)
38523- atomic_inc(&mp->stats.xid_not_found);
38524+ atomic_inc_unchecked(&mp->stats.xid_not_found);
38525 else
38526- atomic_inc(&mp->stats.non_bls_resp);
38527+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
38528
38529 fc_frame_free(fp);
38530 }
38531@@ -2174,13 +2174,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
38532
38533 list_for_each_entry(ema, &lport->ema_list, ema_list) {
38534 mp = ema->mp;
38535- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
38536+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
38537 st->fc_no_free_exch_xid +=
38538- atomic_read(&mp->stats.no_free_exch_xid);
38539- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
38540- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
38541- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
38542- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
38543+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
38544+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
38545+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
38546+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
38547+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
38548 }
38549 }
38550 EXPORT_SYMBOL(fc_exch_update_stats);
38551diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
38552index bdb81cd..d3c7c2c 100644
38553--- a/drivers/scsi/libsas/sas_ata.c
38554+++ b/drivers/scsi/libsas/sas_ata.c
38555@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
38556 .postreset = ata_std_postreset,
38557 .error_handler = ata_std_error_handler,
38558 .post_internal_cmd = sas_ata_post_internal,
38559- .qc_defer = ata_std_qc_defer,
38560+ .qc_defer = ata_std_qc_defer,
38561 .qc_prep = ata_noop_qc_prep,
38562 .qc_issue = sas_ata_qc_issue,
38563 .qc_fill_rtf = sas_ata_qc_fill_rtf,
38564diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
38565index 69b5993..1ac9dce 100644
38566--- a/drivers/scsi/lpfc/lpfc.h
38567+++ b/drivers/scsi/lpfc/lpfc.h
38568@@ -424,7 +424,7 @@ struct lpfc_vport {
38569 struct dentry *debug_nodelist;
38570 struct dentry *vport_debugfs_root;
38571 struct lpfc_debugfs_trc *disc_trc;
38572- atomic_t disc_trc_cnt;
38573+ atomic_unchecked_t disc_trc_cnt;
38574 #endif
38575 uint8_t stat_data_enabled;
38576 uint8_t stat_data_blocked;
38577@@ -840,8 +840,8 @@ struct lpfc_hba {
38578 struct timer_list fabric_block_timer;
38579 unsigned long bit_flags;
38580 #define FABRIC_COMANDS_BLOCKED 0
38581- atomic_t num_rsrc_err;
38582- atomic_t num_cmd_success;
38583+ atomic_unchecked_t num_rsrc_err;
38584+ atomic_unchecked_t num_cmd_success;
38585 unsigned long last_rsrc_error_time;
38586 unsigned long last_ramp_down_time;
38587 unsigned long last_ramp_up_time;
38588@@ -877,7 +877,7 @@ struct lpfc_hba {
38589
38590 struct dentry *debug_slow_ring_trc;
38591 struct lpfc_debugfs_trc *slow_ring_trc;
38592- atomic_t slow_ring_trc_cnt;
38593+ atomic_unchecked_t slow_ring_trc_cnt;
38594 /* iDiag debugfs sub-directory */
38595 struct dentry *idiag_root;
38596 struct dentry *idiag_pci_cfg;
38597diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
38598index f63f5ff..de29189 100644
38599--- a/drivers/scsi/lpfc/lpfc_debugfs.c
38600+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
38601@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
38602
38603 #include <linux/debugfs.h>
38604
38605-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
38606+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
38607 static unsigned long lpfc_debugfs_start_time = 0L;
38608
38609 /* iDiag */
38610@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
38611 lpfc_debugfs_enable = 0;
38612
38613 len = 0;
38614- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
38615+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
38616 (lpfc_debugfs_max_disc_trc - 1);
38617 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
38618 dtp = vport->disc_trc + i;
38619@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
38620 lpfc_debugfs_enable = 0;
38621
38622 len = 0;
38623- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
38624+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
38625 (lpfc_debugfs_max_slow_ring_trc - 1);
38626 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
38627 dtp = phba->slow_ring_trc + i;
38628@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
38629 !vport || !vport->disc_trc)
38630 return;
38631
38632- index = atomic_inc_return(&vport->disc_trc_cnt) &
38633+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
38634 (lpfc_debugfs_max_disc_trc - 1);
38635 dtp = vport->disc_trc + index;
38636 dtp->fmt = fmt;
38637 dtp->data1 = data1;
38638 dtp->data2 = data2;
38639 dtp->data3 = data3;
38640- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
38641+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
38642 dtp->jif = jiffies;
38643 #endif
38644 return;
38645@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
38646 !phba || !phba->slow_ring_trc)
38647 return;
38648
38649- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
38650+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
38651 (lpfc_debugfs_max_slow_ring_trc - 1);
38652 dtp = phba->slow_ring_trc + index;
38653 dtp->fmt = fmt;
38654 dtp->data1 = data1;
38655 dtp->data2 = data2;
38656 dtp->data3 = data3;
38657- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
38658+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
38659 dtp->jif = jiffies;
38660 #endif
38661 return;
38662@@ -4182,7 +4182,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
38663 "slow_ring buffer\n");
38664 goto debug_failed;
38665 }
38666- atomic_set(&phba->slow_ring_trc_cnt, 0);
38667+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
38668 memset(phba->slow_ring_trc, 0,
38669 (sizeof(struct lpfc_debugfs_trc) *
38670 lpfc_debugfs_max_slow_ring_trc));
38671@@ -4228,7 +4228,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
38672 "buffer\n");
38673 goto debug_failed;
38674 }
38675- atomic_set(&vport->disc_trc_cnt, 0);
38676+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
38677
38678 snprintf(name, sizeof(name), "discovery_trace");
38679 vport->debug_disc_trc =
38680diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
38681index 7dc4218..3436f08 100644
38682--- a/drivers/scsi/lpfc/lpfc_init.c
38683+++ b/drivers/scsi/lpfc/lpfc_init.c
38684@@ -10589,8 +10589,10 @@ lpfc_init(void)
38685 "misc_register returned with status %d", error);
38686
38687 if (lpfc_enable_npiv) {
38688- lpfc_transport_functions.vport_create = lpfc_vport_create;
38689- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
38690+ pax_open_kernel();
38691+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
38692+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
38693+ pax_close_kernel();
38694 }
38695 lpfc_transport_template =
38696 fc_attach_transport(&lpfc_transport_functions);
38697diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
38698index 7f45ac9..cf62eda 100644
38699--- a/drivers/scsi/lpfc/lpfc_scsi.c
38700+++ b/drivers/scsi/lpfc/lpfc_scsi.c
38701@@ -305,7 +305,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
38702 uint32_t evt_posted;
38703
38704 spin_lock_irqsave(&phba->hbalock, flags);
38705- atomic_inc(&phba->num_rsrc_err);
38706+ atomic_inc_unchecked(&phba->num_rsrc_err);
38707 phba->last_rsrc_error_time = jiffies;
38708
38709 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
38710@@ -346,7 +346,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
38711 unsigned long flags;
38712 struct lpfc_hba *phba = vport->phba;
38713 uint32_t evt_posted;
38714- atomic_inc(&phba->num_cmd_success);
38715+ atomic_inc_unchecked(&phba->num_cmd_success);
38716
38717 if (vport->cfg_lun_queue_depth <= queue_depth)
38718 return;
38719@@ -390,8 +390,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
38720 unsigned long num_rsrc_err, num_cmd_success;
38721 int i;
38722
38723- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
38724- num_cmd_success = atomic_read(&phba->num_cmd_success);
38725+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
38726+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
38727
38728 /*
38729 * The error and success command counters are global per
38730@@ -419,8 +419,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
38731 }
38732 }
38733 lpfc_destroy_vport_work_array(phba, vports);
38734- atomic_set(&phba->num_rsrc_err, 0);
38735- atomic_set(&phba->num_cmd_success, 0);
38736+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
38737+ atomic_set_unchecked(&phba->num_cmd_success, 0);
38738 }
38739
38740 /**
38741@@ -454,8 +454,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
38742 }
38743 }
38744 lpfc_destroy_vport_work_array(phba, vports);
38745- atomic_set(&phba->num_rsrc_err, 0);
38746- atomic_set(&phba->num_cmd_success, 0);
38747+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
38748+ atomic_set_unchecked(&phba->num_cmd_success, 0);
38749 }
38750
38751 /**
38752diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
38753index af763ea..41904f7 100644
38754--- a/drivers/scsi/pmcraid.c
38755+++ b/drivers/scsi/pmcraid.c
38756@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
38757 res->scsi_dev = scsi_dev;
38758 scsi_dev->hostdata = res;
38759 res->change_detected = 0;
38760- atomic_set(&res->read_failures, 0);
38761- atomic_set(&res->write_failures, 0);
38762+ atomic_set_unchecked(&res->read_failures, 0);
38763+ atomic_set_unchecked(&res->write_failures, 0);
38764 rc = 0;
38765 }
38766 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
38767@@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
38768
38769 /* If this was a SCSI read/write command keep count of errors */
38770 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
38771- atomic_inc(&res->read_failures);
38772+ atomic_inc_unchecked(&res->read_failures);
38773 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
38774- atomic_inc(&res->write_failures);
38775+ atomic_inc_unchecked(&res->write_failures);
38776
38777 if (!RES_IS_GSCSI(res->cfg_entry) &&
38778 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
38779@@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
38780 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
38781 * hrrq_id assigned here in queuecommand
38782 */
38783- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
38784+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
38785 pinstance->num_hrrq;
38786 cmd->cmd_done = pmcraid_io_done;
38787
38788@@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
38789 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
38790 * hrrq_id assigned here in queuecommand
38791 */
38792- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
38793+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
38794 pinstance->num_hrrq;
38795
38796 if (request_size) {
38797@@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
38798
38799 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
38800 /* add resources only after host is added into system */
38801- if (!atomic_read(&pinstance->expose_resources))
38802+ if (!atomic_read_unchecked(&pinstance->expose_resources))
38803 return;
38804
38805 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
38806@@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
38807 init_waitqueue_head(&pinstance->reset_wait_q);
38808
38809 atomic_set(&pinstance->outstanding_cmds, 0);
38810- atomic_set(&pinstance->last_message_id, 0);
38811- atomic_set(&pinstance->expose_resources, 0);
38812+ atomic_set_unchecked(&pinstance->last_message_id, 0);
38813+ atomic_set_unchecked(&pinstance->expose_resources, 0);
38814
38815 INIT_LIST_HEAD(&pinstance->free_res_q);
38816 INIT_LIST_HEAD(&pinstance->used_res_q);
38817@@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
38818 /* Schedule worker thread to handle CCN and take care of adding and
38819 * removing devices to OS
38820 */
38821- atomic_set(&pinstance->expose_resources, 1);
38822+ atomic_set_unchecked(&pinstance->expose_resources, 1);
38823 schedule_work(&pinstance->worker_q);
38824 return rc;
38825
38826diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
38827index e1d150f..6c6df44 100644
38828--- a/drivers/scsi/pmcraid.h
38829+++ b/drivers/scsi/pmcraid.h
38830@@ -748,7 +748,7 @@ struct pmcraid_instance {
38831 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
38832
38833 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
38834- atomic_t last_message_id;
38835+ atomic_unchecked_t last_message_id;
38836
38837 /* configuration table */
38838 struct pmcraid_config_table *cfg_table;
38839@@ -777,7 +777,7 @@ struct pmcraid_instance {
38840 atomic_t outstanding_cmds;
38841
38842 /* should add/delete resources to mid-layer now ?*/
38843- atomic_t expose_resources;
38844+ atomic_unchecked_t expose_resources;
38845
38846
38847
38848@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
38849 struct pmcraid_config_table_entry_ext cfg_entry_ext;
38850 };
38851 struct scsi_device *scsi_dev; /* Link scsi_device structure */
38852- atomic_t read_failures; /* count of failed READ commands */
38853- atomic_t write_failures; /* count of failed WRITE commands */
38854+ atomic_unchecked_t read_failures; /* count of failed READ commands */
38855+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
38856
38857 /* To indicate add/delete/modify during CCN */
38858 u8 change_detected;
38859diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
38860index 83d7984..a27d947 100644
38861--- a/drivers/scsi/qla2xxx/qla_attr.c
38862+++ b/drivers/scsi/qla2xxx/qla_attr.c
38863@@ -1969,7 +1969,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
38864 return 0;
38865 }
38866
38867-struct fc_function_template qla2xxx_transport_functions = {
38868+fc_function_template_no_const qla2xxx_transport_functions = {
38869
38870 .show_host_node_name = 1,
38871 .show_host_port_name = 1,
38872@@ -2016,7 +2016,7 @@ struct fc_function_template qla2xxx_transport_functions = {
38873 .bsg_timeout = qla24xx_bsg_timeout,
38874 };
38875
38876-struct fc_function_template qla2xxx_transport_vport_functions = {
38877+fc_function_template_no_const qla2xxx_transport_vport_functions = {
38878
38879 .show_host_node_name = 1,
38880 .show_host_port_name = 1,
38881diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
38882index 6acb397..d86e3e0 100644
38883--- a/drivers/scsi/qla2xxx/qla_gbl.h
38884+++ b/drivers/scsi/qla2xxx/qla_gbl.h
38885@@ -515,8 +515,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
38886 struct device_attribute;
38887 extern struct device_attribute *qla2x00_host_attrs[];
38888 struct fc_function_template;
38889-extern struct fc_function_template qla2xxx_transport_functions;
38890-extern struct fc_function_template qla2xxx_transport_vport_functions;
38891+extern fc_function_template_no_const qla2xxx_transport_functions;
38892+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
38893 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
38894 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
38895 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
38896diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
38897index f4b1fc8..a1ce4dd 100644
38898--- a/drivers/scsi/qla2xxx/qla_os.c
38899+++ b/drivers/scsi/qla2xxx/qla_os.c
38900@@ -1462,8 +1462,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
38901 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
38902 /* Ok, a 64bit DMA mask is applicable. */
38903 ha->flags.enable_64bit_addressing = 1;
38904- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
38905- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
38906+ pax_open_kernel();
38907+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
38908+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
38909+ pax_close_kernel();
38910 return;
38911 }
38912 }
38913diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
38914index 329d553..f20d31d 100644
38915--- a/drivers/scsi/qla4xxx/ql4_def.h
38916+++ b/drivers/scsi/qla4xxx/ql4_def.h
38917@@ -273,7 +273,7 @@ struct ddb_entry {
38918 * (4000 only) */
38919 atomic_t relogin_timer; /* Max Time to wait for
38920 * relogin to complete */
38921- atomic_t relogin_retry_count; /* Num of times relogin has been
38922+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
38923 * retried */
38924 uint32_t default_time2wait; /* Default Min time between
38925 * relogins (+aens) */
38926diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
38927index fbc546e..c7d1b48 100644
38928--- a/drivers/scsi/qla4xxx/ql4_os.c
38929+++ b/drivers/scsi/qla4xxx/ql4_os.c
38930@@ -2621,12 +2621,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
38931 */
38932 if (!iscsi_is_session_online(cls_sess)) {
38933 /* Reset retry relogin timer */
38934- atomic_inc(&ddb_entry->relogin_retry_count);
38935+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
38936 DEBUG2(ql4_printk(KERN_INFO, ha,
38937 "%s: index[%d] relogin timed out-retrying"
38938 " relogin (%d), retry (%d)\n", __func__,
38939 ddb_entry->fw_ddb_index,
38940- atomic_read(&ddb_entry->relogin_retry_count),
38941+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
38942 ddb_entry->default_time2wait + 4));
38943 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
38944 atomic_set(&ddb_entry->retry_relogin_timer,
38945@@ -4738,7 +4738,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
38946
38947 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
38948 atomic_set(&ddb_entry->relogin_timer, 0);
38949- atomic_set(&ddb_entry->relogin_retry_count, 0);
38950+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
38951 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
38952 ddb_entry->default_relogin_timeout =
38953 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
38954diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
38955index 2c0d0ec..4e8681a 100644
38956--- a/drivers/scsi/scsi.c
38957+++ b/drivers/scsi/scsi.c
38958@@ -661,7 +661,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
38959 unsigned long timeout;
38960 int rtn = 0;
38961
38962- atomic_inc(&cmd->device->iorequest_cnt);
38963+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
38964
38965 /* check if the device is still usable */
38966 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
38967diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
38968index 9032e91..7a805d0 100644
38969--- a/drivers/scsi/scsi_lib.c
38970+++ b/drivers/scsi/scsi_lib.c
38971@@ -1454,7 +1454,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
38972 shost = sdev->host;
38973 scsi_init_cmd_errh(cmd);
38974 cmd->result = DID_NO_CONNECT << 16;
38975- atomic_inc(&cmd->device->iorequest_cnt);
38976+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
38977
38978 /*
38979 * SCSI request completion path will do scsi_device_unbusy(),
38980@@ -1480,9 +1480,9 @@ static void scsi_softirq_done(struct request *rq)
38981
38982 INIT_LIST_HEAD(&cmd->eh_entry);
38983
38984- atomic_inc(&cmd->device->iodone_cnt);
38985+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
38986 if (cmd->result)
38987- atomic_inc(&cmd->device->ioerr_cnt);
38988+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
38989
38990 disposition = scsi_decide_disposition(cmd);
38991 if (disposition != SUCCESS &&
38992diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
38993index 931a7d9..0c2a754 100644
38994--- a/drivers/scsi/scsi_sysfs.c
38995+++ b/drivers/scsi/scsi_sysfs.c
38996@@ -658,7 +658,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
38997 char *buf) \
38998 { \
38999 struct scsi_device *sdev = to_scsi_device(dev); \
39000- unsigned long long count = atomic_read(&sdev->field); \
39001+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
39002 return snprintf(buf, 20, "0x%llx\n", count); \
39003 } \
39004 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
39005diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
39006index 84a1fdf..693b0d6 100644
39007--- a/drivers/scsi/scsi_tgt_lib.c
39008+++ b/drivers/scsi/scsi_tgt_lib.c
39009@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
39010 int err;
39011
39012 dprintk("%lx %u\n", uaddr, len);
39013- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
39014+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
39015 if (err) {
39016 /*
39017 * TODO: need to fixup sg_tablesize, max_segment_size,
39018diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
39019index e894ca7..de9d7660 100644
39020--- a/drivers/scsi/scsi_transport_fc.c
39021+++ b/drivers/scsi/scsi_transport_fc.c
39022@@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
39023 * Netlink Infrastructure
39024 */
39025
39026-static atomic_t fc_event_seq;
39027+static atomic_unchecked_t fc_event_seq;
39028
39029 /**
39030 * fc_get_event_number - Obtain the next sequential FC event number
39031@@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
39032 u32
39033 fc_get_event_number(void)
39034 {
39035- return atomic_add_return(1, &fc_event_seq);
39036+ return atomic_add_return_unchecked(1, &fc_event_seq);
39037 }
39038 EXPORT_SYMBOL(fc_get_event_number);
39039
39040@@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
39041 {
39042 int error;
39043
39044- atomic_set(&fc_event_seq, 0);
39045+ atomic_set_unchecked(&fc_event_seq, 0);
39046
39047 error = transport_class_register(&fc_host_class);
39048 if (error)
39049@@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
39050 char *cp;
39051
39052 *val = simple_strtoul(buf, &cp, 0);
39053- if ((*cp && (*cp != '\n')) || (*val < 0))
39054+ if (*cp && (*cp != '\n'))
39055 return -EINVAL;
39056 /*
39057 * Check for overflow; dev_loss_tmo is u32
39058diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
39059index 31969f2..2b348f0 100644
39060--- a/drivers/scsi/scsi_transport_iscsi.c
39061+++ b/drivers/scsi/scsi_transport_iscsi.c
39062@@ -79,7 +79,7 @@ struct iscsi_internal {
39063 struct transport_container session_cont;
39064 };
39065
39066-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
39067+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
39068 static struct workqueue_struct *iscsi_eh_timer_workq;
39069
39070 static DEFINE_IDA(iscsi_sess_ida);
39071@@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
39072 int err;
39073
39074 ihost = shost->shost_data;
39075- session->sid = atomic_add_return(1, &iscsi_session_nr);
39076+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
39077
39078 if (target_id == ISCSI_MAX_TARGET) {
39079 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
39080@@ -2943,7 +2943,7 @@ static __init int iscsi_transport_init(void)
39081 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
39082 ISCSI_TRANSPORT_VERSION);
39083
39084- atomic_set(&iscsi_session_nr, 0);
39085+ atomic_set_unchecked(&iscsi_session_nr, 0);
39086
39087 err = class_register(&iscsi_transport_class);
39088 if (err)
39089diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
39090index 21a045e..ec89e03 100644
39091--- a/drivers/scsi/scsi_transport_srp.c
39092+++ b/drivers/scsi/scsi_transport_srp.c
39093@@ -33,7 +33,7 @@
39094 #include "scsi_transport_srp_internal.h"
39095
39096 struct srp_host_attrs {
39097- atomic_t next_port_id;
39098+ atomic_unchecked_t next_port_id;
39099 };
39100 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
39101
39102@@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
39103 struct Scsi_Host *shost = dev_to_shost(dev);
39104 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
39105
39106- atomic_set(&srp_host->next_port_id, 0);
39107+ atomic_set_unchecked(&srp_host->next_port_id, 0);
39108 return 0;
39109 }
39110
39111@@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
39112 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
39113 rport->roles = ids->roles;
39114
39115- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
39116+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
39117 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
39118
39119 transport_setup_device(&rport->dev);
39120diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
39121index a45e12a..d9120cb 100644
39122--- a/drivers/scsi/sd.c
39123+++ b/drivers/scsi/sd.c
39124@@ -2899,7 +2899,7 @@ static int sd_probe(struct device *dev)
39125 sdkp->disk = gd;
39126 sdkp->index = index;
39127 atomic_set(&sdkp->openers, 0);
39128- atomic_set(&sdkp->device->ioerr_cnt, 0);
39129+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
39130
39131 if (!sdp->request_queue->rq_timeout) {
39132 if (sdp->type != TYPE_MOD)
39133diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
39134index be2c9a6..275525c 100644
39135--- a/drivers/scsi/sg.c
39136+++ b/drivers/scsi/sg.c
39137@@ -1101,7 +1101,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
39138 sdp->disk->disk_name,
39139 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
39140 NULL,
39141- (char *)arg);
39142+ (char __user *)arg);
39143 case BLKTRACESTART:
39144 return blk_trace_startstop(sdp->device->request_queue, 1);
39145 case BLKTRACESTOP:
39146diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
39147index 84c2861..ece0a31 100644
39148--- a/drivers/spi/spi.c
39149+++ b/drivers/spi/spi.c
39150@@ -1453,7 +1453,7 @@ int spi_bus_unlock(struct spi_master *master)
39151 EXPORT_SYMBOL_GPL(spi_bus_unlock);
39152
39153 /* portable code must never pass more than 32 bytes */
39154-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
39155+#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
39156
39157 static u8 *buf;
39158
39159diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
39160index 34afc16..ffe44dd 100644
39161--- a/drivers/staging/octeon/ethernet-rx.c
39162+++ b/drivers/staging/octeon/ethernet-rx.c
39163@@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
39164 /* Increment RX stats for virtual ports */
39165 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
39166 #ifdef CONFIG_64BIT
39167- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
39168- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
39169+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
39170+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
39171 #else
39172- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
39173- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
39174+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
39175+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
39176 #endif
39177 }
39178 netif_receive_skb(skb);
39179@@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
39180 dev->name);
39181 */
39182 #ifdef CONFIG_64BIT
39183- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
39184+ atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
39185 #else
39186- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
39187+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
39188 #endif
39189 dev_kfree_skb_irq(skb);
39190 }
39191diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
39192index 683bedc..86dba9a 100644
39193--- a/drivers/staging/octeon/ethernet.c
39194+++ b/drivers/staging/octeon/ethernet.c
39195@@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
39196 * since the RX tasklet also increments it.
39197 */
39198 #ifdef CONFIG_64BIT
39199- atomic64_add(rx_status.dropped_packets,
39200- (atomic64_t *)&priv->stats.rx_dropped);
39201+ atomic64_add_unchecked(rx_status.dropped_packets,
39202+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
39203 #else
39204- atomic_add(rx_status.dropped_packets,
39205- (atomic_t *)&priv->stats.rx_dropped);
39206+ atomic_add_unchecked(rx_status.dropped_packets,
39207+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
39208 #endif
39209 }
39210
39211diff --git a/drivers/staging/ramster/tmem.c b/drivers/staging/ramster/tmem.c
39212index a2b7e03..aaf3630 100644
39213--- a/drivers/staging/ramster/tmem.c
39214+++ b/drivers/staging/ramster/tmem.c
39215@@ -50,25 +50,25 @@
39216 * A tmem host implementation must use this function to register callbacks
39217 * for memory allocation.
39218 */
39219-static struct tmem_hostops tmem_hostops;
39220+static struct tmem_hostops *tmem_hostops;
39221
39222 static void tmem_objnode_tree_init(void);
39223
39224 void tmem_register_hostops(struct tmem_hostops *m)
39225 {
39226 tmem_objnode_tree_init();
39227- tmem_hostops = *m;
39228+ tmem_hostops = m;
39229 }
39230
39231 /*
39232 * A tmem host implementation must use this function to register
39233 * callbacks for a page-accessible memory (PAM) implementation.
39234 */
39235-static struct tmem_pamops tmem_pamops;
39236+static struct tmem_pamops *tmem_pamops;
39237
39238 void tmem_register_pamops(struct tmem_pamops *m)
39239 {
39240- tmem_pamops = *m;
39241+ tmem_pamops = m;
39242 }
39243
39244 /*
39245@@ -174,7 +174,7 @@ static void tmem_obj_init(struct tmem_obj *obj, struct tmem_hashbucket *hb,
39246 obj->pampd_count = 0;
39247 #ifdef CONFIG_RAMSTER
39248 if (tmem_pamops.new_obj != NULL)
39249- (*tmem_pamops.new_obj)(obj);
39250+ (tmem_pamops->new_obj)(obj);
39251 #endif
39252 SET_SENTINEL(obj, OBJ);
39253
39254@@ -210,7 +210,7 @@ static void tmem_pool_flush(struct tmem_pool *pool, bool destroy)
39255 rbnode = rb_next(rbnode);
39256 tmem_pampd_destroy_all_in_obj(obj, true);
39257 tmem_obj_free(obj, hb);
39258- (*tmem_hostops.obj_free)(obj, pool);
39259+ (tmem_hostops->obj_free)(obj, pool);
39260 }
39261 spin_unlock(&hb->lock);
39262 }
39263@@ -261,7 +261,7 @@ static struct tmem_objnode *tmem_objnode_alloc(struct tmem_obj *obj)
39264 ASSERT_SENTINEL(obj, OBJ);
39265 BUG_ON(obj->pool == NULL);
39266 ASSERT_SENTINEL(obj->pool, POOL);
39267- objnode = (*tmem_hostops.objnode_alloc)(obj->pool);
39268+ objnode = (tmem_hostops->objnode_alloc)(obj->pool);
39269 if (unlikely(objnode == NULL))
39270 goto out;
39271 objnode->obj = obj;
39272@@ -290,7 +290,7 @@ static void tmem_objnode_free(struct tmem_objnode *objnode)
39273 ASSERT_SENTINEL(pool, POOL);
39274 objnode->obj->objnode_count--;
39275 objnode->obj = NULL;
39276- (*tmem_hostops.objnode_free)(objnode, pool);
39277+ (tmem_hostops->objnode_free)(objnode, pool);
39278 }
39279
39280 /*
39281@@ -348,7 +348,7 @@ static void *tmem_pampd_replace_in_obj(struct tmem_obj *obj, uint32_t index,
39282 void *old_pampd = *(void **)slot;
39283 *(void **)slot = new_pampd;
39284 if (!no_free)
39285- (*tmem_pamops.free)(old_pampd, obj->pool,
39286+ (tmem_pamops->free)(old_pampd, obj->pool,
39287 NULL, 0, false);
39288 ret = new_pampd;
39289 }
39290@@ -505,7 +505,7 @@ static void tmem_objnode_node_destroy(struct tmem_obj *obj,
39291 if (objnode->slots[i]) {
39292 if (ht == 1) {
39293 obj->pampd_count--;
39294- (*tmem_pamops.free)(objnode->slots[i],
39295+ (tmem_pamops->free)(objnode->slots[i],
39296 obj->pool, NULL, 0, true);
39297 objnode->slots[i] = NULL;
39298 continue;
39299@@ -524,7 +524,7 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
39300 return;
39301 if (obj->objnode_tree_height == 0) {
39302 obj->pampd_count--;
39303- (*tmem_pamops.free)(obj->objnode_tree_root,
39304+ (tmem_pamops->free)(obj->objnode_tree_root,
39305 obj->pool, NULL, 0, true);
39306 } else {
39307 tmem_objnode_node_destroy(obj, obj->objnode_tree_root,
39308@@ -535,7 +535,7 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
39309 obj->objnode_tree_root = NULL;
39310 #ifdef CONFIG_RAMSTER
39311 if (tmem_pamops.free_obj != NULL)
39312- (*tmem_pamops.free_obj)(obj->pool, obj, pool_destroy);
39313+ (tmem_pamops->free_obj)(obj->pool, obj, pool_destroy);
39314 #endif
39315 }
39316
39317@@ -574,7 +574,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
39318 /* if found, is a dup put, flush the old one */
39319 pampd_del = tmem_pampd_delete_from_obj(obj, index);
39320 BUG_ON(pampd_del != pampd);
39321- (*tmem_pamops.free)(pampd, pool, oidp, index, true);
39322+ (tmem_pamops->free)(pampd, pool, oidp, index, true);
39323 if (obj->pampd_count == 0) {
39324 objnew = obj;
39325 objfound = NULL;
39326@@ -582,7 +582,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
39327 pampd = NULL;
39328 }
39329 } else {
39330- obj = objnew = (*tmem_hostops.obj_alloc)(pool);
39331+ obj = objnew = (tmem_hostops->obj_alloc)(pool);
39332 if (unlikely(obj == NULL)) {
39333 ret = -ENOMEM;
39334 goto out;
39335@@ -597,16 +597,16 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
39336 if (unlikely(ret == -ENOMEM))
39337 /* may have partially built objnode tree ("stump") */
39338 goto delete_and_free;
39339- (*tmem_pamops.create_finish)(pampd, is_ephemeral(pool));
39340+ (tmem_pamops->create_finish)(pampd, is_ephemeral(pool));
39341 goto out;
39342
39343 delete_and_free:
39344 (void)tmem_pampd_delete_from_obj(obj, index);
39345 if (pampd)
39346- (*tmem_pamops.free)(pampd, pool, NULL, 0, true);
39347+ (tmem_pamops->free)(pampd, pool, NULL, 0, true);
39348 if (objnew) {
39349 tmem_obj_free(objnew, hb);
39350- (*tmem_hostops.obj_free)(objnew, pool);
39351+ (tmem_hostops->obj_free)(objnew, pool);
39352 }
39353 out:
39354 spin_unlock(&hb->lock);
39355@@ -651,7 +651,7 @@ void tmem_localify_finish(struct tmem_obj *obj, uint32_t index,
39356 if (pampd != NULL) {
39357 BUG_ON(obj == NULL);
39358 (void)tmem_pampd_replace_in_obj(obj, index, pampd, 1);
39359- (*tmem_pamops.create_finish)(pampd, is_ephemeral(obj->pool));
39360+ (tmem_pamops->create_finish)(pampd, is_ephemeral(obj->pool));
39361 } else if (delete) {
39362 BUG_ON(obj == NULL);
39363 (void)tmem_pampd_delete_from_obj(obj, index);
39364@@ -671,7 +671,7 @@ static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
39365 int ret = 0;
39366
39367 if (!is_ephemeral(pool))
39368- new_pampd = (*tmem_pamops.repatriate_preload)(
39369+ new_pampd = (tmem_pamops->repatriate_preload)(
39370 old_pampd, pool, oidp, index, &intransit);
39371 if (intransit)
39372 ret = -EAGAIN;
39373@@ -680,7 +680,7 @@ static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
39374 /* must release the hb->lock else repatriate can't sleep */
39375 spin_unlock(&hb->lock);
39376 if (!intransit)
39377- ret = (*tmem_pamops.repatriate)(old_pampd, new_pampd, pool,
39378+ ret = (tmem_pamops->repatriate)(old_pampd, new_pampd, pool,
39379 oidp, index, free, data);
39380 if (ret == -EAGAIN) {
39381 /* rare I think, but should cond_resched()??? */
39382@@ -714,7 +714,7 @@ int tmem_replace(struct tmem_pool *pool, struct tmem_oid *oidp,
39383 new_pampd = tmem_pampd_replace_in_obj(obj, index, new_pampd, 0);
39384 /* if we bug here, pamops wasn't properly set up for ramster */
39385 BUG_ON(tmem_pamops.replace_in_obj == NULL);
39386- ret = (*tmem_pamops.replace_in_obj)(new_pampd, obj);
39387+ ret = (tmem_pamops->replace_in_obj)(new_pampd, obj);
39388 out:
39389 spin_unlock(&hb->lock);
39390 return ret;
39391@@ -776,15 +776,15 @@ int tmem_get(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
39392 if (free) {
39393 if (obj->pampd_count == 0) {
39394 tmem_obj_free(obj, hb);
39395- (*tmem_hostops.obj_free)(obj, pool);
39396+ (tmem_hostops->obj_free)(obj, pool);
39397 obj = NULL;
39398 }
39399 }
39400 if (free)
39401- ret = (*tmem_pamops.get_data_and_free)(
39402+ ret = (tmem_pamops->get_data_and_free)(
39403 data, sizep, raw, pampd, pool, oidp, index);
39404 else
39405- ret = (*tmem_pamops.get_data)(
39406+ ret = (tmem_pamops->get_data)(
39407 data, sizep, raw, pampd, pool, oidp, index);
39408 if (ret < 0)
39409 goto out;
39410@@ -816,10 +816,10 @@ int tmem_flush_page(struct tmem_pool *pool,
39411 pampd = tmem_pampd_delete_from_obj(obj, index);
39412 if (pampd == NULL)
39413 goto out;
39414- (*tmem_pamops.free)(pampd, pool, oidp, index, true);
39415+ (tmem_pamops->free)(pampd, pool, oidp, index, true);
39416 if (obj->pampd_count == 0) {
39417 tmem_obj_free(obj, hb);
39418- (*tmem_hostops.obj_free)(obj, pool);
39419+ (tmem_hostops->obj_free)(obj, pool);
39420 }
39421 ret = 0;
39422
39423@@ -844,7 +844,7 @@ int tmem_flush_object(struct tmem_pool *pool, struct tmem_oid *oidp)
39424 goto out;
39425 tmem_pampd_destroy_all_in_obj(obj, false);
39426 tmem_obj_free(obj, hb);
39427- (*tmem_hostops.obj_free)(obj, pool);
39428+ (tmem_hostops->obj_free)(obj, pool);
39429 ret = 0;
39430
39431 out:
39432diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
39433index dc23395..cf7e9b1 100644
39434--- a/drivers/staging/rtl8712/rtl871x_io.h
39435+++ b/drivers/staging/rtl8712/rtl871x_io.h
39436@@ -108,7 +108,7 @@ struct _io_ops {
39437 u8 *pmem);
39438 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
39439 u8 *pmem);
39440-};
39441+} __no_const;
39442
39443 struct io_req {
39444 struct list_head list;
39445diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
39446index 180c963..1f18377 100644
39447--- a/drivers/staging/sbe-2t3e3/netdev.c
39448+++ b/drivers/staging/sbe-2t3e3/netdev.c
39449@@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
39450 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
39451
39452 if (rlen)
39453- if (copy_to_user(data, &resp, rlen))
39454+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
39455 return -EFAULT;
39456
39457 return 0;
39458diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
39459index c66b8b3..a4a035b 100644
39460--- a/drivers/staging/usbip/vhci.h
39461+++ b/drivers/staging/usbip/vhci.h
39462@@ -83,7 +83,7 @@ struct vhci_hcd {
39463 unsigned resuming:1;
39464 unsigned long re_timeout;
39465
39466- atomic_t seqnum;
39467+ atomic_unchecked_t seqnum;
39468
39469 /*
39470 * NOTE:
39471diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
39472index 620d1be..1cd6711 100644
39473--- a/drivers/staging/usbip/vhci_hcd.c
39474+++ b/drivers/staging/usbip/vhci_hcd.c
39475@@ -471,7 +471,7 @@ static void vhci_tx_urb(struct urb *urb)
39476 return;
39477 }
39478
39479- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
39480+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
39481 if (priv->seqnum == 0xffff)
39482 dev_info(&urb->dev->dev, "seqnum max\n");
39483
39484@@ -723,7 +723,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
39485 return -ENOMEM;
39486 }
39487
39488- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
39489+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
39490 if (unlink->seqnum == 0xffff)
39491 pr_info("seqnum max\n");
39492
39493@@ -924,7 +924,7 @@ static int vhci_start(struct usb_hcd *hcd)
39494 vdev->rhport = rhport;
39495 }
39496
39497- atomic_set(&vhci->seqnum, 0);
39498+ atomic_set_unchecked(&vhci->seqnum, 0);
39499 spin_lock_init(&vhci->lock);
39500
39501 hcd->power_budget = 0; /* no limit */
39502diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
39503index f0eaf04..5a82e06 100644
39504--- a/drivers/staging/usbip/vhci_rx.c
39505+++ b/drivers/staging/usbip/vhci_rx.c
39506@@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
39507 if (!urb) {
39508 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
39509 pr_info("max seqnum %d\n",
39510- atomic_read(&the_controller->seqnum));
39511+ atomic_read_unchecked(&the_controller->seqnum));
39512 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
39513 return;
39514 }
39515diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
39516index 67b1b88..6392fe9 100644
39517--- a/drivers/staging/vt6655/hostap.c
39518+++ b/drivers/staging/vt6655/hostap.c
39519@@ -73,14 +73,13 @@ static int msglevel =MSG_LEVEL_INFO;
39520 *
39521 */
39522
39523+static net_device_ops_no_const apdev_netdev_ops;
39524+
39525 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
39526 {
39527 PSDevice apdev_priv;
39528 struct net_device *dev = pDevice->dev;
39529 int ret;
39530- const struct net_device_ops apdev_netdev_ops = {
39531- .ndo_start_xmit = pDevice->tx_80211,
39532- };
39533
39534 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
39535
39536@@ -92,6 +91,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
39537 *apdev_priv = *pDevice;
39538 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
39539
39540+ /* only half broken now */
39541+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
39542 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
39543
39544 pDevice->apdev->type = ARPHRD_IEEE80211;
39545diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
39546index 0a73d40..6fda560 100644
39547--- a/drivers/staging/vt6656/hostap.c
39548+++ b/drivers/staging/vt6656/hostap.c
39549@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
39550 *
39551 */
39552
39553+static net_device_ops_no_const apdev_netdev_ops;
39554+
39555 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
39556 {
39557 PSDevice apdev_priv;
39558 struct net_device *dev = pDevice->dev;
39559 int ret;
39560- const struct net_device_ops apdev_netdev_ops = {
39561- .ndo_start_xmit = pDevice->tx_80211,
39562- };
39563
39564 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
39565
39566@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
39567 *apdev_priv = *pDevice;
39568 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
39569
39570+ /* only half broken now */
39571+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
39572 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
39573
39574 pDevice->apdev->type = ARPHRD_IEEE80211;
39575diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
39576index 56c8e60..1920c63 100644
39577--- a/drivers/staging/zcache/tmem.c
39578+++ b/drivers/staging/zcache/tmem.c
39579@@ -39,7 +39,7 @@
39580 * A tmem host implementation must use this function to register callbacks
39581 * for memory allocation.
39582 */
39583-static struct tmem_hostops tmem_hostops;
39584+static tmem_hostops_no_const tmem_hostops;
39585
39586 static void tmem_objnode_tree_init(void);
39587
39588@@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
39589 * A tmem host implementation must use this function to register
39590 * callbacks for a page-accessible memory (PAM) implementation
39591 */
39592-static struct tmem_pamops tmem_pamops;
39593+static tmem_pamops_no_const tmem_pamops;
39594
39595 void tmem_register_pamops(struct tmem_pamops *m)
39596 {
39597diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
39598index 0d4aa82..f7832d4 100644
39599--- a/drivers/staging/zcache/tmem.h
39600+++ b/drivers/staging/zcache/tmem.h
39601@@ -180,6 +180,7 @@ struct tmem_pamops {
39602 void (*new_obj)(struct tmem_obj *);
39603 int (*replace_in_obj)(void *, struct tmem_obj *);
39604 };
39605+typedef struct tmem_pamops __no_const tmem_pamops_no_const;
39606 extern void tmem_register_pamops(struct tmem_pamops *m);
39607
39608 /* memory allocation methods provided by the host implementation */
39609@@ -189,6 +190,7 @@ struct tmem_hostops {
39610 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
39611 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
39612 };
39613+typedef struct tmem_hostops __no_const tmem_hostops_no_const;
39614 extern void tmem_register_hostops(struct tmem_hostops *m);
39615
39616 /* core tmem accessor functions */
39617diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
39618index 13fe16c..cbdc39a 100644
39619--- a/drivers/target/target_core_transport.c
39620+++ b/drivers/target/target_core_transport.c
39621@@ -1085,7 +1085,7 @@ struct se_device *transport_add_device_to_core_hba(
39622 spin_lock_init(&dev->se_port_lock);
39623 spin_lock_init(&dev->se_tmr_lock);
39624 spin_lock_init(&dev->qf_cmd_lock);
39625- atomic_set(&dev->dev_ordered_id, 0);
39626+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
39627
39628 se_dev_set_default_attribs(dev, dev_limits);
39629
39630@@ -1275,7 +1275,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
39631 * Used to determine when ORDERED commands should go from
39632 * Dormant to Active status.
39633 */
39634- cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
39635+ cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
39636 smp_mb__after_atomic_inc();
39637 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
39638 cmd->se_ordered_id, cmd->sam_task_attr,
39639diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
39640index 0a6a0bc..5501b06 100644
39641--- a/drivers/tty/cyclades.c
39642+++ b/drivers/tty/cyclades.c
39643@@ -1589,10 +1589,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
39644 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
39645 info->port.count);
39646 #endif
39647- info->port.count++;
39648+ atomic_inc(&info->port.count);
39649 #ifdef CY_DEBUG_COUNT
39650 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
39651- current->pid, info->port.count);
39652+ current->pid, atomic_read(&info->port.count));
39653 #endif
39654
39655 /*
39656@@ -3989,7 +3989,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
39657 for (j = 0; j < cy_card[i].nports; j++) {
39658 info = &cy_card[i].ports[j];
39659
39660- if (info->port.count) {
39661+ if (atomic_read(&info->port.count)) {
39662 /* XXX is the ldisc num worth this? */
39663 struct tty_struct *tty;
39664 struct tty_ldisc *ld;
39665diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
39666index 13ee53b..418d164 100644
39667--- a/drivers/tty/hvc/hvc_console.c
39668+++ b/drivers/tty/hvc/hvc_console.c
39669@@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
39670
39671 spin_lock_irqsave(&hp->port.lock, flags);
39672 /* Check and then increment for fast path open. */
39673- if (hp->port.count++ > 0) {
39674+ if (atomic_inc_return(&hp->port.count) > 1) {
39675 spin_unlock_irqrestore(&hp->port.lock, flags);
39676 hvc_kick();
39677 return 0;
39678@@ -388,7 +388,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
39679
39680 spin_lock_irqsave(&hp->port.lock, flags);
39681
39682- if (--hp->port.count == 0) {
39683+ if (atomic_dec_return(&hp->port.count) == 0) {
39684 spin_unlock_irqrestore(&hp->port.lock, flags);
39685 /* We are done with the tty pointer now. */
39686 tty_port_tty_set(&hp->port, NULL);
39687@@ -406,9 +406,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
39688 */
39689 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
39690 } else {
39691- if (hp->port.count < 0)
39692+ if (atomic_read(&hp->port.count) < 0)
39693 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
39694- hp->vtermno, hp->port.count);
39695+ hp->vtermno, atomic_read(&hp->port.count));
39696 spin_unlock_irqrestore(&hp->port.lock, flags);
39697 }
39698 }
39699@@ -438,12 +438,12 @@ static void hvc_hangup(struct tty_struct *tty)
39700 * open->hangup case this can be called after the final close so prevent
39701 * that from happening for now.
39702 */
39703- if (hp->port.count <= 0) {
39704+ if (atomic_read(&hp->port.count) <= 0) {
39705 spin_unlock_irqrestore(&hp->port.lock, flags);
39706 return;
39707 }
39708
39709- hp->port.count = 0;
39710+ atomic_set(&hp->port.count, 0);
39711 spin_unlock_irqrestore(&hp->port.lock, flags);
39712 tty_port_tty_set(&hp->port, NULL);
39713
39714@@ -491,7 +491,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
39715 return -EPIPE;
39716
39717 /* FIXME what's this (unprotected) check for? */
39718- if (hp->port.count <= 0)
39719+ if (atomic_read(&hp->port.count) <= 0)
39720 return -EIO;
39721
39722 spin_lock_irqsave(&hp->lock, flags);
39723diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
39724index cab5c7a..4cc66ea 100644
39725--- a/drivers/tty/hvc/hvcs.c
39726+++ b/drivers/tty/hvc/hvcs.c
39727@@ -83,6 +83,7 @@
39728 #include <asm/hvcserver.h>
39729 #include <asm/uaccess.h>
39730 #include <asm/vio.h>
39731+#include <asm/local.h>
39732
39733 /*
39734 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
39735@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
39736
39737 spin_lock_irqsave(&hvcsd->lock, flags);
39738
39739- if (hvcsd->port.count > 0) {
39740+ if (atomic_read(&hvcsd->port.count) > 0) {
39741 spin_unlock_irqrestore(&hvcsd->lock, flags);
39742 printk(KERN_INFO "HVCS: vterm state unchanged. "
39743 "The hvcs device node is still in use.\n");
39744@@ -1132,7 +1133,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
39745 }
39746 }
39747
39748- hvcsd->port.count = 0;
39749+ atomic_set(&hvcsd->port.count, 0);
39750 hvcsd->port.tty = tty;
39751 tty->driver_data = hvcsd;
39752
39753@@ -1185,7 +1186,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
39754 unsigned long flags;
39755
39756 spin_lock_irqsave(&hvcsd->lock, flags);
39757- hvcsd->port.count++;
39758+ atomic_inc(&hvcsd->port.count);
39759 hvcsd->todo_mask |= HVCS_SCHED_READ;
39760 spin_unlock_irqrestore(&hvcsd->lock, flags);
39761
39762@@ -1221,7 +1222,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
39763 hvcsd = tty->driver_data;
39764
39765 spin_lock_irqsave(&hvcsd->lock, flags);
39766- if (--hvcsd->port.count == 0) {
39767+ if (atomic_dec_and_test(&hvcsd->port.count)) {
39768
39769 vio_disable_interrupts(hvcsd->vdev);
39770
39771@@ -1246,10 +1247,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
39772
39773 free_irq(irq, hvcsd);
39774 return;
39775- } else if (hvcsd->port.count < 0) {
39776+ } else if (atomic_read(&hvcsd->port.count) < 0) {
39777 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
39778 " is missmanaged.\n",
39779- hvcsd->vdev->unit_address, hvcsd->port.count);
39780+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
39781 }
39782
39783 spin_unlock_irqrestore(&hvcsd->lock, flags);
39784@@ -1271,7 +1272,7 @@ static void hvcs_hangup(struct tty_struct * tty)
39785
39786 spin_lock_irqsave(&hvcsd->lock, flags);
39787 /* Preserve this so that we know how many kref refs to put */
39788- temp_open_count = hvcsd->port.count;
39789+ temp_open_count = atomic_read(&hvcsd->port.count);
39790
39791 /*
39792 * Don't kref put inside the spinlock because the destruction
39793@@ -1286,7 +1287,7 @@ static void hvcs_hangup(struct tty_struct * tty)
39794 tty->driver_data = NULL;
39795 hvcsd->port.tty = NULL;
39796
39797- hvcsd->port.count = 0;
39798+ atomic_set(&hvcsd->port.count, 0);
39799
39800 /* This will drop any buffered data on the floor which is OK in a hangup
39801 * scenario. */
39802@@ -1357,7 +1358,7 @@ static int hvcs_write(struct tty_struct *tty,
39803 * the middle of a write operation? This is a crummy place to do this
39804 * but we want to keep it all in the spinlock.
39805 */
39806- if (hvcsd->port.count <= 0) {
39807+ if (atomic_read(&hvcsd->port.count) <= 0) {
39808 spin_unlock_irqrestore(&hvcsd->lock, flags);
39809 return -ENODEV;
39810 }
39811@@ -1431,7 +1432,7 @@ static int hvcs_write_room(struct tty_struct *tty)
39812 {
39813 struct hvcs_struct *hvcsd = tty->driver_data;
39814
39815- if (!hvcsd || hvcsd->port.count <= 0)
39816+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
39817 return 0;
39818
39819 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
39820diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
39821index 160f0ad..588b853 100644
39822--- a/drivers/tty/ipwireless/tty.c
39823+++ b/drivers/tty/ipwireless/tty.c
39824@@ -29,6 +29,7 @@
39825 #include <linux/tty_driver.h>
39826 #include <linux/tty_flip.h>
39827 #include <linux/uaccess.h>
39828+#include <asm/local.h>
39829
39830 #include "tty.h"
39831 #include "network.h"
39832@@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
39833 mutex_unlock(&tty->ipw_tty_mutex);
39834 return -ENODEV;
39835 }
39836- if (tty->port.count == 0)
39837+ if (atomic_read(&tty->port.count) == 0)
39838 tty->tx_bytes_queued = 0;
39839
39840- tty->port.count++;
39841+ atomic_inc(&tty->port.count);
39842
39843 tty->port.tty = linux_tty;
39844 linux_tty->driver_data = tty;
39845@@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
39846
39847 static void do_ipw_close(struct ipw_tty *tty)
39848 {
39849- tty->port.count--;
39850-
39851- if (tty->port.count == 0) {
39852+ if (atomic_dec_return(&tty->port.count) == 0) {
39853 struct tty_struct *linux_tty = tty->port.tty;
39854
39855 if (linux_tty != NULL) {
39856@@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
39857 return;
39858
39859 mutex_lock(&tty->ipw_tty_mutex);
39860- if (tty->port.count == 0) {
39861+ if (atomic_read(&tty->port.count) == 0) {
39862 mutex_unlock(&tty->ipw_tty_mutex);
39863 return;
39864 }
39865@@ -170,7 +169,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
39866 return;
39867 }
39868
39869- if (!tty->port.count) {
39870+ if (!atomic_read(&tty->port.count)) {
39871 mutex_unlock(&tty->ipw_tty_mutex);
39872 return;
39873 }
39874@@ -212,7 +211,7 @@ static int ipw_write(struct tty_struct *linux_tty,
39875 return -ENODEV;
39876
39877 mutex_lock(&tty->ipw_tty_mutex);
39878- if (!tty->port.count) {
39879+ if (!atomic_read(&tty->port.count)) {
39880 mutex_unlock(&tty->ipw_tty_mutex);
39881 return -EINVAL;
39882 }
39883@@ -252,7 +251,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
39884 if (!tty)
39885 return -ENODEV;
39886
39887- if (!tty->port.count)
39888+ if (!atomic_read(&tty->port.count))
39889 return -EINVAL;
39890
39891 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
39892@@ -294,7 +293,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
39893 if (!tty)
39894 return 0;
39895
39896- if (!tty->port.count)
39897+ if (!atomic_read(&tty->port.count))
39898 return 0;
39899
39900 return tty->tx_bytes_queued;
39901@@ -375,7 +374,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
39902 if (!tty)
39903 return -ENODEV;
39904
39905- if (!tty->port.count)
39906+ if (!atomic_read(&tty->port.count))
39907 return -EINVAL;
39908
39909 return get_control_lines(tty);
39910@@ -391,7 +390,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
39911 if (!tty)
39912 return -ENODEV;
39913
39914- if (!tty->port.count)
39915+ if (!atomic_read(&tty->port.count))
39916 return -EINVAL;
39917
39918 return set_control_lines(tty, set, clear);
39919@@ -405,7 +404,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
39920 if (!tty)
39921 return -ENODEV;
39922
39923- if (!tty->port.count)
39924+ if (!atomic_read(&tty->port.count))
39925 return -EINVAL;
39926
39927 /* FIXME: Exactly how is the tty object locked here .. */
39928@@ -561,7 +560,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
39929 * are gone */
39930 mutex_lock(&ttyj->ipw_tty_mutex);
39931 }
39932- while (ttyj->port.count)
39933+ while (atomic_read(&ttyj->port.count))
39934 do_ipw_close(ttyj);
39935 ipwireless_disassociate_network_ttys(network,
39936 ttyj->channel_idx);
39937diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
39938index 56e616b..9d9f10a 100644
39939--- a/drivers/tty/moxa.c
39940+++ b/drivers/tty/moxa.c
39941@@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
39942 }
39943
39944 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
39945- ch->port.count++;
39946+ atomic_inc(&ch->port.count);
39947 tty->driver_data = ch;
39948 tty_port_tty_set(&ch->port, tty);
39949 mutex_lock(&ch->port.mutex);
39950diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
39951index 1e8e8ce..a9efc93 100644
39952--- a/drivers/tty/n_gsm.c
39953+++ b/drivers/tty/n_gsm.c
39954@@ -1638,7 +1638,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
39955 kref_init(&dlci->ref);
39956 mutex_init(&dlci->mutex);
39957 dlci->fifo = &dlci->_fifo;
39958- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
39959+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
39960 kfree(dlci);
39961 return NULL;
39962 }
39963@@ -2925,7 +2925,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
39964 struct gsm_dlci *dlci = tty->driver_data;
39965 struct tty_port *port = &dlci->port;
39966
39967- port->count++;
39968+ atomic_inc(&port->count);
39969 dlci_get(dlci);
39970 dlci_get(dlci->gsm->dlci[0]);
39971 mux_get(dlci->gsm);
39972diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
39973index 8c0b7b4..e88f052 100644
39974--- a/drivers/tty/n_tty.c
39975+++ b/drivers/tty/n_tty.c
39976@@ -2142,6 +2142,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
39977 {
39978 *ops = tty_ldisc_N_TTY;
39979 ops->owner = NULL;
39980- ops->refcount = ops->flags = 0;
39981+ atomic_set(&ops->refcount, 0);
39982+ ops->flags = 0;
39983 }
39984 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
39985diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
39986index 8cf8d0a..4ef9ed0 100644
39987--- a/drivers/tty/pty.c
39988+++ b/drivers/tty/pty.c
39989@@ -730,8 +730,10 @@ static void __init unix98_pty_init(void)
39990 panic("Couldn't register Unix98 pts driver");
39991
39992 /* Now create the /dev/ptmx special device */
39993+ pax_open_kernel();
39994 tty_default_fops(&ptmx_fops);
39995- ptmx_fops.open = ptmx_open;
39996+ *(void **)&ptmx_fops.open = ptmx_open;
39997+ pax_close_kernel();
39998
39999 cdev_init(&ptmx_cdev, &ptmx_fops);
40000 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
40001diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
40002index 9700d34..df7520c 100644
40003--- a/drivers/tty/rocket.c
40004+++ b/drivers/tty/rocket.c
40005@@ -924,7 +924,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
40006 tty->driver_data = info;
40007 tty_port_tty_set(port, tty);
40008
40009- if (port->count++ == 0) {
40010+ if (atomic_inc_return(&port->count) == 1) {
40011 atomic_inc(&rp_num_ports_open);
40012
40013 #ifdef ROCKET_DEBUG_OPEN
40014@@ -933,7 +933,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
40015 #endif
40016 }
40017 #ifdef ROCKET_DEBUG_OPEN
40018- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
40019+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
40020 #endif
40021
40022 /*
40023@@ -1528,7 +1528,7 @@ static void rp_hangup(struct tty_struct *tty)
40024 spin_unlock_irqrestore(&info->port.lock, flags);
40025 return;
40026 }
40027- if (info->port.count)
40028+ if (atomic_read(&info->port.count))
40029 atomic_dec(&rp_num_ports_open);
40030 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
40031 spin_unlock_irqrestore(&info->port.lock, flags);
40032diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
40033index 1002054..dd644a8 100644
40034--- a/drivers/tty/serial/kgdboc.c
40035+++ b/drivers/tty/serial/kgdboc.c
40036@@ -24,8 +24,9 @@
40037 #define MAX_CONFIG_LEN 40
40038
40039 static struct kgdb_io kgdboc_io_ops;
40040+static struct kgdb_io kgdboc_io_ops_console;
40041
40042-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
40043+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
40044 static int configured = -1;
40045
40046 static char config[MAX_CONFIG_LEN];
40047@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
40048 kgdboc_unregister_kbd();
40049 if (configured == 1)
40050 kgdb_unregister_io_module(&kgdboc_io_ops);
40051+ else if (configured == 2)
40052+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
40053 }
40054
40055 static int configure_kgdboc(void)
40056@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
40057 int err;
40058 char *cptr = config;
40059 struct console *cons;
40060+ int is_console = 0;
40061
40062 err = kgdboc_option_setup(config);
40063 if (err || !strlen(config) || isspace(config[0]))
40064 goto noconfig;
40065
40066 err = -ENODEV;
40067- kgdboc_io_ops.is_console = 0;
40068 kgdb_tty_driver = NULL;
40069
40070 kgdboc_use_kms = 0;
40071@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
40072 int idx;
40073 if (cons->device && cons->device(cons, &idx) == p &&
40074 idx == tty_line) {
40075- kgdboc_io_ops.is_console = 1;
40076+ is_console = 1;
40077 break;
40078 }
40079 cons = cons->next;
40080@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
40081 kgdb_tty_line = tty_line;
40082
40083 do_register:
40084- err = kgdb_register_io_module(&kgdboc_io_ops);
40085+ if (is_console) {
40086+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
40087+ configured = 2;
40088+ } else {
40089+ err = kgdb_register_io_module(&kgdboc_io_ops);
40090+ configured = 1;
40091+ }
40092 if (err)
40093 goto noconfig;
40094
40095@@ -205,8 +214,6 @@ do_register:
40096 if (err)
40097 goto nmi_con_failed;
40098
40099- configured = 1;
40100-
40101 return 0;
40102
40103 nmi_con_failed:
40104@@ -223,7 +230,7 @@ noconfig:
40105 static int __init init_kgdboc(void)
40106 {
40107 /* Already configured? */
40108- if (configured == 1)
40109+ if (configured >= 1)
40110 return 0;
40111
40112 return configure_kgdboc();
40113@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
40114 if (config[len - 1] == '\n')
40115 config[len - 1] = '\0';
40116
40117- if (configured == 1)
40118+ if (configured >= 1)
40119 cleanup_kgdboc();
40120
40121 /* Go and configure with the new params. */
40122@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
40123 .post_exception = kgdboc_post_exp_handler,
40124 };
40125
40126+static struct kgdb_io kgdboc_io_ops_console = {
40127+ .name = "kgdboc",
40128+ .read_char = kgdboc_get_char,
40129+ .write_char = kgdboc_put_char,
40130+ .pre_exception = kgdboc_pre_exp_handler,
40131+ .post_exception = kgdboc_post_exp_handler,
40132+ .is_console = 1
40133+};
40134+
40135 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
40136 /* This is only available if kgdboc is a built in for early debugging */
40137 static int __init kgdboc_early_init(char *opt)
40138diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
40139index 7f04717..0f3794f 100644
40140--- a/drivers/tty/serial/samsung.c
40141+++ b/drivers/tty/serial/samsung.c
40142@@ -445,11 +445,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
40143 }
40144 }
40145
40146+static int s3c64xx_serial_startup(struct uart_port *port);
40147 static int s3c24xx_serial_startup(struct uart_port *port)
40148 {
40149 struct s3c24xx_uart_port *ourport = to_ourport(port);
40150 int ret;
40151
40152+ /* Startup sequence is different for s3c64xx and higher SoC's */
40153+ if (s3c24xx_serial_has_interrupt_mask(port))
40154+ return s3c64xx_serial_startup(port);
40155+
40156 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
40157 port->mapbase, port->membase);
40158
40159@@ -1115,10 +1120,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
40160 /* setup info for port */
40161 port->dev = &platdev->dev;
40162
40163- /* Startup sequence is different for s3c64xx and higher SoC's */
40164- if (s3c24xx_serial_has_interrupt_mask(port))
40165- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
40166-
40167 port->uartclk = 1;
40168
40169 if (cfg->uart_flags & UPF_CONS_FLOW) {
40170diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
40171index 0fcfd98..8244fce 100644
40172--- a/drivers/tty/serial/serial_core.c
40173+++ b/drivers/tty/serial/serial_core.c
40174@@ -1408,7 +1408,7 @@ static void uart_hangup(struct tty_struct *tty)
40175 uart_flush_buffer(tty);
40176 uart_shutdown(tty, state);
40177 spin_lock_irqsave(&port->lock, flags);
40178- port->count = 0;
40179+ atomic_set(&port->count, 0);
40180 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
40181 spin_unlock_irqrestore(&port->lock, flags);
40182 tty_port_tty_set(port, NULL);
40183@@ -1504,7 +1504,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
40184 goto end;
40185 }
40186
40187- port->count++;
40188+ atomic_inc(&port->count);
40189 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
40190 retval = -ENXIO;
40191 goto err_dec_count;
40192@@ -1531,7 +1531,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
40193 /*
40194 * Make sure the device is in D0 state.
40195 */
40196- if (port->count == 1)
40197+ if (atomic_read(&port->count) == 1)
40198 uart_change_pm(state, 0);
40199
40200 /*
40201@@ -1549,7 +1549,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
40202 end:
40203 return retval;
40204 err_dec_count:
40205- port->count--;
40206+ atomic_inc(&port->count);
40207 mutex_unlock(&port->mutex);
40208 goto end;
40209 }
40210diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
40211index 70e3a52..5742052 100644
40212--- a/drivers/tty/synclink.c
40213+++ b/drivers/tty/synclink.c
40214@@ -3095,7 +3095,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
40215
40216 if (debug_level >= DEBUG_LEVEL_INFO)
40217 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
40218- __FILE__,__LINE__, info->device_name, info->port.count);
40219+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
40220
40221 if (tty_port_close_start(&info->port, tty, filp) == 0)
40222 goto cleanup;
40223@@ -3113,7 +3113,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
40224 cleanup:
40225 if (debug_level >= DEBUG_LEVEL_INFO)
40226 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
40227- tty->driver->name, info->port.count);
40228+ tty->driver->name, atomic_read(&info->port.count));
40229
40230 } /* end of mgsl_close() */
40231
40232@@ -3212,8 +3212,8 @@ static void mgsl_hangup(struct tty_struct *tty)
40233
40234 mgsl_flush_buffer(tty);
40235 shutdown(info);
40236-
40237- info->port.count = 0;
40238+
40239+ atomic_set(&info->port.count, 0);
40240 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
40241 info->port.tty = NULL;
40242
40243@@ -3302,12 +3302,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
40244
40245 if (debug_level >= DEBUG_LEVEL_INFO)
40246 printk("%s(%d):block_til_ready before block on %s count=%d\n",
40247- __FILE__,__LINE__, tty->driver->name, port->count );
40248+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
40249
40250 spin_lock_irqsave(&info->irq_spinlock, flags);
40251 if (!tty_hung_up_p(filp)) {
40252 extra_count = true;
40253- port->count--;
40254+ atomic_dec(&port->count);
40255 }
40256 spin_unlock_irqrestore(&info->irq_spinlock, flags);
40257 port->blocked_open++;
40258@@ -3336,7 +3336,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
40259
40260 if (debug_level >= DEBUG_LEVEL_INFO)
40261 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
40262- __FILE__,__LINE__, tty->driver->name, port->count );
40263+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
40264
40265 tty_unlock(tty);
40266 schedule();
40267@@ -3348,12 +3348,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
40268
40269 /* FIXME: Racy on hangup during close wait */
40270 if (extra_count)
40271- port->count++;
40272+ atomic_inc(&port->count);
40273 port->blocked_open--;
40274
40275 if (debug_level >= DEBUG_LEVEL_INFO)
40276 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
40277- __FILE__,__LINE__, tty->driver->name, port->count );
40278+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
40279
40280 if (!retval)
40281 port->flags |= ASYNC_NORMAL_ACTIVE;
40282@@ -3405,7 +3405,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
40283
40284 if (debug_level >= DEBUG_LEVEL_INFO)
40285 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
40286- __FILE__,__LINE__,tty->driver->name, info->port.count);
40287+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
40288
40289 /* If port is closing, signal caller to try again */
40290 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
40291@@ -3424,10 +3424,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
40292 spin_unlock_irqrestore(&info->netlock, flags);
40293 goto cleanup;
40294 }
40295- info->port.count++;
40296+ atomic_inc(&info->port.count);
40297 spin_unlock_irqrestore(&info->netlock, flags);
40298
40299- if (info->port.count == 1) {
40300+ if (atomic_read(&info->port.count) == 1) {
40301 /* 1st open on this device, init hardware */
40302 retval = startup(info);
40303 if (retval < 0)
40304@@ -3451,8 +3451,8 @@ cleanup:
40305 if (retval) {
40306 if (tty->count == 1)
40307 info->port.tty = NULL; /* tty layer will release tty struct */
40308- if(info->port.count)
40309- info->port.count--;
40310+ if (atomic_read(&info->port.count))
40311+ atomic_dec(&info->port.count);
40312 }
40313
40314 return retval;
40315@@ -7661,7 +7661,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
40316 unsigned short new_crctype;
40317
40318 /* return error if TTY interface open */
40319- if (info->port.count)
40320+ if (atomic_read(&info->port.count))
40321 return -EBUSY;
40322
40323 switch (encoding)
40324@@ -7756,7 +7756,7 @@ static int hdlcdev_open(struct net_device *dev)
40325
40326 /* arbitrate between network and tty opens */
40327 spin_lock_irqsave(&info->netlock, flags);
40328- if (info->port.count != 0 || info->netcount != 0) {
40329+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
40330 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
40331 spin_unlock_irqrestore(&info->netlock, flags);
40332 return -EBUSY;
40333@@ -7842,7 +7842,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
40334 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
40335
40336 /* return error if TTY interface open */
40337- if (info->port.count)
40338+ if (atomic_read(&info->port.count))
40339 return -EBUSY;
40340
40341 if (cmd != SIOCWANDEV)
40342diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
40343index b38e954..ce45b38 100644
40344--- a/drivers/tty/synclink_gt.c
40345+++ b/drivers/tty/synclink_gt.c
40346@@ -671,7 +671,7 @@ static int open(struct tty_struct *tty, struct file *filp)
40347 tty->driver_data = info;
40348 info->port.tty = tty;
40349
40350- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
40351+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
40352
40353 /* If port is closing, signal caller to try again */
40354 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
40355@@ -692,10 +692,10 @@ static int open(struct tty_struct *tty, struct file *filp)
40356 mutex_unlock(&info->port.mutex);
40357 goto cleanup;
40358 }
40359- info->port.count++;
40360+ atomic_inc(&info->port.count);
40361 spin_unlock_irqrestore(&info->netlock, flags);
40362
40363- if (info->port.count == 1) {
40364+ if (atomic_read(&info->port.count) == 1) {
40365 /* 1st open on this device, init hardware */
40366 retval = startup(info);
40367 if (retval < 0) {
40368@@ -716,8 +716,8 @@ cleanup:
40369 if (retval) {
40370 if (tty->count == 1)
40371 info->port.tty = NULL; /* tty layer will release tty struct */
40372- if(info->port.count)
40373- info->port.count--;
40374+ if(atomic_read(&info->port.count))
40375+ atomic_dec(&info->port.count);
40376 }
40377
40378 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
40379@@ -730,7 +730,7 @@ static void close(struct tty_struct *tty, struct file *filp)
40380
40381 if (sanity_check(info, tty->name, "close"))
40382 return;
40383- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
40384+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
40385
40386 if (tty_port_close_start(&info->port, tty, filp) == 0)
40387 goto cleanup;
40388@@ -747,7 +747,7 @@ static void close(struct tty_struct *tty, struct file *filp)
40389 tty_port_close_end(&info->port, tty);
40390 info->port.tty = NULL;
40391 cleanup:
40392- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
40393+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
40394 }
40395
40396 static void hangup(struct tty_struct *tty)
40397@@ -765,7 +765,7 @@ static void hangup(struct tty_struct *tty)
40398 shutdown(info);
40399
40400 spin_lock_irqsave(&info->port.lock, flags);
40401- info->port.count = 0;
40402+ atomic_set(&info->port.count, 0);
40403 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
40404 info->port.tty = NULL;
40405 spin_unlock_irqrestore(&info->port.lock, flags);
40406@@ -1450,7 +1450,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
40407 unsigned short new_crctype;
40408
40409 /* return error if TTY interface open */
40410- if (info->port.count)
40411+ if (atomic_read(&info->port.count))
40412 return -EBUSY;
40413
40414 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
40415@@ -1545,7 +1545,7 @@ static int hdlcdev_open(struct net_device *dev)
40416
40417 /* arbitrate between network and tty opens */
40418 spin_lock_irqsave(&info->netlock, flags);
40419- if (info->port.count != 0 || info->netcount != 0) {
40420+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
40421 DBGINFO(("%s hdlc_open busy\n", dev->name));
40422 spin_unlock_irqrestore(&info->netlock, flags);
40423 return -EBUSY;
40424@@ -1630,7 +1630,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
40425 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
40426
40427 /* return error if TTY interface open */
40428- if (info->port.count)
40429+ if (atomic_read(&info->port.count))
40430 return -EBUSY;
40431
40432 if (cmd != SIOCWANDEV)
40433@@ -2419,7 +2419,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
40434 if (port == NULL)
40435 continue;
40436 spin_lock(&port->lock);
40437- if ((port->port.count || port->netcount) &&
40438+ if ((atomic_read(&port->port.count) || port->netcount) &&
40439 port->pending_bh && !port->bh_running &&
40440 !port->bh_requested) {
40441 DBGISR(("%s bh queued\n", port->device_name));
40442@@ -3308,7 +3308,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
40443 spin_lock_irqsave(&info->lock, flags);
40444 if (!tty_hung_up_p(filp)) {
40445 extra_count = true;
40446- port->count--;
40447+ atomic_dec(&port->count);
40448 }
40449 spin_unlock_irqrestore(&info->lock, flags);
40450 port->blocked_open++;
40451@@ -3345,7 +3345,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
40452 remove_wait_queue(&port->open_wait, &wait);
40453
40454 if (extra_count)
40455- port->count++;
40456+ atomic_inc(&port->count);
40457 port->blocked_open--;
40458
40459 if (!retval)
40460diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
40461index f17d9f3..27a041b 100644
40462--- a/drivers/tty/synclinkmp.c
40463+++ b/drivers/tty/synclinkmp.c
40464@@ -751,7 +751,7 @@ static int open(struct tty_struct *tty, struct file *filp)
40465
40466 if (debug_level >= DEBUG_LEVEL_INFO)
40467 printk("%s(%d):%s open(), old ref count = %d\n",
40468- __FILE__,__LINE__,tty->driver->name, info->port.count);
40469+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
40470
40471 /* If port is closing, signal caller to try again */
40472 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
40473@@ -770,10 +770,10 @@ static int open(struct tty_struct *tty, struct file *filp)
40474 spin_unlock_irqrestore(&info->netlock, flags);
40475 goto cleanup;
40476 }
40477- info->port.count++;
40478+ atomic_inc(&info->port.count);
40479 spin_unlock_irqrestore(&info->netlock, flags);
40480
40481- if (info->port.count == 1) {
40482+ if (atomic_read(&info->port.count) == 1) {
40483 /* 1st open on this device, init hardware */
40484 retval = startup(info);
40485 if (retval < 0)
40486@@ -797,8 +797,8 @@ cleanup:
40487 if (retval) {
40488 if (tty->count == 1)
40489 info->port.tty = NULL; /* tty layer will release tty struct */
40490- if(info->port.count)
40491- info->port.count--;
40492+ if(atomic_read(&info->port.count))
40493+ atomic_dec(&info->port.count);
40494 }
40495
40496 return retval;
40497@@ -816,7 +816,7 @@ static void close(struct tty_struct *tty, struct file *filp)
40498
40499 if (debug_level >= DEBUG_LEVEL_INFO)
40500 printk("%s(%d):%s close() entry, count=%d\n",
40501- __FILE__,__LINE__, info->device_name, info->port.count);
40502+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
40503
40504 if (tty_port_close_start(&info->port, tty, filp) == 0)
40505 goto cleanup;
40506@@ -835,7 +835,7 @@ static void close(struct tty_struct *tty, struct file *filp)
40507 cleanup:
40508 if (debug_level >= DEBUG_LEVEL_INFO)
40509 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
40510- tty->driver->name, info->port.count);
40511+ tty->driver->name, atomic_read(&info->port.count));
40512 }
40513
40514 /* Called by tty_hangup() when a hangup is signaled.
40515@@ -858,7 +858,7 @@ static void hangup(struct tty_struct *tty)
40516 shutdown(info);
40517
40518 spin_lock_irqsave(&info->port.lock, flags);
40519- info->port.count = 0;
40520+ atomic_set(&info->port.count, 0);
40521 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
40522 info->port.tty = NULL;
40523 spin_unlock_irqrestore(&info->port.lock, flags);
40524@@ -1566,7 +1566,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
40525 unsigned short new_crctype;
40526
40527 /* return error if TTY interface open */
40528- if (info->port.count)
40529+ if (atomic_read(&info->port.count))
40530 return -EBUSY;
40531
40532 switch (encoding)
40533@@ -1661,7 +1661,7 @@ static int hdlcdev_open(struct net_device *dev)
40534
40535 /* arbitrate between network and tty opens */
40536 spin_lock_irqsave(&info->netlock, flags);
40537- if (info->port.count != 0 || info->netcount != 0) {
40538+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
40539 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
40540 spin_unlock_irqrestore(&info->netlock, flags);
40541 return -EBUSY;
40542@@ -1747,7 +1747,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
40543 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
40544
40545 /* return error if TTY interface open */
40546- if (info->port.count)
40547+ if (atomic_read(&info->port.count))
40548 return -EBUSY;
40549
40550 if (cmd != SIOCWANDEV)
40551@@ -2632,7 +2632,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
40552 * do not request bottom half processing if the
40553 * device is not open in a normal mode.
40554 */
40555- if ( port && (port->port.count || port->netcount) &&
40556+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
40557 port->pending_bh && !port->bh_running &&
40558 !port->bh_requested ) {
40559 if ( debug_level >= DEBUG_LEVEL_ISR )
40560@@ -3330,12 +3330,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
40561
40562 if (debug_level >= DEBUG_LEVEL_INFO)
40563 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
40564- __FILE__,__LINE__, tty->driver->name, port->count );
40565+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
40566
40567 spin_lock_irqsave(&info->lock, flags);
40568 if (!tty_hung_up_p(filp)) {
40569 extra_count = true;
40570- port->count--;
40571+ atomic_dec(&port->count);
40572 }
40573 spin_unlock_irqrestore(&info->lock, flags);
40574 port->blocked_open++;
40575@@ -3364,7 +3364,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
40576
40577 if (debug_level >= DEBUG_LEVEL_INFO)
40578 printk("%s(%d):%s block_til_ready() count=%d\n",
40579- __FILE__,__LINE__, tty->driver->name, port->count );
40580+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
40581
40582 tty_unlock(tty);
40583 schedule();
40584@@ -3375,12 +3375,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
40585 remove_wait_queue(&port->open_wait, &wait);
40586
40587 if (extra_count)
40588- port->count++;
40589+ atomic_inc(&port->count);
40590 port->blocked_open--;
40591
40592 if (debug_level >= DEBUG_LEVEL_INFO)
40593 printk("%s(%d):%s block_til_ready() after, count=%d\n",
40594- __FILE__,__LINE__, tty->driver->name, port->count );
40595+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
40596
40597 if (!retval)
40598 port->flags |= ASYNC_NORMAL_ACTIVE;
40599diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
40600index 16ee6ce..bfcac57 100644
40601--- a/drivers/tty/sysrq.c
40602+++ b/drivers/tty/sysrq.c
40603@@ -866,7 +866,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
40604 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
40605 size_t count, loff_t *ppos)
40606 {
40607- if (count) {
40608+ if (count && capable(CAP_SYS_ADMIN)) {
40609 char c;
40610
40611 if (get_user(c, buf))
40612diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
40613index 2ea176b..2877bc8 100644
40614--- a/drivers/tty/tty_io.c
40615+++ b/drivers/tty/tty_io.c
40616@@ -3395,7 +3395,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
40617
40618 void tty_default_fops(struct file_operations *fops)
40619 {
40620- *fops = tty_fops;
40621+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
40622 }
40623
40624 /*
40625diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
40626index 0f2a2c5..471e228 100644
40627--- a/drivers/tty/tty_ldisc.c
40628+++ b/drivers/tty/tty_ldisc.c
40629@@ -56,7 +56,7 @@ static void put_ldisc(struct tty_ldisc *ld)
40630 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
40631 struct tty_ldisc_ops *ldo = ld->ops;
40632
40633- ldo->refcount--;
40634+ atomic_dec(&ldo->refcount);
40635 module_put(ldo->owner);
40636 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
40637
40638@@ -91,7 +91,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
40639 spin_lock_irqsave(&tty_ldisc_lock, flags);
40640 tty_ldiscs[disc] = new_ldisc;
40641 new_ldisc->num = disc;
40642- new_ldisc->refcount = 0;
40643+ atomic_set(&new_ldisc->refcount, 0);
40644 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
40645
40646 return ret;
40647@@ -119,7 +119,7 @@ int tty_unregister_ldisc(int disc)
40648 return -EINVAL;
40649
40650 spin_lock_irqsave(&tty_ldisc_lock, flags);
40651- if (tty_ldiscs[disc]->refcount)
40652+ if (atomic_read(&tty_ldiscs[disc]->refcount))
40653 ret = -EBUSY;
40654 else
40655 tty_ldiscs[disc] = NULL;
40656@@ -140,7 +140,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
40657 if (ldops) {
40658 ret = ERR_PTR(-EAGAIN);
40659 if (try_module_get(ldops->owner)) {
40660- ldops->refcount++;
40661+ atomic_inc(&ldops->refcount);
40662 ret = ldops;
40663 }
40664 }
40665@@ -153,7 +153,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
40666 unsigned long flags;
40667
40668 spin_lock_irqsave(&tty_ldisc_lock, flags);
40669- ldops->refcount--;
40670+ atomic_dec(&ldops->refcount);
40671 module_put(ldops->owner);
40672 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
40673 }
40674diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
40675index d7bdd8d..feaef30 100644
40676--- a/drivers/tty/tty_port.c
40677+++ b/drivers/tty/tty_port.c
40678@@ -202,7 +202,7 @@ void tty_port_hangup(struct tty_port *port)
40679 unsigned long flags;
40680
40681 spin_lock_irqsave(&port->lock, flags);
40682- port->count = 0;
40683+ atomic_set(&port->count, 0);
40684 port->flags &= ~ASYNC_NORMAL_ACTIVE;
40685 if (port->tty) {
40686 set_bit(TTY_IO_ERROR, &port->tty->flags);
40687@@ -328,7 +328,7 @@ int tty_port_block_til_ready(struct tty_port *port,
40688 /* The port lock protects the port counts */
40689 spin_lock_irqsave(&port->lock, flags);
40690 if (!tty_hung_up_p(filp))
40691- port->count--;
40692+ atomic_dec(&port->count);
40693 port->blocked_open++;
40694 spin_unlock_irqrestore(&port->lock, flags);
40695
40696@@ -370,7 +370,7 @@ int tty_port_block_til_ready(struct tty_port *port,
40697 we must not mess that up further */
40698 spin_lock_irqsave(&port->lock, flags);
40699 if (!tty_hung_up_p(filp))
40700- port->count++;
40701+ atomic_inc(&port->count);
40702 port->blocked_open--;
40703 if (retval == 0)
40704 port->flags |= ASYNC_NORMAL_ACTIVE;
40705@@ -390,19 +390,19 @@ int tty_port_close_start(struct tty_port *port,
40706 return 0;
40707 }
40708
40709- if (tty->count == 1 && port->count != 1) {
40710+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
40711 printk(KERN_WARNING
40712 "tty_port_close_start: tty->count = 1 port count = %d.\n",
40713- port->count);
40714- port->count = 1;
40715+ atomic_read(&port->count));
40716+ atomic_set(&port->count, 1);
40717 }
40718- if (--port->count < 0) {
40719+ if (atomic_dec_return(&port->count) < 0) {
40720 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
40721- port->count);
40722- port->count = 0;
40723+ atomic_read(&port->count));
40724+ atomic_set(&port->count, 0);
40725 }
40726
40727- if (port->count) {
40728+ if (atomic_read(&port->count)) {
40729 spin_unlock_irqrestore(&port->lock, flags);
40730 if (port->ops->drop)
40731 port->ops->drop(port);
40732@@ -500,7 +500,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
40733 {
40734 spin_lock_irq(&port->lock);
40735 if (!tty_hung_up_p(filp))
40736- ++port->count;
40737+ atomic_inc(&port->count);
40738 spin_unlock_irq(&port->lock);
40739 tty_port_tty_set(port, tty);
40740
40741diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
40742index 681765b..d3ccdf2 100644
40743--- a/drivers/tty/vt/keyboard.c
40744+++ b/drivers/tty/vt/keyboard.c
40745@@ -660,6 +660,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
40746 kbd->kbdmode == VC_OFF) &&
40747 value != KVAL(K_SAK))
40748 return; /* SAK is allowed even in raw mode */
40749+
40750+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
40751+ {
40752+ void *func = fn_handler[value];
40753+ if (func == fn_show_state || func == fn_show_ptregs ||
40754+ func == fn_show_mem)
40755+ return;
40756+ }
40757+#endif
40758+
40759 fn_handler[value](vc);
40760 }
40761
40762@@ -1808,9 +1818,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
40763 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
40764 return -EFAULT;
40765
40766- if (!capable(CAP_SYS_TTY_CONFIG))
40767- perm = 0;
40768-
40769 switch (cmd) {
40770 case KDGKBENT:
40771 /* Ensure another thread doesn't free it under us */
40772@@ -1825,6 +1832,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
40773 spin_unlock_irqrestore(&kbd_event_lock, flags);
40774 return put_user(val, &user_kbe->kb_value);
40775 case KDSKBENT:
40776+ if (!capable(CAP_SYS_TTY_CONFIG))
40777+ perm = 0;
40778+
40779 if (!perm)
40780 return -EPERM;
40781 if (!i && v == K_NOSUCHMAP) {
40782@@ -1915,9 +1925,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
40783 int i, j, k;
40784 int ret;
40785
40786- if (!capable(CAP_SYS_TTY_CONFIG))
40787- perm = 0;
40788-
40789 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
40790 if (!kbs) {
40791 ret = -ENOMEM;
40792@@ -1951,6 +1958,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
40793 kfree(kbs);
40794 return ((p && *p) ? -EOVERFLOW : 0);
40795 case KDSKBSENT:
40796+ if (!capable(CAP_SYS_TTY_CONFIG))
40797+ perm = 0;
40798+
40799 if (!perm) {
40800 ret = -EPERM;
40801 goto reterr;
40802diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
40803index 5110f36..8dc0a74 100644
40804--- a/drivers/uio/uio.c
40805+++ b/drivers/uio/uio.c
40806@@ -25,6 +25,7 @@
40807 #include <linux/kobject.h>
40808 #include <linux/cdev.h>
40809 #include <linux/uio_driver.h>
40810+#include <asm/local.h>
40811
40812 #define UIO_MAX_DEVICES (1U << MINORBITS)
40813
40814@@ -32,10 +33,10 @@ struct uio_device {
40815 struct module *owner;
40816 struct device *dev;
40817 int minor;
40818- atomic_t event;
40819+ atomic_unchecked_t event;
40820 struct fasync_struct *async_queue;
40821 wait_queue_head_t wait;
40822- int vma_count;
40823+ local_t vma_count;
40824 struct uio_info *info;
40825 struct kobject *map_dir;
40826 struct kobject *portio_dir;
40827@@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
40828 struct device_attribute *attr, char *buf)
40829 {
40830 struct uio_device *idev = dev_get_drvdata(dev);
40831- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
40832+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
40833 }
40834
40835 static struct device_attribute uio_class_attributes[] = {
40836@@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
40837 {
40838 struct uio_device *idev = info->uio_dev;
40839
40840- atomic_inc(&idev->event);
40841+ atomic_inc_unchecked(&idev->event);
40842 wake_up_interruptible(&idev->wait);
40843 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
40844 }
40845@@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
40846 }
40847
40848 listener->dev = idev;
40849- listener->event_count = atomic_read(&idev->event);
40850+ listener->event_count = atomic_read_unchecked(&idev->event);
40851 filep->private_data = listener;
40852
40853 if (idev->info->open) {
40854@@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
40855 return -EIO;
40856
40857 poll_wait(filep, &idev->wait, wait);
40858- if (listener->event_count != atomic_read(&idev->event))
40859+ if (listener->event_count != atomic_read_unchecked(&idev->event))
40860 return POLLIN | POLLRDNORM;
40861 return 0;
40862 }
40863@@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
40864 do {
40865 set_current_state(TASK_INTERRUPTIBLE);
40866
40867- event_count = atomic_read(&idev->event);
40868+ event_count = atomic_read_unchecked(&idev->event);
40869 if (event_count != listener->event_count) {
40870 if (copy_to_user(buf, &event_count, count))
40871 retval = -EFAULT;
40872@@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
40873 static void uio_vma_open(struct vm_area_struct *vma)
40874 {
40875 struct uio_device *idev = vma->vm_private_data;
40876- idev->vma_count++;
40877+ local_inc(&idev->vma_count);
40878 }
40879
40880 static void uio_vma_close(struct vm_area_struct *vma)
40881 {
40882 struct uio_device *idev = vma->vm_private_data;
40883- idev->vma_count--;
40884+ local_dec(&idev->vma_count);
40885 }
40886
40887 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
40888@@ -819,7 +820,7 @@ int __uio_register_device(struct module *owner,
40889 idev->owner = owner;
40890 idev->info = info;
40891 init_waitqueue_head(&idev->wait);
40892- atomic_set(&idev->event, 0);
40893+ atomic_set_unchecked(&idev->event, 0);
40894
40895 ret = uio_get_minor(idev);
40896 if (ret)
40897diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
40898index b7eb86a..36d28af 100644
40899--- a/drivers/usb/atm/cxacru.c
40900+++ b/drivers/usb/atm/cxacru.c
40901@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
40902 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
40903 if (ret < 2)
40904 return -EINVAL;
40905- if (index < 0 || index > 0x7f)
40906+ if (index > 0x7f)
40907 return -EINVAL;
40908 pos += tmp;
40909
40910diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
40911index 35f10bf..6a38a0b 100644
40912--- a/drivers/usb/atm/usbatm.c
40913+++ b/drivers/usb/atm/usbatm.c
40914@@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
40915 if (printk_ratelimit())
40916 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
40917 __func__, vpi, vci);
40918- atomic_inc(&vcc->stats->rx_err);
40919+ atomic_inc_unchecked(&vcc->stats->rx_err);
40920 return;
40921 }
40922
40923@@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
40924 if (length > ATM_MAX_AAL5_PDU) {
40925 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
40926 __func__, length, vcc);
40927- atomic_inc(&vcc->stats->rx_err);
40928+ atomic_inc_unchecked(&vcc->stats->rx_err);
40929 goto out;
40930 }
40931
40932@@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
40933 if (sarb->len < pdu_length) {
40934 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
40935 __func__, pdu_length, sarb->len, vcc);
40936- atomic_inc(&vcc->stats->rx_err);
40937+ atomic_inc_unchecked(&vcc->stats->rx_err);
40938 goto out;
40939 }
40940
40941 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
40942 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
40943 __func__, vcc);
40944- atomic_inc(&vcc->stats->rx_err);
40945+ atomic_inc_unchecked(&vcc->stats->rx_err);
40946 goto out;
40947 }
40948
40949@@ -389,7 +389,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
40950 if (printk_ratelimit())
40951 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
40952 __func__, length);
40953- atomic_inc(&vcc->stats->rx_drop);
40954+ atomic_inc_unchecked(&vcc->stats->rx_drop);
40955 goto out;
40956 }
40957
40958@@ -417,7 +417,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
40959
40960 vcc->push(vcc, skb);
40961
40962- atomic_inc(&vcc->stats->rx);
40963+ atomic_inc_unchecked(&vcc->stats->rx);
40964 out:
40965 skb_trim(sarb, 0);
40966 }
40967@@ -623,7 +623,7 @@ static void usbatm_tx_process(unsigned long data)
40968 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
40969
40970 usbatm_pop(vcc, skb);
40971- atomic_inc(&vcc->stats->tx);
40972+ atomic_inc_unchecked(&vcc->stats->tx);
40973
40974 skb = skb_dequeue(&instance->sndqueue);
40975 }
40976@@ -779,11 +779,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
40977 if (!left--)
40978 return sprintf(page,
40979 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
40980- atomic_read(&atm_dev->stats.aal5.tx),
40981- atomic_read(&atm_dev->stats.aal5.tx_err),
40982- atomic_read(&atm_dev->stats.aal5.rx),
40983- atomic_read(&atm_dev->stats.aal5.rx_err),
40984- atomic_read(&atm_dev->stats.aal5.rx_drop));
40985+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
40986+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
40987+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
40988+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
40989+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
40990
40991 if (!left--) {
40992 if (instance->disconnected)
40993diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
40994index f460de3..95ba1f6 100644
40995--- a/drivers/usb/core/devices.c
40996+++ b/drivers/usb/core/devices.c
40997@@ -126,7 +126,7 @@ static const char format_endpt[] =
40998 * time it gets called.
40999 */
41000 static struct device_connect_event {
41001- atomic_t count;
41002+ atomic_unchecked_t count;
41003 wait_queue_head_t wait;
41004 } device_event = {
41005 .count = ATOMIC_INIT(1),
41006@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
41007
41008 void usbfs_conn_disc_event(void)
41009 {
41010- atomic_add(2, &device_event.count);
41011+ atomic_add_unchecked(2, &device_event.count);
41012 wake_up(&device_event.wait);
41013 }
41014
41015@@ -647,7 +647,7 @@ static unsigned int usb_device_poll(struct file *file,
41016
41017 poll_wait(file, &device_event.wait, wait);
41018
41019- event_count = atomic_read(&device_event.count);
41020+ event_count = atomic_read_unchecked(&device_event.count);
41021 if (file->f_version != event_count) {
41022 file->f_version = event_count;
41023 return POLLIN | POLLRDNORM;
41024diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
41025index f034716..aed0368 100644
41026--- a/drivers/usb/core/hcd.c
41027+++ b/drivers/usb/core/hcd.c
41028@@ -1478,7 +1478,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
41029 */
41030 usb_get_urb(urb);
41031 atomic_inc(&urb->use_count);
41032- atomic_inc(&urb->dev->urbnum);
41033+ atomic_inc_unchecked(&urb->dev->urbnum);
41034 usbmon_urb_submit(&hcd->self, urb);
41035
41036 /* NOTE requirements on root-hub callers (usbfs and the hub
41037@@ -1505,7 +1505,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
41038 urb->hcpriv = NULL;
41039 INIT_LIST_HEAD(&urb->urb_list);
41040 atomic_dec(&urb->use_count);
41041- atomic_dec(&urb->dev->urbnum);
41042+ atomic_dec_unchecked(&urb->dev->urbnum);
41043 if (atomic_read(&urb->reject))
41044 wake_up(&usb_kill_urb_queue);
41045 usb_put_urb(urb);
41046diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
41047index 818e4a0..0fc9589 100644
41048--- a/drivers/usb/core/sysfs.c
41049+++ b/drivers/usb/core/sysfs.c
41050@@ -226,7 +226,7 @@ show_urbnum(struct device *dev, struct device_attribute *attr, char *buf)
41051 struct usb_device *udev;
41052
41053 udev = to_usb_device(dev);
41054- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
41055+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
41056 }
41057 static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL);
41058
41059diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
41060index cd8fb44..17fbe0c 100644
41061--- a/drivers/usb/core/usb.c
41062+++ b/drivers/usb/core/usb.c
41063@@ -397,7 +397,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
41064 set_dev_node(&dev->dev, dev_to_node(bus->controller));
41065 dev->state = USB_STATE_ATTACHED;
41066 dev->lpm_disable_count = 1;
41067- atomic_set(&dev->urbnum, 0);
41068+ atomic_set_unchecked(&dev->urbnum, 0);
41069
41070 INIT_LIST_HEAD(&dev->ep0.urb_list);
41071 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
41072diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
41073index 4bfa78a..902bfbd 100644
41074--- a/drivers/usb/early/ehci-dbgp.c
41075+++ b/drivers/usb/early/ehci-dbgp.c
41076@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
41077
41078 #ifdef CONFIG_KGDB
41079 static struct kgdb_io kgdbdbgp_io_ops;
41080-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
41081+static struct kgdb_io kgdbdbgp_io_ops_console;
41082+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
41083 #else
41084 #define dbgp_kgdb_mode (0)
41085 #endif
41086@@ -1047,6 +1048,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
41087 .write_char = kgdbdbgp_write_char,
41088 };
41089
41090+static struct kgdb_io kgdbdbgp_io_ops_console = {
41091+ .name = "kgdbdbgp",
41092+ .read_char = kgdbdbgp_read_char,
41093+ .write_char = kgdbdbgp_write_char,
41094+ .is_console = 1
41095+};
41096+
41097 static int kgdbdbgp_wait_time;
41098
41099 static int __init kgdbdbgp_parse_config(char *str)
41100@@ -1062,8 +1070,10 @@ static int __init kgdbdbgp_parse_config(char *str)
41101 ptr++;
41102 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
41103 }
41104- kgdb_register_io_module(&kgdbdbgp_io_ops);
41105- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
41106+ if (early_dbgp_console.index != -1)
41107+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
41108+ else
41109+ kgdb_register_io_module(&kgdbdbgp_io_ops);
41110
41111 return 0;
41112 }
41113diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
41114index f173952..83d6ec0 100644
41115--- a/drivers/usb/gadget/u_serial.c
41116+++ b/drivers/usb/gadget/u_serial.c
41117@@ -735,9 +735,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
41118 spin_lock_irq(&port->port_lock);
41119
41120 /* already open? Great. */
41121- if (port->port.count) {
41122+ if (atomic_read(&port->port.count)) {
41123 status = 0;
41124- port->port.count++;
41125+ atomic_inc(&port->port.count);
41126
41127 /* currently opening/closing? wait ... */
41128 } else if (port->openclose) {
41129@@ -796,7 +796,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
41130 tty->driver_data = port;
41131 port->port.tty = tty;
41132
41133- port->port.count = 1;
41134+ atomic_set(&port->port.count, 1);
41135 port->openclose = false;
41136
41137 /* if connected, start the I/O stream */
41138@@ -838,11 +838,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
41139
41140 spin_lock_irq(&port->port_lock);
41141
41142- if (port->port.count != 1) {
41143- if (port->port.count == 0)
41144+ if (atomic_read(&port->port.count) != 1) {
41145+ if (atomic_read(&port->port.count) == 0)
41146 WARN_ON(1);
41147 else
41148- --port->port.count;
41149+ atomic_dec(&port->port.count);
41150 goto exit;
41151 }
41152
41153@@ -852,7 +852,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
41154 * and sleep if necessary
41155 */
41156 port->openclose = true;
41157- port->port.count = 0;
41158+ atomic_set(&port->port.count, 0);
41159
41160 gser = port->port_usb;
41161 if (gser && gser->disconnect)
41162@@ -1157,7 +1157,7 @@ static int gs_closed(struct gs_port *port)
41163 int cond;
41164
41165 spin_lock_irq(&port->port_lock);
41166- cond = (port->port.count == 0) && !port->openclose;
41167+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
41168 spin_unlock_irq(&port->port_lock);
41169 return cond;
41170 }
41171@@ -1270,7 +1270,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
41172 /* if it's already open, start I/O ... and notify the serial
41173 * protocol about open/close status (connect/disconnect).
41174 */
41175- if (port->port.count) {
41176+ if (atomic_read(&port->port.count)) {
41177 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
41178 gs_start_io(port);
41179 if (gser->connect)
41180@@ -1317,7 +1317,7 @@ void gserial_disconnect(struct gserial *gser)
41181
41182 port->port_usb = NULL;
41183 gser->ioport = NULL;
41184- if (port->port.count > 0 || port->openclose) {
41185+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
41186 wake_up_interruptible(&port->drain_wait);
41187 if (port->port.tty)
41188 tty_hangup(port->port.tty);
41189@@ -1333,7 +1333,7 @@ void gserial_disconnect(struct gserial *gser)
41190
41191 /* finally, free any unused/unusable I/O buffers */
41192 spin_lock_irqsave(&port->port_lock, flags);
41193- if (port->port.count == 0 && !port->openclose)
41194+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
41195 gs_buf_free(&port->port_write_buf);
41196 gs_free_requests(gser->out, &port->read_pool, NULL);
41197 gs_free_requests(gser->out, &port->read_queue, NULL);
41198diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
41199index 5f3bcd3..bfca43f 100644
41200--- a/drivers/usb/serial/console.c
41201+++ b/drivers/usb/serial/console.c
41202@@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
41203
41204 info->port = port;
41205
41206- ++port->port.count;
41207+ atomic_inc(&port->port.count);
41208 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
41209 if (serial->type->set_termios) {
41210 /*
41211@@ -174,7 +174,7 @@ static int usb_console_setup(struct console *co, char *options)
41212 }
41213 /* Now that any required fake tty operations are completed restore
41214 * the tty port count */
41215- --port->port.count;
41216+ atomic_dec(&port->port.count);
41217 /* The console is special in terms of closing the device so
41218 * indicate this port is now acting as a system console. */
41219 port->port.console = 1;
41220@@ -187,7 +187,7 @@ static int usb_console_setup(struct console *co, char *options)
41221 free_tty:
41222 kfree(tty);
41223 reset_open_count:
41224- port->port.count = 0;
41225+ atomic_set(&port->port.count, 0);
41226 usb_autopm_put_interface(serial->interface);
41227 error_get_interface:
41228 usb_serial_put(serial);
41229diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
41230index d6bea3e..60b250e 100644
41231--- a/drivers/usb/wusbcore/wa-hc.h
41232+++ b/drivers/usb/wusbcore/wa-hc.h
41233@@ -192,7 +192,7 @@ struct wahc {
41234 struct list_head xfer_delayed_list;
41235 spinlock_t xfer_list_lock;
41236 struct work_struct xfer_work;
41237- atomic_t xfer_id_count;
41238+ atomic_unchecked_t xfer_id_count;
41239 };
41240
41241
41242@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
41243 INIT_LIST_HEAD(&wa->xfer_delayed_list);
41244 spin_lock_init(&wa->xfer_list_lock);
41245 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
41246- atomic_set(&wa->xfer_id_count, 1);
41247+ atomic_set_unchecked(&wa->xfer_id_count, 1);
41248 }
41249
41250 /**
41251diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
41252index 57c01ab..8a05959 100644
41253--- a/drivers/usb/wusbcore/wa-xfer.c
41254+++ b/drivers/usb/wusbcore/wa-xfer.c
41255@@ -296,7 +296,7 @@ out:
41256 */
41257 static void wa_xfer_id_init(struct wa_xfer *xfer)
41258 {
41259- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
41260+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
41261 }
41262
41263 /*
41264diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
41265index dedaf81..b0f11ab 100644
41266--- a/drivers/vhost/vhost.c
41267+++ b/drivers/vhost/vhost.c
41268@@ -634,7 +634,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
41269 return 0;
41270 }
41271
41272-static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
41273+static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
41274 {
41275 struct file *eventfp, *filep = NULL;
41276 bool pollstart = false, pollstop = false;
41277diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
41278index 0fefa84..7a9d581 100644
41279--- a/drivers/video/aty/aty128fb.c
41280+++ b/drivers/video/aty/aty128fb.c
41281@@ -149,7 +149,7 @@ enum {
41282 };
41283
41284 /* Must match above enum */
41285-static char * const r128_family[] __devinitconst = {
41286+static const char * const r128_family[] __devinitconst = {
41287 "AGP",
41288 "PCI",
41289 "PRO AGP",
41290diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
41291index 5c3960d..15cf8fc 100644
41292--- a/drivers/video/fbcmap.c
41293+++ b/drivers/video/fbcmap.c
41294@@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
41295 rc = -ENODEV;
41296 goto out;
41297 }
41298- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
41299- !info->fbops->fb_setcmap)) {
41300+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
41301 rc = -EINVAL;
41302 goto out1;
41303 }
41304diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
41305index 3ff0105..7589d98 100644
41306--- a/drivers/video/fbmem.c
41307+++ b/drivers/video/fbmem.c
41308@@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
41309 image->dx += image->width + 8;
41310 }
41311 } else if (rotate == FB_ROTATE_UD) {
41312- for (x = 0; x < num && image->dx >= 0; x++) {
41313+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
41314 info->fbops->fb_imageblit(info, image);
41315 image->dx -= image->width + 8;
41316 }
41317@@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
41318 image->dy += image->height + 8;
41319 }
41320 } else if (rotate == FB_ROTATE_CCW) {
41321- for (x = 0; x < num && image->dy >= 0; x++) {
41322+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
41323 info->fbops->fb_imageblit(info, image);
41324 image->dy -= image->height + 8;
41325 }
41326@@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
41327 return -EFAULT;
41328 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
41329 return -EINVAL;
41330- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
41331+ if (con2fb.framebuffer >= FB_MAX)
41332 return -EINVAL;
41333 if (!registered_fb[con2fb.framebuffer])
41334 request_module("fb%d", con2fb.framebuffer);
41335diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
41336index 7672d2e..b56437f 100644
41337--- a/drivers/video/i810/i810_accel.c
41338+++ b/drivers/video/i810/i810_accel.c
41339@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
41340 }
41341 }
41342 printk("ringbuffer lockup!!!\n");
41343+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
41344 i810_report_error(mmio);
41345 par->dev_flags |= LOCKUP;
41346 info->pixmap.scan_align = 1;
41347diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
41348index 3c14e43..eafa544 100644
41349--- a/drivers/video/logo/logo_linux_clut224.ppm
41350+++ b/drivers/video/logo/logo_linux_clut224.ppm
41351@@ -1,1604 +1,1123 @@
41352 P3
41353-# Standard 224-color Linux logo
41354 80 80
41355 255
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 0 0 0 0 0 0 0 0 0 0
41361- 0 0 0 0 0 0 0 0 0 0 0 0
41362- 0 0 0 0 0 0 0 0 0 0 0 0
41363- 0 0 0 0 0 0 0 0 0 0 0 0
41364- 0 0 0 0 0 0 0 0 0 0 0 0
41365- 6 6 6 6 6 6 10 10 10 10 10 10
41366- 10 10 10 6 6 6 6 6 6 6 6 6
41367- 0 0 0 0 0 0 0 0 0 0 0 0
41368- 0 0 0 0 0 0 0 0 0 0 0 0
41369- 0 0 0 0 0 0 0 0 0 0 0 0
41370- 0 0 0 0 0 0 0 0 0 0 0 0
41371- 0 0 0 0 0 0 0 0 0 0 0 0
41372- 0 0 0 0 0 0 0 0 0 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 6 6 6 10 10 10 14 14 14
41385- 22 22 22 26 26 26 30 30 30 34 34 34
41386- 30 30 30 30 30 30 26 26 26 18 18 18
41387- 14 14 14 10 10 10 6 6 6 0 0 0
41388- 0 0 0 0 0 0 0 0 0 0 0 0
41389- 0 0 0 0 0 0 0 0 0 0 0 0
41390- 0 0 0 0 0 0 0 0 0 0 0 0
41391- 0 0 0 0 0 0 0 0 0 0 0 0
41392- 0 0 0 0 0 0 0 0 0 0 0 0
41393- 0 0 0 0 0 0 0 0 0 0 0 0
41394- 0 0 0 0 0 0 0 0 0 0 0 0
41395- 0 0 0 0 0 0 0 0 0 0 0 0
41396- 0 0 0 0 0 0 0 0 0 0 0 0
41397- 0 0 0 0 0 1 0 0 1 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 0 0 0 0
41400- 0 0 0 0 0 0 0 0 0 0 0 0
41401- 0 0 0 0 0 0 0 0 0 0 0 0
41402- 0 0 0 0 0 0 0 0 0 0 0 0
41403- 0 0 0 0 0 0 0 0 0 0 0 0
41404- 6 6 6 14 14 14 26 26 26 42 42 42
41405- 54 54 54 66 66 66 78 78 78 78 78 78
41406- 78 78 78 74 74 74 66 66 66 54 54 54
41407- 42 42 42 26 26 26 18 18 18 10 10 10
41408- 6 6 6 0 0 0 0 0 0 0 0 0
41409- 0 0 0 0 0 0 0 0 0 0 0 0
41410- 0 0 0 0 0 0 0 0 0 0 0 0
41411- 0 0 0 0 0 0 0 0 0 0 0 0
41412- 0 0 0 0 0 0 0 0 0 0 0 0
41413- 0 0 0 0 0 0 0 0 0 0 0 0
41414- 0 0 0 0 0 0 0 0 0 0 0 0
41415- 0 0 0 0 0 0 0 0 0 0 0 0
41416- 0 0 0 0 0 0 0 0 0 0 0 0
41417- 0 0 1 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 10 10 10
41424- 22 22 22 42 42 42 66 66 66 86 86 86
41425- 66 66 66 38 38 38 38 38 38 22 22 22
41426- 26 26 26 34 34 34 54 54 54 66 66 66
41427- 86 86 86 70 70 70 46 46 46 26 26 26
41428- 14 14 14 6 6 6 0 0 0 0 0 0
41429- 0 0 0 0 0 0 0 0 0 0 0 0
41430- 0 0 0 0 0 0 0 0 0 0 0 0
41431- 0 0 0 0 0 0 0 0 0 0 0 0
41432- 0 0 0 0 0 0 0 0 0 0 0 0
41433- 0 0 0 0 0 0 0 0 0 0 0 0
41434- 0 0 0 0 0 0 0 0 0 0 0 0
41435- 0 0 0 0 0 0 0 0 0 0 0 0
41436- 0 0 0 0 0 0 0 0 0 0 0 0
41437- 0 0 1 0 0 1 0 0 1 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 0 0 0 0
41440- 0 0 0 0 0 0 0 0 0 0 0 0
41441- 0 0 0 0 0 0 0 0 0 0 0 0
41442- 0 0 0 0 0 0 0 0 0 0 0 0
41443- 0 0 0 0 0 0 10 10 10 26 26 26
41444- 50 50 50 82 82 82 58 58 58 6 6 6
41445- 2 2 6 2 2 6 2 2 6 2 2 6
41446- 2 2 6 2 2 6 2 2 6 2 2 6
41447- 6 6 6 54 54 54 86 86 86 66 66 66
41448- 38 38 38 18 18 18 6 6 6 0 0 0
41449- 0 0 0 0 0 0 0 0 0 0 0 0
41450- 0 0 0 0 0 0 0 0 0 0 0 0
41451- 0 0 0 0 0 0 0 0 0 0 0 0
41452- 0 0 0 0 0 0 0 0 0 0 0 0
41453- 0 0 0 0 0 0 0 0 0 0 0 0
41454- 0 0 0 0 0 0 0 0 0 0 0 0
41455- 0 0 0 0 0 0 0 0 0 0 0 0
41456- 0 0 0 0 0 0 0 0 0 0 0 0
41457- 0 0 0 0 0 0 0 0 0 0 0 0
41458- 0 0 0 0 0 0 0 0 0 0 0 0
41459- 0 0 0 0 0 0 0 0 0 0 0 0
41460- 0 0 0 0 0 0 0 0 0 0 0 0
41461- 0 0 0 0 0 0 0 0 0 0 0 0
41462- 0 0 0 0 0 0 0 0 0 0 0 0
41463- 0 0 0 6 6 6 22 22 22 50 50 50
41464- 78 78 78 34 34 34 2 2 6 2 2 6
41465- 2 2 6 2 2 6 2 2 6 2 2 6
41466- 2 2 6 2 2 6 2 2 6 2 2 6
41467- 2 2 6 2 2 6 6 6 6 70 70 70
41468- 78 78 78 46 46 46 22 22 22 6 6 6
41469- 0 0 0 0 0 0 0 0 0 0 0 0
41470- 0 0 0 0 0 0 0 0 0 0 0 0
41471- 0 0 0 0 0 0 0 0 0 0 0 0
41472- 0 0 0 0 0 0 0 0 0 0 0 0
41473- 0 0 0 0 0 0 0 0 0 0 0 0
41474- 0 0 0 0 0 0 0 0 0 0 0 0
41475- 0 0 0 0 0 0 0 0 0 0 0 0
41476- 0 0 0 0 0 0 0 0 0 0 0 0
41477- 0 0 1 0 0 1 0 0 1 0 0 0
41478- 0 0 0 0 0 0 0 0 0 0 0 0
41479- 0 0 0 0 0 0 0 0 0 0 0 0
41480- 0 0 0 0 0 0 0 0 0 0 0 0
41481- 0 0 0 0 0 0 0 0 0 0 0 0
41482- 0 0 0 0 0 0 0 0 0 0 0 0
41483- 6 6 6 18 18 18 42 42 42 82 82 82
41484- 26 26 26 2 2 6 2 2 6 2 2 6
41485- 2 2 6 2 2 6 2 2 6 2 2 6
41486- 2 2 6 2 2 6 2 2 6 14 14 14
41487- 46 46 46 34 34 34 6 6 6 2 2 6
41488- 42 42 42 78 78 78 42 42 42 18 18 18
41489- 6 6 6 0 0 0 0 0 0 0 0 0
41490- 0 0 0 0 0 0 0 0 0 0 0 0
41491- 0 0 0 0 0 0 0 0 0 0 0 0
41492- 0 0 0 0 0 0 0 0 0 0 0 0
41493- 0 0 0 0 0 0 0 0 0 0 0 0
41494- 0 0 0 0 0 0 0 0 0 0 0 0
41495- 0 0 0 0 0 0 0 0 0 0 0 0
41496- 0 0 0 0 0 0 0 0 0 0 0 0
41497- 0 0 1 0 0 0 0 0 1 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- 10 10 10 30 30 30 66 66 66 58 58 58
41504- 2 2 6 2 2 6 2 2 6 2 2 6
41505- 2 2 6 2 2 6 2 2 6 2 2 6
41506- 2 2 6 2 2 6 2 2 6 26 26 26
41507- 86 86 86 101 101 101 46 46 46 10 10 10
41508- 2 2 6 58 58 58 70 70 70 34 34 34
41509- 10 10 10 0 0 0 0 0 0 0 0 0
41510- 0 0 0 0 0 0 0 0 0 0 0 0
41511- 0 0 0 0 0 0 0 0 0 0 0 0
41512- 0 0 0 0 0 0 0 0 0 0 0 0
41513- 0 0 0 0 0 0 0 0 0 0 0 0
41514- 0 0 0 0 0 0 0 0 0 0 0 0
41515- 0 0 0 0 0 0 0 0 0 0 0 0
41516- 0 0 0 0 0 0 0 0 0 0 0 0
41517- 0 0 1 0 0 1 0 0 1 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- 14 14 14 42 42 42 86 86 86 10 10 10
41524- 2 2 6 2 2 6 2 2 6 2 2 6
41525- 2 2 6 2 2 6 2 2 6 2 2 6
41526- 2 2 6 2 2 6 2 2 6 30 30 30
41527- 94 94 94 94 94 94 58 58 58 26 26 26
41528- 2 2 6 6 6 6 78 78 78 54 54 54
41529- 22 22 22 6 6 6 0 0 0 0 0 0
41530- 0 0 0 0 0 0 0 0 0 0 0 0
41531- 0 0 0 0 0 0 0 0 0 0 0 0
41532- 0 0 0 0 0 0 0 0 0 0 0 0
41533- 0 0 0 0 0 0 0 0 0 0 0 0
41534- 0 0 0 0 0 0 0 0 0 0 0 0
41535- 0 0 0 0 0 0 0 0 0 0 0 0
41536- 0 0 0 0 0 0 0 0 0 0 0 0
41537- 0 0 0 0 0 0 0 0 0 0 0 0
41538- 0 0 0 0 0 0 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 6 6 6
41543- 22 22 22 62 62 62 62 62 62 2 2 6
41544- 2 2 6 2 2 6 2 2 6 2 2 6
41545- 2 2 6 2 2 6 2 2 6 2 2 6
41546- 2 2 6 2 2 6 2 2 6 26 26 26
41547- 54 54 54 38 38 38 18 18 18 10 10 10
41548- 2 2 6 2 2 6 34 34 34 82 82 82
41549- 38 38 38 14 14 14 0 0 0 0 0 0
41550- 0 0 0 0 0 0 0 0 0 0 0 0
41551- 0 0 0 0 0 0 0 0 0 0 0 0
41552- 0 0 0 0 0 0 0 0 0 0 0 0
41553- 0 0 0 0 0 0 0 0 0 0 0 0
41554- 0 0 0 0 0 0 0 0 0 0 0 0
41555- 0 0 0 0 0 0 0 0 0 0 0 0
41556- 0 0 0 0 0 0 0 0 0 0 0 0
41557- 0 0 0 0 0 1 0 0 1 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 6 6 6
41563- 30 30 30 78 78 78 30 30 30 2 2 6
41564- 2 2 6 2 2 6 2 2 6 2 2 6
41565- 2 2 6 2 2 6 2 2 6 2 2 6
41566- 2 2 6 2 2 6 2 2 6 10 10 10
41567- 10 10 10 2 2 6 2 2 6 2 2 6
41568- 2 2 6 2 2 6 2 2 6 78 78 78
41569- 50 50 50 18 18 18 6 6 6 0 0 0
41570- 0 0 0 0 0 0 0 0 0 0 0 0
41571- 0 0 0 0 0 0 0 0 0 0 0 0
41572- 0 0 0 0 0 0 0 0 0 0 0 0
41573- 0 0 0 0 0 0 0 0 0 0 0 0
41574- 0 0 0 0 0 0 0 0 0 0 0 0
41575- 0 0 0 0 0 0 0 0 0 0 0 0
41576- 0 0 0 0 0 0 0 0 0 0 0 0
41577- 0 0 1 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 10 10 10
41583- 38 38 38 86 86 86 14 14 14 2 2 6
41584- 2 2 6 2 2 6 2 2 6 2 2 6
41585- 2 2 6 2 2 6 2 2 6 2 2 6
41586- 2 2 6 2 2 6 2 2 6 2 2 6
41587- 2 2 6 2 2 6 2 2 6 2 2 6
41588- 2 2 6 2 2 6 2 2 6 54 54 54
41589- 66 66 66 26 26 26 6 6 6 0 0 0
41590- 0 0 0 0 0 0 0 0 0 0 0 0
41591- 0 0 0 0 0 0 0 0 0 0 0 0
41592- 0 0 0 0 0 0 0 0 0 0 0 0
41593- 0 0 0 0 0 0 0 0 0 0 0 0
41594- 0 0 0 0 0 0 0 0 0 0 0 0
41595- 0 0 0 0 0 0 0 0 0 0 0 0
41596- 0 0 0 0 0 0 0 0 0 0 0 0
41597- 0 0 0 0 0 1 0 0 1 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 14 14 14
41603- 42 42 42 82 82 82 2 2 6 2 2 6
41604- 2 2 6 6 6 6 10 10 10 2 2 6
41605- 2 2 6 2 2 6 2 2 6 2 2 6
41606- 2 2 6 2 2 6 2 2 6 6 6 6
41607- 14 14 14 10 10 10 2 2 6 2 2 6
41608- 2 2 6 2 2 6 2 2 6 18 18 18
41609- 82 82 82 34 34 34 10 10 10 0 0 0
41610- 0 0 0 0 0 0 0 0 0 0 0 0
41611- 0 0 0 0 0 0 0 0 0 0 0 0
41612- 0 0 0 0 0 0 0 0 0 0 0 0
41613- 0 0 0 0 0 0 0 0 0 0 0 0
41614- 0 0 0 0 0 0 0 0 0 0 0 0
41615- 0 0 0 0 0 0 0 0 0 0 0 0
41616- 0 0 0 0 0 0 0 0 0 0 0 0
41617- 0 0 1 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 14 14 14
41623- 46 46 46 86 86 86 2 2 6 2 2 6
41624- 6 6 6 6 6 6 22 22 22 34 34 34
41625- 6 6 6 2 2 6 2 2 6 2 2 6
41626- 2 2 6 2 2 6 18 18 18 34 34 34
41627- 10 10 10 50 50 50 22 22 22 2 2 6
41628- 2 2 6 2 2 6 2 2 6 10 10 10
41629- 86 86 86 42 42 42 14 14 14 0 0 0
41630- 0 0 0 0 0 0 0 0 0 0 0 0
41631- 0 0 0 0 0 0 0 0 0 0 0 0
41632- 0 0 0 0 0 0 0 0 0 0 0 0
41633- 0 0 0 0 0 0 0 0 0 0 0 0
41634- 0 0 0 0 0 0 0 0 0 0 0 0
41635- 0 0 0 0 0 0 0 0 0 0 0 0
41636- 0 0 0 0 0 0 0 0 0 0 0 0
41637- 0 0 1 0 0 1 0 0 1 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 14 14 14
41643- 46 46 46 86 86 86 2 2 6 2 2 6
41644- 38 38 38 116 116 116 94 94 94 22 22 22
41645- 22 22 22 2 2 6 2 2 6 2 2 6
41646- 14 14 14 86 86 86 138 138 138 162 162 162
41647-154 154 154 38 38 38 26 26 26 6 6 6
41648- 2 2 6 2 2 6 2 2 6 2 2 6
41649- 86 86 86 46 46 46 14 14 14 0 0 0
41650- 0 0 0 0 0 0 0 0 0 0 0 0
41651- 0 0 0 0 0 0 0 0 0 0 0 0
41652- 0 0 0 0 0 0 0 0 0 0 0 0
41653- 0 0 0 0 0 0 0 0 0 0 0 0
41654- 0 0 0 0 0 0 0 0 0 0 0 0
41655- 0 0 0 0 0 0 0 0 0 0 0 0
41656- 0 0 0 0 0 0 0 0 0 0 0 0
41657- 0 0 0 0 0 0 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 14 14 14
41663- 46 46 46 86 86 86 2 2 6 14 14 14
41664-134 134 134 198 198 198 195 195 195 116 116 116
41665- 10 10 10 2 2 6 2 2 6 6 6 6
41666-101 98 89 187 187 187 210 210 210 218 218 218
41667-214 214 214 134 134 134 14 14 14 6 6 6
41668- 2 2 6 2 2 6 2 2 6 2 2 6
41669- 86 86 86 50 50 50 18 18 18 6 6 6
41670- 0 0 0 0 0 0 0 0 0 0 0 0
41671- 0 0 0 0 0 0 0 0 0 0 0 0
41672- 0 0 0 0 0 0 0 0 0 0 0 0
41673- 0 0 0 0 0 0 0 0 0 0 0 0
41674- 0 0 0 0 0 0 0 0 0 0 0 0
41675- 0 0 0 0 0 0 0 0 0 0 0 0
41676- 0 0 0 0 0 0 0 0 1 0 0 0
41677- 0 0 1 0 0 1 0 0 1 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 14 14 14
41683- 46 46 46 86 86 86 2 2 6 54 54 54
41684-218 218 218 195 195 195 226 226 226 246 246 246
41685- 58 58 58 2 2 6 2 2 6 30 30 30
41686-210 210 210 253 253 253 174 174 174 123 123 123
41687-221 221 221 234 234 234 74 74 74 2 2 6
41688- 2 2 6 2 2 6 2 2 6 2 2 6
41689- 70 70 70 58 58 58 22 22 22 6 6 6
41690- 0 0 0 0 0 0 0 0 0 0 0 0
41691- 0 0 0 0 0 0 0 0 0 0 0 0
41692- 0 0 0 0 0 0 0 0 0 0 0 0
41693- 0 0 0 0 0 0 0 0 0 0 0 0
41694- 0 0 0 0 0 0 0 0 0 0 0 0
41695- 0 0 0 0 0 0 0 0 0 0 0 0
41696- 0 0 0 0 0 0 0 0 0 0 0 0
41697- 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 14 14 14
41703- 46 46 46 82 82 82 2 2 6 106 106 106
41704-170 170 170 26 26 26 86 86 86 226 226 226
41705-123 123 123 10 10 10 14 14 14 46 46 46
41706-231 231 231 190 190 190 6 6 6 70 70 70
41707- 90 90 90 238 238 238 158 158 158 2 2 6
41708- 2 2 6 2 2 6 2 2 6 2 2 6
41709- 70 70 70 58 58 58 22 22 22 6 6 6
41710- 0 0 0 0 0 0 0 0 0 0 0 0
41711- 0 0 0 0 0 0 0 0 0 0 0 0
41712- 0 0 0 0 0 0 0 0 0 0 0 0
41713- 0 0 0 0 0 0 0 0 0 0 0 0
41714- 0 0 0 0 0 0 0 0 0 0 0 0
41715- 0 0 0 0 0 0 0 0 0 0 0 0
41716- 0 0 0 0 0 0 0 0 1 0 0 0
41717- 0 0 1 0 0 1 0 0 1 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 14 14 14
41723- 42 42 42 86 86 86 6 6 6 116 116 116
41724-106 106 106 6 6 6 70 70 70 149 149 149
41725-128 128 128 18 18 18 38 38 38 54 54 54
41726-221 221 221 106 106 106 2 2 6 14 14 14
41727- 46 46 46 190 190 190 198 198 198 2 2 6
41728- 2 2 6 2 2 6 2 2 6 2 2 6
41729- 74 74 74 62 62 62 22 22 22 6 6 6
41730- 0 0 0 0 0 0 0 0 0 0 0 0
41731- 0 0 0 0 0 0 0 0 0 0 0 0
41732- 0 0 0 0 0 0 0 0 0 0 0 0
41733- 0 0 0 0 0 0 0 0 0 0 0 0
41734- 0 0 0 0 0 0 0 0 0 0 0 0
41735- 0 0 0 0 0 0 0 0 0 0 0 0
41736- 0 0 0 0 0 0 0 0 1 0 0 0
41737- 0 0 1 0 0 0 0 0 1 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 14 14 14
41743- 42 42 42 94 94 94 14 14 14 101 101 101
41744-128 128 128 2 2 6 18 18 18 116 116 116
41745-118 98 46 121 92 8 121 92 8 98 78 10
41746-162 162 162 106 106 106 2 2 6 2 2 6
41747- 2 2 6 195 195 195 195 195 195 6 6 6
41748- 2 2 6 2 2 6 2 2 6 2 2 6
41749- 74 74 74 62 62 62 22 22 22 6 6 6
41750- 0 0 0 0 0 0 0 0 0 0 0 0
41751- 0 0 0 0 0 0 0 0 0 0 0 0
41752- 0 0 0 0 0 0 0 0 0 0 0 0
41753- 0 0 0 0 0 0 0 0 0 0 0 0
41754- 0 0 0 0 0 0 0 0 0 0 0 0
41755- 0 0 0 0 0 0 0 0 0 0 0 0
41756- 0 0 0 0 0 0 0 0 1 0 0 1
41757- 0 0 1 0 0 0 0 0 1 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 10 10 10
41763- 38 38 38 90 90 90 14 14 14 58 58 58
41764-210 210 210 26 26 26 54 38 6 154 114 10
41765-226 170 11 236 186 11 225 175 15 184 144 12
41766-215 174 15 175 146 61 37 26 9 2 2 6
41767- 70 70 70 246 246 246 138 138 138 2 2 6
41768- 2 2 6 2 2 6 2 2 6 2 2 6
41769- 70 70 70 66 66 66 26 26 26 6 6 6
41770- 0 0 0 0 0 0 0 0 0 0 0 0
41771- 0 0 0 0 0 0 0 0 0 0 0 0
41772- 0 0 0 0 0 0 0 0 0 0 0 0
41773- 0 0 0 0 0 0 0 0 0 0 0 0
41774- 0 0 0 0 0 0 0 0 0 0 0 0
41775- 0 0 0 0 0 0 0 0 0 0 0 0
41776- 0 0 0 0 0 0 0 0 0 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 10 10 10
41783- 38 38 38 86 86 86 14 14 14 10 10 10
41784-195 195 195 188 164 115 192 133 9 225 175 15
41785-239 182 13 234 190 10 232 195 16 232 200 30
41786-245 207 45 241 208 19 232 195 16 184 144 12
41787-218 194 134 211 206 186 42 42 42 2 2 6
41788- 2 2 6 2 2 6 2 2 6 2 2 6
41789- 50 50 50 74 74 74 30 30 30 6 6 6
41790- 0 0 0 0 0 0 0 0 0 0 0 0
41791- 0 0 0 0 0 0 0 0 0 0 0 0
41792- 0 0 0 0 0 0 0 0 0 0 0 0
41793- 0 0 0 0 0 0 0 0 0 0 0 0
41794- 0 0 0 0 0 0 0 0 0 0 0 0
41795- 0 0 0 0 0 0 0 0 0 0 0 0
41796- 0 0 0 0 0 0 0 0 0 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 10 10 10
41803- 34 34 34 86 86 86 14 14 14 2 2 6
41804-121 87 25 192 133 9 219 162 10 239 182 13
41805-236 186 11 232 195 16 241 208 19 244 214 54
41806-246 218 60 246 218 38 246 215 20 241 208 19
41807-241 208 19 226 184 13 121 87 25 2 2 6
41808- 2 2 6 2 2 6 2 2 6 2 2 6
41809- 50 50 50 82 82 82 34 34 34 10 10 10
41810- 0 0 0 0 0 0 0 0 0 0 0 0
41811- 0 0 0 0 0 0 0 0 0 0 0 0
41812- 0 0 0 0 0 0 0 0 0 0 0 0
41813- 0 0 0 0 0 0 0 0 0 0 0 0
41814- 0 0 0 0 0 0 0 0 0 0 0 0
41815- 0 0 0 0 0 0 0 0 0 0 0 0
41816- 0 0 0 0 0 0 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 10 10 10
41823- 34 34 34 82 82 82 30 30 30 61 42 6
41824-180 123 7 206 145 10 230 174 11 239 182 13
41825-234 190 10 238 202 15 241 208 19 246 218 74
41826-246 218 38 246 215 20 246 215 20 246 215 20
41827-226 184 13 215 174 15 184 144 12 6 6 6
41828- 2 2 6 2 2 6 2 2 6 2 2 6
41829- 26 26 26 94 94 94 42 42 42 14 14 14
41830- 0 0 0 0 0 0 0 0 0 0 0 0
41831- 0 0 0 0 0 0 0 0 0 0 0 0
41832- 0 0 0 0 0 0 0 0 0 0 0 0
41833- 0 0 0 0 0 0 0 0 0 0 0 0
41834- 0 0 0 0 0 0 0 0 0 0 0 0
41835- 0 0 0 0 0 0 0 0 0 0 0 0
41836- 0 0 0 0 0 0 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 10 10 10
41843- 30 30 30 78 78 78 50 50 50 104 69 6
41844-192 133 9 216 158 10 236 178 12 236 186 11
41845-232 195 16 241 208 19 244 214 54 245 215 43
41846-246 215 20 246 215 20 241 208 19 198 155 10
41847-200 144 11 216 158 10 156 118 10 2 2 6
41848- 2 2 6 2 2 6 2 2 6 2 2 6
41849- 6 6 6 90 90 90 54 54 54 18 18 18
41850- 6 6 6 0 0 0 0 0 0 0 0 0
41851- 0 0 0 0 0 0 0 0 0 0 0 0
41852- 0 0 0 0 0 0 0 0 0 0 0 0
41853- 0 0 0 0 0 0 0 0 0 0 0 0
41854- 0 0 0 0 0 0 0 0 0 0 0 0
41855- 0 0 0 0 0 0 0 0 0 0 0 0
41856- 0 0 0 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 10 10 10
41863- 30 30 30 78 78 78 46 46 46 22 22 22
41864-137 92 6 210 162 10 239 182 13 238 190 10
41865-238 202 15 241 208 19 246 215 20 246 215 20
41866-241 208 19 203 166 17 185 133 11 210 150 10
41867-216 158 10 210 150 10 102 78 10 2 2 6
41868- 6 6 6 54 54 54 14 14 14 2 2 6
41869- 2 2 6 62 62 62 74 74 74 30 30 30
41870- 10 10 10 0 0 0 0 0 0 0 0 0
41871- 0 0 0 0 0 0 0 0 0 0 0 0
41872- 0 0 0 0 0 0 0 0 0 0 0 0
41873- 0 0 0 0 0 0 0 0 0 0 0 0
41874- 0 0 0 0 0 0 0 0 0 0 0 0
41875- 0 0 0 0 0 0 0 0 0 0 0 0
41876- 0 0 0 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 10 10 10
41883- 34 34 34 78 78 78 50 50 50 6 6 6
41884- 94 70 30 139 102 15 190 146 13 226 184 13
41885-232 200 30 232 195 16 215 174 15 190 146 13
41886-168 122 10 192 133 9 210 150 10 213 154 11
41887-202 150 34 182 157 106 101 98 89 2 2 6
41888- 2 2 6 78 78 78 116 116 116 58 58 58
41889- 2 2 6 22 22 22 90 90 90 46 46 46
41890- 18 18 18 6 6 6 0 0 0 0 0 0
41891- 0 0 0 0 0 0 0 0 0 0 0 0
41892- 0 0 0 0 0 0 0 0 0 0 0 0
41893- 0 0 0 0 0 0 0 0 0 0 0 0
41894- 0 0 0 0 0 0 0 0 0 0 0 0
41895- 0 0 0 0 0 0 0 0 0 0 0 0
41896- 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 10 10 10
41903- 38 38 38 86 86 86 50 50 50 6 6 6
41904-128 128 128 174 154 114 156 107 11 168 122 10
41905-198 155 10 184 144 12 197 138 11 200 144 11
41906-206 145 10 206 145 10 197 138 11 188 164 115
41907-195 195 195 198 198 198 174 174 174 14 14 14
41908- 2 2 6 22 22 22 116 116 116 116 116 116
41909- 22 22 22 2 2 6 74 74 74 70 70 70
41910- 30 30 30 10 10 10 0 0 0 0 0 0
41911- 0 0 0 0 0 0 0 0 0 0 0 0
41912- 0 0 0 0 0 0 0 0 0 0 0 0
41913- 0 0 0 0 0 0 0 0 0 0 0 0
41914- 0 0 0 0 0 0 0 0 0 0 0 0
41915- 0 0 0 0 0 0 0 0 0 0 0 0
41916- 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 6 6 6 18 18 18
41923- 50 50 50 101 101 101 26 26 26 10 10 10
41924-138 138 138 190 190 190 174 154 114 156 107 11
41925-197 138 11 200 144 11 197 138 11 192 133 9
41926-180 123 7 190 142 34 190 178 144 187 187 187
41927-202 202 202 221 221 221 214 214 214 66 66 66
41928- 2 2 6 2 2 6 50 50 50 62 62 62
41929- 6 6 6 2 2 6 10 10 10 90 90 90
41930- 50 50 50 18 18 18 6 6 6 0 0 0
41931- 0 0 0 0 0 0 0 0 0 0 0 0
41932- 0 0 0 0 0 0 0 0 0 0 0 0
41933- 0 0 0 0 0 0 0 0 0 0 0 0
41934- 0 0 0 0 0 0 0 0 0 0 0 0
41935- 0 0 0 0 0 0 0 0 0 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 10 10 10 34 34 34
41943- 74 74 74 74 74 74 2 2 6 6 6 6
41944-144 144 144 198 198 198 190 190 190 178 166 146
41945-154 121 60 156 107 11 156 107 11 168 124 44
41946-174 154 114 187 187 187 190 190 190 210 210 210
41947-246 246 246 253 253 253 253 253 253 182 182 182
41948- 6 6 6 2 2 6 2 2 6 2 2 6
41949- 2 2 6 2 2 6 2 2 6 62 62 62
41950- 74 74 74 34 34 34 14 14 14 0 0 0
41951- 0 0 0 0 0 0 0 0 0 0 0 0
41952- 0 0 0 0 0 0 0 0 0 0 0 0
41953- 0 0 0 0 0 0 0 0 0 0 0 0
41954- 0 0 0 0 0 0 0 0 0 0 0 0
41955- 0 0 0 0 0 0 0 0 0 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 10 10 10 22 22 22 54 54 54
41963- 94 94 94 18 18 18 2 2 6 46 46 46
41964-234 234 234 221 221 221 190 190 190 190 190 190
41965-190 190 190 187 187 187 187 187 187 190 190 190
41966-190 190 190 195 195 195 214 214 214 242 242 242
41967-253 253 253 253 253 253 253 253 253 253 253 253
41968- 82 82 82 2 2 6 2 2 6 2 2 6
41969- 2 2 6 2 2 6 2 2 6 14 14 14
41970- 86 86 86 54 54 54 22 22 22 6 6 6
41971- 0 0 0 0 0 0 0 0 0 0 0 0
41972- 0 0 0 0 0 0 0 0 0 0 0 0
41973- 0 0 0 0 0 0 0 0 0 0 0 0
41974- 0 0 0 0 0 0 0 0 0 0 0 0
41975- 0 0 0 0 0 0 0 0 0 0 0 0
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- 6 6 6 18 18 18 46 46 46 90 90 90
41983- 46 46 46 18 18 18 6 6 6 182 182 182
41984-253 253 253 246 246 246 206 206 206 190 190 190
41985-190 190 190 190 190 190 190 190 190 190 190 190
41986-206 206 206 231 231 231 250 250 250 253 253 253
41987-253 253 253 253 253 253 253 253 253 253 253 253
41988-202 202 202 14 14 14 2 2 6 2 2 6
41989- 2 2 6 2 2 6 2 2 6 2 2 6
41990- 42 42 42 86 86 86 42 42 42 18 18 18
41991- 6 6 6 0 0 0 0 0 0 0 0 0
41992- 0 0 0 0 0 0 0 0 0 0 0 0
41993- 0 0 0 0 0 0 0 0 0 0 0 0
41994- 0 0 0 0 0 0 0 0 0 0 0 0
41995- 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6
42002- 14 14 14 38 38 38 74 74 74 66 66 66
42003- 2 2 6 6 6 6 90 90 90 250 250 250
42004-253 253 253 253 253 253 238 238 238 198 198 198
42005-190 190 190 190 190 190 195 195 195 221 221 221
42006-246 246 246 253 253 253 253 253 253 253 253 253
42007-253 253 253 253 253 253 253 253 253 253 253 253
42008-253 253 253 82 82 82 2 2 6 2 2 6
42009- 2 2 6 2 2 6 2 2 6 2 2 6
42010- 2 2 6 78 78 78 70 70 70 34 34 34
42011- 14 14 14 6 6 6 0 0 0 0 0 0
42012- 0 0 0 0 0 0 0 0 0 0 0 0
42013- 0 0 0 0 0 0 0 0 0 0 0 0
42014- 0 0 0 0 0 0 0 0 0 0 0 0
42015- 0 0 0 0 0 0 0 0 0 0 0 0
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 14 14 14
42022- 34 34 34 66 66 66 78 78 78 6 6 6
42023- 2 2 6 18 18 18 218 218 218 253 253 253
42024-253 253 253 253 253 253 253 253 253 246 246 246
42025-226 226 226 231 231 231 246 246 246 253 253 253
42026-253 253 253 253 253 253 253 253 253 253 253 253
42027-253 253 253 253 253 253 253 253 253 253 253 253
42028-253 253 253 178 178 178 2 2 6 2 2 6
42029- 2 2 6 2 2 6 2 2 6 2 2 6
42030- 2 2 6 18 18 18 90 90 90 62 62 62
42031- 30 30 30 10 10 10 0 0 0 0 0 0
42032- 0 0 0 0 0 0 0 0 0 0 0 0
42033- 0 0 0 0 0 0 0 0 0 0 0 0
42034- 0 0 0 0 0 0 0 0 0 0 0 0
42035- 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10 26 26 26
42042- 58 58 58 90 90 90 18 18 18 2 2 6
42043- 2 2 6 110 110 110 253 253 253 253 253 253
42044-253 253 253 253 253 253 253 253 253 253 253 253
42045-250 250 250 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 253 253 253 253 253 253
42048-253 253 253 231 231 231 18 18 18 2 2 6
42049- 2 2 6 2 2 6 2 2 6 2 2 6
42050- 2 2 6 2 2 6 18 18 18 94 94 94
42051- 54 54 54 26 26 26 10 10 10 0 0 0
42052- 0 0 0 0 0 0 0 0 0 0 0 0
42053- 0 0 0 0 0 0 0 0 0 0 0 0
42054- 0 0 0 0 0 0 0 0 0 0 0 0
42055- 0 0 0 0 0 0 0 0 0 0 0 0
42056- 0 0 0 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 6 6 6 22 22 22 50 50 50
42062- 90 90 90 26 26 26 2 2 6 2 2 6
42063- 14 14 14 195 195 195 250 250 250 253 253 253
42064-253 253 253 253 253 253 253 253 253 253 253 253
42065-253 253 253 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 253 253 253 253 253 253
42068-250 250 250 242 242 242 54 54 54 2 2 6
42069- 2 2 6 2 2 6 2 2 6 2 2 6
42070- 2 2 6 2 2 6 2 2 6 38 38 38
42071- 86 86 86 50 50 50 22 22 22 6 6 6
42072- 0 0 0 0 0 0 0 0 0 0 0 0
42073- 0 0 0 0 0 0 0 0 0 0 0 0
42074- 0 0 0 0 0 0 0 0 0 0 0 0
42075- 0 0 0 0 0 0 0 0 0 0 0 0
42076- 0 0 0 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- 6 6 6 14 14 14 38 38 38 82 82 82
42082- 34 34 34 2 2 6 2 2 6 2 2 6
42083- 42 42 42 195 195 195 246 246 246 253 253 253
42084-253 253 253 253 253 253 253 253 253 250 250 250
42085-242 242 242 242 242 242 250 250 250 253 253 253
42086-253 253 253 253 253 253 253 253 253 253 253 253
42087-253 253 253 250 250 250 246 246 246 238 238 238
42088-226 226 226 231 231 231 101 101 101 6 6 6
42089- 2 2 6 2 2 6 2 2 6 2 2 6
42090- 2 2 6 2 2 6 2 2 6 2 2 6
42091- 38 38 38 82 82 82 42 42 42 14 14 14
42092- 6 6 6 0 0 0 0 0 0 0 0 0
42093- 0 0 0 0 0 0 0 0 0 0 0 0
42094- 0 0 0 0 0 0 0 0 0 0 0 0
42095- 0 0 0 0 0 0 0 0 0 0 0 0
42096- 0 0 0 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- 10 10 10 26 26 26 62 62 62 66 66 66
42102- 2 2 6 2 2 6 2 2 6 6 6 6
42103- 70 70 70 170 170 170 206 206 206 234 234 234
42104-246 246 246 250 250 250 250 250 250 238 238 238
42105-226 226 226 231 231 231 238 238 238 250 250 250
42106-250 250 250 250 250 250 246 246 246 231 231 231
42107-214 214 214 206 206 206 202 202 202 202 202 202
42108-198 198 198 202 202 202 182 182 182 18 18 18
42109- 2 2 6 2 2 6 2 2 6 2 2 6
42110- 2 2 6 2 2 6 2 2 6 2 2 6
42111- 2 2 6 62 62 62 66 66 66 30 30 30
42112- 10 10 10 0 0 0 0 0 0 0 0 0
42113- 0 0 0 0 0 0 0 0 0 0 0 0
42114- 0 0 0 0 0 0 0 0 0 0 0 0
42115- 0 0 0 0 0 0 0 0 0 0 0 0
42116- 0 0 0 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- 14 14 14 42 42 42 82 82 82 18 18 18
42122- 2 2 6 2 2 6 2 2 6 10 10 10
42123- 94 94 94 182 182 182 218 218 218 242 242 242
42124-250 250 250 253 253 253 253 253 253 250 250 250
42125-234 234 234 253 253 253 253 253 253 253 253 253
42126-253 253 253 253 253 253 253 253 253 246 246 246
42127-238 238 238 226 226 226 210 210 210 202 202 202
42128-195 195 195 195 195 195 210 210 210 158 158 158
42129- 6 6 6 14 14 14 50 50 50 14 14 14
42130- 2 2 6 2 2 6 2 2 6 2 2 6
42131- 2 2 6 6 6 6 86 86 86 46 46 46
42132- 18 18 18 6 6 6 0 0 0 0 0 0
42133- 0 0 0 0 0 0 0 0 0 0 0 0
42134- 0 0 0 0 0 0 0 0 0 0 0 0
42135- 0 0 0 0 0 0 0 0 0 0 0 0
42136- 0 0 0 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 6 6 6
42141- 22 22 22 54 54 54 70 70 70 2 2 6
42142- 2 2 6 10 10 10 2 2 6 22 22 22
42143-166 166 166 231 231 231 250 250 250 253 253 253
42144-253 253 253 253 253 253 253 253 253 250 250 250
42145-242 242 242 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 253 253 253 246 246 246
42148-231 231 231 206 206 206 198 198 198 226 226 226
42149- 94 94 94 2 2 6 6 6 6 38 38 38
42150- 30 30 30 2 2 6 2 2 6 2 2 6
42151- 2 2 6 2 2 6 62 62 62 66 66 66
42152- 26 26 26 10 10 10 0 0 0 0 0 0
42153- 0 0 0 0 0 0 0 0 0 0 0 0
42154- 0 0 0 0 0 0 0 0 0 0 0 0
42155- 0 0 0 0 0 0 0 0 0 0 0 0
42156- 0 0 0 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 10 10 10
42161- 30 30 30 74 74 74 50 50 50 2 2 6
42162- 26 26 26 26 26 26 2 2 6 106 106 106
42163-238 238 238 253 253 253 253 253 253 253 253 253
42164-253 253 253 253 253 253 253 253 253 253 253 253
42165-253 253 253 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 253 253 253 253 253 253
42168-253 253 253 246 246 246 218 218 218 202 202 202
42169-210 210 210 14 14 14 2 2 6 2 2 6
42170- 30 30 30 22 22 22 2 2 6 2 2 6
42171- 2 2 6 2 2 6 18 18 18 86 86 86
42172- 42 42 42 14 14 14 0 0 0 0 0 0
42173- 0 0 0 0 0 0 0 0 0 0 0 0
42174- 0 0 0 0 0 0 0 0 0 0 0 0
42175- 0 0 0 0 0 0 0 0 0 0 0 0
42176- 0 0 0 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 14 14 14
42181- 42 42 42 90 90 90 22 22 22 2 2 6
42182- 42 42 42 2 2 6 18 18 18 218 218 218
42183-253 253 253 253 253 253 253 253 253 253 253 253
42184-253 253 253 253 253 253 253 253 253 253 253 253
42185-253 253 253 253 253 253 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 253 253 253 253 253 253
42188-253 253 253 253 253 253 250 250 250 221 221 221
42189-218 218 218 101 101 101 2 2 6 14 14 14
42190- 18 18 18 38 38 38 10 10 10 2 2 6
42191- 2 2 6 2 2 6 2 2 6 78 78 78
42192- 58 58 58 22 22 22 6 6 6 0 0 0
42193- 0 0 0 0 0 0 0 0 0 0 0 0
42194- 0 0 0 0 0 0 0 0 0 0 0 0
42195- 0 0 0 0 0 0 0 0 0 0 0 0
42196- 0 0 0 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 6 6 6 18 18 18
42201- 54 54 54 82 82 82 2 2 6 26 26 26
42202- 22 22 22 2 2 6 123 123 123 253 253 253
42203-253 253 253 253 253 253 253 253 253 253 253 253
42204-253 253 253 253 253 253 253 253 253 253 253 253
42205-253 253 253 253 253 253 253 253 253 253 253 253
42206-253 253 253 253 253 253 253 253 253 253 253 253
42207-253 253 253 253 253 253 253 253 253 253 253 253
42208-253 253 253 253 253 253 253 253 253 250 250 250
42209-238 238 238 198 198 198 6 6 6 38 38 38
42210- 58 58 58 26 26 26 38 38 38 2 2 6
42211- 2 2 6 2 2 6 2 2 6 46 46 46
42212- 78 78 78 30 30 30 10 10 10 0 0 0
42213- 0 0 0 0 0 0 0 0 0 0 0 0
42214- 0 0 0 0 0 0 0 0 0 0 0 0
42215- 0 0 0 0 0 0 0 0 0 0 0 0
42216- 0 0 0 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 10 10 10 30 30 30
42221- 74 74 74 58 58 58 2 2 6 42 42 42
42222- 2 2 6 22 22 22 231 231 231 253 253 253
42223-253 253 253 253 253 253 253 253 253 253 253 253
42224-253 253 253 253 253 253 253 253 253 250 250 250
42225-253 253 253 253 253 253 253 253 253 253 253 253
42226-253 253 253 253 253 253 253 253 253 253 253 253
42227-253 253 253 253 253 253 253 253 253 253 253 253
42228-253 253 253 253 253 253 253 253 253 253 253 253
42229-253 253 253 246 246 246 46 46 46 38 38 38
42230- 42 42 42 14 14 14 38 38 38 14 14 14
42231- 2 2 6 2 2 6 2 2 6 6 6 6
42232- 86 86 86 46 46 46 14 14 14 0 0 0
42233- 0 0 0 0 0 0 0 0 0 0 0 0
42234- 0 0 0 0 0 0 0 0 0 0 0 0
42235- 0 0 0 0 0 0 0 0 0 0 0 0
42236- 0 0 0 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 6 6 6 14 14 14 42 42 42
42241- 90 90 90 18 18 18 18 18 18 26 26 26
42242- 2 2 6 116 116 116 253 253 253 253 253 253
42243-253 253 253 253 253 253 253 253 253 253 253 253
42244-253 253 253 253 253 253 250 250 250 238 238 238
42245-253 253 253 253 253 253 253 253 253 253 253 253
42246-253 253 253 253 253 253 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 94 94 94 6 6 6
42250- 2 2 6 2 2 6 10 10 10 34 34 34
42251- 2 2 6 2 2 6 2 2 6 2 2 6
42252- 74 74 74 58 58 58 22 22 22 6 6 6
42253- 0 0 0 0 0 0 0 0 0 0 0 0
42254- 0 0 0 0 0 0 0 0 0 0 0 0
42255- 0 0 0 0 0 0 0 0 0 0 0 0
42256- 0 0 0 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 10 10 10 26 26 26 66 66 66
42261- 82 82 82 2 2 6 38 38 38 6 6 6
42262- 14 14 14 210 210 210 253 253 253 253 253 253
42263-253 253 253 253 253 253 253 253 253 253 253 253
42264-253 253 253 253 253 253 246 246 246 242 242 242
42265-253 253 253 253 253 253 253 253 253 253 253 253
42266-253 253 253 253 253 253 253 253 253 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 144 144 144 2 2 6
42270- 2 2 6 2 2 6 2 2 6 46 46 46
42271- 2 2 6 2 2 6 2 2 6 2 2 6
42272- 42 42 42 74 74 74 30 30 30 10 10 10
42273- 0 0 0 0 0 0 0 0 0 0 0 0
42274- 0 0 0 0 0 0 0 0 0 0 0 0
42275- 0 0 0 0 0 0 0 0 0 0 0 0
42276- 0 0 0 0 0 0 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- 6 6 6 14 14 14 42 42 42 90 90 90
42281- 26 26 26 6 6 6 42 42 42 2 2 6
42282- 74 74 74 250 250 250 253 253 253 253 253 253
42283-253 253 253 253 253 253 253 253 253 253 253 253
42284-253 253 253 253 253 253 242 242 242 242 242 242
42285-253 253 253 253 253 253 253 253 253 253 253 253
42286-253 253 253 253 253 253 253 253 253 253 253 253
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 182 182 182 2 2 6
42290- 2 2 6 2 2 6 2 2 6 46 46 46
42291- 2 2 6 2 2 6 2 2 6 2 2 6
42292- 10 10 10 86 86 86 38 38 38 10 10 10
42293- 0 0 0 0 0 0 0 0 0 0 0 0
42294- 0 0 0 0 0 0 0 0 0 0 0 0
42295- 0 0 0 0 0 0 0 0 0 0 0 0
42296- 0 0 0 0 0 0 0 0 0 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- 10 10 10 26 26 26 66 66 66 82 82 82
42301- 2 2 6 22 22 22 18 18 18 2 2 6
42302-149 149 149 253 253 253 253 253 253 253 253 253
42303-253 253 253 253 253 253 253 253 253 253 253 253
42304-253 253 253 253 253 253 234 234 234 242 242 242
42305-253 253 253 253 253 253 253 253 253 253 253 253
42306-253 253 253 253 253 253 253 253 253 253 253 253
42307-253 253 253 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 206 206 206 2 2 6
42310- 2 2 6 2 2 6 2 2 6 38 38 38
42311- 2 2 6 2 2 6 2 2 6 2 2 6
42312- 6 6 6 86 86 86 46 46 46 14 14 14
42313- 0 0 0 0 0 0 0 0 0 0 0 0
42314- 0 0 0 0 0 0 0 0 0 0 0 0
42315- 0 0 0 0 0 0 0 0 0 0 0 0
42316- 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6
42320- 18 18 18 46 46 46 86 86 86 18 18 18
42321- 2 2 6 34 34 34 10 10 10 6 6 6
42322-210 210 210 253 253 253 253 253 253 253 253 253
42323-253 253 253 253 253 253 253 253 253 253 253 253
42324-253 253 253 253 253 253 234 234 234 242 242 242
42325-253 253 253 253 253 253 253 253 253 253 253 253
42326-253 253 253 253 253 253 253 253 253 253 253 253
42327-253 253 253 253 253 253 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 221 221 221 6 6 6
42330- 2 2 6 2 2 6 6 6 6 30 30 30
42331- 2 2 6 2 2 6 2 2 6 2 2 6
42332- 2 2 6 82 82 82 54 54 54 18 18 18
42333- 6 6 6 0 0 0 0 0 0 0 0 0
42334- 0 0 0 0 0 0 0 0 0 0 0 0
42335- 0 0 0 0 0 0 0 0 0 0 0 0
42336- 0 0 0 0 0 0 0 0 0 0 0 0
42337- 0 0 0 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 10 10 10
42340- 26 26 26 66 66 66 62 62 62 2 2 6
42341- 2 2 6 38 38 38 10 10 10 26 26 26
42342-238 238 238 253 253 253 253 253 253 253 253 253
42343-253 253 253 253 253 253 253 253 253 253 253 253
42344-253 253 253 253 253 253 231 231 231 238 238 238
42345-253 253 253 253 253 253 253 253 253 253 253 253
42346-253 253 253 253 253 253 253 253 253 253 253 253
42347-253 253 253 253 253 253 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 231 231 231 6 6 6
42350- 2 2 6 2 2 6 10 10 10 30 30 30
42351- 2 2 6 2 2 6 2 2 6 2 2 6
42352- 2 2 6 66 66 66 58 58 58 22 22 22
42353- 6 6 6 0 0 0 0 0 0 0 0 0
42354- 0 0 0 0 0 0 0 0 0 0 0 0
42355- 0 0 0 0 0 0 0 0 0 0 0 0
42356- 0 0 0 0 0 0 0 0 0 0 0 0
42357- 0 0 0 0 0 0 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 10 10 10
42360- 38 38 38 78 78 78 6 6 6 2 2 6
42361- 2 2 6 46 46 46 14 14 14 42 42 42
42362-246 246 246 253 253 253 253 253 253 253 253 253
42363-253 253 253 253 253 253 253 253 253 253 253 253
42364-253 253 253 253 253 253 231 231 231 242 242 242
42365-253 253 253 253 253 253 253 253 253 253 253 253
42366-253 253 253 253 253 253 253 253 253 253 253 253
42367-253 253 253 253 253 253 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 234 234 234 10 10 10
42370- 2 2 6 2 2 6 22 22 22 14 14 14
42371- 2 2 6 2 2 6 2 2 6 2 2 6
42372- 2 2 6 66 66 66 62 62 62 22 22 22
42373- 6 6 6 0 0 0 0 0 0 0 0 0
42374- 0 0 0 0 0 0 0 0 0 0 0 0
42375- 0 0 0 0 0 0 0 0 0 0 0 0
42376- 0 0 0 0 0 0 0 0 0 0 0 0
42377- 0 0 0 0 0 0 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 6 6 6 18 18 18
42380- 50 50 50 74 74 74 2 2 6 2 2 6
42381- 14 14 14 70 70 70 34 34 34 62 62 62
42382-250 250 250 253 253 253 253 253 253 253 253 253
42383-253 253 253 253 253 253 253 253 253 253 253 253
42384-253 253 253 253 253 253 231 231 231 246 246 246
42385-253 253 253 253 253 253 253 253 253 253 253 253
42386-253 253 253 253 253 253 253 253 253 253 253 253
42387-253 253 253 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 234 234 234 14 14 14
42390- 2 2 6 2 2 6 30 30 30 2 2 6
42391- 2 2 6 2 2 6 2 2 6 2 2 6
42392- 2 2 6 66 66 66 62 62 62 22 22 22
42393- 6 6 6 0 0 0 0 0 0 0 0 0
42394- 0 0 0 0 0 0 0 0 0 0 0 0
42395- 0 0 0 0 0 0 0 0 0 0 0 0
42396- 0 0 0 0 0 0 0 0 0 0 0 0
42397- 0 0 0 0 0 0 0 0 0 0 0 0
42398- 0 0 0 0 0 0 0 0 0 0 0 0
42399- 0 0 0 0 0 0 6 6 6 18 18 18
42400- 54 54 54 62 62 62 2 2 6 2 2 6
42401- 2 2 6 30 30 30 46 46 46 70 70 70
42402-250 250 250 253 253 253 253 253 253 253 253 253
42403-253 253 253 253 253 253 253 253 253 253 253 253
42404-253 253 253 253 253 253 231 231 231 246 246 246
42405-253 253 253 253 253 253 253 253 253 253 253 253
42406-253 253 253 253 253 253 253 253 253 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 226 226 226 10 10 10
42410- 2 2 6 6 6 6 30 30 30 2 2 6
42411- 2 2 6 2 2 6 2 2 6 2 2 6
42412- 2 2 6 66 66 66 58 58 58 22 22 22
42413- 6 6 6 0 0 0 0 0 0 0 0 0
42414- 0 0 0 0 0 0 0 0 0 0 0 0
42415- 0 0 0 0 0 0 0 0 0 0 0 0
42416- 0 0 0 0 0 0 0 0 0 0 0 0
42417- 0 0 0 0 0 0 0 0 0 0 0 0
42418- 0 0 0 0 0 0 0 0 0 0 0 0
42419- 0 0 0 0 0 0 6 6 6 22 22 22
42420- 58 58 58 62 62 62 2 2 6 2 2 6
42421- 2 2 6 2 2 6 30 30 30 78 78 78
42422-250 250 250 253 253 253 253 253 253 253 253 253
42423-253 253 253 253 253 253 253 253 253 253 253 253
42424-253 253 253 253 253 253 231 231 231 246 246 246
42425-253 253 253 253 253 253 253 253 253 253 253 253
42426-253 253 253 253 253 253 253 253 253 253 253 253
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 206 206 206 2 2 6
42430- 22 22 22 34 34 34 18 14 6 22 22 22
42431- 26 26 26 18 18 18 6 6 6 2 2 6
42432- 2 2 6 82 82 82 54 54 54 18 18 18
42433- 6 6 6 0 0 0 0 0 0 0 0 0
42434- 0 0 0 0 0 0 0 0 0 0 0 0
42435- 0 0 0 0 0 0 0 0 0 0 0 0
42436- 0 0 0 0 0 0 0 0 0 0 0 0
42437- 0 0 0 0 0 0 0 0 0 0 0 0
42438- 0 0 0 0 0 0 0 0 0 0 0 0
42439- 0 0 0 0 0 0 6 6 6 26 26 26
42440- 62 62 62 106 106 106 74 54 14 185 133 11
42441-210 162 10 121 92 8 6 6 6 62 62 62
42442-238 238 238 253 253 253 253 253 253 253 253 253
42443-253 253 253 253 253 253 253 253 253 253 253 253
42444-253 253 253 253 253 253 231 231 231 246 246 246
42445-253 253 253 253 253 253 253 253 253 253 253 253
42446-253 253 253 253 253 253 253 253 253 253 253 253
42447-253 253 253 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 158 158 158 18 18 18
42450- 14 14 14 2 2 6 2 2 6 2 2 6
42451- 6 6 6 18 18 18 66 66 66 38 38 38
42452- 6 6 6 94 94 94 50 50 50 18 18 18
42453- 6 6 6 0 0 0 0 0 0 0 0 0
42454- 0 0 0 0 0 0 0 0 0 0 0 0
42455- 0 0 0 0 0 0 0 0 0 0 0 0
42456- 0 0 0 0 0 0 0 0 0 0 0 0
42457- 0 0 0 0 0 0 0 0 0 0 0 0
42458- 0 0 0 0 0 0 0 0 0 6 6 6
42459- 10 10 10 10 10 10 18 18 18 38 38 38
42460- 78 78 78 142 134 106 216 158 10 242 186 14
42461-246 190 14 246 190 14 156 118 10 10 10 10
42462- 90 90 90 238 238 238 253 253 253 253 253 253
42463-253 253 253 253 253 253 253 253 253 253 253 253
42464-253 253 253 253 253 253 231 231 231 250 250 250
42465-253 253 253 253 253 253 253 253 253 253 253 253
42466-253 253 253 253 253 253 253 253 253 253 253 253
42467-253 253 253 253 253 253 253 253 253 253 253 253
42468-253 253 253 253 253 253 253 253 253 246 230 190
42469-238 204 91 238 204 91 181 142 44 37 26 9
42470- 2 2 6 2 2 6 2 2 6 2 2 6
42471- 2 2 6 2 2 6 38 38 38 46 46 46
42472- 26 26 26 106 106 106 54 54 54 18 18 18
42473- 6 6 6 0 0 0 0 0 0 0 0 0
42474- 0 0 0 0 0 0 0 0 0 0 0 0
42475- 0 0 0 0 0 0 0 0 0 0 0 0
42476- 0 0 0 0 0 0 0 0 0 0 0 0
42477- 0 0 0 0 0 0 0 0 0 0 0 0
42478- 0 0 0 6 6 6 14 14 14 22 22 22
42479- 30 30 30 38 38 38 50 50 50 70 70 70
42480-106 106 106 190 142 34 226 170 11 242 186 14
42481-246 190 14 246 190 14 246 190 14 154 114 10
42482- 6 6 6 74 74 74 226 226 226 253 253 253
42483-253 253 253 253 253 253 253 253 253 253 253 253
42484-253 253 253 253 253 253 231 231 231 250 250 250
42485-253 253 253 253 253 253 253 253 253 253 253 253
42486-253 253 253 253 253 253 253 253 253 253 253 253
42487-253 253 253 253 253 253 253 253 253 253 253 253
42488-253 253 253 253 253 253 253 253 253 228 184 62
42489-241 196 14 241 208 19 232 195 16 38 30 10
42490- 2 2 6 2 2 6 2 2 6 2 2 6
42491- 2 2 6 6 6 6 30 30 30 26 26 26
42492-203 166 17 154 142 90 66 66 66 26 26 26
42493- 6 6 6 0 0 0 0 0 0 0 0 0
42494- 0 0 0 0 0 0 0 0 0 0 0 0
42495- 0 0 0 0 0 0 0 0 0 0 0 0
42496- 0 0 0 0 0 0 0 0 0 0 0 0
42497- 0 0 0 0 0 0 0 0 0 0 0 0
42498- 6 6 6 18 18 18 38 38 38 58 58 58
42499- 78 78 78 86 86 86 101 101 101 123 123 123
42500-175 146 61 210 150 10 234 174 13 246 186 14
42501-246 190 14 246 190 14 246 190 14 238 190 10
42502-102 78 10 2 2 6 46 46 46 198 198 198
42503-253 253 253 253 253 253 253 253 253 253 253 253
42504-253 253 253 253 253 253 234 234 234 242 242 242
42505-253 253 253 253 253 253 253 253 253 253 253 253
42506-253 253 253 253 253 253 253 253 253 253 253 253
42507-253 253 253 253 253 253 253 253 253 253 253 253
42508-253 253 253 253 253 253 253 253 253 224 178 62
42509-242 186 14 241 196 14 210 166 10 22 18 6
42510- 2 2 6 2 2 6 2 2 6 2 2 6
42511- 2 2 6 2 2 6 6 6 6 121 92 8
42512-238 202 15 232 195 16 82 82 82 34 34 34
42513- 10 10 10 0 0 0 0 0 0 0 0 0
42514- 0 0 0 0 0 0 0 0 0 0 0 0
42515- 0 0 0 0 0 0 0 0 0 0 0 0
42516- 0 0 0 0 0 0 0 0 0 0 0 0
42517- 0 0 0 0 0 0 0 0 0 0 0 0
42518- 14 14 14 38 38 38 70 70 70 154 122 46
42519-190 142 34 200 144 11 197 138 11 197 138 11
42520-213 154 11 226 170 11 242 186 14 246 190 14
42521-246 190 14 246 190 14 246 190 14 246 190 14
42522-225 175 15 46 32 6 2 2 6 22 22 22
42523-158 158 158 250 250 250 253 253 253 253 253 253
42524-253 253 253 253 253 253 253 253 253 253 253 253
42525-253 253 253 253 253 253 253 253 253 253 253 253
42526-253 253 253 253 253 253 253 253 253 253 253 253
42527-253 253 253 253 253 253 253 253 253 253 253 253
42528-253 253 253 250 250 250 242 242 242 224 178 62
42529-239 182 13 236 186 11 213 154 11 46 32 6
42530- 2 2 6 2 2 6 2 2 6 2 2 6
42531- 2 2 6 2 2 6 61 42 6 225 175 15
42532-238 190 10 236 186 11 112 100 78 42 42 42
42533- 14 14 14 0 0 0 0 0 0 0 0 0
42534- 0 0 0 0 0 0 0 0 0 0 0 0
42535- 0 0 0 0 0 0 0 0 0 0 0 0
42536- 0 0 0 0 0 0 0 0 0 0 0 0
42537- 0 0 0 0 0 0 0 0 0 6 6 6
42538- 22 22 22 54 54 54 154 122 46 213 154 11
42539-226 170 11 230 174 11 226 170 11 226 170 11
42540-236 178 12 242 186 14 246 190 14 246 190 14
42541-246 190 14 246 190 14 246 190 14 246 190 14
42542-241 196 14 184 144 12 10 10 10 2 2 6
42543- 6 6 6 116 116 116 242 242 242 253 253 253
42544-253 253 253 253 253 253 253 253 253 253 253 253
42545-253 253 253 253 253 253 253 253 253 253 253 253
42546-253 253 253 253 253 253 253 253 253 253 253 253
42547-253 253 253 253 253 253 253 253 253 253 253 253
42548-253 253 253 231 231 231 198 198 198 214 170 54
42549-236 178 12 236 178 12 210 150 10 137 92 6
42550- 18 14 6 2 2 6 2 2 6 2 2 6
42551- 6 6 6 70 47 6 200 144 11 236 178 12
42552-239 182 13 239 182 13 124 112 88 58 58 58
42553- 22 22 22 6 6 6 0 0 0 0 0 0
42554- 0 0 0 0 0 0 0 0 0 0 0 0
42555- 0 0 0 0 0 0 0 0 0 0 0 0
42556- 0 0 0 0 0 0 0 0 0 0 0 0
42557- 0 0 0 0 0 0 0 0 0 10 10 10
42558- 30 30 30 70 70 70 180 133 36 226 170 11
42559-239 182 13 242 186 14 242 186 14 246 186 14
42560-246 190 14 246 190 14 246 190 14 246 190 14
42561-246 190 14 246 190 14 246 190 14 246 190 14
42562-246 190 14 232 195 16 98 70 6 2 2 6
42563- 2 2 6 2 2 6 66 66 66 221 221 221
42564-253 253 253 253 253 253 253 253 253 253 253 253
42565-253 253 253 253 253 253 253 253 253 253 253 253
42566-253 253 253 253 253 253 253 253 253 253 253 253
42567-253 253 253 253 253 253 253 253 253 253 253 253
42568-253 253 253 206 206 206 198 198 198 214 166 58
42569-230 174 11 230 174 11 216 158 10 192 133 9
42570-163 110 8 116 81 8 102 78 10 116 81 8
42571-167 114 7 197 138 11 226 170 11 239 182 13
42572-242 186 14 242 186 14 162 146 94 78 78 78
42573- 34 34 34 14 14 14 6 6 6 0 0 0
42574- 0 0 0 0 0 0 0 0 0 0 0 0
42575- 0 0 0 0 0 0 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 6 6 6
42578- 30 30 30 78 78 78 190 142 34 226 170 11
42579-239 182 13 246 190 14 246 190 14 246 190 14
42580-246 190 14 246 190 14 246 190 14 246 190 14
42581-246 190 14 246 190 14 246 190 14 246 190 14
42582-246 190 14 241 196 14 203 166 17 22 18 6
42583- 2 2 6 2 2 6 2 2 6 38 38 38
42584-218 218 218 253 253 253 253 253 253 253 253 253
42585-253 253 253 253 253 253 253 253 253 253 253 253
42586-253 253 253 253 253 253 253 253 253 253 253 253
42587-253 253 253 253 253 253 253 253 253 253 253 253
42588-250 250 250 206 206 206 198 198 198 202 162 69
42589-226 170 11 236 178 12 224 166 10 210 150 10
42590-200 144 11 197 138 11 192 133 9 197 138 11
42591-210 150 10 226 170 11 242 186 14 246 190 14
42592-246 190 14 246 186 14 225 175 15 124 112 88
42593- 62 62 62 30 30 30 14 14 14 6 6 6
42594- 0 0 0 0 0 0 0 0 0 0 0 0
42595- 0 0 0 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 10 10 10
42598- 30 30 30 78 78 78 174 135 50 224 166 10
42599-239 182 13 246 190 14 246 190 14 246 190 14
42600-246 190 14 246 190 14 246 190 14 246 190 14
42601-246 190 14 246 190 14 246 190 14 246 190 14
42602-246 190 14 246 190 14 241 196 14 139 102 15
42603- 2 2 6 2 2 6 2 2 6 2 2 6
42604- 78 78 78 250 250 250 253 253 253 253 253 253
42605-253 253 253 253 253 253 253 253 253 253 253 253
42606-253 253 253 253 253 253 253 253 253 253 253 253
42607-253 253 253 253 253 253 253 253 253 253 253 253
42608-250 250 250 214 214 214 198 198 198 190 150 46
42609-219 162 10 236 178 12 234 174 13 224 166 10
42610-216 158 10 213 154 11 213 154 11 216 158 10
42611-226 170 11 239 182 13 246 190 14 246 190 14
42612-246 190 14 246 190 14 242 186 14 206 162 42
42613-101 101 101 58 58 58 30 30 30 14 14 14
42614- 6 6 6 0 0 0 0 0 0 0 0 0
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 10 10 10
42618- 30 30 30 74 74 74 174 135 50 216 158 10
42619-236 178 12 246 190 14 246 190 14 246 190 14
42620-246 190 14 246 190 14 246 190 14 246 190 14
42621-246 190 14 246 190 14 246 190 14 246 190 14
42622-246 190 14 246 190 14 241 196 14 226 184 13
42623- 61 42 6 2 2 6 2 2 6 2 2 6
42624- 22 22 22 238 238 238 253 253 253 253 253 253
42625-253 253 253 253 253 253 253 253 253 253 253 253
42626-253 253 253 253 253 253 253 253 253 253 253 253
42627-253 253 253 253 253 253 253 253 253 253 253 253
42628-253 253 253 226 226 226 187 187 187 180 133 36
42629-216 158 10 236 178 12 239 182 13 236 178 12
42630-230 174 11 226 170 11 226 170 11 230 174 11
42631-236 178 12 242 186 14 246 190 14 246 190 14
42632-246 190 14 246 190 14 246 186 14 239 182 13
42633-206 162 42 106 106 106 66 66 66 34 34 34
42634- 14 14 14 6 6 6 0 0 0 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 6 6 6
42638- 26 26 26 70 70 70 163 133 67 213 154 11
42639-236 178 12 246 190 14 246 190 14 246 190 14
42640-246 190 14 246 190 14 246 190 14 246 190 14
42641-246 190 14 246 190 14 246 190 14 246 190 14
42642-246 190 14 246 190 14 246 190 14 241 196 14
42643-190 146 13 18 14 6 2 2 6 2 2 6
42644- 46 46 46 246 246 246 253 253 253 253 253 253
42645-253 253 253 253 253 253 253 253 253 253 253 253
42646-253 253 253 253 253 253 253 253 253 253 253 253
42647-253 253 253 253 253 253 253 253 253 253 253 253
42648-253 253 253 221 221 221 86 86 86 156 107 11
42649-216 158 10 236 178 12 242 186 14 246 186 14
42650-242 186 14 239 182 13 239 182 13 242 186 14
42651-242 186 14 246 186 14 246 190 14 246 190 14
42652-246 190 14 246 190 14 246 190 14 246 190 14
42653-242 186 14 225 175 15 142 122 72 66 66 66
42654- 30 30 30 10 10 10 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 6 6 6
42658- 26 26 26 70 70 70 163 133 67 210 150 10
42659-236 178 12 246 190 14 246 190 14 246 190 14
42660-246 190 14 246 190 14 246 190 14 246 190 14
42661-246 190 14 246 190 14 246 190 14 246 190 14
42662-246 190 14 246 190 14 246 190 14 246 190 14
42663-232 195 16 121 92 8 34 34 34 106 106 106
42664-221 221 221 253 253 253 253 253 253 253 253 253
42665-253 253 253 253 253 253 253 253 253 253 253 253
42666-253 253 253 253 253 253 253 253 253 253 253 253
42667-253 253 253 253 253 253 253 253 253 253 253 253
42668-242 242 242 82 82 82 18 14 6 163 110 8
42669-216 158 10 236 178 12 242 186 14 246 190 14
42670-246 190 14 246 190 14 246 190 14 246 190 14
42671-246 190 14 246 190 14 246 190 14 246 190 14
42672-246 190 14 246 190 14 246 190 14 246 190 14
42673-246 190 14 246 190 14 242 186 14 163 133 67
42674- 46 46 46 18 18 18 6 6 6 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 10 10 10
42678- 30 30 30 78 78 78 163 133 67 210 150 10
42679-236 178 12 246 186 14 246 190 14 246 190 14
42680-246 190 14 246 190 14 246 190 14 246 190 14
42681-246 190 14 246 190 14 246 190 14 246 190 14
42682-246 190 14 246 190 14 246 190 14 246 190 14
42683-241 196 14 215 174 15 190 178 144 253 253 253
42684-253 253 253 253 253 253 253 253 253 253 253 253
42685-253 253 253 253 253 253 253 253 253 253 253 253
42686-253 253 253 253 253 253 253 253 253 253 253 253
42687-253 253 253 253 253 253 253 253 253 218 218 218
42688- 58 58 58 2 2 6 22 18 6 167 114 7
42689-216 158 10 236 178 12 246 186 14 246 190 14
42690-246 190 14 246 190 14 246 190 14 246 190 14
42691-246 190 14 246 190 14 246 190 14 246 190 14
42692-246 190 14 246 190 14 246 190 14 246 190 14
42693-246 190 14 246 186 14 242 186 14 190 150 46
42694- 54 54 54 22 22 22 6 6 6 0 0 0
42695- 0 0 0 0 0 0 0 0 0 0 0 0
42696- 0 0 0 0 0 0 0 0 0 0 0 0
42697- 0 0 0 0 0 0 0 0 0 14 14 14
42698- 38 38 38 86 86 86 180 133 36 213 154 11
42699-236 178 12 246 186 14 246 190 14 246 190 14
42700-246 190 14 246 190 14 246 190 14 246 190 14
42701-246 190 14 246 190 14 246 190 14 246 190 14
42702-246 190 14 246 190 14 246 190 14 246 190 14
42703-246 190 14 232 195 16 190 146 13 214 214 214
42704-253 253 253 253 253 253 253 253 253 253 253 253
42705-253 253 253 253 253 253 253 253 253 253 253 253
42706-253 253 253 253 253 253 253 253 253 253 253 253
42707-253 253 253 250 250 250 170 170 170 26 26 26
42708- 2 2 6 2 2 6 37 26 9 163 110 8
42709-219 162 10 239 182 13 246 186 14 246 190 14
42710-246 190 14 246 190 14 246 190 14 246 190 14
42711-246 190 14 246 190 14 246 190 14 246 190 14
42712-246 190 14 246 190 14 246 190 14 246 190 14
42713-246 186 14 236 178 12 224 166 10 142 122 72
42714- 46 46 46 18 18 18 6 6 6 0 0 0
42715- 0 0 0 0 0 0 0 0 0 0 0 0
42716- 0 0 0 0 0 0 0 0 0 0 0 0
42717- 0 0 0 0 0 0 6 6 6 18 18 18
42718- 50 50 50 109 106 95 192 133 9 224 166 10
42719-242 186 14 246 190 14 246 190 14 246 190 14
42720-246 190 14 246 190 14 246 190 14 246 190 14
42721-246 190 14 246 190 14 246 190 14 246 190 14
42722-246 190 14 246 190 14 246 190 14 246 190 14
42723-242 186 14 226 184 13 210 162 10 142 110 46
42724-226 226 226 253 253 253 253 253 253 253 253 253
42725-253 253 253 253 253 253 253 253 253 253 253 253
42726-253 253 253 253 253 253 253 253 253 253 253 253
42727-198 198 198 66 66 66 2 2 6 2 2 6
42728- 2 2 6 2 2 6 50 34 6 156 107 11
42729-219 162 10 239 182 13 246 186 14 246 190 14
42730-246 190 14 246 190 14 246 190 14 246 190 14
42731-246 190 14 246 190 14 246 190 14 246 190 14
42732-246 190 14 246 190 14 246 190 14 242 186 14
42733-234 174 13 213 154 11 154 122 46 66 66 66
42734- 30 30 30 10 10 10 0 0 0 0 0 0
42735- 0 0 0 0 0 0 0 0 0 0 0 0
42736- 0 0 0 0 0 0 0 0 0 0 0 0
42737- 0 0 0 0 0 0 6 6 6 22 22 22
42738- 58 58 58 154 121 60 206 145 10 234 174 13
42739-242 186 14 246 186 14 246 190 14 246 190 14
42740-246 190 14 246 190 14 246 190 14 246 190 14
42741-246 190 14 246 190 14 246 190 14 246 190 14
42742-246 190 14 246 190 14 246 190 14 246 190 14
42743-246 186 14 236 178 12 210 162 10 163 110 8
42744- 61 42 6 138 138 138 218 218 218 250 250 250
42745-253 253 253 253 253 253 253 253 253 250 250 250
42746-242 242 242 210 210 210 144 144 144 66 66 66
42747- 6 6 6 2 2 6 2 2 6 2 2 6
42748- 2 2 6 2 2 6 61 42 6 163 110 8
42749-216 158 10 236 178 12 246 190 14 246 190 14
42750-246 190 14 246 190 14 246 190 14 246 190 14
42751-246 190 14 246 190 14 246 190 14 246 190 14
42752-246 190 14 239 182 13 230 174 11 216 158 10
42753-190 142 34 124 112 88 70 70 70 38 38 38
42754- 18 18 18 6 6 6 0 0 0 0 0 0
42755- 0 0 0 0 0 0 0 0 0 0 0 0
42756- 0 0 0 0 0 0 0 0 0 0 0 0
42757- 0 0 0 0 0 0 6 6 6 22 22 22
42758- 62 62 62 168 124 44 206 145 10 224 166 10
42759-236 178 12 239 182 13 242 186 14 242 186 14
42760-246 186 14 246 190 14 246 190 14 246 190 14
42761-246 190 14 246 190 14 246 190 14 246 190 14
42762-246 190 14 246 190 14 246 190 14 246 190 14
42763-246 190 14 236 178 12 216 158 10 175 118 6
42764- 80 54 7 2 2 6 6 6 6 30 30 30
42765- 54 54 54 62 62 62 50 50 50 38 38 38
42766- 14 14 14 2 2 6 2 2 6 2 2 6
42767- 2 2 6 2 2 6 2 2 6 2 2 6
42768- 2 2 6 6 6 6 80 54 7 167 114 7
42769-213 154 11 236 178 12 246 190 14 246 190 14
42770-246 190 14 246 190 14 246 190 14 246 190 14
42771-246 190 14 242 186 14 239 182 13 239 182 13
42772-230 174 11 210 150 10 174 135 50 124 112 88
42773- 82 82 82 54 54 54 34 34 34 18 18 18
42774- 6 6 6 0 0 0 0 0 0 0 0 0
42775- 0 0 0 0 0 0 0 0 0 0 0 0
42776- 0 0 0 0 0 0 0 0 0 0 0 0
42777- 0 0 0 0 0 0 6 6 6 18 18 18
42778- 50 50 50 158 118 36 192 133 9 200 144 11
42779-216 158 10 219 162 10 224 166 10 226 170 11
42780-230 174 11 236 178 12 239 182 13 239 182 13
42781-242 186 14 246 186 14 246 190 14 246 190 14
42782-246 190 14 246 190 14 246 190 14 246 190 14
42783-246 186 14 230 174 11 210 150 10 163 110 8
42784-104 69 6 10 10 10 2 2 6 2 2 6
42785- 2 2 6 2 2 6 2 2 6 2 2 6
42786- 2 2 6 2 2 6 2 2 6 2 2 6
42787- 2 2 6 2 2 6 2 2 6 2 2 6
42788- 2 2 6 6 6 6 91 60 6 167 114 7
42789-206 145 10 230 174 11 242 186 14 246 190 14
42790-246 190 14 246 190 14 246 186 14 242 186 14
42791-239 182 13 230 174 11 224 166 10 213 154 11
42792-180 133 36 124 112 88 86 86 86 58 58 58
42793- 38 38 38 22 22 22 10 10 10 6 6 6
42794- 0 0 0 0 0 0 0 0 0 0 0 0
42795- 0 0 0 0 0 0 0 0 0 0 0 0
42796- 0 0 0 0 0 0 0 0 0 0 0 0
42797- 0 0 0 0 0 0 0 0 0 14 14 14
42798- 34 34 34 70 70 70 138 110 50 158 118 36
42799-167 114 7 180 123 7 192 133 9 197 138 11
42800-200 144 11 206 145 10 213 154 11 219 162 10
42801-224 166 10 230 174 11 239 182 13 242 186 14
42802-246 186 14 246 186 14 246 186 14 246 186 14
42803-239 182 13 216 158 10 185 133 11 152 99 6
42804-104 69 6 18 14 6 2 2 6 2 2 6
42805- 2 2 6 2 2 6 2 2 6 2 2 6
42806- 2 2 6 2 2 6 2 2 6 2 2 6
42807- 2 2 6 2 2 6 2 2 6 2 2 6
42808- 2 2 6 6 6 6 80 54 7 152 99 6
42809-192 133 9 219 162 10 236 178 12 239 182 13
42810-246 186 14 242 186 14 239 182 13 236 178 12
42811-224 166 10 206 145 10 192 133 9 154 121 60
42812- 94 94 94 62 62 62 42 42 42 22 22 22
42813- 14 14 14 6 6 6 0 0 0 0 0 0
42814- 0 0 0 0 0 0 0 0 0 0 0 0
42815- 0 0 0 0 0 0 0 0 0 0 0 0
42816- 0 0 0 0 0 0 0 0 0 0 0 0
42817- 0 0 0 0 0 0 0 0 0 6 6 6
42818- 18 18 18 34 34 34 58 58 58 78 78 78
42819-101 98 89 124 112 88 142 110 46 156 107 11
42820-163 110 8 167 114 7 175 118 6 180 123 7
42821-185 133 11 197 138 11 210 150 10 219 162 10
42822-226 170 11 236 178 12 236 178 12 234 174 13
42823-219 162 10 197 138 11 163 110 8 130 83 6
42824- 91 60 6 10 10 10 2 2 6 2 2 6
42825- 18 18 18 38 38 38 38 38 38 38 38 38
42826- 38 38 38 38 38 38 38 38 38 38 38 38
42827- 38 38 38 38 38 38 26 26 26 2 2 6
42828- 2 2 6 6 6 6 70 47 6 137 92 6
42829-175 118 6 200 144 11 219 162 10 230 174 11
42830-234 174 13 230 174 11 219 162 10 210 150 10
42831-192 133 9 163 110 8 124 112 88 82 82 82
42832- 50 50 50 30 30 30 14 14 14 6 6 6
42833- 0 0 0 0 0 0 0 0 0 0 0 0
42834- 0 0 0 0 0 0 0 0 0 0 0 0
42835- 0 0 0 0 0 0 0 0 0 0 0 0
42836- 0 0 0 0 0 0 0 0 0 0 0 0
42837- 0 0 0 0 0 0 0 0 0 0 0 0
42838- 6 6 6 14 14 14 22 22 22 34 34 34
42839- 42 42 42 58 58 58 74 74 74 86 86 86
42840-101 98 89 122 102 70 130 98 46 121 87 25
42841-137 92 6 152 99 6 163 110 8 180 123 7
42842-185 133 11 197 138 11 206 145 10 200 144 11
42843-180 123 7 156 107 11 130 83 6 104 69 6
42844- 50 34 6 54 54 54 110 110 110 101 98 89
42845- 86 86 86 82 82 82 78 78 78 78 78 78
42846- 78 78 78 78 78 78 78 78 78 78 78 78
42847- 78 78 78 82 82 82 86 86 86 94 94 94
42848-106 106 106 101 101 101 86 66 34 124 80 6
42849-156 107 11 180 123 7 192 133 9 200 144 11
42850-206 145 10 200 144 11 192 133 9 175 118 6
42851-139 102 15 109 106 95 70 70 70 42 42 42
42852- 22 22 22 10 10 10 0 0 0 0 0 0
42853- 0 0 0 0 0 0 0 0 0 0 0 0
42854- 0 0 0 0 0 0 0 0 0 0 0 0
42855- 0 0 0 0 0 0 0 0 0 0 0 0
42856- 0 0 0 0 0 0 0 0 0 0 0 0
42857- 0 0 0 0 0 0 0 0 0 0 0 0
42858- 0 0 0 0 0 0 6 6 6 10 10 10
42859- 14 14 14 22 22 22 30 30 30 38 38 38
42860- 50 50 50 62 62 62 74 74 74 90 90 90
42861-101 98 89 112 100 78 121 87 25 124 80 6
42862-137 92 6 152 99 6 152 99 6 152 99 6
42863-138 86 6 124 80 6 98 70 6 86 66 30
42864-101 98 89 82 82 82 58 58 58 46 46 46
42865- 38 38 38 34 34 34 34 34 34 34 34 34
42866- 34 34 34 34 34 34 34 34 34 34 34 34
42867- 34 34 34 34 34 34 38 38 38 42 42 42
42868- 54 54 54 82 82 82 94 86 76 91 60 6
42869-134 86 6 156 107 11 167 114 7 175 118 6
42870-175 118 6 167 114 7 152 99 6 121 87 25
42871-101 98 89 62 62 62 34 34 34 18 18 18
42872- 6 6 6 0 0 0 0 0 0 0 0 0
42873- 0 0 0 0 0 0 0 0 0 0 0 0
42874- 0 0 0 0 0 0 0 0 0 0 0 0
42875- 0 0 0 0 0 0 0 0 0 0 0 0
42876- 0 0 0 0 0 0 0 0 0 0 0 0
42877- 0 0 0 0 0 0 0 0 0 0 0 0
42878- 0 0 0 0 0 0 0 0 0 0 0 0
42879- 0 0 0 6 6 6 6 6 6 10 10 10
42880- 18 18 18 22 22 22 30 30 30 42 42 42
42881- 50 50 50 66 66 66 86 86 86 101 98 89
42882-106 86 58 98 70 6 104 69 6 104 69 6
42883-104 69 6 91 60 6 82 62 34 90 90 90
42884- 62 62 62 38 38 38 22 22 22 14 14 14
42885- 10 10 10 10 10 10 10 10 10 10 10 10
42886- 10 10 10 10 10 10 6 6 6 10 10 10
42887- 10 10 10 10 10 10 10 10 10 14 14 14
42888- 22 22 22 42 42 42 70 70 70 89 81 66
42889- 80 54 7 104 69 6 124 80 6 137 92 6
42890-134 86 6 116 81 8 100 82 52 86 86 86
42891- 58 58 58 30 30 30 14 14 14 6 6 6
42892- 0 0 0 0 0 0 0 0 0 0 0 0
42893- 0 0 0 0 0 0 0 0 0 0 0 0
42894- 0 0 0 0 0 0 0 0 0 0 0 0
42895- 0 0 0 0 0 0 0 0 0 0 0 0
42896- 0 0 0 0 0 0 0 0 0 0 0 0
42897- 0 0 0 0 0 0 0 0 0 0 0 0
42898- 0 0 0 0 0 0 0 0 0 0 0 0
42899- 0 0 0 0 0 0 0 0 0 0 0 0
42900- 0 0 0 6 6 6 10 10 10 14 14 14
42901- 18 18 18 26 26 26 38 38 38 54 54 54
42902- 70 70 70 86 86 86 94 86 76 89 81 66
42903- 89 81 66 86 86 86 74 74 74 50 50 50
42904- 30 30 30 14 14 14 6 6 6 0 0 0
42905- 0 0 0 0 0 0 0 0 0 0 0 0
42906- 0 0 0 0 0 0 0 0 0 0 0 0
42907- 0 0 0 0 0 0 0 0 0 0 0 0
42908- 6 6 6 18 18 18 34 34 34 58 58 58
42909- 82 82 82 89 81 66 89 81 66 89 81 66
42910- 94 86 66 94 86 76 74 74 74 50 50 50
42911- 26 26 26 14 14 14 6 6 6 0 0 0
42912- 0 0 0 0 0 0 0 0 0 0 0 0
42913- 0 0 0 0 0 0 0 0 0 0 0 0
42914- 0 0 0 0 0 0 0 0 0 0 0 0
42915- 0 0 0 0 0 0 0 0 0 0 0 0
42916- 0 0 0 0 0 0 0 0 0 0 0 0
42917- 0 0 0 0 0 0 0 0 0 0 0 0
42918- 0 0 0 0 0 0 0 0 0 0 0 0
42919- 0 0 0 0 0 0 0 0 0 0 0 0
42920- 0 0 0 0 0 0 0 0 0 0 0 0
42921- 6 6 6 6 6 6 14 14 14 18 18 18
42922- 30 30 30 38 38 38 46 46 46 54 54 54
42923- 50 50 50 42 42 42 30 30 30 18 18 18
42924- 10 10 10 0 0 0 0 0 0 0 0 0
42925- 0 0 0 0 0 0 0 0 0 0 0 0
42926- 0 0 0 0 0 0 0 0 0 0 0 0
42927- 0 0 0 0 0 0 0 0 0 0 0 0
42928- 0 0 0 6 6 6 14 14 14 26 26 26
42929- 38 38 38 50 50 50 58 58 58 58 58 58
42930- 54 54 54 42 42 42 30 30 30 18 18 18
42931- 10 10 10 0 0 0 0 0 0 0 0 0
42932- 0 0 0 0 0 0 0 0 0 0 0 0
42933- 0 0 0 0 0 0 0 0 0 0 0 0
42934- 0 0 0 0 0 0 0 0 0 0 0 0
42935- 0 0 0 0 0 0 0 0 0 0 0 0
42936- 0 0 0 0 0 0 0 0 0 0 0 0
42937- 0 0 0 0 0 0 0 0 0 0 0 0
42938- 0 0 0 0 0 0 0 0 0 0 0 0
42939- 0 0 0 0 0 0 0 0 0 0 0 0
42940- 0 0 0 0 0 0 0 0 0 0 0 0
42941- 0 0 0 0 0 0 0 0 0 6 6 6
42942- 6 6 6 10 10 10 14 14 14 18 18 18
42943- 18 18 18 14 14 14 10 10 10 6 6 6
42944- 0 0 0 0 0 0 0 0 0 0 0 0
42945- 0 0 0 0 0 0 0 0 0 0 0 0
42946- 0 0 0 0 0 0 0 0 0 0 0 0
42947- 0 0 0 0 0 0 0 0 0 0 0 0
42948- 0 0 0 0 0 0 0 0 0 6 6 6
42949- 14 14 14 18 18 18 22 22 22 22 22 22
42950- 18 18 18 14 14 14 10 10 10 6 6 6
42951- 0 0 0 0 0 0 0 0 0 0 0 0
42952- 0 0 0 0 0 0 0 0 0 0 0 0
42953- 0 0 0 0 0 0 0 0 0 0 0 0
42954- 0 0 0 0 0 0 0 0 0 0 0 0
42955- 0 0 0 0 0 0 0 0 0 0 0 0
42956+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42957+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42958+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42959+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42960+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42961+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42962+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42963+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42964+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42965+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42966+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42967+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42968+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42969+4 4 4 4 4 4
42970+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42971+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42972+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42973+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42974+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42975+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42976+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42977+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42978+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42979+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42980+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42981+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42982+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42983+4 4 4 4 4 4
42984+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42985+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42986+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42987+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42988+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42989+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42990+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42991+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42992+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42993+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42994+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42995+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42996+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42997+4 4 4 4 4 4
42998+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42999+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43000+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43001+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43002+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43003+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43004+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43005+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43006+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43007+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43008+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43009+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43010+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43011+4 4 4 4 4 4
43012+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43013+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43014+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43015+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43016+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43017+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43018+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43019+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43020+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43021+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43022+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43023+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43024+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43025+4 4 4 4 4 4
43026+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43027+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43028+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43029+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43030+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43031+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43032+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43033+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43034+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43035+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43036+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43037+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43038+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43039+4 4 4 4 4 4
43040+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43041+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43042+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43043+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43044+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
43045+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
43046+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43047+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43048+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43049+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
43050+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
43051+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
43052+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43053+4 4 4 4 4 4
43054+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43055+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43056+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43057+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43058+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
43059+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
43060+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43061+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43062+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43063+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
43064+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
43065+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
43066+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43067+4 4 4 4 4 4
43068+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43069+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43070+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43071+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43072+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
43073+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
43074+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
43075+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43076+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43077+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
43078+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
43079+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
43080+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
43081+4 4 4 4 4 4
43082+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43083+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43084+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43085+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
43086+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
43087+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
43088+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
43089+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43090+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
43091+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
43092+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
43093+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
43094+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
43095+4 4 4 4 4 4
43096+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
43099+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
43100+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
43101+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
43102+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
43103+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
43104+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
43105+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
43106+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
43107+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
43108+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
43109+4 4 4 4 4 4
43110+4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 5 5 5
43113+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
43114+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
43115+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
43116+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
43117+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
43118+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
43119+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
43120+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
43121+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
43122+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
43123+4 4 4 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 4 4 4 4 4 4 5 5 5 3 3 3
43127+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
43128+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
43129+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
43130+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
43131+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
43132+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
43133+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
43134+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
43135+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
43136+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
43137+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 4 4 4 2 2 2 0 0 0 4 0 0
43141+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
43142+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
43143+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
43144+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
43145+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
43146+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
43147+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
43148+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
43149+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
43150+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
43151+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 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
43155+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
43156+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
43157+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
43158+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
43159+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
43160+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
43161+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
43162+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
43163+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
43164+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
43165+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+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
43169+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
43170+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
43171+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
43172+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
43173+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
43174+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
43175+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
43176+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
43177+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
43178+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
43179+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 3 3 3 0 0 0
43182+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
43183+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
43184+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
43185+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
43186+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
43187+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
43188+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
43189+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
43190+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
43191+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
43192+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
43193+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 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
43196+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
43197+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
43198+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
43199+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
43200+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
43201+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
43202+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
43203+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
43204+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
43205+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
43206+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
43207+0 0 0 4 4 4
43208+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
43209+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
43210+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
43211+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
43212+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
43213+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
43214+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
43215+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
43216+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
43217+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
43218+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
43219+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
43220+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
43221+2 0 0 0 0 0
43222+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
43223+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
43224+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
43225+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
43226+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
43227+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
43228+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
43229+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
43230+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
43231+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
43232+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
43233+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
43234+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
43235+37 38 37 0 0 0
43236+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
43237+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
43238+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
43239+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
43240+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
43241+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
43242+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
43243+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
43244+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
43245+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
43246+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
43247+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
43248+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
43249+85 115 134 4 0 0
43250+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
43251+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
43252+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
43253+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
43254+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
43255+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
43256+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
43257+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
43258+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
43259+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
43260+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
43261+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
43262+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
43263+60 73 81 4 0 0
43264+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
43265+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
43266+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
43267+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
43268+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
43269+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
43270+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
43271+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
43272+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
43273+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
43274+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
43275+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
43276+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
43277+16 19 21 4 0 0
43278+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
43279+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
43280+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
43281+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
43282+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
43283+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
43284+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
43285+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
43286+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
43287+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
43288+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
43289+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
43290+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
43291+4 0 0 4 3 3
43292+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
43293+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
43294+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
43295+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
43296+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
43297+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
43298+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
43299+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
43300+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
43301+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
43302+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
43303+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
43304+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
43305+3 2 2 4 4 4
43306+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
43307+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
43308+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
43309+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
43310+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
43311+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
43312+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
43313+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
43314+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
43315+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
43316+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
43317+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
43318+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
43319+4 4 4 4 4 4
43320+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
43321+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
43322+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
43323+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
43324+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
43325+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
43326+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
43327+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
43328+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
43329+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
43330+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
43331+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
43332+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
43333+4 4 4 4 4 4
43334+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
43335+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
43336+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
43337+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
43338+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
43339+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
43340+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
43341+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
43342+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
43343+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
43344+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
43345+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
43346+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
43347+5 5 5 5 5 5
43348+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
43349+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
43350+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
43351+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
43352+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
43353+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
43354+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
43355+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
43356+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
43357+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
43358+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
43359+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
43360+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
43361+5 5 5 4 4 4
43362+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
43363+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
43364+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
43365+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
43366+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
43367+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
43368+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
43369+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
43370+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
43371+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
43372+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
43373+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
43374+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43375+4 4 4 4 4 4
43376+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
43377+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
43378+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
43379+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
43380+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
43381+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
43382+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
43383+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
43384+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
43385+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
43386+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
43387+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
43388+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43389+4 4 4 4 4 4
43390+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
43391+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
43392+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
43393+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
43394+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
43395+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
43396+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
43397+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
43398+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
43399+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
43400+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
43401+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43402+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43403+4 4 4 4 4 4
43404+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
43405+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
43406+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
43407+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
43408+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
43409+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
43410+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
43411+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
43412+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
43413+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
43414+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
43415+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43416+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43417+4 4 4 4 4 4
43418+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
43419+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
43420+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
43421+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
43422+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
43423+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
43424+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
43425+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
43426+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
43427+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
43428+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43429+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43430+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43431+4 4 4 4 4 4
43432+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
43433+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
43434+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
43435+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
43436+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
43437+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
43438+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
43439+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
43440+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
43441+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
43442+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
43443+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43444+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43445+4 4 4 4 4 4
43446+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
43447+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
43448+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
43449+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
43450+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
43451+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
43452+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
43453+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
43454+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
43455+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
43456+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
43457+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43458+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43459+4 4 4 4 4 4
43460+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
43461+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
43462+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
43463+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
43464+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
43465+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
43466+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
43467+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
43468+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
43469+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
43470+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43471+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43472+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43473+4 4 4 4 4 4
43474+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
43475+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
43476+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
43477+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
43478+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
43479+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
43480+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
43481+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
43482+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
43483+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
43484+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43485+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43486+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43487+4 4 4 4 4 4
43488+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
43489+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
43490+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
43491+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
43492+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
43493+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
43494+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
43495+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
43496+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
43497+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
43498+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43499+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43500+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43501+4 4 4 4 4 4
43502+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
43503+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
43504+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
43505+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
43506+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
43507+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
43508+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
43509+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
43510+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
43511+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43512+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43513+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43514+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43515+4 4 4 4 4 4
43516+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
43517+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
43518+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
43519+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
43520+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
43521+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
43522+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
43523+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
43524+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
43525+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43526+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43527+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43528+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43529+4 4 4 4 4 4
43530+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
43531+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
43532+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
43533+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
43534+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
43535+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
43536+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
43537+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
43538+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
43539+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43540+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43541+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43542+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43543+4 4 4 4 4 4
43544+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
43545+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
43546+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
43547+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
43548+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
43549+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
43550+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
43551+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
43552+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
43553+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43554+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43555+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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
43558+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
43559+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
43560+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
43561+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
43562+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
43563+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
43564+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
43565+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
43566+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
43567+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43568+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43569+4 4 4 4 4 4 4 4 4 4 4 4 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
43572+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
43573+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
43574+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
43575+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
43576+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
43577+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
43578+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
43579+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
43580+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
43581+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43582+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43583+4 4 4 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
43586+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
43587+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
43588+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
43589+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
43590+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
43591+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
43592+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
43593+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
43594+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
43595+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43596+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
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
43600+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
43601+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
43602+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
43603+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
43604+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
43605+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
43606+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
43607+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
43608+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
43609+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43610+0 0 0 3 3 3 5 5 5 4 4 4 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
43614+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
43615+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
43616+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
43617+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
43618+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
43619+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
43620+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
43621+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
43622+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
43623+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43624+0 0 0 3 3 3 5 5 5 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
43628+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
43629+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
43630+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
43631+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
43632+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
43633+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
43634+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
43635+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
43636+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
43637+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43638+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43639+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43640+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43641+4 4 4 4 4 4
43642+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
43643+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
43644+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
43645+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
43646+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
43647+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
43648+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
43649+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
43650+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
43651+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43652+0 0 0 3 3 3 5 5 5 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
43656+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
43657+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
43658+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
43659+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
43660+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
43661+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
43662+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
43663+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
43664+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
43665+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43666+0 0 0 3 3 3 5 5 5 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
43670+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
43671+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
43672+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
43673+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
43674+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
43675+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
43676+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
43677+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
43678+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
43679+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43680+0 0 0 3 3 3 5 5 5 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
43684+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
43685+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
43686+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
43687+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
43688+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
43689+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
43690+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
43691+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
43692+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
43693+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43694+0 0 0 3 3 3 5 5 5 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
43698+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
43699+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
43700+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
43701+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
43702+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
43703+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
43704+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
43705+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
43706+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
43707+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43708+0 0 0 3 3 3 5 5 5 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
43712+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
43713+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
43714+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
43715+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
43716+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
43717+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
43718+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
43719+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
43720+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
43721+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
43722+0 0 0 3 3 3 5 5 5 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
43726+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
43727+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
43728+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
43729+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
43730+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
43731+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
43732+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
43733+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
43734+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
43735+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
43736+0 0 0 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
43740+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
43741+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
43742+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
43743+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
43744+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
43745+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
43746+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43747+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
43748+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
43749+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
43750+4 3 3 5 5 5 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
43754+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
43755+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
43756+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
43757+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
43758+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
43759+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
43760+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
43761+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
43762+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
43763+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
43764+5 5 5 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
43768+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
43769+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
43770+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
43771+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
43772+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
43773+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
43774+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
43775+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
43776+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
43777+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
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
43782+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
43783+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
43784+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
43785+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
43786+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
43787+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
43788+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
43789+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
43790+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
43791+13 16 17 4 0 0 4 0 0 4 3 3 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
43796+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
43797+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
43798+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
43799+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
43800+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
43801+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
43802+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
43803+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
43804+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
43805+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
43806+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43807+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43808+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43809+4 4 4 4 4 4
43810+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
43811+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
43812+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
43813+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
43814+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
43815+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
43816+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
43817+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
43818+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
43819+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
43820+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43821+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43822+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43823+4 4 4 4 4 4
43824+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
43825+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
43826+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
43827+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
43828+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
43829+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
43830+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
43831+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
43832+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
43833+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43834+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43835+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43836+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43837+4 4 4 4 4 4
43838+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
43839+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
43840+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
43841+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
43842+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
43843+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
43844+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
43845+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
43846+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
43847+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43848+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43849+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43850+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43851+4 4 4 4 4 4
43852+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
43853+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
43854+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
43855+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
43856+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
43857+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
43858+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
43859+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
43860+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43861+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43862+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43863+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43864+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43865+4 4 4 4 4 4
43866+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
43867+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
43868+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
43869+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
43870+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
43871+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
43872+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
43873+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
43874+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43875+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43876+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43877+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43878+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43879+4 4 4 4 4 4
43880+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
43881+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
43882+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
43883+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
43884+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
43885+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
43886+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
43887+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
43888+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43889+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43890+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43891+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43892+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43893+4 4 4 4 4 4
43894+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
43895+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
43896+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
43897+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
43898+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
43899+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
43900+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
43901+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
43902+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43903+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43904+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43905+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43906+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43907+4 4 4 4 4 4
43908+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43909+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
43910+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
43911+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
43912+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
43913+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
43914+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
43915+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
43916+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43917+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43918+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43919+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43920+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43921+4 4 4 4 4 4
43922+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43923+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
43924+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
43925+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
43926+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
43927+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
43928+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
43929+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
43930+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43931+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43932+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43933+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43934+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43935+4 4 4 4 4 4
43936+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43937+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43938+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
43939+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
43940+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
43941+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
43942+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
43943+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
43944+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43945+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43946+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43947+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43948+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43949+4 4 4 4 4 4
43950+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43951+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43952+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
43953+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
43954+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
43955+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
43956+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
43957+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43958+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43959+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43960+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43961+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43962+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43963+4 4 4 4 4 4
43964+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43965+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43966+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43967+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
43968+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
43969+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
43970+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
43971+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43972+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43973+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43974+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43975+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43976+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43977+4 4 4 4 4 4
43978+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43979+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43980+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43981+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
43982+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
43983+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
43984+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
43985+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43986+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43987+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43988+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43989+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43990+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43991+4 4 4 4 4 4
43992+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43993+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43994+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43995+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
43996+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
43997+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
43998+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
43999+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44000+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44001+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44002+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44003+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44004+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44005+4 4 4 4 4 4
44006+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44007+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44008+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44009+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
44010+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
44011+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
44012+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44013+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44014+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44015+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44016+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44017+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44018+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44019+4 4 4 4 4 4
44020+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44021+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44022+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44023+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44024+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
44025+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
44026+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
44027+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44028+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44029+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44030+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44031+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44032+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44033+4 4 4 4 4 4
44034+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44035+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44036+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44037+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44038+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
44039+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
44040+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44041+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44042+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44043+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44044+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44045+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44046+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44047+4 4 4 4 4 4
44048+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44049+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44050+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44051+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44052+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
44053+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
44054+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44055+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44056+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44057+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44058+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44059+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44060+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44061+4 4 4 4 4 4
44062+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44063+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44064+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44065+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44066+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
44067+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
44068+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44069+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44070+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44071+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44072+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44073+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44074+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44075+4 4 4 4 4 4
44076diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
44077index 86d449e..af6a7f7 100644
44078--- a/drivers/video/udlfb.c
44079+++ b/drivers/video/udlfb.c
44080@@ -619,11 +619,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
44081 dlfb_urb_completion(urb);
44082
44083 error:
44084- atomic_add(bytes_sent, &dev->bytes_sent);
44085- atomic_add(bytes_identical, &dev->bytes_identical);
44086- atomic_add(width*height*2, &dev->bytes_rendered);
44087+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
44088+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
44089+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
44090 end_cycles = get_cycles();
44091- atomic_add(((unsigned int) ((end_cycles - start_cycles)
44092+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
44093 >> 10)), /* Kcycles */
44094 &dev->cpu_kcycles_used);
44095
44096@@ -744,11 +744,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
44097 dlfb_urb_completion(urb);
44098
44099 error:
44100- atomic_add(bytes_sent, &dev->bytes_sent);
44101- atomic_add(bytes_identical, &dev->bytes_identical);
44102- atomic_add(bytes_rendered, &dev->bytes_rendered);
44103+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
44104+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
44105+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
44106 end_cycles = get_cycles();
44107- atomic_add(((unsigned int) ((end_cycles - start_cycles)
44108+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
44109 >> 10)), /* Kcycles */
44110 &dev->cpu_kcycles_used);
44111 }
44112@@ -1372,7 +1372,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
44113 struct fb_info *fb_info = dev_get_drvdata(fbdev);
44114 struct dlfb_data *dev = fb_info->par;
44115 return snprintf(buf, PAGE_SIZE, "%u\n",
44116- atomic_read(&dev->bytes_rendered));
44117+ atomic_read_unchecked(&dev->bytes_rendered));
44118 }
44119
44120 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
44121@@ -1380,7 +1380,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
44122 struct fb_info *fb_info = dev_get_drvdata(fbdev);
44123 struct dlfb_data *dev = fb_info->par;
44124 return snprintf(buf, PAGE_SIZE, "%u\n",
44125- atomic_read(&dev->bytes_identical));
44126+ atomic_read_unchecked(&dev->bytes_identical));
44127 }
44128
44129 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
44130@@ -1388,7 +1388,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
44131 struct fb_info *fb_info = dev_get_drvdata(fbdev);
44132 struct dlfb_data *dev = fb_info->par;
44133 return snprintf(buf, PAGE_SIZE, "%u\n",
44134- atomic_read(&dev->bytes_sent));
44135+ atomic_read_unchecked(&dev->bytes_sent));
44136 }
44137
44138 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
44139@@ -1396,7 +1396,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
44140 struct fb_info *fb_info = dev_get_drvdata(fbdev);
44141 struct dlfb_data *dev = fb_info->par;
44142 return snprintf(buf, PAGE_SIZE, "%u\n",
44143- atomic_read(&dev->cpu_kcycles_used));
44144+ atomic_read_unchecked(&dev->cpu_kcycles_used));
44145 }
44146
44147 static ssize_t edid_show(
44148@@ -1456,10 +1456,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
44149 struct fb_info *fb_info = dev_get_drvdata(fbdev);
44150 struct dlfb_data *dev = fb_info->par;
44151
44152- atomic_set(&dev->bytes_rendered, 0);
44153- atomic_set(&dev->bytes_identical, 0);
44154- atomic_set(&dev->bytes_sent, 0);
44155- atomic_set(&dev->cpu_kcycles_used, 0);
44156+ atomic_set_unchecked(&dev->bytes_rendered, 0);
44157+ atomic_set_unchecked(&dev->bytes_identical, 0);
44158+ atomic_set_unchecked(&dev->bytes_sent, 0);
44159+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
44160
44161 return count;
44162 }
44163diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
44164index 2f8f82d..191de37 100644
44165--- a/drivers/video/uvesafb.c
44166+++ b/drivers/video/uvesafb.c
44167@@ -19,6 +19,7 @@
44168 #include <linux/io.h>
44169 #include <linux/mutex.h>
44170 #include <linux/slab.h>
44171+#include <linux/moduleloader.h>
44172 #include <video/edid.h>
44173 #include <video/uvesafb.h>
44174 #ifdef CONFIG_X86
44175@@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
44176 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
44177 par->pmi_setpal = par->ypan = 0;
44178 } else {
44179+
44180+#ifdef CONFIG_PAX_KERNEXEC
44181+#ifdef CONFIG_MODULES
44182+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
44183+#endif
44184+ if (!par->pmi_code) {
44185+ par->pmi_setpal = par->ypan = 0;
44186+ return 0;
44187+ }
44188+#endif
44189+
44190 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
44191 + task->t.regs.edi);
44192+
44193+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
44194+ pax_open_kernel();
44195+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
44196+ pax_close_kernel();
44197+
44198+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
44199+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
44200+#else
44201 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
44202 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
44203+#endif
44204+
44205 printk(KERN_INFO "uvesafb: protected mode interface info at "
44206 "%04x:%04x\n",
44207 (u16)task->t.regs.es, (u16)task->t.regs.edi);
44208@@ -818,13 +841,14 @@ static int __devinit uvesafb_vbe_init(struct fb_info *info)
44209 par->ypan = ypan;
44210
44211 if (par->pmi_setpal || par->ypan) {
44212+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
44213 if (__supported_pte_mask & _PAGE_NX) {
44214 par->pmi_setpal = par->ypan = 0;
44215 printk(KERN_WARNING "uvesafb: NX protection is actively."
44216 "We have better not to use the PMI.\n");
44217- } else {
44218+ } else
44219+#endif
44220 uvesafb_vbe_getpmi(task, par);
44221- }
44222 }
44223 #else
44224 /* The protected mode interface is not available on non-x86. */
44225@@ -1838,6 +1862,11 @@ out:
44226 if (par->vbe_modes)
44227 kfree(par->vbe_modes);
44228
44229+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
44230+ if (par->pmi_code)
44231+ module_free_exec(NULL, par->pmi_code);
44232+#endif
44233+
44234 framebuffer_release(info);
44235 return err;
44236 }
44237@@ -1864,6 +1893,12 @@ static int uvesafb_remove(struct platform_device *dev)
44238 kfree(par->vbe_state_orig);
44239 if (par->vbe_state_saved)
44240 kfree(par->vbe_state_saved);
44241+
44242+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
44243+ if (par->pmi_code)
44244+ module_free_exec(NULL, par->pmi_code);
44245+#endif
44246+
44247 }
44248
44249 framebuffer_release(info);
44250diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
44251index 501b340..86bd4cf 100644
44252--- a/drivers/video/vesafb.c
44253+++ b/drivers/video/vesafb.c
44254@@ -9,6 +9,7 @@
44255 */
44256
44257 #include <linux/module.h>
44258+#include <linux/moduleloader.h>
44259 #include <linux/kernel.h>
44260 #include <linux/errno.h>
44261 #include <linux/string.h>
44262@@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
44263 static int vram_total __initdata; /* Set total amount of memory */
44264 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
44265 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
44266-static void (*pmi_start)(void) __read_mostly;
44267-static void (*pmi_pal) (void) __read_mostly;
44268+static void (*pmi_start)(void) __read_only;
44269+static void (*pmi_pal) (void) __read_only;
44270 static int depth __read_mostly;
44271 static int vga_compat __read_mostly;
44272 /* --------------------------------------------------------------------- */
44273@@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
44274 unsigned int size_vmode;
44275 unsigned int size_remap;
44276 unsigned int size_total;
44277+ void *pmi_code = NULL;
44278
44279 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
44280 return -ENODEV;
44281@@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
44282 size_remap = size_total;
44283 vesafb_fix.smem_len = size_remap;
44284
44285-#ifndef __i386__
44286- screen_info.vesapm_seg = 0;
44287-#endif
44288-
44289 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
44290 printk(KERN_WARNING
44291 "vesafb: cannot reserve video memory at 0x%lx\n",
44292@@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
44293 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
44294 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
44295
44296+#ifdef __i386__
44297+
44298+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
44299+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
44300+ if (!pmi_code)
44301+#elif !defined(CONFIG_PAX_KERNEXEC)
44302+ if (0)
44303+#endif
44304+
44305+#endif
44306+ screen_info.vesapm_seg = 0;
44307+
44308 if (screen_info.vesapm_seg) {
44309- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
44310- screen_info.vesapm_seg,screen_info.vesapm_off);
44311+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
44312+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
44313 }
44314
44315 if (screen_info.vesapm_seg < 0xc000)
44316@@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
44317
44318 if (ypan || pmi_setpal) {
44319 unsigned short *pmi_base;
44320+
44321 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
44322- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
44323- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
44324+
44325+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
44326+ pax_open_kernel();
44327+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
44328+#else
44329+ pmi_code = pmi_base;
44330+#endif
44331+
44332+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
44333+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
44334+
44335+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
44336+ pmi_start = ktva_ktla(pmi_start);
44337+ pmi_pal = ktva_ktla(pmi_pal);
44338+ pax_close_kernel();
44339+#endif
44340+
44341 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
44342 if (pmi_base[3]) {
44343 printk(KERN_INFO "vesafb: pmi: ports = ");
44344@@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
44345 info->node, info->fix.id);
44346 return 0;
44347 err:
44348+
44349+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
44350+ module_free_exec(NULL, pmi_code);
44351+#endif
44352+
44353 if (info->screen_base)
44354 iounmap(info->screen_base);
44355 framebuffer_release(info);
44356diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
44357index 88714ae..16c2e11 100644
44358--- a/drivers/video/via/via_clock.h
44359+++ b/drivers/video/via/via_clock.h
44360@@ -56,7 +56,7 @@ struct via_clock {
44361
44362 void (*set_engine_pll_state)(u8 state);
44363 void (*set_engine_pll)(struct via_pll_config config);
44364-};
44365+} __no_const;
44366
44367
44368 static inline u32 get_pll_internal_frequency(u32 ref_freq,
44369diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
44370index 6b1b7e1..b2fa4d5 100644
44371--- a/drivers/virtio/virtio_mmio.c
44372+++ b/drivers/virtio/virtio_mmio.c
44373@@ -530,7 +530,7 @@ static int vm_cmdline_set(const char *device,
44374
44375 resources[0].end = memparse(device, &str) - 1;
44376
44377- processed = sscanf(str, "@%lli:%u%n:%d%n",
44378+ processed = sscanf(str, "@%lli:%llu%n:%d%n",
44379 &base, &resources[1].start, &consumed,
44380 &vm_cmdline_id, &consumed);
44381
44382diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
44383index fef20db..d28b1ab 100644
44384--- a/drivers/xen/xenfs/xenstored.c
44385+++ b/drivers/xen/xenfs/xenstored.c
44386@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
44387 static int xsd_kva_open(struct inode *inode, struct file *file)
44388 {
44389 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
44390+#ifdef CONFIG_GRKERNSEC_HIDESYM
44391+ NULL);
44392+#else
44393 xen_store_interface);
44394+#endif
44395+
44396 if (!file->private_data)
44397 return -ENOMEM;
44398 return 0;
44399diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
44400index 890bed5..17ae73e 100644
44401--- a/fs/9p/vfs_inode.c
44402+++ b/fs/9p/vfs_inode.c
44403@@ -1329,7 +1329,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
44404 void
44405 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
44406 {
44407- char *s = nd_get_link(nd);
44408+ const char *s = nd_get_link(nd);
44409
44410 p9_debug(P9_DEBUG_VFS, " %s %s\n",
44411 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
44412diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
44413index 0efd152..b5802ad 100644
44414--- a/fs/Kconfig.binfmt
44415+++ b/fs/Kconfig.binfmt
44416@@ -89,7 +89,7 @@ config HAVE_AOUT
44417
44418 config BINFMT_AOUT
44419 tristate "Kernel support for a.out and ECOFF binaries"
44420- depends on HAVE_AOUT
44421+ depends on HAVE_AOUT && BROKEN
44422 ---help---
44423 A.out (Assembler.OUTput) is a set of formats for libraries and
44424 executables used in the earliest versions of UNIX. Linux used
44425diff --git a/fs/aio.c b/fs/aio.c
44426index 71f613c..9d01f1f 100644
44427--- a/fs/aio.c
44428+++ b/fs/aio.c
44429@@ -111,7 +111,7 @@ static int aio_setup_ring(struct kioctx *ctx)
44430 size += sizeof(struct io_event) * nr_events;
44431 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
44432
44433- if (nr_pages < 0)
44434+ if (nr_pages <= 0)
44435 return -EINVAL;
44436
44437 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
44438@@ -1373,18 +1373,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
44439 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
44440 {
44441 ssize_t ret;
44442+ struct iovec iovstack;
44443
44444 #ifdef CONFIG_COMPAT
44445 if (compat)
44446 ret = compat_rw_copy_check_uvector(type,
44447 (struct compat_iovec __user *)kiocb->ki_buf,
44448- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
44449+ kiocb->ki_nbytes, 1, &iovstack,
44450 &kiocb->ki_iovec);
44451 else
44452 #endif
44453 ret = rw_copy_check_uvector(type,
44454 (struct iovec __user *)kiocb->ki_buf,
44455- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
44456+ kiocb->ki_nbytes, 1, &iovstack,
44457 &kiocb->ki_iovec);
44458 if (ret < 0)
44459 goto out;
44460@@ -1393,6 +1394,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
44461 if (ret < 0)
44462 goto out;
44463
44464+ if (kiocb->ki_iovec == &iovstack) {
44465+ kiocb->ki_inline_vec = iovstack;
44466+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
44467+ }
44468 kiocb->ki_nr_segs = kiocb->ki_nbytes;
44469 kiocb->ki_cur_seg = 0;
44470 /* ki_nbytes/left now reflect bytes instead of segs */
44471diff --git a/fs/attr.c b/fs/attr.c
44472index cce7df5..eaa2731 100644
44473--- a/fs/attr.c
44474+++ b/fs/attr.c
44475@@ -100,6 +100,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
44476 unsigned long limit;
44477
44478 limit = rlimit(RLIMIT_FSIZE);
44479+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
44480 if (limit != RLIM_INFINITY && offset > limit)
44481 goto out_sig;
44482 if (offset > inode->i_sb->s_maxbytes)
44483diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
44484index dce436e..55e670d 100644
44485--- a/fs/autofs4/waitq.c
44486+++ b/fs/autofs4/waitq.c
44487@@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
44488 {
44489 unsigned long sigpipe, flags;
44490 mm_segment_t fs;
44491- const char *data = (const char *)addr;
44492+ const char __user *data = (const char __force_user *)addr;
44493 ssize_t wr = 0;
44494
44495 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
44496@@ -347,6 +347,10 @@ static int validate_request(struct autofs_wait_queue **wait,
44497 return 1;
44498 }
44499
44500+#ifdef CONFIG_GRKERNSEC_HIDESYM
44501+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
44502+#endif
44503+
44504 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
44505 enum autofs_notify notify)
44506 {
44507@@ -380,7 +384,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
44508
44509 /* If this is a direct mount request create a dummy name */
44510 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
44511+#ifdef CONFIG_GRKERNSEC_HIDESYM
44512+ /* this name does get written to userland via autofs4_write() */
44513+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
44514+#else
44515 qstr.len = sprintf(name, "%p", dentry);
44516+#endif
44517 else {
44518 qstr.len = autofs4_getpath(sbi, dentry, &name);
44519 if (!qstr.len) {
44520diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
44521index 2b3bda8..6a2d4be 100644
44522--- a/fs/befs/linuxvfs.c
44523+++ b/fs/befs/linuxvfs.c
44524@@ -510,7 +510,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
44525 {
44526 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
44527 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
44528- char *link = nd_get_link(nd);
44529+ const char *link = nd_get_link(nd);
44530 if (!IS_ERR(link))
44531 kfree(link);
44532 }
44533diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
44534index 0e7a6f8..332b1ca 100644
44535--- a/fs/binfmt_aout.c
44536+++ b/fs/binfmt_aout.c
44537@@ -16,6 +16,7 @@
44538 #include <linux/string.h>
44539 #include <linux/fs.h>
44540 #include <linux/file.h>
44541+#include <linux/security.h>
44542 #include <linux/stat.h>
44543 #include <linux/fcntl.h>
44544 #include <linux/ptrace.h>
44545@@ -59,6 +60,8 @@ static int aout_core_dump(struct coredump_params *cprm)
44546 #endif
44547 # define START_STACK(u) ((void __user *)u.start_stack)
44548
44549+ memset(&dump, 0, sizeof(dump));
44550+
44551 fs = get_fs();
44552 set_fs(KERNEL_DS);
44553 has_dumped = 1;
44554@@ -70,10 +73,12 @@ static int aout_core_dump(struct coredump_params *cprm)
44555
44556 /* If the size of the dump file exceeds the rlimit, then see what would happen
44557 if we wrote the stack, but not the data area. */
44558+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
44559 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
44560 dump.u_dsize = 0;
44561
44562 /* Make sure we have enough room to write the stack and data areas. */
44563+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
44564 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
44565 dump.u_ssize = 0;
44566
44567@@ -233,6 +238,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
44568 rlim = rlimit(RLIMIT_DATA);
44569 if (rlim >= RLIM_INFINITY)
44570 rlim = ~0;
44571+
44572+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
44573 if (ex.a_data + ex.a_bss > rlim)
44574 return -ENOMEM;
44575
44576@@ -267,6 +274,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
44577
44578 install_exec_creds(bprm);
44579
44580+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
44581+ current->mm->pax_flags = 0UL;
44582+#endif
44583+
44584+#ifdef CONFIG_PAX_PAGEEXEC
44585+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
44586+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
44587+
44588+#ifdef CONFIG_PAX_EMUTRAMP
44589+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
44590+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
44591+#endif
44592+
44593+#ifdef CONFIG_PAX_MPROTECT
44594+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
44595+ current->mm->pax_flags |= MF_PAX_MPROTECT;
44596+#endif
44597+
44598+ }
44599+#endif
44600+
44601 if (N_MAGIC(ex) == OMAGIC) {
44602 unsigned long text_addr, map_size;
44603 loff_t pos;
44604@@ -332,7 +360,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
44605 }
44606
44607 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
44608- PROT_READ | PROT_WRITE | PROT_EXEC,
44609+ PROT_READ | PROT_WRITE,
44610 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
44611 fd_offset + ex.a_text);
44612 if (error != N_DATADDR(ex)) {
44613diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
44614index fbd9f60..0b845dd 100644
44615--- a/fs/binfmt_elf.c
44616+++ b/fs/binfmt_elf.c
44617@@ -33,6 +33,7 @@
44618 #include <linux/elf.h>
44619 #include <linux/utsname.h>
44620 #include <linux/coredump.h>
44621+#include <linux/xattr.h>
44622 #include <asm/uaccess.h>
44623 #include <asm/param.h>
44624 #include <asm/page.h>
44625@@ -59,6 +60,10 @@ static int elf_core_dump(struct coredump_params *cprm);
44626 #define elf_core_dump NULL
44627 #endif
44628
44629+#ifdef CONFIG_PAX_MPROTECT
44630+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
44631+#endif
44632+
44633 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
44634 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
44635 #else
44636@@ -78,6 +83,11 @@ static struct linux_binfmt elf_format = {
44637 .load_binary = load_elf_binary,
44638 .load_shlib = load_elf_library,
44639 .core_dump = elf_core_dump,
44640+
44641+#ifdef CONFIG_PAX_MPROTECT
44642+ .handle_mprotect= elf_handle_mprotect,
44643+#endif
44644+
44645 .min_coredump = ELF_EXEC_PAGESIZE,
44646 };
44647
44648@@ -85,6 +95,8 @@ static struct linux_binfmt elf_format = {
44649
44650 static int set_brk(unsigned long start, unsigned long end)
44651 {
44652+ unsigned long e = end;
44653+
44654 start = ELF_PAGEALIGN(start);
44655 end = ELF_PAGEALIGN(end);
44656 if (end > start) {
44657@@ -93,7 +105,7 @@ static int set_brk(unsigned long start, unsigned long end)
44658 if (BAD_ADDR(addr))
44659 return addr;
44660 }
44661- current->mm->start_brk = current->mm->brk = end;
44662+ current->mm->start_brk = current->mm->brk = e;
44663 return 0;
44664 }
44665
44666@@ -154,12 +166,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
44667 elf_addr_t __user *u_rand_bytes;
44668 const char *k_platform = ELF_PLATFORM;
44669 const char *k_base_platform = ELF_BASE_PLATFORM;
44670- unsigned char k_rand_bytes[16];
44671+ u32 k_rand_bytes[4];
44672 int items;
44673 elf_addr_t *elf_info;
44674 int ei_index = 0;
44675 const struct cred *cred = current_cred();
44676 struct vm_area_struct *vma;
44677+ unsigned long saved_auxv[AT_VECTOR_SIZE];
44678
44679 /*
44680 * In some cases (e.g. Hyper-Threading), we want to avoid L1
44681@@ -201,8 +214,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
44682 * Generate 16 random bytes for userspace PRNG seeding.
44683 */
44684 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
44685- u_rand_bytes = (elf_addr_t __user *)
44686- STACK_ALLOC(p, sizeof(k_rand_bytes));
44687+ srandom32(k_rand_bytes[0] ^ random32());
44688+ srandom32(k_rand_bytes[1] ^ random32());
44689+ srandom32(k_rand_bytes[2] ^ random32());
44690+ srandom32(k_rand_bytes[3] ^ random32());
44691+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
44692+ u_rand_bytes = (elf_addr_t __user *) p;
44693 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
44694 return -EFAULT;
44695
44696@@ -314,9 +331,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
44697 return -EFAULT;
44698 current->mm->env_end = p;
44699
44700+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
44701+
44702 /* Put the elf_info on the stack in the right place. */
44703 sp = (elf_addr_t __user *)envp + 1;
44704- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
44705+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
44706 return -EFAULT;
44707 return 0;
44708 }
44709@@ -380,15 +399,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
44710 an ELF header */
44711
44712 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
44713- struct file *interpreter, unsigned long *interp_map_addr,
44714- unsigned long no_base)
44715+ struct file *interpreter, unsigned long no_base)
44716 {
44717 struct elf_phdr *elf_phdata;
44718 struct elf_phdr *eppnt;
44719- unsigned long load_addr = 0;
44720+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
44721 int load_addr_set = 0;
44722 unsigned long last_bss = 0, elf_bss = 0;
44723- unsigned long error = ~0UL;
44724+ unsigned long error = -EINVAL;
44725 unsigned long total_size;
44726 int retval, i, size;
44727
44728@@ -434,6 +452,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
44729 goto out_close;
44730 }
44731
44732+#ifdef CONFIG_PAX_SEGMEXEC
44733+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
44734+ pax_task_size = SEGMEXEC_TASK_SIZE;
44735+#endif
44736+
44737 eppnt = elf_phdata;
44738 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
44739 if (eppnt->p_type == PT_LOAD) {
44740@@ -457,8 +480,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
44741 map_addr = elf_map(interpreter, load_addr + vaddr,
44742 eppnt, elf_prot, elf_type, total_size);
44743 total_size = 0;
44744- if (!*interp_map_addr)
44745- *interp_map_addr = map_addr;
44746 error = map_addr;
44747 if (BAD_ADDR(map_addr))
44748 goto out_close;
44749@@ -477,8 +498,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
44750 k = load_addr + eppnt->p_vaddr;
44751 if (BAD_ADDR(k) ||
44752 eppnt->p_filesz > eppnt->p_memsz ||
44753- eppnt->p_memsz > TASK_SIZE ||
44754- TASK_SIZE - eppnt->p_memsz < k) {
44755+ eppnt->p_memsz > pax_task_size ||
44756+ pax_task_size - eppnt->p_memsz < k) {
44757 error = -ENOMEM;
44758 goto out_close;
44759 }
44760@@ -530,6 +551,315 @@ out:
44761 return error;
44762 }
44763
44764+#ifdef CONFIG_PAX_PT_PAX_FLAGS
44765+#ifdef CONFIG_PAX_SOFTMODE
44766+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
44767+{
44768+ unsigned long pax_flags = 0UL;
44769+
44770+#ifdef CONFIG_PAX_PAGEEXEC
44771+ if (elf_phdata->p_flags & PF_PAGEEXEC)
44772+ pax_flags |= MF_PAX_PAGEEXEC;
44773+#endif
44774+
44775+#ifdef CONFIG_PAX_SEGMEXEC
44776+ if (elf_phdata->p_flags & PF_SEGMEXEC)
44777+ pax_flags |= MF_PAX_SEGMEXEC;
44778+#endif
44779+
44780+#ifdef CONFIG_PAX_EMUTRAMP
44781+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
44782+ pax_flags |= MF_PAX_EMUTRAMP;
44783+#endif
44784+
44785+#ifdef CONFIG_PAX_MPROTECT
44786+ if (elf_phdata->p_flags & PF_MPROTECT)
44787+ pax_flags |= MF_PAX_MPROTECT;
44788+#endif
44789+
44790+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
44791+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
44792+ pax_flags |= MF_PAX_RANDMMAP;
44793+#endif
44794+
44795+ return pax_flags;
44796+}
44797+#endif
44798+
44799+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
44800+{
44801+ unsigned long pax_flags = 0UL;
44802+
44803+#ifdef CONFIG_PAX_PAGEEXEC
44804+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
44805+ pax_flags |= MF_PAX_PAGEEXEC;
44806+#endif
44807+
44808+#ifdef CONFIG_PAX_SEGMEXEC
44809+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
44810+ pax_flags |= MF_PAX_SEGMEXEC;
44811+#endif
44812+
44813+#ifdef CONFIG_PAX_EMUTRAMP
44814+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
44815+ pax_flags |= MF_PAX_EMUTRAMP;
44816+#endif
44817+
44818+#ifdef CONFIG_PAX_MPROTECT
44819+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
44820+ pax_flags |= MF_PAX_MPROTECT;
44821+#endif
44822+
44823+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
44824+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
44825+ pax_flags |= MF_PAX_RANDMMAP;
44826+#endif
44827+
44828+ return pax_flags;
44829+}
44830+#endif
44831+
44832+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
44833+#ifdef CONFIG_PAX_SOFTMODE
44834+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
44835+{
44836+ unsigned long pax_flags = 0UL;
44837+
44838+#ifdef CONFIG_PAX_PAGEEXEC
44839+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
44840+ pax_flags |= MF_PAX_PAGEEXEC;
44841+#endif
44842+
44843+#ifdef CONFIG_PAX_SEGMEXEC
44844+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
44845+ pax_flags |= MF_PAX_SEGMEXEC;
44846+#endif
44847+
44848+#ifdef CONFIG_PAX_EMUTRAMP
44849+ if (pax_flags_softmode & MF_PAX_EMUTRAMP)
44850+ pax_flags |= MF_PAX_EMUTRAMP;
44851+#endif
44852+
44853+#ifdef CONFIG_PAX_MPROTECT
44854+ if (pax_flags_softmode & MF_PAX_MPROTECT)
44855+ pax_flags |= MF_PAX_MPROTECT;
44856+#endif
44857+
44858+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
44859+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
44860+ pax_flags |= MF_PAX_RANDMMAP;
44861+#endif
44862+
44863+ return pax_flags;
44864+}
44865+#endif
44866+
44867+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
44868+{
44869+ unsigned long pax_flags = 0UL;
44870+
44871+#ifdef CONFIG_PAX_PAGEEXEC
44872+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
44873+ pax_flags |= MF_PAX_PAGEEXEC;
44874+#endif
44875+
44876+#ifdef CONFIG_PAX_SEGMEXEC
44877+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
44878+ pax_flags |= MF_PAX_SEGMEXEC;
44879+#endif
44880+
44881+#ifdef CONFIG_PAX_EMUTRAMP
44882+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
44883+ pax_flags |= MF_PAX_EMUTRAMP;
44884+#endif
44885+
44886+#ifdef CONFIG_PAX_MPROTECT
44887+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
44888+ pax_flags |= MF_PAX_MPROTECT;
44889+#endif
44890+
44891+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
44892+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
44893+ pax_flags |= MF_PAX_RANDMMAP;
44894+#endif
44895+
44896+ return pax_flags;
44897+}
44898+#endif
44899+
44900+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
44901+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
44902+{
44903+ unsigned long pax_flags = 0UL;
44904+
44905+#ifdef CONFIG_PAX_EI_PAX
44906+
44907+#ifdef CONFIG_PAX_PAGEEXEC
44908+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
44909+ pax_flags |= MF_PAX_PAGEEXEC;
44910+#endif
44911+
44912+#ifdef CONFIG_PAX_SEGMEXEC
44913+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
44914+ pax_flags |= MF_PAX_SEGMEXEC;
44915+#endif
44916+
44917+#ifdef CONFIG_PAX_EMUTRAMP
44918+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
44919+ pax_flags |= MF_PAX_EMUTRAMP;
44920+#endif
44921+
44922+#ifdef CONFIG_PAX_MPROTECT
44923+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
44924+ pax_flags |= MF_PAX_MPROTECT;
44925+#endif
44926+
44927+#ifdef CONFIG_PAX_ASLR
44928+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
44929+ pax_flags |= MF_PAX_RANDMMAP;
44930+#endif
44931+
44932+#else
44933+
44934+#ifdef CONFIG_PAX_PAGEEXEC
44935+ pax_flags |= MF_PAX_PAGEEXEC;
44936+#endif
44937+
44938+#ifdef CONFIG_PAX_SEGMEXEC
44939+ pax_flags |= MF_PAX_SEGMEXEC;
44940+#endif
44941+
44942+#ifdef CONFIG_PAX_MPROTECT
44943+ pax_flags |= MF_PAX_MPROTECT;
44944+#endif
44945+
44946+#ifdef CONFIG_PAX_RANDMMAP
44947+ if (randomize_va_space)
44948+ pax_flags |= MF_PAX_RANDMMAP;
44949+#endif
44950+
44951+#endif
44952+
44953+ return pax_flags;
44954+}
44955+
44956+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
44957+{
44958+
44959+#ifdef CONFIG_PAX_PT_PAX_FLAGS
44960+ unsigned long i;
44961+
44962+ for (i = 0UL; i < elf_ex->e_phnum; i++)
44963+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
44964+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
44965+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
44966+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
44967+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
44968+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
44969+ return ~0UL;
44970+
44971+#ifdef CONFIG_PAX_SOFTMODE
44972+ if (pax_softmode)
44973+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
44974+ else
44975+#endif
44976+
44977+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
44978+ break;
44979+ }
44980+#endif
44981+
44982+ return ~0UL;
44983+}
44984+
44985+static unsigned long pax_parse_xattr_pax(struct file * const file)
44986+{
44987+
44988+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
44989+ ssize_t xattr_size, i;
44990+ unsigned char xattr_value[5];
44991+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
44992+
44993+ xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
44994+ if (xattr_size <= 0 || xattr_size > 5)
44995+ return ~0UL;
44996+
44997+ for (i = 0; i < xattr_size; i++)
44998+ switch (xattr_value[i]) {
44999+ default:
45000+ return ~0UL;
45001+
45002+#define parse_flag(option1, option2, flag) \
45003+ case option1: \
45004+ if (pax_flags_hardmode & MF_PAX_##flag) \
45005+ return ~0UL; \
45006+ pax_flags_hardmode |= MF_PAX_##flag; \
45007+ break; \
45008+ case option2: \
45009+ if (pax_flags_softmode & MF_PAX_##flag) \
45010+ return ~0UL; \
45011+ pax_flags_softmode |= MF_PAX_##flag; \
45012+ break;
45013+
45014+ parse_flag('p', 'P', PAGEEXEC);
45015+ parse_flag('e', 'E', EMUTRAMP);
45016+ parse_flag('m', 'M', MPROTECT);
45017+ parse_flag('r', 'R', RANDMMAP);
45018+ parse_flag('s', 'S', SEGMEXEC);
45019+
45020+#undef parse_flag
45021+ }
45022+
45023+ if (pax_flags_hardmode & pax_flags_softmode)
45024+ return ~0UL;
45025+
45026+#ifdef CONFIG_PAX_SOFTMODE
45027+ if (pax_softmode)
45028+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
45029+ else
45030+#endif
45031+
45032+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
45033+#else
45034+ return ~0UL;
45035+#endif
45036+
45037+}
45038+
45039+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
45040+{
45041+ unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
45042+
45043+ pax_flags = pax_parse_ei_pax(elf_ex);
45044+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
45045+ xattr_pax_flags = pax_parse_xattr_pax(file);
45046+
45047+ if (pt_pax_flags == ~0UL)
45048+ pt_pax_flags = xattr_pax_flags;
45049+ else if (xattr_pax_flags == ~0UL)
45050+ xattr_pax_flags = pt_pax_flags;
45051+ if (pt_pax_flags != xattr_pax_flags)
45052+ return -EINVAL;
45053+ if (pt_pax_flags != ~0UL)
45054+ pax_flags = pt_pax_flags;
45055+
45056+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
45057+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
45058+ if ((__supported_pte_mask & _PAGE_NX))
45059+ pax_flags &= ~MF_PAX_SEGMEXEC;
45060+ else
45061+ pax_flags &= ~MF_PAX_PAGEEXEC;
45062+ }
45063+#endif
45064+
45065+ if (0 > pax_check_flags(&pax_flags))
45066+ return -EINVAL;
45067+
45068+ current->mm->pax_flags = pax_flags;
45069+ return 0;
45070+}
45071+#endif
45072+
45073 /*
45074 * These are the functions used to load ELF style executables and shared
45075 * libraries. There is no binary dependent code anywhere else.
45076@@ -546,6 +876,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
45077 {
45078 unsigned int random_variable = 0;
45079
45080+#ifdef CONFIG_PAX_RANDUSTACK
45081+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
45082+ return stack_top - current->mm->delta_stack;
45083+#endif
45084+
45085 if ((current->flags & PF_RANDOMIZE) &&
45086 !(current->personality & ADDR_NO_RANDOMIZE)) {
45087 random_variable = get_random_int() & STACK_RND_MASK;
45088@@ -564,7 +899,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
45089 unsigned long load_addr = 0, load_bias = 0;
45090 int load_addr_set = 0;
45091 char * elf_interpreter = NULL;
45092- unsigned long error;
45093+ unsigned long error = 0;
45094 struct elf_phdr *elf_ppnt, *elf_phdata;
45095 unsigned long elf_bss, elf_brk;
45096 int retval, i;
45097@@ -574,11 +909,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
45098 unsigned long start_code, end_code, start_data, end_data;
45099 unsigned long reloc_func_desc __maybe_unused = 0;
45100 int executable_stack = EXSTACK_DEFAULT;
45101- unsigned long def_flags = 0;
45102 struct {
45103 struct elfhdr elf_ex;
45104 struct elfhdr interp_elf_ex;
45105 } *loc;
45106+ unsigned long pax_task_size = TASK_SIZE;
45107
45108 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
45109 if (!loc) {
45110@@ -714,11 +1049,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
45111 goto out_free_dentry;
45112
45113 /* OK, This is the point of no return */
45114- current->mm->def_flags = def_flags;
45115+
45116+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
45117+ current->mm->pax_flags = 0UL;
45118+#endif
45119+
45120+#ifdef CONFIG_PAX_DLRESOLVE
45121+ current->mm->call_dl_resolve = 0UL;
45122+#endif
45123+
45124+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
45125+ current->mm->call_syscall = 0UL;
45126+#endif
45127+
45128+#ifdef CONFIG_PAX_ASLR
45129+ current->mm->delta_mmap = 0UL;
45130+ current->mm->delta_stack = 0UL;
45131+#endif
45132+
45133+ current->mm->def_flags = 0;
45134+
45135+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
45136+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
45137+ send_sig(SIGKILL, current, 0);
45138+ goto out_free_dentry;
45139+ }
45140+#endif
45141+
45142+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
45143+ pax_set_initial_flags(bprm);
45144+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
45145+ if (pax_set_initial_flags_func)
45146+ (pax_set_initial_flags_func)(bprm);
45147+#endif
45148+
45149+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
45150+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
45151+ current->mm->context.user_cs_limit = PAGE_SIZE;
45152+ current->mm->def_flags |= VM_PAGEEXEC;
45153+ }
45154+#endif
45155+
45156+#ifdef CONFIG_PAX_SEGMEXEC
45157+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
45158+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
45159+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
45160+ pax_task_size = SEGMEXEC_TASK_SIZE;
45161+ current->mm->def_flags |= VM_NOHUGEPAGE;
45162+ }
45163+#endif
45164+
45165+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
45166+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
45167+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
45168+ put_cpu();
45169+ }
45170+#endif
45171
45172 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
45173 may depend on the personality. */
45174 SET_PERSONALITY(loc->elf_ex);
45175+
45176+#ifdef CONFIG_PAX_ASLR
45177+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
45178+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
45179+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
45180+ }
45181+#endif
45182+
45183+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
45184+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
45185+ executable_stack = EXSTACK_DISABLE_X;
45186+ current->personality &= ~READ_IMPLIES_EXEC;
45187+ } else
45188+#endif
45189+
45190 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
45191 current->personality |= READ_IMPLIES_EXEC;
45192
45193@@ -809,6 +1214,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
45194 #else
45195 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
45196 #endif
45197+
45198+#ifdef CONFIG_PAX_RANDMMAP
45199+ /* PaX: randomize base address at the default exe base if requested */
45200+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
45201+#ifdef CONFIG_SPARC64
45202+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
45203+#else
45204+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
45205+#endif
45206+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
45207+ elf_flags |= MAP_FIXED;
45208+ }
45209+#endif
45210+
45211 }
45212
45213 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
45214@@ -841,9 +1260,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
45215 * allowed task size. Note that p_filesz must always be
45216 * <= p_memsz so it is only necessary to check p_memsz.
45217 */
45218- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
45219- elf_ppnt->p_memsz > TASK_SIZE ||
45220- TASK_SIZE - elf_ppnt->p_memsz < k) {
45221+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
45222+ elf_ppnt->p_memsz > pax_task_size ||
45223+ pax_task_size - elf_ppnt->p_memsz < k) {
45224 /* set_brk can never work. Avoid overflows. */
45225 send_sig(SIGKILL, current, 0);
45226 retval = -EINVAL;
45227@@ -882,17 +1301,44 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
45228 goto out_free_dentry;
45229 }
45230 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
45231- send_sig(SIGSEGV, current, 0);
45232- retval = -EFAULT; /* Nobody gets to see this, but.. */
45233- goto out_free_dentry;
45234+ /*
45235+ * This bss-zeroing can fail if the ELF
45236+ * file specifies odd protections. So
45237+ * we don't check the return value
45238+ */
45239 }
45240
45241+#ifdef CONFIG_PAX_RANDMMAP
45242+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
45243+ unsigned long start, size;
45244+
45245+ start = ELF_PAGEALIGN(elf_brk);
45246+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
45247+ down_read(&current->mm->mmap_sem);
45248+ retval = -ENOMEM;
45249+ if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
45250+ unsigned long prot = PROT_NONE;
45251+
45252+ up_read(&current->mm->mmap_sem);
45253+ current->mm->brk_gap = PAGE_ALIGN(size) >> PAGE_SHIFT;
45254+// if (current->personality & ADDR_NO_RANDOMIZE)
45255+// prot = PROT_READ;
45256+ start = vm_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
45257+ retval = IS_ERR_VALUE(start) ? start : 0;
45258+ } else
45259+ up_read(&current->mm->mmap_sem);
45260+ if (retval == 0)
45261+ retval = set_brk(start + size, start + size + PAGE_SIZE);
45262+ if (retval < 0) {
45263+ send_sig(SIGKILL, current, 0);
45264+ goto out_free_dentry;
45265+ }
45266+ }
45267+#endif
45268+
45269 if (elf_interpreter) {
45270- unsigned long interp_map_addr = 0;
45271-
45272 elf_entry = load_elf_interp(&loc->interp_elf_ex,
45273 interpreter,
45274- &interp_map_addr,
45275 load_bias);
45276 if (!IS_ERR((void *)elf_entry)) {
45277 /*
45278@@ -1114,7 +1560,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
45279 * Decide what to dump of a segment, part, all or none.
45280 */
45281 static unsigned long vma_dump_size(struct vm_area_struct *vma,
45282- unsigned long mm_flags)
45283+ unsigned long mm_flags, long signr)
45284 {
45285 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
45286
45287@@ -1151,7 +1597,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
45288 if (vma->vm_file == NULL)
45289 return 0;
45290
45291- if (FILTER(MAPPED_PRIVATE))
45292+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
45293 goto whole;
45294
45295 /*
45296@@ -1373,9 +1819,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
45297 {
45298 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
45299 int i = 0;
45300- do
45301+ do {
45302 i += 2;
45303- while (auxv[i - 2] != AT_NULL);
45304+ } while (auxv[i - 2] != AT_NULL);
45305 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
45306 }
45307
45308@@ -2003,14 +2449,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
45309 }
45310
45311 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
45312- unsigned long mm_flags)
45313+ struct coredump_params *cprm)
45314 {
45315 struct vm_area_struct *vma;
45316 size_t size = 0;
45317
45318 for (vma = first_vma(current, gate_vma); vma != NULL;
45319 vma = next_vma(vma, gate_vma))
45320- size += vma_dump_size(vma, mm_flags);
45321+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
45322 return size;
45323 }
45324
45325@@ -2104,7 +2550,7 @@ static int elf_core_dump(struct coredump_params *cprm)
45326
45327 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
45328
45329- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
45330+ offset += elf_core_vma_data_size(gate_vma, cprm);
45331 offset += elf_core_extra_data_size();
45332 e_shoff = offset;
45333
45334@@ -2118,10 +2564,12 @@ static int elf_core_dump(struct coredump_params *cprm)
45335 offset = dataoff;
45336
45337 size += sizeof(*elf);
45338+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
45339 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
45340 goto end_coredump;
45341
45342 size += sizeof(*phdr4note);
45343+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
45344 if (size > cprm->limit
45345 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
45346 goto end_coredump;
45347@@ -2135,7 +2583,7 @@ static int elf_core_dump(struct coredump_params *cprm)
45348 phdr.p_offset = offset;
45349 phdr.p_vaddr = vma->vm_start;
45350 phdr.p_paddr = 0;
45351- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
45352+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
45353 phdr.p_memsz = vma->vm_end - vma->vm_start;
45354 offset += phdr.p_filesz;
45355 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
45356@@ -2146,6 +2594,7 @@ static int elf_core_dump(struct coredump_params *cprm)
45357 phdr.p_align = ELF_EXEC_PAGESIZE;
45358
45359 size += sizeof(phdr);
45360+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
45361 if (size > cprm->limit
45362 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
45363 goto end_coredump;
45364@@ -2170,7 +2619,7 @@ static int elf_core_dump(struct coredump_params *cprm)
45365 unsigned long addr;
45366 unsigned long end;
45367
45368- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
45369+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
45370
45371 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
45372 struct page *page;
45373@@ -2179,6 +2628,7 @@ static int elf_core_dump(struct coredump_params *cprm)
45374 page = get_dump_page(addr);
45375 if (page) {
45376 void *kaddr = kmap(page);
45377+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
45378 stop = ((size += PAGE_SIZE) > cprm->limit) ||
45379 !dump_write(cprm->file, kaddr,
45380 PAGE_SIZE);
45381@@ -2196,6 +2646,7 @@ static int elf_core_dump(struct coredump_params *cprm)
45382
45383 if (e_phnum == PN_XNUM) {
45384 size += sizeof(*shdr4extnum);
45385+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
45386 if (size > cprm->limit
45387 || !dump_write(cprm->file, shdr4extnum,
45388 sizeof(*shdr4extnum)))
45389@@ -2216,6 +2667,97 @@ out:
45390
45391 #endif /* CONFIG_ELF_CORE */
45392
45393+#ifdef CONFIG_PAX_MPROTECT
45394+/* PaX: non-PIC ELF libraries need relocations on their executable segments
45395+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
45396+ * we'll remove VM_MAYWRITE for good on RELRO segments.
45397+ *
45398+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
45399+ * basis because we want to allow the common case and not the special ones.
45400+ */
45401+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
45402+{
45403+ struct elfhdr elf_h;
45404+ struct elf_phdr elf_p;
45405+ unsigned long i;
45406+ unsigned long oldflags;
45407+ bool is_textrel_rw, is_textrel_rx, is_relro;
45408+
45409+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
45410+ return;
45411+
45412+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
45413+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
45414+
45415+#ifdef CONFIG_PAX_ELFRELOCS
45416+ /* possible TEXTREL */
45417+ is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
45418+ 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);
45419+#else
45420+ is_textrel_rw = false;
45421+ is_textrel_rx = false;
45422+#endif
45423+
45424+ /* possible RELRO */
45425+ is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
45426+
45427+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
45428+ return;
45429+
45430+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
45431+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
45432+
45433+#ifdef CONFIG_PAX_ETEXECRELOCS
45434+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
45435+#else
45436+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
45437+#endif
45438+
45439+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
45440+ !elf_check_arch(&elf_h) ||
45441+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
45442+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
45443+ return;
45444+
45445+ for (i = 0UL; i < elf_h.e_phnum; i++) {
45446+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
45447+ return;
45448+ switch (elf_p.p_type) {
45449+ case PT_DYNAMIC:
45450+ if (!is_textrel_rw && !is_textrel_rx)
45451+ continue;
45452+ i = 0UL;
45453+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
45454+ elf_dyn dyn;
45455+
45456+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
45457+ return;
45458+ if (dyn.d_tag == DT_NULL)
45459+ return;
45460+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
45461+ gr_log_textrel(vma);
45462+ if (is_textrel_rw)
45463+ vma->vm_flags |= VM_MAYWRITE;
45464+ else
45465+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
45466+ vma->vm_flags &= ~VM_MAYWRITE;
45467+ return;
45468+ }
45469+ i++;
45470+ }
45471+ return;
45472+
45473+ case PT_GNU_RELRO:
45474+ if (!is_relro)
45475+ continue;
45476+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
45477+ vma->vm_flags &= ~VM_MAYWRITE;
45478+ return;
45479+ }
45480+ }
45481+}
45482+#endif
45483+
45484 static int __init init_elf_binfmt(void)
45485 {
45486 register_binfmt(&elf_format);
45487diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
45488index e280352..7b2f231 100644
45489--- a/fs/binfmt_flat.c
45490+++ b/fs/binfmt_flat.c
45491@@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
45492 realdatastart = (unsigned long) -ENOMEM;
45493 printk("Unable to allocate RAM for process data, errno %d\n",
45494 (int)-realdatastart);
45495+ down_write(&current->mm->mmap_sem);
45496 vm_munmap(textpos, text_len);
45497+ up_write(&current->mm->mmap_sem);
45498 ret = realdatastart;
45499 goto err;
45500 }
45501@@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
45502 }
45503 if (IS_ERR_VALUE(result)) {
45504 printk("Unable to read data+bss, errno %d\n", (int)-result);
45505+ down_write(&current->mm->mmap_sem);
45506 vm_munmap(textpos, text_len);
45507 vm_munmap(realdatastart, len);
45508+ up_write(&current->mm->mmap_sem);
45509 ret = result;
45510 goto err;
45511 }
45512@@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
45513 }
45514 if (IS_ERR_VALUE(result)) {
45515 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
45516+ down_write(&current->mm->mmap_sem);
45517 vm_munmap(textpos, text_len + data_len + extra +
45518 MAX_SHARED_LIBS * sizeof(unsigned long));
45519+ up_write(&current->mm->mmap_sem);
45520 ret = result;
45521 goto err;
45522 }
45523diff --git a/fs/bio.c b/fs/bio.c
45524index b96fc6c..431d628 100644
45525--- a/fs/bio.c
45526+++ b/fs/bio.c
45527@@ -818,7 +818,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
45528 /*
45529 * Overflow, abort
45530 */
45531- if (end < start)
45532+ if (end < start || end - start > INT_MAX - nr_pages)
45533 return ERR_PTR(-EINVAL);
45534
45535 nr_pages += end - start;
45536@@ -952,7 +952,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
45537 /*
45538 * Overflow, abort
45539 */
45540- if (end < start)
45541+ if (end < start || end - start > INT_MAX - nr_pages)
45542 return ERR_PTR(-EINVAL);
45543
45544 nr_pages += end - start;
45545@@ -1214,7 +1214,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
45546 const int read = bio_data_dir(bio) == READ;
45547 struct bio_map_data *bmd = bio->bi_private;
45548 int i;
45549- char *p = bmd->sgvecs[0].iov_base;
45550+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
45551
45552 __bio_for_each_segment(bvec, bio, i, 0) {
45553 char *addr = page_address(bvec->bv_page);
45554diff --git a/fs/block_dev.c b/fs/block_dev.c
45555index ab3a456..7da538b 100644
45556--- a/fs/block_dev.c
45557+++ b/fs/block_dev.c
45558@@ -651,7 +651,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
45559 else if (bdev->bd_contains == bdev)
45560 return true; /* is a whole device which isn't held */
45561
45562- else if (whole->bd_holder == bd_may_claim)
45563+ else if (whole->bd_holder == (void *)bd_may_claim)
45564 return true; /* is a partition of a device that is being partitioned */
45565 else if (whole->bd_holder != NULL)
45566 return false; /* is a partition of a held device */
45567diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
45568index cdfb4c4..da736d4 100644
45569--- a/fs/btrfs/ctree.c
45570+++ b/fs/btrfs/ctree.c
45571@@ -1035,9 +1035,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
45572 free_extent_buffer(buf);
45573 add_root_to_dirty_list(root);
45574 } else {
45575- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
45576- parent_start = parent->start;
45577- else
45578+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
45579+ if (parent)
45580+ parent_start = parent->start;
45581+ else
45582+ parent_start = 0;
45583+ } else
45584 parent_start = 0;
45585
45586 WARN_ON(trans->transid != btrfs_header_generation(parent));
45587diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
45588index 95542a1..95a8727 100644
45589--- a/fs/btrfs/inode.c
45590+++ b/fs/btrfs/inode.c
45591@@ -7243,7 +7243,7 @@ fail:
45592 return -ENOMEM;
45593 }
45594
45595-static int btrfs_getattr(struct vfsmount *mnt,
45596+int btrfs_getattr(struct vfsmount *mnt,
45597 struct dentry *dentry, struct kstat *stat)
45598 {
45599 struct inode *inode = dentry->d_inode;
45600@@ -7257,6 +7257,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
45601 return 0;
45602 }
45603
45604+EXPORT_SYMBOL(btrfs_getattr);
45605+
45606+dev_t get_btrfs_dev_from_inode(struct inode *inode)
45607+{
45608+ return BTRFS_I(inode)->root->anon_dev;
45609+}
45610+EXPORT_SYMBOL(get_btrfs_dev_from_inode);
45611+
45612 /*
45613 * If a file is moved, it will inherit the cow and compression flags of the new
45614 * directory.
45615diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
45616index 8fcf9a5..a200000 100644
45617--- a/fs/btrfs/ioctl.c
45618+++ b/fs/btrfs/ioctl.c
45619@@ -2965,9 +2965,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
45620 for (i = 0; i < num_types; i++) {
45621 struct btrfs_space_info *tmp;
45622
45623+ /* Don't copy in more than we allocated */
45624 if (!slot_count)
45625 break;
45626
45627+ slot_count--;
45628+
45629 info = NULL;
45630 rcu_read_lock();
45631 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
45632@@ -2989,10 +2992,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
45633 memcpy(dest, &space, sizeof(space));
45634 dest++;
45635 space_args.total_spaces++;
45636- slot_count--;
45637 }
45638- if (!slot_count)
45639- break;
45640 }
45641 up_read(&info->groups_sem);
45642 }
45643diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
45644index 776f0aa..3aad281 100644
45645--- a/fs/btrfs/relocation.c
45646+++ b/fs/btrfs/relocation.c
45647@@ -1269,7 +1269,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
45648 }
45649 spin_unlock(&rc->reloc_root_tree.lock);
45650
45651- BUG_ON((struct btrfs_root *)node->data != root);
45652+ BUG_ON(!node || (struct btrfs_root *)node->data != root);
45653
45654 if (!del) {
45655 spin_lock(&rc->reloc_root_tree.lock);
45656diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
45657index 622f469..e8d2d55 100644
45658--- a/fs/cachefiles/bind.c
45659+++ b/fs/cachefiles/bind.c
45660@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
45661 args);
45662
45663 /* start by checking things over */
45664- ASSERT(cache->fstop_percent >= 0 &&
45665- cache->fstop_percent < cache->fcull_percent &&
45666+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
45667 cache->fcull_percent < cache->frun_percent &&
45668 cache->frun_percent < 100);
45669
45670- ASSERT(cache->bstop_percent >= 0 &&
45671- cache->bstop_percent < cache->bcull_percent &&
45672+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
45673 cache->bcull_percent < cache->brun_percent &&
45674 cache->brun_percent < 100);
45675
45676diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
45677index 0a1467b..6a53245 100644
45678--- a/fs/cachefiles/daemon.c
45679+++ b/fs/cachefiles/daemon.c
45680@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
45681 if (n > buflen)
45682 return -EMSGSIZE;
45683
45684- if (copy_to_user(_buffer, buffer, n) != 0)
45685+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
45686 return -EFAULT;
45687
45688 return n;
45689@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
45690 if (test_bit(CACHEFILES_DEAD, &cache->flags))
45691 return -EIO;
45692
45693- if (datalen < 0 || datalen > PAGE_SIZE - 1)
45694+ if (datalen > PAGE_SIZE - 1)
45695 return -EOPNOTSUPP;
45696
45697 /* drag the command string into the kernel so we can parse it */
45698@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
45699 if (args[0] != '%' || args[1] != '\0')
45700 return -EINVAL;
45701
45702- if (fstop < 0 || fstop >= cache->fcull_percent)
45703+ if (fstop >= cache->fcull_percent)
45704 return cachefiles_daemon_range_error(cache, args);
45705
45706 cache->fstop_percent = fstop;
45707@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
45708 if (args[0] != '%' || args[1] != '\0')
45709 return -EINVAL;
45710
45711- if (bstop < 0 || bstop >= cache->bcull_percent)
45712+ if (bstop >= cache->bcull_percent)
45713 return cachefiles_daemon_range_error(cache, args);
45714
45715 cache->bstop_percent = bstop;
45716diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
45717index bd6bc1b..b627b53 100644
45718--- a/fs/cachefiles/internal.h
45719+++ b/fs/cachefiles/internal.h
45720@@ -57,7 +57,7 @@ struct cachefiles_cache {
45721 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
45722 struct rb_root active_nodes; /* active nodes (can't be culled) */
45723 rwlock_t active_lock; /* lock for active_nodes */
45724- atomic_t gravecounter; /* graveyard uniquifier */
45725+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
45726 unsigned frun_percent; /* when to stop culling (% files) */
45727 unsigned fcull_percent; /* when to start culling (% files) */
45728 unsigned fstop_percent; /* when to stop allocating (% files) */
45729@@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
45730 * proc.c
45731 */
45732 #ifdef CONFIG_CACHEFILES_HISTOGRAM
45733-extern atomic_t cachefiles_lookup_histogram[HZ];
45734-extern atomic_t cachefiles_mkdir_histogram[HZ];
45735-extern atomic_t cachefiles_create_histogram[HZ];
45736+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
45737+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
45738+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
45739
45740 extern int __init cachefiles_proc_init(void);
45741 extern void cachefiles_proc_cleanup(void);
45742 static inline
45743-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
45744+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
45745 {
45746 unsigned long jif = jiffies - start_jif;
45747 if (jif >= HZ)
45748 jif = HZ - 1;
45749- atomic_inc(&histogram[jif]);
45750+ atomic_inc_unchecked(&histogram[jif]);
45751 }
45752
45753 #else
45754diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
45755index b0b5f7c..039bb26 100644
45756--- a/fs/cachefiles/namei.c
45757+++ b/fs/cachefiles/namei.c
45758@@ -318,7 +318,7 @@ try_again:
45759 /* first step is to make up a grave dentry in the graveyard */
45760 sprintf(nbuffer, "%08x%08x",
45761 (uint32_t) get_seconds(),
45762- (uint32_t) atomic_inc_return(&cache->gravecounter));
45763+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
45764
45765 /* do the multiway lock magic */
45766 trap = lock_rename(cache->graveyard, dir);
45767diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
45768index eccd339..4c1d995 100644
45769--- a/fs/cachefiles/proc.c
45770+++ b/fs/cachefiles/proc.c
45771@@ -14,9 +14,9 @@
45772 #include <linux/seq_file.h>
45773 #include "internal.h"
45774
45775-atomic_t cachefiles_lookup_histogram[HZ];
45776-atomic_t cachefiles_mkdir_histogram[HZ];
45777-atomic_t cachefiles_create_histogram[HZ];
45778+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
45779+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
45780+atomic_unchecked_t cachefiles_create_histogram[HZ];
45781
45782 /*
45783 * display the latency histogram
45784@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
45785 return 0;
45786 default:
45787 index = (unsigned long) v - 3;
45788- x = atomic_read(&cachefiles_lookup_histogram[index]);
45789- y = atomic_read(&cachefiles_mkdir_histogram[index]);
45790- z = atomic_read(&cachefiles_create_histogram[index]);
45791+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
45792+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
45793+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
45794 if (x == 0 && y == 0 && z == 0)
45795 return 0;
45796
45797diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
45798index c994691..2a1537f 100644
45799--- a/fs/cachefiles/rdwr.c
45800+++ b/fs/cachefiles/rdwr.c
45801@@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
45802 old_fs = get_fs();
45803 set_fs(KERNEL_DS);
45804 ret = file->f_op->write(
45805- file, (const void __user *) data, len, &pos);
45806+ file, (const void __force_user *) data, len, &pos);
45807 set_fs(old_fs);
45808 kunmap(page);
45809 if (ret != len)
45810diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
45811index e5b7731..b9c59fb 100644
45812--- a/fs/ceph/dir.c
45813+++ b/fs/ceph/dir.c
45814@@ -243,7 +243,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
45815 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
45816 struct ceph_mds_client *mdsc = fsc->mdsc;
45817 unsigned frag = fpos_frag(filp->f_pos);
45818- int off = fpos_off(filp->f_pos);
45819+ unsigned int off = fpos_off(filp->f_pos);
45820 int err;
45821 u32 ftype;
45822 struct ceph_mds_reply_info_parsed *rinfo;
45823diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
45824index d9ea6ed..1e6c8ac 100644
45825--- a/fs/cifs/cifs_debug.c
45826+++ b/fs/cifs/cifs_debug.c
45827@@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
45828
45829 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
45830 #ifdef CONFIG_CIFS_STATS2
45831- atomic_set(&totBufAllocCount, 0);
45832- atomic_set(&totSmBufAllocCount, 0);
45833+ atomic_set_unchecked(&totBufAllocCount, 0);
45834+ atomic_set_unchecked(&totSmBufAllocCount, 0);
45835 #endif /* CONFIG_CIFS_STATS2 */
45836 spin_lock(&cifs_tcp_ses_lock);
45837 list_for_each(tmp1, &cifs_tcp_ses_list) {
45838@@ -281,7 +281,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
45839 tcon = list_entry(tmp3,
45840 struct cifs_tcon,
45841 tcon_list);
45842- atomic_set(&tcon->num_smbs_sent, 0);
45843+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
45844 if (server->ops->clear_stats)
45845 server->ops->clear_stats(tcon);
45846 }
45847@@ -313,8 +313,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
45848 smBufAllocCount.counter, cifs_min_small);
45849 #ifdef CONFIG_CIFS_STATS2
45850 seq_printf(m, "Total Large %d Small %d Allocations\n",
45851- atomic_read(&totBufAllocCount),
45852- atomic_read(&totSmBufAllocCount));
45853+ atomic_read_unchecked(&totBufAllocCount),
45854+ atomic_read_unchecked(&totSmBufAllocCount));
45855 #endif /* CONFIG_CIFS_STATS2 */
45856
45857 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
45858@@ -343,7 +343,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
45859 if (tcon->need_reconnect)
45860 seq_puts(m, "\tDISCONNECTED ");
45861 seq_printf(m, "\nSMBs: %d",
45862- atomic_read(&tcon->num_smbs_sent));
45863+ atomic_read_unchecked(&tcon->num_smbs_sent));
45864 if (server->ops->print_stats)
45865 server->ops->print_stats(m, tcon);
45866 }
45867diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
45868index e7931cc..76a1ab9 100644
45869--- a/fs/cifs/cifsfs.c
45870+++ b/fs/cifs/cifsfs.c
45871@@ -999,7 +999,7 @@ cifs_init_request_bufs(void)
45872 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
45873 cifs_req_cachep = kmem_cache_create("cifs_request",
45874 CIFSMaxBufSize + max_hdr_size, 0,
45875- SLAB_HWCACHE_ALIGN, NULL);
45876+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
45877 if (cifs_req_cachep == NULL)
45878 return -ENOMEM;
45879
45880@@ -1026,7 +1026,7 @@ cifs_init_request_bufs(void)
45881 efficient to alloc 1 per page off the slab compared to 17K (5page)
45882 alloc of large cifs buffers even when page debugging is on */
45883 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
45884- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
45885+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
45886 NULL);
45887 if (cifs_sm_req_cachep == NULL) {
45888 mempool_destroy(cifs_req_poolp);
45889@@ -1111,8 +1111,8 @@ init_cifs(void)
45890 atomic_set(&bufAllocCount, 0);
45891 atomic_set(&smBufAllocCount, 0);
45892 #ifdef CONFIG_CIFS_STATS2
45893- atomic_set(&totBufAllocCount, 0);
45894- atomic_set(&totSmBufAllocCount, 0);
45895+ atomic_set_unchecked(&totBufAllocCount, 0);
45896+ atomic_set_unchecked(&totSmBufAllocCount, 0);
45897 #endif /* CONFIG_CIFS_STATS2 */
45898
45899 atomic_set(&midCount, 0);
45900diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
45901index f5af252..489b5f2 100644
45902--- a/fs/cifs/cifsglob.h
45903+++ b/fs/cifs/cifsglob.h
45904@@ -751,35 +751,35 @@ struct cifs_tcon {
45905 __u16 Flags; /* optional support bits */
45906 enum statusEnum tidStatus;
45907 #ifdef CONFIG_CIFS_STATS
45908- atomic_t num_smbs_sent;
45909+ atomic_unchecked_t num_smbs_sent;
45910 union {
45911 struct {
45912- atomic_t num_writes;
45913- atomic_t num_reads;
45914- atomic_t num_flushes;
45915- atomic_t num_oplock_brks;
45916- atomic_t num_opens;
45917- atomic_t num_closes;
45918- atomic_t num_deletes;
45919- atomic_t num_mkdirs;
45920- atomic_t num_posixopens;
45921- atomic_t num_posixmkdirs;
45922- atomic_t num_rmdirs;
45923- atomic_t num_renames;
45924- atomic_t num_t2renames;
45925- atomic_t num_ffirst;
45926- atomic_t num_fnext;
45927- atomic_t num_fclose;
45928- atomic_t num_hardlinks;
45929- atomic_t num_symlinks;
45930- atomic_t num_locks;
45931- atomic_t num_acl_get;
45932- atomic_t num_acl_set;
45933+ atomic_unchecked_t num_writes;
45934+ atomic_unchecked_t num_reads;
45935+ atomic_unchecked_t num_flushes;
45936+ atomic_unchecked_t num_oplock_brks;
45937+ atomic_unchecked_t num_opens;
45938+ atomic_unchecked_t num_closes;
45939+ atomic_unchecked_t num_deletes;
45940+ atomic_unchecked_t num_mkdirs;
45941+ atomic_unchecked_t num_posixopens;
45942+ atomic_unchecked_t num_posixmkdirs;
45943+ atomic_unchecked_t num_rmdirs;
45944+ atomic_unchecked_t num_renames;
45945+ atomic_unchecked_t num_t2renames;
45946+ atomic_unchecked_t num_ffirst;
45947+ atomic_unchecked_t num_fnext;
45948+ atomic_unchecked_t num_fclose;
45949+ atomic_unchecked_t num_hardlinks;
45950+ atomic_unchecked_t num_symlinks;
45951+ atomic_unchecked_t num_locks;
45952+ atomic_unchecked_t num_acl_get;
45953+ atomic_unchecked_t num_acl_set;
45954 } cifs_stats;
45955 #ifdef CONFIG_CIFS_SMB2
45956 struct {
45957- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
45958- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
45959+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
45960+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
45961 } smb2_stats;
45962 #endif /* CONFIG_CIFS_SMB2 */
45963 } stats;
45964@@ -1094,7 +1094,7 @@ build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb,
45965 }
45966
45967 #ifdef CONFIG_CIFS_STATS
45968-#define cifs_stats_inc atomic_inc
45969+#define cifs_stats_inc atomic_inc_unchecked
45970
45971 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
45972 unsigned int bytes)
45973@@ -1459,8 +1459,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
45974 /* Various Debug counters */
45975 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
45976 #ifdef CONFIG_CIFS_STATS2
45977-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
45978-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
45979+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
45980+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
45981 #endif
45982 GLOBAL_EXTERN atomic_t smBufAllocCount;
45983 GLOBAL_EXTERN atomic_t midCount;
45984diff --git a/fs/cifs/link.c b/fs/cifs/link.c
45985index 51dc2fb..1e12a33 100644
45986--- a/fs/cifs/link.c
45987+++ b/fs/cifs/link.c
45988@@ -616,7 +616,7 @@ symlink_exit:
45989
45990 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
45991 {
45992- char *p = nd_get_link(nd);
45993+ const char *p = nd_get_link(nd);
45994 if (!IS_ERR(p))
45995 kfree(p);
45996 }
45997diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
45998index 3a00c0d..42d901c 100644
45999--- a/fs/cifs/misc.c
46000+++ b/fs/cifs/misc.c
46001@@ -169,7 +169,7 @@ cifs_buf_get(void)
46002 memset(ret_buf, 0, buf_size + 3);
46003 atomic_inc(&bufAllocCount);
46004 #ifdef CONFIG_CIFS_STATS2
46005- atomic_inc(&totBufAllocCount);
46006+ atomic_inc_unchecked(&totBufAllocCount);
46007 #endif /* CONFIG_CIFS_STATS2 */
46008 }
46009
46010@@ -204,7 +204,7 @@ cifs_small_buf_get(void)
46011 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
46012 atomic_inc(&smBufAllocCount);
46013 #ifdef CONFIG_CIFS_STATS2
46014- atomic_inc(&totSmBufAllocCount);
46015+ atomic_inc_unchecked(&totSmBufAllocCount);
46016 #endif /* CONFIG_CIFS_STATS2 */
46017
46018 }
46019diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
46020index 591bf19..690d600 100644
46021--- a/fs/cifs/smb1ops.c
46022+++ b/fs/cifs/smb1ops.c
46023@@ -617,27 +617,27 @@ static void
46024 cifs_clear_stats(struct cifs_tcon *tcon)
46025 {
46026 #ifdef CONFIG_CIFS_STATS
46027- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
46028- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
46029- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
46030- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
46031- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
46032- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
46033- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
46034- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
46035- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
46036- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
46037- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
46038- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
46039- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
46040- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
46041- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
46042- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
46043- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
46044- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
46045- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
46046- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
46047- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
46048+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
46049+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
46050+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
46051+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
46052+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
46053+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
46054+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
46055+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
46056+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
46057+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
46058+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
46059+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
46060+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
46061+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
46062+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
46063+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
46064+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
46065+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
46066+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
46067+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
46068+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
46069 #endif
46070 }
46071
46072@@ -646,36 +646,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
46073 {
46074 #ifdef CONFIG_CIFS_STATS
46075 seq_printf(m, " Oplocks breaks: %d",
46076- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
46077+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
46078 seq_printf(m, "\nReads: %d Bytes: %llu",
46079- atomic_read(&tcon->stats.cifs_stats.num_reads),
46080+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
46081 (long long)(tcon->bytes_read));
46082 seq_printf(m, "\nWrites: %d Bytes: %llu",
46083- atomic_read(&tcon->stats.cifs_stats.num_writes),
46084+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
46085 (long long)(tcon->bytes_written));
46086 seq_printf(m, "\nFlushes: %d",
46087- atomic_read(&tcon->stats.cifs_stats.num_flushes));
46088+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
46089 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
46090- atomic_read(&tcon->stats.cifs_stats.num_locks),
46091- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
46092- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
46093+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
46094+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
46095+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
46096 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
46097- atomic_read(&tcon->stats.cifs_stats.num_opens),
46098- atomic_read(&tcon->stats.cifs_stats.num_closes),
46099- atomic_read(&tcon->stats.cifs_stats.num_deletes));
46100+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
46101+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
46102+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
46103 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
46104- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
46105- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
46106+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
46107+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
46108 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
46109- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
46110- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
46111+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
46112+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
46113 seq_printf(m, "\nRenames: %d T2 Renames %d",
46114- atomic_read(&tcon->stats.cifs_stats.num_renames),
46115- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
46116+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
46117+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
46118 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
46119- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
46120- atomic_read(&tcon->stats.cifs_stats.num_fnext),
46121- atomic_read(&tcon->stats.cifs_stats.num_fclose));
46122+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
46123+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
46124+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
46125 #endif
46126 }
46127
46128diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
46129index 4d9dbe0..0af4601 100644
46130--- a/fs/cifs/smb2ops.c
46131+++ b/fs/cifs/smb2ops.c
46132@@ -291,8 +291,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
46133 #ifdef CONFIG_CIFS_STATS
46134 int i;
46135 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
46136- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
46137- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
46138+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
46139+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
46140 }
46141 #endif
46142 }
46143@@ -301,66 +301,66 @@ static void
46144 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
46145 {
46146 #ifdef CONFIG_CIFS_STATS
46147- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
46148- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
46149+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
46150+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
46151 seq_printf(m, "\nNegotiates: %d sent %d failed",
46152- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
46153- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
46154+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
46155+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
46156 seq_printf(m, "\nSessionSetups: %d sent %d failed",
46157- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
46158- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
46159+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
46160+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
46161 #define SMB2LOGOFF 0x0002 /* trivial request/resp */
46162 seq_printf(m, "\nLogoffs: %d sent %d failed",
46163- atomic_read(&sent[SMB2_LOGOFF_HE]),
46164- atomic_read(&failed[SMB2_LOGOFF_HE]));
46165+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
46166+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
46167 seq_printf(m, "\nTreeConnects: %d sent %d failed",
46168- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
46169- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
46170+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
46171+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
46172 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
46173- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
46174- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
46175+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
46176+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
46177 seq_printf(m, "\nCreates: %d sent %d failed",
46178- atomic_read(&sent[SMB2_CREATE_HE]),
46179- atomic_read(&failed[SMB2_CREATE_HE]));
46180+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
46181+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
46182 seq_printf(m, "\nCloses: %d sent %d failed",
46183- atomic_read(&sent[SMB2_CLOSE_HE]),
46184- atomic_read(&failed[SMB2_CLOSE_HE]));
46185+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
46186+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
46187 seq_printf(m, "\nFlushes: %d sent %d failed",
46188- atomic_read(&sent[SMB2_FLUSH_HE]),
46189- atomic_read(&failed[SMB2_FLUSH_HE]));
46190+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
46191+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
46192 seq_printf(m, "\nReads: %d sent %d failed",
46193- atomic_read(&sent[SMB2_READ_HE]),
46194- atomic_read(&failed[SMB2_READ_HE]));
46195+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
46196+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
46197 seq_printf(m, "\nWrites: %d sent %d failed",
46198- atomic_read(&sent[SMB2_WRITE_HE]),
46199- atomic_read(&failed[SMB2_WRITE_HE]));
46200+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
46201+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
46202 seq_printf(m, "\nLocks: %d sent %d failed",
46203- atomic_read(&sent[SMB2_LOCK_HE]),
46204- atomic_read(&failed[SMB2_LOCK_HE]));
46205+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
46206+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
46207 seq_printf(m, "\nIOCTLs: %d sent %d failed",
46208- atomic_read(&sent[SMB2_IOCTL_HE]),
46209- atomic_read(&failed[SMB2_IOCTL_HE]));
46210+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
46211+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
46212 seq_printf(m, "\nCancels: %d sent %d failed",
46213- atomic_read(&sent[SMB2_CANCEL_HE]),
46214- atomic_read(&failed[SMB2_CANCEL_HE]));
46215+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
46216+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
46217 seq_printf(m, "\nEchos: %d sent %d failed",
46218- atomic_read(&sent[SMB2_ECHO_HE]),
46219- atomic_read(&failed[SMB2_ECHO_HE]));
46220+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
46221+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
46222 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
46223- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
46224- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
46225+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
46226+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
46227 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
46228- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
46229- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
46230+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
46231+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
46232 seq_printf(m, "\nQueryInfos: %d sent %d failed",
46233- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
46234- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
46235+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
46236+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
46237 seq_printf(m, "\nSetInfos: %d sent %d failed",
46238- atomic_read(&sent[SMB2_SET_INFO_HE]),
46239- atomic_read(&failed[SMB2_SET_INFO_HE]));
46240+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
46241+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
46242 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
46243- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
46244- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
46245+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
46246+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
46247 #endif
46248 }
46249
46250diff --git a/fs/coda/cache.c b/fs/coda/cache.c
46251index 958ae0e..505c9d0 100644
46252--- a/fs/coda/cache.c
46253+++ b/fs/coda/cache.c
46254@@ -24,7 +24,7 @@
46255 #include "coda_linux.h"
46256 #include "coda_cache.h"
46257
46258-static atomic_t permission_epoch = ATOMIC_INIT(0);
46259+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
46260
46261 /* replace or extend an acl cache hit */
46262 void coda_cache_enter(struct inode *inode, int mask)
46263@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
46264 struct coda_inode_info *cii = ITOC(inode);
46265
46266 spin_lock(&cii->c_lock);
46267- cii->c_cached_epoch = atomic_read(&permission_epoch);
46268+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
46269 if (cii->c_uid != current_fsuid()) {
46270 cii->c_uid = current_fsuid();
46271 cii->c_cached_perm = mask;
46272@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
46273 {
46274 struct coda_inode_info *cii = ITOC(inode);
46275 spin_lock(&cii->c_lock);
46276- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
46277+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
46278 spin_unlock(&cii->c_lock);
46279 }
46280
46281 /* remove all acl caches */
46282 void coda_cache_clear_all(struct super_block *sb)
46283 {
46284- atomic_inc(&permission_epoch);
46285+ atomic_inc_unchecked(&permission_epoch);
46286 }
46287
46288
46289@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
46290 spin_lock(&cii->c_lock);
46291 hit = (mask & cii->c_cached_perm) == mask &&
46292 cii->c_uid == current_fsuid() &&
46293- cii->c_cached_epoch == atomic_read(&permission_epoch);
46294+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
46295 spin_unlock(&cii->c_lock);
46296
46297 return hit;
46298diff --git a/fs/compat.c b/fs/compat.c
46299index 015e1e1..5ce8e54 100644
46300--- a/fs/compat.c
46301+++ b/fs/compat.c
46302@@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
46303
46304 set_fs(KERNEL_DS);
46305 /* The __user pointer cast is valid because of the set_fs() */
46306- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
46307+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
46308 set_fs(oldfs);
46309 /* truncating is ok because it's a user address */
46310 if (!ret)
46311@@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
46312 goto out;
46313
46314 ret = -EINVAL;
46315- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
46316+ if (nr_segs > UIO_MAXIOV)
46317 goto out;
46318 if (nr_segs > fast_segs) {
46319 ret = -ENOMEM;
46320@@ -831,6 +831,7 @@ struct compat_old_linux_dirent {
46321
46322 struct compat_readdir_callback {
46323 struct compat_old_linux_dirent __user *dirent;
46324+ struct file * file;
46325 int result;
46326 };
46327
46328@@ -848,6 +849,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
46329 buf->result = -EOVERFLOW;
46330 return -EOVERFLOW;
46331 }
46332+
46333+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
46334+ return 0;
46335+
46336 buf->result++;
46337 dirent = buf->dirent;
46338 if (!access_ok(VERIFY_WRITE, dirent,
46339@@ -878,6 +883,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
46340
46341 buf.result = 0;
46342 buf.dirent = dirent;
46343+ buf.file = f.file;
46344
46345 error = vfs_readdir(f.file, compat_fillonedir, &buf);
46346 if (buf.result)
46347@@ -897,6 +903,7 @@ struct compat_linux_dirent {
46348 struct compat_getdents_callback {
46349 struct compat_linux_dirent __user *current_dir;
46350 struct compat_linux_dirent __user *previous;
46351+ struct file * file;
46352 int count;
46353 int error;
46354 };
46355@@ -918,6 +925,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
46356 buf->error = -EOVERFLOW;
46357 return -EOVERFLOW;
46358 }
46359+
46360+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
46361+ return 0;
46362+
46363 dirent = buf->previous;
46364 if (dirent) {
46365 if (__put_user(offset, &dirent->d_off))
46366@@ -963,6 +974,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
46367 buf.previous = NULL;
46368 buf.count = count;
46369 buf.error = 0;
46370+ buf.file = f.file;
46371
46372 error = vfs_readdir(f.file, compat_filldir, &buf);
46373 if (error >= 0)
46374@@ -983,6 +995,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
46375 struct compat_getdents_callback64 {
46376 struct linux_dirent64 __user *current_dir;
46377 struct linux_dirent64 __user *previous;
46378+ struct file * file;
46379 int count;
46380 int error;
46381 };
46382@@ -999,6 +1012,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
46383 buf->error = -EINVAL; /* only used if we fail.. */
46384 if (reclen > buf->count)
46385 return -EINVAL;
46386+
46387+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
46388+ return 0;
46389+
46390 dirent = buf->previous;
46391
46392 if (dirent) {
46393@@ -1048,13 +1065,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
46394 buf.previous = NULL;
46395 buf.count = count;
46396 buf.error = 0;
46397+ buf.file = f.file;
46398
46399 error = vfs_readdir(f.file, compat_filldir64, &buf);
46400 if (error >= 0)
46401 error = buf.error;
46402 lastdirent = buf.previous;
46403 if (lastdirent) {
46404- typeof(lastdirent->d_off) d_off = f.file->f_pos;
46405+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
46406 if (__put_user_unaligned(d_off, &lastdirent->d_off))
46407 error = -EFAULT;
46408 else
46409diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
46410index a81147e..20bf2b5 100644
46411--- a/fs/compat_binfmt_elf.c
46412+++ b/fs/compat_binfmt_elf.c
46413@@ -30,11 +30,13 @@
46414 #undef elf_phdr
46415 #undef elf_shdr
46416 #undef elf_note
46417+#undef elf_dyn
46418 #undef elf_addr_t
46419 #define elfhdr elf32_hdr
46420 #define elf_phdr elf32_phdr
46421 #define elf_shdr elf32_shdr
46422 #define elf_note elf32_note
46423+#define elf_dyn Elf32_Dyn
46424 #define elf_addr_t Elf32_Addr
46425
46426 /*
46427diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
46428index 4c6285f..b7a2411 100644
46429--- a/fs/compat_ioctl.c
46430+++ b/fs/compat_ioctl.c
46431@@ -623,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
46432 return -EFAULT;
46433 if (__get_user(udata, &ss32->iomem_base))
46434 return -EFAULT;
46435- ss.iomem_base = compat_ptr(udata);
46436+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
46437 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
46438 __get_user(ss.port_high, &ss32->port_high))
46439 return -EFAULT;
46440@@ -798,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
46441 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
46442 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
46443 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
46444- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
46445+ copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
46446 return -EFAULT;
46447
46448 return ioctl_preallocate(file, p);
46449@@ -1617,8 +1617,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
46450 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
46451 {
46452 unsigned int a, b;
46453- a = *(unsigned int *)p;
46454- b = *(unsigned int *)q;
46455+ a = *(const unsigned int *)p;
46456+ b = *(const unsigned int *)q;
46457 if (a > b)
46458 return 1;
46459 if (a < b)
46460diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
46461index 7414ae2..d98ad6d 100644
46462--- a/fs/configfs/dir.c
46463+++ b/fs/configfs/dir.c
46464@@ -1564,7 +1564,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
46465 }
46466 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
46467 struct configfs_dirent *next;
46468- const char * name;
46469+ const unsigned char * name;
46470+ char d_name[sizeof(next->s_dentry->d_iname)];
46471 int len;
46472 struct inode *inode = NULL;
46473
46474@@ -1574,7 +1575,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
46475 continue;
46476
46477 name = configfs_get_name(next);
46478- len = strlen(name);
46479+ if (next->s_dentry && name == next->s_dentry->d_iname) {
46480+ len = next->s_dentry->d_name.len;
46481+ memcpy(d_name, name, len);
46482+ name = d_name;
46483+ } else
46484+ len = strlen(name);
46485
46486 /*
46487 * We'll have a dentry and an inode for
46488diff --git a/fs/coredump.c b/fs/coredump.c
46489index ce47379..68c8e43 100644
46490--- a/fs/coredump.c
46491+++ b/fs/coredump.c
46492@@ -52,7 +52,7 @@ struct core_name {
46493 char *corename;
46494 int used, size;
46495 };
46496-static atomic_t call_count = ATOMIC_INIT(1);
46497+static atomic_unchecked_t call_count = ATOMIC_INIT(1);
46498
46499 /* The maximal length of core_pattern is also specified in sysctl.c */
46500
46501@@ -60,7 +60,7 @@ static int expand_corename(struct core_name *cn)
46502 {
46503 char *old_corename = cn->corename;
46504
46505- cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
46506+ cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
46507 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
46508
46509 if (!cn->corename) {
46510@@ -157,7 +157,7 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm)
46511 int pid_in_pattern = 0;
46512 int err = 0;
46513
46514- cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
46515+ cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
46516 cn->corename = kmalloc(cn->size, GFP_KERNEL);
46517 cn->used = 0;
46518
46519@@ -414,17 +414,17 @@ static void wait_for_dump_helpers(struct file *file)
46520 pipe = file->f_path.dentry->d_inode->i_pipe;
46521
46522 pipe_lock(pipe);
46523- pipe->readers++;
46524- pipe->writers--;
46525+ atomic_inc(&pipe->readers);
46526+ atomic_dec(&pipe->writers);
46527
46528- while ((pipe->readers > 1) && (!signal_pending(current))) {
46529+ while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
46530 wake_up_interruptible_sync(&pipe->wait);
46531 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
46532 pipe_wait(pipe);
46533 }
46534
46535- pipe->readers--;
46536- pipe->writers++;
46537+ atomic_dec(&pipe->readers);
46538+ atomic_inc(&pipe->writers);
46539 pipe_unlock(pipe);
46540
46541 }
46542@@ -471,7 +471,8 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
46543 int ispipe;
46544 struct files_struct *displaced;
46545 bool need_nonrelative = false;
46546- static atomic_t core_dump_count = ATOMIC_INIT(0);
46547+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
46548+ long signr = siginfo->si_signo;
46549 struct coredump_params cprm = {
46550 .siginfo = siginfo,
46551 .regs = regs,
46552@@ -484,7 +485,10 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
46553 .mm_flags = mm->flags,
46554 };
46555
46556- audit_core_dumps(siginfo->si_signo);
46557+ audit_core_dumps(signr);
46558+
46559+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
46560+ gr_handle_brute_attach(cprm.mm_flags);
46561
46562 binfmt = mm->binfmt;
46563 if (!binfmt || !binfmt->core_dump)
46564@@ -508,7 +512,7 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
46565 need_nonrelative = true;
46566 }
46567
46568- retval = coredump_wait(siginfo->si_signo, &core_state);
46569+ retval = coredump_wait(signr, &core_state);
46570 if (retval < 0)
46571 goto fail_creds;
46572
46573@@ -556,7 +560,7 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
46574 }
46575 cprm.limit = RLIM_INFINITY;
46576
46577- dump_count = atomic_inc_return(&core_dump_count);
46578+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
46579 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
46580 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
46581 task_tgid_vnr(current), current->comm);
46582@@ -583,6 +587,8 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
46583 } else {
46584 struct inode *inode;
46585
46586+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
46587+
46588 if (cprm.limit < binfmt->min_coredump)
46589 goto fail_unlock;
46590
46591@@ -640,7 +646,7 @@ close_fail:
46592 filp_close(cprm.file, NULL);
46593 fail_dropcount:
46594 if (ispipe)
46595- atomic_dec(&core_dump_count);
46596+ atomic_dec_unchecked(&core_dump_count);
46597 fail_unlock:
46598 kfree(cn.corename);
46599 fail_corename:
46600@@ -659,7 +665,7 @@ fail:
46601 */
46602 int dump_write(struct file *file, const void *addr, int nr)
46603 {
46604- return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
46605+ return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
46606 }
46607 EXPORT_SYMBOL(dump_write);
46608
46609diff --git a/fs/dcache.c b/fs/dcache.c
46610index 0d0adb6..f4646e9 100644
46611--- a/fs/dcache.c
46612+++ b/fs/dcache.c
46613@@ -3164,7 +3164,7 @@ void __init vfs_caches_init(unsigned long mempages)
46614 mempages -= reserve;
46615
46616 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
46617- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
46618+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
46619
46620 dcache_init();
46621 inode_init();
46622diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
46623index b607d92..41fda09 100644
46624--- a/fs/debugfs/inode.c
46625+++ b/fs/debugfs/inode.c
46626@@ -416,7 +416,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
46627 */
46628 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
46629 {
46630+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
46631+ return __create_file(name, S_IFDIR | S_IRWXU,
46632+#else
46633 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
46634+#endif
46635 parent, NULL, NULL);
46636 }
46637 EXPORT_SYMBOL_GPL(debugfs_create_dir);
46638diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
46639index cc7709e..7e7211f 100644
46640--- a/fs/ecryptfs/inode.c
46641+++ b/fs/ecryptfs/inode.c
46642@@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
46643 old_fs = get_fs();
46644 set_fs(get_ds());
46645 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
46646- (char __user *)lower_buf,
46647+ (char __force_user *)lower_buf,
46648 PATH_MAX);
46649 set_fs(old_fs);
46650 if (rc < 0)
46651@@ -706,7 +706,7 @@ out:
46652 static void
46653 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
46654 {
46655- char *buf = nd_get_link(nd);
46656+ const char *buf = nd_get_link(nd);
46657 if (!IS_ERR(buf)) {
46658 /* Free the char* */
46659 kfree(buf);
46660diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
46661index 412e6ed..4292d22 100644
46662--- a/fs/ecryptfs/miscdev.c
46663+++ b/fs/ecryptfs/miscdev.c
46664@@ -315,7 +315,7 @@ check_list:
46665 goto out_unlock_msg_ctx;
46666 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
46667 if (msg_ctx->msg) {
46668- if (copy_to_user(&buf[i], packet_length, packet_length_size))
46669+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
46670 goto out_unlock_msg_ctx;
46671 i += packet_length_size;
46672 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
46673diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
46674index b2a34a1..162fa69 100644
46675--- a/fs/ecryptfs/read_write.c
46676+++ b/fs/ecryptfs/read_write.c
46677@@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
46678 return -EIO;
46679 fs_save = get_fs();
46680 set_fs(get_ds());
46681- rc = vfs_write(lower_file, data, size, &offset);
46682+ rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
46683 set_fs(fs_save);
46684 mark_inode_dirty_sync(ecryptfs_inode);
46685 return rc;
46686@@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
46687 return -EIO;
46688 fs_save = get_fs();
46689 set_fs(get_ds());
46690- rc = vfs_read(lower_file, data, size, &offset);
46691+ rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
46692 set_fs(fs_save);
46693 return rc;
46694 }
46695diff --git a/fs/exec.c b/fs/exec.c
46696index c6e6de4..45e71ad 100644
46697--- a/fs/exec.c
46698+++ b/fs/exec.c
46699@@ -55,6 +55,17 @@
46700 #include <linux/pipe_fs_i.h>
46701 #include <linux/oom.h>
46702 #include <linux/compat.h>
46703+#include <linux/random.h>
46704+#include <linux/seq_file.h>
46705+#include <linux/coredump.h>
46706+#include <linux/mman.h>
46707+
46708+#ifdef CONFIG_PAX_REFCOUNT
46709+#include <linux/kallsyms.h>
46710+#include <linux/kdebug.h>
46711+#endif
46712+
46713+#include <trace/events/fs.h>
46714
46715 #include <asm/uaccess.h>
46716 #include <asm/mmu_context.h>
46717@@ -66,6 +77,18 @@
46718
46719 #include <trace/events/sched.h>
46720
46721+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
46722+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
46723+{
46724+ 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");
46725+}
46726+#endif
46727+
46728+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
46729+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
46730+EXPORT_SYMBOL(pax_set_initial_flags_func);
46731+#endif
46732+
46733 int suid_dumpable = 0;
46734
46735 static LIST_HEAD(formats);
46736@@ -180,18 +203,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
46737 int write)
46738 {
46739 struct page *page;
46740- int ret;
46741
46742-#ifdef CONFIG_STACK_GROWSUP
46743- if (write) {
46744- ret = expand_downwards(bprm->vma, pos);
46745- if (ret < 0)
46746- return NULL;
46747- }
46748-#endif
46749- ret = get_user_pages(current, bprm->mm, pos,
46750- 1, write, 1, &page, NULL);
46751- if (ret <= 0)
46752+ if (0 > expand_downwards(bprm->vma, pos))
46753+ return NULL;
46754+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
46755 return NULL;
46756
46757 if (write) {
46758@@ -207,6 +222,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
46759 if (size <= ARG_MAX)
46760 return page;
46761
46762+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46763+ // only allow 512KB for argv+env on suid/sgid binaries
46764+ // to prevent easy ASLR exhaustion
46765+ if (((bprm->cred->euid != current_euid()) ||
46766+ (bprm->cred->egid != current_egid())) &&
46767+ (size > (512 * 1024))) {
46768+ put_page(page);
46769+ return NULL;
46770+ }
46771+#endif
46772+
46773 /*
46774 * Limit to 1/4-th the stack size for the argv+env strings.
46775 * This ensures that:
46776@@ -266,6 +292,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
46777 vma->vm_end = STACK_TOP_MAX;
46778 vma->vm_start = vma->vm_end - PAGE_SIZE;
46779 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
46780+
46781+#ifdef CONFIG_PAX_SEGMEXEC
46782+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
46783+#endif
46784+
46785 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
46786 INIT_LIST_HEAD(&vma->anon_vma_chain);
46787
46788@@ -276,6 +307,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
46789 mm->stack_vm = mm->total_vm = 1;
46790 up_write(&mm->mmap_sem);
46791 bprm->p = vma->vm_end - sizeof(void *);
46792+
46793+#ifdef CONFIG_PAX_RANDUSTACK
46794+ if (randomize_va_space)
46795+ bprm->p ^= random32() & ~PAGE_MASK;
46796+#endif
46797+
46798 return 0;
46799 err:
46800 up_write(&mm->mmap_sem);
46801@@ -384,19 +421,7 @@ err:
46802 return err;
46803 }
46804
46805-struct user_arg_ptr {
46806-#ifdef CONFIG_COMPAT
46807- bool is_compat;
46808-#endif
46809- union {
46810- const char __user *const __user *native;
46811-#ifdef CONFIG_COMPAT
46812- const compat_uptr_t __user *compat;
46813-#endif
46814- } ptr;
46815-};
46816-
46817-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
46818+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
46819 {
46820 const char __user *native;
46821
46822@@ -405,14 +430,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
46823 compat_uptr_t compat;
46824
46825 if (get_user(compat, argv.ptr.compat + nr))
46826- return ERR_PTR(-EFAULT);
46827+ return (const char __force_user *)ERR_PTR(-EFAULT);
46828
46829 return compat_ptr(compat);
46830 }
46831 #endif
46832
46833 if (get_user(native, argv.ptr.native + nr))
46834- return ERR_PTR(-EFAULT);
46835+ return (const char __force_user *)ERR_PTR(-EFAULT);
46836
46837 return native;
46838 }
46839@@ -431,11 +456,12 @@ static int count(struct user_arg_ptr argv, int max)
46840 if (!p)
46841 break;
46842
46843- if (IS_ERR(p))
46844+ if (IS_ERR((const char __force_kernel *)p))
46845 return -EFAULT;
46846
46847- if (i++ >= max)
46848+ if (i >= max)
46849 return -E2BIG;
46850+ ++i;
46851
46852 if (fatal_signal_pending(current))
46853 return -ERESTARTNOHAND;
46854@@ -465,7 +491,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
46855
46856 ret = -EFAULT;
46857 str = get_user_arg_ptr(argv, argc);
46858- if (IS_ERR(str))
46859+ if (IS_ERR((const char __force_kernel *)str))
46860 goto out;
46861
46862 len = strnlen_user(str, MAX_ARG_STRLEN);
46863@@ -547,7 +573,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
46864 int r;
46865 mm_segment_t oldfs = get_fs();
46866 struct user_arg_ptr argv = {
46867- .ptr.native = (const char __user *const __user *)__argv,
46868+ .ptr.native = (const char __force_user *const __force_user *)__argv,
46869 };
46870
46871 set_fs(KERNEL_DS);
46872@@ -582,7 +608,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
46873 unsigned long new_end = old_end - shift;
46874 struct mmu_gather tlb;
46875
46876- BUG_ON(new_start > new_end);
46877+ if (new_start >= new_end || new_start < mmap_min_addr)
46878+ return -ENOMEM;
46879
46880 /*
46881 * ensure there are no vmas between where we want to go
46882@@ -591,6 +618,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
46883 if (vma != find_vma(mm, new_start))
46884 return -EFAULT;
46885
46886+#ifdef CONFIG_PAX_SEGMEXEC
46887+ BUG_ON(pax_find_mirror_vma(vma));
46888+#endif
46889+
46890 /*
46891 * cover the whole range: [new_start, old_end)
46892 */
46893@@ -671,10 +702,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
46894 stack_top = arch_align_stack(stack_top);
46895 stack_top = PAGE_ALIGN(stack_top);
46896
46897- if (unlikely(stack_top < mmap_min_addr) ||
46898- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
46899- return -ENOMEM;
46900-
46901 stack_shift = vma->vm_end - stack_top;
46902
46903 bprm->p -= stack_shift;
46904@@ -686,8 +713,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
46905 bprm->exec -= stack_shift;
46906
46907 down_write(&mm->mmap_sem);
46908+
46909+ /* Move stack pages down in memory. */
46910+ if (stack_shift) {
46911+ ret = shift_arg_pages(vma, stack_shift);
46912+ if (ret)
46913+ goto out_unlock;
46914+ }
46915+
46916 vm_flags = VM_STACK_FLAGS;
46917
46918+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
46919+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
46920+ vm_flags &= ~VM_EXEC;
46921+
46922+#ifdef CONFIG_PAX_MPROTECT
46923+ if (mm->pax_flags & MF_PAX_MPROTECT)
46924+ vm_flags &= ~VM_MAYEXEC;
46925+#endif
46926+
46927+ }
46928+#endif
46929+
46930 /*
46931 * Adjust stack execute permissions; explicitly enable for
46932 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
46933@@ -706,13 +753,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
46934 goto out_unlock;
46935 BUG_ON(prev != vma);
46936
46937- /* Move stack pages down in memory. */
46938- if (stack_shift) {
46939- ret = shift_arg_pages(vma, stack_shift);
46940- if (ret)
46941- goto out_unlock;
46942- }
46943-
46944 /* mprotect_fixup is overkill to remove the temporary stack flags */
46945 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
46946
46947@@ -736,6 +776,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
46948 #endif
46949 current->mm->start_stack = bprm->p;
46950 ret = expand_stack(vma, stack_base);
46951+
46952+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_ASLR)
46953+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
46954+ unsigned long size, flags, vm_flags;
46955+
46956+ size = STACK_TOP - vma->vm_end;
46957+ flags = MAP_FIXED | MAP_PRIVATE;
46958+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
46959+
46960+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, flags, vm_flags, 0);
46961+
46962+#ifdef CONFIG_X86
46963+ if (!ret) {
46964+ size = mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
46965+ ret = 0 != mmap_region(NULL, 0, size, flags, vm_flags, 0);
46966+ }
46967+#endif
46968+
46969+ }
46970+#endif
46971+
46972 if (ret)
46973 ret = -EFAULT;
46974
46975@@ -771,6 +832,8 @@ struct file *open_exec(const char *name)
46976
46977 fsnotify_open(file);
46978
46979+ trace_open_exec(name);
46980+
46981 err = deny_write_access(file);
46982 if (err)
46983 goto exit;
46984@@ -794,7 +857,7 @@ int kernel_read(struct file *file, loff_t offset,
46985 old_fs = get_fs();
46986 set_fs(get_ds());
46987 /* The cast to a user pointer is valid due to the set_fs() */
46988- result = vfs_read(file, (void __user *)addr, count, &pos);
46989+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
46990 set_fs(old_fs);
46991 return result;
46992 }
46993@@ -1246,7 +1309,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
46994 }
46995 rcu_read_unlock();
46996
46997- if (p->fs->users > n_fs) {
46998+ if (atomic_read(&p->fs->users) > n_fs) {
46999 bprm->unsafe |= LSM_UNSAFE_SHARE;
47000 } else {
47001 res = -EAGAIN;
47002@@ -1449,6 +1512,28 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
47003
47004 EXPORT_SYMBOL(search_binary_handler);
47005
47006+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47007+static DEFINE_PER_CPU(u64, exec_counter);
47008+static int __init init_exec_counters(void)
47009+{
47010+ unsigned int cpu;
47011+
47012+ for_each_possible_cpu(cpu) {
47013+ per_cpu(exec_counter, cpu) = (u64)cpu;
47014+ }
47015+
47016+ return 0;
47017+}
47018+early_initcall(init_exec_counters);
47019+static inline void increment_exec_counter(void)
47020+{
47021+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
47022+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
47023+}
47024+#else
47025+static inline void increment_exec_counter(void) {}
47026+#endif
47027+
47028 /*
47029 * sys_execve() executes a new program.
47030 */
47031@@ -1457,6 +1542,11 @@ static int do_execve_common(const char *filename,
47032 struct user_arg_ptr envp,
47033 struct pt_regs *regs)
47034 {
47035+#ifdef CONFIG_GRKERNSEC
47036+ struct file *old_exec_file;
47037+ struct acl_subject_label *old_acl;
47038+ struct rlimit old_rlim[RLIM_NLIMITS];
47039+#endif
47040 struct linux_binprm *bprm;
47041 struct file *file;
47042 struct files_struct *displaced;
47043@@ -1464,6 +1554,8 @@ static int do_execve_common(const char *filename,
47044 int retval;
47045 const struct cred *cred = current_cred();
47046
47047+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
47048+
47049 /*
47050 * We move the actual failure in case of RLIMIT_NPROC excess from
47051 * set*uid() to execve() because too many poorly written programs
47052@@ -1504,12 +1596,27 @@ static int do_execve_common(const char *filename,
47053 if (IS_ERR(file))
47054 goto out_unmark;
47055
47056+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
47057+ retval = -EPERM;
47058+ goto out_file;
47059+ }
47060+
47061 sched_exec();
47062
47063 bprm->file = file;
47064 bprm->filename = filename;
47065 bprm->interp = filename;
47066
47067+ if (gr_process_user_ban()) {
47068+ retval = -EPERM;
47069+ goto out_file;
47070+ }
47071+
47072+ if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
47073+ retval = -EACCES;
47074+ goto out_file;
47075+ }
47076+
47077 retval = bprm_mm_init(bprm);
47078 if (retval)
47079 goto out_file;
47080@@ -1526,24 +1633,65 @@ static int do_execve_common(const char *filename,
47081 if (retval < 0)
47082 goto out;
47083
47084+#ifdef CONFIG_GRKERNSEC
47085+ old_acl = current->acl;
47086+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
47087+ old_exec_file = current->exec_file;
47088+ get_file(file);
47089+ current->exec_file = file;
47090+#endif
47091+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47092+ /* limit suid stack to 8MB
47093+ we saved the old limits above and will restore them if this exec fails
47094+ */
47095+ if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
47096+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
47097+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
47098+#endif
47099+
47100+ if (!gr_tpe_allow(file)) {
47101+ retval = -EACCES;
47102+ goto out_fail;
47103+ }
47104+
47105+ if (gr_check_crash_exec(file)) {
47106+ retval = -EACCES;
47107+ goto out_fail;
47108+ }
47109+
47110+ retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
47111+ bprm->unsafe);
47112+ if (retval < 0)
47113+ goto out_fail;
47114+
47115 retval = copy_strings_kernel(1, &bprm->filename, bprm);
47116 if (retval < 0)
47117- goto out;
47118+ goto out_fail;
47119
47120 bprm->exec = bprm->p;
47121 retval = copy_strings(bprm->envc, envp, bprm);
47122 if (retval < 0)
47123- goto out;
47124+ goto out_fail;
47125
47126 retval = copy_strings(bprm->argc, argv, bprm);
47127 if (retval < 0)
47128- goto out;
47129+ goto out_fail;
47130+
47131+ gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
47132+
47133+ gr_handle_exec_args(bprm, argv);
47134
47135 retval = search_binary_handler(bprm,regs);
47136 if (retval < 0)
47137- goto out;
47138+ goto out_fail;
47139+#ifdef CONFIG_GRKERNSEC
47140+ if (old_exec_file)
47141+ fput(old_exec_file);
47142+#endif
47143
47144 /* execve succeeded */
47145+
47146+ increment_exec_counter();
47147 current->fs->in_exec = 0;
47148 current->in_execve = 0;
47149 acct_update_integrals(current);
47150@@ -1552,6 +1700,14 @@ static int do_execve_common(const char *filename,
47151 put_files_struct(displaced);
47152 return retval;
47153
47154+out_fail:
47155+#ifdef CONFIG_GRKERNSEC
47156+ current->acl = old_acl;
47157+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
47158+ fput(current->exec_file);
47159+ current->exec_file = old_exec_file;
47160+#endif
47161+
47162 out:
47163 if (bprm->mm) {
47164 acct_arg_size(bprm, 0);
47165@@ -1727,3 +1883,253 @@ int kernel_execve(const char *filename,
47166 ret_from_kernel_execve(p);
47167 }
47168 #endif
47169+
47170+int pax_check_flags(unsigned long *flags)
47171+{
47172+ int retval = 0;
47173+
47174+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
47175+ if (*flags & MF_PAX_SEGMEXEC)
47176+ {
47177+ *flags &= ~MF_PAX_SEGMEXEC;
47178+ retval = -EINVAL;
47179+ }
47180+#endif
47181+
47182+ if ((*flags & MF_PAX_PAGEEXEC)
47183+
47184+#ifdef CONFIG_PAX_PAGEEXEC
47185+ && (*flags & MF_PAX_SEGMEXEC)
47186+#endif
47187+
47188+ )
47189+ {
47190+ *flags &= ~MF_PAX_PAGEEXEC;
47191+ retval = -EINVAL;
47192+ }
47193+
47194+ if ((*flags & MF_PAX_MPROTECT)
47195+
47196+#ifdef CONFIG_PAX_MPROTECT
47197+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
47198+#endif
47199+
47200+ )
47201+ {
47202+ *flags &= ~MF_PAX_MPROTECT;
47203+ retval = -EINVAL;
47204+ }
47205+
47206+ if ((*flags & MF_PAX_EMUTRAMP)
47207+
47208+#ifdef CONFIG_PAX_EMUTRAMP
47209+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
47210+#endif
47211+
47212+ )
47213+ {
47214+ *flags &= ~MF_PAX_EMUTRAMP;
47215+ retval = -EINVAL;
47216+ }
47217+
47218+ return retval;
47219+}
47220+
47221+EXPORT_SYMBOL(pax_check_flags);
47222+
47223+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
47224+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
47225+{
47226+ struct task_struct *tsk = current;
47227+ struct mm_struct *mm = current->mm;
47228+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
47229+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
47230+ char *path_exec = NULL;
47231+ char *path_fault = NULL;
47232+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
47233+ siginfo_t info = { };
47234+
47235+ if (buffer_exec && buffer_fault) {
47236+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
47237+
47238+ down_read(&mm->mmap_sem);
47239+ vma = mm->mmap;
47240+ while (vma && (!vma_exec || !vma_fault)) {
47241+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
47242+ vma_exec = vma;
47243+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
47244+ vma_fault = vma;
47245+ vma = vma->vm_next;
47246+ }
47247+ if (vma_exec) {
47248+ path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
47249+ if (IS_ERR(path_exec))
47250+ path_exec = "<path too long>";
47251+ else {
47252+ path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
47253+ if (path_exec) {
47254+ *path_exec = 0;
47255+ path_exec = buffer_exec;
47256+ } else
47257+ path_exec = "<path too long>";
47258+ }
47259+ }
47260+ if (vma_fault) {
47261+ start = vma_fault->vm_start;
47262+ end = vma_fault->vm_end;
47263+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
47264+ if (vma_fault->vm_file) {
47265+ path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
47266+ if (IS_ERR(path_fault))
47267+ path_fault = "<path too long>";
47268+ else {
47269+ path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
47270+ if (path_fault) {
47271+ *path_fault = 0;
47272+ path_fault = buffer_fault;
47273+ } else
47274+ path_fault = "<path too long>";
47275+ }
47276+ } else
47277+ path_fault = "<anonymous mapping>";
47278+ }
47279+ up_read(&mm->mmap_sem);
47280+ }
47281+ if (tsk->signal->curr_ip)
47282+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
47283+ else
47284+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
47285+ printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
47286+ from_kuid(&init_user_ns, task_uid(tsk)), from_kuid(&init_user_ns, task_euid(tsk)), pc, sp);
47287+ free_page((unsigned long)buffer_exec);
47288+ free_page((unsigned long)buffer_fault);
47289+ pax_report_insns(regs, pc, sp);
47290+ info.si_signo = SIGKILL;
47291+ info.si_errno = 0;
47292+ info.si_code = SI_KERNEL;
47293+ info.si_pid = 0;
47294+ info.si_uid = 0;
47295+ do_coredump(&info, regs);
47296+}
47297+#endif
47298+
47299+#ifdef CONFIG_PAX_REFCOUNT
47300+void pax_report_refcount_overflow(struct pt_regs *regs)
47301+{
47302+ if (current->signal->curr_ip)
47303+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
47304+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
47305+ from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
47306+ else
47307+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
47308+ from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
47309+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
47310+ show_regs(regs);
47311+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
47312+}
47313+#endif
47314+
47315+#ifdef CONFIG_PAX_USERCOPY
47316+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
47317+static noinline int check_stack_object(const void *obj, unsigned long len)
47318+{
47319+ const void * const stack = task_stack_page(current);
47320+ const void * const stackend = stack + THREAD_SIZE;
47321+
47322+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
47323+ const void *frame = NULL;
47324+ const void *oldframe;
47325+#endif
47326+
47327+ if (obj + len < obj)
47328+ return -1;
47329+
47330+ if (obj + len <= stack || stackend <= obj)
47331+ return 0;
47332+
47333+ if (obj < stack || stackend < obj + len)
47334+ return -1;
47335+
47336+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
47337+ oldframe = __builtin_frame_address(1);
47338+ if (oldframe)
47339+ frame = __builtin_frame_address(2);
47340+ /*
47341+ low ----------------------------------------------> high
47342+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
47343+ ^----------------^
47344+ allow copies only within here
47345+ */
47346+ while (stack <= frame && frame < stackend) {
47347+ /* if obj + len extends past the last frame, this
47348+ check won't pass and the next frame will be 0,
47349+ causing us to bail out and correctly report
47350+ the copy as invalid
47351+ */
47352+ if (obj + len <= frame)
47353+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
47354+ oldframe = frame;
47355+ frame = *(const void * const *)frame;
47356+ }
47357+ return -1;
47358+#else
47359+ return 1;
47360+#endif
47361+}
47362+
47363+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
47364+{
47365+ if (current->signal->curr_ip)
47366+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
47367+ &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
47368+ else
47369+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
47370+ to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
47371+ dump_stack();
47372+ gr_handle_kernel_exploit();
47373+ do_group_exit(SIGKILL);
47374+}
47375+#endif
47376+
47377+void __check_object_size(const void *ptr, unsigned long n, bool to)
47378+{
47379+
47380+#ifdef CONFIG_PAX_USERCOPY
47381+ const char *type;
47382+
47383+ if (!n)
47384+ return;
47385+
47386+ type = check_heap_object(ptr, n);
47387+ if (!type) {
47388+ if (check_stack_object(ptr, n) != -1)
47389+ return;
47390+ type = "<process stack>";
47391+ }
47392+
47393+ pax_report_usercopy(ptr, n, to, type);
47394+#endif
47395+
47396+}
47397+EXPORT_SYMBOL(__check_object_size);
47398+
47399+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
47400+void pax_track_stack(void)
47401+{
47402+ unsigned long sp = (unsigned long)&sp;
47403+ if (sp < current_thread_info()->lowest_stack &&
47404+ sp > (unsigned long)task_stack_page(current))
47405+ current_thread_info()->lowest_stack = sp;
47406+}
47407+EXPORT_SYMBOL(pax_track_stack);
47408+#endif
47409+
47410+#ifdef CONFIG_PAX_SIZE_OVERFLOW
47411+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
47412+{
47413+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
47414+ dump_stack();
47415+ do_group_exit(SIGKILL);
47416+}
47417+EXPORT_SYMBOL(report_size_overflow);
47418+#endif
47419diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
47420index 2616d0e..2ffdec9 100644
47421--- a/fs/ext2/balloc.c
47422+++ b/fs/ext2/balloc.c
47423@@ -1190,10 +1190,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
47424
47425 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
47426 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
47427- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
47428+ if (free_blocks < root_blocks + 1 &&
47429 !uid_eq(sbi->s_resuid, current_fsuid()) &&
47430 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
47431- !in_group_p (sbi->s_resgid))) {
47432+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
47433 return 0;
47434 }
47435 return 1;
47436diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
47437index 22548f5..41521d8 100644
47438--- a/fs/ext3/balloc.c
47439+++ b/fs/ext3/balloc.c
47440@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
47441
47442 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
47443 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
47444- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
47445+ if (free_blocks < root_blocks + 1 &&
47446 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
47447 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
47448- !in_group_p (sbi->s_resgid))) {
47449+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
47450 return 0;
47451 }
47452 return 1;
47453diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
47454index cf18217..8f6b9c3 100644
47455--- a/fs/ext4/balloc.c
47456+++ b/fs/ext4/balloc.c
47457@@ -498,8 +498,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
47458 /* Hm, nope. Are (enough) root reserved clusters available? */
47459 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
47460 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
47461- capable(CAP_SYS_RESOURCE) ||
47462- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
47463+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
47464+ capable_nolog(CAP_SYS_RESOURCE)) {
47465
47466 if (free_clusters >= (nclusters + dirty_clusters))
47467 return 1;
47468diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
47469index 3c20de1..6ff2460 100644
47470--- a/fs/ext4/ext4.h
47471+++ b/fs/ext4/ext4.h
47472@@ -1247,19 +1247,19 @@ struct ext4_sb_info {
47473 unsigned long s_mb_last_start;
47474
47475 /* stats for buddy allocator */
47476- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
47477- atomic_t s_bal_success; /* we found long enough chunks */
47478- atomic_t s_bal_allocated; /* in blocks */
47479- atomic_t s_bal_ex_scanned; /* total extents scanned */
47480- atomic_t s_bal_goals; /* goal hits */
47481- atomic_t s_bal_breaks; /* too long searches */
47482- atomic_t s_bal_2orders; /* 2^order hits */
47483+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
47484+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
47485+ atomic_unchecked_t s_bal_allocated; /* in blocks */
47486+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
47487+ atomic_unchecked_t s_bal_goals; /* goal hits */
47488+ atomic_unchecked_t s_bal_breaks; /* too long searches */
47489+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
47490 spinlock_t s_bal_lock;
47491 unsigned long s_mb_buddies_generated;
47492 unsigned long long s_mb_generation_time;
47493- atomic_t s_mb_lost_chunks;
47494- atomic_t s_mb_preallocated;
47495- atomic_t s_mb_discarded;
47496+ atomic_unchecked_t s_mb_lost_chunks;
47497+ atomic_unchecked_t s_mb_preallocated;
47498+ atomic_unchecked_t s_mb_discarded;
47499 atomic_t s_lock_busy;
47500
47501 /* locality groups */
47502diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
47503index 526e553..3f2de85 100644
47504--- a/fs/ext4/mballoc.c
47505+++ b/fs/ext4/mballoc.c
47506@@ -1747,7 +1747,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
47507 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
47508
47509 if (EXT4_SB(sb)->s_mb_stats)
47510- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
47511+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
47512
47513 break;
47514 }
47515@@ -2044,7 +2044,7 @@ repeat:
47516 ac->ac_status = AC_STATUS_CONTINUE;
47517 ac->ac_flags |= EXT4_MB_HINT_FIRST;
47518 cr = 3;
47519- atomic_inc(&sbi->s_mb_lost_chunks);
47520+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
47521 goto repeat;
47522 }
47523 }
47524@@ -2552,25 +2552,25 @@ int ext4_mb_release(struct super_block *sb)
47525 if (sbi->s_mb_stats) {
47526 ext4_msg(sb, KERN_INFO,
47527 "mballoc: %u blocks %u reqs (%u success)",
47528- atomic_read(&sbi->s_bal_allocated),
47529- atomic_read(&sbi->s_bal_reqs),
47530- atomic_read(&sbi->s_bal_success));
47531+ atomic_read_unchecked(&sbi->s_bal_allocated),
47532+ atomic_read_unchecked(&sbi->s_bal_reqs),
47533+ atomic_read_unchecked(&sbi->s_bal_success));
47534 ext4_msg(sb, KERN_INFO,
47535 "mballoc: %u extents scanned, %u goal hits, "
47536 "%u 2^N hits, %u breaks, %u lost",
47537- atomic_read(&sbi->s_bal_ex_scanned),
47538- atomic_read(&sbi->s_bal_goals),
47539- atomic_read(&sbi->s_bal_2orders),
47540- atomic_read(&sbi->s_bal_breaks),
47541- atomic_read(&sbi->s_mb_lost_chunks));
47542+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
47543+ atomic_read_unchecked(&sbi->s_bal_goals),
47544+ atomic_read_unchecked(&sbi->s_bal_2orders),
47545+ atomic_read_unchecked(&sbi->s_bal_breaks),
47546+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
47547 ext4_msg(sb, KERN_INFO,
47548 "mballoc: %lu generated and it took %Lu",
47549 sbi->s_mb_buddies_generated,
47550 sbi->s_mb_generation_time);
47551 ext4_msg(sb, KERN_INFO,
47552 "mballoc: %u preallocated, %u discarded",
47553- atomic_read(&sbi->s_mb_preallocated),
47554- atomic_read(&sbi->s_mb_discarded));
47555+ atomic_read_unchecked(&sbi->s_mb_preallocated),
47556+ atomic_read_unchecked(&sbi->s_mb_discarded));
47557 }
47558
47559 free_percpu(sbi->s_locality_groups);
47560@@ -3052,16 +3052,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
47561 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
47562
47563 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
47564- atomic_inc(&sbi->s_bal_reqs);
47565- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
47566+ atomic_inc_unchecked(&sbi->s_bal_reqs);
47567+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
47568 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
47569- atomic_inc(&sbi->s_bal_success);
47570- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
47571+ atomic_inc_unchecked(&sbi->s_bal_success);
47572+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
47573 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
47574 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
47575- atomic_inc(&sbi->s_bal_goals);
47576+ atomic_inc_unchecked(&sbi->s_bal_goals);
47577 if (ac->ac_found > sbi->s_mb_max_to_scan)
47578- atomic_inc(&sbi->s_bal_breaks);
47579+ atomic_inc_unchecked(&sbi->s_bal_breaks);
47580 }
47581
47582 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
47583@@ -3461,7 +3461,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
47584 trace_ext4_mb_new_inode_pa(ac, pa);
47585
47586 ext4_mb_use_inode_pa(ac, pa);
47587- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
47588+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
47589
47590 ei = EXT4_I(ac->ac_inode);
47591 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
47592@@ -3521,7 +3521,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
47593 trace_ext4_mb_new_group_pa(ac, pa);
47594
47595 ext4_mb_use_group_pa(ac, pa);
47596- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
47597+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
47598
47599 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
47600 lg = ac->ac_lg;
47601@@ -3610,7 +3610,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
47602 * from the bitmap and continue.
47603 */
47604 }
47605- atomic_add(free, &sbi->s_mb_discarded);
47606+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
47607
47608 return err;
47609 }
47610@@ -3628,7 +3628,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
47611 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
47612 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
47613 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
47614- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
47615+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
47616 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
47617
47618 return 0;
47619diff --git a/fs/ext4/super.c b/fs/ext4/super.c
47620index d59b351..775f8c8 100644
47621--- a/fs/ext4/super.c
47622+++ b/fs/ext4/super.c
47623@@ -3212,7 +3212,6 @@ int ext4_calculate_overhead(struct super_block *sb)
47624 ext4_fsblk_t overhead = 0;
47625 char *buf = (char *) get_zeroed_page(GFP_KERNEL);
47626
47627- memset(buf, 0, PAGE_SIZE);
47628 if (!buf)
47629 return -ENOMEM;
47630
47631diff --git a/fs/fcntl.c b/fs/fcntl.c
47632index 71a600a..20d87b1 100644
47633--- a/fs/fcntl.c
47634+++ b/fs/fcntl.c
47635@@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
47636 if (err)
47637 return err;
47638
47639+ if (gr_handle_chroot_fowner(pid, type))
47640+ return -ENOENT;
47641+ if (gr_check_protected_task_fowner(pid, type))
47642+ return -EACCES;
47643+
47644 f_modown(filp, pid, type, force);
47645 return 0;
47646 }
47647diff --git a/fs/fhandle.c b/fs/fhandle.c
47648index f775bfd..629bd4c 100644
47649--- a/fs/fhandle.c
47650+++ b/fs/fhandle.c
47651@@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
47652 } else
47653 retval = 0;
47654 /* copy the mount id */
47655- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
47656- sizeof(*mnt_id)) ||
47657+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
47658 copy_to_user(ufh, handle,
47659 sizeof(struct file_handle) + handle_bytes))
47660 retval = -EFAULT;
47661diff --git a/fs/fifo.c b/fs/fifo.c
47662index cf6f434..3d7942c 100644
47663--- a/fs/fifo.c
47664+++ b/fs/fifo.c
47665@@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
47666 */
47667 filp->f_op = &read_pipefifo_fops;
47668 pipe->r_counter++;
47669- if (pipe->readers++ == 0)
47670+ if (atomic_inc_return(&pipe->readers) == 1)
47671 wake_up_partner(inode);
47672
47673- if (!pipe->writers) {
47674+ if (!atomic_read(&pipe->writers)) {
47675 if ((filp->f_flags & O_NONBLOCK)) {
47676 /* suppress POLLHUP until we have
47677 * seen a writer */
47678@@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
47679 * errno=ENXIO when there is no process reading the FIFO.
47680 */
47681 ret = -ENXIO;
47682- if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
47683+ if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
47684 goto err;
47685
47686 filp->f_op = &write_pipefifo_fops;
47687 pipe->w_counter++;
47688- if (!pipe->writers++)
47689+ if (atomic_inc_return(&pipe->writers) == 1)
47690 wake_up_partner(inode);
47691
47692- if (!pipe->readers) {
47693+ if (!atomic_read(&pipe->readers)) {
47694 if (wait_for_partner(inode, &pipe->r_counter))
47695 goto err_wr;
47696 }
47697@@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
47698 */
47699 filp->f_op = &rdwr_pipefifo_fops;
47700
47701- pipe->readers++;
47702- pipe->writers++;
47703+ atomic_inc(&pipe->readers);
47704+ atomic_inc(&pipe->writers);
47705 pipe->r_counter++;
47706 pipe->w_counter++;
47707- if (pipe->readers == 1 || pipe->writers == 1)
47708+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
47709 wake_up_partner(inode);
47710 break;
47711
47712@@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
47713 return 0;
47714
47715 err_rd:
47716- if (!--pipe->readers)
47717+ if (atomic_dec_and_test(&pipe->readers))
47718 wake_up_interruptible(&pipe->wait);
47719 ret = -ERESTARTSYS;
47720 goto err;
47721
47722 err_wr:
47723- if (!--pipe->writers)
47724+ if (atomic_dec_and_test(&pipe->writers))
47725 wake_up_interruptible(&pipe->wait);
47726 ret = -ERESTARTSYS;
47727 goto err;
47728
47729 err:
47730- if (!pipe->readers && !pipe->writers)
47731+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
47732 free_pipe_info(inode);
47733
47734 err_nocleanup:
47735diff --git a/fs/file.c b/fs/file.c
47736index eff2316..8c8930c 100644
47737--- a/fs/file.c
47738+++ b/fs/file.c
47739@@ -16,6 +16,7 @@
47740 #include <linux/slab.h>
47741 #include <linux/vmalloc.h>
47742 #include <linux/file.h>
47743+#include <linux/security.h>
47744 #include <linux/fdtable.h>
47745 #include <linux/bitops.h>
47746 #include <linux/interrupt.h>
47747@@ -898,6 +899,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
47748 if (!file)
47749 return __close_fd(files, fd);
47750
47751+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
47752 if (fd >= rlimit(RLIMIT_NOFILE))
47753 return -EBADF;
47754
47755@@ -924,6 +926,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
47756 if (unlikely(oldfd == newfd))
47757 return -EINVAL;
47758
47759+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
47760 if (newfd >= rlimit(RLIMIT_NOFILE))
47761 return -EBADF;
47762
47763@@ -979,6 +982,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
47764 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
47765 {
47766 int err;
47767+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
47768 if (from >= rlimit(RLIMIT_NOFILE))
47769 return -EINVAL;
47770 err = alloc_fd(from, flags);
47771diff --git a/fs/filesystems.c b/fs/filesystems.c
47772index da165f6..3671bdb 100644
47773--- a/fs/filesystems.c
47774+++ b/fs/filesystems.c
47775@@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
47776 int len = dot ? dot - name : strlen(name);
47777
47778 fs = __get_fs_type(name, len);
47779+
47780+#ifdef CONFIG_GRKERNSEC_MODHARDEN
47781+ if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
47782+#else
47783 if (!fs && (request_module("%.*s", len, name) == 0))
47784+#endif
47785 fs = __get_fs_type(name, len);
47786
47787 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
47788diff --git a/fs/fs_struct.c b/fs/fs_struct.c
47789index 5df4775..9d9336f 100644
47790--- a/fs/fs_struct.c
47791+++ b/fs/fs_struct.c
47792@@ -4,6 +4,7 @@
47793 #include <linux/path.h>
47794 #include <linux/slab.h>
47795 #include <linux/fs_struct.h>
47796+#include <linux/grsecurity.h>
47797 #include "internal.h"
47798
47799 /*
47800@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
47801 write_seqcount_begin(&fs->seq);
47802 old_root = fs->root;
47803 fs->root = *path;
47804+ gr_set_chroot_entries(current, path);
47805 write_seqcount_end(&fs->seq);
47806 spin_unlock(&fs->lock);
47807 if (old_root.dentry)
47808@@ -53,6 +55,21 @@ static inline int replace_path(struct path *p, const struct path *old, const str
47809 return 1;
47810 }
47811
47812+static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
47813+{
47814+ if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
47815+ return 0;
47816+ *p = *new;
47817+
47818+ /* This function is only called from pivot_root(). Leave our
47819+ gr_chroot_dentry and is_chrooted flags as-is, so that a
47820+ pivoted root isn't treated as a chroot
47821+ */
47822+ //gr_set_chroot_entries(task, new);
47823+
47824+ return 1;
47825+}
47826+
47827 void chroot_fs_refs(struct path *old_root, struct path *new_root)
47828 {
47829 struct task_struct *g, *p;
47830@@ -67,7 +84,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
47831 int hits = 0;
47832 spin_lock(&fs->lock);
47833 write_seqcount_begin(&fs->seq);
47834- hits += replace_path(&fs->root, old_root, new_root);
47835+ hits += replace_root_path(p, &fs->root, old_root, new_root);
47836 hits += replace_path(&fs->pwd, old_root, new_root);
47837 write_seqcount_end(&fs->seq);
47838 while (hits--) {
47839@@ -99,7 +116,8 @@ void exit_fs(struct task_struct *tsk)
47840 task_lock(tsk);
47841 spin_lock(&fs->lock);
47842 tsk->fs = NULL;
47843- kill = !--fs->users;
47844+ gr_clear_chroot_entries(tsk);
47845+ kill = !atomic_dec_return(&fs->users);
47846 spin_unlock(&fs->lock);
47847 task_unlock(tsk);
47848 if (kill)
47849@@ -112,7 +130,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
47850 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
47851 /* We don't need to lock fs - think why ;-) */
47852 if (fs) {
47853- fs->users = 1;
47854+ atomic_set(&fs->users, 1);
47855 fs->in_exec = 0;
47856 spin_lock_init(&fs->lock);
47857 seqcount_init(&fs->seq);
47858@@ -121,6 +139,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
47859 spin_lock(&old->lock);
47860 fs->root = old->root;
47861 path_get(&fs->root);
47862+ /* instead of calling gr_set_chroot_entries here,
47863+ we call it from every caller of this function
47864+ */
47865 fs->pwd = old->pwd;
47866 path_get(&fs->pwd);
47867 spin_unlock(&old->lock);
47868@@ -139,8 +160,9 @@ int unshare_fs_struct(void)
47869
47870 task_lock(current);
47871 spin_lock(&fs->lock);
47872- kill = !--fs->users;
47873+ kill = !atomic_dec_return(&fs->users);
47874 current->fs = new_fs;
47875+ gr_set_chroot_entries(current, &new_fs->root);
47876 spin_unlock(&fs->lock);
47877 task_unlock(current);
47878
47879@@ -153,13 +175,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
47880
47881 int current_umask(void)
47882 {
47883- return current->fs->umask;
47884+ return current->fs->umask | gr_acl_umask();
47885 }
47886 EXPORT_SYMBOL(current_umask);
47887
47888 /* to be mentioned only in INIT_TASK */
47889 struct fs_struct init_fs = {
47890- .users = 1,
47891+ .users = ATOMIC_INIT(1),
47892 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
47893 .seq = SEQCNT_ZERO,
47894 .umask = 0022,
47895@@ -175,12 +197,13 @@ void daemonize_fs_struct(void)
47896 task_lock(current);
47897
47898 spin_lock(&init_fs.lock);
47899- init_fs.users++;
47900+ atomic_inc(&init_fs.users);
47901 spin_unlock(&init_fs.lock);
47902
47903 spin_lock(&fs->lock);
47904 current->fs = &init_fs;
47905- kill = !--fs->users;
47906+ gr_set_chroot_entries(current, &current->fs->root);
47907+ kill = !atomic_dec_return(&fs->users);
47908 spin_unlock(&fs->lock);
47909
47910 task_unlock(current);
47911diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
47912index 9905350..02eaec4 100644
47913--- a/fs/fscache/cookie.c
47914+++ b/fs/fscache/cookie.c
47915@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
47916 parent ? (char *) parent->def->name : "<no-parent>",
47917 def->name, netfs_data);
47918
47919- fscache_stat(&fscache_n_acquires);
47920+ fscache_stat_unchecked(&fscache_n_acquires);
47921
47922 /* if there's no parent cookie, then we don't create one here either */
47923 if (!parent) {
47924- fscache_stat(&fscache_n_acquires_null);
47925+ fscache_stat_unchecked(&fscache_n_acquires_null);
47926 _leave(" [no parent]");
47927 return NULL;
47928 }
47929@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
47930 /* allocate and initialise a cookie */
47931 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
47932 if (!cookie) {
47933- fscache_stat(&fscache_n_acquires_oom);
47934+ fscache_stat_unchecked(&fscache_n_acquires_oom);
47935 _leave(" [ENOMEM]");
47936 return NULL;
47937 }
47938@@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
47939
47940 switch (cookie->def->type) {
47941 case FSCACHE_COOKIE_TYPE_INDEX:
47942- fscache_stat(&fscache_n_cookie_index);
47943+ fscache_stat_unchecked(&fscache_n_cookie_index);
47944 break;
47945 case FSCACHE_COOKIE_TYPE_DATAFILE:
47946- fscache_stat(&fscache_n_cookie_data);
47947+ fscache_stat_unchecked(&fscache_n_cookie_data);
47948 break;
47949 default:
47950- fscache_stat(&fscache_n_cookie_special);
47951+ fscache_stat_unchecked(&fscache_n_cookie_special);
47952 break;
47953 }
47954
47955@@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
47956 if (fscache_acquire_non_index_cookie(cookie) < 0) {
47957 atomic_dec(&parent->n_children);
47958 __fscache_cookie_put(cookie);
47959- fscache_stat(&fscache_n_acquires_nobufs);
47960+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
47961 _leave(" = NULL");
47962 return NULL;
47963 }
47964 }
47965
47966- fscache_stat(&fscache_n_acquires_ok);
47967+ fscache_stat_unchecked(&fscache_n_acquires_ok);
47968 _leave(" = %p", cookie);
47969 return cookie;
47970 }
47971@@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
47972 cache = fscache_select_cache_for_object(cookie->parent);
47973 if (!cache) {
47974 up_read(&fscache_addremove_sem);
47975- fscache_stat(&fscache_n_acquires_no_cache);
47976+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
47977 _leave(" = -ENOMEDIUM [no cache]");
47978 return -ENOMEDIUM;
47979 }
47980@@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
47981 object = cache->ops->alloc_object(cache, cookie);
47982 fscache_stat_d(&fscache_n_cop_alloc_object);
47983 if (IS_ERR(object)) {
47984- fscache_stat(&fscache_n_object_no_alloc);
47985+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
47986 ret = PTR_ERR(object);
47987 goto error;
47988 }
47989
47990- fscache_stat(&fscache_n_object_alloc);
47991+ fscache_stat_unchecked(&fscache_n_object_alloc);
47992
47993 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
47994
47995@@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
47996 struct fscache_object *object;
47997 struct hlist_node *_p;
47998
47999- fscache_stat(&fscache_n_updates);
48000+ fscache_stat_unchecked(&fscache_n_updates);
48001
48002 if (!cookie) {
48003- fscache_stat(&fscache_n_updates_null);
48004+ fscache_stat_unchecked(&fscache_n_updates_null);
48005 _leave(" [no cookie]");
48006 return;
48007 }
48008@@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
48009 struct fscache_object *object;
48010 unsigned long event;
48011
48012- fscache_stat(&fscache_n_relinquishes);
48013+ fscache_stat_unchecked(&fscache_n_relinquishes);
48014 if (retire)
48015- fscache_stat(&fscache_n_relinquishes_retire);
48016+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
48017
48018 if (!cookie) {
48019- fscache_stat(&fscache_n_relinquishes_null);
48020+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
48021 _leave(" [no cookie]");
48022 return;
48023 }
48024@@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
48025
48026 /* wait for the cookie to finish being instantiated (or to fail) */
48027 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
48028- fscache_stat(&fscache_n_relinquishes_waitcrt);
48029+ fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
48030 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
48031 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
48032 }
48033diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
48034index f6aad48..88dcf26 100644
48035--- a/fs/fscache/internal.h
48036+++ b/fs/fscache/internal.h
48037@@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
48038 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
48039 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
48040
48041-extern atomic_t fscache_n_op_pend;
48042-extern atomic_t fscache_n_op_run;
48043-extern atomic_t fscache_n_op_enqueue;
48044-extern atomic_t fscache_n_op_deferred_release;
48045-extern atomic_t fscache_n_op_release;
48046-extern atomic_t fscache_n_op_gc;
48047-extern atomic_t fscache_n_op_cancelled;
48048-extern atomic_t fscache_n_op_rejected;
48049+extern atomic_unchecked_t fscache_n_op_pend;
48050+extern atomic_unchecked_t fscache_n_op_run;
48051+extern atomic_unchecked_t fscache_n_op_enqueue;
48052+extern atomic_unchecked_t fscache_n_op_deferred_release;
48053+extern atomic_unchecked_t fscache_n_op_release;
48054+extern atomic_unchecked_t fscache_n_op_gc;
48055+extern atomic_unchecked_t fscache_n_op_cancelled;
48056+extern atomic_unchecked_t fscache_n_op_rejected;
48057
48058-extern atomic_t fscache_n_attr_changed;
48059-extern atomic_t fscache_n_attr_changed_ok;
48060-extern atomic_t fscache_n_attr_changed_nobufs;
48061-extern atomic_t fscache_n_attr_changed_nomem;
48062-extern atomic_t fscache_n_attr_changed_calls;
48063+extern atomic_unchecked_t fscache_n_attr_changed;
48064+extern atomic_unchecked_t fscache_n_attr_changed_ok;
48065+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
48066+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
48067+extern atomic_unchecked_t fscache_n_attr_changed_calls;
48068
48069-extern atomic_t fscache_n_allocs;
48070-extern atomic_t fscache_n_allocs_ok;
48071-extern atomic_t fscache_n_allocs_wait;
48072-extern atomic_t fscache_n_allocs_nobufs;
48073-extern atomic_t fscache_n_allocs_intr;
48074-extern atomic_t fscache_n_allocs_object_dead;
48075-extern atomic_t fscache_n_alloc_ops;
48076-extern atomic_t fscache_n_alloc_op_waits;
48077+extern atomic_unchecked_t fscache_n_allocs;
48078+extern atomic_unchecked_t fscache_n_allocs_ok;
48079+extern atomic_unchecked_t fscache_n_allocs_wait;
48080+extern atomic_unchecked_t fscache_n_allocs_nobufs;
48081+extern atomic_unchecked_t fscache_n_allocs_intr;
48082+extern atomic_unchecked_t fscache_n_allocs_object_dead;
48083+extern atomic_unchecked_t fscache_n_alloc_ops;
48084+extern atomic_unchecked_t fscache_n_alloc_op_waits;
48085
48086-extern atomic_t fscache_n_retrievals;
48087-extern atomic_t fscache_n_retrievals_ok;
48088-extern atomic_t fscache_n_retrievals_wait;
48089-extern atomic_t fscache_n_retrievals_nodata;
48090-extern atomic_t fscache_n_retrievals_nobufs;
48091-extern atomic_t fscache_n_retrievals_intr;
48092-extern atomic_t fscache_n_retrievals_nomem;
48093-extern atomic_t fscache_n_retrievals_object_dead;
48094-extern atomic_t fscache_n_retrieval_ops;
48095-extern atomic_t fscache_n_retrieval_op_waits;
48096+extern atomic_unchecked_t fscache_n_retrievals;
48097+extern atomic_unchecked_t fscache_n_retrievals_ok;
48098+extern atomic_unchecked_t fscache_n_retrievals_wait;
48099+extern atomic_unchecked_t fscache_n_retrievals_nodata;
48100+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
48101+extern atomic_unchecked_t fscache_n_retrievals_intr;
48102+extern atomic_unchecked_t fscache_n_retrievals_nomem;
48103+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
48104+extern atomic_unchecked_t fscache_n_retrieval_ops;
48105+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
48106
48107-extern atomic_t fscache_n_stores;
48108-extern atomic_t fscache_n_stores_ok;
48109-extern atomic_t fscache_n_stores_again;
48110-extern atomic_t fscache_n_stores_nobufs;
48111-extern atomic_t fscache_n_stores_oom;
48112-extern atomic_t fscache_n_store_ops;
48113-extern atomic_t fscache_n_store_calls;
48114-extern atomic_t fscache_n_store_pages;
48115-extern atomic_t fscache_n_store_radix_deletes;
48116-extern atomic_t fscache_n_store_pages_over_limit;
48117+extern atomic_unchecked_t fscache_n_stores;
48118+extern atomic_unchecked_t fscache_n_stores_ok;
48119+extern atomic_unchecked_t fscache_n_stores_again;
48120+extern atomic_unchecked_t fscache_n_stores_nobufs;
48121+extern atomic_unchecked_t fscache_n_stores_oom;
48122+extern atomic_unchecked_t fscache_n_store_ops;
48123+extern atomic_unchecked_t fscache_n_store_calls;
48124+extern atomic_unchecked_t fscache_n_store_pages;
48125+extern atomic_unchecked_t fscache_n_store_radix_deletes;
48126+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
48127
48128-extern atomic_t fscache_n_store_vmscan_not_storing;
48129-extern atomic_t fscache_n_store_vmscan_gone;
48130-extern atomic_t fscache_n_store_vmscan_busy;
48131-extern atomic_t fscache_n_store_vmscan_cancelled;
48132+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
48133+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
48134+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
48135+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
48136
48137-extern atomic_t fscache_n_marks;
48138-extern atomic_t fscache_n_uncaches;
48139+extern atomic_unchecked_t fscache_n_marks;
48140+extern atomic_unchecked_t fscache_n_uncaches;
48141
48142-extern atomic_t fscache_n_acquires;
48143-extern atomic_t fscache_n_acquires_null;
48144-extern atomic_t fscache_n_acquires_no_cache;
48145-extern atomic_t fscache_n_acquires_ok;
48146-extern atomic_t fscache_n_acquires_nobufs;
48147-extern atomic_t fscache_n_acquires_oom;
48148+extern atomic_unchecked_t fscache_n_acquires;
48149+extern atomic_unchecked_t fscache_n_acquires_null;
48150+extern atomic_unchecked_t fscache_n_acquires_no_cache;
48151+extern atomic_unchecked_t fscache_n_acquires_ok;
48152+extern atomic_unchecked_t fscache_n_acquires_nobufs;
48153+extern atomic_unchecked_t fscache_n_acquires_oom;
48154
48155-extern atomic_t fscache_n_updates;
48156-extern atomic_t fscache_n_updates_null;
48157-extern atomic_t fscache_n_updates_run;
48158+extern atomic_unchecked_t fscache_n_updates;
48159+extern atomic_unchecked_t fscache_n_updates_null;
48160+extern atomic_unchecked_t fscache_n_updates_run;
48161
48162-extern atomic_t fscache_n_relinquishes;
48163-extern atomic_t fscache_n_relinquishes_null;
48164-extern atomic_t fscache_n_relinquishes_waitcrt;
48165-extern atomic_t fscache_n_relinquishes_retire;
48166+extern atomic_unchecked_t fscache_n_relinquishes;
48167+extern atomic_unchecked_t fscache_n_relinquishes_null;
48168+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
48169+extern atomic_unchecked_t fscache_n_relinquishes_retire;
48170
48171-extern atomic_t fscache_n_cookie_index;
48172-extern atomic_t fscache_n_cookie_data;
48173-extern atomic_t fscache_n_cookie_special;
48174+extern atomic_unchecked_t fscache_n_cookie_index;
48175+extern atomic_unchecked_t fscache_n_cookie_data;
48176+extern atomic_unchecked_t fscache_n_cookie_special;
48177
48178-extern atomic_t fscache_n_object_alloc;
48179-extern atomic_t fscache_n_object_no_alloc;
48180-extern atomic_t fscache_n_object_lookups;
48181-extern atomic_t fscache_n_object_lookups_negative;
48182-extern atomic_t fscache_n_object_lookups_positive;
48183-extern atomic_t fscache_n_object_lookups_timed_out;
48184-extern atomic_t fscache_n_object_created;
48185-extern atomic_t fscache_n_object_avail;
48186-extern atomic_t fscache_n_object_dead;
48187+extern atomic_unchecked_t fscache_n_object_alloc;
48188+extern atomic_unchecked_t fscache_n_object_no_alloc;
48189+extern atomic_unchecked_t fscache_n_object_lookups;
48190+extern atomic_unchecked_t fscache_n_object_lookups_negative;
48191+extern atomic_unchecked_t fscache_n_object_lookups_positive;
48192+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
48193+extern atomic_unchecked_t fscache_n_object_created;
48194+extern atomic_unchecked_t fscache_n_object_avail;
48195+extern atomic_unchecked_t fscache_n_object_dead;
48196
48197-extern atomic_t fscache_n_checkaux_none;
48198-extern atomic_t fscache_n_checkaux_okay;
48199-extern atomic_t fscache_n_checkaux_update;
48200-extern atomic_t fscache_n_checkaux_obsolete;
48201+extern atomic_unchecked_t fscache_n_checkaux_none;
48202+extern atomic_unchecked_t fscache_n_checkaux_okay;
48203+extern atomic_unchecked_t fscache_n_checkaux_update;
48204+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
48205
48206 extern atomic_t fscache_n_cop_alloc_object;
48207 extern atomic_t fscache_n_cop_lookup_object;
48208@@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
48209 atomic_inc(stat);
48210 }
48211
48212+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
48213+{
48214+ atomic_inc_unchecked(stat);
48215+}
48216+
48217 static inline void fscache_stat_d(atomic_t *stat)
48218 {
48219 atomic_dec(stat);
48220@@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
48221
48222 #define __fscache_stat(stat) (NULL)
48223 #define fscache_stat(stat) do {} while (0)
48224+#define fscache_stat_unchecked(stat) do {} while (0)
48225 #define fscache_stat_d(stat) do {} while (0)
48226 #endif
48227
48228diff --git a/fs/fscache/object.c b/fs/fscache/object.c
48229index b6b897c..0ffff9c 100644
48230--- a/fs/fscache/object.c
48231+++ b/fs/fscache/object.c
48232@@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
48233 /* update the object metadata on disk */
48234 case FSCACHE_OBJECT_UPDATING:
48235 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
48236- fscache_stat(&fscache_n_updates_run);
48237+ fscache_stat_unchecked(&fscache_n_updates_run);
48238 fscache_stat(&fscache_n_cop_update_object);
48239 object->cache->ops->update_object(object);
48240 fscache_stat_d(&fscache_n_cop_update_object);
48241@@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
48242 spin_lock(&object->lock);
48243 object->state = FSCACHE_OBJECT_DEAD;
48244 spin_unlock(&object->lock);
48245- fscache_stat(&fscache_n_object_dead);
48246+ fscache_stat_unchecked(&fscache_n_object_dead);
48247 goto terminal_transit;
48248
48249 /* handle the parent cache of this object being withdrawn from
48250@@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
48251 spin_lock(&object->lock);
48252 object->state = FSCACHE_OBJECT_DEAD;
48253 spin_unlock(&object->lock);
48254- fscache_stat(&fscache_n_object_dead);
48255+ fscache_stat_unchecked(&fscache_n_object_dead);
48256 goto terminal_transit;
48257
48258 /* complain about the object being woken up once it is
48259@@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
48260 parent->cookie->def->name, cookie->def->name,
48261 object->cache->tag->name);
48262
48263- fscache_stat(&fscache_n_object_lookups);
48264+ fscache_stat_unchecked(&fscache_n_object_lookups);
48265 fscache_stat(&fscache_n_cop_lookup_object);
48266 ret = object->cache->ops->lookup_object(object);
48267 fscache_stat_d(&fscache_n_cop_lookup_object);
48268@@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
48269 if (ret == -ETIMEDOUT) {
48270 /* probably stuck behind another object, so move this one to
48271 * the back of the queue */
48272- fscache_stat(&fscache_n_object_lookups_timed_out);
48273+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
48274 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
48275 }
48276
48277@@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
48278
48279 spin_lock(&object->lock);
48280 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
48281- fscache_stat(&fscache_n_object_lookups_negative);
48282+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
48283
48284 /* transit here to allow write requests to begin stacking up
48285 * and read requests to begin returning ENODATA */
48286@@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
48287 * result, in which case there may be data available */
48288 spin_lock(&object->lock);
48289 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
48290- fscache_stat(&fscache_n_object_lookups_positive);
48291+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
48292
48293 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
48294
48295@@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
48296 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
48297 } else {
48298 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
48299- fscache_stat(&fscache_n_object_created);
48300+ fscache_stat_unchecked(&fscache_n_object_created);
48301
48302 object->state = FSCACHE_OBJECT_AVAILABLE;
48303 spin_unlock(&object->lock);
48304@@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
48305 fscache_enqueue_dependents(object);
48306
48307 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
48308- fscache_stat(&fscache_n_object_avail);
48309+ fscache_stat_unchecked(&fscache_n_object_avail);
48310
48311 _leave("");
48312 }
48313@@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
48314 enum fscache_checkaux result;
48315
48316 if (!object->cookie->def->check_aux) {
48317- fscache_stat(&fscache_n_checkaux_none);
48318+ fscache_stat_unchecked(&fscache_n_checkaux_none);
48319 return FSCACHE_CHECKAUX_OKAY;
48320 }
48321
48322@@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
48323 switch (result) {
48324 /* entry okay as is */
48325 case FSCACHE_CHECKAUX_OKAY:
48326- fscache_stat(&fscache_n_checkaux_okay);
48327+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
48328 break;
48329
48330 /* entry requires update */
48331 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
48332- fscache_stat(&fscache_n_checkaux_update);
48333+ fscache_stat_unchecked(&fscache_n_checkaux_update);
48334 break;
48335
48336 /* entry requires deletion */
48337 case FSCACHE_CHECKAUX_OBSOLETE:
48338- fscache_stat(&fscache_n_checkaux_obsolete);
48339+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
48340 break;
48341
48342 default:
48343diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
48344index 30afdfa..2256596 100644
48345--- a/fs/fscache/operation.c
48346+++ b/fs/fscache/operation.c
48347@@ -17,7 +17,7 @@
48348 #include <linux/slab.h>
48349 #include "internal.h"
48350
48351-atomic_t fscache_op_debug_id;
48352+atomic_unchecked_t fscache_op_debug_id;
48353 EXPORT_SYMBOL(fscache_op_debug_id);
48354
48355 /**
48356@@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
48357 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
48358 ASSERTCMP(atomic_read(&op->usage), >, 0);
48359
48360- fscache_stat(&fscache_n_op_enqueue);
48361+ fscache_stat_unchecked(&fscache_n_op_enqueue);
48362 switch (op->flags & FSCACHE_OP_TYPE) {
48363 case FSCACHE_OP_ASYNC:
48364 _debug("queue async");
48365@@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
48366 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
48367 if (op->processor)
48368 fscache_enqueue_operation(op);
48369- fscache_stat(&fscache_n_op_run);
48370+ fscache_stat_unchecked(&fscache_n_op_run);
48371 }
48372
48373 /*
48374@@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
48375 if (object->n_ops > 1) {
48376 atomic_inc(&op->usage);
48377 list_add_tail(&op->pend_link, &object->pending_ops);
48378- fscache_stat(&fscache_n_op_pend);
48379+ fscache_stat_unchecked(&fscache_n_op_pend);
48380 } else if (!list_empty(&object->pending_ops)) {
48381 atomic_inc(&op->usage);
48382 list_add_tail(&op->pend_link, &object->pending_ops);
48383- fscache_stat(&fscache_n_op_pend);
48384+ fscache_stat_unchecked(&fscache_n_op_pend);
48385 fscache_start_operations(object);
48386 } else {
48387 ASSERTCMP(object->n_in_progress, ==, 0);
48388@@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
48389 object->n_exclusive++; /* reads and writes must wait */
48390 atomic_inc(&op->usage);
48391 list_add_tail(&op->pend_link, &object->pending_ops);
48392- fscache_stat(&fscache_n_op_pend);
48393+ fscache_stat_unchecked(&fscache_n_op_pend);
48394 ret = 0;
48395 } else {
48396 /* not allowed to submit ops in any other state */
48397@@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
48398 if (object->n_exclusive > 0) {
48399 atomic_inc(&op->usage);
48400 list_add_tail(&op->pend_link, &object->pending_ops);
48401- fscache_stat(&fscache_n_op_pend);
48402+ fscache_stat_unchecked(&fscache_n_op_pend);
48403 } else if (!list_empty(&object->pending_ops)) {
48404 atomic_inc(&op->usage);
48405 list_add_tail(&op->pend_link, &object->pending_ops);
48406- fscache_stat(&fscache_n_op_pend);
48407+ fscache_stat_unchecked(&fscache_n_op_pend);
48408 fscache_start_operations(object);
48409 } else {
48410 ASSERTCMP(object->n_exclusive, ==, 0);
48411@@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
48412 object->n_ops++;
48413 atomic_inc(&op->usage);
48414 list_add_tail(&op->pend_link, &object->pending_ops);
48415- fscache_stat(&fscache_n_op_pend);
48416+ fscache_stat_unchecked(&fscache_n_op_pend);
48417 ret = 0;
48418 } else if (object->state == FSCACHE_OBJECT_DYING ||
48419 object->state == FSCACHE_OBJECT_LC_DYING ||
48420 object->state == FSCACHE_OBJECT_WITHDRAWING) {
48421- fscache_stat(&fscache_n_op_rejected);
48422+ fscache_stat_unchecked(&fscache_n_op_rejected);
48423 ret = -ENOBUFS;
48424 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
48425 fscache_report_unexpected_submission(object, op, ostate);
48426@@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
48427
48428 ret = -EBUSY;
48429 if (!list_empty(&op->pend_link)) {
48430- fscache_stat(&fscache_n_op_cancelled);
48431+ fscache_stat_unchecked(&fscache_n_op_cancelled);
48432 list_del_init(&op->pend_link);
48433 object->n_ops--;
48434 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
48435@@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
48436 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
48437 BUG();
48438
48439- fscache_stat(&fscache_n_op_release);
48440+ fscache_stat_unchecked(&fscache_n_op_release);
48441
48442 if (op->release) {
48443 op->release(op);
48444@@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
48445 * lock, and defer it otherwise */
48446 if (!spin_trylock(&object->lock)) {
48447 _debug("defer put");
48448- fscache_stat(&fscache_n_op_deferred_release);
48449+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
48450
48451 cache = object->cache;
48452 spin_lock(&cache->op_gc_list_lock);
48453@@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
48454
48455 _debug("GC DEFERRED REL OBJ%x OP%x",
48456 object->debug_id, op->debug_id);
48457- fscache_stat(&fscache_n_op_gc);
48458+ fscache_stat_unchecked(&fscache_n_op_gc);
48459
48460 ASSERTCMP(atomic_read(&op->usage), ==, 0);
48461
48462diff --git a/fs/fscache/page.c b/fs/fscache/page.c
48463index 3f7a59b..cf196cc 100644
48464--- a/fs/fscache/page.c
48465+++ b/fs/fscache/page.c
48466@@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
48467 val = radix_tree_lookup(&cookie->stores, page->index);
48468 if (!val) {
48469 rcu_read_unlock();
48470- fscache_stat(&fscache_n_store_vmscan_not_storing);
48471+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
48472 __fscache_uncache_page(cookie, page);
48473 return true;
48474 }
48475@@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
48476 spin_unlock(&cookie->stores_lock);
48477
48478 if (xpage) {
48479- fscache_stat(&fscache_n_store_vmscan_cancelled);
48480- fscache_stat(&fscache_n_store_radix_deletes);
48481+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
48482+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
48483 ASSERTCMP(xpage, ==, page);
48484 } else {
48485- fscache_stat(&fscache_n_store_vmscan_gone);
48486+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
48487 }
48488
48489 wake_up_bit(&cookie->flags, 0);
48490@@ -107,7 +107,7 @@ page_busy:
48491 /* we might want to wait here, but that could deadlock the allocator as
48492 * the work threads writing to the cache may all end up sleeping
48493 * on memory allocation */
48494- fscache_stat(&fscache_n_store_vmscan_busy);
48495+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
48496 return false;
48497 }
48498 EXPORT_SYMBOL(__fscache_maybe_release_page);
48499@@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
48500 FSCACHE_COOKIE_STORING_TAG);
48501 if (!radix_tree_tag_get(&cookie->stores, page->index,
48502 FSCACHE_COOKIE_PENDING_TAG)) {
48503- fscache_stat(&fscache_n_store_radix_deletes);
48504+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
48505 xpage = radix_tree_delete(&cookie->stores, page->index);
48506 }
48507 spin_unlock(&cookie->stores_lock);
48508@@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
48509
48510 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
48511
48512- fscache_stat(&fscache_n_attr_changed_calls);
48513+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
48514
48515 if (fscache_object_is_active(object)) {
48516 fscache_stat(&fscache_n_cop_attr_changed);
48517@@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
48518
48519 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
48520
48521- fscache_stat(&fscache_n_attr_changed);
48522+ fscache_stat_unchecked(&fscache_n_attr_changed);
48523
48524 op = kzalloc(sizeof(*op), GFP_KERNEL);
48525 if (!op) {
48526- fscache_stat(&fscache_n_attr_changed_nomem);
48527+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
48528 _leave(" = -ENOMEM");
48529 return -ENOMEM;
48530 }
48531@@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
48532 if (fscache_submit_exclusive_op(object, op) < 0)
48533 goto nobufs;
48534 spin_unlock(&cookie->lock);
48535- fscache_stat(&fscache_n_attr_changed_ok);
48536+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
48537 fscache_put_operation(op);
48538 _leave(" = 0");
48539 return 0;
48540@@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
48541 nobufs:
48542 spin_unlock(&cookie->lock);
48543 kfree(op);
48544- fscache_stat(&fscache_n_attr_changed_nobufs);
48545+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
48546 _leave(" = %d", -ENOBUFS);
48547 return -ENOBUFS;
48548 }
48549@@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
48550 /* allocate a retrieval operation and attempt to submit it */
48551 op = kzalloc(sizeof(*op), GFP_NOIO);
48552 if (!op) {
48553- fscache_stat(&fscache_n_retrievals_nomem);
48554+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
48555 return NULL;
48556 }
48557
48558@@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
48559 return 0;
48560 }
48561
48562- fscache_stat(&fscache_n_retrievals_wait);
48563+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
48564
48565 jif = jiffies;
48566 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
48567 fscache_wait_bit_interruptible,
48568 TASK_INTERRUPTIBLE) != 0) {
48569- fscache_stat(&fscache_n_retrievals_intr);
48570+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
48571 _leave(" = -ERESTARTSYS");
48572 return -ERESTARTSYS;
48573 }
48574@@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
48575 */
48576 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
48577 struct fscache_retrieval *op,
48578- atomic_t *stat_op_waits,
48579- atomic_t *stat_object_dead)
48580+ atomic_unchecked_t *stat_op_waits,
48581+ atomic_unchecked_t *stat_object_dead)
48582 {
48583 int ret;
48584
48585@@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
48586 goto check_if_dead;
48587
48588 _debug(">>> WT");
48589- fscache_stat(stat_op_waits);
48590+ fscache_stat_unchecked(stat_op_waits);
48591 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
48592 fscache_wait_bit_interruptible,
48593 TASK_INTERRUPTIBLE) < 0) {
48594@@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
48595
48596 check_if_dead:
48597 if (unlikely(fscache_object_is_dead(object))) {
48598- fscache_stat(stat_object_dead);
48599+ fscache_stat_unchecked(stat_object_dead);
48600 return -ENOBUFS;
48601 }
48602 return 0;
48603@@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
48604
48605 _enter("%p,%p,,,", cookie, page);
48606
48607- fscache_stat(&fscache_n_retrievals);
48608+ fscache_stat_unchecked(&fscache_n_retrievals);
48609
48610 if (hlist_empty(&cookie->backing_objects))
48611 goto nobufs;
48612@@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
48613 goto nobufs_unlock;
48614 spin_unlock(&cookie->lock);
48615
48616- fscache_stat(&fscache_n_retrieval_ops);
48617+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
48618
48619 /* pin the netfs read context in case we need to do the actual netfs
48620 * read because we've encountered a cache read failure */
48621@@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
48622
48623 error:
48624 if (ret == -ENOMEM)
48625- fscache_stat(&fscache_n_retrievals_nomem);
48626+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
48627 else if (ret == -ERESTARTSYS)
48628- fscache_stat(&fscache_n_retrievals_intr);
48629+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
48630 else if (ret == -ENODATA)
48631- fscache_stat(&fscache_n_retrievals_nodata);
48632+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
48633 else if (ret < 0)
48634- fscache_stat(&fscache_n_retrievals_nobufs);
48635+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
48636 else
48637- fscache_stat(&fscache_n_retrievals_ok);
48638+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
48639
48640 fscache_put_retrieval(op);
48641 _leave(" = %d", ret);
48642@@ -429,7 +429,7 @@ nobufs_unlock:
48643 spin_unlock(&cookie->lock);
48644 kfree(op);
48645 nobufs:
48646- fscache_stat(&fscache_n_retrievals_nobufs);
48647+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
48648 _leave(" = -ENOBUFS");
48649 return -ENOBUFS;
48650 }
48651@@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
48652
48653 _enter("%p,,%d,,,", cookie, *nr_pages);
48654
48655- fscache_stat(&fscache_n_retrievals);
48656+ fscache_stat_unchecked(&fscache_n_retrievals);
48657
48658 if (hlist_empty(&cookie->backing_objects))
48659 goto nobufs;
48660@@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
48661 goto nobufs_unlock;
48662 spin_unlock(&cookie->lock);
48663
48664- fscache_stat(&fscache_n_retrieval_ops);
48665+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
48666
48667 /* pin the netfs read context in case we need to do the actual netfs
48668 * read because we've encountered a cache read failure */
48669@@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
48670
48671 error:
48672 if (ret == -ENOMEM)
48673- fscache_stat(&fscache_n_retrievals_nomem);
48674+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
48675 else if (ret == -ERESTARTSYS)
48676- fscache_stat(&fscache_n_retrievals_intr);
48677+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
48678 else if (ret == -ENODATA)
48679- fscache_stat(&fscache_n_retrievals_nodata);
48680+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
48681 else if (ret < 0)
48682- fscache_stat(&fscache_n_retrievals_nobufs);
48683+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
48684 else
48685- fscache_stat(&fscache_n_retrievals_ok);
48686+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
48687
48688 fscache_put_retrieval(op);
48689 _leave(" = %d", ret);
48690@@ -545,7 +545,7 @@ nobufs_unlock:
48691 spin_unlock(&cookie->lock);
48692 kfree(op);
48693 nobufs:
48694- fscache_stat(&fscache_n_retrievals_nobufs);
48695+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
48696 _leave(" = -ENOBUFS");
48697 return -ENOBUFS;
48698 }
48699@@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
48700
48701 _enter("%p,%p,,,", cookie, page);
48702
48703- fscache_stat(&fscache_n_allocs);
48704+ fscache_stat_unchecked(&fscache_n_allocs);
48705
48706 if (hlist_empty(&cookie->backing_objects))
48707 goto nobufs;
48708@@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
48709 goto nobufs_unlock;
48710 spin_unlock(&cookie->lock);
48711
48712- fscache_stat(&fscache_n_alloc_ops);
48713+ fscache_stat_unchecked(&fscache_n_alloc_ops);
48714
48715 ret = fscache_wait_for_retrieval_activation(
48716 object, op,
48717@@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
48718
48719 error:
48720 if (ret == -ERESTARTSYS)
48721- fscache_stat(&fscache_n_allocs_intr);
48722+ fscache_stat_unchecked(&fscache_n_allocs_intr);
48723 else if (ret < 0)
48724- fscache_stat(&fscache_n_allocs_nobufs);
48725+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
48726 else
48727- fscache_stat(&fscache_n_allocs_ok);
48728+ fscache_stat_unchecked(&fscache_n_allocs_ok);
48729
48730 fscache_put_retrieval(op);
48731 _leave(" = %d", ret);
48732@@ -625,7 +625,7 @@ nobufs_unlock:
48733 spin_unlock(&cookie->lock);
48734 kfree(op);
48735 nobufs:
48736- fscache_stat(&fscache_n_allocs_nobufs);
48737+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
48738 _leave(" = -ENOBUFS");
48739 return -ENOBUFS;
48740 }
48741@@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
48742
48743 spin_lock(&cookie->stores_lock);
48744
48745- fscache_stat(&fscache_n_store_calls);
48746+ fscache_stat_unchecked(&fscache_n_store_calls);
48747
48748 /* find a page to store */
48749 page = NULL;
48750@@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
48751 page = results[0];
48752 _debug("gang %d [%lx]", n, page->index);
48753 if (page->index > op->store_limit) {
48754- fscache_stat(&fscache_n_store_pages_over_limit);
48755+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
48756 goto superseded;
48757 }
48758
48759@@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
48760 spin_unlock(&cookie->stores_lock);
48761 spin_unlock(&object->lock);
48762
48763- fscache_stat(&fscache_n_store_pages);
48764+ fscache_stat_unchecked(&fscache_n_store_pages);
48765 fscache_stat(&fscache_n_cop_write_page);
48766 ret = object->cache->ops->write_page(op, page);
48767 fscache_stat_d(&fscache_n_cop_write_page);
48768@@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
48769 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
48770 ASSERT(PageFsCache(page));
48771
48772- fscache_stat(&fscache_n_stores);
48773+ fscache_stat_unchecked(&fscache_n_stores);
48774
48775 op = kzalloc(sizeof(*op), GFP_NOIO);
48776 if (!op)
48777@@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
48778 spin_unlock(&cookie->stores_lock);
48779 spin_unlock(&object->lock);
48780
48781- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
48782+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
48783 op->store_limit = object->store_limit;
48784
48785 if (fscache_submit_op(object, &op->op) < 0)
48786@@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
48787
48788 spin_unlock(&cookie->lock);
48789 radix_tree_preload_end();
48790- fscache_stat(&fscache_n_store_ops);
48791- fscache_stat(&fscache_n_stores_ok);
48792+ fscache_stat_unchecked(&fscache_n_store_ops);
48793+ fscache_stat_unchecked(&fscache_n_stores_ok);
48794
48795 /* the work queue now carries its own ref on the object */
48796 fscache_put_operation(&op->op);
48797@@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
48798 return 0;
48799
48800 already_queued:
48801- fscache_stat(&fscache_n_stores_again);
48802+ fscache_stat_unchecked(&fscache_n_stores_again);
48803 already_pending:
48804 spin_unlock(&cookie->stores_lock);
48805 spin_unlock(&object->lock);
48806 spin_unlock(&cookie->lock);
48807 radix_tree_preload_end();
48808 kfree(op);
48809- fscache_stat(&fscache_n_stores_ok);
48810+ fscache_stat_unchecked(&fscache_n_stores_ok);
48811 _leave(" = 0");
48812 return 0;
48813
48814@@ -851,14 +851,14 @@ nobufs:
48815 spin_unlock(&cookie->lock);
48816 radix_tree_preload_end();
48817 kfree(op);
48818- fscache_stat(&fscache_n_stores_nobufs);
48819+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
48820 _leave(" = -ENOBUFS");
48821 return -ENOBUFS;
48822
48823 nomem_free:
48824 kfree(op);
48825 nomem:
48826- fscache_stat(&fscache_n_stores_oom);
48827+ fscache_stat_unchecked(&fscache_n_stores_oom);
48828 _leave(" = -ENOMEM");
48829 return -ENOMEM;
48830 }
48831@@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
48832 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
48833 ASSERTCMP(page, !=, NULL);
48834
48835- fscache_stat(&fscache_n_uncaches);
48836+ fscache_stat_unchecked(&fscache_n_uncaches);
48837
48838 /* cache withdrawal may beat us to it */
48839 if (!PageFsCache(page))
48840@@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
48841 unsigned long loop;
48842
48843 #ifdef CONFIG_FSCACHE_STATS
48844- atomic_add(pagevec->nr, &fscache_n_marks);
48845+ atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
48846 #endif
48847
48848 for (loop = 0; loop < pagevec->nr; loop++) {
48849diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
48850index 4765190..2a067f2 100644
48851--- a/fs/fscache/stats.c
48852+++ b/fs/fscache/stats.c
48853@@ -18,95 +18,95 @@
48854 /*
48855 * operation counters
48856 */
48857-atomic_t fscache_n_op_pend;
48858-atomic_t fscache_n_op_run;
48859-atomic_t fscache_n_op_enqueue;
48860-atomic_t fscache_n_op_requeue;
48861-atomic_t fscache_n_op_deferred_release;
48862-atomic_t fscache_n_op_release;
48863-atomic_t fscache_n_op_gc;
48864-atomic_t fscache_n_op_cancelled;
48865-atomic_t fscache_n_op_rejected;
48866+atomic_unchecked_t fscache_n_op_pend;
48867+atomic_unchecked_t fscache_n_op_run;
48868+atomic_unchecked_t fscache_n_op_enqueue;
48869+atomic_unchecked_t fscache_n_op_requeue;
48870+atomic_unchecked_t fscache_n_op_deferred_release;
48871+atomic_unchecked_t fscache_n_op_release;
48872+atomic_unchecked_t fscache_n_op_gc;
48873+atomic_unchecked_t fscache_n_op_cancelled;
48874+atomic_unchecked_t fscache_n_op_rejected;
48875
48876-atomic_t fscache_n_attr_changed;
48877-atomic_t fscache_n_attr_changed_ok;
48878-atomic_t fscache_n_attr_changed_nobufs;
48879-atomic_t fscache_n_attr_changed_nomem;
48880-atomic_t fscache_n_attr_changed_calls;
48881+atomic_unchecked_t fscache_n_attr_changed;
48882+atomic_unchecked_t fscache_n_attr_changed_ok;
48883+atomic_unchecked_t fscache_n_attr_changed_nobufs;
48884+atomic_unchecked_t fscache_n_attr_changed_nomem;
48885+atomic_unchecked_t fscache_n_attr_changed_calls;
48886
48887-atomic_t fscache_n_allocs;
48888-atomic_t fscache_n_allocs_ok;
48889-atomic_t fscache_n_allocs_wait;
48890-atomic_t fscache_n_allocs_nobufs;
48891-atomic_t fscache_n_allocs_intr;
48892-atomic_t fscache_n_allocs_object_dead;
48893-atomic_t fscache_n_alloc_ops;
48894-atomic_t fscache_n_alloc_op_waits;
48895+atomic_unchecked_t fscache_n_allocs;
48896+atomic_unchecked_t fscache_n_allocs_ok;
48897+atomic_unchecked_t fscache_n_allocs_wait;
48898+atomic_unchecked_t fscache_n_allocs_nobufs;
48899+atomic_unchecked_t fscache_n_allocs_intr;
48900+atomic_unchecked_t fscache_n_allocs_object_dead;
48901+atomic_unchecked_t fscache_n_alloc_ops;
48902+atomic_unchecked_t fscache_n_alloc_op_waits;
48903
48904-atomic_t fscache_n_retrievals;
48905-atomic_t fscache_n_retrievals_ok;
48906-atomic_t fscache_n_retrievals_wait;
48907-atomic_t fscache_n_retrievals_nodata;
48908-atomic_t fscache_n_retrievals_nobufs;
48909-atomic_t fscache_n_retrievals_intr;
48910-atomic_t fscache_n_retrievals_nomem;
48911-atomic_t fscache_n_retrievals_object_dead;
48912-atomic_t fscache_n_retrieval_ops;
48913-atomic_t fscache_n_retrieval_op_waits;
48914+atomic_unchecked_t fscache_n_retrievals;
48915+atomic_unchecked_t fscache_n_retrievals_ok;
48916+atomic_unchecked_t fscache_n_retrievals_wait;
48917+atomic_unchecked_t fscache_n_retrievals_nodata;
48918+atomic_unchecked_t fscache_n_retrievals_nobufs;
48919+atomic_unchecked_t fscache_n_retrievals_intr;
48920+atomic_unchecked_t fscache_n_retrievals_nomem;
48921+atomic_unchecked_t fscache_n_retrievals_object_dead;
48922+atomic_unchecked_t fscache_n_retrieval_ops;
48923+atomic_unchecked_t fscache_n_retrieval_op_waits;
48924
48925-atomic_t fscache_n_stores;
48926-atomic_t fscache_n_stores_ok;
48927-atomic_t fscache_n_stores_again;
48928-atomic_t fscache_n_stores_nobufs;
48929-atomic_t fscache_n_stores_oom;
48930-atomic_t fscache_n_store_ops;
48931-atomic_t fscache_n_store_calls;
48932-atomic_t fscache_n_store_pages;
48933-atomic_t fscache_n_store_radix_deletes;
48934-atomic_t fscache_n_store_pages_over_limit;
48935+atomic_unchecked_t fscache_n_stores;
48936+atomic_unchecked_t fscache_n_stores_ok;
48937+atomic_unchecked_t fscache_n_stores_again;
48938+atomic_unchecked_t fscache_n_stores_nobufs;
48939+atomic_unchecked_t fscache_n_stores_oom;
48940+atomic_unchecked_t fscache_n_store_ops;
48941+atomic_unchecked_t fscache_n_store_calls;
48942+atomic_unchecked_t fscache_n_store_pages;
48943+atomic_unchecked_t fscache_n_store_radix_deletes;
48944+atomic_unchecked_t fscache_n_store_pages_over_limit;
48945
48946-atomic_t fscache_n_store_vmscan_not_storing;
48947-atomic_t fscache_n_store_vmscan_gone;
48948-atomic_t fscache_n_store_vmscan_busy;
48949-atomic_t fscache_n_store_vmscan_cancelled;
48950+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
48951+atomic_unchecked_t fscache_n_store_vmscan_gone;
48952+atomic_unchecked_t fscache_n_store_vmscan_busy;
48953+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
48954
48955-atomic_t fscache_n_marks;
48956-atomic_t fscache_n_uncaches;
48957+atomic_unchecked_t fscache_n_marks;
48958+atomic_unchecked_t fscache_n_uncaches;
48959
48960-atomic_t fscache_n_acquires;
48961-atomic_t fscache_n_acquires_null;
48962-atomic_t fscache_n_acquires_no_cache;
48963-atomic_t fscache_n_acquires_ok;
48964-atomic_t fscache_n_acquires_nobufs;
48965-atomic_t fscache_n_acquires_oom;
48966+atomic_unchecked_t fscache_n_acquires;
48967+atomic_unchecked_t fscache_n_acquires_null;
48968+atomic_unchecked_t fscache_n_acquires_no_cache;
48969+atomic_unchecked_t fscache_n_acquires_ok;
48970+atomic_unchecked_t fscache_n_acquires_nobufs;
48971+atomic_unchecked_t fscache_n_acquires_oom;
48972
48973-atomic_t fscache_n_updates;
48974-atomic_t fscache_n_updates_null;
48975-atomic_t fscache_n_updates_run;
48976+atomic_unchecked_t fscache_n_updates;
48977+atomic_unchecked_t fscache_n_updates_null;
48978+atomic_unchecked_t fscache_n_updates_run;
48979
48980-atomic_t fscache_n_relinquishes;
48981-atomic_t fscache_n_relinquishes_null;
48982-atomic_t fscache_n_relinquishes_waitcrt;
48983-atomic_t fscache_n_relinquishes_retire;
48984+atomic_unchecked_t fscache_n_relinquishes;
48985+atomic_unchecked_t fscache_n_relinquishes_null;
48986+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
48987+atomic_unchecked_t fscache_n_relinquishes_retire;
48988
48989-atomic_t fscache_n_cookie_index;
48990-atomic_t fscache_n_cookie_data;
48991-atomic_t fscache_n_cookie_special;
48992+atomic_unchecked_t fscache_n_cookie_index;
48993+atomic_unchecked_t fscache_n_cookie_data;
48994+atomic_unchecked_t fscache_n_cookie_special;
48995
48996-atomic_t fscache_n_object_alloc;
48997-atomic_t fscache_n_object_no_alloc;
48998-atomic_t fscache_n_object_lookups;
48999-atomic_t fscache_n_object_lookups_negative;
49000-atomic_t fscache_n_object_lookups_positive;
49001-atomic_t fscache_n_object_lookups_timed_out;
49002-atomic_t fscache_n_object_created;
49003-atomic_t fscache_n_object_avail;
49004-atomic_t fscache_n_object_dead;
49005+atomic_unchecked_t fscache_n_object_alloc;
49006+atomic_unchecked_t fscache_n_object_no_alloc;
49007+atomic_unchecked_t fscache_n_object_lookups;
49008+atomic_unchecked_t fscache_n_object_lookups_negative;
49009+atomic_unchecked_t fscache_n_object_lookups_positive;
49010+atomic_unchecked_t fscache_n_object_lookups_timed_out;
49011+atomic_unchecked_t fscache_n_object_created;
49012+atomic_unchecked_t fscache_n_object_avail;
49013+atomic_unchecked_t fscache_n_object_dead;
49014
49015-atomic_t fscache_n_checkaux_none;
49016-atomic_t fscache_n_checkaux_okay;
49017-atomic_t fscache_n_checkaux_update;
49018-atomic_t fscache_n_checkaux_obsolete;
49019+atomic_unchecked_t fscache_n_checkaux_none;
49020+atomic_unchecked_t fscache_n_checkaux_okay;
49021+atomic_unchecked_t fscache_n_checkaux_update;
49022+atomic_unchecked_t fscache_n_checkaux_obsolete;
49023
49024 atomic_t fscache_n_cop_alloc_object;
49025 atomic_t fscache_n_cop_lookup_object;
49026@@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
49027 seq_puts(m, "FS-Cache statistics\n");
49028
49029 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
49030- atomic_read(&fscache_n_cookie_index),
49031- atomic_read(&fscache_n_cookie_data),
49032- atomic_read(&fscache_n_cookie_special));
49033+ atomic_read_unchecked(&fscache_n_cookie_index),
49034+ atomic_read_unchecked(&fscache_n_cookie_data),
49035+ atomic_read_unchecked(&fscache_n_cookie_special));
49036
49037 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
49038- atomic_read(&fscache_n_object_alloc),
49039- atomic_read(&fscache_n_object_no_alloc),
49040- atomic_read(&fscache_n_object_avail),
49041- atomic_read(&fscache_n_object_dead));
49042+ atomic_read_unchecked(&fscache_n_object_alloc),
49043+ atomic_read_unchecked(&fscache_n_object_no_alloc),
49044+ atomic_read_unchecked(&fscache_n_object_avail),
49045+ atomic_read_unchecked(&fscache_n_object_dead));
49046 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
49047- atomic_read(&fscache_n_checkaux_none),
49048- atomic_read(&fscache_n_checkaux_okay),
49049- atomic_read(&fscache_n_checkaux_update),
49050- atomic_read(&fscache_n_checkaux_obsolete));
49051+ atomic_read_unchecked(&fscache_n_checkaux_none),
49052+ atomic_read_unchecked(&fscache_n_checkaux_okay),
49053+ atomic_read_unchecked(&fscache_n_checkaux_update),
49054+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
49055
49056 seq_printf(m, "Pages : mrk=%u unc=%u\n",
49057- atomic_read(&fscache_n_marks),
49058- atomic_read(&fscache_n_uncaches));
49059+ atomic_read_unchecked(&fscache_n_marks),
49060+ atomic_read_unchecked(&fscache_n_uncaches));
49061
49062 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
49063 " oom=%u\n",
49064- atomic_read(&fscache_n_acquires),
49065- atomic_read(&fscache_n_acquires_null),
49066- atomic_read(&fscache_n_acquires_no_cache),
49067- atomic_read(&fscache_n_acquires_ok),
49068- atomic_read(&fscache_n_acquires_nobufs),
49069- atomic_read(&fscache_n_acquires_oom));
49070+ atomic_read_unchecked(&fscache_n_acquires),
49071+ atomic_read_unchecked(&fscache_n_acquires_null),
49072+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
49073+ atomic_read_unchecked(&fscache_n_acquires_ok),
49074+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
49075+ atomic_read_unchecked(&fscache_n_acquires_oom));
49076
49077 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
49078- atomic_read(&fscache_n_object_lookups),
49079- atomic_read(&fscache_n_object_lookups_negative),
49080- atomic_read(&fscache_n_object_lookups_positive),
49081- atomic_read(&fscache_n_object_created),
49082- atomic_read(&fscache_n_object_lookups_timed_out));
49083+ atomic_read_unchecked(&fscache_n_object_lookups),
49084+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
49085+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
49086+ atomic_read_unchecked(&fscache_n_object_created),
49087+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
49088
49089 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
49090- atomic_read(&fscache_n_updates),
49091- atomic_read(&fscache_n_updates_null),
49092- atomic_read(&fscache_n_updates_run));
49093+ atomic_read_unchecked(&fscache_n_updates),
49094+ atomic_read_unchecked(&fscache_n_updates_null),
49095+ atomic_read_unchecked(&fscache_n_updates_run));
49096
49097 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
49098- atomic_read(&fscache_n_relinquishes),
49099- atomic_read(&fscache_n_relinquishes_null),
49100- atomic_read(&fscache_n_relinquishes_waitcrt),
49101- atomic_read(&fscache_n_relinquishes_retire));
49102+ atomic_read_unchecked(&fscache_n_relinquishes),
49103+ atomic_read_unchecked(&fscache_n_relinquishes_null),
49104+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
49105+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
49106
49107 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
49108- atomic_read(&fscache_n_attr_changed),
49109- atomic_read(&fscache_n_attr_changed_ok),
49110- atomic_read(&fscache_n_attr_changed_nobufs),
49111- atomic_read(&fscache_n_attr_changed_nomem),
49112- atomic_read(&fscache_n_attr_changed_calls));
49113+ atomic_read_unchecked(&fscache_n_attr_changed),
49114+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
49115+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
49116+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
49117+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
49118
49119 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
49120- atomic_read(&fscache_n_allocs),
49121- atomic_read(&fscache_n_allocs_ok),
49122- atomic_read(&fscache_n_allocs_wait),
49123- atomic_read(&fscache_n_allocs_nobufs),
49124- atomic_read(&fscache_n_allocs_intr));
49125+ atomic_read_unchecked(&fscache_n_allocs),
49126+ atomic_read_unchecked(&fscache_n_allocs_ok),
49127+ atomic_read_unchecked(&fscache_n_allocs_wait),
49128+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
49129+ atomic_read_unchecked(&fscache_n_allocs_intr));
49130 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
49131- atomic_read(&fscache_n_alloc_ops),
49132- atomic_read(&fscache_n_alloc_op_waits),
49133- atomic_read(&fscache_n_allocs_object_dead));
49134+ atomic_read_unchecked(&fscache_n_alloc_ops),
49135+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
49136+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
49137
49138 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
49139 " int=%u oom=%u\n",
49140- atomic_read(&fscache_n_retrievals),
49141- atomic_read(&fscache_n_retrievals_ok),
49142- atomic_read(&fscache_n_retrievals_wait),
49143- atomic_read(&fscache_n_retrievals_nodata),
49144- atomic_read(&fscache_n_retrievals_nobufs),
49145- atomic_read(&fscache_n_retrievals_intr),
49146- atomic_read(&fscache_n_retrievals_nomem));
49147+ atomic_read_unchecked(&fscache_n_retrievals),
49148+ atomic_read_unchecked(&fscache_n_retrievals_ok),
49149+ atomic_read_unchecked(&fscache_n_retrievals_wait),
49150+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
49151+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
49152+ atomic_read_unchecked(&fscache_n_retrievals_intr),
49153+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
49154 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
49155- atomic_read(&fscache_n_retrieval_ops),
49156- atomic_read(&fscache_n_retrieval_op_waits),
49157- atomic_read(&fscache_n_retrievals_object_dead));
49158+ atomic_read_unchecked(&fscache_n_retrieval_ops),
49159+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
49160+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
49161
49162 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
49163- atomic_read(&fscache_n_stores),
49164- atomic_read(&fscache_n_stores_ok),
49165- atomic_read(&fscache_n_stores_again),
49166- atomic_read(&fscache_n_stores_nobufs),
49167- atomic_read(&fscache_n_stores_oom));
49168+ atomic_read_unchecked(&fscache_n_stores),
49169+ atomic_read_unchecked(&fscache_n_stores_ok),
49170+ atomic_read_unchecked(&fscache_n_stores_again),
49171+ atomic_read_unchecked(&fscache_n_stores_nobufs),
49172+ atomic_read_unchecked(&fscache_n_stores_oom));
49173 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
49174- atomic_read(&fscache_n_store_ops),
49175- atomic_read(&fscache_n_store_calls),
49176- atomic_read(&fscache_n_store_pages),
49177- atomic_read(&fscache_n_store_radix_deletes),
49178- atomic_read(&fscache_n_store_pages_over_limit));
49179+ atomic_read_unchecked(&fscache_n_store_ops),
49180+ atomic_read_unchecked(&fscache_n_store_calls),
49181+ atomic_read_unchecked(&fscache_n_store_pages),
49182+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
49183+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
49184
49185 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
49186- atomic_read(&fscache_n_store_vmscan_not_storing),
49187- atomic_read(&fscache_n_store_vmscan_gone),
49188- atomic_read(&fscache_n_store_vmscan_busy),
49189- atomic_read(&fscache_n_store_vmscan_cancelled));
49190+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
49191+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
49192+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
49193+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
49194
49195 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
49196- atomic_read(&fscache_n_op_pend),
49197- atomic_read(&fscache_n_op_run),
49198- atomic_read(&fscache_n_op_enqueue),
49199- atomic_read(&fscache_n_op_cancelled),
49200- atomic_read(&fscache_n_op_rejected));
49201+ atomic_read_unchecked(&fscache_n_op_pend),
49202+ atomic_read_unchecked(&fscache_n_op_run),
49203+ atomic_read_unchecked(&fscache_n_op_enqueue),
49204+ atomic_read_unchecked(&fscache_n_op_cancelled),
49205+ atomic_read_unchecked(&fscache_n_op_rejected));
49206 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
49207- atomic_read(&fscache_n_op_deferred_release),
49208- atomic_read(&fscache_n_op_release),
49209- atomic_read(&fscache_n_op_gc));
49210+ atomic_read_unchecked(&fscache_n_op_deferred_release),
49211+ atomic_read_unchecked(&fscache_n_op_release),
49212+ atomic_read_unchecked(&fscache_n_op_gc));
49213
49214 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
49215 atomic_read(&fscache_n_cop_alloc_object),
49216diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
49217index ee8d550..7189d8c 100644
49218--- a/fs/fuse/cuse.c
49219+++ b/fs/fuse/cuse.c
49220@@ -585,10 +585,12 @@ static int __init cuse_init(void)
49221 INIT_LIST_HEAD(&cuse_conntbl[i]);
49222
49223 /* inherit and extend fuse_dev_operations */
49224- cuse_channel_fops = fuse_dev_operations;
49225- cuse_channel_fops.owner = THIS_MODULE;
49226- cuse_channel_fops.open = cuse_channel_open;
49227- cuse_channel_fops.release = cuse_channel_release;
49228+ pax_open_kernel();
49229+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
49230+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
49231+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
49232+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
49233+ pax_close_kernel();
49234
49235 cuse_class = class_create(THIS_MODULE, "cuse");
49236 if (IS_ERR(cuse_class))
49237diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
49238index 8c23fa7..0e3aac7 100644
49239--- a/fs/fuse/dev.c
49240+++ b/fs/fuse/dev.c
49241@@ -1241,7 +1241,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
49242 ret = 0;
49243 pipe_lock(pipe);
49244
49245- if (!pipe->readers) {
49246+ if (!atomic_read(&pipe->readers)) {
49247 send_sig(SIGPIPE, current, 0);
49248 if (!ret)
49249 ret = -EPIPE;
49250diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
49251index 324bc08..4fdd56e 100644
49252--- a/fs/fuse/dir.c
49253+++ b/fs/fuse/dir.c
49254@@ -1226,7 +1226,7 @@ static char *read_link(struct dentry *dentry)
49255 return link;
49256 }
49257
49258-static void free_link(char *link)
49259+static void free_link(const char *link)
49260 {
49261 if (!IS_ERR(link))
49262 free_page((unsigned long) link);
49263diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
49264index 381893c..3793318 100644
49265--- a/fs/gfs2/inode.c
49266+++ b/fs/gfs2/inode.c
49267@@ -1490,7 +1490,7 @@ out:
49268
49269 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
49270 {
49271- char *s = nd_get_link(nd);
49272+ const char *s = nd_get_link(nd);
49273 if (!IS_ERR(s))
49274 kfree(s);
49275 }
49276diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
49277index c5bc355..f94f2d7 100644
49278--- a/fs/hugetlbfs/inode.c
49279+++ b/fs/hugetlbfs/inode.c
49280@@ -165,18 +165,21 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
49281 return addr;
49282 }
49283
49284+#ifdef CONFIG_PAX_RANDMMAP
49285+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
49286+#endif
49287+
49288 if (addr) {
49289 addr = ALIGN(addr, huge_page_size(h));
49290 vma = find_vma(mm, addr);
49291- if (TASK_SIZE - len >= addr &&
49292- (!vma || addr + len <= vma->vm_start))
49293+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
49294 return addr;
49295 }
49296
49297 if (len > mm->cached_hole_size)
49298 start_addr = mm->free_area_cache;
49299 else {
49300- start_addr = TASK_UNMAPPED_BASE;
49301+ start_addr = mm->mmap_base;
49302 mm->cached_hole_size = 0;
49303 }
49304
49305@@ -190,15 +193,15 @@ full_search:
49306 * Start a new search - just in case we missed
49307 * some holes.
49308 */
49309- if (start_addr != TASK_UNMAPPED_BASE) {
49310- start_addr = TASK_UNMAPPED_BASE;
49311+ if (start_addr != mm->mmap_base) {
49312+ start_addr = mm->mmap_base;
49313 mm->cached_hole_size = 0;
49314 goto full_search;
49315 }
49316 return -ENOMEM;
49317 }
49318
49319- if (!vma || addr + len <= vma->vm_start) {
49320+ if (check_heap_stack_gap(vma, addr, len)) {
49321 mm->free_area_cache = addr + len;
49322 return addr;
49323 }
49324@@ -923,7 +926,7 @@ static struct file_system_type hugetlbfs_fs_type = {
49325 .kill_sb = kill_litter_super,
49326 };
49327
49328-static struct vfsmount *hugetlbfs_vfsmount;
49329+struct vfsmount *hugetlbfs_vfsmount;
49330
49331 static int can_do_hugetlb_shm(void)
49332 {
49333diff --git a/fs/inode.c b/fs/inode.c
49334index 64999f1..8fad608 100644
49335--- a/fs/inode.c
49336+++ b/fs/inode.c
49337@@ -880,8 +880,8 @@ unsigned int get_next_ino(void)
49338
49339 #ifdef CONFIG_SMP
49340 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
49341- static atomic_t shared_last_ino;
49342- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
49343+ static atomic_unchecked_t shared_last_ino;
49344+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
49345
49346 res = next - LAST_INO_BATCH;
49347 }
49348diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
49349index 4a6cf28..d3a29d3 100644
49350--- a/fs/jffs2/erase.c
49351+++ b/fs/jffs2/erase.c
49352@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
49353 struct jffs2_unknown_node marker = {
49354 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
49355 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
49356- .totlen = cpu_to_je32(c->cleanmarker_size)
49357+ .totlen = cpu_to_je32(c->cleanmarker_size),
49358+ .hdr_crc = cpu_to_je32(0)
49359 };
49360
49361 jffs2_prealloc_raw_node_refs(c, jeb, 1);
49362diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
49363index a6597d6..41b30ec 100644
49364--- a/fs/jffs2/wbuf.c
49365+++ b/fs/jffs2/wbuf.c
49366@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
49367 {
49368 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
49369 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
49370- .totlen = constant_cpu_to_je32(8)
49371+ .totlen = constant_cpu_to_je32(8),
49372+ .hdr_crc = constant_cpu_to_je32(0)
49373 };
49374
49375 /*
49376diff --git a/fs/jfs/super.c b/fs/jfs/super.c
49377index 1a543be..d803c40 100644
49378--- a/fs/jfs/super.c
49379+++ b/fs/jfs/super.c
49380@@ -855,7 +855,7 @@ static int __init init_jfs_fs(void)
49381
49382 jfs_inode_cachep =
49383 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
49384- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
49385+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
49386 init_once);
49387 if (jfs_inode_cachep == NULL)
49388 return -ENOMEM;
49389diff --git a/fs/libfs.c b/fs/libfs.c
49390index 7cc37ca..b3e3eec 100644
49391--- a/fs/libfs.c
49392+++ b/fs/libfs.c
49393@@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
49394
49395 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
49396 struct dentry *next;
49397+ char d_name[sizeof(next->d_iname)];
49398+ const unsigned char *name;
49399+
49400 next = list_entry(p, struct dentry, d_u.d_child);
49401 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
49402 if (!simple_positive(next)) {
49403@@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
49404
49405 spin_unlock(&next->d_lock);
49406 spin_unlock(&dentry->d_lock);
49407- if (filldir(dirent, next->d_name.name,
49408+ name = next->d_name.name;
49409+ if (name == next->d_iname) {
49410+ memcpy(d_name, name, next->d_name.len);
49411+ name = d_name;
49412+ }
49413+ if (filldir(dirent, name,
49414 next->d_name.len, filp->f_pos,
49415 next->d_inode->i_ino,
49416 dt_type(next->d_inode)) < 0)
49417diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
49418index 05d2912..760abfa 100644
49419--- a/fs/lockd/clntproc.c
49420+++ b/fs/lockd/clntproc.c
49421@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
49422 /*
49423 * Cookie counter for NLM requests
49424 */
49425-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
49426+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
49427
49428 void nlmclnt_next_cookie(struct nlm_cookie *c)
49429 {
49430- u32 cookie = atomic_inc_return(&nlm_cookie);
49431+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
49432
49433 memcpy(c->data, &cookie, 4);
49434 c->len=4;
49435diff --git a/fs/locks.c b/fs/locks.c
49436index a94e331..060bce3 100644
49437--- a/fs/locks.c
49438+++ b/fs/locks.c
49439@@ -2064,16 +2064,16 @@ void locks_remove_flock(struct file *filp)
49440 return;
49441
49442 if (filp->f_op && filp->f_op->flock) {
49443- struct file_lock fl = {
49444+ struct file_lock flock = {
49445 .fl_pid = current->tgid,
49446 .fl_file = filp,
49447 .fl_flags = FL_FLOCK,
49448 .fl_type = F_UNLCK,
49449 .fl_end = OFFSET_MAX,
49450 };
49451- filp->f_op->flock(filp, F_SETLKW, &fl);
49452- if (fl.fl_ops && fl.fl_ops->fl_release_private)
49453- fl.fl_ops->fl_release_private(&fl);
49454+ filp->f_op->flock(filp, F_SETLKW, &flock);
49455+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
49456+ flock.fl_ops->fl_release_private(&flock);
49457 }
49458
49459 lock_flocks();
49460diff --git a/fs/namei.c b/fs/namei.c
49461index 5f4cdf3..959a013 100644
49462--- a/fs/namei.c
49463+++ b/fs/namei.c
49464@@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
49465 if (ret != -EACCES)
49466 return ret;
49467
49468+#ifdef CONFIG_GRKERNSEC
49469+ /* we'll block if we have to log due to a denied capability use */
49470+ if (mask & MAY_NOT_BLOCK)
49471+ return -ECHILD;
49472+#endif
49473+
49474 if (S_ISDIR(inode->i_mode)) {
49475 /* DACs are overridable for directories */
49476- if (inode_capable(inode, CAP_DAC_OVERRIDE))
49477- return 0;
49478 if (!(mask & MAY_WRITE))
49479- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
49480+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
49481+ inode_capable(inode, CAP_DAC_READ_SEARCH))
49482 return 0;
49483+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
49484+ return 0;
49485 return -EACCES;
49486 }
49487 /*
49488+ * Searching includes executable on directories, else just read.
49489+ */
49490+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
49491+ if (mask == MAY_READ)
49492+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
49493+ inode_capable(inode, CAP_DAC_READ_SEARCH))
49494+ return 0;
49495+
49496+ /*
49497 * Read/write DACs are always overridable.
49498 * Executable DACs are overridable when there is
49499 * at least one exec bit set.
49500@@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
49501 if (inode_capable(inode, CAP_DAC_OVERRIDE))
49502 return 0;
49503
49504- /*
49505- * Searching includes executable on directories, else just read.
49506- */
49507- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
49508- if (mask == MAY_READ)
49509- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
49510- return 0;
49511-
49512 return -EACCES;
49513 }
49514
49515@@ -826,7 +834,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
49516 {
49517 struct dentry *dentry = link->dentry;
49518 int error;
49519- char *s;
49520+ const char *s;
49521
49522 BUG_ON(nd->flags & LOOKUP_RCU);
49523
49524@@ -847,6 +855,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
49525 if (error)
49526 goto out_put_nd_path;
49527
49528+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
49529+ dentry->d_inode, dentry, nd->path.mnt)) {
49530+ error = -EACCES;
49531+ goto out_put_nd_path;
49532+ }
49533+
49534 nd->last_type = LAST_BIND;
49535 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
49536 error = PTR_ERR(*p);
49537@@ -1605,6 +1619,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
49538 break;
49539 res = walk_component(nd, path, &nd->last,
49540 nd->last_type, LOOKUP_FOLLOW);
49541+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
49542+ res = -EACCES;
49543 put_link(nd, &link, cookie);
49544 } while (res > 0);
49545
49546@@ -1703,7 +1719,7 @@ EXPORT_SYMBOL(full_name_hash);
49547 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
49548 {
49549 unsigned long a, b, adata, bdata, mask, hash, len;
49550- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
49551+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
49552
49553 hash = a = 0;
49554 len = -sizeof(unsigned long);
49555@@ -1993,6 +2009,8 @@ static int path_lookupat(int dfd, const char *name,
49556 if (err)
49557 break;
49558 err = lookup_last(nd, &path);
49559+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
49560+ err = -EACCES;
49561 put_link(nd, &link, cookie);
49562 }
49563 }
49564@@ -2000,6 +2018,21 @@ static int path_lookupat(int dfd, const char *name,
49565 if (!err)
49566 err = complete_walk(nd);
49567
49568+ if (!(nd->flags & LOOKUP_PARENT)) {
49569+#ifdef CONFIG_GRKERNSEC
49570+ if (flags & LOOKUP_RCU) {
49571+ if (!err)
49572+ path_put(&nd->path);
49573+ err = -ECHILD;
49574+ } else
49575+#endif
49576+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
49577+ if (!err)
49578+ path_put(&nd->path);
49579+ err = -ENOENT;
49580+ }
49581+ }
49582+
49583 if (!err && nd->flags & LOOKUP_DIRECTORY) {
49584 if (!nd->inode->i_op->lookup) {
49585 path_put(&nd->path);
49586@@ -2027,8 +2060,17 @@ static int filename_lookup(int dfd, struct filename *name,
49587 retval = path_lookupat(dfd, name->name,
49588 flags | LOOKUP_REVAL, nd);
49589
49590- if (likely(!retval))
49591+ if (likely(!retval)) {
49592+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
49593+#ifdef CONFIG_GRKERNSEC
49594+ if (flags & LOOKUP_RCU)
49595+ return -ECHILD;
49596+#endif
49597+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
49598+ return -ENOENT;
49599+ }
49600 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
49601+ }
49602 return retval;
49603 }
49604
49605@@ -2402,6 +2444,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
49606 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
49607 return -EPERM;
49608
49609+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
49610+ return -EPERM;
49611+ if (gr_handle_rawio(inode))
49612+ return -EPERM;
49613+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
49614+ return -EACCES;
49615+
49616 return 0;
49617 }
49618
49619@@ -2623,7 +2672,7 @@ looked_up:
49620 * cleared otherwise prior to returning.
49621 */
49622 static int lookup_open(struct nameidata *nd, struct path *path,
49623- struct file *file,
49624+ struct path *link, struct file *file,
49625 const struct open_flags *op,
49626 bool got_write, int *opened)
49627 {
49628@@ -2658,6 +2707,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
49629 /* Negative dentry, just create the file */
49630 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
49631 umode_t mode = op->mode;
49632+
49633+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
49634+ error = -EACCES;
49635+ goto out_dput;
49636+ }
49637+
49638+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
49639+ error = -EACCES;
49640+ goto out_dput;
49641+ }
49642+
49643 if (!IS_POSIXACL(dir->d_inode))
49644 mode &= ~current_umask();
49645 /*
49646@@ -2679,6 +2739,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
49647 nd->flags & LOOKUP_EXCL);
49648 if (error)
49649 goto out_dput;
49650+ else
49651+ gr_handle_create(dentry, nd->path.mnt);
49652 }
49653 out_no_open:
49654 path->dentry = dentry;
49655@@ -2693,7 +2755,7 @@ out_dput:
49656 /*
49657 * Handle the last step of open()
49658 */
49659-static int do_last(struct nameidata *nd, struct path *path,
49660+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
49661 struct file *file, const struct open_flags *op,
49662 int *opened, struct filename *name)
49663 {
49664@@ -2722,16 +2784,44 @@ static int do_last(struct nameidata *nd, struct path *path,
49665 error = complete_walk(nd);
49666 if (error)
49667 return error;
49668+#ifdef CONFIG_GRKERNSEC
49669+ if (nd->flags & LOOKUP_RCU) {
49670+ error = -ECHILD;
49671+ goto out;
49672+ }
49673+#endif
49674+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
49675+ error = -ENOENT;
49676+ goto out;
49677+ }
49678 audit_inode(name, nd->path.dentry, 0);
49679 if (open_flag & O_CREAT) {
49680 error = -EISDIR;
49681 goto out;
49682 }
49683+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
49684+ error = -EACCES;
49685+ goto out;
49686+ }
49687 goto finish_open;
49688 case LAST_BIND:
49689 error = complete_walk(nd);
49690 if (error)
49691 return error;
49692+#ifdef CONFIG_GRKERNSEC
49693+ if (nd->flags & LOOKUP_RCU) {
49694+ error = -ECHILD;
49695+ goto out;
49696+ }
49697+#endif
49698+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
49699+ error = -ENOENT;
49700+ goto out;
49701+ }
49702+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
49703+ error = -EACCES;
49704+ goto out;
49705+ }
49706 audit_inode(name, dir, 0);
49707 goto finish_open;
49708 }
49709@@ -2780,7 +2870,7 @@ retry_lookup:
49710 */
49711 }
49712 mutex_lock(&dir->d_inode->i_mutex);
49713- error = lookup_open(nd, path, file, op, got_write, opened);
49714+ error = lookup_open(nd, path, link, file, op, got_write, opened);
49715 mutex_unlock(&dir->d_inode->i_mutex);
49716
49717 if (error <= 0) {
49718@@ -2804,11 +2894,28 @@ retry_lookup:
49719 goto finish_open_created;
49720 }
49721
49722+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
49723+ error = -ENOENT;
49724+ goto exit_dput;
49725+ }
49726+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
49727+ error = -EACCES;
49728+ goto exit_dput;
49729+ }
49730+
49731 /*
49732 * create/update audit record if it already exists.
49733 */
49734- if (path->dentry->d_inode)
49735+ if (path->dentry->d_inode) {
49736+ /* only check if O_CREAT is specified, all other checks need to go
49737+ into may_open */
49738+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
49739+ error = -EACCES;
49740+ goto exit_dput;
49741+ }
49742+
49743 audit_inode(name, path->dentry, 0);
49744+ }
49745
49746 /*
49747 * If atomic_open() acquired write access it is dropped now due to
49748@@ -2849,6 +2956,11 @@ finish_lookup:
49749 }
49750 }
49751 BUG_ON(inode != path->dentry->d_inode);
49752+ /* if we're resolving a symlink to another symlink */
49753+ if (link && gr_handle_symlink_owner(link, inode)) {
49754+ error = -EACCES;
49755+ goto out;
49756+ }
49757 return 1;
49758 }
49759
49760@@ -2858,7 +2970,6 @@ finish_lookup:
49761 save_parent.dentry = nd->path.dentry;
49762 save_parent.mnt = mntget(path->mnt);
49763 nd->path.dentry = path->dentry;
49764-
49765 }
49766 nd->inode = inode;
49767 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
49768@@ -2867,6 +2978,22 @@ finish_lookup:
49769 path_put(&save_parent);
49770 return error;
49771 }
49772+
49773+#ifdef CONFIG_GRKERNSEC
49774+ if (nd->flags & LOOKUP_RCU) {
49775+ error = -ECHILD;
49776+ goto out;
49777+ }
49778+#endif
49779+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
49780+ error = -ENOENT;
49781+ goto out;
49782+ }
49783+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
49784+ error = -EACCES;
49785+ goto out;
49786+ }
49787+
49788 error = -EISDIR;
49789 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
49790 goto out;
49791@@ -2965,7 +3092,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
49792 if (unlikely(error))
49793 goto out;
49794
49795- error = do_last(nd, &path, file, op, &opened, pathname);
49796+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
49797 while (unlikely(error > 0)) { /* trailing symlink */
49798 struct path link = path;
49799 void *cookie;
49800@@ -2983,7 +3110,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
49801 error = follow_link(&link, nd, &cookie);
49802 if (unlikely(error))
49803 break;
49804- error = do_last(nd, &path, file, op, &opened, pathname);
49805+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
49806 put_link(nd, &link, cookie);
49807 }
49808 out:
49809@@ -3073,8 +3200,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
49810 goto unlock;
49811
49812 error = -EEXIST;
49813- if (dentry->d_inode)
49814+ if (dentry->d_inode) {
49815+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
49816+ error = -ENOENT;
49817+ }
49818 goto fail;
49819+ }
49820 /*
49821 * Special case - lookup gave negative, but... we had foo/bar/
49822 * From the vfs_mknod() POV we just have a negative dentry -
49823@@ -3125,6 +3256,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
49824 }
49825 EXPORT_SYMBOL(user_path_create);
49826
49827+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, int is_dir)
49828+{
49829+ struct filename *tmp = getname(pathname);
49830+ struct dentry *res;
49831+ if (IS_ERR(tmp))
49832+ return ERR_CAST(tmp);
49833+ res = kern_path_create(dfd, tmp->name, path, is_dir);
49834+ if (IS_ERR(res))
49835+ putname(tmp);
49836+ else
49837+ *to = tmp;
49838+ return res;
49839+}
49840+
49841 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
49842 {
49843 int error = may_create(dir, dentry);
49844@@ -3186,6 +3331,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
49845
49846 if (!IS_POSIXACL(path.dentry->d_inode))
49847 mode &= ~current_umask();
49848+
49849+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
49850+ error = -EPERM;
49851+ goto out;
49852+ }
49853+
49854+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
49855+ error = -EACCES;
49856+ goto out;
49857+ }
49858+
49859 error = security_path_mknod(&path, dentry, mode, dev);
49860 if (error)
49861 goto out;
49862@@ -3202,6 +3358,8 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
49863 break;
49864 }
49865 out:
49866+ if (!error)
49867+ gr_handle_create(dentry, path.mnt);
49868 done_path_create(&path, dentry);
49869 return error;
49870 }
49871@@ -3248,9 +3406,18 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode)
49872
49873 if (!IS_POSIXACL(path.dentry->d_inode))
49874 mode &= ~current_umask();
49875+
49876+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
49877+ error = -EACCES;
49878+ goto out;
49879+ }
49880+
49881 error = security_path_mkdir(&path, dentry, mode);
49882 if (!error)
49883 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
49884+ if (!error)
49885+ gr_handle_create(dentry, path.mnt);
49886+out:
49887 done_path_create(&path, dentry);
49888 return error;
49889 }
49890@@ -3327,6 +3494,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
49891 struct filename *name;
49892 struct dentry *dentry;
49893 struct nameidata nd;
49894+ ino_t saved_ino = 0;
49895+ dev_t saved_dev = 0;
49896
49897 name = user_path_parent(dfd, pathname, &nd);
49898 if (IS_ERR(name))
49899@@ -3358,10 +3527,21 @@ static long do_rmdir(int dfd, const char __user *pathname)
49900 error = -ENOENT;
49901 goto exit3;
49902 }
49903+
49904+ saved_ino = dentry->d_inode->i_ino;
49905+ saved_dev = gr_get_dev_from_dentry(dentry);
49906+
49907+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
49908+ error = -EACCES;
49909+ goto exit3;
49910+ }
49911+
49912 error = security_path_rmdir(&nd.path, dentry);
49913 if (error)
49914 goto exit3;
49915 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
49916+ if (!error && (saved_dev || saved_ino))
49917+ gr_handle_delete(saved_ino, saved_dev);
49918 exit3:
49919 dput(dentry);
49920 exit2:
49921@@ -3423,6 +3603,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
49922 struct dentry *dentry;
49923 struct nameidata nd;
49924 struct inode *inode = NULL;
49925+ ino_t saved_ino = 0;
49926+ dev_t saved_dev = 0;
49927
49928 name = user_path_parent(dfd, pathname, &nd);
49929 if (IS_ERR(name))
49930@@ -3448,10 +3630,22 @@ static long do_unlinkat(int dfd, const char __user *pathname)
49931 if (!inode)
49932 goto slashes;
49933 ihold(inode);
49934+
49935+ if (inode->i_nlink <= 1) {
49936+ saved_ino = inode->i_ino;
49937+ saved_dev = gr_get_dev_from_dentry(dentry);
49938+ }
49939+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
49940+ error = -EACCES;
49941+ goto exit2;
49942+ }
49943+
49944 error = security_path_unlink(&nd.path, dentry);
49945 if (error)
49946 goto exit2;
49947 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
49948+ if (!error && (saved_ino || saved_dev))
49949+ gr_handle_delete(saved_ino, saved_dev);
49950 exit2:
49951 dput(dentry);
49952 }
49953@@ -3523,9 +3717,17 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
49954 if (IS_ERR(dentry))
49955 goto out_putname;
49956
49957+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
49958+ error = -EACCES;
49959+ goto out;
49960+ }
49961+
49962 error = security_path_symlink(&path, dentry, from->name);
49963 if (!error)
49964 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
49965+ if (!error)
49966+ gr_handle_create(dentry, path.mnt);
49967+out:
49968 done_path_create(&path, dentry);
49969 out_putname:
49970 putname(from);
49971@@ -3595,6 +3797,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
49972 {
49973 struct dentry *new_dentry;
49974 struct path old_path, new_path;
49975+ struct filename *to = NULL;
49976 int how = 0;
49977 int error;
49978
49979@@ -3618,7 +3821,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
49980 if (error)
49981 return error;
49982
49983- new_dentry = user_path_create(newdfd, newname, &new_path, 0);
49984+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
49985 error = PTR_ERR(new_dentry);
49986 if (IS_ERR(new_dentry))
49987 goto out;
49988@@ -3629,11 +3832,28 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
49989 error = may_linkat(&old_path);
49990 if (unlikely(error))
49991 goto out_dput;
49992+
49993+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
49994+ old_path.dentry->d_inode,
49995+ old_path.dentry->d_inode->i_mode, to)) {
49996+ error = -EACCES;
49997+ goto out_dput;
49998+ }
49999+
50000+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
50001+ old_path.dentry, old_path.mnt, to)) {
50002+ error = -EACCES;
50003+ goto out_dput;
50004+ }
50005+
50006 error = security_path_link(old_path.dentry, &new_path, new_dentry);
50007 if (error)
50008 goto out_dput;
50009 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
50010+ if (!error)
50011+ gr_handle_create(new_dentry, new_path.mnt);
50012 out_dput:
50013+ putname(to);
50014 done_path_create(&new_path, new_dentry);
50015 out:
50016 path_put(&old_path);
50017@@ -3873,12 +4093,21 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
50018 if (new_dentry == trap)
50019 goto exit5;
50020
50021+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
50022+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
50023+ to);
50024+ if (error)
50025+ goto exit5;
50026+
50027 error = security_path_rename(&oldnd.path, old_dentry,
50028 &newnd.path, new_dentry);
50029 if (error)
50030 goto exit5;
50031 error = vfs_rename(old_dir->d_inode, old_dentry,
50032 new_dir->d_inode, new_dentry);
50033+ if (!error)
50034+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
50035+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
50036 exit5:
50037 dput(new_dentry);
50038 exit4:
50039@@ -3903,6 +4132,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
50040
50041 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
50042 {
50043+ char tmpbuf[64];
50044+ const char *newlink;
50045 int len;
50046
50047 len = PTR_ERR(link);
50048@@ -3912,7 +4143,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
50049 len = strlen(link);
50050 if (len > (unsigned) buflen)
50051 len = buflen;
50052- if (copy_to_user(buffer, link, len))
50053+
50054+ if (len < sizeof(tmpbuf)) {
50055+ memcpy(tmpbuf, link, len);
50056+ newlink = tmpbuf;
50057+ } else
50058+ newlink = link;
50059+
50060+ if (copy_to_user(buffer, newlink, len))
50061 len = -EFAULT;
50062 out:
50063 return len;
50064diff --git a/fs/namespace.c b/fs/namespace.c
50065index 2496062..e26f6d6 100644
50066--- a/fs/namespace.c
50067+++ b/fs/namespace.c
50068@@ -1212,6 +1212,9 @@ static int do_umount(struct mount *mnt, int flags)
50069 if (!(sb->s_flags & MS_RDONLY))
50070 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
50071 up_write(&sb->s_umount);
50072+
50073+ gr_log_remount(mnt->mnt_devname, retval);
50074+
50075 return retval;
50076 }
50077
50078@@ -1231,6 +1234,9 @@ static int do_umount(struct mount *mnt, int flags)
50079 br_write_unlock(&vfsmount_lock);
50080 up_write(&namespace_sem);
50081 release_mounts(&umount_list);
50082+
50083+ gr_log_unmount(mnt->mnt_devname, retval);
50084+
50085 return retval;
50086 }
50087
50088@@ -2244,6 +2250,16 @@ long do_mount(const char *dev_name, const char *dir_name,
50089 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
50090 MS_STRICTATIME);
50091
50092+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
50093+ retval = -EPERM;
50094+ goto dput_out;
50095+ }
50096+
50097+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
50098+ retval = -EPERM;
50099+ goto dput_out;
50100+ }
50101+
50102 if (flags & MS_REMOUNT)
50103 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
50104 data_page);
50105@@ -2258,6 +2274,9 @@ long do_mount(const char *dev_name, const char *dir_name,
50106 dev_name, data_page);
50107 dput_out:
50108 path_put(&path);
50109+
50110+ gr_log_mount(dev_name, dir_name, retval);
50111+
50112 return retval;
50113 }
50114
50115@@ -2516,6 +2535,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
50116 if (error)
50117 goto out2;
50118
50119+ if (gr_handle_chroot_pivot()) {
50120+ error = -EPERM;
50121+ goto out2;
50122+ }
50123+
50124 get_fs_root(current->fs, &root);
50125 error = lock_mount(&old);
50126 if (error)
50127diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
50128index 6fa01ae..2790820 100644
50129--- a/fs/nfs/inode.c
50130+++ b/fs/nfs/inode.c
50131@@ -1029,16 +1029,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
50132 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
50133 }
50134
50135-static atomic_long_t nfs_attr_generation_counter;
50136+static atomic_long_unchecked_t nfs_attr_generation_counter;
50137
50138 static unsigned long nfs_read_attr_generation_counter(void)
50139 {
50140- return atomic_long_read(&nfs_attr_generation_counter);
50141+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
50142 }
50143
50144 unsigned long nfs_inc_attr_generation_counter(void)
50145 {
50146- return atomic_long_inc_return(&nfs_attr_generation_counter);
50147+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
50148 }
50149
50150 void nfs_fattr_init(struct nfs_fattr *fattr)
50151diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
50152index f59169e..fd7d359 100644
50153--- a/fs/nfsd/vfs.c
50154+++ b/fs/nfsd/vfs.c
50155@@ -941,7 +941,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
50156 } else {
50157 oldfs = get_fs();
50158 set_fs(KERNEL_DS);
50159- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
50160+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
50161 set_fs(oldfs);
50162 }
50163
50164@@ -1045,7 +1045,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
50165
50166 /* Write the data. */
50167 oldfs = get_fs(); set_fs(KERNEL_DS);
50168- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
50169+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
50170 set_fs(oldfs);
50171 if (host_err < 0)
50172 goto out_nfserr;
50173@@ -1587,7 +1587,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
50174 */
50175
50176 oldfs = get_fs(); set_fs(KERNEL_DS);
50177- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
50178+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
50179 set_fs(oldfs);
50180
50181 if (host_err < 0)
50182diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
50183index 6fcaeb8..9d16d04 100644
50184--- a/fs/notify/fanotify/fanotify_user.c
50185+++ b/fs/notify/fanotify/fanotify_user.c
50186@@ -250,8 +250,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
50187
50188 fd = fanotify_event_metadata.fd;
50189 ret = -EFAULT;
50190- if (copy_to_user(buf, &fanotify_event_metadata,
50191- fanotify_event_metadata.event_len))
50192+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
50193+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
50194 goto out_close_fd;
50195
50196 ret = prepare_for_access_response(group, event, fd);
50197diff --git a/fs/notify/notification.c b/fs/notify/notification.c
50198index c887b13..0fdf472 100644
50199--- a/fs/notify/notification.c
50200+++ b/fs/notify/notification.c
50201@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
50202 * get set to 0 so it will never get 'freed'
50203 */
50204 static struct fsnotify_event *q_overflow_event;
50205-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
50206+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
50207
50208 /**
50209 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
50210@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
50211 */
50212 u32 fsnotify_get_cookie(void)
50213 {
50214- return atomic_inc_return(&fsnotify_sync_cookie);
50215+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
50216 }
50217 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
50218
50219diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
50220index 99e3610..02c1068 100644
50221--- a/fs/ntfs/dir.c
50222+++ b/fs/ntfs/dir.c
50223@@ -1329,7 +1329,7 @@ find_next_index_buffer:
50224 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
50225 ~(s64)(ndir->itype.index.block_size - 1)));
50226 /* Bounds checks. */
50227- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
50228+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
50229 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
50230 "inode 0x%lx or driver bug.", vdir->i_ino);
50231 goto err_out;
50232diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
50233index 1ecf464..e1ff8bf 100644
50234--- a/fs/ntfs/file.c
50235+++ b/fs/ntfs/file.c
50236@@ -2232,6 +2232,6 @@ const struct inode_operations ntfs_file_inode_ops = {
50237 #endif /* NTFS_RW */
50238 };
50239
50240-const struct file_operations ntfs_empty_file_ops = {};
50241+const struct file_operations ntfs_empty_file_ops __read_only;
50242
50243-const struct inode_operations ntfs_empty_inode_ops = {};
50244+const struct inode_operations ntfs_empty_inode_ops __read_only;
50245diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
50246index a9f78c7..ed8a381 100644
50247--- a/fs/ocfs2/localalloc.c
50248+++ b/fs/ocfs2/localalloc.c
50249@@ -1279,7 +1279,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
50250 goto bail;
50251 }
50252
50253- atomic_inc(&osb->alloc_stats.moves);
50254+ atomic_inc_unchecked(&osb->alloc_stats.moves);
50255
50256 bail:
50257 if (handle)
50258diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
50259index d355e6e..578d905 100644
50260--- a/fs/ocfs2/ocfs2.h
50261+++ b/fs/ocfs2/ocfs2.h
50262@@ -235,11 +235,11 @@ enum ocfs2_vol_state
50263
50264 struct ocfs2_alloc_stats
50265 {
50266- atomic_t moves;
50267- atomic_t local_data;
50268- atomic_t bitmap_data;
50269- atomic_t bg_allocs;
50270- atomic_t bg_extends;
50271+ atomic_unchecked_t moves;
50272+ atomic_unchecked_t local_data;
50273+ atomic_unchecked_t bitmap_data;
50274+ atomic_unchecked_t bg_allocs;
50275+ atomic_unchecked_t bg_extends;
50276 };
50277
50278 enum ocfs2_local_alloc_state
50279diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
50280index f169da4..9112253 100644
50281--- a/fs/ocfs2/suballoc.c
50282+++ b/fs/ocfs2/suballoc.c
50283@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
50284 mlog_errno(status);
50285 goto bail;
50286 }
50287- atomic_inc(&osb->alloc_stats.bg_extends);
50288+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
50289
50290 /* You should never ask for this much metadata */
50291 BUG_ON(bits_wanted >
50292@@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
50293 mlog_errno(status);
50294 goto bail;
50295 }
50296- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
50297+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
50298
50299 *suballoc_loc = res.sr_bg_blkno;
50300 *suballoc_bit_start = res.sr_bit_offset;
50301@@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
50302 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
50303 res->sr_bits);
50304
50305- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
50306+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
50307
50308 BUG_ON(res->sr_bits != 1);
50309
50310@@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
50311 mlog_errno(status);
50312 goto bail;
50313 }
50314- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
50315+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
50316
50317 BUG_ON(res.sr_bits != 1);
50318
50319@@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
50320 cluster_start,
50321 num_clusters);
50322 if (!status)
50323- atomic_inc(&osb->alloc_stats.local_data);
50324+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
50325 } else {
50326 if (min_clusters > (osb->bitmap_cpg - 1)) {
50327 /* The only paths asking for contiguousness
50328@@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
50329 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
50330 res.sr_bg_blkno,
50331 res.sr_bit_offset);
50332- atomic_inc(&osb->alloc_stats.bitmap_data);
50333+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
50334 *num_clusters = res.sr_bits;
50335 }
50336 }
50337diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
50338index 0e91ec2..f4b3fc6 100644
50339--- a/fs/ocfs2/super.c
50340+++ b/fs/ocfs2/super.c
50341@@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
50342 "%10s => GlobalAllocs: %d LocalAllocs: %d "
50343 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
50344 "Stats",
50345- atomic_read(&osb->alloc_stats.bitmap_data),
50346- atomic_read(&osb->alloc_stats.local_data),
50347- atomic_read(&osb->alloc_stats.bg_allocs),
50348- atomic_read(&osb->alloc_stats.moves),
50349- atomic_read(&osb->alloc_stats.bg_extends));
50350+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
50351+ atomic_read_unchecked(&osb->alloc_stats.local_data),
50352+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
50353+ atomic_read_unchecked(&osb->alloc_stats.moves),
50354+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
50355
50356 out += snprintf(buf + out, len - out,
50357 "%10s => State: %u Descriptor: %llu Size: %u bits "
50358@@ -2121,11 +2121,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
50359 spin_lock_init(&osb->osb_xattr_lock);
50360 ocfs2_init_steal_slots(osb);
50361
50362- atomic_set(&osb->alloc_stats.moves, 0);
50363- atomic_set(&osb->alloc_stats.local_data, 0);
50364- atomic_set(&osb->alloc_stats.bitmap_data, 0);
50365- atomic_set(&osb->alloc_stats.bg_allocs, 0);
50366- atomic_set(&osb->alloc_stats.bg_extends, 0);
50367+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
50368+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
50369+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
50370+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
50371+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
50372
50373 /* Copy the blockcheck stats from the superblock probe */
50374 osb->osb_ecc_stats = *stats;
50375diff --git a/fs/open.c b/fs/open.c
50376index 59071f5..c6229a0 100644
50377--- a/fs/open.c
50378+++ b/fs/open.c
50379@@ -31,6 +31,8 @@
50380 #include <linux/ima.h>
50381 #include <linux/dnotify.h>
50382
50383+#define CREATE_TRACE_POINTS
50384+#include <trace/events/fs.h>
50385 #include "internal.h"
50386
50387 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
50388@@ -112,6 +114,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
50389 error = locks_verify_truncate(inode, NULL, length);
50390 if (!error)
50391 error = security_path_truncate(&path);
50392+
50393+ if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
50394+ error = -EACCES;
50395+
50396 if (!error)
50397 error = do_truncate(path.dentry, length, 0, NULL);
50398
50399@@ -362,6 +368,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
50400 if (__mnt_is_readonly(path.mnt))
50401 res = -EROFS;
50402
50403+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
50404+ res = -EACCES;
50405+
50406 out_path_release:
50407 path_put(&path);
50408 out:
50409@@ -388,6 +397,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
50410 if (error)
50411 goto dput_and_out;
50412
50413+ gr_log_chdir(path.dentry, path.mnt);
50414+
50415 set_fs_pwd(current->fs, &path);
50416
50417 dput_and_out:
50418@@ -413,6 +424,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
50419 goto out_putf;
50420
50421 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
50422+
50423+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
50424+ error = -EPERM;
50425+
50426+ if (!error)
50427+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
50428+
50429 if (!error)
50430 set_fs_pwd(current->fs, &f.file->f_path);
50431 out_putf:
50432@@ -441,7 +459,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
50433 if (error)
50434 goto dput_and_out;
50435
50436+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
50437+ goto dput_and_out;
50438+
50439 set_fs_root(current->fs, &path);
50440+
50441+ gr_handle_chroot_chdir(&path);
50442+
50443 error = 0;
50444 dput_and_out:
50445 path_put(&path);
50446@@ -459,6 +483,16 @@ static int chmod_common(struct path *path, umode_t mode)
50447 if (error)
50448 return error;
50449 mutex_lock(&inode->i_mutex);
50450+
50451+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
50452+ error = -EACCES;
50453+ goto out_unlock;
50454+ }
50455+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
50456+ error = -EACCES;
50457+ goto out_unlock;
50458+ }
50459+
50460 error = security_path_chmod(path, mode);
50461 if (error)
50462 goto out_unlock;
50463@@ -514,6 +548,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
50464 uid = make_kuid(current_user_ns(), user);
50465 gid = make_kgid(current_user_ns(), group);
50466
50467+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
50468+ return -EACCES;
50469+
50470 newattrs.ia_valid = ATTR_CTIME;
50471 if (user != (uid_t) -1) {
50472 if (!uid_valid(uid))
50473@@ -925,6 +962,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
50474 } else {
50475 fsnotify_open(f);
50476 fd_install(fd, f);
50477+ trace_do_sys_open(tmp->name, flags, mode);
50478 }
50479 }
50480 putname(tmp);
50481diff --git a/fs/pipe.c b/fs/pipe.c
50482index bd3479d..fb92c4d 100644
50483--- a/fs/pipe.c
50484+++ b/fs/pipe.c
50485@@ -438,9 +438,9 @@ redo:
50486 }
50487 if (bufs) /* More to do? */
50488 continue;
50489- if (!pipe->writers)
50490+ if (!atomic_read(&pipe->writers))
50491 break;
50492- if (!pipe->waiting_writers) {
50493+ if (!atomic_read(&pipe->waiting_writers)) {
50494 /* syscall merging: Usually we must not sleep
50495 * if O_NONBLOCK is set, or if we got some data.
50496 * But if a writer sleeps in kernel space, then
50497@@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
50498 mutex_lock(&inode->i_mutex);
50499 pipe = inode->i_pipe;
50500
50501- if (!pipe->readers) {
50502+ if (!atomic_read(&pipe->readers)) {
50503 send_sig(SIGPIPE, current, 0);
50504 ret = -EPIPE;
50505 goto out;
50506@@ -553,7 +553,7 @@ redo1:
50507 for (;;) {
50508 int bufs;
50509
50510- if (!pipe->readers) {
50511+ if (!atomic_read(&pipe->readers)) {
50512 send_sig(SIGPIPE, current, 0);
50513 if (!ret)
50514 ret = -EPIPE;
50515@@ -644,9 +644,9 @@ redo2:
50516 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
50517 do_wakeup = 0;
50518 }
50519- pipe->waiting_writers++;
50520+ atomic_inc(&pipe->waiting_writers);
50521 pipe_wait(pipe);
50522- pipe->waiting_writers--;
50523+ atomic_dec(&pipe->waiting_writers);
50524 }
50525 out:
50526 mutex_unlock(&inode->i_mutex);
50527@@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
50528 mask = 0;
50529 if (filp->f_mode & FMODE_READ) {
50530 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
50531- if (!pipe->writers && filp->f_version != pipe->w_counter)
50532+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
50533 mask |= POLLHUP;
50534 }
50535
50536@@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
50537 * Most Unices do not set POLLERR for FIFOs but on Linux they
50538 * behave exactly like pipes for poll().
50539 */
50540- if (!pipe->readers)
50541+ if (!atomic_read(&pipe->readers))
50542 mask |= POLLERR;
50543 }
50544
50545@@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
50546
50547 mutex_lock(&inode->i_mutex);
50548 pipe = inode->i_pipe;
50549- pipe->readers -= decr;
50550- pipe->writers -= decw;
50551+ atomic_sub(decr, &pipe->readers);
50552+ atomic_sub(decw, &pipe->writers);
50553
50554- if (!pipe->readers && !pipe->writers) {
50555+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
50556 free_pipe_info(inode);
50557 } else {
50558 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
50559@@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
50560
50561 if (inode->i_pipe) {
50562 ret = 0;
50563- inode->i_pipe->readers++;
50564+ atomic_inc(&inode->i_pipe->readers);
50565 }
50566
50567 mutex_unlock(&inode->i_mutex);
50568@@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
50569
50570 if (inode->i_pipe) {
50571 ret = 0;
50572- inode->i_pipe->writers++;
50573+ atomic_inc(&inode->i_pipe->writers);
50574 }
50575
50576 mutex_unlock(&inode->i_mutex);
50577@@ -868,9 +868,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
50578 if (inode->i_pipe) {
50579 ret = 0;
50580 if (filp->f_mode & FMODE_READ)
50581- inode->i_pipe->readers++;
50582+ atomic_inc(&inode->i_pipe->readers);
50583 if (filp->f_mode & FMODE_WRITE)
50584- inode->i_pipe->writers++;
50585+ atomic_inc(&inode->i_pipe->writers);
50586 }
50587
50588 mutex_unlock(&inode->i_mutex);
50589@@ -962,7 +962,7 @@ void free_pipe_info(struct inode *inode)
50590 inode->i_pipe = NULL;
50591 }
50592
50593-static struct vfsmount *pipe_mnt __read_mostly;
50594+struct vfsmount *pipe_mnt __read_mostly;
50595
50596 /*
50597 * pipefs_dname() is called from d_path().
50598@@ -992,7 +992,8 @@ static struct inode * get_pipe_inode(void)
50599 goto fail_iput;
50600 inode->i_pipe = pipe;
50601
50602- pipe->readers = pipe->writers = 1;
50603+ atomic_set(&pipe->readers, 1);
50604+ atomic_set(&pipe->writers, 1);
50605 inode->i_fop = &rdwr_pipefifo_fops;
50606
50607 /*
50608diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
50609index 15af622..0e9f4467 100644
50610--- a/fs/proc/Kconfig
50611+++ b/fs/proc/Kconfig
50612@@ -30,12 +30,12 @@ config PROC_FS
50613
50614 config PROC_KCORE
50615 bool "/proc/kcore support" if !ARM
50616- depends on PROC_FS && MMU
50617+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
50618
50619 config PROC_VMCORE
50620 bool "/proc/vmcore support"
50621- depends on PROC_FS && CRASH_DUMP
50622- default y
50623+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
50624+ default n
50625 help
50626 Exports the dump image of crashed kernel in ELF format.
50627
50628@@ -59,8 +59,8 @@ config PROC_SYSCTL
50629 limited in memory.
50630
50631 config PROC_PAGE_MONITOR
50632- default y
50633- depends on PROC_FS && MMU
50634+ default n
50635+ depends on PROC_FS && MMU && !GRKERNSEC
50636 bool "Enable /proc page monitoring" if EXPERT
50637 help
50638 Various /proc files exist to monitor process memory utilization:
50639diff --git a/fs/proc/array.c b/fs/proc/array.c
50640index bd31e02..15cae71 100644
50641--- a/fs/proc/array.c
50642+++ b/fs/proc/array.c
50643@@ -60,6 +60,7 @@
50644 #include <linux/tty.h>
50645 #include <linux/string.h>
50646 #include <linux/mman.h>
50647+#include <linux/grsecurity.h>
50648 #include <linux/proc_fs.h>
50649 #include <linux/ioport.h>
50650 #include <linux/uaccess.h>
50651@@ -346,6 +347,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
50652 seq_putc(m, '\n');
50653 }
50654
50655+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
50656+static inline void task_pax(struct seq_file *m, struct task_struct *p)
50657+{
50658+ if (p->mm)
50659+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
50660+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
50661+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
50662+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
50663+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
50664+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
50665+ else
50666+ seq_printf(m, "PaX:\t-----\n");
50667+}
50668+#endif
50669+
50670 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
50671 struct pid *pid, struct task_struct *task)
50672 {
50673@@ -363,9 +379,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
50674 task_cpus_allowed(m, task);
50675 cpuset_task_status_allowed(m, task);
50676 task_context_switch_counts(m, task);
50677+
50678+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
50679+ task_pax(m, task);
50680+#endif
50681+
50682+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
50683+ task_grsec_rbac(m, task);
50684+#endif
50685+
50686 return 0;
50687 }
50688
50689+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50690+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
50691+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
50692+ _mm->pax_flags & MF_PAX_SEGMEXEC))
50693+#endif
50694+
50695 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
50696 struct pid *pid, struct task_struct *task, int whole)
50697 {
50698@@ -387,6 +418,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
50699 char tcomm[sizeof(task->comm)];
50700 unsigned long flags;
50701
50702+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50703+ if (current->exec_id != m->exec_id) {
50704+ gr_log_badprocpid("stat");
50705+ return 0;
50706+ }
50707+#endif
50708+
50709 state = *get_task_state(task);
50710 vsize = eip = esp = 0;
50711 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
50712@@ -458,6 +496,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
50713 gtime = task->gtime;
50714 }
50715
50716+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50717+ if (PAX_RAND_FLAGS(mm)) {
50718+ eip = 0;
50719+ esp = 0;
50720+ wchan = 0;
50721+ }
50722+#endif
50723+#ifdef CONFIG_GRKERNSEC_HIDESYM
50724+ wchan = 0;
50725+ eip =0;
50726+ esp =0;
50727+#endif
50728+
50729 /* scale priority and nice values from timeslices to -20..20 */
50730 /* to make it look like a "normal" Unix priority/nice value */
50731 priority = task_prio(task);
50732@@ -494,9 +545,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
50733 seq_put_decimal_ull(m, ' ', vsize);
50734 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
50735 seq_put_decimal_ull(m, ' ', rsslim);
50736+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50737+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
50738+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
50739+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
50740+#else
50741 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
50742 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
50743 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
50744+#endif
50745 seq_put_decimal_ull(m, ' ', esp);
50746 seq_put_decimal_ull(m, ' ', eip);
50747 /* The signal information here is obsolete.
50748@@ -518,7 +575,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
50749 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
50750 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
50751
50752- if (mm && permitted) {
50753+ if (mm && permitted
50754+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50755+ && !PAX_RAND_FLAGS(mm)
50756+#endif
50757+ ) {
50758 seq_put_decimal_ull(m, ' ', mm->start_data);
50759 seq_put_decimal_ull(m, ' ', mm->end_data);
50760 seq_put_decimal_ull(m, ' ', mm->start_brk);
50761@@ -556,8 +617,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
50762 struct pid *pid, struct task_struct *task)
50763 {
50764 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
50765- struct mm_struct *mm = get_task_mm(task);
50766+ struct mm_struct *mm;
50767
50768+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50769+ if (current->exec_id != m->exec_id) {
50770+ gr_log_badprocpid("statm");
50771+ return 0;
50772+ }
50773+#endif
50774+ mm = get_task_mm(task);
50775 if (mm) {
50776 size = task_statm(mm, &shared, &text, &data, &resident);
50777 mmput(mm);
50778@@ -580,6 +648,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
50779 return 0;
50780 }
50781
50782+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
50783+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
50784+{
50785+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
50786+}
50787+#endif
50788+
50789 #ifdef CONFIG_CHECKPOINT_RESTORE
50790 static struct pid *
50791 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
50792diff --git a/fs/proc/base.c b/fs/proc/base.c
50793index 9e28356..c485b3c 100644
50794--- a/fs/proc/base.c
50795+++ b/fs/proc/base.c
50796@@ -111,6 +111,14 @@ struct pid_entry {
50797 union proc_op op;
50798 };
50799
50800+struct getdents_callback {
50801+ struct linux_dirent __user * current_dir;
50802+ struct linux_dirent __user * previous;
50803+ struct file * file;
50804+ int count;
50805+ int error;
50806+};
50807+
50808 #define NOD(NAME, MODE, IOP, FOP, OP) { \
50809 .name = (NAME), \
50810 .len = sizeof(NAME) - 1, \
50811@@ -208,6 +216,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
50812 if (!mm->arg_end)
50813 goto out_mm; /* Shh! No looking before we're done */
50814
50815+ if (gr_acl_handle_procpidmem(task))
50816+ goto out_mm;
50817+
50818 len = mm->arg_end - mm->arg_start;
50819
50820 if (len > PAGE_SIZE)
50821@@ -235,12 +246,28 @@ out:
50822 return res;
50823 }
50824
50825+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50826+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
50827+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
50828+ _mm->pax_flags & MF_PAX_SEGMEXEC))
50829+#endif
50830+
50831 static int proc_pid_auxv(struct task_struct *task, char *buffer)
50832 {
50833 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
50834 int res = PTR_ERR(mm);
50835 if (mm && !IS_ERR(mm)) {
50836 unsigned int nwords = 0;
50837+
50838+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50839+ /* allow if we're currently ptracing this task */
50840+ if (PAX_RAND_FLAGS(mm) &&
50841+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
50842+ mmput(mm);
50843+ return 0;
50844+ }
50845+#endif
50846+
50847 do {
50848 nwords += 2;
50849 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
50850@@ -254,7 +281,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
50851 }
50852
50853
50854-#ifdef CONFIG_KALLSYMS
50855+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
50856 /*
50857 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
50858 * Returns the resolved symbol. If that fails, simply return the address.
50859@@ -293,7 +320,7 @@ static void unlock_trace(struct task_struct *task)
50860 mutex_unlock(&task->signal->cred_guard_mutex);
50861 }
50862
50863-#ifdef CONFIG_STACKTRACE
50864+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
50865
50866 #define MAX_STACK_TRACE_DEPTH 64
50867
50868@@ -485,7 +512,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
50869 return count;
50870 }
50871
50872-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
50873+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
50874 static int proc_pid_syscall(struct task_struct *task, char *buffer)
50875 {
50876 long nr;
50877@@ -514,7 +541,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
50878 /************************************************************************/
50879
50880 /* permission checks */
50881-static int proc_fd_access_allowed(struct inode *inode)
50882+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
50883 {
50884 struct task_struct *task;
50885 int allowed = 0;
50886@@ -524,7 +551,10 @@ static int proc_fd_access_allowed(struct inode *inode)
50887 */
50888 task = get_proc_task(inode);
50889 if (task) {
50890- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
50891+ if (log)
50892+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
50893+ else
50894+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
50895 put_task_struct(task);
50896 }
50897 return allowed;
50898@@ -562,10 +592,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
50899 struct task_struct *task,
50900 int hide_pid_min)
50901 {
50902+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
50903+ return false;
50904+
50905+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50906+ rcu_read_lock();
50907+ {
50908+ const struct cred *tmpcred = current_cred();
50909+ const struct cred *cred = __task_cred(task);
50910+
50911+ if (!tmpcred->uid || (tmpcred->uid == cred->uid)
50912+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
50913+ || in_group_p(grsec_proc_gid)
50914+#endif
50915+ ) {
50916+ rcu_read_unlock();
50917+ return true;
50918+ }
50919+ }
50920+ rcu_read_unlock();
50921+
50922+ if (!pid->hide_pid)
50923+ return false;
50924+#endif
50925+
50926 if (pid->hide_pid < hide_pid_min)
50927 return true;
50928 if (in_group_p(pid->pid_gid))
50929 return true;
50930+
50931 return ptrace_may_access(task, PTRACE_MODE_READ);
50932 }
50933
50934@@ -583,7 +638,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
50935 put_task_struct(task);
50936
50937 if (!has_perms) {
50938+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50939+ {
50940+#else
50941 if (pid->hide_pid == 2) {
50942+#endif
50943 /*
50944 * Let's make getdents(), stat(), and open()
50945 * consistent with each other. If a process
50946@@ -681,6 +740,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
50947 if (!task)
50948 return -ESRCH;
50949
50950+ if (gr_acl_handle_procpidmem(task)) {
50951+ put_task_struct(task);
50952+ return -EPERM;
50953+ }
50954+
50955 mm = mm_access(task, mode);
50956 put_task_struct(task);
50957
50958@@ -696,6 +760,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
50959
50960 file->private_data = mm;
50961
50962+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50963+ file->f_version = current->exec_id;
50964+#endif
50965+
50966 return 0;
50967 }
50968
50969@@ -717,6 +785,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
50970 ssize_t copied;
50971 char *page;
50972
50973+#ifdef CONFIG_GRKERNSEC
50974+ if (write)
50975+ return -EPERM;
50976+#endif
50977+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50978+ if (file->f_version != current->exec_id) {
50979+ gr_log_badprocpid("mem");
50980+ return 0;
50981+ }
50982+#endif
50983+
50984 if (!mm)
50985 return 0;
50986
50987@@ -821,6 +900,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
50988 if (!mm)
50989 return 0;
50990
50991+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50992+ if (file->f_version != current->exec_id) {
50993+ gr_log_badprocpid("environ");
50994+ return 0;
50995+ }
50996+#endif
50997+
50998 page = (char *)__get_free_page(GFP_TEMPORARY);
50999 if (!page)
51000 return -ENOMEM;
51001@@ -1436,7 +1522,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
51002 int error = -EACCES;
51003
51004 /* Are we allowed to snoop on the tasks file descriptors? */
51005- if (!proc_fd_access_allowed(inode))
51006+ if (!proc_fd_access_allowed(inode, 0))
51007 goto out;
51008
51009 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
51010@@ -1480,8 +1566,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
51011 struct path path;
51012
51013 /* Are we allowed to snoop on the tasks file descriptors? */
51014- if (!proc_fd_access_allowed(inode))
51015- goto out;
51016+ /* logging this is needed for learning on chromium to work properly,
51017+ but we don't want to flood the logs from 'ps' which does a readlink
51018+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
51019+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
51020+ */
51021+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
51022+ if (!proc_fd_access_allowed(inode,0))
51023+ goto out;
51024+ } else {
51025+ if (!proc_fd_access_allowed(inode,1))
51026+ goto out;
51027+ }
51028
51029 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
51030 if (error)
51031@@ -1531,7 +1627,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
51032 rcu_read_lock();
51033 cred = __task_cred(task);
51034 inode->i_uid = cred->euid;
51035+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
51036+ inode->i_gid = grsec_proc_gid;
51037+#else
51038 inode->i_gid = cred->egid;
51039+#endif
51040 rcu_read_unlock();
51041 }
51042 security_task_to_inode(task, inode);
51043@@ -1567,10 +1667,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
51044 return -ENOENT;
51045 }
51046 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
51047+#ifdef CONFIG_GRKERNSEC_PROC_USER
51048+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
51049+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51050+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
51051+#endif
51052 task_dumpable(task)) {
51053 cred = __task_cred(task);
51054 stat->uid = cred->euid;
51055+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
51056+ stat->gid = grsec_proc_gid;
51057+#else
51058 stat->gid = cred->egid;
51059+#endif
51060 }
51061 }
51062 rcu_read_unlock();
51063@@ -1608,11 +1717,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
51064
51065 if (task) {
51066 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
51067+#ifdef CONFIG_GRKERNSEC_PROC_USER
51068+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
51069+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51070+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
51071+#endif
51072 task_dumpable(task)) {
51073 rcu_read_lock();
51074 cred = __task_cred(task);
51075 inode->i_uid = cred->euid;
51076+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
51077+ inode->i_gid = grsec_proc_gid;
51078+#else
51079 inode->i_gid = cred->egid;
51080+#endif
51081 rcu_read_unlock();
51082 } else {
51083 inode->i_uid = GLOBAL_ROOT_UID;
51084@@ -2065,6 +2183,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
51085 if (!task)
51086 goto out_no_task;
51087
51088+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
51089+ goto out;
51090+
51091 /*
51092 * Yes, it does not scale. And it should not. Don't add
51093 * new entries into /proc/<tgid>/ without very good reasons.
51094@@ -2109,6 +2230,9 @@ static int proc_pident_readdir(struct file *filp,
51095 if (!task)
51096 goto out_no_task;
51097
51098+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
51099+ goto out;
51100+
51101 ret = 0;
51102 i = filp->f_pos;
51103 switch (i) {
51104@@ -2380,7 +2504,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
51105 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
51106 void *cookie)
51107 {
51108- char *s = nd_get_link(nd);
51109+ const char *s = nd_get_link(nd);
51110 if (!IS_ERR(s))
51111 kfree(s);
51112 }
51113@@ -2662,7 +2786,7 @@ static const struct pid_entry tgid_base_stuff[] = {
51114 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
51115 #endif
51116 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
51117-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
51118+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
51119 INF("syscall", S_IRUGO, proc_pid_syscall),
51120 #endif
51121 INF("cmdline", S_IRUGO, proc_pid_cmdline),
51122@@ -2687,10 +2811,10 @@ static const struct pid_entry tgid_base_stuff[] = {
51123 #ifdef CONFIG_SECURITY
51124 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
51125 #endif
51126-#ifdef CONFIG_KALLSYMS
51127+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
51128 INF("wchan", S_IRUGO, proc_pid_wchan),
51129 #endif
51130-#ifdef CONFIG_STACKTRACE
51131+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
51132 ONE("stack", S_IRUGO, proc_pid_stack),
51133 #endif
51134 #ifdef CONFIG_SCHEDSTATS
51135@@ -2724,6 +2848,9 @@ static const struct pid_entry tgid_base_stuff[] = {
51136 #ifdef CONFIG_HARDWALL
51137 INF("hardwall", S_IRUGO, proc_pid_hardwall),
51138 #endif
51139+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
51140+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
51141+#endif
51142 #ifdef CONFIG_USER_NS
51143 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
51144 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
51145@@ -2856,7 +2983,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
51146 if (!inode)
51147 goto out;
51148
51149+#ifdef CONFIG_GRKERNSEC_PROC_USER
51150+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
51151+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51152+ inode->i_gid = grsec_proc_gid;
51153+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
51154+#else
51155 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
51156+#endif
51157 inode->i_op = &proc_tgid_base_inode_operations;
51158 inode->i_fop = &proc_tgid_base_operations;
51159 inode->i_flags|=S_IMMUTABLE;
51160@@ -2898,7 +3032,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
51161 if (!task)
51162 goto out;
51163
51164+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
51165+ goto out_put_task;
51166+
51167 result = proc_pid_instantiate(dir, dentry, task, NULL);
51168+out_put_task:
51169 put_task_struct(task);
51170 out:
51171 return result;
51172@@ -2961,6 +3099,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
51173 static int fake_filldir(void *buf, const char *name, int namelen,
51174 loff_t offset, u64 ino, unsigned d_type)
51175 {
51176+ struct getdents_callback * __buf = (struct getdents_callback *) buf;
51177+ __buf->error = -EINVAL;
51178 return 0;
51179 }
51180
51181@@ -3027,7 +3167,7 @@ static const struct pid_entry tid_base_stuff[] = {
51182 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
51183 #endif
51184 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
51185-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
51186+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
51187 INF("syscall", S_IRUGO, proc_pid_syscall),
51188 #endif
51189 INF("cmdline", S_IRUGO, proc_pid_cmdline),
51190@@ -3054,10 +3194,10 @@ static const struct pid_entry tid_base_stuff[] = {
51191 #ifdef CONFIG_SECURITY
51192 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
51193 #endif
51194-#ifdef CONFIG_KALLSYMS
51195+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
51196 INF("wchan", S_IRUGO, proc_pid_wchan),
51197 #endif
51198-#ifdef CONFIG_STACKTRACE
51199+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
51200 ONE("stack", S_IRUGO, proc_pid_stack),
51201 #endif
51202 #ifdef CONFIG_SCHEDSTATS
51203diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
51204index 82676e3..5f8518a 100644
51205--- a/fs/proc/cmdline.c
51206+++ b/fs/proc/cmdline.c
51207@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
51208
51209 static int __init proc_cmdline_init(void)
51210 {
51211+#ifdef CONFIG_GRKERNSEC_PROC_ADD
51212+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
51213+#else
51214 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
51215+#endif
51216 return 0;
51217 }
51218 module_init(proc_cmdline_init);
51219diff --git a/fs/proc/devices.c b/fs/proc/devices.c
51220index b143471..bb105e5 100644
51221--- a/fs/proc/devices.c
51222+++ b/fs/proc/devices.c
51223@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
51224
51225 static int __init proc_devices_init(void)
51226 {
51227+#ifdef CONFIG_GRKERNSEC_PROC_ADD
51228+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
51229+#else
51230 proc_create("devices", 0, NULL, &proc_devinfo_operations);
51231+#endif
51232 return 0;
51233 }
51234 module_init(proc_devices_init);
51235diff --git a/fs/proc/fd.c b/fs/proc/fd.c
51236index f28a875..c467953 100644
51237--- a/fs/proc/fd.c
51238+++ b/fs/proc/fd.c
51239@@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
51240 if (!task)
51241 return -ENOENT;
51242
51243- files = get_files_struct(task);
51244+ if (!gr_acl_handle_procpidmem(task))
51245+ files = get_files_struct(task);
51246 put_task_struct(task);
51247
51248 if (files) {
51249@@ -300,11 +301,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
51250 */
51251 int proc_fd_permission(struct inode *inode, int mask)
51252 {
51253+ struct task_struct *task;
51254 int rv = generic_permission(inode, mask);
51255- if (rv == 0)
51256- return 0;
51257+
51258 if (task_pid(current) == proc_pid(inode))
51259 rv = 0;
51260+
51261+ task = get_proc_task(inode);
51262+ if (task == NULL)
51263+ return rv;
51264+
51265+ if (gr_acl_handle_procpidmem(task))
51266+ rv = -EACCES;
51267+
51268+ put_task_struct(task);
51269+
51270 return rv;
51271 }
51272
51273diff --git a/fs/proc/inode.c b/fs/proc/inode.c
51274index 3b22bbd..895b58c 100644
51275--- a/fs/proc/inode.c
51276+++ b/fs/proc/inode.c
51277@@ -21,11 +21,17 @@
51278 #include <linux/seq_file.h>
51279 #include <linux/slab.h>
51280 #include <linux/mount.h>
51281+#include <linux/grsecurity.h>
51282
51283 #include <asm/uaccess.h>
51284
51285 #include "internal.h"
51286
51287+#ifdef CONFIG_PROC_SYSCTL
51288+extern const struct inode_operations proc_sys_inode_operations;
51289+extern const struct inode_operations proc_sys_dir_operations;
51290+#endif
51291+
51292 static void proc_evict_inode(struct inode *inode)
51293 {
51294 struct proc_dir_entry *de;
51295@@ -51,6 +57,13 @@ static void proc_evict_inode(struct inode *inode)
51296 ns_ops = PROC_I(inode)->ns_ops;
51297 if (ns_ops && ns_ops->put)
51298 ns_ops->put(PROC_I(inode)->ns);
51299+
51300+#ifdef CONFIG_PROC_SYSCTL
51301+ if (inode->i_op == &proc_sys_inode_operations ||
51302+ inode->i_op == &proc_sys_dir_operations)
51303+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
51304+#endif
51305+
51306 }
51307
51308 static struct kmem_cache * proc_inode_cachep;
51309@@ -455,7 +468,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
51310 if (de->mode) {
51311 inode->i_mode = de->mode;
51312 inode->i_uid = de->uid;
51313+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
51314+ inode->i_gid = grsec_proc_gid;
51315+#else
51316 inode->i_gid = de->gid;
51317+#endif
51318 }
51319 if (de->size)
51320 inode->i_size = de->size;
51321diff --git a/fs/proc/internal.h b/fs/proc/internal.h
51322index 43973b0..a20e704 100644
51323--- a/fs/proc/internal.h
51324+++ b/fs/proc/internal.h
51325@@ -54,6 +54,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
51326 struct pid *pid, struct task_struct *task);
51327 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
51328 struct pid *pid, struct task_struct *task);
51329+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
51330+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
51331+#endif
51332 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
51333
51334 extern const struct file_operations proc_tid_children_operations;
51335diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
51336index 86c67ee..cdca321 100644
51337--- a/fs/proc/kcore.c
51338+++ b/fs/proc/kcore.c
51339@@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
51340 * the addresses in the elf_phdr on our list.
51341 */
51342 start = kc_offset_to_vaddr(*fpos - elf_buflen);
51343- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
51344+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
51345+ if (tsz > buflen)
51346 tsz = buflen;
51347-
51348+
51349 while (buflen) {
51350 struct kcore_list *m;
51351
51352@@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
51353 kfree(elf_buf);
51354 } else {
51355 if (kern_addr_valid(start)) {
51356- unsigned long n;
51357+ char *elf_buf;
51358+ mm_segment_t oldfs;
51359
51360- n = copy_to_user(buffer, (char *)start, tsz);
51361- /*
51362- * We cannot distinguish between fault on source
51363- * and fault on destination. When this happens
51364- * we clear too and hope it will trigger the
51365- * EFAULT again.
51366- */
51367- if (n) {
51368- if (clear_user(buffer + tsz - n,
51369- n))
51370+ elf_buf = kmalloc(tsz, GFP_KERNEL);
51371+ if (!elf_buf)
51372+ return -ENOMEM;
51373+ oldfs = get_fs();
51374+ set_fs(KERNEL_DS);
51375+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
51376+ set_fs(oldfs);
51377+ if (copy_to_user(buffer, elf_buf, tsz)) {
51378+ kfree(elf_buf);
51379 return -EFAULT;
51380+ }
51381 }
51382+ set_fs(oldfs);
51383+ kfree(elf_buf);
51384 } else {
51385 if (clear_user(buffer, tsz))
51386 return -EFAULT;
51387@@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
51388
51389 static int open_kcore(struct inode *inode, struct file *filp)
51390 {
51391+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
51392+ return -EPERM;
51393+#endif
51394 if (!capable(CAP_SYS_RAWIO))
51395 return -EPERM;
51396 if (kcore_need_update)
51397diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
51398index 80e4645..53e5fcf 100644
51399--- a/fs/proc/meminfo.c
51400+++ b/fs/proc/meminfo.c
51401@@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
51402 vmi.used >> 10,
51403 vmi.largest_chunk >> 10
51404 #ifdef CONFIG_MEMORY_FAILURE
51405- ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
51406+ ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
51407 #endif
51408 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
51409 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
51410diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
51411index b1822dd..df622cb 100644
51412--- a/fs/proc/nommu.c
51413+++ b/fs/proc/nommu.c
51414@@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
51415 if (len < 1)
51416 len = 1;
51417 seq_printf(m, "%*c", len, ' ');
51418- seq_path(m, &file->f_path, "");
51419+ seq_path(m, &file->f_path, "\n\\");
51420 }
51421
51422 seq_putc(m, '\n');
51423diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
51424index fe72cd0..cb9b67d 100644
51425--- a/fs/proc/proc_net.c
51426+++ b/fs/proc/proc_net.c
51427@@ -23,6 +23,7 @@
51428 #include <linux/nsproxy.h>
51429 #include <net/net_namespace.h>
51430 #include <linux/seq_file.h>
51431+#include <linux/grsecurity.h>
51432
51433 #include "internal.h"
51434
51435@@ -105,6 +106,17 @@ static struct net *get_proc_task_net(struct inode *dir)
51436 struct task_struct *task;
51437 struct nsproxy *ns;
51438 struct net *net = NULL;
51439+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51440+ const struct cred *cred = current_cred();
51441+#endif
51442+
51443+#ifdef CONFIG_GRKERNSEC_PROC_USER
51444+ if (cred->fsuid)
51445+ return net;
51446+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51447+ if (cred->fsuid && !in_group_p(grsec_proc_gid))
51448+ return net;
51449+#endif
51450
51451 rcu_read_lock();
51452 task = pid_task(proc_pid(dir), PIDTYPE_PID);
51453diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
51454index a781bdf..6665284 100644
51455--- a/fs/proc/proc_sysctl.c
51456+++ b/fs/proc/proc_sysctl.c
51457@@ -12,11 +12,15 @@
51458 #include <linux/module.h>
51459 #include "internal.h"
51460
51461+extern int gr_handle_chroot_sysctl(const int op);
51462+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
51463+ const int op);
51464+
51465 static const struct dentry_operations proc_sys_dentry_operations;
51466 static const struct file_operations proc_sys_file_operations;
51467-static const struct inode_operations proc_sys_inode_operations;
51468+const struct inode_operations proc_sys_inode_operations;
51469 static const struct file_operations proc_sys_dir_file_operations;
51470-static const struct inode_operations proc_sys_dir_operations;
51471+const struct inode_operations proc_sys_dir_operations;
51472
51473 void proc_sys_poll_notify(struct ctl_table_poll *poll)
51474 {
51475@@ -465,6 +469,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
51476
51477 err = NULL;
51478 d_set_d_op(dentry, &proc_sys_dentry_operations);
51479+
51480+ gr_handle_proc_create(dentry, inode);
51481+
51482 d_add(dentry, inode);
51483
51484 out:
51485@@ -480,18 +487,20 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
51486 struct inode *inode = filp->f_path.dentry->d_inode;
51487 struct ctl_table_header *head = grab_header(inode);
51488 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
51489+ int op = write ? MAY_WRITE : MAY_READ;
51490 ssize_t error;
51491 size_t res;
51492
51493 if (IS_ERR(head))
51494 return PTR_ERR(head);
51495
51496+
51497 /*
51498 * At this point we know that the sysctl was not unregistered
51499 * and won't be until we finish.
51500 */
51501 error = -EPERM;
51502- if (sysctl_perm(head->root, table, write ? MAY_WRITE : MAY_READ))
51503+ if (sysctl_perm(head->root, table, op))
51504 goto out;
51505
51506 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
51507@@ -499,6 +508,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
51508 if (!table->proc_handler)
51509 goto out;
51510
51511+#ifdef CONFIG_GRKERNSEC
51512+ error = -EPERM;
51513+ if (gr_handle_chroot_sysctl(op))
51514+ goto out;
51515+ dget(filp->f_path.dentry);
51516+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
51517+ dput(filp->f_path.dentry);
51518+ goto out;
51519+ }
51520+ dput(filp->f_path.dentry);
51521+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
51522+ goto out;
51523+ if (write && !capable(CAP_SYS_ADMIN))
51524+ goto out;
51525+#endif
51526+
51527 /* careful: calling conventions are nasty here */
51528 res = count;
51529 error = table->proc_handler(table, write, buf, &res, ppos);
51530@@ -596,6 +621,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
51531 return -ENOMEM;
51532 } else {
51533 d_set_d_op(child, &proc_sys_dentry_operations);
51534+
51535+ gr_handle_proc_create(child, inode);
51536+
51537 d_add(child, inode);
51538 }
51539 } else {
51540@@ -639,6 +667,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
51541 if ((*pos)++ < file->f_pos)
51542 return 0;
51543
51544+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
51545+ return 0;
51546+
51547 if (unlikely(S_ISLNK(table->mode)))
51548 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
51549 else
51550@@ -756,6 +787,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
51551 if (IS_ERR(head))
51552 return PTR_ERR(head);
51553
51554+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
51555+ return -ENOENT;
51556+
51557 generic_fillattr(inode, stat);
51558 if (table)
51559 stat->mode = (stat->mode & S_IFMT) | table->mode;
51560@@ -778,13 +812,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
51561 .llseek = generic_file_llseek,
51562 };
51563
51564-static const struct inode_operations proc_sys_inode_operations = {
51565+const struct inode_operations proc_sys_inode_operations = {
51566 .permission = proc_sys_permission,
51567 .setattr = proc_sys_setattr,
51568 .getattr = proc_sys_getattr,
51569 };
51570
51571-static const struct inode_operations proc_sys_dir_operations = {
51572+const struct inode_operations proc_sys_dir_operations = {
51573 .lookup = proc_sys_lookup,
51574 .permission = proc_sys_permission,
51575 .setattr = proc_sys_setattr,
51576diff --git a/fs/proc/root.c b/fs/proc/root.c
51577index 9889a92..2613b48 100644
51578--- a/fs/proc/root.c
51579+++ b/fs/proc/root.c
51580@@ -187,7 +187,15 @@ void __init proc_root_init(void)
51581 #ifdef CONFIG_PROC_DEVICETREE
51582 proc_device_tree_init();
51583 #endif
51584+#ifdef CONFIG_GRKERNSEC_PROC_ADD
51585+#ifdef CONFIG_GRKERNSEC_PROC_USER
51586+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
51587+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51588+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
51589+#endif
51590+#else
51591 proc_mkdir("bus", NULL);
51592+#endif
51593 proc_sys_init();
51594 }
51595
51596diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
51597index 90c63f9..e662cfc 100644
51598--- a/fs/proc/task_mmu.c
51599+++ b/fs/proc/task_mmu.c
51600@@ -11,12 +11,19 @@
51601 #include <linux/rmap.h>
51602 #include <linux/swap.h>
51603 #include <linux/swapops.h>
51604+#include <linux/grsecurity.h>
51605
51606 #include <asm/elf.h>
51607 #include <asm/uaccess.h>
51608 #include <asm/tlbflush.h>
51609 #include "internal.h"
51610
51611+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51612+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
51613+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
51614+ _mm->pax_flags & MF_PAX_SEGMEXEC))
51615+#endif
51616+
51617 void task_mem(struct seq_file *m, struct mm_struct *mm)
51618 {
51619 unsigned long data, text, lib, swap;
51620@@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
51621 "VmExe:\t%8lu kB\n"
51622 "VmLib:\t%8lu kB\n"
51623 "VmPTE:\t%8lu kB\n"
51624- "VmSwap:\t%8lu kB\n",
51625- hiwater_vm << (PAGE_SHIFT-10),
51626+ "VmSwap:\t%8lu kB\n"
51627+
51628+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
51629+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
51630+#endif
51631+
51632+ ,hiwater_vm << (PAGE_SHIFT-10),
51633 total_vm << (PAGE_SHIFT-10),
51634 mm->locked_vm << (PAGE_SHIFT-10),
51635 mm->pinned_vm << (PAGE_SHIFT-10),
51636@@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
51637 data << (PAGE_SHIFT-10),
51638 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
51639 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
51640- swap << (PAGE_SHIFT-10));
51641+ swap << (PAGE_SHIFT-10)
51642+
51643+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
51644+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51645+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
51646+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
51647+#else
51648+ , mm->context.user_cs_base
51649+ , mm->context.user_cs_limit
51650+#endif
51651+#endif
51652+
51653+ );
51654 }
51655
51656 unsigned long task_vsize(struct mm_struct *mm)
51657@@ -277,13 +301,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
51658 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
51659 }
51660
51661- /* We don't show the stack guard page in /proc/maps */
51662+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51663+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
51664+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
51665+#else
51666 start = vma->vm_start;
51667- if (stack_guard_page_start(vma, start))
51668- start += PAGE_SIZE;
51669 end = vma->vm_end;
51670- if (stack_guard_page_end(vma, end))
51671- end -= PAGE_SIZE;
51672+#endif
51673
51674 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
51675 start,
51676@@ -292,7 +316,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
51677 flags & VM_WRITE ? 'w' : '-',
51678 flags & VM_EXEC ? 'x' : '-',
51679 flags & VM_MAYSHARE ? 's' : 'p',
51680+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51681+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
51682+#else
51683 pgoff,
51684+#endif
51685 MAJOR(dev), MINOR(dev), ino, &len);
51686
51687 /*
51688@@ -301,7 +329,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
51689 */
51690 if (file) {
51691 pad_len_spaces(m, len);
51692- seq_path(m, &file->f_path, "\n");
51693+ seq_path(m, &file->f_path, "\n\\");
51694 goto done;
51695 }
51696
51697@@ -327,8 +355,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
51698 * Thread stack in /proc/PID/task/TID/maps or
51699 * the main process stack.
51700 */
51701- if (!is_pid || (vma->vm_start <= mm->start_stack &&
51702- vma->vm_end >= mm->start_stack)) {
51703+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
51704+ (vma->vm_start <= mm->start_stack &&
51705+ vma->vm_end >= mm->start_stack)) {
51706 name = "[stack]";
51707 } else {
51708 /* Thread stack in /proc/PID/maps */
51709@@ -352,6 +381,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
51710 struct proc_maps_private *priv = m->private;
51711 struct task_struct *task = priv->task;
51712
51713+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51714+ if (current->exec_id != m->exec_id) {
51715+ gr_log_badprocpid("maps");
51716+ return 0;
51717+ }
51718+#endif
51719+
51720 show_map_vma(m, vma, is_pid);
51721
51722 if (m->count < m->size) /* vma is copied successfully */
51723@@ -538,12 +574,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
51724 .private = &mss,
51725 };
51726
51727+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51728+ if (current->exec_id != m->exec_id) {
51729+ gr_log_badprocpid("smaps");
51730+ return 0;
51731+ }
51732+#endif
51733 memset(&mss, 0, sizeof mss);
51734- mss.vma = vma;
51735- /* mmap_sem is held in m_start */
51736- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
51737- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
51738-
51739+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51740+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
51741+#endif
51742+ mss.vma = vma;
51743+ /* mmap_sem is held in m_start */
51744+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
51745+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
51746+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51747+ }
51748+#endif
51749 show_map_vma(m, vma, is_pid);
51750
51751 seq_printf(m,
51752@@ -561,7 +608,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
51753 "KernelPageSize: %8lu kB\n"
51754 "MMUPageSize: %8lu kB\n"
51755 "Locked: %8lu kB\n",
51756+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51757+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
51758+#else
51759 (vma->vm_end - vma->vm_start) >> 10,
51760+#endif
51761 mss.resident >> 10,
51762 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
51763 mss.shared_clean >> 10,
51764@@ -1211,6 +1262,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
51765 int n;
51766 char buffer[50];
51767
51768+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51769+ if (current->exec_id != m->exec_id) {
51770+ gr_log_badprocpid("numa_maps");
51771+ return 0;
51772+ }
51773+#endif
51774+
51775 if (!mm)
51776 return 0;
51777
51778@@ -1228,11 +1286,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
51779 mpol_to_str(buffer, sizeof(buffer), pol, 0);
51780 mpol_cond_put(pol);
51781
51782+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51783+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
51784+#else
51785 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
51786+#endif
51787
51788 if (file) {
51789 seq_printf(m, " file=");
51790- seq_path(m, &file->f_path, "\n\t= ");
51791+ seq_path(m, &file->f_path, "\n\t\\= ");
51792 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
51793 seq_printf(m, " heap");
51794 } else {
51795diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
51796index 1ccfa53..0848f95 100644
51797--- a/fs/proc/task_nommu.c
51798+++ b/fs/proc/task_nommu.c
51799@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
51800 else
51801 bytes += kobjsize(mm);
51802
51803- if (current->fs && current->fs->users > 1)
51804+ if (current->fs && atomic_read(&current->fs->users) > 1)
51805 sbytes += kobjsize(current->fs);
51806 else
51807 bytes += kobjsize(current->fs);
51808@@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
51809
51810 if (file) {
51811 pad_len_spaces(m, len);
51812- seq_path(m, &file->f_path, "");
51813+ seq_path(m, &file->f_path, "\n\\");
51814 } else if (mm) {
51815 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
51816
51817diff --git a/fs/pstore/ftrace.c b/fs/pstore/ftrace.c
51818index 2d57e1a..43b1280 100644
51819--- a/fs/pstore/ftrace.c
51820+++ b/fs/pstore/ftrace.c
51821@@ -28,7 +28,9 @@
51822 #include "internal.h"
51823
51824 static void notrace pstore_ftrace_call(unsigned long ip,
51825- unsigned long parent_ip)
51826+ unsigned long parent_ip,
51827+ struct ftrace_ops *op,
51828+ struct pt_regs *regs)
51829 {
51830 unsigned long flags;
51831 struct pstore_ftrace_record rec = {};
51832diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
51833index 16e8abb..2dcf914 100644
51834--- a/fs/quota/netlink.c
51835+++ b/fs/quota/netlink.c
51836@@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
51837 void quota_send_warning(struct kqid qid, dev_t dev,
51838 const char warntype)
51839 {
51840- static atomic_t seq;
51841+ static atomic_unchecked_t seq;
51842 struct sk_buff *skb;
51843 void *msg_head;
51844 int ret;
51845@@ -49,7 +49,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
51846 "VFS: Not enough memory to send quota warning.\n");
51847 return;
51848 }
51849- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
51850+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
51851 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
51852 if (!msg_head) {
51853 printk(KERN_ERR
51854diff --git a/fs/read_write.c b/fs/read_write.c
51855index d065348..8e2b43d 100644
51856--- a/fs/read_write.c
51857+++ b/fs/read_write.c
51858@@ -935,6 +935,8 @@ ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos, size_t count,
51859 if (retval > 0) {
51860 add_rchar(current, retval);
51861 add_wchar(current, retval);
51862+ fsnotify_access(in.file);
51863+ fsnotify_modify(out.file);
51864 }
51865
51866 inc_syscr(current);
51867diff --git a/fs/readdir.c b/fs/readdir.c
51868index 5e69ef5..e5d9099 100644
51869--- a/fs/readdir.c
51870+++ b/fs/readdir.c
51871@@ -17,6 +17,7 @@
51872 #include <linux/security.h>
51873 #include <linux/syscalls.h>
51874 #include <linux/unistd.h>
51875+#include <linux/namei.h>
51876
51877 #include <asm/uaccess.h>
51878
51879@@ -67,6 +68,7 @@ struct old_linux_dirent {
51880
51881 struct readdir_callback {
51882 struct old_linux_dirent __user * dirent;
51883+ struct file * file;
51884 int result;
51885 };
51886
51887@@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
51888 buf->result = -EOVERFLOW;
51889 return -EOVERFLOW;
51890 }
51891+
51892+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
51893+ return 0;
51894+
51895 buf->result++;
51896 dirent = buf->dirent;
51897 if (!access_ok(VERIFY_WRITE, dirent,
51898@@ -114,6 +120,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
51899
51900 buf.result = 0;
51901 buf.dirent = dirent;
51902+ buf.file = f.file;
51903
51904 error = vfs_readdir(f.file, fillonedir, &buf);
51905 if (buf.result)
51906@@ -139,6 +146,7 @@ struct linux_dirent {
51907 struct getdents_callback {
51908 struct linux_dirent __user * current_dir;
51909 struct linux_dirent __user * previous;
51910+ struct file * file;
51911 int count;
51912 int error;
51913 };
51914@@ -160,6 +168,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
51915 buf->error = -EOVERFLOW;
51916 return -EOVERFLOW;
51917 }
51918+
51919+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
51920+ return 0;
51921+
51922 dirent = buf->previous;
51923 if (dirent) {
51924 if (__put_user(offset, &dirent->d_off))
51925@@ -205,6 +217,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
51926 buf.previous = NULL;
51927 buf.count = count;
51928 buf.error = 0;
51929+ buf.file = f.file;
51930
51931 error = vfs_readdir(f.file, filldir, &buf);
51932 if (error >= 0)
51933@@ -223,6 +236,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
51934 struct getdents_callback64 {
51935 struct linux_dirent64 __user * current_dir;
51936 struct linux_dirent64 __user * previous;
51937+ struct file *file;
51938 int count;
51939 int error;
51940 };
51941@@ -238,6 +252,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
51942 buf->error = -EINVAL; /* only used if we fail.. */
51943 if (reclen > buf->count)
51944 return -EINVAL;
51945+
51946+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
51947+ return 0;
51948+
51949 dirent = buf->previous;
51950 if (dirent) {
51951 if (__put_user(offset, &dirent->d_off))
51952@@ -283,6 +301,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
51953
51954 buf.current_dir = dirent;
51955 buf.previous = NULL;
51956+ buf.file = f.file;
51957 buf.count = count;
51958 buf.error = 0;
51959
51960@@ -291,7 +310,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
51961 error = buf.error;
51962 lastdirent = buf.previous;
51963 if (lastdirent) {
51964- typeof(lastdirent->d_off) d_off = f.file->f_pos;
51965+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
51966 if (__put_user(d_off, &lastdirent->d_off))
51967 error = -EFAULT;
51968 else
51969diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
51970index 2b7882b..1c5ef48 100644
51971--- a/fs/reiserfs/do_balan.c
51972+++ b/fs/reiserfs/do_balan.c
51973@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
51974 return;
51975 }
51976
51977- atomic_inc(&(fs_generation(tb->tb_sb)));
51978+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
51979 do_balance_starts(tb);
51980
51981 /* balance leaf returns 0 except if combining L R and S into
51982diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
51983index e60e870..f40ac16 100644
51984--- a/fs/reiserfs/procfs.c
51985+++ b/fs/reiserfs/procfs.c
51986@@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
51987 "SMALL_TAILS " : "NO_TAILS ",
51988 replay_only(sb) ? "REPLAY_ONLY " : "",
51989 convert_reiserfs(sb) ? "CONV " : "",
51990- atomic_read(&r->s_generation_counter),
51991+ atomic_read_unchecked(&r->s_generation_counter),
51992 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
51993 SF(s_do_balance), SF(s_unneeded_left_neighbor),
51994 SF(s_good_search_by_key_reada), SF(s_bmaps),
51995diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
51996index 33215f5..c5d427a 100644
51997--- a/fs/reiserfs/reiserfs.h
51998+++ b/fs/reiserfs/reiserfs.h
51999@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
52000 /* Comment? -Hans */
52001 wait_queue_head_t s_wait;
52002 /* To be obsoleted soon by per buffer seals.. -Hans */
52003- atomic_t s_generation_counter; // increased by one every time the
52004+ atomic_unchecked_t s_generation_counter; // increased by one every time the
52005 // tree gets re-balanced
52006 unsigned long s_properties; /* File system properties. Currently holds
52007 on-disk FS format */
52008@@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
52009 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
52010
52011 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
52012-#define get_generation(s) atomic_read (&fs_generation(s))
52013+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
52014 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
52015 #define __fs_changed(gen,s) (gen != get_generation (s))
52016 #define fs_changed(gen,s) \
52017diff --git a/fs/select.c b/fs/select.c
52018index 2ef72d9..f213b17 100644
52019--- a/fs/select.c
52020+++ b/fs/select.c
52021@@ -20,6 +20,7 @@
52022 #include <linux/export.h>
52023 #include <linux/slab.h>
52024 #include <linux/poll.h>
52025+#include <linux/security.h>
52026 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
52027 #include <linux/file.h>
52028 #include <linux/fdtable.h>
52029@@ -826,6 +827,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
52030 struct poll_list *walk = head;
52031 unsigned long todo = nfds;
52032
52033+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
52034 if (nfds > rlimit(RLIMIT_NOFILE))
52035 return -EINVAL;
52036
52037diff --git a/fs/seq_file.c b/fs/seq_file.c
52038index 99dffab..e4fcb71 100644
52039--- a/fs/seq_file.c
52040+++ b/fs/seq_file.c
52041@@ -10,6 +10,7 @@
52042 #include <linux/seq_file.h>
52043 #include <linux/slab.h>
52044 #include <linux/cred.h>
52045+#include <linux/sched.h>
52046
52047 #include <asm/uaccess.h>
52048 #include <asm/page.h>
52049@@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
52050 #ifdef CONFIG_USER_NS
52051 p->user_ns = file->f_cred->user_ns;
52052 #endif
52053+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52054+ p->exec_id = current->exec_id;
52055+#endif
52056
52057 /*
52058 * Wrappers around seq_open(e.g. swaps_open) need to be
52059@@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
52060 return 0;
52061 }
52062 if (!m->buf) {
52063- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
52064+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
52065 if (!m->buf)
52066 return -ENOMEM;
52067 }
52068@@ -136,7 +140,7 @@ static int traverse(struct seq_file *m, loff_t offset)
52069 Eoverflow:
52070 m->op->stop(m, p);
52071 kfree(m->buf);
52072- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
52073+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
52074 return !m->buf ? -ENOMEM : -EAGAIN;
52075 }
52076
52077@@ -191,7 +195,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
52078
52079 /* grab buffer if we didn't have one */
52080 if (!m->buf) {
52081- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
52082+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
52083 if (!m->buf)
52084 goto Enomem;
52085 }
52086@@ -232,7 +236,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
52087 goto Fill;
52088 m->op->stop(m, p);
52089 kfree(m->buf);
52090- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
52091+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
52092 if (!m->buf)
52093 goto Enomem;
52094 m->count = 0;
52095@@ -581,7 +585,7 @@ static void single_stop(struct seq_file *p, void *v)
52096 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
52097 void *data)
52098 {
52099- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
52100+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
52101 int res = -ENOMEM;
52102
52103 if (op) {
52104diff --git a/fs/splice.c b/fs/splice.c
52105index 48c7bd1..d0740e4 100644
52106--- a/fs/splice.c
52107+++ b/fs/splice.c
52108@@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
52109 pipe_lock(pipe);
52110
52111 for (;;) {
52112- if (!pipe->readers) {
52113+ if (!atomic_read(&pipe->readers)) {
52114 send_sig(SIGPIPE, current, 0);
52115 if (!ret)
52116 ret = -EPIPE;
52117@@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
52118 do_wakeup = 0;
52119 }
52120
52121- pipe->waiting_writers++;
52122+ atomic_inc(&pipe->waiting_writers);
52123 pipe_wait(pipe);
52124- pipe->waiting_writers--;
52125+ atomic_dec(&pipe->waiting_writers);
52126 }
52127
52128 pipe_unlock(pipe);
52129@@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
52130 old_fs = get_fs();
52131 set_fs(get_ds());
52132 /* The cast to a user pointer is valid due to the set_fs() */
52133- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
52134+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
52135 set_fs(old_fs);
52136
52137 return res;
52138@@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
52139 old_fs = get_fs();
52140 set_fs(get_ds());
52141 /* The cast to a user pointer is valid due to the set_fs() */
52142- res = vfs_write(file, (const char __user *)buf, count, &pos);
52143+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
52144 set_fs(old_fs);
52145
52146 return res;
52147@@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
52148 goto err;
52149
52150 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
52151- vec[i].iov_base = (void __user *) page_address(page);
52152+ vec[i].iov_base = (void __force_user *) page_address(page);
52153 vec[i].iov_len = this_len;
52154 spd.pages[i] = page;
52155 spd.nr_pages++;
52156@@ -851,10 +851,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
52157 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
52158 {
52159 while (!pipe->nrbufs) {
52160- if (!pipe->writers)
52161+ if (!atomic_read(&pipe->writers))
52162 return 0;
52163
52164- if (!pipe->waiting_writers && sd->num_spliced)
52165+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
52166 return 0;
52167
52168 if (sd->flags & SPLICE_F_NONBLOCK)
52169@@ -1192,7 +1192,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
52170 * out of the pipe right after the splice_to_pipe(). So set
52171 * PIPE_READERS appropriately.
52172 */
52173- pipe->readers = 1;
52174+ atomic_set(&pipe->readers, 1);
52175
52176 current->splice_pipe = pipe;
52177 }
52178@@ -1741,9 +1741,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
52179 ret = -ERESTARTSYS;
52180 break;
52181 }
52182- if (!pipe->writers)
52183+ if (!atomic_read(&pipe->writers))
52184 break;
52185- if (!pipe->waiting_writers) {
52186+ if (!atomic_read(&pipe->waiting_writers)) {
52187 if (flags & SPLICE_F_NONBLOCK) {
52188 ret = -EAGAIN;
52189 break;
52190@@ -1775,7 +1775,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
52191 pipe_lock(pipe);
52192
52193 while (pipe->nrbufs >= pipe->buffers) {
52194- if (!pipe->readers) {
52195+ if (!atomic_read(&pipe->readers)) {
52196 send_sig(SIGPIPE, current, 0);
52197 ret = -EPIPE;
52198 break;
52199@@ -1788,9 +1788,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
52200 ret = -ERESTARTSYS;
52201 break;
52202 }
52203- pipe->waiting_writers++;
52204+ atomic_inc(&pipe->waiting_writers);
52205 pipe_wait(pipe);
52206- pipe->waiting_writers--;
52207+ atomic_dec(&pipe->waiting_writers);
52208 }
52209
52210 pipe_unlock(pipe);
52211@@ -1826,14 +1826,14 @@ retry:
52212 pipe_double_lock(ipipe, opipe);
52213
52214 do {
52215- if (!opipe->readers) {
52216+ if (!atomic_read(&opipe->readers)) {
52217 send_sig(SIGPIPE, current, 0);
52218 if (!ret)
52219 ret = -EPIPE;
52220 break;
52221 }
52222
52223- if (!ipipe->nrbufs && !ipipe->writers)
52224+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
52225 break;
52226
52227 /*
52228@@ -1930,7 +1930,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
52229 pipe_double_lock(ipipe, opipe);
52230
52231 do {
52232- if (!opipe->readers) {
52233+ if (!atomic_read(&opipe->readers)) {
52234 send_sig(SIGPIPE, current, 0);
52235 if (!ret)
52236 ret = -EPIPE;
52237@@ -1975,7 +1975,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
52238 * return EAGAIN if we have the potential of some data in the
52239 * future, otherwise just return 0
52240 */
52241- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
52242+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
52243 ret = -EAGAIN;
52244
52245 pipe_unlock(ipipe);
52246diff --git a/fs/stat.c b/fs/stat.c
52247index eae4946..6198f55 100644
52248--- a/fs/stat.c
52249+++ b/fs/stat.c
52250@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
52251 stat->gid = inode->i_gid;
52252 stat->rdev = inode->i_rdev;
52253 stat->size = i_size_read(inode);
52254- stat->atime = inode->i_atime;
52255- stat->mtime = inode->i_mtime;
52256+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
52257+ stat->atime = inode->i_ctime;
52258+ stat->mtime = inode->i_ctime;
52259+ } else {
52260+ stat->atime = inode->i_atime;
52261+ stat->mtime = inode->i_mtime;
52262+ }
52263 stat->ctime = inode->i_ctime;
52264 stat->blksize = (1 << inode->i_blkbits);
52265 stat->blocks = inode->i_blocks;
52266@@ -46,8 +51,14 @@ int vfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
52267 if (retval)
52268 return retval;
52269
52270- if (inode->i_op->getattr)
52271- return inode->i_op->getattr(mnt, dentry, stat);
52272+ if (inode->i_op->getattr) {
52273+ retval = inode->i_op->getattr(mnt, dentry, stat);
52274+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
52275+ stat->atime = stat->ctime;
52276+ stat->mtime = stat->ctime;
52277+ }
52278+ return retval;
52279+ }
52280
52281 generic_fillattr(inode, stat);
52282 return 0;
52283diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
52284index 2fbdff6..5530a61 100644
52285--- a/fs/sysfs/dir.c
52286+++ b/fs/sysfs/dir.c
52287@@ -685,6 +685,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
52288 struct sysfs_dirent *sd;
52289 int rc;
52290
52291+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
52292+ const char *parent_name = parent_sd->s_name;
52293+
52294+ mode = S_IFDIR | S_IRWXU;
52295+
52296+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
52297+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
52298+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
52299+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
52300+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
52301+#endif
52302+
52303 /* allocate */
52304 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
52305 if (!sd)
52306diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
52307index 00012e3..8392349 100644
52308--- a/fs/sysfs/file.c
52309+++ b/fs/sysfs/file.c
52310@@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
52311
52312 struct sysfs_open_dirent {
52313 atomic_t refcnt;
52314- atomic_t event;
52315+ atomic_unchecked_t event;
52316 wait_queue_head_t poll;
52317 struct list_head buffers; /* goes through sysfs_buffer.list */
52318 };
52319@@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
52320 if (!sysfs_get_active(attr_sd))
52321 return -ENODEV;
52322
52323- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
52324+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
52325 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
52326
52327 sysfs_put_active(attr_sd);
52328@@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
52329 return -ENOMEM;
52330
52331 atomic_set(&new_od->refcnt, 0);
52332- atomic_set(&new_od->event, 1);
52333+ atomic_set_unchecked(&new_od->event, 1);
52334 init_waitqueue_head(&new_od->poll);
52335 INIT_LIST_HEAD(&new_od->buffers);
52336 goto retry;
52337@@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
52338
52339 sysfs_put_active(attr_sd);
52340
52341- if (buffer->event != atomic_read(&od->event))
52342+ if (buffer->event != atomic_read_unchecked(&od->event))
52343 goto trigger;
52344
52345 return DEFAULT_POLLMASK;
52346@@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
52347
52348 od = sd->s_attr.open;
52349 if (od) {
52350- atomic_inc(&od->event);
52351+ atomic_inc_unchecked(&od->event);
52352 wake_up_interruptible(&od->poll);
52353 }
52354
52355diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
52356index 3c9eb56..9dea5be 100644
52357--- a/fs/sysfs/symlink.c
52358+++ b/fs/sysfs/symlink.c
52359@@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
52360
52361 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
52362 {
52363- char *page = nd_get_link(nd);
52364+ const char *page = nd_get_link(nd);
52365 if (!IS_ERR(page))
52366 free_page((unsigned long)page);
52367 }
52368diff --git a/fs/udf/misc.c b/fs/udf/misc.c
52369index c175b4d..8f36a16 100644
52370--- a/fs/udf/misc.c
52371+++ b/fs/udf/misc.c
52372@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
52373
52374 u8 udf_tag_checksum(const struct tag *t)
52375 {
52376- u8 *data = (u8 *)t;
52377+ const u8 *data = (const u8 *)t;
52378 u8 checksum = 0;
52379 int i;
52380 for (i = 0; i < sizeof(struct tag); ++i)
52381diff --git a/fs/utimes.c b/fs/utimes.c
52382index bb0696a..552054b 100644
52383--- a/fs/utimes.c
52384+++ b/fs/utimes.c
52385@@ -1,6 +1,7 @@
52386 #include <linux/compiler.h>
52387 #include <linux/file.h>
52388 #include <linux/fs.h>
52389+#include <linux/security.h>
52390 #include <linux/linkage.h>
52391 #include <linux/mount.h>
52392 #include <linux/namei.h>
52393@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
52394 goto mnt_drop_write_and_out;
52395 }
52396 }
52397+
52398+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
52399+ error = -EACCES;
52400+ goto mnt_drop_write_and_out;
52401+ }
52402+
52403 mutex_lock(&inode->i_mutex);
52404 error = notify_change(path->dentry, &newattrs);
52405 mutex_unlock(&inode->i_mutex);
52406diff --git a/fs/xattr.c b/fs/xattr.c
52407index e21c119..21dfc7c 100644
52408--- a/fs/xattr.c
52409+++ b/fs/xattr.c
52410@@ -319,7 +319,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
52411 * Extended attribute SET operations
52412 */
52413 static long
52414-setxattr(struct dentry *d, const char __user *name, const void __user *value,
52415+setxattr(struct path *path, const char __user *name, const void __user *value,
52416 size_t size, int flags)
52417 {
52418 int error;
52419@@ -355,7 +355,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
52420 posix_acl_fix_xattr_from_user(kvalue, size);
52421 }
52422
52423- error = vfs_setxattr(d, kname, kvalue, size, flags);
52424+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
52425+ error = -EACCES;
52426+ goto out;
52427+ }
52428+
52429+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
52430 out:
52431 if (vvalue)
52432 vfree(vvalue);
52433@@ -376,7 +381,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
52434 return error;
52435 error = mnt_want_write(path.mnt);
52436 if (!error) {
52437- error = setxattr(path.dentry, name, value, size, flags);
52438+ error = setxattr(&path, name, value, size, flags);
52439 mnt_drop_write(path.mnt);
52440 }
52441 path_put(&path);
52442@@ -395,7 +400,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
52443 return error;
52444 error = mnt_want_write(path.mnt);
52445 if (!error) {
52446- error = setxattr(path.dentry, name, value, size, flags);
52447+ error = setxattr(&path, name, value, size, flags);
52448 mnt_drop_write(path.mnt);
52449 }
52450 path_put(&path);
52451@@ -406,16 +411,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
52452 const void __user *,value, size_t, size, int, flags)
52453 {
52454 struct fd f = fdget(fd);
52455- struct dentry *dentry;
52456 int error = -EBADF;
52457
52458 if (!f.file)
52459 return error;
52460- dentry = f.file->f_path.dentry;
52461- audit_inode(NULL, dentry, 0);
52462+ audit_inode(NULL, f.file->f_path.dentry, 0);
52463 error = mnt_want_write_file(f.file);
52464 if (!error) {
52465- error = setxattr(dentry, name, value, size, flags);
52466+ error = setxattr(&f.file->f_path, name, value, size, flags);
52467 mnt_drop_write_file(f.file);
52468 }
52469 fdput(f);
52470diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
52471index 9fbea87..6b19972 100644
52472--- a/fs/xattr_acl.c
52473+++ b/fs/xattr_acl.c
52474@@ -76,8 +76,8 @@ struct posix_acl *
52475 posix_acl_from_xattr(struct user_namespace *user_ns,
52476 const void *value, size_t size)
52477 {
52478- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
52479- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
52480+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
52481+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
52482 int count;
52483 struct posix_acl *acl;
52484 struct posix_acl_entry *acl_e;
52485diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
52486index 83d0cf3..2ef526b 100644
52487--- a/fs/xfs/xfs_bmap.c
52488+++ b/fs/xfs/xfs_bmap.c
52489@@ -189,7 +189,7 @@ xfs_bmap_validate_ret(
52490 int nmap,
52491 int ret_nmap);
52492 #else
52493-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
52494+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
52495 #endif /* DEBUG */
52496
52497 STATIC int
52498diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
52499index 1b9fc3e..e1bdde0 100644
52500--- a/fs/xfs/xfs_dir2_sf.c
52501+++ b/fs/xfs/xfs_dir2_sf.c
52502@@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
52503 }
52504
52505 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
52506- if (filldir(dirent, (char *)sfep->name, sfep->namelen,
52507+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
52508+ char name[sfep->namelen];
52509+ memcpy(name, sfep->name, sfep->namelen);
52510+ if (filldir(dirent, name, sfep->namelen,
52511+ off & 0x7fffffff, ino, DT_UNKNOWN)) {
52512+ *offset = off & 0x7fffffff;
52513+ return 0;
52514+ }
52515+ } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
52516 off & 0x7fffffff, ino, DT_UNKNOWN)) {
52517 *offset = off & 0x7fffffff;
52518 return 0;
52519diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
52520index c1df3c6..f987db6 100644
52521--- a/fs/xfs/xfs_ioctl.c
52522+++ b/fs/xfs/xfs_ioctl.c
52523@@ -126,7 +126,7 @@ xfs_find_handle(
52524 }
52525
52526 error = -EFAULT;
52527- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
52528+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
52529 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
52530 goto out_put;
52531
52532diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
52533index 4e00cf0..3374374 100644
52534--- a/fs/xfs/xfs_iops.c
52535+++ b/fs/xfs/xfs_iops.c
52536@@ -394,7 +394,7 @@ xfs_vn_put_link(
52537 struct nameidata *nd,
52538 void *p)
52539 {
52540- char *s = nd_get_link(nd);
52541+ const char *s = nd_get_link(nd);
52542
52543 if (!IS_ERR(s))
52544 kfree(s);
52545diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
52546new file mode 100644
52547index 0000000..92247e4
52548--- /dev/null
52549+++ b/grsecurity/Kconfig
52550@@ -0,0 +1,1021 @@
52551+#
52552+# grecurity configuration
52553+#
52554+menu "Memory Protections"
52555+depends on GRKERNSEC
52556+
52557+config GRKERNSEC_KMEM
52558+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
52559+ default y if GRKERNSEC_CONFIG_AUTO
52560+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
52561+ help
52562+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
52563+ be written to or read from to modify or leak the contents of the running
52564+ kernel. /dev/port will also not be allowed to be opened and support
52565+ for /dev/cpu/*/msr will be removed. If you have module
52566+ support disabled, enabling this will close up five ways that are
52567+ currently used to insert malicious code into the running kernel.
52568+
52569+ Even with all these features enabled, we still highly recommend that
52570+ you use the RBAC system, as it is still possible for an attacker to
52571+ modify the running kernel through privileged I/O granted by ioperm/iopl.
52572+
52573+ If you are not using XFree86, you may be able to stop this additional
52574+ case by enabling the 'Disable privileged I/O' option. Though nothing
52575+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
52576+ but only to video memory, which is the only writing we allow in this
52577+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
52578+ not be allowed to mprotect it with PROT_WRITE later.
52579+ Enabling this feature will prevent the "cpupower" and "powertop" tools
52580+ from working.
52581+
52582+ It is highly recommended that you say Y here if you meet all the
52583+ conditions above.
52584+
52585+config GRKERNSEC_VM86
52586+ bool "Restrict VM86 mode"
52587+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
52588+ depends on X86_32
52589+
52590+ help
52591+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
52592+ make use of a special execution mode on 32bit x86 processors called
52593+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
52594+ video cards and will still work with this option enabled. The purpose
52595+ of the option is to prevent exploitation of emulation errors in
52596+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
52597+ Nearly all users should be able to enable this option.
52598+
52599+config GRKERNSEC_IO
52600+ bool "Disable privileged I/O"
52601+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
52602+ depends on X86
52603+ select RTC_CLASS
52604+ select RTC_INTF_DEV
52605+ select RTC_DRV_CMOS
52606+
52607+ help
52608+ If you say Y here, all ioperm and iopl calls will return an error.
52609+ Ioperm and iopl can be used to modify the running kernel.
52610+ Unfortunately, some programs need this access to operate properly,
52611+ the most notable of which are XFree86 and hwclock. hwclock can be
52612+ remedied by having RTC support in the kernel, so real-time
52613+ clock support is enabled if this option is enabled, to ensure
52614+ that hwclock operates correctly. XFree86 still will not
52615+ operate correctly with this option enabled, so DO NOT CHOOSE Y
52616+ IF YOU USE XFree86. If you use XFree86 and you still want to
52617+ protect your kernel against modification, use the RBAC system.
52618+
52619+config GRKERNSEC_JIT_HARDEN
52620+ bool "Harden BPF JIT against spray attacks"
52621+ default y if GRKERNSEC_CONFIG_AUTO
52622+ depends on BPF_JIT
52623+ help
52624+ If you say Y here, the native code generated by the kernel's Berkeley
52625+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
52626+ attacks that attempt to fit attacker-beneficial instructions in
52627+ 32bit immediate fields of JIT-generated native instructions. The
52628+ attacker will generally aim to cause an unintended instruction sequence
52629+ of JIT-generated native code to execute by jumping into the middle of
52630+ a generated instruction. This feature effectively randomizes the 32bit
52631+ immediate constants present in the generated code to thwart such attacks.
52632+
52633+ If you're using KERNEXEC, it's recommended that you enable this option
52634+ to supplement the hardening of the kernel.
52635+
52636+config GRKERNSEC_RAND_THREADSTACK
52637+ bool "Insert random gaps between thread stacks"
52638+ default y if GRKERNSEC_CONFIG_AUTO
52639+ depends on PAX_RANDMMAP && !PPC
52640+ help
52641+ If you say Y here, a random-sized gap will be enforced between allocated
52642+ thread stacks. Glibc's NPTL and other threading libraries that
52643+ pass MAP_STACK to the kernel for thread stack allocation are supported.
52644+ The implementation currently provides 8 bits of entropy for the gap.
52645+
52646+ Many distributions do not compile threaded remote services with the
52647+ -fstack-check argument to GCC, causing the variable-sized stack-based
52648+ allocator, alloca(), to not probe the stack on allocation. This
52649+ permits an unbounded alloca() to skip over any guard page and potentially
52650+ modify another thread's stack reliably. An enforced random gap
52651+ reduces the reliability of such an attack and increases the chance
52652+ that such a read/write to another thread's stack instead lands in
52653+ an unmapped area, causing a crash and triggering grsecurity's
52654+ anti-bruteforcing logic.
52655+
52656+config GRKERNSEC_PROC_MEMMAP
52657+ bool "Harden ASLR against information leaks and entropy reduction"
52658+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
52659+ depends on PAX_NOEXEC || PAX_ASLR
52660+ help
52661+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
52662+ give no information about the addresses of its mappings if
52663+ PaX features that rely on random addresses are enabled on the task.
52664+ In addition to sanitizing this information and disabling other
52665+ dangerous sources of information, this option causes reads of sensitive
52666+ /proc/<pid> entries where the file descriptor was opened in a different
52667+ task than the one performing the read. Such attempts are logged.
52668+ This option also limits argv/env strings for suid/sgid binaries
52669+ to 512KB to prevent a complete exhaustion of the stack entropy provided
52670+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
52671+ binaries to prevent alternative mmap layouts from being abused.
52672+
52673+ If you use PaX it is essential that you say Y here as it closes up
52674+ several holes that make full ASLR useless locally.
52675+
52676+config GRKERNSEC_BRUTE
52677+ bool "Deter exploit bruteforcing"
52678+ default y if GRKERNSEC_CONFIG_AUTO
52679+ help
52680+ If you say Y here, attempts to bruteforce exploits against forking
52681+ daemons such as apache or sshd, as well as against suid/sgid binaries
52682+ will be deterred. When a child of a forking daemon is killed by PaX
52683+ or crashes due to an illegal instruction or other suspicious signal,
52684+ the parent process will be delayed 30 seconds upon every subsequent
52685+ fork until the administrator is able to assess the situation and
52686+ restart the daemon.
52687+ In the suid/sgid case, the attempt is logged, the user has all their
52688+ processes terminated, and they are prevented from executing any further
52689+ processes for 15 minutes.
52690+ It is recommended that you also enable signal logging in the auditing
52691+ section so that logs are generated when a process triggers a suspicious
52692+ signal.
52693+ If the sysctl option is enabled, a sysctl option with name
52694+ "deter_bruteforce" is created.
52695+
52696+
52697+config GRKERNSEC_MODHARDEN
52698+ bool "Harden module auto-loading"
52699+ default y if GRKERNSEC_CONFIG_AUTO
52700+ depends on MODULES
52701+ help
52702+ If you say Y here, module auto-loading in response to use of some
52703+ feature implemented by an unloaded module will be restricted to
52704+ root users. Enabling this option helps defend against attacks
52705+ by unprivileged users who abuse the auto-loading behavior to
52706+ cause a vulnerable module to load that is then exploited.
52707+
52708+ If this option prevents a legitimate use of auto-loading for a
52709+ non-root user, the administrator can execute modprobe manually
52710+ with the exact name of the module mentioned in the alert log.
52711+ Alternatively, the administrator can add the module to the list
52712+ of modules loaded at boot by modifying init scripts.
52713+
52714+ Modification of init scripts will most likely be needed on
52715+ Ubuntu servers with encrypted home directory support enabled,
52716+ as the first non-root user logging in will cause the ecb(aes),
52717+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
52718+
52719+config GRKERNSEC_HIDESYM
52720+ bool "Hide kernel symbols"
52721+ default y if GRKERNSEC_CONFIG_AUTO
52722+ select PAX_USERCOPY_SLABS
52723+ help
52724+ If you say Y here, getting information on loaded modules, and
52725+ displaying all kernel symbols through a syscall will be restricted
52726+ to users with CAP_SYS_MODULE. For software compatibility reasons,
52727+ /proc/kallsyms will be restricted to the root user. The RBAC
52728+ system can hide that entry even from root.
52729+
52730+ This option also prevents leaking of kernel addresses through
52731+ several /proc entries.
52732+
52733+ Note that this option is only effective provided the following
52734+ conditions are met:
52735+ 1) The kernel using grsecurity is not precompiled by some distribution
52736+ 2) You have also enabled GRKERNSEC_DMESG
52737+ 3) You are using the RBAC system and hiding other files such as your
52738+ kernel image and System.map. Alternatively, enabling this option
52739+ causes the permissions on /boot, /lib/modules, and the kernel
52740+ source directory to change at compile time to prevent
52741+ reading by non-root users.
52742+ If the above conditions are met, this option will aid in providing a
52743+ useful protection against local kernel exploitation of overflows
52744+ and arbitrary read/write vulnerabilities.
52745+
52746+config GRKERNSEC_KERN_LOCKOUT
52747+ bool "Active kernel exploit response"
52748+ default y if GRKERNSEC_CONFIG_AUTO
52749+ depends on X86 || ARM || PPC || SPARC
52750+ help
52751+ If you say Y here, when a PaX alert is triggered due to suspicious
52752+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
52753+ or an OOPS occurs due to bad memory accesses, instead of just
52754+ terminating the offending process (and potentially allowing
52755+ a subsequent exploit from the same user), we will take one of two
52756+ actions:
52757+ If the user was root, we will panic the system
52758+ If the user was non-root, we will log the attempt, terminate
52759+ all processes owned by the user, then prevent them from creating
52760+ any new processes until the system is restarted
52761+ This deters repeated kernel exploitation/bruteforcing attempts
52762+ and is useful for later forensics.
52763+
52764+endmenu
52765+menu "Role Based Access Control Options"
52766+depends on GRKERNSEC
52767+
52768+config GRKERNSEC_RBAC_DEBUG
52769+ bool
52770+
52771+config GRKERNSEC_NO_RBAC
52772+ bool "Disable RBAC system"
52773+ help
52774+ If you say Y here, the /dev/grsec device will be removed from the kernel,
52775+ preventing the RBAC system from being enabled. You should only say Y
52776+ here if you have no intention of using the RBAC system, so as to prevent
52777+ an attacker with root access from misusing the RBAC system to hide files
52778+ and processes when loadable module support and /dev/[k]mem have been
52779+ locked down.
52780+
52781+config GRKERNSEC_ACL_HIDEKERN
52782+ bool "Hide kernel processes"
52783+ help
52784+ If you say Y here, all kernel threads will be hidden to all
52785+ processes but those whose subject has the "view hidden processes"
52786+ flag.
52787+
52788+config GRKERNSEC_ACL_MAXTRIES
52789+ int "Maximum tries before password lockout"
52790+ default 3
52791+ help
52792+ This option enforces the maximum number of times a user can attempt
52793+ to authorize themselves with the grsecurity RBAC system before being
52794+ denied the ability to attempt authorization again for a specified time.
52795+ The lower the number, the harder it will be to brute-force a password.
52796+
52797+config GRKERNSEC_ACL_TIMEOUT
52798+ int "Time to wait after max password tries, in seconds"
52799+ default 30
52800+ help
52801+ This option specifies the time the user must wait after attempting to
52802+ authorize to the RBAC system with the maximum number of invalid
52803+ passwords. The higher the number, the harder it will be to brute-force
52804+ a password.
52805+
52806+endmenu
52807+menu "Filesystem Protections"
52808+depends on GRKERNSEC
52809+
52810+config GRKERNSEC_PROC
52811+ bool "Proc restrictions"
52812+ default y if GRKERNSEC_CONFIG_AUTO
52813+ help
52814+ If you say Y here, the permissions of the /proc filesystem
52815+ will be altered to enhance system security and privacy. You MUST
52816+ choose either a user only restriction or a user and group restriction.
52817+ Depending upon the option you choose, you can either restrict users to
52818+ see only the processes they themselves run, or choose a group that can
52819+ view all processes and files normally restricted to root if you choose
52820+ the "restrict to user only" option. NOTE: If you're running identd or
52821+ ntpd as a non-root user, you will have to run it as the group you
52822+ specify here.
52823+
52824+config GRKERNSEC_PROC_USER
52825+ bool "Restrict /proc to user only"
52826+ depends on GRKERNSEC_PROC
52827+ help
52828+ If you say Y here, non-root users will only be able to view their own
52829+ processes, and restricts them from viewing network-related information,
52830+ and viewing kernel symbol and module information.
52831+
52832+config GRKERNSEC_PROC_USERGROUP
52833+ bool "Allow special group"
52834+ default y if GRKERNSEC_CONFIG_AUTO
52835+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
52836+ help
52837+ If you say Y here, you will be able to select a group that will be
52838+ able to view all processes and network-related information. If you've
52839+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
52840+ remain hidden. This option is useful if you want to run identd as
52841+ a non-root user. The group you select may also be chosen at boot time
52842+ via "grsec_proc_gid=" on the kernel commandline.
52843+
52844+config GRKERNSEC_PROC_GID
52845+ int "GID for special group"
52846+ depends on GRKERNSEC_PROC_USERGROUP
52847+ default 1001
52848+
52849+config GRKERNSEC_PROC_ADD
52850+ bool "Additional restrictions"
52851+ default y if GRKERNSEC_CONFIG_AUTO
52852+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
52853+ help
52854+ If you say Y here, additional restrictions will be placed on
52855+ /proc that keep normal users from viewing device information and
52856+ slabinfo information that could be useful for exploits.
52857+
52858+config GRKERNSEC_LINK
52859+ bool "Linking restrictions"
52860+ default y if GRKERNSEC_CONFIG_AUTO
52861+ help
52862+ If you say Y here, /tmp race exploits will be prevented, since users
52863+ will no longer be able to follow symlinks owned by other users in
52864+ world-writable +t directories (e.g. /tmp), unless the owner of the
52865+ symlink is the owner of the directory. users will also not be
52866+ able to hardlink to files they do not own. If the sysctl option is
52867+ enabled, a sysctl option with name "linking_restrictions" is created.
52868+
52869+config GRKERNSEC_SYMLINKOWN
52870+ bool "Kernel-enforced SymlinksIfOwnerMatch"
52871+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
52872+ help
52873+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
52874+ that prevents it from being used as a security feature. As Apache
52875+ verifies the symlink by performing a stat() against the target of
52876+ the symlink before it is followed, an attacker can setup a symlink
52877+ to point to a same-owned file, then replace the symlink with one
52878+ that targets another user's file just after Apache "validates" the
52879+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
52880+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
52881+ will be in place for the group you specify. If the sysctl option
52882+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
52883+ created.
52884+
52885+config GRKERNSEC_SYMLINKOWN_GID
52886+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
52887+ depends on GRKERNSEC_SYMLINKOWN
52888+ default 1006
52889+ help
52890+ Setting this GID determines what group kernel-enforced
52891+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
52892+ is enabled, a sysctl option with name "symlinkown_gid" is created.
52893+
52894+config GRKERNSEC_FIFO
52895+ bool "FIFO restrictions"
52896+ default y if GRKERNSEC_CONFIG_AUTO
52897+ help
52898+ If you say Y here, users will not be able to write to FIFOs they don't
52899+ own in world-writable +t directories (e.g. /tmp), unless the owner of
52900+ the FIFO is the same owner of the directory it's held in. If the sysctl
52901+ option is enabled, a sysctl option with name "fifo_restrictions" is
52902+ created.
52903+
52904+config GRKERNSEC_SYSFS_RESTRICT
52905+ bool "Sysfs/debugfs restriction"
52906+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
52907+ depends on SYSFS
52908+ help
52909+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
52910+ any filesystem normally mounted under it (e.g. debugfs) will be
52911+ mostly accessible only by root. These filesystems generally provide access
52912+ to hardware and debug information that isn't appropriate for unprivileged
52913+ users of the system. Sysfs and debugfs have also become a large source
52914+ of new vulnerabilities, ranging from infoleaks to local compromise.
52915+ There has been very little oversight with an eye toward security involved
52916+ in adding new exporters of information to these filesystems, so their
52917+ use is discouraged.
52918+ For reasons of compatibility, a few directories have been whitelisted
52919+ for access by non-root users:
52920+ /sys/fs/selinux
52921+ /sys/fs/fuse
52922+ /sys/devices/system/cpu
52923+
52924+config GRKERNSEC_ROFS
52925+ bool "Runtime read-only mount protection"
52926+ help
52927+ If you say Y here, a sysctl option with name "romount_protect" will
52928+ be created. By setting this option to 1 at runtime, filesystems
52929+ will be protected in the following ways:
52930+ * No new writable mounts will be allowed
52931+ * Existing read-only mounts won't be able to be remounted read/write
52932+ * Write operations will be denied on all block devices
52933+ This option acts independently of grsec_lock: once it is set to 1,
52934+ it cannot be turned off. Therefore, please be mindful of the resulting
52935+ behavior if this option is enabled in an init script on a read-only
52936+ filesystem. This feature is mainly intended for secure embedded systems.
52937+
52938+config GRKERNSEC_DEVICE_SIDECHANNEL
52939+ bool "Eliminate stat/notify-based device sidechannels"
52940+ default y if GRKERNSEC_CONFIG_AUTO
52941+ help
52942+ If you say Y here, timing analyses on block or character
52943+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
52944+ will be thwarted for unprivileged users. If a process without
52945+ CAP_MKNOD stats such a device, the last access and last modify times
52946+ will match the device's create time. No access or modify events
52947+ will be triggered through inotify/dnotify/fanotify for such devices.
52948+ This feature will prevent attacks that may at a minimum
52949+ allow an attacker to determine the administrator's password length.
52950+
52951+config GRKERNSEC_CHROOT
52952+ bool "Chroot jail restrictions"
52953+ default y if GRKERNSEC_CONFIG_AUTO
52954+ help
52955+ If you say Y here, you will be able to choose several options that will
52956+ make breaking out of a chrooted jail much more difficult. If you
52957+ encounter no software incompatibilities with the following options, it
52958+ is recommended that you enable each one.
52959+
52960+config GRKERNSEC_CHROOT_MOUNT
52961+ bool "Deny mounts"
52962+ default y if GRKERNSEC_CONFIG_AUTO
52963+ depends on GRKERNSEC_CHROOT
52964+ help
52965+ If you say Y here, processes inside a chroot will not be able to
52966+ mount or remount filesystems. If the sysctl option is enabled, a
52967+ sysctl option with name "chroot_deny_mount" is created.
52968+
52969+config GRKERNSEC_CHROOT_DOUBLE
52970+ bool "Deny double-chroots"
52971+ default y if GRKERNSEC_CONFIG_AUTO
52972+ depends on GRKERNSEC_CHROOT
52973+ help
52974+ If you say Y here, processes inside a chroot will not be able to chroot
52975+ again outside the chroot. This is a widely used method of breaking
52976+ out of a chroot jail and should not be allowed. If the sysctl
52977+ option is enabled, a sysctl option with name
52978+ "chroot_deny_chroot" is created.
52979+
52980+config GRKERNSEC_CHROOT_PIVOT
52981+ bool "Deny pivot_root in chroot"
52982+ default y if GRKERNSEC_CONFIG_AUTO
52983+ depends on GRKERNSEC_CHROOT
52984+ help
52985+ If you say Y here, processes inside a chroot will not be able to use
52986+ a function called pivot_root() that was introduced in Linux 2.3.41. It
52987+ works similar to chroot in that it changes the root filesystem. This
52988+ function could be misused in a chrooted process to attempt to break out
52989+ of the chroot, and therefore should not be allowed. If the sysctl
52990+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
52991+ created.
52992+
52993+config GRKERNSEC_CHROOT_CHDIR
52994+ bool "Enforce chdir(\"/\") on all chroots"
52995+ default y if GRKERNSEC_CONFIG_AUTO
52996+ depends on GRKERNSEC_CHROOT
52997+ help
52998+ If you say Y here, the current working directory of all newly-chrooted
52999+ applications will be set to the the root directory of the chroot.
53000+ The man page on chroot(2) states:
53001+ Note that this call does not change the current working
53002+ directory, so that `.' can be outside the tree rooted at
53003+ `/'. In particular, the super-user can escape from a
53004+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
53005+
53006+ It is recommended that you say Y here, since it's not known to break
53007+ any software. If the sysctl option is enabled, a sysctl option with
53008+ name "chroot_enforce_chdir" is created.
53009+
53010+config GRKERNSEC_CHROOT_CHMOD
53011+ bool "Deny (f)chmod +s"
53012+ default y if GRKERNSEC_CONFIG_AUTO
53013+ depends on GRKERNSEC_CHROOT
53014+ help
53015+ If you say Y here, processes inside a chroot will not be able to chmod
53016+ or fchmod files to make them have suid or sgid bits. This protects
53017+ against another published method of breaking a chroot. If the sysctl
53018+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
53019+ created.
53020+
53021+config GRKERNSEC_CHROOT_FCHDIR
53022+ bool "Deny fchdir out of chroot"
53023+ default y if GRKERNSEC_CONFIG_AUTO
53024+ depends on GRKERNSEC_CHROOT
53025+ help
53026+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
53027+ to a file descriptor of the chrooting process that points to a directory
53028+ outside the filesystem will be stopped. If the sysctl option
53029+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
53030+
53031+config GRKERNSEC_CHROOT_MKNOD
53032+ bool "Deny mknod"
53033+ default y if GRKERNSEC_CONFIG_AUTO
53034+ depends on GRKERNSEC_CHROOT
53035+ help
53036+ If you say Y here, processes inside a chroot will not be allowed to
53037+ mknod. The problem with using mknod inside a chroot is that it
53038+ would allow an attacker to create a device entry that is the same
53039+ as one on the physical root of your system, which could range from
53040+ anything from the console device to a device for your harddrive (which
53041+ they could then use to wipe the drive or steal data). It is recommended
53042+ that you say Y here, unless you run into software incompatibilities.
53043+ If the sysctl option is enabled, a sysctl option with name
53044+ "chroot_deny_mknod" is created.
53045+
53046+config GRKERNSEC_CHROOT_SHMAT
53047+ bool "Deny shmat() out of chroot"
53048+ default y if GRKERNSEC_CONFIG_AUTO
53049+ depends on GRKERNSEC_CHROOT
53050+ help
53051+ If you say Y here, processes inside a chroot will not be able to attach
53052+ to shared memory segments that were created outside of the chroot jail.
53053+ It is recommended that you say Y here. If the sysctl option is enabled,
53054+ a sysctl option with name "chroot_deny_shmat" is created.
53055+
53056+config GRKERNSEC_CHROOT_UNIX
53057+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
53058+ default y if GRKERNSEC_CONFIG_AUTO
53059+ depends on GRKERNSEC_CHROOT
53060+ help
53061+ If you say Y here, processes inside a chroot will not be able to
53062+ connect to abstract (meaning not belonging to a filesystem) Unix
53063+ domain sockets that were bound outside of a chroot. It is recommended
53064+ that you say Y here. If the sysctl option is enabled, a sysctl option
53065+ with name "chroot_deny_unix" is created.
53066+
53067+config GRKERNSEC_CHROOT_FINDTASK
53068+ bool "Protect outside processes"
53069+ default y if GRKERNSEC_CONFIG_AUTO
53070+ depends on GRKERNSEC_CHROOT
53071+ help
53072+ If you say Y here, processes inside a chroot will not be able to
53073+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
53074+ getsid, or view any process outside of the chroot. If the sysctl
53075+ option is enabled, a sysctl option with name "chroot_findtask" is
53076+ created.
53077+
53078+config GRKERNSEC_CHROOT_NICE
53079+ bool "Restrict priority changes"
53080+ default y if GRKERNSEC_CONFIG_AUTO
53081+ depends on GRKERNSEC_CHROOT
53082+ help
53083+ If you say Y here, processes inside a chroot will not be able to raise
53084+ the priority of processes in the chroot, or alter the priority of
53085+ processes outside the chroot. This provides more security than simply
53086+ removing CAP_SYS_NICE from the process' capability set. If the
53087+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
53088+ is created.
53089+
53090+config GRKERNSEC_CHROOT_SYSCTL
53091+ bool "Deny sysctl writes"
53092+ default y if GRKERNSEC_CONFIG_AUTO
53093+ depends on GRKERNSEC_CHROOT
53094+ help
53095+ If you say Y here, an attacker in a chroot will not be able to
53096+ write to sysctl entries, either by sysctl(2) or through a /proc
53097+ interface. It is strongly recommended that you say Y here. If the
53098+ sysctl option is enabled, a sysctl option with name
53099+ "chroot_deny_sysctl" is created.
53100+
53101+config GRKERNSEC_CHROOT_CAPS
53102+ bool "Capability restrictions"
53103+ default y if GRKERNSEC_CONFIG_AUTO
53104+ depends on GRKERNSEC_CHROOT
53105+ help
53106+ If you say Y here, the capabilities on all processes within a
53107+ chroot jail will be lowered to stop module insertion, raw i/o,
53108+ system and net admin tasks, rebooting the system, modifying immutable
53109+ files, modifying IPC owned by another, and changing the system time.
53110+ This is left an option because it can break some apps. Disable this
53111+ if your chrooted apps are having problems performing those kinds of
53112+ tasks. If the sysctl option is enabled, a sysctl option with
53113+ name "chroot_caps" is created.
53114+
53115+endmenu
53116+menu "Kernel Auditing"
53117+depends on GRKERNSEC
53118+
53119+config GRKERNSEC_AUDIT_GROUP
53120+ bool "Single group for auditing"
53121+ help
53122+ If you say Y here, the exec and chdir logging features will only operate
53123+ on a group you specify. This option is recommended if you only want to
53124+ watch certain users instead of having a large amount of logs from the
53125+ entire system. If the sysctl option is enabled, a sysctl option with
53126+ name "audit_group" is created.
53127+
53128+config GRKERNSEC_AUDIT_GID
53129+ int "GID for auditing"
53130+ depends on GRKERNSEC_AUDIT_GROUP
53131+ default 1007
53132+
53133+config GRKERNSEC_EXECLOG
53134+ bool "Exec logging"
53135+ help
53136+ If you say Y here, all execve() calls will be logged (since the
53137+ other exec*() calls are frontends to execve(), all execution
53138+ will be logged). Useful for shell-servers that like to keep track
53139+ of their users. If the sysctl option is enabled, a sysctl option with
53140+ name "exec_logging" is created.
53141+ WARNING: This option when enabled will produce a LOT of logs, especially
53142+ on an active system.
53143+
53144+config GRKERNSEC_RESLOG
53145+ bool "Resource logging"
53146+ default y if GRKERNSEC_CONFIG_AUTO
53147+ help
53148+ If you say Y here, all attempts to overstep resource limits will
53149+ be logged with the resource name, the requested size, and the current
53150+ limit. It is highly recommended that you say Y here. If the sysctl
53151+ option is enabled, a sysctl option with name "resource_logging" is
53152+ created. If the RBAC system is enabled, the sysctl value is ignored.
53153+
53154+config GRKERNSEC_CHROOT_EXECLOG
53155+ bool "Log execs within chroot"
53156+ help
53157+ If you say Y here, all executions inside a chroot jail will be logged
53158+ to syslog. This can cause a large amount of logs if certain
53159+ applications (eg. djb's daemontools) are installed on the system, and
53160+ is therefore left as an option. If the sysctl option is enabled, a
53161+ sysctl option with name "chroot_execlog" is created.
53162+
53163+config GRKERNSEC_AUDIT_PTRACE
53164+ bool "Ptrace logging"
53165+ help
53166+ If you say Y here, all attempts to attach to a process via ptrace
53167+ will be logged. If the sysctl option is enabled, a sysctl option
53168+ with name "audit_ptrace" is created.
53169+
53170+config GRKERNSEC_AUDIT_CHDIR
53171+ bool "Chdir logging"
53172+ help
53173+ If you say Y here, all chdir() calls will be logged. If the sysctl
53174+ option is enabled, a sysctl option with name "audit_chdir" is created.
53175+
53176+config GRKERNSEC_AUDIT_MOUNT
53177+ bool "(Un)Mount logging"
53178+ help
53179+ If you say Y here, all mounts and unmounts will be logged. If the
53180+ sysctl option is enabled, a sysctl option with name "audit_mount" is
53181+ created.
53182+
53183+config GRKERNSEC_SIGNAL
53184+ bool "Signal logging"
53185+ default y if GRKERNSEC_CONFIG_AUTO
53186+ help
53187+ If you say Y here, certain important signals will be logged, such as
53188+ SIGSEGV, which will as a result inform you of when a error in a program
53189+ occurred, which in some cases could mean a possible exploit attempt.
53190+ If the sysctl option is enabled, a sysctl option with name
53191+ "signal_logging" is created.
53192+
53193+config GRKERNSEC_FORKFAIL
53194+ bool "Fork failure logging"
53195+ help
53196+ If you say Y here, all failed fork() attempts will be logged.
53197+ This could suggest a fork bomb, or someone attempting to overstep
53198+ their process limit. If the sysctl option is enabled, a sysctl option
53199+ with name "forkfail_logging" is created.
53200+
53201+config GRKERNSEC_TIME
53202+ bool "Time change logging"
53203+ default y if GRKERNSEC_CONFIG_AUTO
53204+ help
53205+ If you say Y here, any changes of the system clock will be logged.
53206+ If the sysctl option is enabled, a sysctl option with name
53207+ "timechange_logging" is created.
53208+
53209+config GRKERNSEC_PROC_IPADDR
53210+ bool "/proc/<pid>/ipaddr support"
53211+ default y if GRKERNSEC_CONFIG_AUTO
53212+ help
53213+ If you say Y here, a new entry will be added to each /proc/<pid>
53214+ directory that contains the IP address of the person using the task.
53215+ The IP is carried across local TCP and AF_UNIX stream sockets.
53216+ This information can be useful for IDS/IPSes to perform remote response
53217+ to a local attack. The entry is readable by only the owner of the
53218+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
53219+ the RBAC system), and thus does not create privacy concerns.
53220+
53221+config GRKERNSEC_RWXMAP_LOG
53222+ bool 'Denied RWX mmap/mprotect logging'
53223+ default y if GRKERNSEC_CONFIG_AUTO
53224+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
53225+ help
53226+ If you say Y here, calls to mmap() and mprotect() with explicit
53227+ usage of PROT_WRITE and PROT_EXEC together will be logged when
53228+ denied by the PAX_MPROTECT feature. If the sysctl option is
53229+ enabled, a sysctl option with name "rwxmap_logging" is created.
53230+
53231+config GRKERNSEC_AUDIT_TEXTREL
53232+ bool 'ELF text relocations logging (READ HELP)'
53233+ depends on PAX_MPROTECT
53234+ help
53235+ If you say Y here, text relocations will be logged with the filename
53236+ of the offending library or binary. The purpose of the feature is
53237+ to help Linux distribution developers get rid of libraries and
53238+ binaries that need text relocations which hinder the future progress
53239+ of PaX. Only Linux distribution developers should say Y here, and
53240+ never on a production machine, as this option creates an information
53241+ leak that could aid an attacker in defeating the randomization of
53242+ a single memory region. If the sysctl option is enabled, a sysctl
53243+ option with name "audit_textrel" is created.
53244+
53245+endmenu
53246+
53247+menu "Executable Protections"
53248+depends on GRKERNSEC
53249+
53250+config GRKERNSEC_DMESG
53251+ bool "Dmesg(8) restriction"
53252+ default y if GRKERNSEC_CONFIG_AUTO
53253+ help
53254+ If you say Y here, non-root users will not be able to use dmesg(8)
53255+ to view the contents of the kernel's circular log buffer.
53256+ The kernel's log buffer often contains kernel addresses and other
53257+ identifying information useful to an attacker in fingerprinting a
53258+ system for a targeted exploit.
53259+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
53260+ created.
53261+
53262+config GRKERNSEC_HARDEN_PTRACE
53263+ bool "Deter ptrace-based process snooping"
53264+ default y if GRKERNSEC_CONFIG_AUTO
53265+ help
53266+ If you say Y here, TTY sniffers and other malicious monitoring
53267+ programs implemented through ptrace will be defeated. If you
53268+ have been using the RBAC system, this option has already been
53269+ enabled for several years for all users, with the ability to make
53270+ fine-grained exceptions.
53271+
53272+ This option only affects the ability of non-root users to ptrace
53273+ processes that are not a descendent of the ptracing process.
53274+ This means that strace ./binary and gdb ./binary will still work,
53275+ but attaching to arbitrary processes will not. If the sysctl
53276+ option is enabled, a sysctl option with name "harden_ptrace" is
53277+ created.
53278+
53279+config GRKERNSEC_PTRACE_READEXEC
53280+ bool "Require read access to ptrace sensitive binaries"
53281+ default y if GRKERNSEC_CONFIG_AUTO
53282+ help
53283+ If you say Y here, unprivileged users will not be able to ptrace unreadable
53284+ binaries. This option is useful in environments that
53285+ remove the read bits (e.g. file mode 4711) from suid binaries to
53286+ prevent infoleaking of their contents. This option adds
53287+ consistency to the use of that file mode, as the binary could normally
53288+ be read out when run without privileges while ptracing.
53289+
53290+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
53291+ is created.
53292+
53293+config GRKERNSEC_SETXID
53294+ bool "Enforce consistent multithreaded privileges"
53295+ default y if GRKERNSEC_CONFIG_AUTO
53296+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
53297+ help
53298+ If you say Y here, a change from a root uid to a non-root uid
53299+ in a multithreaded application will cause the resulting uids,
53300+ gids, supplementary groups, and capabilities in that thread
53301+ to be propagated to the other threads of the process. In most
53302+ cases this is unnecessary, as glibc will emulate this behavior
53303+ on behalf of the application. Other libcs do not act in the
53304+ same way, allowing the other threads of the process to continue
53305+ running with root privileges. If the sysctl option is enabled,
53306+ a sysctl option with name "consistent_setxid" is created.
53307+
53308+config GRKERNSEC_TPE
53309+ bool "Trusted Path Execution (TPE)"
53310+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
53311+ help
53312+ If you say Y here, you will be able to choose a gid to add to the
53313+ supplementary groups of users you want to mark as "untrusted."
53314+ These users will not be able to execute any files that are not in
53315+ root-owned directories writable only by root. If the sysctl option
53316+ is enabled, a sysctl option with name "tpe" is created.
53317+
53318+config GRKERNSEC_TPE_ALL
53319+ bool "Partially restrict all non-root users"
53320+ depends on GRKERNSEC_TPE
53321+ help
53322+ If you say Y here, all non-root users will be covered under
53323+ a weaker TPE restriction. This is separate from, and in addition to,
53324+ the main TPE options that you have selected elsewhere. Thus, if a
53325+ "trusted" GID is chosen, this restriction applies to even that GID.
53326+ Under this restriction, all non-root users will only be allowed to
53327+ execute files in directories they own that are not group or
53328+ world-writable, or in directories owned by root and writable only by
53329+ root. If the sysctl option is enabled, a sysctl option with name
53330+ "tpe_restrict_all" is created.
53331+
53332+config GRKERNSEC_TPE_INVERT
53333+ bool "Invert GID option"
53334+ depends on GRKERNSEC_TPE
53335+ help
53336+ If you say Y here, the group you specify in the TPE configuration will
53337+ decide what group TPE restrictions will be *disabled* for. This
53338+ option is useful if you want TPE restrictions to be applied to most
53339+ users on the system. If the sysctl option is enabled, a sysctl option
53340+ with name "tpe_invert" is created. Unlike other sysctl options, this
53341+ entry will default to on for backward-compatibility.
53342+
53343+config GRKERNSEC_TPE_GID
53344+ int
53345+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
53346+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
53347+
53348+config GRKERNSEC_TPE_UNTRUSTED_GID
53349+ int "GID for TPE-untrusted users"
53350+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
53351+ default 1005
53352+ help
53353+ Setting this GID determines what group TPE restrictions will be
53354+ *enabled* for. If the sysctl option is enabled, a sysctl option
53355+ with name "tpe_gid" is created.
53356+
53357+config GRKERNSEC_TPE_TRUSTED_GID
53358+ int "GID for TPE-trusted users"
53359+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
53360+ default 1005
53361+ help
53362+ Setting this GID determines what group TPE restrictions will be
53363+ *disabled* for. If the sysctl option is enabled, a sysctl option
53364+ with name "tpe_gid" is created.
53365+
53366+endmenu
53367+menu "Network Protections"
53368+depends on GRKERNSEC
53369+
53370+config GRKERNSEC_RANDNET
53371+ bool "Larger entropy pools"
53372+ default y if GRKERNSEC_CONFIG_AUTO
53373+ help
53374+ If you say Y here, the entropy pools used for many features of Linux
53375+ and grsecurity will be doubled in size. Since several grsecurity
53376+ features use additional randomness, it is recommended that you say Y
53377+ here. Saying Y here has a similar effect as modifying
53378+ /proc/sys/kernel/random/poolsize.
53379+
53380+config GRKERNSEC_BLACKHOLE
53381+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
53382+ default y if GRKERNSEC_CONFIG_AUTO
53383+ depends on NET
53384+ help
53385+ If you say Y here, neither TCP resets nor ICMP
53386+ destination-unreachable packets will be sent in response to packets
53387+ sent to ports for which no associated listening process exists.
53388+ This feature supports both IPV4 and IPV6 and exempts the
53389+ loopback interface from blackholing. Enabling this feature
53390+ makes a host more resilient to DoS attacks and reduces network
53391+ visibility against scanners.
53392+
53393+ The blackhole feature as-implemented is equivalent to the FreeBSD
53394+ blackhole feature, as it prevents RST responses to all packets, not
53395+ just SYNs. Under most application behavior this causes no
53396+ problems, but applications (like haproxy) may not close certain
53397+ connections in a way that cleanly terminates them on the remote
53398+ end, leaving the remote host in LAST_ACK state. Because of this
53399+ side-effect and to prevent intentional LAST_ACK DoSes, this
53400+ feature also adds automatic mitigation against such attacks.
53401+ The mitigation drastically reduces the amount of time a socket
53402+ can spend in LAST_ACK state. If you're using haproxy and not
53403+ all servers it connects to have this option enabled, consider
53404+ disabling this feature on the haproxy host.
53405+
53406+ If the sysctl option is enabled, two sysctl options with names
53407+ "ip_blackhole" and "lastack_retries" will be created.
53408+ While "ip_blackhole" takes the standard zero/non-zero on/off
53409+ toggle, "lastack_retries" uses the same kinds of values as
53410+ "tcp_retries1" and "tcp_retries2". The default value of 4
53411+ prevents a socket from lasting more than 45 seconds in LAST_ACK
53412+ state.
53413+
53414+config GRKERNSEC_NO_SIMULT_CONNECT
53415+ bool "Disable TCP Simultaneous Connect"
53416+ default y if GRKERNSEC_CONFIG_AUTO
53417+ depends on NET
53418+ help
53419+ If you say Y here, a feature by Willy Tarreau will be enabled that
53420+ removes a weakness in Linux's strict implementation of TCP that
53421+ allows two clients to connect to each other without either entering
53422+ a listening state. The weakness allows an attacker to easily prevent
53423+ a client from connecting to a known server provided the source port
53424+ for the connection is guessed correctly.
53425+
53426+ As the weakness could be used to prevent an antivirus or IPS from
53427+ fetching updates, or prevent an SSL gateway from fetching a CRL,
53428+ it should be eliminated by enabling this option. Though Linux is
53429+ one of few operating systems supporting simultaneous connect, it
53430+ has no legitimate use in practice and is rarely supported by firewalls.
53431+
53432+config GRKERNSEC_SOCKET
53433+ bool "Socket restrictions"
53434+ depends on NET
53435+ help
53436+ If you say Y here, you will be able to choose from several options.
53437+ If you assign a GID on your system and add it to the supplementary
53438+ groups of users you want to restrict socket access to, this patch
53439+ will perform up to three things, based on the option(s) you choose.
53440+
53441+config GRKERNSEC_SOCKET_ALL
53442+ bool "Deny any sockets to group"
53443+ depends on GRKERNSEC_SOCKET
53444+ help
53445+ If you say Y here, you will be able to choose a GID of whose users will
53446+ be unable to connect to other hosts from your machine or run server
53447+ applications from your machine. If the sysctl option is enabled, a
53448+ sysctl option with name "socket_all" is created.
53449+
53450+config GRKERNSEC_SOCKET_ALL_GID
53451+ int "GID to deny all sockets for"
53452+ depends on GRKERNSEC_SOCKET_ALL
53453+ default 1004
53454+ help
53455+ Here you can choose the GID to disable socket access for. Remember to
53456+ add the users you want socket access disabled for to the GID
53457+ specified here. If the sysctl option is enabled, a sysctl option
53458+ with name "socket_all_gid" is created.
53459+
53460+config GRKERNSEC_SOCKET_CLIENT
53461+ bool "Deny client sockets to group"
53462+ depends on GRKERNSEC_SOCKET
53463+ help
53464+ If you say Y here, you will be able to choose a GID of whose users will
53465+ be unable to connect to other hosts from your machine, but will be
53466+ able to run servers. If this option is enabled, all users in the group
53467+ you specify will have to use passive mode when initiating ftp transfers
53468+ from the shell on your machine. If the sysctl option is enabled, a
53469+ sysctl option with name "socket_client" is created.
53470+
53471+config GRKERNSEC_SOCKET_CLIENT_GID
53472+ int "GID to deny client sockets for"
53473+ depends on GRKERNSEC_SOCKET_CLIENT
53474+ default 1003
53475+ help
53476+ Here you can choose the GID to disable client socket access for.
53477+ Remember to add the users you want client socket access disabled for to
53478+ the GID specified here. If the sysctl option is enabled, a sysctl
53479+ option with name "socket_client_gid" is created.
53480+
53481+config GRKERNSEC_SOCKET_SERVER
53482+ bool "Deny server sockets to group"
53483+ depends on GRKERNSEC_SOCKET
53484+ help
53485+ If you say Y here, you will be able to choose a GID of whose users will
53486+ be unable to run server applications from your machine. If the sysctl
53487+ option is enabled, a sysctl option with name "socket_server" is created.
53488+
53489+config GRKERNSEC_SOCKET_SERVER_GID
53490+ int "GID to deny server sockets for"
53491+ depends on GRKERNSEC_SOCKET_SERVER
53492+ default 1002
53493+ help
53494+ Here you can choose the GID to disable server socket access for.
53495+ Remember to add the users you want server socket access disabled for to
53496+ the GID specified here. If the sysctl option is enabled, a sysctl
53497+ option with name "socket_server_gid" is created.
53498+
53499+endmenu
53500+menu "Sysctl Support"
53501+depends on GRKERNSEC && SYSCTL
53502+
53503+config GRKERNSEC_SYSCTL
53504+ bool "Sysctl support"
53505+ default y if GRKERNSEC_CONFIG_AUTO
53506+ help
53507+ If you say Y here, you will be able to change the options that
53508+ grsecurity runs with at bootup, without having to recompile your
53509+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
53510+ to enable (1) or disable (0) various features. All the sysctl entries
53511+ are mutable until the "grsec_lock" entry is set to a non-zero value.
53512+ All features enabled in the kernel configuration are disabled at boot
53513+ if you do not say Y to the "Turn on features by default" option.
53514+ All options should be set at startup, and the grsec_lock entry should
53515+ be set to a non-zero value after all the options are set.
53516+ *THIS IS EXTREMELY IMPORTANT*
53517+
53518+config GRKERNSEC_SYSCTL_DISTRO
53519+ bool "Extra sysctl support for distro makers (READ HELP)"
53520+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
53521+ help
53522+ If you say Y here, additional sysctl options will be created
53523+ for features that affect processes running as root. Therefore,
53524+ it is critical when using this option that the grsec_lock entry be
53525+ enabled after boot. Only distros with prebuilt kernel packages
53526+ with this option enabled that can ensure grsec_lock is enabled
53527+ after boot should use this option.
53528+ *Failure to set grsec_lock after boot makes all grsec features
53529+ this option covers useless*
53530+
53531+ Currently this option creates the following sysctl entries:
53532+ "Disable Privileged I/O": "disable_priv_io"
53533+
53534+config GRKERNSEC_SYSCTL_ON
53535+ bool "Turn on features by default"
53536+ default y if GRKERNSEC_CONFIG_AUTO
53537+ depends on GRKERNSEC_SYSCTL
53538+ help
53539+ If you say Y here, instead of having all features enabled in the
53540+ kernel configuration disabled at boot time, the features will be
53541+ enabled at boot time. It is recommended you say Y here unless
53542+ there is some reason you would want all sysctl-tunable features to
53543+ be disabled by default. As mentioned elsewhere, it is important
53544+ to enable the grsec_lock entry once you have finished modifying
53545+ the sysctl entries.
53546+
53547+endmenu
53548+menu "Logging Options"
53549+depends on GRKERNSEC
53550+
53551+config GRKERNSEC_FLOODTIME
53552+ int "Seconds in between log messages (minimum)"
53553+ default 10
53554+ help
53555+ This option allows you to enforce the number of seconds between
53556+ grsecurity log messages. The default should be suitable for most
53557+ people, however, if you choose to change it, choose a value small enough
53558+ to allow informative logs to be produced, but large enough to
53559+ prevent flooding.
53560+
53561+config GRKERNSEC_FLOODBURST
53562+ int "Number of messages in a burst (maximum)"
53563+ default 6
53564+ help
53565+ This option allows you to choose the maximum number of messages allowed
53566+ within the flood time interval you chose in a separate option. The
53567+ default should be suitable for most people, however if you find that
53568+ many of your logs are being interpreted as flooding, you may want to
53569+ raise this value.
53570+
53571+endmenu
53572diff --git a/grsecurity/Makefile b/grsecurity/Makefile
53573new file mode 100644
53574index 0000000..1b9afa9
53575--- /dev/null
53576+++ b/grsecurity/Makefile
53577@@ -0,0 +1,38 @@
53578+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
53579+# during 2001-2009 it has been completely redesigned by Brad Spengler
53580+# into an RBAC system
53581+#
53582+# All code in this directory and various hooks inserted throughout the kernel
53583+# are copyright Brad Spengler - Open Source Security, Inc., and released
53584+# under the GPL v2 or higher
53585+
53586+KBUILD_CFLAGS += -Werror
53587+
53588+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
53589+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
53590+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
53591+
53592+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
53593+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
53594+ gracl_learn.o grsec_log.o
53595+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
53596+
53597+ifdef CONFIG_NET
53598+obj-y += grsec_sock.o
53599+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
53600+endif
53601+
53602+ifndef CONFIG_GRKERNSEC
53603+obj-y += grsec_disabled.o
53604+endif
53605+
53606+ifdef CONFIG_GRKERNSEC_HIDESYM
53607+extra-y := grsec_hidesym.o
53608+$(obj)/grsec_hidesym.o:
53609+ @-chmod -f 500 /boot
53610+ @-chmod -f 500 /lib/modules
53611+ @-chmod -f 500 /lib64/modules
53612+ @-chmod -f 500 /lib32/modules
53613+ @-chmod -f 700 .
53614+ @echo ' grsec: protected kernel image paths'
53615+endif
53616diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
53617new file mode 100644
53618index 0000000..960766a
53619--- /dev/null
53620+++ b/grsecurity/gracl.c
53621@@ -0,0 +1,4003 @@
53622+#include <linux/kernel.h>
53623+#include <linux/module.h>
53624+#include <linux/sched.h>
53625+#include <linux/mm.h>
53626+#include <linux/file.h>
53627+#include <linux/fs.h>
53628+#include <linux/namei.h>
53629+#include <linux/mount.h>
53630+#include <linux/tty.h>
53631+#include <linux/proc_fs.h>
53632+#include <linux/lglock.h>
53633+#include <linux/slab.h>
53634+#include <linux/vmalloc.h>
53635+#include <linux/types.h>
53636+#include <linux/sysctl.h>
53637+#include <linux/netdevice.h>
53638+#include <linux/ptrace.h>
53639+#include <linux/gracl.h>
53640+#include <linux/gralloc.h>
53641+#include <linux/security.h>
53642+#include <linux/grinternal.h>
53643+#include <linux/pid_namespace.h>
53644+#include <linux/stop_machine.h>
53645+#include <linux/fdtable.h>
53646+#include <linux/percpu.h>
53647+#include <linux/lglock.h>
53648+#include "../fs/mount.h"
53649+
53650+#include <asm/uaccess.h>
53651+#include <asm/errno.h>
53652+#include <asm/mman.h>
53653+
53654+extern struct lglock vfsmount_lock;
53655+
53656+static struct acl_role_db acl_role_set;
53657+static struct name_db name_set;
53658+static struct inodev_db inodev_set;
53659+
53660+/* for keeping track of userspace pointers used for subjects, so we
53661+ can share references in the kernel as well
53662+*/
53663+
53664+static struct path real_root;
53665+
53666+static struct acl_subj_map_db subj_map_set;
53667+
53668+static struct acl_role_label *default_role;
53669+
53670+static struct acl_role_label *role_list;
53671+
53672+static u16 acl_sp_role_value;
53673+
53674+extern char *gr_shared_page[4];
53675+static DEFINE_MUTEX(gr_dev_mutex);
53676+DEFINE_RWLOCK(gr_inode_lock);
53677+
53678+struct gr_arg *gr_usermode;
53679+
53680+static unsigned int gr_status __read_only = GR_STATUS_INIT;
53681+
53682+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
53683+extern void gr_clear_learn_entries(void);
53684+
53685+unsigned char *gr_system_salt;
53686+unsigned char *gr_system_sum;
53687+
53688+static struct sprole_pw **acl_special_roles = NULL;
53689+static __u16 num_sprole_pws = 0;
53690+
53691+static struct acl_role_label *kernel_role = NULL;
53692+
53693+static unsigned int gr_auth_attempts = 0;
53694+static unsigned long gr_auth_expires = 0UL;
53695+
53696+#ifdef CONFIG_NET
53697+extern struct vfsmount *sock_mnt;
53698+#endif
53699+
53700+extern struct vfsmount *pipe_mnt;
53701+extern struct vfsmount *shm_mnt;
53702+#ifdef CONFIG_HUGETLBFS
53703+extern struct vfsmount *hugetlbfs_vfsmount;
53704+#endif
53705+
53706+static struct acl_object_label *fakefs_obj_rw;
53707+static struct acl_object_label *fakefs_obj_rwx;
53708+
53709+extern int gr_init_uidset(void);
53710+extern void gr_free_uidset(void);
53711+extern void gr_remove_uid(uid_t uid);
53712+extern int gr_find_uid(uid_t uid);
53713+
53714+__inline__ int
53715+gr_acl_is_enabled(void)
53716+{
53717+ return (gr_status & GR_READY);
53718+}
53719+
53720+#ifdef CONFIG_BTRFS_FS
53721+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
53722+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
53723+#endif
53724+
53725+static inline dev_t __get_dev(const struct dentry *dentry)
53726+{
53727+#ifdef CONFIG_BTRFS_FS
53728+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
53729+ return get_btrfs_dev_from_inode(dentry->d_inode);
53730+ else
53731+#endif
53732+ return dentry->d_inode->i_sb->s_dev;
53733+}
53734+
53735+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
53736+{
53737+ return __get_dev(dentry);
53738+}
53739+
53740+static char gr_task_roletype_to_char(struct task_struct *task)
53741+{
53742+ switch (task->role->roletype &
53743+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
53744+ GR_ROLE_SPECIAL)) {
53745+ case GR_ROLE_DEFAULT:
53746+ return 'D';
53747+ case GR_ROLE_USER:
53748+ return 'U';
53749+ case GR_ROLE_GROUP:
53750+ return 'G';
53751+ case GR_ROLE_SPECIAL:
53752+ return 'S';
53753+ }
53754+
53755+ return 'X';
53756+}
53757+
53758+char gr_roletype_to_char(void)
53759+{
53760+ return gr_task_roletype_to_char(current);
53761+}
53762+
53763+__inline__ int
53764+gr_acl_tpe_check(void)
53765+{
53766+ if (unlikely(!(gr_status & GR_READY)))
53767+ return 0;
53768+ if (current->role->roletype & GR_ROLE_TPE)
53769+ return 1;
53770+ else
53771+ return 0;
53772+}
53773+
53774+int
53775+gr_handle_rawio(const struct inode *inode)
53776+{
53777+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
53778+ if (inode && S_ISBLK(inode->i_mode) &&
53779+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
53780+ !capable(CAP_SYS_RAWIO))
53781+ return 1;
53782+#endif
53783+ return 0;
53784+}
53785+
53786+static int
53787+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
53788+{
53789+ if (likely(lena != lenb))
53790+ return 0;
53791+
53792+ return !memcmp(a, b, lena);
53793+}
53794+
53795+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
53796+{
53797+ *buflen -= namelen;
53798+ if (*buflen < 0)
53799+ return -ENAMETOOLONG;
53800+ *buffer -= namelen;
53801+ memcpy(*buffer, str, namelen);
53802+ return 0;
53803+}
53804+
53805+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
53806+{
53807+ return prepend(buffer, buflen, name->name, name->len);
53808+}
53809+
53810+static int prepend_path(const struct path *path, struct path *root,
53811+ char **buffer, int *buflen)
53812+{
53813+ struct dentry *dentry = path->dentry;
53814+ struct vfsmount *vfsmnt = path->mnt;
53815+ struct mount *mnt = real_mount(vfsmnt);
53816+ bool slash = false;
53817+ int error = 0;
53818+
53819+ while (dentry != root->dentry || vfsmnt != root->mnt) {
53820+ struct dentry * parent;
53821+
53822+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
53823+ /* Global root? */
53824+ if (!mnt_has_parent(mnt)) {
53825+ goto out;
53826+ }
53827+ dentry = mnt->mnt_mountpoint;
53828+ mnt = mnt->mnt_parent;
53829+ vfsmnt = &mnt->mnt;
53830+ continue;
53831+ }
53832+ parent = dentry->d_parent;
53833+ prefetch(parent);
53834+ spin_lock(&dentry->d_lock);
53835+ error = prepend_name(buffer, buflen, &dentry->d_name);
53836+ spin_unlock(&dentry->d_lock);
53837+ if (!error)
53838+ error = prepend(buffer, buflen, "/", 1);
53839+ if (error)
53840+ break;
53841+
53842+ slash = true;
53843+ dentry = parent;
53844+ }
53845+
53846+out:
53847+ if (!error && !slash)
53848+ error = prepend(buffer, buflen, "/", 1);
53849+
53850+ return error;
53851+}
53852+
53853+/* this must be called with vfsmount_lock and rename_lock held */
53854+
53855+static char *__our_d_path(const struct path *path, struct path *root,
53856+ char *buf, int buflen)
53857+{
53858+ char *res = buf + buflen;
53859+ int error;
53860+
53861+ prepend(&res, &buflen, "\0", 1);
53862+ error = prepend_path(path, root, &res, &buflen);
53863+ if (error)
53864+ return ERR_PTR(error);
53865+
53866+ return res;
53867+}
53868+
53869+static char *
53870+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
53871+{
53872+ char *retval;
53873+
53874+ retval = __our_d_path(path, root, buf, buflen);
53875+ if (unlikely(IS_ERR(retval)))
53876+ retval = strcpy(buf, "<path too long>");
53877+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
53878+ retval[1] = '\0';
53879+
53880+ return retval;
53881+}
53882+
53883+static char *
53884+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
53885+ char *buf, int buflen)
53886+{
53887+ struct path path;
53888+ char *res;
53889+
53890+ path.dentry = (struct dentry *)dentry;
53891+ path.mnt = (struct vfsmount *)vfsmnt;
53892+
53893+ /* we can use real_root.dentry, real_root.mnt, because this is only called
53894+ by the RBAC system */
53895+ res = gen_full_path(&path, &real_root, buf, buflen);
53896+
53897+ return res;
53898+}
53899+
53900+static char *
53901+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
53902+ char *buf, int buflen)
53903+{
53904+ char *res;
53905+ struct path path;
53906+ struct path root;
53907+ struct task_struct *reaper = init_pid_ns.child_reaper;
53908+
53909+ path.dentry = (struct dentry *)dentry;
53910+ path.mnt = (struct vfsmount *)vfsmnt;
53911+
53912+ /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
53913+ get_fs_root(reaper->fs, &root);
53914+
53915+ write_seqlock(&rename_lock);
53916+ br_read_lock(&vfsmount_lock);
53917+ res = gen_full_path(&path, &root, buf, buflen);
53918+ br_read_unlock(&vfsmount_lock);
53919+ write_sequnlock(&rename_lock);
53920+
53921+ path_put(&root);
53922+ return res;
53923+}
53924+
53925+static char *
53926+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
53927+{
53928+ char *ret;
53929+ write_seqlock(&rename_lock);
53930+ br_read_lock(&vfsmount_lock);
53931+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
53932+ PAGE_SIZE);
53933+ br_read_unlock(&vfsmount_lock);
53934+ write_sequnlock(&rename_lock);
53935+ return ret;
53936+}
53937+
53938+static char *
53939+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
53940+{
53941+ char *ret;
53942+ char *buf;
53943+ int buflen;
53944+
53945+ write_seqlock(&rename_lock);
53946+ br_read_lock(&vfsmount_lock);
53947+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
53948+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
53949+ buflen = (int)(ret - buf);
53950+ if (buflen >= 5)
53951+ prepend(&ret, &buflen, "/proc", 5);
53952+ else
53953+ ret = strcpy(buf, "<path too long>");
53954+ br_read_unlock(&vfsmount_lock);
53955+ write_sequnlock(&rename_lock);
53956+ return ret;
53957+}
53958+
53959+char *
53960+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
53961+{
53962+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
53963+ PAGE_SIZE);
53964+}
53965+
53966+char *
53967+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
53968+{
53969+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
53970+ PAGE_SIZE);
53971+}
53972+
53973+char *
53974+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
53975+{
53976+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
53977+ PAGE_SIZE);
53978+}
53979+
53980+char *
53981+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
53982+{
53983+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
53984+ PAGE_SIZE);
53985+}
53986+
53987+char *
53988+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
53989+{
53990+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
53991+ PAGE_SIZE);
53992+}
53993+
53994+__inline__ __u32
53995+to_gr_audit(const __u32 reqmode)
53996+{
53997+ /* masks off auditable permission flags, then shifts them to create
53998+ auditing flags, and adds the special case of append auditing if
53999+ we're requesting write */
54000+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
54001+}
54002+
54003+struct acl_subject_label *
54004+lookup_subject_map(const struct acl_subject_label *userp)
54005+{
54006+ unsigned int index = gr_shash(userp, subj_map_set.s_size);
54007+ struct subject_map *match;
54008+
54009+ match = subj_map_set.s_hash[index];
54010+
54011+ while (match && match->user != userp)
54012+ match = match->next;
54013+
54014+ if (match != NULL)
54015+ return match->kernel;
54016+ else
54017+ return NULL;
54018+}
54019+
54020+static void
54021+insert_subj_map_entry(struct subject_map *subjmap)
54022+{
54023+ unsigned int index = gr_shash(subjmap->user, subj_map_set.s_size);
54024+ struct subject_map **curr;
54025+
54026+ subjmap->prev = NULL;
54027+
54028+ curr = &subj_map_set.s_hash[index];
54029+ if (*curr != NULL)
54030+ (*curr)->prev = subjmap;
54031+
54032+ subjmap->next = *curr;
54033+ *curr = subjmap;
54034+
54035+ return;
54036+}
54037+
54038+static struct acl_role_label *
54039+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
54040+ const gid_t gid)
54041+{
54042+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
54043+ struct acl_role_label *match;
54044+ struct role_allowed_ip *ipp;
54045+ unsigned int x;
54046+ u32 curr_ip = task->signal->curr_ip;
54047+
54048+ task->signal->saved_ip = curr_ip;
54049+
54050+ match = acl_role_set.r_hash[index];
54051+
54052+ while (match) {
54053+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
54054+ for (x = 0; x < match->domain_child_num; x++) {
54055+ if (match->domain_children[x] == uid)
54056+ goto found;
54057+ }
54058+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
54059+ break;
54060+ match = match->next;
54061+ }
54062+found:
54063+ if (match == NULL) {
54064+ try_group:
54065+ index = gr_rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
54066+ match = acl_role_set.r_hash[index];
54067+
54068+ while (match) {
54069+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
54070+ for (x = 0; x < match->domain_child_num; x++) {
54071+ if (match->domain_children[x] == gid)
54072+ goto found2;
54073+ }
54074+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
54075+ break;
54076+ match = match->next;
54077+ }
54078+found2:
54079+ if (match == NULL)
54080+ match = default_role;
54081+ if (match->allowed_ips == NULL)
54082+ return match;
54083+ else {
54084+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
54085+ if (likely
54086+ ((ntohl(curr_ip) & ipp->netmask) ==
54087+ (ntohl(ipp->addr) & ipp->netmask)))
54088+ return match;
54089+ }
54090+ match = default_role;
54091+ }
54092+ } else if (match->allowed_ips == NULL) {
54093+ return match;
54094+ } else {
54095+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
54096+ if (likely
54097+ ((ntohl(curr_ip) & ipp->netmask) ==
54098+ (ntohl(ipp->addr) & ipp->netmask)))
54099+ return match;
54100+ }
54101+ goto try_group;
54102+ }
54103+
54104+ return match;
54105+}
54106+
54107+struct acl_subject_label *
54108+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
54109+ const struct acl_role_label *role)
54110+{
54111+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
54112+ struct acl_subject_label *match;
54113+
54114+ match = role->subj_hash[index];
54115+
54116+ while (match && (match->inode != ino || match->device != dev ||
54117+ (match->mode & GR_DELETED))) {
54118+ match = match->next;
54119+ }
54120+
54121+ if (match && !(match->mode & GR_DELETED))
54122+ return match;
54123+ else
54124+ return NULL;
54125+}
54126+
54127+struct acl_subject_label *
54128+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
54129+ const struct acl_role_label *role)
54130+{
54131+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
54132+ struct acl_subject_label *match;
54133+
54134+ match = role->subj_hash[index];
54135+
54136+ while (match && (match->inode != ino || match->device != dev ||
54137+ !(match->mode & GR_DELETED))) {
54138+ match = match->next;
54139+ }
54140+
54141+ if (match && (match->mode & GR_DELETED))
54142+ return match;
54143+ else
54144+ return NULL;
54145+}
54146+
54147+static struct acl_object_label *
54148+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
54149+ const struct acl_subject_label *subj)
54150+{
54151+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
54152+ struct acl_object_label *match;
54153+
54154+ match = subj->obj_hash[index];
54155+
54156+ while (match && (match->inode != ino || match->device != dev ||
54157+ (match->mode & GR_DELETED))) {
54158+ match = match->next;
54159+ }
54160+
54161+ if (match && !(match->mode & GR_DELETED))
54162+ return match;
54163+ else
54164+ return NULL;
54165+}
54166+
54167+static struct acl_object_label *
54168+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
54169+ const struct acl_subject_label *subj)
54170+{
54171+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
54172+ struct acl_object_label *match;
54173+
54174+ match = subj->obj_hash[index];
54175+
54176+ while (match && (match->inode != ino || match->device != dev ||
54177+ !(match->mode & GR_DELETED))) {
54178+ match = match->next;
54179+ }
54180+
54181+ if (match && (match->mode & GR_DELETED))
54182+ return match;
54183+
54184+ match = subj->obj_hash[index];
54185+
54186+ while (match && (match->inode != ino || match->device != dev ||
54187+ (match->mode & GR_DELETED))) {
54188+ match = match->next;
54189+ }
54190+
54191+ if (match && !(match->mode & GR_DELETED))
54192+ return match;
54193+ else
54194+ return NULL;
54195+}
54196+
54197+static struct name_entry *
54198+lookup_name_entry(const char *name)
54199+{
54200+ unsigned int len = strlen(name);
54201+ unsigned int key = full_name_hash(name, len);
54202+ unsigned int index = key % name_set.n_size;
54203+ struct name_entry *match;
54204+
54205+ match = name_set.n_hash[index];
54206+
54207+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
54208+ match = match->next;
54209+
54210+ return match;
54211+}
54212+
54213+static struct name_entry *
54214+lookup_name_entry_create(const char *name)
54215+{
54216+ unsigned int len = strlen(name);
54217+ unsigned int key = full_name_hash(name, len);
54218+ unsigned int index = key % name_set.n_size;
54219+ struct name_entry *match;
54220+
54221+ match = name_set.n_hash[index];
54222+
54223+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
54224+ !match->deleted))
54225+ match = match->next;
54226+
54227+ if (match && match->deleted)
54228+ return match;
54229+
54230+ match = name_set.n_hash[index];
54231+
54232+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
54233+ match->deleted))
54234+ match = match->next;
54235+
54236+ if (match && !match->deleted)
54237+ return match;
54238+ else
54239+ return NULL;
54240+}
54241+
54242+static struct inodev_entry *
54243+lookup_inodev_entry(const ino_t ino, const dev_t dev)
54244+{
54245+ unsigned int index = gr_fhash(ino, dev, inodev_set.i_size);
54246+ struct inodev_entry *match;
54247+
54248+ match = inodev_set.i_hash[index];
54249+
54250+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
54251+ match = match->next;
54252+
54253+ return match;
54254+}
54255+
54256+static void
54257+insert_inodev_entry(struct inodev_entry *entry)
54258+{
54259+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
54260+ inodev_set.i_size);
54261+ struct inodev_entry **curr;
54262+
54263+ entry->prev = NULL;
54264+
54265+ curr = &inodev_set.i_hash[index];
54266+ if (*curr != NULL)
54267+ (*curr)->prev = entry;
54268+
54269+ entry->next = *curr;
54270+ *curr = entry;
54271+
54272+ return;
54273+}
54274+
54275+static void
54276+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
54277+{
54278+ unsigned int index =
54279+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
54280+ struct acl_role_label **curr;
54281+ struct acl_role_label *tmp, *tmp2;
54282+
54283+ curr = &acl_role_set.r_hash[index];
54284+
54285+ /* simple case, slot is empty, just set it to our role */
54286+ if (*curr == NULL) {
54287+ *curr = role;
54288+ } else {
54289+ /* example:
54290+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
54291+ 2 -> 3
54292+ */
54293+ /* first check to see if we can already be reached via this slot */
54294+ tmp = *curr;
54295+ while (tmp && tmp != role)
54296+ tmp = tmp->next;
54297+ if (tmp == role) {
54298+ /* we don't need to add ourselves to this slot's chain */
54299+ return;
54300+ }
54301+ /* we need to add ourselves to this chain, two cases */
54302+ if (role->next == NULL) {
54303+ /* simple case, append the current chain to our role */
54304+ role->next = *curr;
54305+ *curr = role;
54306+ } else {
54307+ /* 1 -> 2 -> 3 -> 4
54308+ 2 -> 3 -> 4
54309+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
54310+ */
54311+ /* trickier case: walk our role's chain until we find
54312+ the role for the start of the current slot's chain */
54313+ tmp = role;
54314+ tmp2 = *curr;
54315+ while (tmp->next && tmp->next != tmp2)
54316+ tmp = tmp->next;
54317+ if (tmp->next == tmp2) {
54318+ /* from example above, we found 3, so just
54319+ replace this slot's chain with ours */
54320+ *curr = role;
54321+ } else {
54322+ /* we didn't find a subset of our role's chain
54323+ in the current slot's chain, so append their
54324+ chain to ours, and set us as the first role in
54325+ the slot's chain
54326+
54327+ we could fold this case with the case above,
54328+ but making it explicit for clarity
54329+ */
54330+ tmp->next = tmp2;
54331+ *curr = role;
54332+ }
54333+ }
54334+ }
54335+
54336+ return;
54337+}
54338+
54339+static void
54340+insert_acl_role_label(struct acl_role_label *role)
54341+{
54342+ int i;
54343+
54344+ if (role_list == NULL) {
54345+ role_list = role;
54346+ role->prev = NULL;
54347+ } else {
54348+ role->prev = role_list;
54349+ role_list = role;
54350+ }
54351+
54352+ /* used for hash chains */
54353+ role->next = NULL;
54354+
54355+ if (role->roletype & GR_ROLE_DOMAIN) {
54356+ for (i = 0; i < role->domain_child_num; i++)
54357+ __insert_acl_role_label(role, role->domain_children[i]);
54358+ } else
54359+ __insert_acl_role_label(role, role->uidgid);
54360+}
54361+
54362+static int
54363+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
54364+{
54365+ struct name_entry **curr, *nentry;
54366+ struct inodev_entry *ientry;
54367+ unsigned int len = strlen(name);
54368+ unsigned int key = full_name_hash(name, len);
54369+ unsigned int index = key % name_set.n_size;
54370+
54371+ curr = &name_set.n_hash[index];
54372+
54373+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
54374+ curr = &((*curr)->next);
54375+
54376+ if (*curr != NULL)
54377+ return 1;
54378+
54379+ nentry = acl_alloc(sizeof (struct name_entry));
54380+ if (nentry == NULL)
54381+ return 0;
54382+ ientry = acl_alloc(sizeof (struct inodev_entry));
54383+ if (ientry == NULL)
54384+ return 0;
54385+ ientry->nentry = nentry;
54386+
54387+ nentry->key = key;
54388+ nentry->name = name;
54389+ nentry->inode = inode;
54390+ nentry->device = device;
54391+ nentry->len = len;
54392+ nentry->deleted = deleted;
54393+
54394+ nentry->prev = NULL;
54395+ curr = &name_set.n_hash[index];
54396+ if (*curr != NULL)
54397+ (*curr)->prev = nentry;
54398+ nentry->next = *curr;
54399+ *curr = nentry;
54400+
54401+ /* insert us into the table searchable by inode/dev */
54402+ insert_inodev_entry(ientry);
54403+
54404+ return 1;
54405+}
54406+
54407+static void
54408+insert_acl_obj_label(struct acl_object_label *obj,
54409+ struct acl_subject_label *subj)
54410+{
54411+ unsigned int index =
54412+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
54413+ struct acl_object_label **curr;
54414+
54415+
54416+ obj->prev = NULL;
54417+
54418+ curr = &subj->obj_hash[index];
54419+ if (*curr != NULL)
54420+ (*curr)->prev = obj;
54421+
54422+ obj->next = *curr;
54423+ *curr = obj;
54424+
54425+ return;
54426+}
54427+
54428+static void
54429+insert_acl_subj_label(struct acl_subject_label *obj,
54430+ struct acl_role_label *role)
54431+{
54432+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
54433+ struct acl_subject_label **curr;
54434+
54435+ obj->prev = NULL;
54436+
54437+ curr = &role->subj_hash[index];
54438+ if (*curr != NULL)
54439+ (*curr)->prev = obj;
54440+
54441+ obj->next = *curr;
54442+ *curr = obj;
54443+
54444+ return;
54445+}
54446+
54447+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
54448+
54449+static void *
54450+create_table(__u32 * len, int elementsize)
54451+{
54452+ unsigned int table_sizes[] = {
54453+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
54454+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
54455+ 4194301, 8388593, 16777213, 33554393, 67108859
54456+ };
54457+ void *newtable = NULL;
54458+ unsigned int pwr = 0;
54459+
54460+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
54461+ table_sizes[pwr] <= *len)
54462+ pwr++;
54463+
54464+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
54465+ return newtable;
54466+
54467+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
54468+ newtable =
54469+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
54470+ else
54471+ newtable = vmalloc(table_sizes[pwr] * elementsize);
54472+
54473+ *len = table_sizes[pwr];
54474+
54475+ return newtable;
54476+}
54477+
54478+static int
54479+init_variables(const struct gr_arg *arg)
54480+{
54481+ struct task_struct *reaper = init_pid_ns.child_reaper;
54482+ unsigned int stacksize;
54483+
54484+ subj_map_set.s_size = arg->role_db.num_subjects;
54485+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
54486+ name_set.n_size = arg->role_db.num_objects;
54487+ inodev_set.i_size = arg->role_db.num_objects;
54488+
54489+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
54490+ !name_set.n_size || !inodev_set.i_size)
54491+ return 1;
54492+
54493+ if (!gr_init_uidset())
54494+ return 1;
54495+
54496+ /* set up the stack that holds allocation info */
54497+
54498+ stacksize = arg->role_db.num_pointers + 5;
54499+
54500+ if (!acl_alloc_stack_init(stacksize))
54501+ return 1;
54502+
54503+ /* grab reference for the real root dentry and vfsmount */
54504+ get_fs_root(reaper->fs, &real_root);
54505+
54506+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54507+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
54508+#endif
54509+
54510+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
54511+ if (fakefs_obj_rw == NULL)
54512+ return 1;
54513+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
54514+
54515+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
54516+ if (fakefs_obj_rwx == NULL)
54517+ return 1;
54518+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
54519+
54520+ subj_map_set.s_hash =
54521+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
54522+ acl_role_set.r_hash =
54523+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
54524+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
54525+ inodev_set.i_hash =
54526+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
54527+
54528+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
54529+ !name_set.n_hash || !inodev_set.i_hash)
54530+ return 1;
54531+
54532+ memset(subj_map_set.s_hash, 0,
54533+ sizeof(struct subject_map *) * subj_map_set.s_size);
54534+ memset(acl_role_set.r_hash, 0,
54535+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
54536+ memset(name_set.n_hash, 0,
54537+ sizeof (struct name_entry *) * name_set.n_size);
54538+ memset(inodev_set.i_hash, 0,
54539+ sizeof (struct inodev_entry *) * inodev_set.i_size);
54540+
54541+ return 0;
54542+}
54543+
54544+/* free information not needed after startup
54545+ currently contains user->kernel pointer mappings for subjects
54546+*/
54547+
54548+static void
54549+free_init_variables(void)
54550+{
54551+ __u32 i;
54552+
54553+ if (subj_map_set.s_hash) {
54554+ for (i = 0; i < subj_map_set.s_size; i++) {
54555+ if (subj_map_set.s_hash[i]) {
54556+ kfree(subj_map_set.s_hash[i]);
54557+ subj_map_set.s_hash[i] = NULL;
54558+ }
54559+ }
54560+
54561+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
54562+ PAGE_SIZE)
54563+ kfree(subj_map_set.s_hash);
54564+ else
54565+ vfree(subj_map_set.s_hash);
54566+ }
54567+
54568+ return;
54569+}
54570+
54571+static void
54572+free_variables(void)
54573+{
54574+ struct acl_subject_label *s;
54575+ struct acl_role_label *r;
54576+ struct task_struct *task, *task2;
54577+ unsigned int x;
54578+
54579+ gr_clear_learn_entries();
54580+
54581+ read_lock(&tasklist_lock);
54582+ do_each_thread(task2, task) {
54583+ task->acl_sp_role = 0;
54584+ task->acl_role_id = 0;
54585+ task->acl = NULL;
54586+ task->role = NULL;
54587+ } while_each_thread(task2, task);
54588+ read_unlock(&tasklist_lock);
54589+
54590+ /* release the reference to the real root dentry and vfsmount */
54591+ path_put(&real_root);
54592+ memset(&real_root, 0, sizeof(real_root));
54593+
54594+ /* free all object hash tables */
54595+
54596+ FOR_EACH_ROLE_START(r)
54597+ if (r->subj_hash == NULL)
54598+ goto next_role;
54599+ FOR_EACH_SUBJECT_START(r, s, x)
54600+ if (s->obj_hash == NULL)
54601+ break;
54602+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
54603+ kfree(s->obj_hash);
54604+ else
54605+ vfree(s->obj_hash);
54606+ FOR_EACH_SUBJECT_END(s, x)
54607+ FOR_EACH_NESTED_SUBJECT_START(r, s)
54608+ if (s->obj_hash == NULL)
54609+ break;
54610+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
54611+ kfree(s->obj_hash);
54612+ else
54613+ vfree(s->obj_hash);
54614+ FOR_EACH_NESTED_SUBJECT_END(s)
54615+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
54616+ kfree(r->subj_hash);
54617+ else
54618+ vfree(r->subj_hash);
54619+ r->subj_hash = NULL;
54620+next_role:
54621+ FOR_EACH_ROLE_END(r)
54622+
54623+ acl_free_all();
54624+
54625+ if (acl_role_set.r_hash) {
54626+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
54627+ PAGE_SIZE)
54628+ kfree(acl_role_set.r_hash);
54629+ else
54630+ vfree(acl_role_set.r_hash);
54631+ }
54632+ if (name_set.n_hash) {
54633+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
54634+ PAGE_SIZE)
54635+ kfree(name_set.n_hash);
54636+ else
54637+ vfree(name_set.n_hash);
54638+ }
54639+
54640+ if (inodev_set.i_hash) {
54641+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
54642+ PAGE_SIZE)
54643+ kfree(inodev_set.i_hash);
54644+ else
54645+ vfree(inodev_set.i_hash);
54646+ }
54647+
54648+ gr_free_uidset();
54649+
54650+ memset(&name_set, 0, sizeof (struct name_db));
54651+ memset(&inodev_set, 0, sizeof (struct inodev_db));
54652+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
54653+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
54654+
54655+ default_role = NULL;
54656+ kernel_role = NULL;
54657+ role_list = NULL;
54658+
54659+ return;
54660+}
54661+
54662+static __u32
54663+count_user_objs(struct acl_object_label *userp)
54664+{
54665+ struct acl_object_label o_tmp;
54666+ __u32 num = 0;
54667+
54668+ while (userp) {
54669+ if (copy_from_user(&o_tmp, userp,
54670+ sizeof (struct acl_object_label)))
54671+ break;
54672+
54673+ userp = o_tmp.prev;
54674+ num++;
54675+ }
54676+
54677+ return num;
54678+}
54679+
54680+static struct acl_subject_label *
54681+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
54682+
54683+static int
54684+copy_user_glob(struct acl_object_label *obj)
54685+{
54686+ struct acl_object_label *g_tmp, **guser;
54687+ unsigned int len;
54688+ char *tmp;
54689+
54690+ if (obj->globbed == NULL)
54691+ return 0;
54692+
54693+ guser = &obj->globbed;
54694+ while (*guser) {
54695+ g_tmp = (struct acl_object_label *)
54696+ acl_alloc(sizeof (struct acl_object_label));
54697+ if (g_tmp == NULL)
54698+ return -ENOMEM;
54699+
54700+ if (copy_from_user(g_tmp, *guser,
54701+ sizeof (struct acl_object_label)))
54702+ return -EFAULT;
54703+
54704+ len = strnlen_user(g_tmp->filename, PATH_MAX);
54705+
54706+ if (!len || len >= PATH_MAX)
54707+ return -EINVAL;
54708+
54709+ if ((tmp = (char *) acl_alloc(len)) == NULL)
54710+ return -ENOMEM;
54711+
54712+ if (copy_from_user(tmp, g_tmp->filename, len))
54713+ return -EFAULT;
54714+ tmp[len-1] = '\0';
54715+ g_tmp->filename = tmp;
54716+
54717+ *guser = g_tmp;
54718+ guser = &(g_tmp->next);
54719+ }
54720+
54721+ return 0;
54722+}
54723+
54724+static int
54725+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
54726+ struct acl_role_label *role)
54727+{
54728+ struct acl_object_label *o_tmp;
54729+ unsigned int len;
54730+ int ret;
54731+ char *tmp;
54732+
54733+ while (userp) {
54734+ if ((o_tmp = (struct acl_object_label *)
54735+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
54736+ return -ENOMEM;
54737+
54738+ if (copy_from_user(o_tmp, userp,
54739+ sizeof (struct acl_object_label)))
54740+ return -EFAULT;
54741+
54742+ userp = o_tmp->prev;
54743+
54744+ len = strnlen_user(o_tmp->filename, PATH_MAX);
54745+
54746+ if (!len || len >= PATH_MAX)
54747+ return -EINVAL;
54748+
54749+ if ((tmp = (char *) acl_alloc(len)) == NULL)
54750+ return -ENOMEM;
54751+
54752+ if (copy_from_user(tmp, o_tmp->filename, len))
54753+ return -EFAULT;
54754+ tmp[len-1] = '\0';
54755+ o_tmp->filename = tmp;
54756+
54757+ insert_acl_obj_label(o_tmp, subj);
54758+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
54759+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
54760+ return -ENOMEM;
54761+
54762+ ret = copy_user_glob(o_tmp);
54763+ if (ret)
54764+ return ret;
54765+
54766+ if (o_tmp->nested) {
54767+ int already_copied;
54768+
54769+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
54770+ if (IS_ERR(o_tmp->nested))
54771+ return PTR_ERR(o_tmp->nested);
54772+
54773+ /* insert into nested subject list if we haven't copied this one yet
54774+ to prevent duplicate entries */
54775+ if (!already_copied) {
54776+ o_tmp->nested->next = role->hash->first;
54777+ role->hash->first = o_tmp->nested;
54778+ }
54779+ }
54780+ }
54781+
54782+ return 0;
54783+}
54784+
54785+static __u32
54786+count_user_subjs(struct acl_subject_label *userp)
54787+{
54788+ struct acl_subject_label s_tmp;
54789+ __u32 num = 0;
54790+
54791+ while (userp) {
54792+ if (copy_from_user(&s_tmp, userp,
54793+ sizeof (struct acl_subject_label)))
54794+ break;
54795+
54796+ userp = s_tmp.prev;
54797+ }
54798+
54799+ return num;
54800+}
54801+
54802+static int
54803+copy_user_allowedips(struct acl_role_label *rolep)
54804+{
54805+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
54806+
54807+ ruserip = rolep->allowed_ips;
54808+
54809+ while (ruserip) {
54810+ rlast = rtmp;
54811+
54812+ if ((rtmp = (struct role_allowed_ip *)
54813+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
54814+ return -ENOMEM;
54815+
54816+ if (copy_from_user(rtmp, ruserip,
54817+ sizeof (struct role_allowed_ip)))
54818+ return -EFAULT;
54819+
54820+ ruserip = rtmp->prev;
54821+
54822+ if (!rlast) {
54823+ rtmp->prev = NULL;
54824+ rolep->allowed_ips = rtmp;
54825+ } else {
54826+ rlast->next = rtmp;
54827+ rtmp->prev = rlast;
54828+ }
54829+
54830+ if (!ruserip)
54831+ rtmp->next = NULL;
54832+ }
54833+
54834+ return 0;
54835+}
54836+
54837+static int
54838+copy_user_transitions(struct acl_role_label *rolep)
54839+{
54840+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
54841+
54842+ unsigned int len;
54843+ char *tmp;
54844+
54845+ rusertp = rolep->transitions;
54846+
54847+ while (rusertp) {
54848+ rlast = rtmp;
54849+
54850+ if ((rtmp = (struct role_transition *)
54851+ acl_alloc(sizeof (struct role_transition))) == NULL)
54852+ return -ENOMEM;
54853+
54854+ if (copy_from_user(rtmp, rusertp,
54855+ sizeof (struct role_transition)))
54856+ return -EFAULT;
54857+
54858+ rusertp = rtmp->prev;
54859+
54860+ len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
54861+
54862+ if (!len || len >= GR_SPROLE_LEN)
54863+ return -EINVAL;
54864+
54865+ if ((tmp = (char *) acl_alloc(len)) == NULL)
54866+ return -ENOMEM;
54867+
54868+ if (copy_from_user(tmp, rtmp->rolename, len))
54869+ return -EFAULT;
54870+ tmp[len-1] = '\0';
54871+ rtmp->rolename = tmp;
54872+
54873+ if (!rlast) {
54874+ rtmp->prev = NULL;
54875+ rolep->transitions = rtmp;
54876+ } else {
54877+ rlast->next = rtmp;
54878+ rtmp->prev = rlast;
54879+ }
54880+
54881+ if (!rusertp)
54882+ rtmp->next = NULL;
54883+ }
54884+
54885+ return 0;
54886+}
54887+
54888+static struct acl_subject_label *
54889+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
54890+{
54891+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
54892+ unsigned int len;
54893+ char *tmp;
54894+ __u32 num_objs;
54895+ struct acl_ip_label **i_tmp, *i_utmp2;
54896+ struct gr_hash_struct ghash;
54897+ struct subject_map *subjmap;
54898+ unsigned int i_num;
54899+ int err;
54900+
54901+ if (already_copied != NULL)
54902+ *already_copied = 0;
54903+
54904+ s_tmp = lookup_subject_map(userp);
54905+
54906+ /* we've already copied this subject into the kernel, just return
54907+ the reference to it, and don't copy it over again
54908+ */
54909+ if (s_tmp) {
54910+ if (already_copied != NULL)
54911+ *already_copied = 1;
54912+ return(s_tmp);
54913+ }
54914+
54915+ if ((s_tmp = (struct acl_subject_label *)
54916+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
54917+ return ERR_PTR(-ENOMEM);
54918+
54919+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
54920+ if (subjmap == NULL)
54921+ return ERR_PTR(-ENOMEM);
54922+
54923+ subjmap->user = userp;
54924+ subjmap->kernel = s_tmp;
54925+ insert_subj_map_entry(subjmap);
54926+
54927+ if (copy_from_user(s_tmp, userp,
54928+ sizeof (struct acl_subject_label)))
54929+ return ERR_PTR(-EFAULT);
54930+
54931+ len = strnlen_user(s_tmp->filename, PATH_MAX);
54932+
54933+ if (!len || len >= PATH_MAX)
54934+ return ERR_PTR(-EINVAL);
54935+
54936+ if ((tmp = (char *) acl_alloc(len)) == NULL)
54937+ return ERR_PTR(-ENOMEM);
54938+
54939+ if (copy_from_user(tmp, s_tmp->filename, len))
54940+ return ERR_PTR(-EFAULT);
54941+ tmp[len-1] = '\0';
54942+ s_tmp->filename = tmp;
54943+
54944+ if (!strcmp(s_tmp->filename, "/"))
54945+ role->root_label = s_tmp;
54946+
54947+ if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
54948+ return ERR_PTR(-EFAULT);
54949+
54950+ /* copy user and group transition tables */
54951+
54952+ if (s_tmp->user_trans_num) {
54953+ uid_t *uidlist;
54954+
54955+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
54956+ if (uidlist == NULL)
54957+ return ERR_PTR(-ENOMEM);
54958+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
54959+ return ERR_PTR(-EFAULT);
54960+
54961+ s_tmp->user_transitions = uidlist;
54962+ }
54963+
54964+ if (s_tmp->group_trans_num) {
54965+ gid_t *gidlist;
54966+
54967+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
54968+ if (gidlist == NULL)
54969+ return ERR_PTR(-ENOMEM);
54970+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
54971+ return ERR_PTR(-EFAULT);
54972+
54973+ s_tmp->group_transitions = gidlist;
54974+ }
54975+
54976+ /* set up object hash table */
54977+ num_objs = count_user_objs(ghash.first);
54978+
54979+ s_tmp->obj_hash_size = num_objs;
54980+ s_tmp->obj_hash =
54981+ (struct acl_object_label **)
54982+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
54983+
54984+ if (!s_tmp->obj_hash)
54985+ return ERR_PTR(-ENOMEM);
54986+
54987+ memset(s_tmp->obj_hash, 0,
54988+ s_tmp->obj_hash_size *
54989+ sizeof (struct acl_object_label *));
54990+
54991+ /* add in objects */
54992+ err = copy_user_objs(ghash.first, s_tmp, role);
54993+
54994+ if (err)
54995+ return ERR_PTR(err);
54996+
54997+ /* set pointer for parent subject */
54998+ if (s_tmp->parent_subject) {
54999+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
55000+
55001+ if (IS_ERR(s_tmp2))
55002+ return s_tmp2;
55003+
55004+ s_tmp->parent_subject = s_tmp2;
55005+ }
55006+
55007+ /* add in ip acls */
55008+
55009+ if (!s_tmp->ip_num) {
55010+ s_tmp->ips = NULL;
55011+ goto insert;
55012+ }
55013+
55014+ i_tmp =
55015+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
55016+ sizeof (struct acl_ip_label *));
55017+
55018+ if (!i_tmp)
55019+ return ERR_PTR(-ENOMEM);
55020+
55021+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
55022+ *(i_tmp + i_num) =
55023+ (struct acl_ip_label *)
55024+ acl_alloc(sizeof (struct acl_ip_label));
55025+ if (!*(i_tmp + i_num))
55026+ return ERR_PTR(-ENOMEM);
55027+
55028+ if (copy_from_user
55029+ (&i_utmp2, s_tmp->ips + i_num,
55030+ sizeof (struct acl_ip_label *)))
55031+ return ERR_PTR(-EFAULT);
55032+
55033+ if (copy_from_user
55034+ (*(i_tmp + i_num), i_utmp2,
55035+ sizeof (struct acl_ip_label)))
55036+ return ERR_PTR(-EFAULT);
55037+
55038+ if ((*(i_tmp + i_num))->iface == NULL)
55039+ continue;
55040+
55041+ len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
55042+ if (!len || len >= IFNAMSIZ)
55043+ return ERR_PTR(-EINVAL);
55044+ tmp = acl_alloc(len);
55045+ if (tmp == NULL)
55046+ return ERR_PTR(-ENOMEM);
55047+ if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
55048+ return ERR_PTR(-EFAULT);
55049+ (*(i_tmp + i_num))->iface = tmp;
55050+ }
55051+
55052+ s_tmp->ips = i_tmp;
55053+
55054+insert:
55055+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
55056+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
55057+ return ERR_PTR(-ENOMEM);
55058+
55059+ return s_tmp;
55060+}
55061+
55062+static int
55063+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
55064+{
55065+ struct acl_subject_label s_pre;
55066+ struct acl_subject_label * ret;
55067+ int err;
55068+
55069+ while (userp) {
55070+ if (copy_from_user(&s_pre, userp,
55071+ sizeof (struct acl_subject_label)))
55072+ return -EFAULT;
55073+
55074+ ret = do_copy_user_subj(userp, role, NULL);
55075+
55076+ err = PTR_ERR(ret);
55077+ if (IS_ERR(ret))
55078+ return err;
55079+
55080+ insert_acl_subj_label(ret, role);
55081+
55082+ userp = s_pre.prev;
55083+ }
55084+
55085+ return 0;
55086+}
55087+
55088+static int
55089+copy_user_acl(struct gr_arg *arg)
55090+{
55091+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
55092+ struct acl_subject_label *subj_list;
55093+ struct sprole_pw *sptmp;
55094+ struct gr_hash_struct *ghash;
55095+ uid_t *domainlist;
55096+ unsigned int r_num;
55097+ unsigned int len;
55098+ char *tmp;
55099+ int err = 0;
55100+ __u16 i;
55101+ __u32 num_subjs;
55102+
55103+ /* we need a default and kernel role */
55104+ if (arg->role_db.num_roles < 2)
55105+ return -EINVAL;
55106+
55107+ /* copy special role authentication info from userspace */
55108+
55109+ num_sprole_pws = arg->num_sprole_pws;
55110+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
55111+
55112+ if (!acl_special_roles && num_sprole_pws)
55113+ return -ENOMEM;
55114+
55115+ for (i = 0; i < num_sprole_pws; i++) {
55116+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
55117+ if (!sptmp)
55118+ return -ENOMEM;
55119+ if (copy_from_user(sptmp, arg->sprole_pws + i,
55120+ sizeof (struct sprole_pw)))
55121+ return -EFAULT;
55122+
55123+ len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
55124+
55125+ if (!len || len >= GR_SPROLE_LEN)
55126+ return -EINVAL;
55127+
55128+ if ((tmp = (char *) acl_alloc(len)) == NULL)
55129+ return -ENOMEM;
55130+
55131+ if (copy_from_user(tmp, sptmp->rolename, len))
55132+ return -EFAULT;
55133+
55134+ tmp[len-1] = '\0';
55135+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
55136+ printk(KERN_ALERT "Copying special role %s\n", tmp);
55137+#endif
55138+ sptmp->rolename = tmp;
55139+ acl_special_roles[i] = sptmp;
55140+ }
55141+
55142+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
55143+
55144+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
55145+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
55146+
55147+ if (!r_tmp)
55148+ return -ENOMEM;
55149+
55150+ if (copy_from_user(&r_utmp2, r_utmp + r_num,
55151+ sizeof (struct acl_role_label *)))
55152+ return -EFAULT;
55153+
55154+ if (copy_from_user(r_tmp, r_utmp2,
55155+ sizeof (struct acl_role_label)))
55156+ return -EFAULT;
55157+
55158+ len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
55159+
55160+ if (!len || len >= PATH_MAX)
55161+ return -EINVAL;
55162+
55163+ if ((tmp = (char *) acl_alloc(len)) == NULL)
55164+ return -ENOMEM;
55165+
55166+ if (copy_from_user(tmp, r_tmp->rolename, len))
55167+ return -EFAULT;
55168+
55169+ tmp[len-1] = '\0';
55170+ r_tmp->rolename = tmp;
55171+
55172+ if (!strcmp(r_tmp->rolename, "default")
55173+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
55174+ default_role = r_tmp;
55175+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
55176+ kernel_role = r_tmp;
55177+ }
55178+
55179+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
55180+ return -ENOMEM;
55181+
55182+ if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
55183+ return -EFAULT;
55184+
55185+ r_tmp->hash = ghash;
55186+
55187+ num_subjs = count_user_subjs(r_tmp->hash->first);
55188+
55189+ r_tmp->subj_hash_size = num_subjs;
55190+ r_tmp->subj_hash =
55191+ (struct acl_subject_label **)
55192+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
55193+
55194+ if (!r_tmp->subj_hash)
55195+ return -ENOMEM;
55196+
55197+ err = copy_user_allowedips(r_tmp);
55198+ if (err)
55199+ return err;
55200+
55201+ /* copy domain info */
55202+ if (r_tmp->domain_children != NULL) {
55203+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
55204+ if (domainlist == NULL)
55205+ return -ENOMEM;
55206+
55207+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
55208+ return -EFAULT;
55209+
55210+ r_tmp->domain_children = domainlist;
55211+ }
55212+
55213+ err = copy_user_transitions(r_tmp);
55214+ if (err)
55215+ return err;
55216+
55217+ memset(r_tmp->subj_hash, 0,
55218+ r_tmp->subj_hash_size *
55219+ sizeof (struct acl_subject_label *));
55220+
55221+ /* acquire the list of subjects, then NULL out
55222+ the list prior to parsing the subjects for this role,
55223+ as during this parsing the list is replaced with a list
55224+ of *nested* subjects for the role
55225+ */
55226+ subj_list = r_tmp->hash->first;
55227+
55228+ /* set nested subject list to null */
55229+ r_tmp->hash->first = NULL;
55230+
55231+ err = copy_user_subjs(subj_list, r_tmp);
55232+
55233+ if (err)
55234+ return err;
55235+
55236+ insert_acl_role_label(r_tmp);
55237+ }
55238+
55239+ if (default_role == NULL || kernel_role == NULL)
55240+ return -EINVAL;
55241+
55242+ return err;
55243+}
55244+
55245+static int
55246+gracl_init(struct gr_arg *args)
55247+{
55248+ int error = 0;
55249+
55250+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
55251+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
55252+
55253+ if (init_variables(args)) {
55254+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
55255+ error = -ENOMEM;
55256+ free_variables();
55257+ goto out;
55258+ }
55259+
55260+ error = copy_user_acl(args);
55261+ free_init_variables();
55262+ if (error) {
55263+ free_variables();
55264+ goto out;
55265+ }
55266+
55267+ if ((error = gr_set_acls(0))) {
55268+ free_variables();
55269+ goto out;
55270+ }
55271+
55272+ pax_open_kernel();
55273+ gr_status |= GR_READY;
55274+ pax_close_kernel();
55275+
55276+ out:
55277+ return error;
55278+}
55279+
55280+/* derived from glibc fnmatch() 0: match, 1: no match*/
55281+
55282+static int
55283+glob_match(const char *p, const char *n)
55284+{
55285+ char c;
55286+
55287+ while ((c = *p++) != '\0') {
55288+ switch (c) {
55289+ case '?':
55290+ if (*n == '\0')
55291+ return 1;
55292+ else if (*n == '/')
55293+ return 1;
55294+ break;
55295+ case '\\':
55296+ if (*n != c)
55297+ return 1;
55298+ break;
55299+ case '*':
55300+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
55301+ if (*n == '/')
55302+ return 1;
55303+ else if (c == '?') {
55304+ if (*n == '\0')
55305+ return 1;
55306+ else
55307+ ++n;
55308+ }
55309+ }
55310+ if (c == '\0') {
55311+ return 0;
55312+ } else {
55313+ const char *endp;
55314+
55315+ if ((endp = strchr(n, '/')) == NULL)
55316+ endp = n + strlen(n);
55317+
55318+ if (c == '[') {
55319+ for (--p; n < endp; ++n)
55320+ if (!glob_match(p, n))
55321+ return 0;
55322+ } else if (c == '/') {
55323+ while (*n != '\0' && *n != '/')
55324+ ++n;
55325+ if (*n == '/' && !glob_match(p, n + 1))
55326+ return 0;
55327+ } else {
55328+ for (--p; n < endp; ++n)
55329+ if (*n == c && !glob_match(p, n))
55330+ return 0;
55331+ }
55332+
55333+ return 1;
55334+ }
55335+ case '[':
55336+ {
55337+ int not;
55338+ char cold;
55339+
55340+ if (*n == '\0' || *n == '/')
55341+ return 1;
55342+
55343+ not = (*p == '!' || *p == '^');
55344+ if (not)
55345+ ++p;
55346+
55347+ c = *p++;
55348+ for (;;) {
55349+ unsigned char fn = (unsigned char)*n;
55350+
55351+ if (c == '\0')
55352+ return 1;
55353+ else {
55354+ if (c == fn)
55355+ goto matched;
55356+ cold = c;
55357+ c = *p++;
55358+
55359+ if (c == '-' && *p != ']') {
55360+ unsigned char cend = *p++;
55361+
55362+ if (cend == '\0')
55363+ return 1;
55364+
55365+ if (cold <= fn && fn <= cend)
55366+ goto matched;
55367+
55368+ c = *p++;
55369+ }
55370+ }
55371+
55372+ if (c == ']')
55373+ break;
55374+ }
55375+ if (!not)
55376+ return 1;
55377+ break;
55378+ matched:
55379+ while (c != ']') {
55380+ if (c == '\0')
55381+ return 1;
55382+
55383+ c = *p++;
55384+ }
55385+ if (not)
55386+ return 1;
55387+ }
55388+ break;
55389+ default:
55390+ if (c != *n)
55391+ return 1;
55392+ }
55393+
55394+ ++n;
55395+ }
55396+
55397+ if (*n == '\0')
55398+ return 0;
55399+
55400+ if (*n == '/')
55401+ return 0;
55402+
55403+ return 1;
55404+}
55405+
55406+static struct acl_object_label *
55407+chk_glob_label(struct acl_object_label *globbed,
55408+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
55409+{
55410+ struct acl_object_label *tmp;
55411+
55412+ if (*path == NULL)
55413+ *path = gr_to_filename_nolock(dentry, mnt);
55414+
55415+ tmp = globbed;
55416+
55417+ while (tmp) {
55418+ if (!glob_match(tmp->filename, *path))
55419+ return tmp;
55420+ tmp = tmp->next;
55421+ }
55422+
55423+ return NULL;
55424+}
55425+
55426+static struct acl_object_label *
55427+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
55428+ const ino_t curr_ino, const dev_t curr_dev,
55429+ const struct acl_subject_label *subj, char **path, const int checkglob)
55430+{
55431+ struct acl_subject_label *tmpsubj;
55432+ struct acl_object_label *retval;
55433+ struct acl_object_label *retval2;
55434+
55435+ tmpsubj = (struct acl_subject_label *) subj;
55436+ read_lock(&gr_inode_lock);
55437+ do {
55438+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
55439+ if (retval) {
55440+ if (checkglob && retval->globbed) {
55441+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
55442+ if (retval2)
55443+ retval = retval2;
55444+ }
55445+ break;
55446+ }
55447+ } while ((tmpsubj = tmpsubj->parent_subject));
55448+ read_unlock(&gr_inode_lock);
55449+
55450+ return retval;
55451+}
55452+
55453+static __inline__ struct acl_object_label *
55454+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
55455+ struct dentry *curr_dentry,
55456+ const struct acl_subject_label *subj, char **path, const int checkglob)
55457+{
55458+ int newglob = checkglob;
55459+ ino_t inode;
55460+ dev_t device;
55461+
55462+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
55463+ as we don't want a / * rule to match instead of the / object
55464+ don't do this for create lookups that call this function though, since they're looking up
55465+ on the parent and thus need globbing checks on all paths
55466+ */
55467+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
55468+ newglob = GR_NO_GLOB;
55469+
55470+ spin_lock(&curr_dentry->d_lock);
55471+ inode = curr_dentry->d_inode->i_ino;
55472+ device = __get_dev(curr_dentry);
55473+ spin_unlock(&curr_dentry->d_lock);
55474+
55475+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
55476+}
55477+
55478+static struct acl_object_label *
55479+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
55480+ const struct acl_subject_label *subj, char *path, const int checkglob)
55481+{
55482+ struct dentry *dentry = (struct dentry *) l_dentry;
55483+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
55484+ struct mount *real_mnt = real_mount(mnt);
55485+ struct acl_object_label *retval;
55486+ struct dentry *parent;
55487+
55488+ write_seqlock(&rename_lock);
55489+ br_read_lock(&vfsmount_lock);
55490+
55491+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
55492+#ifdef CONFIG_NET
55493+ mnt == sock_mnt ||
55494+#endif
55495+#ifdef CONFIG_HUGETLBFS
55496+ (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
55497+#endif
55498+ /* ignore Eric Biederman */
55499+ IS_PRIVATE(l_dentry->d_inode))) {
55500+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
55501+ goto out;
55502+ }
55503+
55504+ for (;;) {
55505+ if (dentry == real_root.dentry && mnt == real_root.mnt)
55506+ break;
55507+
55508+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
55509+ if (!mnt_has_parent(real_mnt))
55510+ break;
55511+
55512+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
55513+ if (retval != NULL)
55514+ goto out;
55515+
55516+ dentry = real_mnt->mnt_mountpoint;
55517+ real_mnt = real_mnt->mnt_parent;
55518+ mnt = &real_mnt->mnt;
55519+ continue;
55520+ }
55521+
55522+ parent = dentry->d_parent;
55523+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
55524+ if (retval != NULL)
55525+ goto out;
55526+
55527+ dentry = parent;
55528+ }
55529+
55530+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
55531+
55532+ /* real_root is pinned so we don't have to hold a reference */
55533+ if (retval == NULL)
55534+ retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
55535+out:
55536+ br_read_unlock(&vfsmount_lock);
55537+ write_sequnlock(&rename_lock);
55538+
55539+ BUG_ON(retval == NULL);
55540+
55541+ return retval;
55542+}
55543+
55544+static __inline__ struct acl_object_label *
55545+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
55546+ const struct acl_subject_label *subj)
55547+{
55548+ char *path = NULL;
55549+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
55550+}
55551+
55552+static __inline__ struct acl_object_label *
55553+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
55554+ const struct acl_subject_label *subj)
55555+{
55556+ char *path = NULL;
55557+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
55558+}
55559+
55560+static __inline__ struct acl_object_label *
55561+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
55562+ const struct acl_subject_label *subj, char *path)
55563+{
55564+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
55565+}
55566+
55567+static struct acl_subject_label *
55568+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
55569+ const struct acl_role_label *role)
55570+{
55571+ struct dentry *dentry = (struct dentry *) l_dentry;
55572+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
55573+ struct mount *real_mnt = real_mount(mnt);
55574+ struct acl_subject_label *retval;
55575+ struct dentry *parent;
55576+
55577+ write_seqlock(&rename_lock);
55578+ br_read_lock(&vfsmount_lock);
55579+
55580+ for (;;) {
55581+ if (dentry == real_root.dentry && mnt == real_root.mnt)
55582+ break;
55583+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
55584+ if (!mnt_has_parent(real_mnt))
55585+ break;
55586+
55587+ spin_lock(&dentry->d_lock);
55588+ read_lock(&gr_inode_lock);
55589+ retval =
55590+ lookup_acl_subj_label(dentry->d_inode->i_ino,
55591+ __get_dev(dentry), role);
55592+ read_unlock(&gr_inode_lock);
55593+ spin_unlock(&dentry->d_lock);
55594+ if (retval != NULL)
55595+ goto out;
55596+
55597+ dentry = real_mnt->mnt_mountpoint;
55598+ real_mnt = real_mnt->mnt_parent;
55599+ mnt = &real_mnt->mnt;
55600+ continue;
55601+ }
55602+
55603+ spin_lock(&dentry->d_lock);
55604+ read_lock(&gr_inode_lock);
55605+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
55606+ __get_dev(dentry), role);
55607+ read_unlock(&gr_inode_lock);
55608+ parent = dentry->d_parent;
55609+ spin_unlock(&dentry->d_lock);
55610+
55611+ if (retval != NULL)
55612+ goto out;
55613+
55614+ dentry = parent;
55615+ }
55616+
55617+ spin_lock(&dentry->d_lock);
55618+ read_lock(&gr_inode_lock);
55619+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
55620+ __get_dev(dentry), role);
55621+ read_unlock(&gr_inode_lock);
55622+ spin_unlock(&dentry->d_lock);
55623+
55624+ if (unlikely(retval == NULL)) {
55625+ /* real_root is pinned, we don't need to hold a reference */
55626+ read_lock(&gr_inode_lock);
55627+ retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
55628+ __get_dev(real_root.dentry), role);
55629+ read_unlock(&gr_inode_lock);
55630+ }
55631+out:
55632+ br_read_unlock(&vfsmount_lock);
55633+ write_sequnlock(&rename_lock);
55634+
55635+ BUG_ON(retval == NULL);
55636+
55637+ return retval;
55638+}
55639+
55640+static void
55641+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
55642+{
55643+ struct task_struct *task = current;
55644+ const struct cred *cred = current_cred();
55645+
55646+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
55647+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
55648+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
55649+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
55650+
55651+ return;
55652+}
55653+
55654+static void
55655+gr_log_learn_id_change(const char type, const unsigned int real,
55656+ const unsigned int effective, const unsigned int fs)
55657+{
55658+ struct task_struct *task = current;
55659+ const struct cred *cred = current_cred();
55660+
55661+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
55662+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
55663+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
55664+ type, real, effective, fs, &task->signal->saved_ip);
55665+
55666+ return;
55667+}
55668+
55669+__u32
55670+gr_search_file(const struct dentry * dentry, const __u32 mode,
55671+ const struct vfsmount * mnt)
55672+{
55673+ __u32 retval = mode;
55674+ struct acl_subject_label *curracl;
55675+ struct acl_object_label *currobj;
55676+
55677+ if (unlikely(!(gr_status & GR_READY)))
55678+ return (mode & ~GR_AUDITS);
55679+
55680+ curracl = current->acl;
55681+
55682+ currobj = chk_obj_label(dentry, mnt, curracl);
55683+ retval = currobj->mode & mode;
55684+
55685+ /* if we're opening a specified transfer file for writing
55686+ (e.g. /dev/initctl), then transfer our role to init
55687+ */
55688+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
55689+ current->role->roletype & GR_ROLE_PERSIST)) {
55690+ struct task_struct *task = init_pid_ns.child_reaper;
55691+
55692+ if (task->role != current->role) {
55693+ task->acl_sp_role = 0;
55694+ task->acl_role_id = current->acl_role_id;
55695+ task->role = current->role;
55696+ rcu_read_lock();
55697+ read_lock(&grsec_exec_file_lock);
55698+ gr_apply_subject_to_task(task);
55699+ read_unlock(&grsec_exec_file_lock);
55700+ rcu_read_unlock();
55701+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
55702+ }
55703+ }
55704+
55705+ if (unlikely
55706+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
55707+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
55708+ __u32 new_mode = mode;
55709+
55710+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
55711+
55712+ retval = new_mode;
55713+
55714+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
55715+ new_mode |= GR_INHERIT;
55716+
55717+ if (!(mode & GR_NOLEARN))
55718+ gr_log_learn(dentry, mnt, new_mode);
55719+ }
55720+
55721+ return retval;
55722+}
55723+
55724+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
55725+ const struct dentry *parent,
55726+ const struct vfsmount *mnt)
55727+{
55728+ struct name_entry *match;
55729+ struct acl_object_label *matchpo;
55730+ struct acl_subject_label *curracl;
55731+ char *path;
55732+
55733+ if (unlikely(!(gr_status & GR_READY)))
55734+ return NULL;
55735+
55736+ preempt_disable();
55737+ path = gr_to_filename_rbac(new_dentry, mnt);
55738+ match = lookup_name_entry_create(path);
55739+
55740+ curracl = current->acl;
55741+
55742+ if (match) {
55743+ read_lock(&gr_inode_lock);
55744+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
55745+ read_unlock(&gr_inode_lock);
55746+
55747+ if (matchpo) {
55748+ preempt_enable();
55749+ return matchpo;
55750+ }
55751+ }
55752+
55753+ // lookup parent
55754+
55755+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
55756+
55757+ preempt_enable();
55758+ return matchpo;
55759+}
55760+
55761+__u32
55762+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
55763+ const struct vfsmount * mnt, const __u32 mode)
55764+{
55765+ struct acl_object_label *matchpo;
55766+ __u32 retval;
55767+
55768+ if (unlikely(!(gr_status & GR_READY)))
55769+ return (mode & ~GR_AUDITS);
55770+
55771+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
55772+
55773+ retval = matchpo->mode & mode;
55774+
55775+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
55776+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
55777+ __u32 new_mode = mode;
55778+
55779+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
55780+
55781+ gr_log_learn(new_dentry, mnt, new_mode);
55782+ return new_mode;
55783+ }
55784+
55785+ return retval;
55786+}
55787+
55788+__u32
55789+gr_check_link(const struct dentry * new_dentry,
55790+ const struct dentry * parent_dentry,
55791+ const struct vfsmount * parent_mnt,
55792+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
55793+{
55794+ struct acl_object_label *obj;
55795+ __u32 oldmode, newmode;
55796+ __u32 needmode;
55797+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
55798+ GR_DELETE | GR_INHERIT;
55799+
55800+ if (unlikely(!(gr_status & GR_READY)))
55801+ return (GR_CREATE | GR_LINK);
55802+
55803+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
55804+ oldmode = obj->mode;
55805+
55806+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
55807+ newmode = obj->mode;
55808+
55809+ needmode = newmode & checkmodes;
55810+
55811+ // old name for hardlink must have at least the permissions of the new name
55812+ if ((oldmode & needmode) != needmode)
55813+ goto bad;
55814+
55815+ // if old name had restrictions/auditing, make sure the new name does as well
55816+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
55817+
55818+ // don't allow hardlinking of suid/sgid/fcapped files without permission
55819+ if (is_privileged_binary(old_dentry))
55820+ needmode |= GR_SETID;
55821+
55822+ if ((newmode & needmode) != needmode)
55823+ goto bad;
55824+
55825+ // enforce minimum permissions
55826+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
55827+ return newmode;
55828+bad:
55829+ needmode = oldmode;
55830+ if (is_privileged_binary(old_dentry))
55831+ needmode |= GR_SETID;
55832+
55833+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
55834+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
55835+ return (GR_CREATE | GR_LINK);
55836+ } else if (newmode & GR_SUPPRESS)
55837+ return GR_SUPPRESS;
55838+ else
55839+ return 0;
55840+}
55841+
55842+int
55843+gr_check_hidden_task(const struct task_struct *task)
55844+{
55845+ if (unlikely(!(gr_status & GR_READY)))
55846+ return 0;
55847+
55848+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
55849+ return 1;
55850+
55851+ return 0;
55852+}
55853+
55854+int
55855+gr_check_protected_task(const struct task_struct *task)
55856+{
55857+ if (unlikely(!(gr_status & GR_READY) || !task))
55858+ return 0;
55859+
55860+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
55861+ task->acl != current->acl)
55862+ return 1;
55863+
55864+ return 0;
55865+}
55866+
55867+int
55868+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
55869+{
55870+ struct task_struct *p;
55871+ int ret = 0;
55872+
55873+ if (unlikely(!(gr_status & GR_READY) || !pid))
55874+ return ret;
55875+
55876+ read_lock(&tasklist_lock);
55877+ do_each_pid_task(pid, type, p) {
55878+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
55879+ p->acl != current->acl) {
55880+ ret = 1;
55881+ goto out;
55882+ }
55883+ } while_each_pid_task(pid, type, p);
55884+out:
55885+ read_unlock(&tasklist_lock);
55886+
55887+ return ret;
55888+}
55889+
55890+void
55891+gr_copy_label(struct task_struct *tsk)
55892+{
55893+ tsk->signal->used_accept = 0;
55894+ tsk->acl_sp_role = 0;
55895+ tsk->acl_role_id = current->acl_role_id;
55896+ tsk->acl = current->acl;
55897+ tsk->role = current->role;
55898+ tsk->signal->curr_ip = current->signal->curr_ip;
55899+ tsk->signal->saved_ip = current->signal->saved_ip;
55900+ if (current->exec_file)
55901+ get_file(current->exec_file);
55902+ tsk->exec_file = current->exec_file;
55903+ tsk->is_writable = current->is_writable;
55904+ if (unlikely(current->signal->used_accept)) {
55905+ current->signal->curr_ip = 0;
55906+ current->signal->saved_ip = 0;
55907+ }
55908+
55909+ return;
55910+}
55911+
55912+static void
55913+gr_set_proc_res(struct task_struct *task)
55914+{
55915+ struct acl_subject_label *proc;
55916+ unsigned short i;
55917+
55918+ proc = task->acl;
55919+
55920+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
55921+ return;
55922+
55923+ for (i = 0; i < RLIM_NLIMITS; i++) {
55924+ if (!(proc->resmask & (1 << i)))
55925+ continue;
55926+
55927+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
55928+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
55929+ }
55930+
55931+ return;
55932+}
55933+
55934+extern int __gr_process_user_ban(struct user_struct *user);
55935+
55936+int
55937+gr_check_user_change(int real, int effective, int fs)
55938+{
55939+ unsigned int i;
55940+ __u16 num;
55941+ uid_t *uidlist;
55942+ int curuid;
55943+ int realok = 0;
55944+ int effectiveok = 0;
55945+ int fsok = 0;
55946+
55947+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
55948+ struct user_struct *user;
55949+
55950+ if (real == -1)
55951+ goto skipit;
55952+
55953+ user = find_user(real);
55954+ if (user == NULL)
55955+ goto skipit;
55956+
55957+ if (__gr_process_user_ban(user)) {
55958+ /* for find_user */
55959+ free_uid(user);
55960+ return 1;
55961+ }
55962+
55963+ /* for find_user */
55964+ free_uid(user);
55965+
55966+skipit:
55967+#endif
55968+
55969+ if (unlikely(!(gr_status & GR_READY)))
55970+ return 0;
55971+
55972+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
55973+ gr_log_learn_id_change('u', real, effective, fs);
55974+
55975+ num = current->acl->user_trans_num;
55976+ uidlist = current->acl->user_transitions;
55977+
55978+ if (uidlist == NULL)
55979+ return 0;
55980+
55981+ if (real == -1)
55982+ realok = 1;
55983+ if (effective == -1)
55984+ effectiveok = 1;
55985+ if (fs == -1)
55986+ fsok = 1;
55987+
55988+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
55989+ for (i = 0; i < num; i++) {
55990+ curuid = (int)uidlist[i];
55991+ if (real == curuid)
55992+ realok = 1;
55993+ if (effective == curuid)
55994+ effectiveok = 1;
55995+ if (fs == curuid)
55996+ fsok = 1;
55997+ }
55998+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
55999+ for (i = 0; i < num; i++) {
56000+ curuid = (int)uidlist[i];
56001+ if (real == curuid)
56002+ break;
56003+ if (effective == curuid)
56004+ break;
56005+ if (fs == curuid)
56006+ break;
56007+ }
56008+ /* not in deny list */
56009+ if (i == num) {
56010+ realok = 1;
56011+ effectiveok = 1;
56012+ fsok = 1;
56013+ }
56014+ }
56015+
56016+ if (realok && effectiveok && fsok)
56017+ return 0;
56018+ else {
56019+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
56020+ return 1;
56021+ }
56022+}
56023+
56024+int
56025+gr_check_group_change(int real, int effective, int fs)
56026+{
56027+ unsigned int i;
56028+ __u16 num;
56029+ gid_t *gidlist;
56030+ int curgid;
56031+ int realok = 0;
56032+ int effectiveok = 0;
56033+ int fsok = 0;
56034+
56035+ if (unlikely(!(gr_status & GR_READY)))
56036+ return 0;
56037+
56038+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
56039+ gr_log_learn_id_change('g', real, effective, fs);
56040+
56041+ num = current->acl->group_trans_num;
56042+ gidlist = current->acl->group_transitions;
56043+
56044+ if (gidlist == NULL)
56045+ return 0;
56046+
56047+ if (real == -1)
56048+ realok = 1;
56049+ if (effective == -1)
56050+ effectiveok = 1;
56051+ if (fs == -1)
56052+ fsok = 1;
56053+
56054+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
56055+ for (i = 0; i < num; i++) {
56056+ curgid = (int)gidlist[i];
56057+ if (real == curgid)
56058+ realok = 1;
56059+ if (effective == curgid)
56060+ effectiveok = 1;
56061+ if (fs == curgid)
56062+ fsok = 1;
56063+ }
56064+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
56065+ for (i = 0; i < num; i++) {
56066+ curgid = (int)gidlist[i];
56067+ if (real == curgid)
56068+ break;
56069+ if (effective == curgid)
56070+ break;
56071+ if (fs == curgid)
56072+ break;
56073+ }
56074+ /* not in deny list */
56075+ if (i == num) {
56076+ realok = 1;
56077+ effectiveok = 1;
56078+ fsok = 1;
56079+ }
56080+ }
56081+
56082+ if (realok && effectiveok && fsok)
56083+ return 0;
56084+ else {
56085+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
56086+ return 1;
56087+ }
56088+}
56089+
56090+extern int gr_acl_is_capable(const int cap);
56091+
56092+void
56093+gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
56094+{
56095+ struct acl_role_label *role = task->role;
56096+ struct acl_subject_label *subj = NULL;
56097+ struct acl_object_label *obj;
56098+ struct file *filp;
56099+
56100+ if (unlikely(!(gr_status & GR_READY)))
56101+ return;
56102+
56103+ filp = task->exec_file;
56104+
56105+ /* kernel process, we'll give them the kernel role */
56106+ if (unlikely(!filp)) {
56107+ task->role = kernel_role;
56108+ task->acl = kernel_role->root_label;
56109+ return;
56110+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
56111+ role = lookup_acl_role_label(task, uid, gid);
56112+
56113+ /* don't change the role if we're not a privileged process */
56114+ if (role && task->role != role &&
56115+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
56116+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
56117+ return;
56118+
56119+ /* perform subject lookup in possibly new role
56120+ we can use this result below in the case where role == task->role
56121+ */
56122+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
56123+
56124+ /* if we changed uid/gid, but result in the same role
56125+ and are using inheritance, don't lose the inherited subject
56126+ if current subject is other than what normal lookup
56127+ would result in, we arrived via inheritance, don't
56128+ lose subject
56129+ */
56130+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
56131+ (subj == task->acl)))
56132+ task->acl = subj;
56133+
56134+ task->role = role;
56135+
56136+ task->is_writable = 0;
56137+
56138+ /* ignore additional mmap checks for processes that are writable
56139+ by the default ACL */
56140+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
56141+ if (unlikely(obj->mode & GR_WRITE))
56142+ task->is_writable = 1;
56143+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
56144+ if (unlikely(obj->mode & GR_WRITE))
56145+ task->is_writable = 1;
56146+
56147+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
56148+ printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
56149+#endif
56150+
56151+ gr_set_proc_res(task);
56152+
56153+ return;
56154+}
56155+
56156+int
56157+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
56158+ const int unsafe_flags)
56159+{
56160+ struct task_struct *task = current;
56161+ struct acl_subject_label *newacl;
56162+ struct acl_object_label *obj;
56163+ __u32 retmode;
56164+
56165+ if (unlikely(!(gr_status & GR_READY)))
56166+ return 0;
56167+
56168+ newacl = chk_subj_label(dentry, mnt, task->role);
56169+
56170+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
56171+ did an exec
56172+ */
56173+ rcu_read_lock();
56174+ read_lock(&tasklist_lock);
56175+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
56176+ (task->parent->acl->mode & GR_POVERRIDE))) {
56177+ read_unlock(&tasklist_lock);
56178+ rcu_read_unlock();
56179+ goto skip_check;
56180+ }
56181+ read_unlock(&tasklist_lock);
56182+ rcu_read_unlock();
56183+
56184+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
56185+ !(task->role->roletype & GR_ROLE_GOD) &&
56186+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
56187+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
56188+ if (unsafe_flags & LSM_UNSAFE_SHARE)
56189+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
56190+ else
56191+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
56192+ return -EACCES;
56193+ }
56194+
56195+skip_check:
56196+
56197+ obj = chk_obj_label(dentry, mnt, task->acl);
56198+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
56199+
56200+ if (!(task->acl->mode & GR_INHERITLEARN) &&
56201+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
56202+ if (obj->nested)
56203+ task->acl = obj->nested;
56204+ else
56205+ task->acl = newacl;
56206+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
56207+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
56208+
56209+ task->is_writable = 0;
56210+
56211+ /* ignore additional mmap checks for processes that are writable
56212+ by the default ACL */
56213+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
56214+ if (unlikely(obj->mode & GR_WRITE))
56215+ task->is_writable = 1;
56216+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
56217+ if (unlikely(obj->mode & GR_WRITE))
56218+ task->is_writable = 1;
56219+
56220+ gr_set_proc_res(task);
56221+
56222+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
56223+ printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
56224+#endif
56225+ return 0;
56226+}
56227+
56228+/* always called with valid inodev ptr */
56229+static void
56230+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
56231+{
56232+ struct acl_object_label *matchpo;
56233+ struct acl_subject_label *matchps;
56234+ struct acl_subject_label *subj;
56235+ struct acl_role_label *role;
56236+ unsigned int x;
56237+
56238+ FOR_EACH_ROLE_START(role)
56239+ FOR_EACH_SUBJECT_START(role, subj, x)
56240+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
56241+ matchpo->mode |= GR_DELETED;
56242+ FOR_EACH_SUBJECT_END(subj,x)
56243+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
56244+ /* nested subjects aren't in the role's subj_hash table */
56245+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
56246+ matchpo->mode |= GR_DELETED;
56247+ FOR_EACH_NESTED_SUBJECT_END(subj)
56248+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
56249+ matchps->mode |= GR_DELETED;
56250+ FOR_EACH_ROLE_END(role)
56251+
56252+ inodev->nentry->deleted = 1;
56253+
56254+ return;
56255+}
56256+
56257+void
56258+gr_handle_delete(const ino_t ino, const dev_t dev)
56259+{
56260+ struct inodev_entry *inodev;
56261+
56262+ if (unlikely(!(gr_status & GR_READY)))
56263+ return;
56264+
56265+ write_lock(&gr_inode_lock);
56266+ inodev = lookup_inodev_entry(ino, dev);
56267+ if (inodev != NULL)
56268+ do_handle_delete(inodev, ino, dev);
56269+ write_unlock(&gr_inode_lock);
56270+
56271+ return;
56272+}
56273+
56274+static void
56275+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
56276+ const ino_t newinode, const dev_t newdevice,
56277+ struct acl_subject_label *subj)
56278+{
56279+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
56280+ struct acl_object_label *match;
56281+
56282+ match = subj->obj_hash[index];
56283+
56284+ while (match && (match->inode != oldinode ||
56285+ match->device != olddevice ||
56286+ !(match->mode & GR_DELETED)))
56287+ match = match->next;
56288+
56289+ if (match && (match->inode == oldinode)
56290+ && (match->device == olddevice)
56291+ && (match->mode & GR_DELETED)) {
56292+ if (match->prev == NULL) {
56293+ subj->obj_hash[index] = match->next;
56294+ if (match->next != NULL)
56295+ match->next->prev = NULL;
56296+ } else {
56297+ match->prev->next = match->next;
56298+ if (match->next != NULL)
56299+ match->next->prev = match->prev;
56300+ }
56301+ match->prev = NULL;
56302+ match->next = NULL;
56303+ match->inode = newinode;
56304+ match->device = newdevice;
56305+ match->mode &= ~GR_DELETED;
56306+
56307+ insert_acl_obj_label(match, subj);
56308+ }
56309+
56310+ return;
56311+}
56312+
56313+static void
56314+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
56315+ const ino_t newinode, const dev_t newdevice,
56316+ struct acl_role_label *role)
56317+{
56318+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
56319+ struct acl_subject_label *match;
56320+
56321+ match = role->subj_hash[index];
56322+
56323+ while (match && (match->inode != oldinode ||
56324+ match->device != olddevice ||
56325+ !(match->mode & GR_DELETED)))
56326+ match = match->next;
56327+
56328+ if (match && (match->inode == oldinode)
56329+ && (match->device == olddevice)
56330+ && (match->mode & GR_DELETED)) {
56331+ if (match->prev == NULL) {
56332+ role->subj_hash[index] = match->next;
56333+ if (match->next != NULL)
56334+ match->next->prev = NULL;
56335+ } else {
56336+ match->prev->next = match->next;
56337+ if (match->next != NULL)
56338+ match->next->prev = match->prev;
56339+ }
56340+ match->prev = NULL;
56341+ match->next = NULL;
56342+ match->inode = newinode;
56343+ match->device = newdevice;
56344+ match->mode &= ~GR_DELETED;
56345+
56346+ insert_acl_subj_label(match, role);
56347+ }
56348+
56349+ return;
56350+}
56351+
56352+static void
56353+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
56354+ const ino_t newinode, const dev_t newdevice)
56355+{
56356+ unsigned int index = gr_fhash(oldinode, olddevice, inodev_set.i_size);
56357+ struct inodev_entry *match;
56358+
56359+ match = inodev_set.i_hash[index];
56360+
56361+ while (match && (match->nentry->inode != oldinode ||
56362+ match->nentry->device != olddevice || !match->nentry->deleted))
56363+ match = match->next;
56364+
56365+ if (match && (match->nentry->inode == oldinode)
56366+ && (match->nentry->device == olddevice) &&
56367+ match->nentry->deleted) {
56368+ if (match->prev == NULL) {
56369+ inodev_set.i_hash[index] = match->next;
56370+ if (match->next != NULL)
56371+ match->next->prev = NULL;
56372+ } else {
56373+ match->prev->next = match->next;
56374+ if (match->next != NULL)
56375+ match->next->prev = match->prev;
56376+ }
56377+ match->prev = NULL;
56378+ match->next = NULL;
56379+ match->nentry->inode = newinode;
56380+ match->nentry->device = newdevice;
56381+ match->nentry->deleted = 0;
56382+
56383+ insert_inodev_entry(match);
56384+ }
56385+
56386+ return;
56387+}
56388+
56389+static void
56390+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
56391+{
56392+ struct acl_subject_label *subj;
56393+ struct acl_role_label *role;
56394+ unsigned int x;
56395+
56396+ FOR_EACH_ROLE_START(role)
56397+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
56398+
56399+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
56400+ if ((subj->inode == ino) && (subj->device == dev)) {
56401+ subj->inode = ino;
56402+ subj->device = dev;
56403+ }
56404+ /* nested subjects aren't in the role's subj_hash table */
56405+ update_acl_obj_label(matchn->inode, matchn->device,
56406+ ino, dev, subj);
56407+ FOR_EACH_NESTED_SUBJECT_END(subj)
56408+ FOR_EACH_SUBJECT_START(role, subj, x)
56409+ update_acl_obj_label(matchn->inode, matchn->device,
56410+ ino, dev, subj);
56411+ FOR_EACH_SUBJECT_END(subj,x)
56412+ FOR_EACH_ROLE_END(role)
56413+
56414+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
56415+
56416+ return;
56417+}
56418+
56419+static void
56420+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
56421+ const struct vfsmount *mnt)
56422+{
56423+ ino_t ino = dentry->d_inode->i_ino;
56424+ dev_t dev = __get_dev(dentry);
56425+
56426+ __do_handle_create(matchn, ino, dev);
56427+
56428+ return;
56429+}
56430+
56431+void
56432+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
56433+{
56434+ struct name_entry *matchn;
56435+
56436+ if (unlikely(!(gr_status & GR_READY)))
56437+ return;
56438+
56439+ preempt_disable();
56440+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
56441+
56442+ if (unlikely((unsigned long)matchn)) {
56443+ write_lock(&gr_inode_lock);
56444+ do_handle_create(matchn, dentry, mnt);
56445+ write_unlock(&gr_inode_lock);
56446+ }
56447+ preempt_enable();
56448+
56449+ return;
56450+}
56451+
56452+void
56453+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
56454+{
56455+ struct name_entry *matchn;
56456+
56457+ if (unlikely(!(gr_status & GR_READY)))
56458+ return;
56459+
56460+ preempt_disable();
56461+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
56462+
56463+ if (unlikely((unsigned long)matchn)) {
56464+ write_lock(&gr_inode_lock);
56465+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
56466+ write_unlock(&gr_inode_lock);
56467+ }
56468+ preempt_enable();
56469+
56470+ return;
56471+}
56472+
56473+void
56474+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
56475+ struct dentry *old_dentry,
56476+ struct dentry *new_dentry,
56477+ struct vfsmount *mnt, const __u8 replace)
56478+{
56479+ struct name_entry *matchn;
56480+ struct inodev_entry *inodev;
56481+ struct inode *inode = new_dentry->d_inode;
56482+ ino_t old_ino = old_dentry->d_inode->i_ino;
56483+ dev_t old_dev = __get_dev(old_dentry);
56484+
56485+ /* vfs_rename swaps the name and parent link for old_dentry and
56486+ new_dentry
56487+ at this point, old_dentry has the new name, parent link, and inode
56488+ for the renamed file
56489+ if a file is being replaced by a rename, new_dentry has the inode
56490+ and name for the replaced file
56491+ */
56492+
56493+ if (unlikely(!(gr_status & GR_READY)))
56494+ return;
56495+
56496+ preempt_disable();
56497+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
56498+
56499+ /* we wouldn't have to check d_inode if it weren't for
56500+ NFS silly-renaming
56501+ */
56502+
56503+ write_lock(&gr_inode_lock);
56504+ if (unlikely(replace && inode)) {
56505+ ino_t new_ino = inode->i_ino;
56506+ dev_t new_dev = __get_dev(new_dentry);
56507+
56508+ inodev = lookup_inodev_entry(new_ino, new_dev);
56509+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
56510+ do_handle_delete(inodev, new_ino, new_dev);
56511+ }
56512+
56513+ inodev = lookup_inodev_entry(old_ino, old_dev);
56514+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
56515+ do_handle_delete(inodev, old_ino, old_dev);
56516+
56517+ if (unlikely((unsigned long)matchn))
56518+ do_handle_create(matchn, old_dentry, mnt);
56519+
56520+ write_unlock(&gr_inode_lock);
56521+ preempt_enable();
56522+
56523+ return;
56524+}
56525+
56526+static int
56527+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
56528+ unsigned char **sum)
56529+{
56530+ struct acl_role_label *r;
56531+ struct role_allowed_ip *ipp;
56532+ struct role_transition *trans;
56533+ unsigned int i;
56534+ int found = 0;
56535+ u32 curr_ip = current->signal->curr_ip;
56536+
56537+ current->signal->saved_ip = curr_ip;
56538+
56539+ /* check transition table */
56540+
56541+ for (trans = current->role->transitions; trans; trans = trans->next) {
56542+ if (!strcmp(rolename, trans->rolename)) {
56543+ found = 1;
56544+ break;
56545+ }
56546+ }
56547+
56548+ if (!found)
56549+ return 0;
56550+
56551+ /* handle special roles that do not require authentication
56552+ and check ip */
56553+
56554+ FOR_EACH_ROLE_START(r)
56555+ if (!strcmp(rolename, r->rolename) &&
56556+ (r->roletype & GR_ROLE_SPECIAL)) {
56557+ found = 0;
56558+ if (r->allowed_ips != NULL) {
56559+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
56560+ if ((ntohl(curr_ip) & ipp->netmask) ==
56561+ (ntohl(ipp->addr) & ipp->netmask))
56562+ found = 1;
56563+ }
56564+ } else
56565+ found = 2;
56566+ if (!found)
56567+ return 0;
56568+
56569+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
56570+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
56571+ *salt = NULL;
56572+ *sum = NULL;
56573+ return 1;
56574+ }
56575+ }
56576+ FOR_EACH_ROLE_END(r)
56577+
56578+ for (i = 0; i < num_sprole_pws; i++) {
56579+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
56580+ *salt = acl_special_roles[i]->salt;
56581+ *sum = acl_special_roles[i]->sum;
56582+ return 1;
56583+ }
56584+ }
56585+
56586+ return 0;
56587+}
56588+
56589+static void
56590+assign_special_role(char *rolename)
56591+{
56592+ struct acl_object_label *obj;
56593+ struct acl_role_label *r;
56594+ struct acl_role_label *assigned = NULL;
56595+ struct task_struct *tsk;
56596+ struct file *filp;
56597+
56598+ FOR_EACH_ROLE_START(r)
56599+ if (!strcmp(rolename, r->rolename) &&
56600+ (r->roletype & GR_ROLE_SPECIAL)) {
56601+ assigned = r;
56602+ break;
56603+ }
56604+ FOR_EACH_ROLE_END(r)
56605+
56606+ if (!assigned)
56607+ return;
56608+
56609+ read_lock(&tasklist_lock);
56610+ read_lock(&grsec_exec_file_lock);
56611+
56612+ tsk = current->real_parent;
56613+ if (tsk == NULL)
56614+ goto out_unlock;
56615+
56616+ filp = tsk->exec_file;
56617+ if (filp == NULL)
56618+ goto out_unlock;
56619+
56620+ tsk->is_writable = 0;
56621+
56622+ tsk->acl_sp_role = 1;
56623+ tsk->acl_role_id = ++acl_sp_role_value;
56624+ tsk->role = assigned;
56625+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
56626+
56627+ /* ignore additional mmap checks for processes that are writable
56628+ by the default ACL */
56629+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
56630+ if (unlikely(obj->mode & GR_WRITE))
56631+ tsk->is_writable = 1;
56632+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
56633+ if (unlikely(obj->mode & GR_WRITE))
56634+ tsk->is_writable = 1;
56635+
56636+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
56637+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
56638+#endif
56639+
56640+out_unlock:
56641+ read_unlock(&grsec_exec_file_lock);
56642+ read_unlock(&tasklist_lock);
56643+ return;
56644+}
56645+
56646+int gr_check_secure_terminal(struct task_struct *task)
56647+{
56648+ struct task_struct *p, *p2, *p3;
56649+ struct files_struct *files;
56650+ struct fdtable *fdt;
56651+ struct file *our_file = NULL, *file;
56652+ int i;
56653+
56654+ if (task->signal->tty == NULL)
56655+ return 1;
56656+
56657+ files = get_files_struct(task);
56658+ if (files != NULL) {
56659+ rcu_read_lock();
56660+ fdt = files_fdtable(files);
56661+ for (i=0; i < fdt->max_fds; i++) {
56662+ file = fcheck_files(files, i);
56663+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
56664+ get_file(file);
56665+ our_file = file;
56666+ }
56667+ }
56668+ rcu_read_unlock();
56669+ put_files_struct(files);
56670+ }
56671+
56672+ if (our_file == NULL)
56673+ return 1;
56674+
56675+ read_lock(&tasklist_lock);
56676+ do_each_thread(p2, p) {
56677+ files = get_files_struct(p);
56678+ if (files == NULL ||
56679+ (p->signal && p->signal->tty == task->signal->tty)) {
56680+ if (files != NULL)
56681+ put_files_struct(files);
56682+ continue;
56683+ }
56684+ rcu_read_lock();
56685+ fdt = files_fdtable(files);
56686+ for (i=0; i < fdt->max_fds; i++) {
56687+ file = fcheck_files(files, i);
56688+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
56689+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
56690+ p3 = task;
56691+ while (p3->pid > 0) {
56692+ if (p3 == p)
56693+ break;
56694+ p3 = p3->real_parent;
56695+ }
56696+ if (p3 == p)
56697+ break;
56698+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
56699+ gr_handle_alertkill(p);
56700+ rcu_read_unlock();
56701+ put_files_struct(files);
56702+ read_unlock(&tasklist_lock);
56703+ fput(our_file);
56704+ return 0;
56705+ }
56706+ }
56707+ rcu_read_unlock();
56708+ put_files_struct(files);
56709+ } while_each_thread(p2, p);
56710+ read_unlock(&tasklist_lock);
56711+
56712+ fput(our_file);
56713+ return 1;
56714+}
56715+
56716+static int gr_rbac_disable(void *unused)
56717+{
56718+ pax_open_kernel();
56719+ gr_status &= ~GR_READY;
56720+ pax_close_kernel();
56721+
56722+ return 0;
56723+}
56724+
56725+ssize_t
56726+write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
56727+{
56728+ struct gr_arg_wrapper uwrap;
56729+ unsigned char *sprole_salt = NULL;
56730+ unsigned char *sprole_sum = NULL;
56731+ int error = sizeof (struct gr_arg_wrapper);
56732+ int error2 = 0;
56733+
56734+ mutex_lock(&gr_dev_mutex);
56735+
56736+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
56737+ error = -EPERM;
56738+ goto out;
56739+ }
56740+
56741+ if (count != sizeof (struct gr_arg_wrapper)) {
56742+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
56743+ error = -EINVAL;
56744+ goto out;
56745+ }
56746+
56747+
56748+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
56749+ gr_auth_expires = 0;
56750+ gr_auth_attempts = 0;
56751+ }
56752+
56753+ if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
56754+ error = -EFAULT;
56755+ goto out;
56756+ }
56757+
56758+ if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
56759+ error = -EINVAL;
56760+ goto out;
56761+ }
56762+
56763+ if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
56764+ error = -EFAULT;
56765+ goto out;
56766+ }
56767+
56768+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
56769+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
56770+ time_after(gr_auth_expires, get_seconds())) {
56771+ error = -EBUSY;
56772+ goto out;
56773+ }
56774+
56775+ /* if non-root trying to do anything other than use a special role,
56776+ do not attempt authentication, do not count towards authentication
56777+ locking
56778+ */
56779+
56780+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
56781+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
56782+ !uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
56783+ error = -EPERM;
56784+ goto out;
56785+ }
56786+
56787+ /* ensure pw and special role name are null terminated */
56788+
56789+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
56790+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
56791+
56792+ /* Okay.
56793+ * We have our enough of the argument structure..(we have yet
56794+ * to copy_from_user the tables themselves) . Copy the tables
56795+ * only if we need them, i.e. for loading operations. */
56796+
56797+ switch (gr_usermode->mode) {
56798+ case GR_STATUS:
56799+ if (gr_status & GR_READY) {
56800+ error = 1;
56801+ if (!gr_check_secure_terminal(current))
56802+ error = 3;
56803+ } else
56804+ error = 2;
56805+ goto out;
56806+ case GR_SHUTDOWN:
56807+ if ((gr_status & GR_READY)
56808+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
56809+ stop_machine(gr_rbac_disable, NULL, NULL);
56810+ free_variables();
56811+ memset(gr_usermode, 0, sizeof (struct gr_arg));
56812+ memset(gr_system_salt, 0, GR_SALT_LEN);
56813+ memset(gr_system_sum, 0, GR_SHA_LEN);
56814+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
56815+ } else if (gr_status & GR_READY) {
56816+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
56817+ error = -EPERM;
56818+ } else {
56819+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
56820+ error = -EAGAIN;
56821+ }
56822+ break;
56823+ case GR_ENABLE:
56824+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
56825+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
56826+ else {
56827+ if (gr_status & GR_READY)
56828+ error = -EAGAIN;
56829+ else
56830+ error = error2;
56831+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
56832+ }
56833+ break;
56834+ case GR_RELOAD:
56835+ if (!(gr_status & GR_READY)) {
56836+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
56837+ error = -EAGAIN;
56838+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
56839+ stop_machine(gr_rbac_disable, NULL, NULL);
56840+ free_variables();
56841+ error2 = gracl_init(gr_usermode);
56842+ if (!error2)
56843+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
56844+ else {
56845+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
56846+ error = error2;
56847+ }
56848+ } else {
56849+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
56850+ error = -EPERM;
56851+ }
56852+ break;
56853+ case GR_SEGVMOD:
56854+ if (unlikely(!(gr_status & GR_READY))) {
56855+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
56856+ error = -EAGAIN;
56857+ break;
56858+ }
56859+
56860+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
56861+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
56862+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
56863+ struct acl_subject_label *segvacl;
56864+ segvacl =
56865+ lookup_acl_subj_label(gr_usermode->segv_inode,
56866+ gr_usermode->segv_device,
56867+ current->role);
56868+ if (segvacl) {
56869+ segvacl->crashes = 0;
56870+ segvacl->expires = 0;
56871+ }
56872+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
56873+ gr_remove_uid(gr_usermode->segv_uid);
56874+ }
56875+ } else {
56876+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
56877+ error = -EPERM;
56878+ }
56879+ break;
56880+ case GR_SPROLE:
56881+ case GR_SPROLEPAM:
56882+ if (unlikely(!(gr_status & GR_READY))) {
56883+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
56884+ error = -EAGAIN;
56885+ break;
56886+ }
56887+
56888+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
56889+ current->role->expires = 0;
56890+ current->role->auth_attempts = 0;
56891+ }
56892+
56893+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
56894+ time_after(current->role->expires, get_seconds())) {
56895+ error = -EBUSY;
56896+ goto out;
56897+ }
56898+
56899+ if (lookup_special_role_auth
56900+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
56901+ && ((!sprole_salt && !sprole_sum)
56902+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
56903+ char *p = "";
56904+ assign_special_role(gr_usermode->sp_role);
56905+ read_lock(&tasklist_lock);
56906+ if (current->real_parent)
56907+ p = current->real_parent->role->rolename;
56908+ read_unlock(&tasklist_lock);
56909+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
56910+ p, acl_sp_role_value);
56911+ } else {
56912+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
56913+ error = -EPERM;
56914+ if(!(current->role->auth_attempts++))
56915+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
56916+
56917+ goto out;
56918+ }
56919+ break;
56920+ case GR_UNSPROLE:
56921+ if (unlikely(!(gr_status & GR_READY))) {
56922+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
56923+ error = -EAGAIN;
56924+ break;
56925+ }
56926+
56927+ if (current->role->roletype & GR_ROLE_SPECIAL) {
56928+ char *p = "";
56929+ int i = 0;
56930+
56931+ read_lock(&tasklist_lock);
56932+ if (current->real_parent) {
56933+ p = current->real_parent->role->rolename;
56934+ i = current->real_parent->acl_role_id;
56935+ }
56936+ read_unlock(&tasklist_lock);
56937+
56938+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
56939+ gr_set_acls(1);
56940+ } else {
56941+ error = -EPERM;
56942+ goto out;
56943+ }
56944+ break;
56945+ default:
56946+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
56947+ error = -EINVAL;
56948+ break;
56949+ }
56950+
56951+ if (error != -EPERM)
56952+ goto out;
56953+
56954+ if(!(gr_auth_attempts++))
56955+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
56956+
56957+ out:
56958+ mutex_unlock(&gr_dev_mutex);
56959+ return error;
56960+}
56961+
56962+/* must be called with
56963+ rcu_read_lock();
56964+ read_lock(&tasklist_lock);
56965+ read_lock(&grsec_exec_file_lock);
56966+*/
56967+int gr_apply_subject_to_task(struct task_struct *task)
56968+{
56969+ struct acl_object_label *obj;
56970+ char *tmpname;
56971+ struct acl_subject_label *tmpsubj;
56972+ struct file *filp;
56973+ struct name_entry *nmatch;
56974+
56975+ filp = task->exec_file;
56976+ if (filp == NULL)
56977+ return 0;
56978+
56979+ /* the following is to apply the correct subject
56980+ on binaries running when the RBAC system
56981+ is enabled, when the binaries have been
56982+ replaced or deleted since their execution
56983+ -----
56984+ when the RBAC system starts, the inode/dev
56985+ from exec_file will be one the RBAC system
56986+ is unaware of. It only knows the inode/dev
56987+ of the present file on disk, or the absence
56988+ of it.
56989+ */
56990+ preempt_disable();
56991+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
56992+
56993+ nmatch = lookup_name_entry(tmpname);
56994+ preempt_enable();
56995+ tmpsubj = NULL;
56996+ if (nmatch) {
56997+ if (nmatch->deleted)
56998+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
56999+ else
57000+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
57001+ if (tmpsubj != NULL)
57002+ task->acl = tmpsubj;
57003+ }
57004+ if (tmpsubj == NULL)
57005+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
57006+ task->role);
57007+ if (task->acl) {
57008+ task->is_writable = 0;
57009+ /* ignore additional mmap checks for processes that are writable
57010+ by the default ACL */
57011+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
57012+ if (unlikely(obj->mode & GR_WRITE))
57013+ task->is_writable = 1;
57014+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
57015+ if (unlikely(obj->mode & GR_WRITE))
57016+ task->is_writable = 1;
57017+
57018+ gr_set_proc_res(task);
57019+
57020+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
57021+ printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
57022+#endif
57023+ } else {
57024+ return 1;
57025+ }
57026+
57027+ return 0;
57028+}
57029+
57030+int
57031+gr_set_acls(const int type)
57032+{
57033+ struct task_struct *task, *task2;
57034+ struct acl_role_label *role = current->role;
57035+ __u16 acl_role_id = current->acl_role_id;
57036+ const struct cred *cred;
57037+ int ret;
57038+
57039+ rcu_read_lock();
57040+ read_lock(&tasklist_lock);
57041+ read_lock(&grsec_exec_file_lock);
57042+ do_each_thread(task2, task) {
57043+ /* check to see if we're called from the exit handler,
57044+ if so, only replace ACLs that have inherited the admin
57045+ ACL */
57046+
57047+ if (type && (task->role != role ||
57048+ task->acl_role_id != acl_role_id))
57049+ continue;
57050+
57051+ task->acl_role_id = 0;
57052+ task->acl_sp_role = 0;
57053+
57054+ if (task->exec_file) {
57055+ cred = __task_cred(task);
57056+ task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
57057+ ret = gr_apply_subject_to_task(task);
57058+ if (ret) {
57059+ read_unlock(&grsec_exec_file_lock);
57060+ read_unlock(&tasklist_lock);
57061+ rcu_read_unlock();
57062+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
57063+ return ret;
57064+ }
57065+ } else {
57066+ // it's a kernel process
57067+ task->role = kernel_role;
57068+ task->acl = kernel_role->root_label;
57069+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
57070+ task->acl->mode &= ~GR_PROCFIND;
57071+#endif
57072+ }
57073+ } while_each_thread(task2, task);
57074+ read_unlock(&grsec_exec_file_lock);
57075+ read_unlock(&tasklist_lock);
57076+ rcu_read_unlock();
57077+
57078+ return 0;
57079+}
57080+
57081+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
57082+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
57083+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
57084+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
57085+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
57086+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
57087+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
57088+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
57089+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
57090+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
57091+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
57092+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
57093+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
57094+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
57095+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
57096+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
57097+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
57098+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
57099+};
57100+
57101+void
57102+gr_learn_resource(const struct task_struct *task,
57103+ const int res, const unsigned long wanted, const int gt)
57104+{
57105+ struct acl_subject_label *acl;
57106+ const struct cred *cred;
57107+
57108+ if (unlikely((gr_status & GR_READY) &&
57109+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
57110+ goto skip_reslog;
57111+
57112+ gr_log_resource(task, res, wanted, gt);
57113+skip_reslog:
57114+
57115+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
57116+ return;
57117+
57118+ acl = task->acl;
57119+
57120+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
57121+ !(acl->resmask & (1 << (unsigned short) res))))
57122+ return;
57123+
57124+ if (wanted >= acl->res[res].rlim_cur) {
57125+ unsigned long res_add;
57126+
57127+ res_add = wanted + res_learn_bumps[res];
57128+
57129+ acl->res[res].rlim_cur = res_add;
57130+
57131+ if (wanted > acl->res[res].rlim_max)
57132+ acl->res[res].rlim_max = res_add;
57133+
57134+ /* only log the subject filename, since resource logging is supported for
57135+ single-subject learning only */
57136+ rcu_read_lock();
57137+ cred = __task_cred(task);
57138+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
57139+ task->role->roletype, cred->uid, cred->gid, acl->filename,
57140+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
57141+ "", (unsigned long) res, &task->signal->saved_ip);
57142+ rcu_read_unlock();
57143+ }
57144+
57145+ return;
57146+}
57147+EXPORT_SYMBOL(gr_learn_resource);
57148+#endif
57149+
57150+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
57151+void
57152+pax_set_initial_flags(struct linux_binprm *bprm)
57153+{
57154+ struct task_struct *task = current;
57155+ struct acl_subject_label *proc;
57156+ unsigned long flags;
57157+
57158+ if (unlikely(!(gr_status & GR_READY)))
57159+ return;
57160+
57161+ flags = pax_get_flags(task);
57162+
57163+ proc = task->acl;
57164+
57165+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
57166+ flags &= ~MF_PAX_PAGEEXEC;
57167+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
57168+ flags &= ~MF_PAX_SEGMEXEC;
57169+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
57170+ flags &= ~MF_PAX_RANDMMAP;
57171+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
57172+ flags &= ~MF_PAX_EMUTRAMP;
57173+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
57174+ flags &= ~MF_PAX_MPROTECT;
57175+
57176+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
57177+ flags |= MF_PAX_PAGEEXEC;
57178+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
57179+ flags |= MF_PAX_SEGMEXEC;
57180+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
57181+ flags |= MF_PAX_RANDMMAP;
57182+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
57183+ flags |= MF_PAX_EMUTRAMP;
57184+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
57185+ flags |= MF_PAX_MPROTECT;
57186+
57187+ pax_set_flags(task, flags);
57188+
57189+ return;
57190+}
57191+#endif
57192+
57193+int
57194+gr_handle_proc_ptrace(struct task_struct *task)
57195+{
57196+ struct file *filp;
57197+ struct task_struct *tmp = task;
57198+ struct task_struct *curtemp = current;
57199+ __u32 retmode;
57200+
57201+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
57202+ if (unlikely(!(gr_status & GR_READY)))
57203+ return 0;
57204+#endif
57205+
57206+ read_lock(&tasklist_lock);
57207+ read_lock(&grsec_exec_file_lock);
57208+ filp = task->exec_file;
57209+
57210+ while (tmp->pid > 0) {
57211+ if (tmp == curtemp)
57212+ break;
57213+ tmp = tmp->real_parent;
57214+ }
57215+
57216+ if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
57217+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
57218+ read_unlock(&grsec_exec_file_lock);
57219+ read_unlock(&tasklist_lock);
57220+ return 1;
57221+ }
57222+
57223+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
57224+ if (!(gr_status & GR_READY)) {
57225+ read_unlock(&grsec_exec_file_lock);
57226+ read_unlock(&tasklist_lock);
57227+ return 0;
57228+ }
57229+#endif
57230+
57231+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
57232+ read_unlock(&grsec_exec_file_lock);
57233+ read_unlock(&tasklist_lock);
57234+
57235+ if (retmode & GR_NOPTRACE)
57236+ return 1;
57237+
57238+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
57239+ && (current->acl != task->acl || (current->acl != current->role->root_label
57240+ && current->pid != task->pid)))
57241+ return 1;
57242+
57243+ return 0;
57244+}
57245+
57246+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
57247+{
57248+ if (unlikely(!(gr_status & GR_READY)))
57249+ return;
57250+
57251+ if (!(current->role->roletype & GR_ROLE_GOD))
57252+ return;
57253+
57254+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
57255+ p->role->rolename, gr_task_roletype_to_char(p),
57256+ p->acl->filename);
57257+}
57258+
57259+int
57260+gr_handle_ptrace(struct task_struct *task, const long request)
57261+{
57262+ struct task_struct *tmp = task;
57263+ struct task_struct *curtemp = current;
57264+ __u32 retmode;
57265+
57266+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
57267+ if (unlikely(!(gr_status & GR_READY)))
57268+ return 0;
57269+#endif
57270+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
57271+ read_lock(&tasklist_lock);
57272+ while (tmp->pid > 0) {
57273+ if (tmp == curtemp)
57274+ break;
57275+ tmp = tmp->real_parent;
57276+ }
57277+
57278+ if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
57279+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
57280+ read_unlock(&tasklist_lock);
57281+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
57282+ return 1;
57283+ }
57284+ read_unlock(&tasklist_lock);
57285+ }
57286+
57287+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
57288+ if (!(gr_status & GR_READY))
57289+ return 0;
57290+#endif
57291+
57292+ read_lock(&grsec_exec_file_lock);
57293+ if (unlikely(!task->exec_file)) {
57294+ read_unlock(&grsec_exec_file_lock);
57295+ return 0;
57296+ }
57297+
57298+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
57299+ read_unlock(&grsec_exec_file_lock);
57300+
57301+ if (retmode & GR_NOPTRACE) {
57302+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
57303+ return 1;
57304+ }
57305+
57306+ if (retmode & GR_PTRACERD) {
57307+ switch (request) {
57308+ case PTRACE_SEIZE:
57309+ case PTRACE_POKETEXT:
57310+ case PTRACE_POKEDATA:
57311+ case PTRACE_POKEUSR:
57312+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
57313+ case PTRACE_SETREGS:
57314+ case PTRACE_SETFPREGS:
57315+#endif
57316+#ifdef CONFIG_X86
57317+ case PTRACE_SETFPXREGS:
57318+#endif
57319+#ifdef CONFIG_ALTIVEC
57320+ case PTRACE_SETVRREGS:
57321+#endif
57322+ return 1;
57323+ default:
57324+ return 0;
57325+ }
57326+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
57327+ !(current->role->roletype & GR_ROLE_GOD) &&
57328+ (current->acl != task->acl)) {
57329+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
57330+ return 1;
57331+ }
57332+
57333+ return 0;
57334+}
57335+
57336+static int is_writable_mmap(const struct file *filp)
57337+{
57338+ struct task_struct *task = current;
57339+ struct acl_object_label *obj, *obj2;
57340+
57341+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
57342+ !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))) {
57343+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
57344+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
57345+ task->role->root_label);
57346+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
57347+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
57348+ return 1;
57349+ }
57350+ }
57351+ return 0;
57352+}
57353+
57354+int
57355+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
57356+{
57357+ __u32 mode;
57358+
57359+ if (unlikely(!file || !(prot & PROT_EXEC)))
57360+ return 1;
57361+
57362+ if (is_writable_mmap(file))
57363+ return 0;
57364+
57365+ mode =
57366+ gr_search_file(file->f_path.dentry,
57367+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
57368+ file->f_path.mnt);
57369+
57370+ if (!gr_tpe_allow(file))
57371+ return 0;
57372+
57373+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
57374+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
57375+ return 0;
57376+ } else if (unlikely(!(mode & GR_EXEC))) {
57377+ return 0;
57378+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
57379+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
57380+ return 1;
57381+ }
57382+
57383+ return 1;
57384+}
57385+
57386+int
57387+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
57388+{
57389+ __u32 mode;
57390+
57391+ if (unlikely(!file || !(prot & PROT_EXEC)))
57392+ return 1;
57393+
57394+ if (is_writable_mmap(file))
57395+ return 0;
57396+
57397+ mode =
57398+ gr_search_file(file->f_path.dentry,
57399+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
57400+ file->f_path.mnt);
57401+
57402+ if (!gr_tpe_allow(file))
57403+ return 0;
57404+
57405+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
57406+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
57407+ return 0;
57408+ } else if (unlikely(!(mode & GR_EXEC))) {
57409+ return 0;
57410+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
57411+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
57412+ return 1;
57413+ }
57414+
57415+ return 1;
57416+}
57417+
57418+void
57419+gr_acl_handle_psacct(struct task_struct *task, const long code)
57420+{
57421+ unsigned long runtime;
57422+ unsigned long cputime;
57423+ unsigned int wday, cday;
57424+ __u8 whr, chr;
57425+ __u8 wmin, cmin;
57426+ __u8 wsec, csec;
57427+ struct timespec timeval;
57428+
57429+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
57430+ !(task->acl->mode & GR_PROCACCT)))
57431+ return;
57432+
57433+ do_posix_clock_monotonic_gettime(&timeval);
57434+ runtime = timeval.tv_sec - task->start_time.tv_sec;
57435+ wday = runtime / (3600 * 24);
57436+ runtime -= wday * (3600 * 24);
57437+ whr = runtime / 3600;
57438+ runtime -= whr * 3600;
57439+ wmin = runtime / 60;
57440+ runtime -= wmin * 60;
57441+ wsec = runtime;
57442+
57443+ cputime = (task->utime + task->stime) / HZ;
57444+ cday = cputime / (3600 * 24);
57445+ cputime -= cday * (3600 * 24);
57446+ chr = cputime / 3600;
57447+ cputime -= chr * 3600;
57448+ cmin = cputime / 60;
57449+ cputime -= cmin * 60;
57450+ csec = cputime;
57451+
57452+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
57453+
57454+ return;
57455+}
57456+
57457+void gr_set_kernel_label(struct task_struct *task)
57458+{
57459+ if (gr_status & GR_READY) {
57460+ task->role = kernel_role;
57461+ task->acl = kernel_role->root_label;
57462+ }
57463+ return;
57464+}
57465+
57466+#ifdef CONFIG_TASKSTATS
57467+int gr_is_taskstats_denied(int pid)
57468+{
57469+ struct task_struct *task;
57470+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
57471+ const struct cred *cred;
57472+#endif
57473+ int ret = 0;
57474+
57475+ /* restrict taskstats viewing to un-chrooted root users
57476+ who have the 'view' subject flag if the RBAC system is enabled
57477+ */
57478+
57479+ rcu_read_lock();
57480+ read_lock(&tasklist_lock);
57481+ task = find_task_by_vpid(pid);
57482+ if (task) {
57483+#ifdef CONFIG_GRKERNSEC_CHROOT
57484+ if (proc_is_chrooted(task))
57485+ ret = -EACCES;
57486+#endif
57487+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
57488+ cred = __task_cred(task);
57489+#ifdef CONFIG_GRKERNSEC_PROC_USER
57490+ if (!uid_eq(cred->uid, GLOBAL_ROOT_UID))
57491+ ret = -EACCES;
57492+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
57493+ if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && !groups_search(cred->group_info, grsec_proc_gid))
57494+ ret = -EACCES;
57495+#endif
57496+#endif
57497+ if (gr_status & GR_READY) {
57498+ if (!(task->acl->mode & GR_VIEW))
57499+ ret = -EACCES;
57500+ }
57501+ } else
57502+ ret = -ENOENT;
57503+
57504+ read_unlock(&tasklist_lock);
57505+ rcu_read_unlock();
57506+
57507+ return ret;
57508+}
57509+#endif
57510+
57511+/* AUXV entries are filled via a descendant of search_binary_handler
57512+ after we've already applied the subject for the target
57513+*/
57514+int gr_acl_enable_at_secure(void)
57515+{
57516+ if (unlikely(!(gr_status & GR_READY)))
57517+ return 0;
57518+
57519+ if (current->acl->mode & GR_ATSECURE)
57520+ return 1;
57521+
57522+ return 0;
57523+}
57524+
57525+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
57526+{
57527+ struct task_struct *task = current;
57528+ struct dentry *dentry = file->f_path.dentry;
57529+ struct vfsmount *mnt = file->f_path.mnt;
57530+ struct acl_object_label *obj, *tmp;
57531+ struct acl_subject_label *subj;
57532+ unsigned int bufsize;
57533+ int is_not_root;
57534+ char *path;
57535+ dev_t dev = __get_dev(dentry);
57536+
57537+ if (unlikely(!(gr_status & GR_READY)))
57538+ return 1;
57539+
57540+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
57541+ return 1;
57542+
57543+ /* ignore Eric Biederman */
57544+ if (IS_PRIVATE(dentry->d_inode))
57545+ return 1;
57546+
57547+ subj = task->acl;
57548+ read_lock(&gr_inode_lock);
57549+ do {
57550+ obj = lookup_acl_obj_label(ino, dev, subj);
57551+ if (obj != NULL) {
57552+ read_unlock(&gr_inode_lock);
57553+ return (obj->mode & GR_FIND) ? 1 : 0;
57554+ }
57555+ } while ((subj = subj->parent_subject));
57556+ read_unlock(&gr_inode_lock);
57557+
57558+ /* this is purely an optimization since we're looking for an object
57559+ for the directory we're doing a readdir on
57560+ if it's possible for any globbed object to match the entry we're
57561+ filling into the directory, then the object we find here will be
57562+ an anchor point with attached globbed objects
57563+ */
57564+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
57565+ if (obj->globbed == NULL)
57566+ return (obj->mode & GR_FIND) ? 1 : 0;
57567+
57568+ is_not_root = ((obj->filename[0] == '/') &&
57569+ (obj->filename[1] == '\0')) ? 0 : 1;
57570+ bufsize = PAGE_SIZE - namelen - is_not_root;
57571+
57572+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
57573+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
57574+ return 1;
57575+
57576+ preempt_disable();
57577+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
57578+ bufsize);
57579+
57580+ bufsize = strlen(path);
57581+
57582+ /* if base is "/", don't append an additional slash */
57583+ if (is_not_root)
57584+ *(path + bufsize) = '/';
57585+ memcpy(path + bufsize + is_not_root, name, namelen);
57586+ *(path + bufsize + namelen + is_not_root) = '\0';
57587+
57588+ tmp = obj->globbed;
57589+ while (tmp) {
57590+ if (!glob_match(tmp->filename, path)) {
57591+ preempt_enable();
57592+ return (tmp->mode & GR_FIND) ? 1 : 0;
57593+ }
57594+ tmp = tmp->next;
57595+ }
57596+ preempt_enable();
57597+ return (obj->mode & GR_FIND) ? 1 : 0;
57598+}
57599+
57600+void gr_put_exec_file(struct task_struct *task)
57601+{
57602+ struct file *filp;
57603+
57604+ write_lock(&grsec_exec_file_lock);
57605+ filp = task->exec_file;
57606+ task->exec_file = NULL;
57607+ write_unlock(&grsec_exec_file_lock);
57608+
57609+ if (filp)
57610+ fput(filp);
57611+
57612+ return;
57613+}
57614+
57615+
57616+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
57617+EXPORT_SYMBOL(gr_acl_is_enabled);
57618+#endif
57619+EXPORT_SYMBOL(gr_set_kernel_label);
57620+#ifdef CONFIG_SECURITY
57621+EXPORT_SYMBOL(gr_check_user_change);
57622+EXPORT_SYMBOL(gr_check_group_change);
57623+#endif
57624+
57625diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
57626new file mode 100644
57627index 0000000..34fefda
57628--- /dev/null
57629+++ b/grsecurity/gracl_alloc.c
57630@@ -0,0 +1,105 @@
57631+#include <linux/kernel.h>
57632+#include <linux/mm.h>
57633+#include <linux/slab.h>
57634+#include <linux/vmalloc.h>
57635+#include <linux/gracl.h>
57636+#include <linux/grsecurity.h>
57637+
57638+static unsigned long alloc_stack_next = 1;
57639+static unsigned long alloc_stack_size = 1;
57640+static void **alloc_stack;
57641+
57642+static __inline__ int
57643+alloc_pop(void)
57644+{
57645+ if (alloc_stack_next == 1)
57646+ return 0;
57647+
57648+ kfree(alloc_stack[alloc_stack_next - 2]);
57649+
57650+ alloc_stack_next--;
57651+
57652+ return 1;
57653+}
57654+
57655+static __inline__ int
57656+alloc_push(void *buf)
57657+{
57658+ if (alloc_stack_next >= alloc_stack_size)
57659+ return 1;
57660+
57661+ alloc_stack[alloc_stack_next - 1] = buf;
57662+
57663+ alloc_stack_next++;
57664+
57665+ return 0;
57666+}
57667+
57668+void *
57669+acl_alloc(unsigned long len)
57670+{
57671+ void *ret = NULL;
57672+
57673+ if (!len || len > PAGE_SIZE)
57674+ goto out;
57675+
57676+ ret = kmalloc(len, GFP_KERNEL);
57677+
57678+ if (ret) {
57679+ if (alloc_push(ret)) {
57680+ kfree(ret);
57681+ ret = NULL;
57682+ }
57683+ }
57684+
57685+out:
57686+ return ret;
57687+}
57688+
57689+void *
57690+acl_alloc_num(unsigned long num, unsigned long len)
57691+{
57692+ if (!len || (num > (PAGE_SIZE / len)))
57693+ return NULL;
57694+
57695+ return acl_alloc(num * len);
57696+}
57697+
57698+void
57699+acl_free_all(void)
57700+{
57701+ if (gr_acl_is_enabled() || !alloc_stack)
57702+ return;
57703+
57704+ while (alloc_pop()) ;
57705+
57706+ if (alloc_stack) {
57707+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
57708+ kfree(alloc_stack);
57709+ else
57710+ vfree(alloc_stack);
57711+ }
57712+
57713+ alloc_stack = NULL;
57714+ alloc_stack_size = 1;
57715+ alloc_stack_next = 1;
57716+
57717+ return;
57718+}
57719+
57720+int
57721+acl_alloc_stack_init(unsigned long size)
57722+{
57723+ if ((size * sizeof (void *)) <= PAGE_SIZE)
57724+ alloc_stack =
57725+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
57726+ else
57727+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
57728+
57729+ alloc_stack_size = size;
57730+
57731+ if (!alloc_stack)
57732+ return 0;
57733+ else
57734+ return 1;
57735+}
57736diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
57737new file mode 100644
57738index 0000000..6d21049
57739--- /dev/null
57740+++ b/grsecurity/gracl_cap.c
57741@@ -0,0 +1,110 @@
57742+#include <linux/kernel.h>
57743+#include <linux/module.h>
57744+#include <linux/sched.h>
57745+#include <linux/gracl.h>
57746+#include <linux/grsecurity.h>
57747+#include <linux/grinternal.h>
57748+
57749+extern const char *captab_log[];
57750+extern int captab_log_entries;
57751+
57752+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
57753+{
57754+ struct acl_subject_label *curracl;
57755+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
57756+ kernel_cap_t cap_audit = __cap_empty_set;
57757+
57758+ if (!gr_acl_is_enabled())
57759+ return 1;
57760+
57761+ curracl = task->acl;
57762+
57763+ cap_drop = curracl->cap_lower;
57764+ cap_mask = curracl->cap_mask;
57765+ cap_audit = curracl->cap_invert_audit;
57766+
57767+ while ((curracl = curracl->parent_subject)) {
57768+ /* if the cap isn't specified in the current computed mask but is specified in the
57769+ current level subject, and is lowered in the current level subject, then add
57770+ it to the set of dropped capabilities
57771+ otherwise, add the current level subject's mask to the current computed mask
57772+ */
57773+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
57774+ cap_raise(cap_mask, cap);
57775+ if (cap_raised(curracl->cap_lower, cap))
57776+ cap_raise(cap_drop, cap);
57777+ if (cap_raised(curracl->cap_invert_audit, cap))
57778+ cap_raise(cap_audit, cap);
57779+ }
57780+ }
57781+
57782+ if (!cap_raised(cap_drop, cap)) {
57783+ if (cap_raised(cap_audit, cap))
57784+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
57785+ return 1;
57786+ }
57787+
57788+ curracl = task->acl;
57789+
57790+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
57791+ && cap_raised(cred->cap_effective, cap)) {
57792+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
57793+ task->role->roletype, cred->uid,
57794+ cred->gid, task->exec_file ?
57795+ gr_to_filename(task->exec_file->f_path.dentry,
57796+ task->exec_file->f_path.mnt) : curracl->filename,
57797+ curracl->filename, 0UL,
57798+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
57799+ return 1;
57800+ }
57801+
57802+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
57803+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
57804+
57805+ return 0;
57806+}
57807+
57808+int
57809+gr_acl_is_capable(const int cap)
57810+{
57811+ return gr_task_acl_is_capable(current, current_cred(), cap);
57812+}
57813+
57814+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
57815+{
57816+ struct acl_subject_label *curracl;
57817+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
57818+
57819+ if (!gr_acl_is_enabled())
57820+ return 1;
57821+
57822+ curracl = task->acl;
57823+
57824+ cap_drop = curracl->cap_lower;
57825+ cap_mask = curracl->cap_mask;
57826+
57827+ while ((curracl = curracl->parent_subject)) {
57828+ /* if the cap isn't specified in the current computed mask but is specified in the
57829+ current level subject, and is lowered in the current level subject, then add
57830+ it to the set of dropped capabilities
57831+ otherwise, add the current level subject's mask to the current computed mask
57832+ */
57833+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
57834+ cap_raise(cap_mask, cap);
57835+ if (cap_raised(curracl->cap_lower, cap))
57836+ cap_raise(cap_drop, cap);
57837+ }
57838+ }
57839+
57840+ if (!cap_raised(cap_drop, cap))
57841+ return 1;
57842+
57843+ return 0;
57844+}
57845+
57846+int
57847+gr_acl_is_capable_nolog(const int cap)
57848+{
57849+ return gr_task_acl_is_capable_nolog(current, cap);
57850+}
57851+
57852diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
57853new file mode 100644
57854index 0000000..a340c17
57855--- /dev/null
57856+++ b/grsecurity/gracl_fs.c
57857@@ -0,0 +1,431 @@
57858+#include <linux/kernel.h>
57859+#include <linux/sched.h>
57860+#include <linux/types.h>
57861+#include <linux/fs.h>
57862+#include <linux/file.h>
57863+#include <linux/stat.h>
57864+#include <linux/grsecurity.h>
57865+#include <linux/grinternal.h>
57866+#include <linux/gracl.h>
57867+
57868+umode_t
57869+gr_acl_umask(void)
57870+{
57871+ if (unlikely(!gr_acl_is_enabled()))
57872+ return 0;
57873+
57874+ return current->role->umask;
57875+}
57876+
57877+__u32
57878+gr_acl_handle_hidden_file(const struct dentry * dentry,
57879+ const struct vfsmount * mnt)
57880+{
57881+ __u32 mode;
57882+
57883+ if (unlikely(!dentry->d_inode))
57884+ return GR_FIND;
57885+
57886+ mode =
57887+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
57888+
57889+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
57890+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
57891+ return mode;
57892+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
57893+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
57894+ return 0;
57895+ } else if (unlikely(!(mode & GR_FIND)))
57896+ return 0;
57897+
57898+ return GR_FIND;
57899+}
57900+
57901+__u32
57902+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
57903+ int acc_mode)
57904+{
57905+ __u32 reqmode = GR_FIND;
57906+ __u32 mode;
57907+
57908+ if (unlikely(!dentry->d_inode))
57909+ return reqmode;
57910+
57911+ if (acc_mode & MAY_APPEND)
57912+ reqmode |= GR_APPEND;
57913+ else if (acc_mode & MAY_WRITE)
57914+ reqmode |= GR_WRITE;
57915+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
57916+ reqmode |= GR_READ;
57917+
57918+ mode =
57919+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
57920+ mnt);
57921+
57922+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
57923+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
57924+ reqmode & GR_READ ? " reading" : "",
57925+ reqmode & GR_WRITE ? " writing" : reqmode &
57926+ GR_APPEND ? " appending" : "");
57927+ return reqmode;
57928+ } else
57929+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
57930+ {
57931+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
57932+ reqmode & GR_READ ? " reading" : "",
57933+ reqmode & GR_WRITE ? " writing" : reqmode &
57934+ GR_APPEND ? " appending" : "");
57935+ return 0;
57936+ } else if (unlikely((mode & reqmode) != reqmode))
57937+ return 0;
57938+
57939+ return reqmode;
57940+}
57941+
57942+__u32
57943+gr_acl_handle_creat(const struct dentry * dentry,
57944+ const struct dentry * p_dentry,
57945+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
57946+ const int imode)
57947+{
57948+ __u32 reqmode = GR_WRITE | GR_CREATE;
57949+ __u32 mode;
57950+
57951+ if (acc_mode & MAY_APPEND)
57952+ reqmode |= GR_APPEND;
57953+ // if a directory was required or the directory already exists, then
57954+ // don't count this open as a read
57955+ if ((acc_mode & MAY_READ) &&
57956+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
57957+ reqmode |= GR_READ;
57958+ if ((open_flags & O_CREAT) &&
57959+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
57960+ reqmode |= GR_SETID;
57961+
57962+ mode =
57963+ gr_check_create(dentry, p_dentry, p_mnt,
57964+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
57965+
57966+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
57967+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
57968+ reqmode & GR_READ ? " reading" : "",
57969+ reqmode & GR_WRITE ? " writing" : reqmode &
57970+ GR_APPEND ? " appending" : "");
57971+ return reqmode;
57972+ } else
57973+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
57974+ {
57975+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
57976+ reqmode & GR_READ ? " reading" : "",
57977+ reqmode & GR_WRITE ? " writing" : reqmode &
57978+ GR_APPEND ? " appending" : "");
57979+ return 0;
57980+ } else if (unlikely((mode & reqmode) != reqmode))
57981+ return 0;
57982+
57983+ return reqmode;
57984+}
57985+
57986+__u32
57987+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
57988+ const int fmode)
57989+{
57990+ __u32 mode, reqmode = GR_FIND;
57991+
57992+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
57993+ reqmode |= GR_EXEC;
57994+ if (fmode & S_IWOTH)
57995+ reqmode |= GR_WRITE;
57996+ if (fmode & S_IROTH)
57997+ reqmode |= GR_READ;
57998+
57999+ mode =
58000+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
58001+ mnt);
58002+
58003+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
58004+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
58005+ reqmode & GR_READ ? " reading" : "",
58006+ reqmode & GR_WRITE ? " writing" : "",
58007+ reqmode & GR_EXEC ? " executing" : "");
58008+ return reqmode;
58009+ } else
58010+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
58011+ {
58012+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
58013+ reqmode & GR_READ ? " reading" : "",
58014+ reqmode & GR_WRITE ? " writing" : "",
58015+ reqmode & GR_EXEC ? " executing" : "");
58016+ return 0;
58017+ } else if (unlikely((mode & reqmode) != reqmode))
58018+ return 0;
58019+
58020+ return reqmode;
58021+}
58022+
58023+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
58024+{
58025+ __u32 mode;
58026+
58027+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
58028+
58029+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
58030+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
58031+ return mode;
58032+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
58033+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
58034+ return 0;
58035+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
58036+ return 0;
58037+
58038+ return (reqmode);
58039+}
58040+
58041+__u32
58042+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
58043+{
58044+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
58045+}
58046+
58047+__u32
58048+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
58049+{
58050+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
58051+}
58052+
58053+__u32
58054+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
58055+{
58056+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
58057+}
58058+
58059+__u32
58060+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
58061+{
58062+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
58063+}
58064+
58065+__u32
58066+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
58067+ umode_t *modeptr)
58068+{
58069+ umode_t mode;
58070+
58071+ *modeptr &= ~gr_acl_umask();
58072+ mode = *modeptr;
58073+
58074+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
58075+ return 1;
58076+
58077+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
58078+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
58079+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
58080+ GR_CHMOD_ACL_MSG);
58081+ } else {
58082+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
58083+ }
58084+}
58085+
58086+__u32
58087+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
58088+{
58089+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
58090+}
58091+
58092+__u32
58093+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
58094+{
58095+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
58096+}
58097+
58098+__u32
58099+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
58100+{
58101+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
58102+}
58103+
58104+__u32
58105+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
58106+{
58107+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
58108+ GR_UNIXCONNECT_ACL_MSG);
58109+}
58110+
58111+/* hardlinks require at minimum create and link permission,
58112+ any additional privilege required is based on the
58113+ privilege of the file being linked to
58114+*/
58115+__u32
58116+gr_acl_handle_link(const struct dentry * new_dentry,
58117+ const struct dentry * parent_dentry,
58118+ const struct vfsmount * parent_mnt,
58119+ const struct dentry * old_dentry,
58120+ const struct vfsmount * old_mnt, const struct filename *to)
58121+{
58122+ __u32 mode;
58123+ __u32 needmode = GR_CREATE | GR_LINK;
58124+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
58125+
58126+ mode =
58127+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
58128+ old_mnt);
58129+
58130+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
58131+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
58132+ return mode;
58133+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
58134+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
58135+ return 0;
58136+ } else if (unlikely((mode & needmode) != needmode))
58137+ return 0;
58138+
58139+ return 1;
58140+}
58141+
58142+__u32
58143+gr_acl_handle_symlink(const struct dentry * new_dentry,
58144+ const struct dentry * parent_dentry,
58145+ const struct vfsmount * parent_mnt, const struct filename *from)
58146+{
58147+ __u32 needmode = GR_WRITE | GR_CREATE;
58148+ __u32 mode;
58149+
58150+ mode =
58151+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
58152+ GR_CREATE | GR_AUDIT_CREATE |
58153+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
58154+
58155+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
58156+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
58157+ return mode;
58158+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
58159+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
58160+ return 0;
58161+ } else if (unlikely((mode & needmode) != needmode))
58162+ return 0;
58163+
58164+ return (GR_WRITE | GR_CREATE);
58165+}
58166+
58167+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)
58168+{
58169+ __u32 mode;
58170+
58171+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
58172+
58173+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
58174+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
58175+ return mode;
58176+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
58177+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
58178+ return 0;
58179+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
58180+ return 0;
58181+
58182+ return (reqmode);
58183+}
58184+
58185+__u32
58186+gr_acl_handle_mknod(const struct dentry * new_dentry,
58187+ const struct dentry * parent_dentry,
58188+ const struct vfsmount * parent_mnt,
58189+ const int mode)
58190+{
58191+ __u32 reqmode = GR_WRITE | GR_CREATE;
58192+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
58193+ reqmode |= GR_SETID;
58194+
58195+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
58196+ reqmode, GR_MKNOD_ACL_MSG);
58197+}
58198+
58199+__u32
58200+gr_acl_handle_mkdir(const struct dentry *new_dentry,
58201+ const struct dentry *parent_dentry,
58202+ const struct vfsmount *parent_mnt)
58203+{
58204+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
58205+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
58206+}
58207+
58208+#define RENAME_CHECK_SUCCESS(old, new) \
58209+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
58210+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
58211+
58212+int
58213+gr_acl_handle_rename(struct dentry *new_dentry,
58214+ struct dentry *parent_dentry,
58215+ const struct vfsmount *parent_mnt,
58216+ struct dentry *old_dentry,
58217+ struct inode *old_parent_inode,
58218+ struct vfsmount *old_mnt, const struct filename *newname)
58219+{
58220+ __u32 comp1, comp2;
58221+ int error = 0;
58222+
58223+ if (unlikely(!gr_acl_is_enabled()))
58224+ return 0;
58225+
58226+ if (!new_dentry->d_inode) {
58227+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
58228+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
58229+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
58230+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
58231+ GR_DELETE | GR_AUDIT_DELETE |
58232+ GR_AUDIT_READ | GR_AUDIT_WRITE |
58233+ GR_SUPPRESS, old_mnt);
58234+ } else {
58235+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
58236+ GR_CREATE | GR_DELETE |
58237+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
58238+ GR_AUDIT_READ | GR_AUDIT_WRITE |
58239+ GR_SUPPRESS, parent_mnt);
58240+ comp2 =
58241+ gr_search_file(old_dentry,
58242+ GR_READ | GR_WRITE | GR_AUDIT_READ |
58243+ GR_DELETE | GR_AUDIT_DELETE |
58244+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
58245+ }
58246+
58247+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
58248+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
58249+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
58250+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
58251+ && !(comp2 & GR_SUPPRESS)) {
58252+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
58253+ error = -EACCES;
58254+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
58255+ error = -EACCES;
58256+
58257+ return error;
58258+}
58259+
58260+void
58261+gr_acl_handle_exit(void)
58262+{
58263+ u16 id;
58264+ char *rolename;
58265+
58266+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
58267+ !(current->role->roletype & GR_ROLE_PERSIST))) {
58268+ id = current->acl_role_id;
58269+ rolename = current->role->rolename;
58270+ gr_set_acls(1);
58271+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
58272+ }
58273+
58274+ gr_put_exec_file(current);
58275+ return;
58276+}
58277+
58278+int
58279+gr_acl_handle_procpidmem(const struct task_struct *task)
58280+{
58281+ if (unlikely(!gr_acl_is_enabled()))
58282+ return 0;
58283+
58284+ if (task != current && task->acl->mode & GR_PROTPROCFD)
58285+ return -EACCES;
58286+
58287+ return 0;
58288+}
58289diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
58290new file mode 100644
58291index 0000000..58800a7
58292--- /dev/null
58293+++ b/grsecurity/gracl_ip.c
58294@@ -0,0 +1,384 @@
58295+#include <linux/kernel.h>
58296+#include <asm/uaccess.h>
58297+#include <asm/errno.h>
58298+#include <net/sock.h>
58299+#include <linux/file.h>
58300+#include <linux/fs.h>
58301+#include <linux/net.h>
58302+#include <linux/in.h>
58303+#include <linux/skbuff.h>
58304+#include <linux/ip.h>
58305+#include <linux/udp.h>
58306+#include <linux/types.h>
58307+#include <linux/sched.h>
58308+#include <linux/netdevice.h>
58309+#include <linux/inetdevice.h>
58310+#include <linux/gracl.h>
58311+#include <linux/grsecurity.h>
58312+#include <linux/grinternal.h>
58313+
58314+#define GR_BIND 0x01
58315+#define GR_CONNECT 0x02
58316+#define GR_INVERT 0x04
58317+#define GR_BINDOVERRIDE 0x08
58318+#define GR_CONNECTOVERRIDE 0x10
58319+#define GR_SOCK_FAMILY 0x20
58320+
58321+static const char * gr_protocols[IPPROTO_MAX] = {
58322+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
58323+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
58324+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
58325+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
58326+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
58327+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
58328+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
58329+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
58330+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
58331+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
58332+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
58333+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
58334+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
58335+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
58336+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
58337+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
58338+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
58339+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
58340+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
58341+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
58342+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
58343+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
58344+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
58345+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
58346+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
58347+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
58348+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
58349+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
58350+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
58351+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
58352+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
58353+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
58354+ };
58355+
58356+static const char * gr_socktypes[SOCK_MAX] = {
58357+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
58358+ "unknown:7", "unknown:8", "unknown:9", "packet"
58359+ };
58360+
58361+static const char * gr_sockfamilies[AF_MAX+1] = {
58362+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
58363+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
58364+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
58365+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
58366+ };
58367+
58368+const char *
58369+gr_proto_to_name(unsigned char proto)
58370+{
58371+ return gr_protocols[proto];
58372+}
58373+
58374+const char *
58375+gr_socktype_to_name(unsigned char type)
58376+{
58377+ return gr_socktypes[type];
58378+}
58379+
58380+const char *
58381+gr_sockfamily_to_name(unsigned char family)
58382+{
58383+ return gr_sockfamilies[family];
58384+}
58385+
58386+int
58387+gr_search_socket(const int domain, const int type, const int protocol)
58388+{
58389+ struct acl_subject_label *curr;
58390+ const struct cred *cred = current_cred();
58391+
58392+ if (unlikely(!gr_acl_is_enabled()))
58393+ goto exit;
58394+
58395+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
58396+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
58397+ goto exit; // let the kernel handle it
58398+
58399+ curr = current->acl;
58400+
58401+ if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
58402+ /* the family is allowed, if this is PF_INET allow it only if
58403+ the extra sock type/protocol checks pass */
58404+ if (domain == PF_INET)
58405+ goto inet_check;
58406+ goto exit;
58407+ } else {
58408+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
58409+ __u32 fakeip = 0;
58410+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
58411+ current->role->roletype, cred->uid,
58412+ cred->gid, current->exec_file ?
58413+ gr_to_filename(current->exec_file->f_path.dentry,
58414+ current->exec_file->f_path.mnt) :
58415+ curr->filename, curr->filename,
58416+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
58417+ &current->signal->saved_ip);
58418+ goto exit;
58419+ }
58420+ goto exit_fail;
58421+ }
58422+
58423+inet_check:
58424+ /* the rest of this checking is for IPv4 only */
58425+ if (!curr->ips)
58426+ goto exit;
58427+
58428+ if ((curr->ip_type & (1 << type)) &&
58429+ (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
58430+ goto exit;
58431+
58432+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
58433+ /* we don't place acls on raw sockets , and sometimes
58434+ dgram/ip sockets are opened for ioctl and not
58435+ bind/connect, so we'll fake a bind learn log */
58436+ if (type == SOCK_RAW || type == SOCK_PACKET) {
58437+ __u32 fakeip = 0;
58438+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
58439+ current->role->roletype, cred->uid,
58440+ cred->gid, current->exec_file ?
58441+ gr_to_filename(current->exec_file->f_path.dentry,
58442+ current->exec_file->f_path.mnt) :
58443+ curr->filename, curr->filename,
58444+ &fakeip, 0, type,
58445+ protocol, GR_CONNECT, &current->signal->saved_ip);
58446+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
58447+ __u32 fakeip = 0;
58448+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
58449+ current->role->roletype, cred->uid,
58450+ cred->gid, current->exec_file ?
58451+ gr_to_filename(current->exec_file->f_path.dentry,
58452+ current->exec_file->f_path.mnt) :
58453+ curr->filename, curr->filename,
58454+ &fakeip, 0, type,
58455+ protocol, GR_BIND, &current->signal->saved_ip);
58456+ }
58457+ /* we'll log when they use connect or bind */
58458+ goto exit;
58459+ }
58460+
58461+exit_fail:
58462+ if (domain == PF_INET)
58463+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
58464+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
58465+ else
58466+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
58467+ gr_socktype_to_name(type), protocol);
58468+
58469+ return 0;
58470+exit:
58471+ return 1;
58472+}
58473+
58474+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)
58475+{
58476+ if ((ip->mode & mode) &&
58477+ (ip_port >= ip->low) &&
58478+ (ip_port <= ip->high) &&
58479+ ((ntohl(ip_addr) & our_netmask) ==
58480+ (ntohl(our_addr) & our_netmask))
58481+ && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
58482+ && (ip->type & (1 << type))) {
58483+ if (ip->mode & GR_INVERT)
58484+ return 2; // specifically denied
58485+ else
58486+ return 1; // allowed
58487+ }
58488+
58489+ return 0; // not specifically allowed, may continue parsing
58490+}
58491+
58492+static int
58493+gr_search_connectbind(const int full_mode, struct sock *sk,
58494+ struct sockaddr_in *addr, const int type)
58495+{
58496+ char iface[IFNAMSIZ] = {0};
58497+ struct acl_subject_label *curr;
58498+ struct acl_ip_label *ip;
58499+ struct inet_sock *isk;
58500+ struct net_device *dev;
58501+ struct in_device *idev;
58502+ unsigned long i;
58503+ int ret;
58504+ int mode = full_mode & (GR_BIND | GR_CONNECT);
58505+ __u32 ip_addr = 0;
58506+ __u32 our_addr;
58507+ __u32 our_netmask;
58508+ char *p;
58509+ __u16 ip_port = 0;
58510+ const struct cred *cred = current_cred();
58511+
58512+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
58513+ return 0;
58514+
58515+ curr = current->acl;
58516+ isk = inet_sk(sk);
58517+
58518+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
58519+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
58520+ addr->sin_addr.s_addr = curr->inaddr_any_override;
58521+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
58522+ struct sockaddr_in saddr;
58523+ int err;
58524+
58525+ saddr.sin_family = AF_INET;
58526+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
58527+ saddr.sin_port = isk->inet_sport;
58528+
58529+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
58530+ if (err)
58531+ return err;
58532+
58533+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
58534+ if (err)
58535+ return err;
58536+ }
58537+
58538+ if (!curr->ips)
58539+ return 0;
58540+
58541+ ip_addr = addr->sin_addr.s_addr;
58542+ ip_port = ntohs(addr->sin_port);
58543+
58544+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
58545+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
58546+ current->role->roletype, cred->uid,
58547+ cred->gid, current->exec_file ?
58548+ gr_to_filename(current->exec_file->f_path.dentry,
58549+ current->exec_file->f_path.mnt) :
58550+ curr->filename, curr->filename,
58551+ &ip_addr, ip_port, type,
58552+ sk->sk_protocol, mode, &current->signal->saved_ip);
58553+ return 0;
58554+ }
58555+
58556+ for (i = 0; i < curr->ip_num; i++) {
58557+ ip = *(curr->ips + i);
58558+ if (ip->iface != NULL) {
58559+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
58560+ p = strchr(iface, ':');
58561+ if (p != NULL)
58562+ *p = '\0';
58563+ dev = dev_get_by_name(sock_net(sk), iface);
58564+ if (dev == NULL)
58565+ continue;
58566+ idev = in_dev_get(dev);
58567+ if (idev == NULL) {
58568+ dev_put(dev);
58569+ continue;
58570+ }
58571+ rcu_read_lock();
58572+ for_ifa(idev) {
58573+ if (!strcmp(ip->iface, ifa->ifa_label)) {
58574+ our_addr = ifa->ifa_address;
58575+ our_netmask = 0xffffffff;
58576+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
58577+ if (ret == 1) {
58578+ rcu_read_unlock();
58579+ in_dev_put(idev);
58580+ dev_put(dev);
58581+ return 0;
58582+ } else if (ret == 2) {
58583+ rcu_read_unlock();
58584+ in_dev_put(idev);
58585+ dev_put(dev);
58586+ goto denied;
58587+ }
58588+ }
58589+ } endfor_ifa(idev);
58590+ rcu_read_unlock();
58591+ in_dev_put(idev);
58592+ dev_put(dev);
58593+ } else {
58594+ our_addr = ip->addr;
58595+ our_netmask = ip->netmask;
58596+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
58597+ if (ret == 1)
58598+ return 0;
58599+ else if (ret == 2)
58600+ goto denied;
58601+ }
58602+ }
58603+
58604+denied:
58605+ if (mode == GR_BIND)
58606+ 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));
58607+ else if (mode == GR_CONNECT)
58608+ 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));
58609+
58610+ return -EACCES;
58611+}
58612+
58613+int
58614+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
58615+{
58616+ /* always allow disconnection of dgram sockets with connect */
58617+ if (addr->sin_family == AF_UNSPEC)
58618+ return 0;
58619+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
58620+}
58621+
58622+int
58623+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
58624+{
58625+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
58626+}
58627+
58628+int gr_search_listen(struct socket *sock)
58629+{
58630+ struct sock *sk = sock->sk;
58631+ struct sockaddr_in addr;
58632+
58633+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
58634+ addr.sin_port = inet_sk(sk)->inet_sport;
58635+
58636+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
58637+}
58638+
58639+int gr_search_accept(struct socket *sock)
58640+{
58641+ struct sock *sk = sock->sk;
58642+ struct sockaddr_in addr;
58643+
58644+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
58645+ addr.sin_port = inet_sk(sk)->inet_sport;
58646+
58647+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
58648+}
58649+
58650+int
58651+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
58652+{
58653+ if (addr)
58654+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
58655+ else {
58656+ struct sockaddr_in sin;
58657+ const struct inet_sock *inet = inet_sk(sk);
58658+
58659+ sin.sin_addr.s_addr = inet->inet_daddr;
58660+ sin.sin_port = inet->inet_dport;
58661+
58662+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
58663+ }
58664+}
58665+
58666+int
58667+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
58668+{
58669+ struct sockaddr_in sin;
58670+
58671+ if (unlikely(skb->len < sizeof (struct udphdr)))
58672+ return 0; // skip this packet
58673+
58674+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
58675+ sin.sin_port = udp_hdr(skb)->source;
58676+
58677+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
58678+}
58679diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
58680new file mode 100644
58681index 0000000..25f54ef
58682--- /dev/null
58683+++ b/grsecurity/gracl_learn.c
58684@@ -0,0 +1,207 @@
58685+#include <linux/kernel.h>
58686+#include <linux/mm.h>
58687+#include <linux/sched.h>
58688+#include <linux/poll.h>
58689+#include <linux/string.h>
58690+#include <linux/file.h>
58691+#include <linux/types.h>
58692+#include <linux/vmalloc.h>
58693+#include <linux/grinternal.h>
58694+
58695+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
58696+ size_t count, loff_t *ppos);
58697+extern int gr_acl_is_enabled(void);
58698+
58699+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
58700+static int gr_learn_attached;
58701+
58702+/* use a 512k buffer */
58703+#define LEARN_BUFFER_SIZE (512 * 1024)
58704+
58705+static DEFINE_SPINLOCK(gr_learn_lock);
58706+static DEFINE_MUTEX(gr_learn_user_mutex);
58707+
58708+/* we need to maintain two buffers, so that the kernel context of grlearn
58709+ uses a semaphore around the userspace copying, and the other kernel contexts
58710+ use a spinlock when copying into the buffer, since they cannot sleep
58711+*/
58712+static char *learn_buffer;
58713+static char *learn_buffer_user;
58714+static int learn_buffer_len;
58715+static int learn_buffer_user_len;
58716+
58717+static ssize_t
58718+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
58719+{
58720+ DECLARE_WAITQUEUE(wait, current);
58721+ ssize_t retval = 0;
58722+
58723+ add_wait_queue(&learn_wait, &wait);
58724+ set_current_state(TASK_INTERRUPTIBLE);
58725+ do {
58726+ mutex_lock(&gr_learn_user_mutex);
58727+ spin_lock(&gr_learn_lock);
58728+ if (learn_buffer_len)
58729+ break;
58730+ spin_unlock(&gr_learn_lock);
58731+ mutex_unlock(&gr_learn_user_mutex);
58732+ if (file->f_flags & O_NONBLOCK) {
58733+ retval = -EAGAIN;
58734+ goto out;
58735+ }
58736+ if (signal_pending(current)) {
58737+ retval = -ERESTARTSYS;
58738+ goto out;
58739+ }
58740+
58741+ schedule();
58742+ } while (1);
58743+
58744+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
58745+ learn_buffer_user_len = learn_buffer_len;
58746+ retval = learn_buffer_len;
58747+ learn_buffer_len = 0;
58748+
58749+ spin_unlock(&gr_learn_lock);
58750+
58751+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
58752+ retval = -EFAULT;
58753+
58754+ mutex_unlock(&gr_learn_user_mutex);
58755+out:
58756+ set_current_state(TASK_RUNNING);
58757+ remove_wait_queue(&learn_wait, &wait);
58758+ return retval;
58759+}
58760+
58761+static unsigned int
58762+poll_learn(struct file * file, poll_table * wait)
58763+{
58764+ poll_wait(file, &learn_wait, wait);
58765+
58766+ if (learn_buffer_len)
58767+ return (POLLIN | POLLRDNORM);
58768+
58769+ return 0;
58770+}
58771+
58772+void
58773+gr_clear_learn_entries(void)
58774+{
58775+ char *tmp;
58776+
58777+ mutex_lock(&gr_learn_user_mutex);
58778+ spin_lock(&gr_learn_lock);
58779+ tmp = learn_buffer;
58780+ learn_buffer = NULL;
58781+ spin_unlock(&gr_learn_lock);
58782+ if (tmp)
58783+ vfree(tmp);
58784+ if (learn_buffer_user != NULL) {
58785+ vfree(learn_buffer_user);
58786+ learn_buffer_user = NULL;
58787+ }
58788+ learn_buffer_len = 0;
58789+ mutex_unlock(&gr_learn_user_mutex);
58790+
58791+ return;
58792+}
58793+
58794+void
58795+gr_add_learn_entry(const char *fmt, ...)
58796+{
58797+ va_list args;
58798+ unsigned int len;
58799+
58800+ if (!gr_learn_attached)
58801+ return;
58802+
58803+ spin_lock(&gr_learn_lock);
58804+
58805+ /* leave a gap at the end so we know when it's "full" but don't have to
58806+ compute the exact length of the string we're trying to append
58807+ */
58808+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
58809+ spin_unlock(&gr_learn_lock);
58810+ wake_up_interruptible(&learn_wait);
58811+ return;
58812+ }
58813+ if (learn_buffer == NULL) {
58814+ spin_unlock(&gr_learn_lock);
58815+ return;
58816+ }
58817+
58818+ va_start(args, fmt);
58819+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
58820+ va_end(args);
58821+
58822+ learn_buffer_len += len + 1;
58823+
58824+ spin_unlock(&gr_learn_lock);
58825+ wake_up_interruptible(&learn_wait);
58826+
58827+ return;
58828+}
58829+
58830+static int
58831+open_learn(struct inode *inode, struct file *file)
58832+{
58833+ if (file->f_mode & FMODE_READ && gr_learn_attached)
58834+ return -EBUSY;
58835+ if (file->f_mode & FMODE_READ) {
58836+ int retval = 0;
58837+ mutex_lock(&gr_learn_user_mutex);
58838+ if (learn_buffer == NULL)
58839+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
58840+ if (learn_buffer_user == NULL)
58841+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
58842+ if (learn_buffer == NULL) {
58843+ retval = -ENOMEM;
58844+ goto out_error;
58845+ }
58846+ if (learn_buffer_user == NULL) {
58847+ retval = -ENOMEM;
58848+ goto out_error;
58849+ }
58850+ learn_buffer_len = 0;
58851+ learn_buffer_user_len = 0;
58852+ gr_learn_attached = 1;
58853+out_error:
58854+ mutex_unlock(&gr_learn_user_mutex);
58855+ return retval;
58856+ }
58857+ return 0;
58858+}
58859+
58860+static int
58861+close_learn(struct inode *inode, struct file *file)
58862+{
58863+ if (file->f_mode & FMODE_READ) {
58864+ char *tmp = NULL;
58865+ mutex_lock(&gr_learn_user_mutex);
58866+ spin_lock(&gr_learn_lock);
58867+ tmp = learn_buffer;
58868+ learn_buffer = NULL;
58869+ spin_unlock(&gr_learn_lock);
58870+ if (tmp)
58871+ vfree(tmp);
58872+ if (learn_buffer_user != NULL) {
58873+ vfree(learn_buffer_user);
58874+ learn_buffer_user = NULL;
58875+ }
58876+ learn_buffer_len = 0;
58877+ learn_buffer_user_len = 0;
58878+ gr_learn_attached = 0;
58879+ mutex_unlock(&gr_learn_user_mutex);
58880+ }
58881+
58882+ return 0;
58883+}
58884+
58885+const struct file_operations grsec_fops = {
58886+ .read = read_learn,
58887+ .write = write_grsec_handler,
58888+ .open = open_learn,
58889+ .release = close_learn,
58890+ .poll = poll_learn,
58891+};
58892diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
58893new file mode 100644
58894index 0000000..39645c9
58895--- /dev/null
58896+++ b/grsecurity/gracl_res.c
58897@@ -0,0 +1,68 @@
58898+#include <linux/kernel.h>
58899+#include <linux/sched.h>
58900+#include <linux/gracl.h>
58901+#include <linux/grinternal.h>
58902+
58903+static const char *restab_log[] = {
58904+ [RLIMIT_CPU] = "RLIMIT_CPU",
58905+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
58906+ [RLIMIT_DATA] = "RLIMIT_DATA",
58907+ [RLIMIT_STACK] = "RLIMIT_STACK",
58908+ [RLIMIT_CORE] = "RLIMIT_CORE",
58909+ [RLIMIT_RSS] = "RLIMIT_RSS",
58910+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
58911+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
58912+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
58913+ [RLIMIT_AS] = "RLIMIT_AS",
58914+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
58915+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
58916+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
58917+ [RLIMIT_NICE] = "RLIMIT_NICE",
58918+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
58919+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
58920+ [GR_CRASH_RES] = "RLIMIT_CRASH"
58921+};
58922+
58923+void
58924+gr_log_resource(const struct task_struct *task,
58925+ const int res, const unsigned long wanted, const int gt)
58926+{
58927+ const struct cred *cred;
58928+ unsigned long rlim;
58929+
58930+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
58931+ return;
58932+
58933+ // not yet supported resource
58934+ if (unlikely(!restab_log[res]))
58935+ return;
58936+
58937+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
58938+ rlim = task_rlimit_max(task, res);
58939+ else
58940+ rlim = task_rlimit(task, res);
58941+
58942+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
58943+ return;
58944+
58945+ rcu_read_lock();
58946+ cred = __task_cred(task);
58947+
58948+ if (res == RLIMIT_NPROC &&
58949+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
58950+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
58951+ goto out_rcu_unlock;
58952+ else if (res == RLIMIT_MEMLOCK &&
58953+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
58954+ goto out_rcu_unlock;
58955+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
58956+ goto out_rcu_unlock;
58957+ rcu_read_unlock();
58958+
58959+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
58960+
58961+ return;
58962+out_rcu_unlock:
58963+ rcu_read_unlock();
58964+ return;
58965+}
58966diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
58967new file mode 100644
58968index 0000000..25197e9
58969--- /dev/null
58970+++ b/grsecurity/gracl_segv.c
58971@@ -0,0 +1,299 @@
58972+#include <linux/kernel.h>
58973+#include <linux/mm.h>
58974+#include <asm/uaccess.h>
58975+#include <asm/errno.h>
58976+#include <asm/mman.h>
58977+#include <net/sock.h>
58978+#include <linux/file.h>
58979+#include <linux/fs.h>
58980+#include <linux/net.h>
58981+#include <linux/in.h>
58982+#include <linux/slab.h>
58983+#include <linux/types.h>
58984+#include <linux/sched.h>
58985+#include <linux/timer.h>
58986+#include <linux/gracl.h>
58987+#include <linux/grsecurity.h>
58988+#include <linux/grinternal.h>
58989+
58990+static struct crash_uid *uid_set;
58991+static unsigned short uid_used;
58992+static DEFINE_SPINLOCK(gr_uid_lock);
58993+extern rwlock_t gr_inode_lock;
58994+extern struct acl_subject_label *
58995+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
58996+ struct acl_role_label *role);
58997+
58998+#ifdef CONFIG_BTRFS_FS
58999+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
59000+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
59001+#endif
59002+
59003+static inline dev_t __get_dev(const struct dentry *dentry)
59004+{
59005+#ifdef CONFIG_BTRFS_FS
59006+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
59007+ return get_btrfs_dev_from_inode(dentry->d_inode);
59008+ else
59009+#endif
59010+ return dentry->d_inode->i_sb->s_dev;
59011+}
59012+
59013+int
59014+gr_init_uidset(void)
59015+{
59016+ uid_set =
59017+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
59018+ uid_used = 0;
59019+
59020+ return uid_set ? 1 : 0;
59021+}
59022+
59023+void
59024+gr_free_uidset(void)
59025+{
59026+ if (uid_set)
59027+ kfree(uid_set);
59028+
59029+ return;
59030+}
59031+
59032+int
59033+gr_find_uid(const uid_t uid)
59034+{
59035+ struct crash_uid *tmp = uid_set;
59036+ uid_t buid;
59037+ int low = 0, high = uid_used - 1, mid;
59038+
59039+ while (high >= low) {
59040+ mid = (low + high) >> 1;
59041+ buid = tmp[mid].uid;
59042+ if (buid == uid)
59043+ return mid;
59044+ if (buid > uid)
59045+ high = mid - 1;
59046+ if (buid < uid)
59047+ low = mid + 1;
59048+ }
59049+
59050+ return -1;
59051+}
59052+
59053+static __inline__ void
59054+gr_insertsort(void)
59055+{
59056+ unsigned short i, j;
59057+ struct crash_uid index;
59058+
59059+ for (i = 1; i < uid_used; i++) {
59060+ index = uid_set[i];
59061+ j = i;
59062+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
59063+ uid_set[j] = uid_set[j - 1];
59064+ j--;
59065+ }
59066+ uid_set[j] = index;
59067+ }
59068+
59069+ return;
59070+}
59071+
59072+static __inline__ void
59073+gr_insert_uid(const uid_t uid, const unsigned long expires)
59074+{
59075+ int loc;
59076+
59077+ if (uid_used == GR_UIDTABLE_MAX)
59078+ return;
59079+
59080+ loc = gr_find_uid(uid);
59081+
59082+ if (loc >= 0) {
59083+ uid_set[loc].expires = expires;
59084+ return;
59085+ }
59086+
59087+ uid_set[uid_used].uid = uid;
59088+ uid_set[uid_used].expires = expires;
59089+ uid_used++;
59090+
59091+ gr_insertsort();
59092+
59093+ return;
59094+}
59095+
59096+void
59097+gr_remove_uid(const unsigned short loc)
59098+{
59099+ unsigned short i;
59100+
59101+ for (i = loc + 1; i < uid_used; i++)
59102+ uid_set[i - 1] = uid_set[i];
59103+
59104+ uid_used--;
59105+
59106+ return;
59107+}
59108+
59109+int
59110+gr_check_crash_uid(const uid_t uid)
59111+{
59112+ int loc;
59113+ int ret = 0;
59114+
59115+ if (unlikely(!gr_acl_is_enabled()))
59116+ return 0;
59117+
59118+ spin_lock(&gr_uid_lock);
59119+ loc = gr_find_uid(uid);
59120+
59121+ if (loc < 0)
59122+ goto out_unlock;
59123+
59124+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
59125+ gr_remove_uid(loc);
59126+ else
59127+ ret = 1;
59128+
59129+out_unlock:
59130+ spin_unlock(&gr_uid_lock);
59131+ return ret;
59132+}
59133+
59134+static __inline__ int
59135+proc_is_setxid(const struct cred *cred)
59136+{
59137+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
59138+ !uid_eq(cred->uid, cred->fsuid))
59139+ return 1;
59140+ if (!uid_eq(cred->gid, cred->egid) || !uid_eq(cred->gid, cred->sgid) ||
59141+ !uid_eq(cred->gid, cred->fsgid))
59142+ return 1;
59143+
59144+ return 0;
59145+}
59146+
59147+extern int gr_fake_force_sig(int sig, struct task_struct *t);
59148+
59149+void
59150+gr_handle_crash(struct task_struct *task, const int sig)
59151+{
59152+ struct acl_subject_label *curr;
59153+ struct task_struct *tsk, *tsk2;
59154+ const struct cred *cred;
59155+ const struct cred *cred2;
59156+
59157+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
59158+ return;
59159+
59160+ if (unlikely(!gr_acl_is_enabled()))
59161+ return;
59162+
59163+ curr = task->acl;
59164+
59165+ if (!(curr->resmask & (1 << GR_CRASH_RES)))
59166+ return;
59167+
59168+ if (time_before_eq(curr->expires, get_seconds())) {
59169+ curr->expires = 0;
59170+ curr->crashes = 0;
59171+ }
59172+
59173+ curr->crashes++;
59174+
59175+ if (!curr->expires)
59176+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
59177+
59178+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
59179+ time_after(curr->expires, get_seconds())) {
59180+ rcu_read_lock();
59181+ cred = __task_cred(task);
59182+ if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && proc_is_setxid(cred)) {
59183+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
59184+ spin_lock(&gr_uid_lock);
59185+ gr_insert_uid(cred->uid, curr->expires);
59186+ spin_unlock(&gr_uid_lock);
59187+ curr->expires = 0;
59188+ curr->crashes = 0;
59189+ read_lock(&tasklist_lock);
59190+ do_each_thread(tsk2, tsk) {
59191+ cred2 = __task_cred(tsk);
59192+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
59193+ gr_fake_force_sig(SIGKILL, tsk);
59194+ } while_each_thread(tsk2, tsk);
59195+ read_unlock(&tasklist_lock);
59196+ } else {
59197+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
59198+ read_lock(&tasklist_lock);
59199+ read_lock(&grsec_exec_file_lock);
59200+ do_each_thread(tsk2, tsk) {
59201+ if (likely(tsk != task)) {
59202+ // if this thread has the same subject as the one that triggered
59203+ // RES_CRASH and it's the same binary, kill it
59204+ if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
59205+ gr_fake_force_sig(SIGKILL, tsk);
59206+ }
59207+ } while_each_thread(tsk2, tsk);
59208+ read_unlock(&grsec_exec_file_lock);
59209+ read_unlock(&tasklist_lock);
59210+ }
59211+ rcu_read_unlock();
59212+ }
59213+
59214+ return;
59215+}
59216+
59217+int
59218+gr_check_crash_exec(const struct file *filp)
59219+{
59220+ struct acl_subject_label *curr;
59221+
59222+ if (unlikely(!gr_acl_is_enabled()))
59223+ return 0;
59224+
59225+ read_lock(&gr_inode_lock);
59226+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
59227+ __get_dev(filp->f_path.dentry),
59228+ current->role);
59229+ read_unlock(&gr_inode_lock);
59230+
59231+ if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
59232+ (!curr->crashes && !curr->expires))
59233+ return 0;
59234+
59235+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
59236+ time_after(curr->expires, get_seconds()))
59237+ return 1;
59238+ else if (time_before_eq(curr->expires, get_seconds())) {
59239+ curr->crashes = 0;
59240+ curr->expires = 0;
59241+ }
59242+
59243+ return 0;
59244+}
59245+
59246+void
59247+gr_handle_alertkill(struct task_struct *task)
59248+{
59249+ struct acl_subject_label *curracl;
59250+ __u32 curr_ip;
59251+ struct task_struct *p, *p2;
59252+
59253+ if (unlikely(!gr_acl_is_enabled()))
59254+ return;
59255+
59256+ curracl = task->acl;
59257+ curr_ip = task->signal->curr_ip;
59258+
59259+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
59260+ read_lock(&tasklist_lock);
59261+ do_each_thread(p2, p) {
59262+ if (p->signal->curr_ip == curr_ip)
59263+ gr_fake_force_sig(SIGKILL, p);
59264+ } while_each_thread(p2, p);
59265+ read_unlock(&tasklist_lock);
59266+ } else if (curracl->mode & GR_KILLPROC)
59267+ gr_fake_force_sig(SIGKILL, task);
59268+
59269+ return;
59270+}
59271diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
59272new file mode 100644
59273index 0000000..9d83a69
59274--- /dev/null
59275+++ b/grsecurity/gracl_shm.c
59276@@ -0,0 +1,40 @@
59277+#include <linux/kernel.h>
59278+#include <linux/mm.h>
59279+#include <linux/sched.h>
59280+#include <linux/file.h>
59281+#include <linux/ipc.h>
59282+#include <linux/gracl.h>
59283+#include <linux/grsecurity.h>
59284+#include <linux/grinternal.h>
59285+
59286+int
59287+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
59288+ const time_t shm_createtime, const uid_t cuid, const int shmid)
59289+{
59290+ struct task_struct *task;
59291+
59292+ if (!gr_acl_is_enabled())
59293+ return 1;
59294+
59295+ rcu_read_lock();
59296+ read_lock(&tasklist_lock);
59297+
59298+ task = find_task_by_vpid(shm_cprid);
59299+
59300+ if (unlikely(!task))
59301+ task = find_task_by_vpid(shm_lapid);
59302+
59303+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
59304+ (task->pid == shm_lapid)) &&
59305+ (task->acl->mode & GR_PROTSHM) &&
59306+ (task->acl != current->acl))) {
59307+ read_unlock(&tasklist_lock);
59308+ rcu_read_unlock();
59309+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
59310+ return 0;
59311+ }
59312+ read_unlock(&tasklist_lock);
59313+ rcu_read_unlock();
59314+
59315+ return 1;
59316+}
59317diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
59318new file mode 100644
59319index 0000000..bc0be01
59320--- /dev/null
59321+++ b/grsecurity/grsec_chdir.c
59322@@ -0,0 +1,19 @@
59323+#include <linux/kernel.h>
59324+#include <linux/sched.h>
59325+#include <linux/fs.h>
59326+#include <linux/file.h>
59327+#include <linux/grsecurity.h>
59328+#include <linux/grinternal.h>
59329+
59330+void
59331+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
59332+{
59333+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
59334+ if ((grsec_enable_chdir && grsec_enable_group &&
59335+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
59336+ !grsec_enable_group)) {
59337+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
59338+ }
59339+#endif
59340+ return;
59341+}
59342diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
59343new file mode 100644
59344index 0000000..70fe0ae
59345--- /dev/null
59346+++ b/grsecurity/grsec_chroot.c
59347@@ -0,0 +1,357 @@
59348+#include <linux/kernel.h>
59349+#include <linux/module.h>
59350+#include <linux/sched.h>
59351+#include <linux/file.h>
59352+#include <linux/fs.h>
59353+#include <linux/mount.h>
59354+#include <linux/types.h>
59355+#include "../fs/mount.h"
59356+#include <linux/grsecurity.h>
59357+#include <linux/grinternal.h>
59358+
59359+void gr_set_chroot_entries(struct task_struct *task, struct path *path)
59360+{
59361+#ifdef CONFIG_GRKERNSEC
59362+ if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
59363+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
59364+ task->gr_is_chrooted = 1;
59365+ else
59366+ task->gr_is_chrooted = 0;
59367+
59368+ task->gr_chroot_dentry = path->dentry;
59369+#endif
59370+ return;
59371+}
59372+
59373+void gr_clear_chroot_entries(struct task_struct *task)
59374+{
59375+#ifdef CONFIG_GRKERNSEC
59376+ task->gr_is_chrooted = 0;
59377+ task->gr_chroot_dentry = NULL;
59378+#endif
59379+ return;
59380+}
59381+
59382+int
59383+gr_handle_chroot_unix(const pid_t pid)
59384+{
59385+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
59386+ struct task_struct *p;
59387+
59388+ if (unlikely(!grsec_enable_chroot_unix))
59389+ return 1;
59390+
59391+ if (likely(!proc_is_chrooted(current)))
59392+ return 1;
59393+
59394+ rcu_read_lock();
59395+ read_lock(&tasklist_lock);
59396+ p = find_task_by_vpid_unrestricted(pid);
59397+ if (unlikely(p && !have_same_root(current, p))) {
59398+ read_unlock(&tasklist_lock);
59399+ rcu_read_unlock();
59400+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
59401+ return 0;
59402+ }
59403+ read_unlock(&tasklist_lock);
59404+ rcu_read_unlock();
59405+#endif
59406+ return 1;
59407+}
59408+
59409+int
59410+gr_handle_chroot_nice(void)
59411+{
59412+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
59413+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
59414+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
59415+ return -EPERM;
59416+ }
59417+#endif
59418+ return 0;
59419+}
59420+
59421+int
59422+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
59423+{
59424+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
59425+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
59426+ && proc_is_chrooted(current)) {
59427+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
59428+ return -EACCES;
59429+ }
59430+#endif
59431+ return 0;
59432+}
59433+
59434+int
59435+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
59436+{
59437+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
59438+ struct task_struct *p;
59439+ int ret = 0;
59440+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
59441+ return ret;
59442+
59443+ read_lock(&tasklist_lock);
59444+ do_each_pid_task(pid, type, p) {
59445+ if (!have_same_root(current, p)) {
59446+ ret = 1;
59447+ goto out;
59448+ }
59449+ } while_each_pid_task(pid, type, p);
59450+out:
59451+ read_unlock(&tasklist_lock);
59452+ return ret;
59453+#endif
59454+ return 0;
59455+}
59456+
59457+int
59458+gr_pid_is_chrooted(struct task_struct *p)
59459+{
59460+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
59461+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
59462+ return 0;
59463+
59464+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
59465+ !have_same_root(current, p)) {
59466+ return 1;
59467+ }
59468+#endif
59469+ return 0;
59470+}
59471+
59472+EXPORT_SYMBOL(gr_pid_is_chrooted);
59473+
59474+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
59475+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
59476+{
59477+ struct path path, currentroot;
59478+ int ret = 0;
59479+
59480+ path.dentry = (struct dentry *)u_dentry;
59481+ path.mnt = (struct vfsmount *)u_mnt;
59482+ get_fs_root(current->fs, &currentroot);
59483+ if (path_is_under(&path, &currentroot))
59484+ ret = 1;
59485+ path_put(&currentroot);
59486+
59487+ return ret;
59488+}
59489+#endif
59490+
59491+int
59492+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
59493+{
59494+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
59495+ if (!grsec_enable_chroot_fchdir)
59496+ return 1;
59497+
59498+ if (!proc_is_chrooted(current))
59499+ return 1;
59500+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
59501+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
59502+ return 0;
59503+ }
59504+#endif
59505+ return 1;
59506+}
59507+
59508+int
59509+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
59510+ const time_t shm_createtime)
59511+{
59512+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
59513+ struct task_struct *p;
59514+ time_t starttime;
59515+
59516+ if (unlikely(!grsec_enable_chroot_shmat))
59517+ return 1;
59518+
59519+ if (likely(!proc_is_chrooted(current)))
59520+ return 1;
59521+
59522+ rcu_read_lock();
59523+ read_lock(&tasklist_lock);
59524+
59525+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
59526+ starttime = p->start_time.tv_sec;
59527+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
59528+ if (have_same_root(current, p)) {
59529+ goto allow;
59530+ } else {
59531+ read_unlock(&tasklist_lock);
59532+ rcu_read_unlock();
59533+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
59534+ return 0;
59535+ }
59536+ }
59537+ /* creator exited, pid reuse, fall through to next check */
59538+ }
59539+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
59540+ if (unlikely(!have_same_root(current, p))) {
59541+ read_unlock(&tasklist_lock);
59542+ rcu_read_unlock();
59543+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
59544+ return 0;
59545+ }
59546+ }
59547+
59548+allow:
59549+ read_unlock(&tasklist_lock);
59550+ rcu_read_unlock();
59551+#endif
59552+ return 1;
59553+}
59554+
59555+void
59556+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
59557+{
59558+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
59559+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
59560+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
59561+#endif
59562+ return;
59563+}
59564+
59565+int
59566+gr_handle_chroot_mknod(const struct dentry *dentry,
59567+ const struct vfsmount *mnt, const int mode)
59568+{
59569+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
59570+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
59571+ proc_is_chrooted(current)) {
59572+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
59573+ return -EPERM;
59574+ }
59575+#endif
59576+ return 0;
59577+}
59578+
59579+int
59580+gr_handle_chroot_mount(const struct dentry *dentry,
59581+ const struct vfsmount *mnt, const char *dev_name)
59582+{
59583+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
59584+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
59585+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
59586+ return -EPERM;
59587+ }
59588+#endif
59589+ return 0;
59590+}
59591+
59592+int
59593+gr_handle_chroot_pivot(void)
59594+{
59595+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
59596+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
59597+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
59598+ return -EPERM;
59599+ }
59600+#endif
59601+ return 0;
59602+}
59603+
59604+int
59605+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
59606+{
59607+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
59608+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
59609+ !gr_is_outside_chroot(dentry, mnt)) {
59610+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
59611+ return -EPERM;
59612+ }
59613+#endif
59614+ return 0;
59615+}
59616+
59617+extern const char *captab_log[];
59618+extern int captab_log_entries;
59619+
59620+int
59621+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
59622+{
59623+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59624+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
59625+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
59626+ if (cap_raised(chroot_caps, cap)) {
59627+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
59628+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
59629+ }
59630+ return 0;
59631+ }
59632+ }
59633+#endif
59634+ return 1;
59635+}
59636+
59637+int
59638+gr_chroot_is_capable(const int cap)
59639+{
59640+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59641+ return gr_task_chroot_is_capable(current, current_cred(), cap);
59642+#endif
59643+ return 1;
59644+}
59645+
59646+int
59647+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
59648+{
59649+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59650+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
59651+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
59652+ if (cap_raised(chroot_caps, cap)) {
59653+ return 0;
59654+ }
59655+ }
59656+#endif
59657+ return 1;
59658+}
59659+
59660+int
59661+gr_chroot_is_capable_nolog(const int cap)
59662+{
59663+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59664+ return gr_task_chroot_is_capable_nolog(current, cap);
59665+#endif
59666+ return 1;
59667+}
59668+
59669+int
59670+gr_handle_chroot_sysctl(const int op)
59671+{
59672+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
59673+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
59674+ proc_is_chrooted(current))
59675+ return -EACCES;
59676+#endif
59677+ return 0;
59678+}
59679+
59680+void
59681+gr_handle_chroot_chdir(struct path *path)
59682+{
59683+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
59684+ if (grsec_enable_chroot_chdir)
59685+ set_fs_pwd(current->fs, path);
59686+#endif
59687+ return;
59688+}
59689+
59690+int
59691+gr_handle_chroot_chmod(const struct dentry *dentry,
59692+ const struct vfsmount *mnt, const int mode)
59693+{
59694+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
59695+ /* allow chmod +s on directories, but not files */
59696+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
59697+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
59698+ proc_is_chrooted(current)) {
59699+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
59700+ return -EPERM;
59701+ }
59702+#endif
59703+ return 0;
59704+}
59705diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
59706new file mode 100644
59707index 0000000..e6796b3
59708--- /dev/null
59709+++ b/grsecurity/grsec_disabled.c
59710@@ -0,0 +1,434 @@
59711+#include <linux/kernel.h>
59712+#include <linux/module.h>
59713+#include <linux/sched.h>
59714+#include <linux/file.h>
59715+#include <linux/fs.h>
59716+#include <linux/kdev_t.h>
59717+#include <linux/net.h>
59718+#include <linux/in.h>
59719+#include <linux/ip.h>
59720+#include <linux/skbuff.h>
59721+#include <linux/sysctl.h>
59722+
59723+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
59724+void
59725+pax_set_initial_flags(struct linux_binprm *bprm)
59726+{
59727+ return;
59728+}
59729+#endif
59730+
59731+#ifdef CONFIG_SYSCTL
59732+__u32
59733+gr_handle_sysctl(const struct ctl_table * table, const int op)
59734+{
59735+ return 0;
59736+}
59737+#endif
59738+
59739+#ifdef CONFIG_TASKSTATS
59740+int gr_is_taskstats_denied(int pid)
59741+{
59742+ return 0;
59743+}
59744+#endif
59745+
59746+int
59747+gr_acl_is_enabled(void)
59748+{
59749+ return 0;
59750+}
59751+
59752+void
59753+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
59754+{
59755+ return;
59756+}
59757+
59758+int
59759+gr_handle_rawio(const struct inode *inode)
59760+{
59761+ return 0;
59762+}
59763+
59764+void
59765+gr_acl_handle_psacct(struct task_struct *task, const long code)
59766+{
59767+ return;
59768+}
59769+
59770+int
59771+gr_handle_ptrace(struct task_struct *task, const long request)
59772+{
59773+ return 0;
59774+}
59775+
59776+int
59777+gr_handle_proc_ptrace(struct task_struct *task)
59778+{
59779+ return 0;
59780+}
59781+
59782+int
59783+gr_set_acls(const int type)
59784+{
59785+ return 0;
59786+}
59787+
59788+int
59789+gr_check_hidden_task(const struct task_struct *tsk)
59790+{
59791+ return 0;
59792+}
59793+
59794+int
59795+gr_check_protected_task(const struct task_struct *task)
59796+{
59797+ return 0;
59798+}
59799+
59800+int
59801+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
59802+{
59803+ return 0;
59804+}
59805+
59806+void
59807+gr_copy_label(struct task_struct *tsk)
59808+{
59809+ return;
59810+}
59811+
59812+void
59813+gr_set_pax_flags(struct task_struct *task)
59814+{
59815+ return;
59816+}
59817+
59818+int
59819+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
59820+ const int unsafe_share)
59821+{
59822+ return 0;
59823+}
59824+
59825+void
59826+gr_handle_delete(const ino_t ino, const dev_t dev)
59827+{
59828+ return;
59829+}
59830+
59831+void
59832+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
59833+{
59834+ return;
59835+}
59836+
59837+void
59838+gr_handle_crash(struct task_struct *task, const int sig)
59839+{
59840+ return;
59841+}
59842+
59843+int
59844+gr_check_crash_exec(const struct file *filp)
59845+{
59846+ return 0;
59847+}
59848+
59849+int
59850+gr_check_crash_uid(const uid_t uid)
59851+{
59852+ return 0;
59853+}
59854+
59855+void
59856+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
59857+ struct dentry *old_dentry,
59858+ struct dentry *new_dentry,
59859+ struct vfsmount *mnt, const __u8 replace)
59860+{
59861+ return;
59862+}
59863+
59864+int
59865+gr_search_socket(const int family, const int type, const int protocol)
59866+{
59867+ return 1;
59868+}
59869+
59870+int
59871+gr_search_connectbind(const int mode, const struct socket *sock,
59872+ const struct sockaddr_in *addr)
59873+{
59874+ return 0;
59875+}
59876+
59877+void
59878+gr_handle_alertkill(struct task_struct *task)
59879+{
59880+ return;
59881+}
59882+
59883+__u32
59884+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
59885+{
59886+ return 1;
59887+}
59888+
59889+__u32
59890+gr_acl_handle_hidden_file(const struct dentry * dentry,
59891+ const struct vfsmount * mnt)
59892+{
59893+ return 1;
59894+}
59895+
59896+__u32
59897+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
59898+ int acc_mode)
59899+{
59900+ return 1;
59901+}
59902+
59903+__u32
59904+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
59905+{
59906+ return 1;
59907+}
59908+
59909+__u32
59910+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
59911+{
59912+ return 1;
59913+}
59914+
59915+int
59916+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
59917+ unsigned int *vm_flags)
59918+{
59919+ return 1;
59920+}
59921+
59922+__u32
59923+gr_acl_handle_truncate(const struct dentry * dentry,
59924+ const struct vfsmount * mnt)
59925+{
59926+ return 1;
59927+}
59928+
59929+__u32
59930+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
59931+{
59932+ return 1;
59933+}
59934+
59935+__u32
59936+gr_acl_handle_access(const struct dentry * dentry,
59937+ const struct vfsmount * mnt, const int fmode)
59938+{
59939+ return 1;
59940+}
59941+
59942+__u32
59943+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
59944+ umode_t *mode)
59945+{
59946+ return 1;
59947+}
59948+
59949+__u32
59950+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
59951+{
59952+ return 1;
59953+}
59954+
59955+__u32
59956+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
59957+{
59958+ return 1;
59959+}
59960+
59961+void
59962+grsecurity_init(void)
59963+{
59964+ return;
59965+}
59966+
59967+umode_t gr_acl_umask(void)
59968+{
59969+ return 0;
59970+}
59971+
59972+__u32
59973+gr_acl_handle_mknod(const struct dentry * new_dentry,
59974+ const struct dentry * parent_dentry,
59975+ const struct vfsmount * parent_mnt,
59976+ const int mode)
59977+{
59978+ return 1;
59979+}
59980+
59981+__u32
59982+gr_acl_handle_mkdir(const struct dentry * new_dentry,
59983+ const struct dentry * parent_dentry,
59984+ const struct vfsmount * parent_mnt)
59985+{
59986+ return 1;
59987+}
59988+
59989+__u32
59990+gr_acl_handle_symlink(const struct dentry * new_dentry,
59991+ const struct dentry * parent_dentry,
59992+ const struct vfsmount * parent_mnt, const struct filename *from)
59993+{
59994+ return 1;
59995+}
59996+
59997+__u32
59998+gr_acl_handle_link(const struct dentry * new_dentry,
59999+ const struct dentry * parent_dentry,
60000+ const struct vfsmount * parent_mnt,
60001+ const struct dentry * old_dentry,
60002+ const struct vfsmount * old_mnt, const struct filename *to)
60003+{
60004+ return 1;
60005+}
60006+
60007+int
60008+gr_acl_handle_rename(const struct dentry *new_dentry,
60009+ const struct dentry *parent_dentry,
60010+ const struct vfsmount *parent_mnt,
60011+ const struct dentry *old_dentry,
60012+ const struct inode *old_parent_inode,
60013+ const struct vfsmount *old_mnt, const struct filename *newname)
60014+{
60015+ return 0;
60016+}
60017+
60018+int
60019+gr_acl_handle_filldir(const struct file *file, const char *name,
60020+ const int namelen, const ino_t ino)
60021+{
60022+ return 1;
60023+}
60024+
60025+int
60026+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
60027+ const time_t shm_createtime, const uid_t cuid, const int shmid)
60028+{
60029+ return 1;
60030+}
60031+
60032+int
60033+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
60034+{
60035+ return 0;
60036+}
60037+
60038+int
60039+gr_search_accept(const struct socket *sock)
60040+{
60041+ return 0;
60042+}
60043+
60044+int
60045+gr_search_listen(const struct socket *sock)
60046+{
60047+ return 0;
60048+}
60049+
60050+int
60051+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
60052+{
60053+ return 0;
60054+}
60055+
60056+__u32
60057+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
60058+{
60059+ return 1;
60060+}
60061+
60062+__u32
60063+gr_acl_handle_creat(const struct dentry * dentry,
60064+ const struct dentry * p_dentry,
60065+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
60066+ const int imode)
60067+{
60068+ return 1;
60069+}
60070+
60071+void
60072+gr_acl_handle_exit(void)
60073+{
60074+ return;
60075+}
60076+
60077+int
60078+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
60079+{
60080+ return 1;
60081+}
60082+
60083+void
60084+gr_set_role_label(const uid_t uid, const gid_t gid)
60085+{
60086+ return;
60087+}
60088+
60089+int
60090+gr_acl_handle_procpidmem(const struct task_struct *task)
60091+{
60092+ return 0;
60093+}
60094+
60095+int
60096+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
60097+{
60098+ return 0;
60099+}
60100+
60101+int
60102+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
60103+{
60104+ return 0;
60105+}
60106+
60107+void
60108+gr_set_kernel_label(struct task_struct *task)
60109+{
60110+ return;
60111+}
60112+
60113+int
60114+gr_check_user_change(int real, int effective, int fs)
60115+{
60116+ return 0;
60117+}
60118+
60119+int
60120+gr_check_group_change(int real, int effective, int fs)
60121+{
60122+ return 0;
60123+}
60124+
60125+int gr_acl_enable_at_secure(void)
60126+{
60127+ return 0;
60128+}
60129+
60130+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
60131+{
60132+ return dentry->d_inode->i_sb->s_dev;
60133+}
60134+
60135+void gr_put_exec_file(struct task_struct *task)
60136+{
60137+ return;
60138+}
60139+
60140+EXPORT_SYMBOL(gr_set_kernel_label);
60141+#ifdef CONFIG_SECURITY
60142+EXPORT_SYMBOL(gr_check_user_change);
60143+EXPORT_SYMBOL(gr_check_group_change);
60144+#endif
60145diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
60146new file mode 100644
60147index 0000000..abfa971
60148--- /dev/null
60149+++ b/grsecurity/grsec_exec.c
60150@@ -0,0 +1,174 @@
60151+#include <linux/kernel.h>
60152+#include <linux/sched.h>
60153+#include <linux/file.h>
60154+#include <linux/binfmts.h>
60155+#include <linux/fs.h>
60156+#include <linux/types.h>
60157+#include <linux/grdefs.h>
60158+#include <linux/grsecurity.h>
60159+#include <linux/grinternal.h>
60160+#include <linux/capability.h>
60161+#include <linux/module.h>
60162+
60163+#include <asm/uaccess.h>
60164+
60165+#ifdef CONFIG_GRKERNSEC_EXECLOG
60166+static char gr_exec_arg_buf[132];
60167+static DEFINE_MUTEX(gr_exec_arg_mutex);
60168+#endif
60169+
60170+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
60171+
60172+void
60173+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
60174+{
60175+#ifdef CONFIG_GRKERNSEC_EXECLOG
60176+ char *grarg = gr_exec_arg_buf;
60177+ unsigned int i, x, execlen = 0;
60178+ char c;
60179+
60180+ if (!((grsec_enable_execlog && grsec_enable_group &&
60181+ in_group_p(grsec_audit_gid))
60182+ || (grsec_enable_execlog && !grsec_enable_group)))
60183+ return;
60184+
60185+ mutex_lock(&gr_exec_arg_mutex);
60186+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
60187+
60188+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
60189+ const char __user *p;
60190+ unsigned int len;
60191+
60192+ p = get_user_arg_ptr(argv, i);
60193+ if (IS_ERR(p))
60194+ goto log;
60195+
60196+ len = strnlen_user(p, 128 - execlen);
60197+ if (len > 128 - execlen)
60198+ len = 128 - execlen;
60199+ else if (len > 0)
60200+ len--;
60201+ if (copy_from_user(grarg + execlen, p, len))
60202+ goto log;
60203+
60204+ /* rewrite unprintable characters */
60205+ for (x = 0; x < len; x++) {
60206+ c = *(grarg + execlen + x);
60207+ if (c < 32 || c > 126)
60208+ *(grarg + execlen + x) = ' ';
60209+ }
60210+
60211+ execlen += len;
60212+ *(grarg + execlen) = ' ';
60213+ *(grarg + execlen + 1) = '\0';
60214+ execlen++;
60215+ }
60216+
60217+ log:
60218+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
60219+ bprm->file->f_path.mnt, grarg);
60220+ mutex_unlock(&gr_exec_arg_mutex);
60221+#endif
60222+ return;
60223+}
60224+
60225+#ifdef CONFIG_GRKERNSEC
60226+extern int gr_acl_is_capable(const int cap);
60227+extern int gr_acl_is_capable_nolog(const int cap);
60228+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
60229+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
60230+extern int gr_chroot_is_capable(const int cap);
60231+extern int gr_chroot_is_capable_nolog(const int cap);
60232+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
60233+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
60234+#endif
60235+
60236+const char *captab_log[] = {
60237+ "CAP_CHOWN",
60238+ "CAP_DAC_OVERRIDE",
60239+ "CAP_DAC_READ_SEARCH",
60240+ "CAP_FOWNER",
60241+ "CAP_FSETID",
60242+ "CAP_KILL",
60243+ "CAP_SETGID",
60244+ "CAP_SETUID",
60245+ "CAP_SETPCAP",
60246+ "CAP_LINUX_IMMUTABLE",
60247+ "CAP_NET_BIND_SERVICE",
60248+ "CAP_NET_BROADCAST",
60249+ "CAP_NET_ADMIN",
60250+ "CAP_NET_RAW",
60251+ "CAP_IPC_LOCK",
60252+ "CAP_IPC_OWNER",
60253+ "CAP_SYS_MODULE",
60254+ "CAP_SYS_RAWIO",
60255+ "CAP_SYS_CHROOT",
60256+ "CAP_SYS_PTRACE",
60257+ "CAP_SYS_PACCT",
60258+ "CAP_SYS_ADMIN",
60259+ "CAP_SYS_BOOT",
60260+ "CAP_SYS_NICE",
60261+ "CAP_SYS_RESOURCE",
60262+ "CAP_SYS_TIME",
60263+ "CAP_SYS_TTY_CONFIG",
60264+ "CAP_MKNOD",
60265+ "CAP_LEASE",
60266+ "CAP_AUDIT_WRITE",
60267+ "CAP_AUDIT_CONTROL",
60268+ "CAP_SETFCAP",
60269+ "CAP_MAC_OVERRIDE",
60270+ "CAP_MAC_ADMIN",
60271+ "CAP_SYSLOG",
60272+ "CAP_WAKE_ALARM"
60273+};
60274+
60275+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
60276+
60277+int gr_is_capable(const int cap)
60278+{
60279+#ifdef CONFIG_GRKERNSEC
60280+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
60281+ return 1;
60282+ return 0;
60283+#else
60284+ return 1;
60285+#endif
60286+}
60287+
60288+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
60289+{
60290+#ifdef CONFIG_GRKERNSEC
60291+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
60292+ return 1;
60293+ return 0;
60294+#else
60295+ return 1;
60296+#endif
60297+}
60298+
60299+int gr_is_capable_nolog(const int cap)
60300+{
60301+#ifdef CONFIG_GRKERNSEC
60302+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
60303+ return 1;
60304+ return 0;
60305+#else
60306+ return 1;
60307+#endif
60308+}
60309+
60310+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
60311+{
60312+#ifdef CONFIG_GRKERNSEC
60313+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
60314+ return 1;
60315+ return 0;
60316+#else
60317+ return 1;
60318+#endif
60319+}
60320+
60321+EXPORT_SYMBOL(gr_is_capable);
60322+EXPORT_SYMBOL(gr_is_capable_nolog);
60323+EXPORT_SYMBOL(gr_task_is_capable);
60324+EXPORT_SYMBOL(gr_task_is_capable_nolog);
60325diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
60326new file mode 100644
60327index 0000000..d3ee748
60328--- /dev/null
60329+++ b/grsecurity/grsec_fifo.c
60330@@ -0,0 +1,24 @@
60331+#include <linux/kernel.h>
60332+#include <linux/sched.h>
60333+#include <linux/fs.h>
60334+#include <linux/file.h>
60335+#include <linux/grinternal.h>
60336+
60337+int
60338+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
60339+ const struct dentry *dir, const int flag, const int acc_mode)
60340+{
60341+#ifdef CONFIG_GRKERNSEC_FIFO
60342+ const struct cred *cred = current_cred();
60343+
60344+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
60345+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
60346+ (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
60347+ (cred->fsuid != dentry->d_inode->i_uid)) {
60348+ if (!inode_permission(dentry->d_inode, acc_mode))
60349+ gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
60350+ return -EACCES;
60351+ }
60352+#endif
60353+ return 0;
60354+}
60355diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
60356new file mode 100644
60357index 0000000..8ca18bf
60358--- /dev/null
60359+++ b/grsecurity/grsec_fork.c
60360@@ -0,0 +1,23 @@
60361+#include <linux/kernel.h>
60362+#include <linux/sched.h>
60363+#include <linux/grsecurity.h>
60364+#include <linux/grinternal.h>
60365+#include <linux/errno.h>
60366+
60367+void
60368+gr_log_forkfail(const int retval)
60369+{
60370+#ifdef CONFIG_GRKERNSEC_FORKFAIL
60371+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
60372+ switch (retval) {
60373+ case -EAGAIN:
60374+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
60375+ break;
60376+ case -ENOMEM:
60377+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
60378+ break;
60379+ }
60380+ }
60381+#endif
60382+ return;
60383+}
60384diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
60385new file mode 100644
60386index 0000000..05a6015
60387--- /dev/null
60388+++ b/grsecurity/grsec_init.c
60389@@ -0,0 +1,283 @@
60390+#include <linux/kernel.h>
60391+#include <linux/sched.h>
60392+#include <linux/mm.h>
60393+#include <linux/gracl.h>
60394+#include <linux/slab.h>
60395+#include <linux/vmalloc.h>
60396+#include <linux/percpu.h>
60397+#include <linux/module.h>
60398+
60399+int grsec_enable_ptrace_readexec;
60400+int grsec_enable_setxid;
60401+int grsec_enable_symlinkown;
60402+int grsec_symlinkown_gid;
60403+int grsec_enable_brute;
60404+int grsec_enable_link;
60405+int grsec_enable_dmesg;
60406+int grsec_enable_harden_ptrace;
60407+int grsec_enable_fifo;
60408+int grsec_enable_execlog;
60409+int grsec_enable_signal;
60410+int grsec_enable_forkfail;
60411+int grsec_enable_audit_ptrace;
60412+int grsec_enable_time;
60413+int grsec_enable_audit_textrel;
60414+int grsec_enable_group;
60415+int grsec_audit_gid;
60416+int grsec_enable_chdir;
60417+int grsec_enable_mount;
60418+int grsec_enable_rofs;
60419+int grsec_enable_chroot_findtask;
60420+int grsec_enable_chroot_mount;
60421+int grsec_enable_chroot_shmat;
60422+int grsec_enable_chroot_fchdir;
60423+int grsec_enable_chroot_double;
60424+int grsec_enable_chroot_pivot;
60425+int grsec_enable_chroot_chdir;
60426+int grsec_enable_chroot_chmod;
60427+int grsec_enable_chroot_mknod;
60428+int grsec_enable_chroot_nice;
60429+int grsec_enable_chroot_execlog;
60430+int grsec_enable_chroot_caps;
60431+int grsec_enable_chroot_sysctl;
60432+int grsec_enable_chroot_unix;
60433+int grsec_enable_tpe;
60434+int grsec_tpe_gid;
60435+int grsec_enable_blackhole;
60436+#ifdef CONFIG_IPV6_MODULE
60437+EXPORT_SYMBOL(grsec_enable_blackhole);
60438+#endif
60439+int grsec_lastack_retries;
60440+int grsec_enable_tpe_all;
60441+int grsec_enable_tpe_invert;
60442+int grsec_enable_socket_all;
60443+int grsec_socket_all_gid;
60444+int grsec_enable_socket_client;
60445+int grsec_socket_client_gid;
60446+int grsec_enable_socket_server;
60447+int grsec_socket_server_gid;
60448+int grsec_resource_logging;
60449+int grsec_disable_privio;
60450+int grsec_enable_log_rwxmaps;
60451+int grsec_lock;
60452+
60453+DEFINE_SPINLOCK(grsec_alert_lock);
60454+unsigned long grsec_alert_wtime = 0;
60455+unsigned long grsec_alert_fyet = 0;
60456+
60457+DEFINE_SPINLOCK(grsec_audit_lock);
60458+
60459+DEFINE_RWLOCK(grsec_exec_file_lock);
60460+
60461+char *gr_shared_page[4];
60462+
60463+char *gr_alert_log_fmt;
60464+char *gr_audit_log_fmt;
60465+char *gr_alert_log_buf;
60466+char *gr_audit_log_buf;
60467+
60468+extern struct gr_arg *gr_usermode;
60469+extern unsigned char *gr_system_salt;
60470+extern unsigned char *gr_system_sum;
60471+
60472+void __init
60473+grsecurity_init(void)
60474+{
60475+ int j;
60476+ /* create the per-cpu shared pages */
60477+
60478+#ifdef CONFIG_X86
60479+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
60480+#endif
60481+
60482+ for (j = 0; j < 4; j++) {
60483+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
60484+ if (gr_shared_page[j] == NULL) {
60485+ panic("Unable to allocate grsecurity shared page");
60486+ return;
60487+ }
60488+ }
60489+
60490+ /* allocate log buffers */
60491+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
60492+ if (!gr_alert_log_fmt) {
60493+ panic("Unable to allocate grsecurity alert log format buffer");
60494+ return;
60495+ }
60496+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
60497+ if (!gr_audit_log_fmt) {
60498+ panic("Unable to allocate grsecurity audit log format buffer");
60499+ return;
60500+ }
60501+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
60502+ if (!gr_alert_log_buf) {
60503+ panic("Unable to allocate grsecurity alert log buffer");
60504+ return;
60505+ }
60506+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
60507+ if (!gr_audit_log_buf) {
60508+ panic("Unable to allocate grsecurity audit log buffer");
60509+ return;
60510+ }
60511+
60512+ /* allocate memory for authentication structure */
60513+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
60514+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
60515+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
60516+
60517+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
60518+ panic("Unable to allocate grsecurity authentication structure");
60519+ return;
60520+ }
60521+
60522+
60523+#ifdef CONFIG_GRKERNSEC_IO
60524+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
60525+ grsec_disable_privio = 1;
60526+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
60527+ grsec_disable_privio = 1;
60528+#else
60529+ grsec_disable_privio = 0;
60530+#endif
60531+#endif
60532+
60533+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
60534+ /* for backward compatibility, tpe_invert always defaults to on if
60535+ enabled in the kernel
60536+ */
60537+ grsec_enable_tpe_invert = 1;
60538+#endif
60539+
60540+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
60541+#ifndef CONFIG_GRKERNSEC_SYSCTL
60542+ grsec_lock = 1;
60543+#endif
60544+
60545+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
60546+ grsec_enable_audit_textrel = 1;
60547+#endif
60548+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
60549+ grsec_enable_log_rwxmaps = 1;
60550+#endif
60551+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
60552+ grsec_enable_group = 1;
60553+ grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
60554+#endif
60555+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
60556+ grsec_enable_ptrace_readexec = 1;
60557+#endif
60558+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
60559+ grsec_enable_chdir = 1;
60560+#endif
60561+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
60562+ grsec_enable_harden_ptrace = 1;
60563+#endif
60564+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
60565+ grsec_enable_mount = 1;
60566+#endif
60567+#ifdef CONFIG_GRKERNSEC_LINK
60568+ grsec_enable_link = 1;
60569+#endif
60570+#ifdef CONFIG_GRKERNSEC_BRUTE
60571+ grsec_enable_brute = 1;
60572+#endif
60573+#ifdef CONFIG_GRKERNSEC_DMESG
60574+ grsec_enable_dmesg = 1;
60575+#endif
60576+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
60577+ grsec_enable_blackhole = 1;
60578+ grsec_lastack_retries = 4;
60579+#endif
60580+#ifdef CONFIG_GRKERNSEC_FIFO
60581+ grsec_enable_fifo = 1;
60582+#endif
60583+#ifdef CONFIG_GRKERNSEC_EXECLOG
60584+ grsec_enable_execlog = 1;
60585+#endif
60586+#ifdef CONFIG_GRKERNSEC_SETXID
60587+ grsec_enable_setxid = 1;
60588+#endif
60589+#ifdef CONFIG_GRKERNSEC_SIGNAL
60590+ grsec_enable_signal = 1;
60591+#endif
60592+#ifdef CONFIG_GRKERNSEC_FORKFAIL
60593+ grsec_enable_forkfail = 1;
60594+#endif
60595+#ifdef CONFIG_GRKERNSEC_TIME
60596+ grsec_enable_time = 1;
60597+#endif
60598+#ifdef CONFIG_GRKERNSEC_RESLOG
60599+ grsec_resource_logging = 1;
60600+#endif
60601+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
60602+ grsec_enable_chroot_findtask = 1;
60603+#endif
60604+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
60605+ grsec_enable_chroot_unix = 1;
60606+#endif
60607+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
60608+ grsec_enable_chroot_mount = 1;
60609+#endif
60610+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
60611+ grsec_enable_chroot_fchdir = 1;
60612+#endif
60613+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
60614+ grsec_enable_chroot_shmat = 1;
60615+#endif
60616+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
60617+ grsec_enable_audit_ptrace = 1;
60618+#endif
60619+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
60620+ grsec_enable_chroot_double = 1;
60621+#endif
60622+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
60623+ grsec_enable_chroot_pivot = 1;
60624+#endif
60625+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
60626+ grsec_enable_chroot_chdir = 1;
60627+#endif
60628+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
60629+ grsec_enable_chroot_chmod = 1;
60630+#endif
60631+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
60632+ grsec_enable_chroot_mknod = 1;
60633+#endif
60634+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
60635+ grsec_enable_chroot_nice = 1;
60636+#endif
60637+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
60638+ grsec_enable_chroot_execlog = 1;
60639+#endif
60640+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
60641+ grsec_enable_chroot_caps = 1;
60642+#endif
60643+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
60644+ grsec_enable_chroot_sysctl = 1;
60645+#endif
60646+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
60647+ grsec_enable_symlinkown = 1;
60648+ grsec_symlinkown_gid = CONFIG_GRKERNSEC_SYMLINKOWN_GID;
60649+#endif
60650+#ifdef CONFIG_GRKERNSEC_TPE
60651+ grsec_enable_tpe = 1;
60652+ grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
60653+#ifdef CONFIG_GRKERNSEC_TPE_ALL
60654+ grsec_enable_tpe_all = 1;
60655+#endif
60656+#endif
60657+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
60658+ grsec_enable_socket_all = 1;
60659+ grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
60660+#endif
60661+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
60662+ grsec_enable_socket_client = 1;
60663+ grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
60664+#endif
60665+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
60666+ grsec_enable_socket_server = 1;
60667+ grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
60668+#endif
60669+#endif
60670+
60671+ return;
60672+}
60673diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
60674new file mode 100644
60675index 0000000..6095407
60676--- /dev/null
60677+++ b/grsecurity/grsec_link.c
60678@@ -0,0 +1,58 @@
60679+#include <linux/kernel.h>
60680+#include <linux/sched.h>
60681+#include <linux/fs.h>
60682+#include <linux/file.h>
60683+#include <linux/grinternal.h>
60684+
60685+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
60686+{
60687+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
60688+ const struct inode *link_inode = link->dentry->d_inode;
60689+
60690+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
60691+ /* ignore root-owned links, e.g. /proc/self */
60692+ !uid_eq(link_inode->i_uid, GLOBAL_ROOT_UID) && target &&
60693+ !uid_eq(link_inode->i_uid, target->i_uid)) {
60694+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
60695+ return 1;
60696+ }
60697+#endif
60698+ return 0;
60699+}
60700+
60701+int
60702+gr_handle_follow_link(const struct inode *parent,
60703+ const struct inode *inode,
60704+ const struct dentry *dentry, const struct vfsmount *mnt)
60705+{
60706+#ifdef CONFIG_GRKERNSEC_LINK
60707+ const struct cred *cred = current_cred();
60708+
60709+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
60710+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
60711+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
60712+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
60713+ return -EACCES;
60714+ }
60715+#endif
60716+ return 0;
60717+}
60718+
60719+int
60720+gr_handle_hardlink(const struct dentry *dentry,
60721+ const struct vfsmount *mnt,
60722+ struct inode *inode, const int mode, const struct filename *to)
60723+{
60724+#ifdef CONFIG_GRKERNSEC_LINK
60725+ const struct cred *cred = current_cred();
60726+
60727+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
60728+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
60729+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
60730+ !capable(CAP_FOWNER) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
60731+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
60732+ return -EPERM;
60733+ }
60734+#endif
60735+ return 0;
60736+}
60737diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
60738new file mode 100644
60739index 0000000..7bd6c2b
60740--- /dev/null
60741+++ b/grsecurity/grsec_log.c
60742@@ -0,0 +1,329 @@
60743+#include <linux/kernel.h>
60744+#include <linux/sched.h>
60745+#include <linux/file.h>
60746+#include <linux/tty.h>
60747+#include <linux/fs.h>
60748+#include <linux/grinternal.h>
60749+
60750+#ifdef CONFIG_TREE_PREEMPT_RCU
60751+#define DISABLE_PREEMPT() preempt_disable()
60752+#define ENABLE_PREEMPT() preempt_enable()
60753+#else
60754+#define DISABLE_PREEMPT()
60755+#define ENABLE_PREEMPT()
60756+#endif
60757+
60758+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
60759+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
60760+
60761+#define BEGIN_LOCKS(x) \
60762+ DISABLE_PREEMPT(); \
60763+ rcu_read_lock(); \
60764+ read_lock(&tasklist_lock); \
60765+ read_lock(&grsec_exec_file_lock); \
60766+ if (x != GR_DO_AUDIT) \
60767+ spin_lock(&grsec_alert_lock); \
60768+ else \
60769+ spin_lock(&grsec_audit_lock)
60770+
60771+#define END_LOCKS(x) \
60772+ if (x != GR_DO_AUDIT) \
60773+ spin_unlock(&grsec_alert_lock); \
60774+ else \
60775+ spin_unlock(&grsec_audit_lock); \
60776+ read_unlock(&grsec_exec_file_lock); \
60777+ read_unlock(&tasklist_lock); \
60778+ rcu_read_unlock(); \
60779+ ENABLE_PREEMPT(); \
60780+ if (x == GR_DONT_AUDIT) \
60781+ gr_handle_alertkill(current)
60782+
60783+enum {
60784+ FLOODING,
60785+ NO_FLOODING
60786+};
60787+
60788+extern char *gr_alert_log_fmt;
60789+extern char *gr_audit_log_fmt;
60790+extern char *gr_alert_log_buf;
60791+extern char *gr_audit_log_buf;
60792+
60793+static int gr_log_start(int audit)
60794+{
60795+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
60796+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
60797+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
60798+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
60799+ unsigned long curr_secs = get_seconds();
60800+
60801+ if (audit == GR_DO_AUDIT)
60802+ goto set_fmt;
60803+
60804+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
60805+ grsec_alert_wtime = curr_secs;
60806+ grsec_alert_fyet = 0;
60807+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
60808+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
60809+ grsec_alert_fyet++;
60810+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
60811+ grsec_alert_wtime = curr_secs;
60812+ grsec_alert_fyet++;
60813+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
60814+ return FLOODING;
60815+ }
60816+ else return FLOODING;
60817+
60818+set_fmt:
60819+#endif
60820+ memset(buf, 0, PAGE_SIZE);
60821+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
60822+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
60823+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
60824+ } else if (current->signal->curr_ip) {
60825+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
60826+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
60827+ } else if (gr_acl_is_enabled()) {
60828+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
60829+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
60830+ } else {
60831+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
60832+ strcpy(buf, fmt);
60833+ }
60834+
60835+ return NO_FLOODING;
60836+}
60837+
60838+static void gr_log_middle(int audit, const char *msg, va_list ap)
60839+ __attribute__ ((format (printf, 2, 0)));
60840+
60841+static void gr_log_middle(int audit, const char *msg, va_list ap)
60842+{
60843+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
60844+ unsigned int len = strlen(buf);
60845+
60846+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
60847+
60848+ return;
60849+}
60850+
60851+static void gr_log_middle_varargs(int audit, const char *msg, ...)
60852+ __attribute__ ((format (printf, 2, 3)));
60853+
60854+static void gr_log_middle_varargs(int audit, const char *msg, ...)
60855+{
60856+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
60857+ unsigned int len = strlen(buf);
60858+ va_list ap;
60859+
60860+ va_start(ap, msg);
60861+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
60862+ va_end(ap);
60863+
60864+ return;
60865+}
60866+
60867+static void gr_log_end(int audit, int append_default)
60868+{
60869+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
60870+ if (append_default) {
60871+ struct task_struct *task = current;
60872+ struct task_struct *parent = task->real_parent;
60873+ const struct cred *cred = __task_cred(task);
60874+ const struct cred *pcred = __task_cred(parent);
60875+ unsigned int len = strlen(buf);
60876+
60877+ snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, gr_task_fullpath(task), task->comm, task_pid_nr(task), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), gr_parent_task_fullpath(task), parent->comm, task_pid_nr(task->real_parent), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid));
60878+ }
60879+
60880+ printk("%s\n", buf);
60881+
60882+ return;
60883+}
60884+
60885+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
60886+{
60887+ int logtype;
60888+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
60889+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
60890+ void *voidptr = NULL;
60891+ int num1 = 0, num2 = 0;
60892+ unsigned long ulong1 = 0, ulong2 = 0;
60893+ struct dentry *dentry = NULL;
60894+ struct vfsmount *mnt = NULL;
60895+ struct file *file = NULL;
60896+ struct task_struct *task = NULL;
60897+ const struct cred *cred, *pcred;
60898+ va_list ap;
60899+
60900+ BEGIN_LOCKS(audit);
60901+ logtype = gr_log_start(audit);
60902+ if (logtype == FLOODING) {
60903+ END_LOCKS(audit);
60904+ return;
60905+ }
60906+ va_start(ap, argtypes);
60907+ switch (argtypes) {
60908+ case GR_TTYSNIFF:
60909+ task = va_arg(ap, struct task_struct *);
60910+ gr_log_middle_varargs(audit, msg, &task->signal->curr_ip, gr_task_fullpath0(task), task->comm, task_pid_nr(task), gr_parent_task_fullpath0(task), task->real_parent->comm, task_pid_nr(task->real_parent));
60911+ break;
60912+ case GR_SYSCTL_HIDDEN:
60913+ str1 = va_arg(ap, char *);
60914+ gr_log_middle_varargs(audit, msg, result, str1);
60915+ break;
60916+ case GR_RBAC:
60917+ dentry = va_arg(ap, struct dentry *);
60918+ mnt = va_arg(ap, struct vfsmount *);
60919+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
60920+ break;
60921+ case GR_RBAC_STR:
60922+ dentry = va_arg(ap, struct dentry *);
60923+ mnt = va_arg(ap, struct vfsmount *);
60924+ str1 = va_arg(ap, char *);
60925+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
60926+ break;
60927+ case GR_STR_RBAC:
60928+ str1 = va_arg(ap, char *);
60929+ dentry = va_arg(ap, struct dentry *);
60930+ mnt = va_arg(ap, struct vfsmount *);
60931+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
60932+ break;
60933+ case GR_RBAC_MODE2:
60934+ dentry = va_arg(ap, struct dentry *);
60935+ mnt = va_arg(ap, struct vfsmount *);
60936+ str1 = va_arg(ap, char *);
60937+ str2 = va_arg(ap, char *);
60938+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
60939+ break;
60940+ case GR_RBAC_MODE3:
60941+ dentry = va_arg(ap, struct dentry *);
60942+ mnt = va_arg(ap, struct vfsmount *);
60943+ str1 = va_arg(ap, char *);
60944+ str2 = va_arg(ap, char *);
60945+ str3 = va_arg(ap, char *);
60946+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
60947+ break;
60948+ case GR_FILENAME:
60949+ dentry = va_arg(ap, struct dentry *);
60950+ mnt = va_arg(ap, struct vfsmount *);
60951+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
60952+ break;
60953+ case GR_STR_FILENAME:
60954+ str1 = va_arg(ap, char *);
60955+ dentry = va_arg(ap, struct dentry *);
60956+ mnt = va_arg(ap, struct vfsmount *);
60957+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
60958+ break;
60959+ case GR_FILENAME_STR:
60960+ dentry = va_arg(ap, struct dentry *);
60961+ mnt = va_arg(ap, struct vfsmount *);
60962+ str1 = va_arg(ap, char *);
60963+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
60964+ break;
60965+ case GR_FILENAME_TWO_INT:
60966+ dentry = va_arg(ap, struct dentry *);
60967+ mnt = va_arg(ap, struct vfsmount *);
60968+ num1 = va_arg(ap, int);
60969+ num2 = va_arg(ap, int);
60970+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
60971+ break;
60972+ case GR_FILENAME_TWO_INT_STR:
60973+ dentry = va_arg(ap, struct dentry *);
60974+ mnt = va_arg(ap, struct vfsmount *);
60975+ num1 = va_arg(ap, int);
60976+ num2 = va_arg(ap, int);
60977+ str1 = va_arg(ap, char *);
60978+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
60979+ break;
60980+ case GR_TEXTREL:
60981+ file = va_arg(ap, struct file *);
60982+ ulong1 = va_arg(ap, unsigned long);
60983+ ulong2 = va_arg(ap, unsigned long);
60984+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
60985+ break;
60986+ case GR_PTRACE:
60987+ task = va_arg(ap, struct task_struct *);
60988+ gr_log_middle_varargs(audit, msg, task->exec_file ? gr_to_filename(task->exec_file->f_path.dentry, task->exec_file->f_path.mnt) : "(none)", task->comm, task_pid_nr(task));
60989+ break;
60990+ case GR_RESOURCE:
60991+ task = va_arg(ap, struct task_struct *);
60992+ cred = __task_cred(task);
60993+ pcred = __task_cred(task->real_parent);
60994+ ulong1 = va_arg(ap, unsigned long);
60995+ str1 = va_arg(ap, char *);
60996+ ulong2 = va_arg(ap, unsigned long);
60997+ gr_log_middle_varargs(audit, msg, ulong1, str1, ulong2, gr_task_fullpath(task), task->comm, task_pid_nr(task), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), gr_parent_task_fullpath(task), task->real_parent->comm, task_pid_nr(task->real_parent), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid));
60998+ break;
60999+ case GR_CAP:
61000+ task = va_arg(ap, struct task_struct *);
61001+ cred = __task_cred(task);
61002+ pcred = __task_cred(task->real_parent);
61003+ str1 = va_arg(ap, char *);
61004+ gr_log_middle_varargs(audit, msg, str1, gr_task_fullpath(task), task->comm, task_pid_nr(task), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), gr_parent_task_fullpath(task), task->real_parent->comm, task_pid_nr(task->real_parent), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid));
61005+ break;
61006+ case GR_SIG:
61007+ str1 = va_arg(ap, char *);
61008+ voidptr = va_arg(ap, void *);
61009+ gr_log_middle_varargs(audit, msg, str1, voidptr);
61010+ break;
61011+ case GR_SIG2:
61012+ task = va_arg(ap, struct task_struct *);
61013+ cred = __task_cred(task);
61014+ pcred = __task_cred(task->real_parent);
61015+ num1 = va_arg(ap, int);
61016+ gr_log_middle_varargs(audit, msg, num1, gr_task_fullpath0(task), task->comm, task_pid_nr(task), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), gr_parent_task_fullpath0(task), task->real_parent->comm, task_pid_nr(task->real_parent), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid));
61017+ break;
61018+ case GR_CRASH1:
61019+ task = va_arg(ap, struct task_struct *);
61020+ cred = __task_cred(task);
61021+ pcred = __task_cred(task->real_parent);
61022+ ulong1 = va_arg(ap, unsigned long);
61023+ gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task_pid_nr(task), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), gr_parent_task_fullpath(task), task->real_parent->comm, task_pid_nr(task->real_parent), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid), GR_GLOBAL_UID(cred->uid), ulong1);
61024+ break;
61025+ case GR_CRASH2:
61026+ task = va_arg(ap, struct task_struct *);
61027+ cred = __task_cred(task);
61028+ pcred = __task_cred(task->real_parent);
61029+ ulong1 = va_arg(ap, unsigned long);
61030+ gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task_pid_nr(task), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), gr_parent_task_fullpath(task), task->real_parent->comm, task_pid_nr(task->real_parent), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid), ulong1);
61031+ break;
61032+ case GR_RWXMAP:
61033+ file = va_arg(ap, struct file *);
61034+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
61035+ break;
61036+ case GR_PSACCT:
61037+ {
61038+ unsigned int wday, cday;
61039+ __u8 whr, chr;
61040+ __u8 wmin, cmin;
61041+ __u8 wsec, csec;
61042+ char cur_tty[64] = { 0 };
61043+ char parent_tty[64] = { 0 };
61044+
61045+ task = va_arg(ap, struct task_struct *);
61046+ wday = va_arg(ap, unsigned int);
61047+ cday = va_arg(ap, unsigned int);
61048+ whr = va_arg(ap, int);
61049+ chr = va_arg(ap, int);
61050+ wmin = va_arg(ap, int);
61051+ cmin = va_arg(ap, int);
61052+ wsec = va_arg(ap, int);
61053+ csec = va_arg(ap, int);
61054+ ulong1 = va_arg(ap, unsigned long);
61055+ cred = __task_cred(task);
61056+ pcred = __task_cred(task->real_parent);
61057+
61058+ gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task_pid_nr(task), &task->signal->curr_ip, tty_name(task->signal->tty, cur_tty), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), wday, whr, wmin, wsec, cday, chr, cmin, csec, (task->flags & PF_SIGNALED) ? "killed by signal" : "exited", ulong1, gr_parent_task_fullpath(task), task->real_parent->comm, task_pid_nr(task->real_parent), &task->real_parent->signal->curr_ip, tty_name(task->real_parent->signal->tty, parent_tty), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid));
61059+ }
61060+ break;
61061+ default:
61062+ gr_log_middle(audit, msg, ap);
61063+ }
61064+ va_end(ap);
61065+ // these don't need DEFAULTSECARGS printed on the end
61066+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
61067+ gr_log_end(audit, 0);
61068+ else
61069+ gr_log_end(audit, 1);
61070+ END_LOCKS(audit);
61071+}
61072diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
61073new file mode 100644
61074index 0000000..f536303
61075--- /dev/null
61076+++ b/grsecurity/grsec_mem.c
61077@@ -0,0 +1,40 @@
61078+#include <linux/kernel.h>
61079+#include <linux/sched.h>
61080+#include <linux/mm.h>
61081+#include <linux/mman.h>
61082+#include <linux/grinternal.h>
61083+
61084+void
61085+gr_handle_ioperm(void)
61086+{
61087+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
61088+ return;
61089+}
61090+
61091+void
61092+gr_handle_iopl(void)
61093+{
61094+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
61095+ return;
61096+}
61097+
61098+void
61099+gr_handle_mem_readwrite(u64 from, u64 to)
61100+{
61101+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
61102+ return;
61103+}
61104+
61105+void
61106+gr_handle_vm86(void)
61107+{
61108+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
61109+ return;
61110+}
61111+
61112+void
61113+gr_log_badprocpid(const char *entry)
61114+{
61115+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
61116+ return;
61117+}
61118diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
61119new file mode 100644
61120index 0000000..2131422
61121--- /dev/null
61122+++ b/grsecurity/grsec_mount.c
61123@@ -0,0 +1,62 @@
61124+#include <linux/kernel.h>
61125+#include <linux/sched.h>
61126+#include <linux/mount.h>
61127+#include <linux/grsecurity.h>
61128+#include <linux/grinternal.h>
61129+
61130+void
61131+gr_log_remount(const char *devname, const int retval)
61132+{
61133+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
61134+ if (grsec_enable_mount && (retval >= 0))
61135+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
61136+#endif
61137+ return;
61138+}
61139+
61140+void
61141+gr_log_unmount(const char *devname, const int retval)
61142+{
61143+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
61144+ if (grsec_enable_mount && (retval >= 0))
61145+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
61146+#endif
61147+ return;
61148+}
61149+
61150+void
61151+gr_log_mount(const char *from, const char *to, const int retval)
61152+{
61153+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
61154+ if (grsec_enable_mount && (retval >= 0))
61155+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
61156+#endif
61157+ return;
61158+}
61159+
61160+int
61161+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
61162+{
61163+#ifdef CONFIG_GRKERNSEC_ROFS
61164+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
61165+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
61166+ return -EPERM;
61167+ } else
61168+ return 0;
61169+#endif
61170+ return 0;
61171+}
61172+
61173+int
61174+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
61175+{
61176+#ifdef CONFIG_GRKERNSEC_ROFS
61177+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
61178+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
61179+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
61180+ return -EPERM;
61181+ } else
61182+ return 0;
61183+#endif
61184+ return 0;
61185+}
61186diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
61187new file mode 100644
61188index 0000000..a3b12a0
61189--- /dev/null
61190+++ b/grsecurity/grsec_pax.c
61191@@ -0,0 +1,36 @@
61192+#include <linux/kernel.h>
61193+#include <linux/sched.h>
61194+#include <linux/mm.h>
61195+#include <linux/file.h>
61196+#include <linux/grinternal.h>
61197+#include <linux/grsecurity.h>
61198+
61199+void
61200+gr_log_textrel(struct vm_area_struct * vma)
61201+{
61202+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
61203+ if (grsec_enable_audit_textrel)
61204+ gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
61205+#endif
61206+ return;
61207+}
61208+
61209+void
61210+gr_log_rwxmmap(struct file *file)
61211+{
61212+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
61213+ if (grsec_enable_log_rwxmaps)
61214+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
61215+#endif
61216+ return;
61217+}
61218+
61219+void
61220+gr_log_rwxmprotect(struct file *file)
61221+{
61222+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
61223+ if (grsec_enable_log_rwxmaps)
61224+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
61225+#endif
61226+ return;
61227+}
61228diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
61229new file mode 100644
61230index 0000000..f7f29aa
61231--- /dev/null
61232+++ b/grsecurity/grsec_ptrace.c
61233@@ -0,0 +1,30 @@
61234+#include <linux/kernel.h>
61235+#include <linux/sched.h>
61236+#include <linux/grinternal.h>
61237+#include <linux/security.h>
61238+
61239+void
61240+gr_audit_ptrace(struct task_struct *task)
61241+{
61242+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
61243+ if (grsec_enable_audit_ptrace)
61244+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
61245+#endif
61246+ return;
61247+}
61248+
61249+int
61250+gr_ptrace_readexec(struct file *file, int unsafe_flags)
61251+{
61252+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
61253+ const struct dentry *dentry = file->f_path.dentry;
61254+ const struct vfsmount *mnt = file->f_path.mnt;
61255+
61256+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
61257+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
61258+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
61259+ return -EACCES;
61260+ }
61261+#endif
61262+ return 0;
61263+}
61264diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
61265new file mode 100644
61266index 0000000..5c00416
61267--- /dev/null
61268+++ b/grsecurity/grsec_sig.c
61269@@ -0,0 +1,222 @@
61270+#include <linux/kernel.h>
61271+#include <linux/sched.h>
61272+#include <linux/delay.h>
61273+#include <linux/grsecurity.h>
61274+#include <linux/grinternal.h>
61275+#include <linux/hardirq.h>
61276+
61277+char *signames[] = {
61278+ [SIGSEGV] = "Segmentation fault",
61279+ [SIGILL] = "Illegal instruction",
61280+ [SIGABRT] = "Abort",
61281+ [SIGBUS] = "Invalid alignment/Bus error"
61282+};
61283+
61284+void
61285+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
61286+{
61287+#ifdef CONFIG_GRKERNSEC_SIGNAL
61288+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
61289+ (sig == SIGABRT) || (sig == SIGBUS))) {
61290+ if (t->pid == current->pid) {
61291+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
61292+ } else {
61293+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
61294+ }
61295+ }
61296+#endif
61297+ return;
61298+}
61299+
61300+int
61301+gr_handle_signal(const struct task_struct *p, const int sig)
61302+{
61303+#ifdef CONFIG_GRKERNSEC
61304+ /* ignore the 0 signal for protected task checks */
61305+ if (current->pid > 1 && sig && gr_check_protected_task(p)) {
61306+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
61307+ return -EPERM;
61308+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
61309+ return -EPERM;
61310+ }
61311+#endif
61312+ return 0;
61313+}
61314+
61315+#ifdef CONFIG_GRKERNSEC
61316+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
61317+
61318+int gr_fake_force_sig(int sig, struct task_struct *t)
61319+{
61320+ unsigned long int flags;
61321+ int ret, blocked, ignored;
61322+ struct k_sigaction *action;
61323+
61324+ spin_lock_irqsave(&t->sighand->siglock, flags);
61325+ action = &t->sighand->action[sig-1];
61326+ ignored = action->sa.sa_handler == SIG_IGN;
61327+ blocked = sigismember(&t->blocked, sig);
61328+ if (blocked || ignored) {
61329+ action->sa.sa_handler = SIG_DFL;
61330+ if (blocked) {
61331+ sigdelset(&t->blocked, sig);
61332+ recalc_sigpending_and_wake(t);
61333+ }
61334+ }
61335+ if (action->sa.sa_handler == SIG_DFL)
61336+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
61337+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
61338+
61339+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
61340+
61341+ return ret;
61342+}
61343+#endif
61344+
61345+#ifdef CONFIG_GRKERNSEC_BRUTE
61346+#define GR_USER_BAN_TIME (15 * 60)
61347+#define GR_DAEMON_BRUTE_TIME (30 * 60)
61348+
61349+static int __get_dumpable(unsigned long mm_flags)
61350+{
61351+ int ret;
61352+
61353+ ret = mm_flags & MMF_DUMPABLE_MASK;
61354+ return (ret >= 2) ? 2 : ret;
61355+}
61356+#endif
61357+
61358+void gr_handle_brute_attach(unsigned long mm_flags)
61359+{
61360+#ifdef CONFIG_GRKERNSEC_BRUTE
61361+ struct task_struct *p = current;
61362+ kuid_t uid = GLOBAL_ROOT_UID;
61363+ int daemon = 0;
61364+
61365+ if (!grsec_enable_brute)
61366+ return;
61367+
61368+ rcu_read_lock();
61369+ read_lock(&tasklist_lock);
61370+ read_lock(&grsec_exec_file_lock);
61371+ if (p->real_parent && p->real_parent->exec_file == p->exec_file) {
61372+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
61373+ p->real_parent->brute = 1;
61374+ daemon = 1;
61375+ } else {
61376+ const struct cred *cred = __task_cred(p), *cred2;
61377+ struct task_struct *tsk, *tsk2;
61378+
61379+ if (!__get_dumpable(mm_flags) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
61380+ struct user_struct *user;
61381+
61382+ uid = cred->uid;
61383+
61384+ /* this is put upon execution past expiration */
61385+ user = find_user(uid);
61386+ if (user == NULL)
61387+ goto unlock;
61388+ user->banned = 1;
61389+ user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
61390+ if (user->ban_expires == ~0UL)
61391+ user->ban_expires--;
61392+
61393+ do_each_thread(tsk2, tsk) {
61394+ cred2 = __task_cred(tsk);
61395+ if (tsk != p && uid_eq(cred2->uid, uid))
61396+ gr_fake_force_sig(SIGKILL, tsk);
61397+ } while_each_thread(tsk2, tsk);
61398+ }
61399+ }
61400+unlock:
61401+ read_unlock(&grsec_exec_file_lock);
61402+ read_unlock(&tasklist_lock);
61403+ rcu_read_unlock();
61404+
61405+ if (!uid_eq(uid, GLOBAL_ROOT_UID))
61406+ printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
61407+ from_kuid_munged(&init_user_ns, uid), GR_USER_BAN_TIME / 60);
61408+ else if (daemon)
61409+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
61410+
61411+#endif
61412+ return;
61413+}
61414+
61415+void gr_handle_brute_check(void)
61416+{
61417+#ifdef CONFIG_GRKERNSEC_BRUTE
61418+ struct task_struct *p = current;
61419+
61420+ if (unlikely(p->brute)) {
61421+ if (!grsec_enable_brute)
61422+ p->brute = 0;
61423+ else if (time_before(get_seconds(), p->brute_expires))
61424+ msleep(30 * 1000);
61425+ }
61426+#endif
61427+ return;
61428+}
61429+
61430+void gr_handle_kernel_exploit(void)
61431+{
61432+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
61433+ const struct cred *cred;
61434+ struct task_struct *tsk, *tsk2;
61435+ struct user_struct *user;
61436+ kuid_t uid;
61437+
61438+ if (in_irq() || in_serving_softirq() || in_nmi())
61439+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
61440+
61441+ uid = current_uid();
61442+
61443+ if (uid_eq(uid, GLOBAL_ROOT_UID))
61444+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
61445+ else {
61446+ /* kill all the processes of this user, hold a reference
61447+ to their creds struct, and prevent them from creating
61448+ another process until system reset
61449+ */
61450+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
61451+ from_kuid_munged(&init_user_ns, uid));
61452+ /* we intentionally leak this ref */
61453+ user = get_uid(current->cred->user);
61454+ if (user) {
61455+ user->banned = 1;
61456+ user->ban_expires = ~0UL;
61457+ }
61458+
61459+ read_lock(&tasklist_lock);
61460+ do_each_thread(tsk2, tsk) {
61461+ cred = __task_cred(tsk);
61462+ if (uid_eq(cred->uid, uid))
61463+ gr_fake_force_sig(SIGKILL, tsk);
61464+ } while_each_thread(tsk2, tsk);
61465+ read_unlock(&tasklist_lock);
61466+ }
61467+#endif
61468+}
61469+
61470+int __gr_process_user_ban(struct user_struct *user)
61471+{
61472+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
61473+ if (unlikely(user->banned)) {
61474+ if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
61475+ user->banned = 0;
61476+ user->ban_expires = 0;
61477+ free_uid(user);
61478+ } else
61479+ return -EPERM;
61480+ }
61481+#endif
61482+ return 0;
61483+}
61484+
61485+int gr_process_user_ban(void)
61486+{
61487+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
61488+ return __gr_process_user_ban(current->cred->user);
61489+#endif
61490+ return 0;
61491+}
61492diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
61493new file mode 100644
61494index 0000000..4030d57
61495--- /dev/null
61496+++ b/grsecurity/grsec_sock.c
61497@@ -0,0 +1,244 @@
61498+#include <linux/kernel.h>
61499+#include <linux/module.h>
61500+#include <linux/sched.h>
61501+#include <linux/file.h>
61502+#include <linux/net.h>
61503+#include <linux/in.h>
61504+#include <linux/ip.h>
61505+#include <net/sock.h>
61506+#include <net/inet_sock.h>
61507+#include <linux/grsecurity.h>
61508+#include <linux/grinternal.h>
61509+#include <linux/gracl.h>
61510+
61511+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
61512+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
61513+
61514+EXPORT_SYMBOL(gr_search_udp_recvmsg);
61515+EXPORT_SYMBOL(gr_search_udp_sendmsg);
61516+
61517+#ifdef CONFIG_UNIX_MODULE
61518+EXPORT_SYMBOL(gr_acl_handle_unix);
61519+EXPORT_SYMBOL(gr_acl_handle_mknod);
61520+EXPORT_SYMBOL(gr_handle_chroot_unix);
61521+EXPORT_SYMBOL(gr_handle_create);
61522+#endif
61523+
61524+#ifdef CONFIG_GRKERNSEC
61525+#define gr_conn_table_size 32749
61526+struct conn_table_entry {
61527+ struct conn_table_entry *next;
61528+ struct signal_struct *sig;
61529+};
61530+
61531+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
61532+DEFINE_SPINLOCK(gr_conn_table_lock);
61533+
61534+extern const char * gr_socktype_to_name(unsigned char type);
61535+extern const char * gr_proto_to_name(unsigned char proto);
61536+extern const char * gr_sockfamily_to_name(unsigned char family);
61537+
61538+static __inline__ int
61539+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
61540+{
61541+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
61542+}
61543+
61544+static __inline__ int
61545+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
61546+ __u16 sport, __u16 dport)
61547+{
61548+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
61549+ sig->gr_sport == sport && sig->gr_dport == dport))
61550+ return 1;
61551+ else
61552+ return 0;
61553+}
61554+
61555+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
61556+{
61557+ struct conn_table_entry **match;
61558+ unsigned int index;
61559+
61560+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
61561+ sig->gr_sport, sig->gr_dport,
61562+ gr_conn_table_size);
61563+
61564+ newent->sig = sig;
61565+
61566+ match = &gr_conn_table[index];
61567+ newent->next = *match;
61568+ *match = newent;
61569+
61570+ return;
61571+}
61572+
61573+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
61574+{
61575+ struct conn_table_entry *match, *last = NULL;
61576+ unsigned int index;
61577+
61578+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
61579+ sig->gr_sport, sig->gr_dport,
61580+ gr_conn_table_size);
61581+
61582+ match = gr_conn_table[index];
61583+ while (match && !conn_match(match->sig,
61584+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
61585+ sig->gr_dport)) {
61586+ last = match;
61587+ match = match->next;
61588+ }
61589+
61590+ if (match) {
61591+ if (last)
61592+ last->next = match->next;
61593+ else
61594+ gr_conn_table[index] = NULL;
61595+ kfree(match);
61596+ }
61597+
61598+ return;
61599+}
61600+
61601+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
61602+ __u16 sport, __u16 dport)
61603+{
61604+ struct conn_table_entry *match;
61605+ unsigned int index;
61606+
61607+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
61608+
61609+ match = gr_conn_table[index];
61610+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
61611+ match = match->next;
61612+
61613+ if (match)
61614+ return match->sig;
61615+ else
61616+ return NULL;
61617+}
61618+
61619+#endif
61620+
61621+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
61622+{
61623+#ifdef CONFIG_GRKERNSEC
61624+ struct signal_struct *sig = task->signal;
61625+ struct conn_table_entry *newent;
61626+
61627+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
61628+ if (newent == NULL)
61629+ return;
61630+ /* no bh lock needed since we are called with bh disabled */
61631+ spin_lock(&gr_conn_table_lock);
61632+ gr_del_task_from_ip_table_nolock(sig);
61633+ sig->gr_saddr = inet->inet_rcv_saddr;
61634+ sig->gr_daddr = inet->inet_daddr;
61635+ sig->gr_sport = inet->inet_sport;
61636+ sig->gr_dport = inet->inet_dport;
61637+ gr_add_to_task_ip_table_nolock(sig, newent);
61638+ spin_unlock(&gr_conn_table_lock);
61639+#endif
61640+ return;
61641+}
61642+
61643+void gr_del_task_from_ip_table(struct task_struct *task)
61644+{
61645+#ifdef CONFIG_GRKERNSEC
61646+ spin_lock_bh(&gr_conn_table_lock);
61647+ gr_del_task_from_ip_table_nolock(task->signal);
61648+ spin_unlock_bh(&gr_conn_table_lock);
61649+#endif
61650+ return;
61651+}
61652+
61653+void
61654+gr_attach_curr_ip(const struct sock *sk)
61655+{
61656+#ifdef CONFIG_GRKERNSEC
61657+ struct signal_struct *p, *set;
61658+ const struct inet_sock *inet = inet_sk(sk);
61659+
61660+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
61661+ return;
61662+
61663+ set = current->signal;
61664+
61665+ spin_lock_bh(&gr_conn_table_lock);
61666+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
61667+ inet->inet_dport, inet->inet_sport);
61668+ if (unlikely(p != NULL)) {
61669+ set->curr_ip = p->curr_ip;
61670+ set->used_accept = 1;
61671+ gr_del_task_from_ip_table_nolock(p);
61672+ spin_unlock_bh(&gr_conn_table_lock);
61673+ return;
61674+ }
61675+ spin_unlock_bh(&gr_conn_table_lock);
61676+
61677+ set->curr_ip = inet->inet_daddr;
61678+ set->used_accept = 1;
61679+#endif
61680+ return;
61681+}
61682+
61683+int
61684+gr_handle_sock_all(const int family, const int type, const int protocol)
61685+{
61686+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
61687+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
61688+ (family != AF_UNIX)) {
61689+ if (family == AF_INET)
61690+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
61691+ else
61692+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
61693+ return -EACCES;
61694+ }
61695+#endif
61696+ return 0;
61697+}
61698+
61699+int
61700+gr_handle_sock_server(const struct sockaddr *sck)
61701+{
61702+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
61703+ if (grsec_enable_socket_server &&
61704+ in_group_p(grsec_socket_server_gid) &&
61705+ sck && (sck->sa_family != AF_UNIX) &&
61706+ (sck->sa_family != AF_LOCAL)) {
61707+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
61708+ return -EACCES;
61709+ }
61710+#endif
61711+ return 0;
61712+}
61713+
61714+int
61715+gr_handle_sock_server_other(const struct sock *sck)
61716+{
61717+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
61718+ if (grsec_enable_socket_server &&
61719+ in_group_p(grsec_socket_server_gid) &&
61720+ sck && (sck->sk_family != AF_UNIX) &&
61721+ (sck->sk_family != AF_LOCAL)) {
61722+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
61723+ return -EACCES;
61724+ }
61725+#endif
61726+ return 0;
61727+}
61728+
61729+int
61730+gr_handle_sock_client(const struct sockaddr *sck)
61731+{
61732+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
61733+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
61734+ sck && (sck->sa_family != AF_UNIX) &&
61735+ (sck->sa_family != AF_LOCAL)) {
61736+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
61737+ return -EACCES;
61738+ }
61739+#endif
61740+ return 0;
61741+}
61742diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
61743new file mode 100644
61744index 0000000..f55ef0f
61745--- /dev/null
61746+++ b/grsecurity/grsec_sysctl.c
61747@@ -0,0 +1,469 @@
61748+#include <linux/kernel.h>
61749+#include <linux/sched.h>
61750+#include <linux/sysctl.h>
61751+#include <linux/grsecurity.h>
61752+#include <linux/grinternal.h>
61753+
61754+int
61755+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
61756+{
61757+#ifdef CONFIG_GRKERNSEC_SYSCTL
61758+ if (dirname == NULL || name == NULL)
61759+ return 0;
61760+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
61761+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
61762+ return -EACCES;
61763+ }
61764+#endif
61765+ return 0;
61766+}
61767+
61768+#ifdef CONFIG_GRKERNSEC_ROFS
61769+static int __maybe_unused one = 1;
61770+#endif
61771+
61772+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
61773+struct ctl_table grsecurity_table[] = {
61774+#ifdef CONFIG_GRKERNSEC_SYSCTL
61775+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
61776+#ifdef CONFIG_GRKERNSEC_IO
61777+ {
61778+ .procname = "disable_priv_io",
61779+ .data = &grsec_disable_privio,
61780+ .maxlen = sizeof(int),
61781+ .mode = 0600,
61782+ .proc_handler = &proc_dointvec,
61783+ },
61784+#endif
61785+#endif
61786+#ifdef CONFIG_GRKERNSEC_LINK
61787+ {
61788+ .procname = "linking_restrictions",
61789+ .data = &grsec_enable_link,
61790+ .maxlen = sizeof(int),
61791+ .mode = 0600,
61792+ .proc_handler = &proc_dointvec,
61793+ },
61794+#endif
61795+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
61796+ {
61797+ .procname = "enforce_symlinksifowner",
61798+ .data = &grsec_enable_symlinkown,
61799+ .maxlen = sizeof(int),
61800+ .mode = 0600,
61801+ .proc_handler = &proc_dointvec,
61802+ },
61803+ {
61804+ .procname = "symlinkown_gid",
61805+ .data = &grsec_symlinkown_gid,
61806+ .maxlen = sizeof(int),
61807+ .mode = 0600,
61808+ .proc_handler = &proc_dointvec,
61809+ },
61810+#endif
61811+#ifdef CONFIG_GRKERNSEC_BRUTE
61812+ {
61813+ .procname = "deter_bruteforce",
61814+ .data = &grsec_enable_brute,
61815+ .maxlen = sizeof(int),
61816+ .mode = 0600,
61817+ .proc_handler = &proc_dointvec,
61818+ },
61819+#endif
61820+#ifdef CONFIG_GRKERNSEC_FIFO
61821+ {
61822+ .procname = "fifo_restrictions",
61823+ .data = &grsec_enable_fifo,
61824+ .maxlen = sizeof(int),
61825+ .mode = 0600,
61826+ .proc_handler = &proc_dointvec,
61827+ },
61828+#endif
61829+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
61830+ {
61831+ .procname = "ptrace_readexec",
61832+ .data = &grsec_enable_ptrace_readexec,
61833+ .maxlen = sizeof(int),
61834+ .mode = 0600,
61835+ .proc_handler = &proc_dointvec,
61836+ },
61837+#endif
61838+#ifdef CONFIG_GRKERNSEC_SETXID
61839+ {
61840+ .procname = "consistent_setxid",
61841+ .data = &grsec_enable_setxid,
61842+ .maxlen = sizeof(int),
61843+ .mode = 0600,
61844+ .proc_handler = &proc_dointvec,
61845+ },
61846+#endif
61847+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
61848+ {
61849+ .procname = "ip_blackhole",
61850+ .data = &grsec_enable_blackhole,
61851+ .maxlen = sizeof(int),
61852+ .mode = 0600,
61853+ .proc_handler = &proc_dointvec,
61854+ },
61855+ {
61856+ .procname = "lastack_retries",
61857+ .data = &grsec_lastack_retries,
61858+ .maxlen = sizeof(int),
61859+ .mode = 0600,
61860+ .proc_handler = &proc_dointvec,
61861+ },
61862+#endif
61863+#ifdef CONFIG_GRKERNSEC_EXECLOG
61864+ {
61865+ .procname = "exec_logging",
61866+ .data = &grsec_enable_execlog,
61867+ .maxlen = sizeof(int),
61868+ .mode = 0600,
61869+ .proc_handler = &proc_dointvec,
61870+ },
61871+#endif
61872+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
61873+ {
61874+ .procname = "rwxmap_logging",
61875+ .data = &grsec_enable_log_rwxmaps,
61876+ .maxlen = sizeof(int),
61877+ .mode = 0600,
61878+ .proc_handler = &proc_dointvec,
61879+ },
61880+#endif
61881+#ifdef CONFIG_GRKERNSEC_SIGNAL
61882+ {
61883+ .procname = "signal_logging",
61884+ .data = &grsec_enable_signal,
61885+ .maxlen = sizeof(int),
61886+ .mode = 0600,
61887+ .proc_handler = &proc_dointvec,
61888+ },
61889+#endif
61890+#ifdef CONFIG_GRKERNSEC_FORKFAIL
61891+ {
61892+ .procname = "forkfail_logging",
61893+ .data = &grsec_enable_forkfail,
61894+ .maxlen = sizeof(int),
61895+ .mode = 0600,
61896+ .proc_handler = &proc_dointvec,
61897+ },
61898+#endif
61899+#ifdef CONFIG_GRKERNSEC_TIME
61900+ {
61901+ .procname = "timechange_logging",
61902+ .data = &grsec_enable_time,
61903+ .maxlen = sizeof(int),
61904+ .mode = 0600,
61905+ .proc_handler = &proc_dointvec,
61906+ },
61907+#endif
61908+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
61909+ {
61910+ .procname = "chroot_deny_shmat",
61911+ .data = &grsec_enable_chroot_shmat,
61912+ .maxlen = sizeof(int),
61913+ .mode = 0600,
61914+ .proc_handler = &proc_dointvec,
61915+ },
61916+#endif
61917+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
61918+ {
61919+ .procname = "chroot_deny_unix",
61920+ .data = &grsec_enable_chroot_unix,
61921+ .maxlen = sizeof(int),
61922+ .mode = 0600,
61923+ .proc_handler = &proc_dointvec,
61924+ },
61925+#endif
61926+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
61927+ {
61928+ .procname = "chroot_deny_mount",
61929+ .data = &grsec_enable_chroot_mount,
61930+ .maxlen = sizeof(int),
61931+ .mode = 0600,
61932+ .proc_handler = &proc_dointvec,
61933+ },
61934+#endif
61935+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
61936+ {
61937+ .procname = "chroot_deny_fchdir",
61938+ .data = &grsec_enable_chroot_fchdir,
61939+ .maxlen = sizeof(int),
61940+ .mode = 0600,
61941+ .proc_handler = &proc_dointvec,
61942+ },
61943+#endif
61944+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
61945+ {
61946+ .procname = "chroot_deny_chroot",
61947+ .data = &grsec_enable_chroot_double,
61948+ .maxlen = sizeof(int),
61949+ .mode = 0600,
61950+ .proc_handler = &proc_dointvec,
61951+ },
61952+#endif
61953+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
61954+ {
61955+ .procname = "chroot_deny_pivot",
61956+ .data = &grsec_enable_chroot_pivot,
61957+ .maxlen = sizeof(int),
61958+ .mode = 0600,
61959+ .proc_handler = &proc_dointvec,
61960+ },
61961+#endif
61962+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
61963+ {
61964+ .procname = "chroot_enforce_chdir",
61965+ .data = &grsec_enable_chroot_chdir,
61966+ .maxlen = sizeof(int),
61967+ .mode = 0600,
61968+ .proc_handler = &proc_dointvec,
61969+ },
61970+#endif
61971+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
61972+ {
61973+ .procname = "chroot_deny_chmod",
61974+ .data = &grsec_enable_chroot_chmod,
61975+ .maxlen = sizeof(int),
61976+ .mode = 0600,
61977+ .proc_handler = &proc_dointvec,
61978+ },
61979+#endif
61980+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
61981+ {
61982+ .procname = "chroot_deny_mknod",
61983+ .data = &grsec_enable_chroot_mknod,
61984+ .maxlen = sizeof(int),
61985+ .mode = 0600,
61986+ .proc_handler = &proc_dointvec,
61987+ },
61988+#endif
61989+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
61990+ {
61991+ .procname = "chroot_restrict_nice",
61992+ .data = &grsec_enable_chroot_nice,
61993+ .maxlen = sizeof(int),
61994+ .mode = 0600,
61995+ .proc_handler = &proc_dointvec,
61996+ },
61997+#endif
61998+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
61999+ {
62000+ .procname = "chroot_execlog",
62001+ .data = &grsec_enable_chroot_execlog,
62002+ .maxlen = sizeof(int),
62003+ .mode = 0600,
62004+ .proc_handler = &proc_dointvec,
62005+ },
62006+#endif
62007+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
62008+ {
62009+ .procname = "chroot_caps",
62010+ .data = &grsec_enable_chroot_caps,
62011+ .maxlen = sizeof(int),
62012+ .mode = 0600,
62013+ .proc_handler = &proc_dointvec,
62014+ },
62015+#endif
62016+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
62017+ {
62018+ .procname = "chroot_deny_sysctl",
62019+ .data = &grsec_enable_chroot_sysctl,
62020+ .maxlen = sizeof(int),
62021+ .mode = 0600,
62022+ .proc_handler = &proc_dointvec,
62023+ },
62024+#endif
62025+#ifdef CONFIG_GRKERNSEC_TPE
62026+ {
62027+ .procname = "tpe",
62028+ .data = &grsec_enable_tpe,
62029+ .maxlen = sizeof(int),
62030+ .mode = 0600,
62031+ .proc_handler = &proc_dointvec,
62032+ },
62033+ {
62034+ .procname = "tpe_gid",
62035+ .data = &grsec_tpe_gid,
62036+ .maxlen = sizeof(int),
62037+ .mode = 0600,
62038+ .proc_handler = &proc_dointvec,
62039+ },
62040+#endif
62041+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
62042+ {
62043+ .procname = "tpe_invert",
62044+ .data = &grsec_enable_tpe_invert,
62045+ .maxlen = sizeof(int),
62046+ .mode = 0600,
62047+ .proc_handler = &proc_dointvec,
62048+ },
62049+#endif
62050+#ifdef CONFIG_GRKERNSEC_TPE_ALL
62051+ {
62052+ .procname = "tpe_restrict_all",
62053+ .data = &grsec_enable_tpe_all,
62054+ .maxlen = sizeof(int),
62055+ .mode = 0600,
62056+ .proc_handler = &proc_dointvec,
62057+ },
62058+#endif
62059+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
62060+ {
62061+ .procname = "socket_all",
62062+ .data = &grsec_enable_socket_all,
62063+ .maxlen = sizeof(int),
62064+ .mode = 0600,
62065+ .proc_handler = &proc_dointvec,
62066+ },
62067+ {
62068+ .procname = "socket_all_gid",
62069+ .data = &grsec_socket_all_gid,
62070+ .maxlen = sizeof(int),
62071+ .mode = 0600,
62072+ .proc_handler = &proc_dointvec,
62073+ },
62074+#endif
62075+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
62076+ {
62077+ .procname = "socket_client",
62078+ .data = &grsec_enable_socket_client,
62079+ .maxlen = sizeof(int),
62080+ .mode = 0600,
62081+ .proc_handler = &proc_dointvec,
62082+ },
62083+ {
62084+ .procname = "socket_client_gid",
62085+ .data = &grsec_socket_client_gid,
62086+ .maxlen = sizeof(int),
62087+ .mode = 0600,
62088+ .proc_handler = &proc_dointvec,
62089+ },
62090+#endif
62091+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
62092+ {
62093+ .procname = "socket_server",
62094+ .data = &grsec_enable_socket_server,
62095+ .maxlen = sizeof(int),
62096+ .mode = 0600,
62097+ .proc_handler = &proc_dointvec,
62098+ },
62099+ {
62100+ .procname = "socket_server_gid",
62101+ .data = &grsec_socket_server_gid,
62102+ .maxlen = sizeof(int),
62103+ .mode = 0600,
62104+ .proc_handler = &proc_dointvec,
62105+ },
62106+#endif
62107+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
62108+ {
62109+ .procname = "audit_group",
62110+ .data = &grsec_enable_group,
62111+ .maxlen = sizeof(int),
62112+ .mode = 0600,
62113+ .proc_handler = &proc_dointvec,
62114+ },
62115+ {
62116+ .procname = "audit_gid",
62117+ .data = &grsec_audit_gid,
62118+ .maxlen = sizeof(int),
62119+ .mode = 0600,
62120+ .proc_handler = &proc_dointvec,
62121+ },
62122+#endif
62123+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
62124+ {
62125+ .procname = "audit_chdir",
62126+ .data = &grsec_enable_chdir,
62127+ .maxlen = sizeof(int),
62128+ .mode = 0600,
62129+ .proc_handler = &proc_dointvec,
62130+ },
62131+#endif
62132+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
62133+ {
62134+ .procname = "audit_mount",
62135+ .data = &grsec_enable_mount,
62136+ .maxlen = sizeof(int),
62137+ .mode = 0600,
62138+ .proc_handler = &proc_dointvec,
62139+ },
62140+#endif
62141+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
62142+ {
62143+ .procname = "audit_textrel",
62144+ .data = &grsec_enable_audit_textrel,
62145+ .maxlen = sizeof(int),
62146+ .mode = 0600,
62147+ .proc_handler = &proc_dointvec,
62148+ },
62149+#endif
62150+#ifdef CONFIG_GRKERNSEC_DMESG
62151+ {
62152+ .procname = "dmesg",
62153+ .data = &grsec_enable_dmesg,
62154+ .maxlen = sizeof(int),
62155+ .mode = 0600,
62156+ .proc_handler = &proc_dointvec,
62157+ },
62158+#endif
62159+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
62160+ {
62161+ .procname = "chroot_findtask",
62162+ .data = &grsec_enable_chroot_findtask,
62163+ .maxlen = sizeof(int),
62164+ .mode = 0600,
62165+ .proc_handler = &proc_dointvec,
62166+ },
62167+#endif
62168+#ifdef CONFIG_GRKERNSEC_RESLOG
62169+ {
62170+ .procname = "resource_logging",
62171+ .data = &grsec_resource_logging,
62172+ .maxlen = sizeof(int),
62173+ .mode = 0600,
62174+ .proc_handler = &proc_dointvec,
62175+ },
62176+#endif
62177+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
62178+ {
62179+ .procname = "audit_ptrace",
62180+ .data = &grsec_enable_audit_ptrace,
62181+ .maxlen = sizeof(int),
62182+ .mode = 0600,
62183+ .proc_handler = &proc_dointvec,
62184+ },
62185+#endif
62186+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
62187+ {
62188+ .procname = "harden_ptrace",
62189+ .data = &grsec_enable_harden_ptrace,
62190+ .maxlen = sizeof(int),
62191+ .mode = 0600,
62192+ .proc_handler = &proc_dointvec,
62193+ },
62194+#endif
62195+ {
62196+ .procname = "grsec_lock",
62197+ .data = &grsec_lock,
62198+ .maxlen = sizeof(int),
62199+ .mode = 0600,
62200+ .proc_handler = &proc_dointvec,
62201+ },
62202+#endif
62203+#ifdef CONFIG_GRKERNSEC_ROFS
62204+ {
62205+ .procname = "romount_protect",
62206+ .data = &grsec_enable_rofs,
62207+ .maxlen = sizeof(int),
62208+ .mode = 0600,
62209+ .proc_handler = &proc_dointvec_minmax,
62210+ .extra1 = &one,
62211+ .extra2 = &one,
62212+ },
62213+#endif
62214+ { }
62215+};
62216+#endif
62217diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
62218new file mode 100644
62219index 0000000..0dc13c3
62220--- /dev/null
62221+++ b/grsecurity/grsec_time.c
62222@@ -0,0 +1,16 @@
62223+#include <linux/kernel.h>
62224+#include <linux/sched.h>
62225+#include <linux/grinternal.h>
62226+#include <linux/module.h>
62227+
62228+void
62229+gr_log_timechange(void)
62230+{
62231+#ifdef CONFIG_GRKERNSEC_TIME
62232+ if (grsec_enable_time)
62233+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
62234+#endif
62235+ return;
62236+}
62237+
62238+EXPORT_SYMBOL(gr_log_timechange);
62239diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
62240new file mode 100644
62241index 0000000..07e0dc0
62242--- /dev/null
62243+++ b/grsecurity/grsec_tpe.c
62244@@ -0,0 +1,73 @@
62245+#include <linux/kernel.h>
62246+#include <linux/sched.h>
62247+#include <linux/file.h>
62248+#include <linux/fs.h>
62249+#include <linux/grinternal.h>
62250+
62251+extern int gr_acl_tpe_check(void);
62252+
62253+int
62254+gr_tpe_allow(const struct file *file)
62255+{
62256+#ifdef CONFIG_GRKERNSEC
62257+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
62258+ const struct cred *cred = current_cred();
62259+ char *msg = NULL;
62260+ char *msg2 = NULL;
62261+
62262+ // never restrict root
62263+ if (!cred->uid)
62264+ return 1;
62265+
62266+ if (grsec_enable_tpe) {
62267+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
62268+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
62269+ msg = "not being in trusted group";
62270+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
62271+ msg = "being in untrusted group";
62272+#else
62273+ if (in_group_p(grsec_tpe_gid))
62274+ msg = "being in untrusted group";
62275+#endif
62276+ }
62277+ if (!msg && gr_acl_tpe_check())
62278+ msg = "being in untrusted role";
62279+
62280+ // not in any affected group/role
62281+ if (!msg)
62282+ goto next_check;
62283+
62284+ if (inode->i_uid)
62285+ msg2 = "file in non-root-owned directory";
62286+ else if (inode->i_mode & S_IWOTH)
62287+ msg2 = "file in world-writable directory";
62288+ else if (inode->i_mode & S_IWGRP)
62289+ msg2 = "file in group-writable directory";
62290+
62291+ if (msg && msg2) {
62292+ char fullmsg[70] = {0};
62293+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
62294+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
62295+ return 0;
62296+ }
62297+ msg = NULL;
62298+next_check:
62299+#ifdef CONFIG_GRKERNSEC_TPE_ALL
62300+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
62301+ return 1;
62302+
62303+ if (inode->i_uid && (inode->i_uid != cred->uid))
62304+ msg = "directory not owned by user";
62305+ else if (inode->i_mode & S_IWOTH)
62306+ msg = "file in world-writable directory";
62307+ else if (inode->i_mode & S_IWGRP)
62308+ msg = "file in group-writable directory";
62309+
62310+ if (msg) {
62311+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
62312+ return 0;
62313+ }
62314+#endif
62315+#endif
62316+ return 1;
62317+}
62318diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
62319new file mode 100644
62320index 0000000..9f7b1ac
62321--- /dev/null
62322+++ b/grsecurity/grsum.c
62323@@ -0,0 +1,61 @@
62324+#include <linux/err.h>
62325+#include <linux/kernel.h>
62326+#include <linux/sched.h>
62327+#include <linux/mm.h>
62328+#include <linux/scatterlist.h>
62329+#include <linux/crypto.h>
62330+#include <linux/gracl.h>
62331+
62332+
62333+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
62334+#error "crypto and sha256 must be built into the kernel"
62335+#endif
62336+
62337+int
62338+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
62339+{
62340+ char *p;
62341+ struct crypto_hash *tfm;
62342+ struct hash_desc desc;
62343+ struct scatterlist sg;
62344+ unsigned char temp_sum[GR_SHA_LEN];
62345+ volatile int retval = 0;
62346+ volatile int dummy = 0;
62347+ unsigned int i;
62348+
62349+ sg_init_table(&sg, 1);
62350+
62351+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
62352+ if (IS_ERR(tfm)) {
62353+ /* should never happen, since sha256 should be built in */
62354+ return 1;
62355+ }
62356+
62357+ desc.tfm = tfm;
62358+ desc.flags = 0;
62359+
62360+ crypto_hash_init(&desc);
62361+
62362+ p = salt;
62363+ sg_set_buf(&sg, p, GR_SALT_LEN);
62364+ crypto_hash_update(&desc, &sg, sg.length);
62365+
62366+ p = entry->pw;
62367+ sg_set_buf(&sg, p, strlen(p));
62368+
62369+ crypto_hash_update(&desc, &sg, sg.length);
62370+
62371+ crypto_hash_final(&desc, temp_sum);
62372+
62373+ memset(entry->pw, 0, GR_PW_LEN);
62374+
62375+ for (i = 0; i < GR_SHA_LEN; i++)
62376+ if (sum[i] != temp_sum[i])
62377+ retval = 1;
62378+ else
62379+ dummy = 1; // waste a cycle
62380+
62381+ crypto_free_hash(tfm);
62382+
62383+ return retval;
62384+}
62385diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
62386index 77ff547..181834f 100644
62387--- a/include/asm-generic/4level-fixup.h
62388+++ b/include/asm-generic/4level-fixup.h
62389@@ -13,8 +13,10 @@
62390 #define pmd_alloc(mm, pud, address) \
62391 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
62392 NULL: pmd_offset(pud, address))
62393+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
62394
62395 #define pud_alloc(mm, pgd, address) (pgd)
62396+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
62397 #define pud_offset(pgd, start) (pgd)
62398 #define pud_none(pud) 0
62399 #define pud_bad(pud) 0
62400diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
62401index b7babf0..04ad282 100644
62402--- a/include/asm-generic/atomic-long.h
62403+++ b/include/asm-generic/atomic-long.h
62404@@ -22,6 +22,12 @@
62405
62406 typedef atomic64_t atomic_long_t;
62407
62408+#ifdef CONFIG_PAX_REFCOUNT
62409+typedef atomic64_unchecked_t atomic_long_unchecked_t;
62410+#else
62411+typedef atomic64_t atomic_long_unchecked_t;
62412+#endif
62413+
62414 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
62415
62416 static inline long atomic_long_read(atomic_long_t *l)
62417@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
62418 return (long)atomic64_read(v);
62419 }
62420
62421+#ifdef CONFIG_PAX_REFCOUNT
62422+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
62423+{
62424+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62425+
62426+ return (long)atomic64_read_unchecked(v);
62427+}
62428+#endif
62429+
62430 static inline void atomic_long_set(atomic_long_t *l, long i)
62431 {
62432 atomic64_t *v = (atomic64_t *)l;
62433@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
62434 atomic64_set(v, i);
62435 }
62436
62437+#ifdef CONFIG_PAX_REFCOUNT
62438+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
62439+{
62440+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62441+
62442+ atomic64_set_unchecked(v, i);
62443+}
62444+#endif
62445+
62446 static inline void atomic_long_inc(atomic_long_t *l)
62447 {
62448 atomic64_t *v = (atomic64_t *)l;
62449@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
62450 atomic64_inc(v);
62451 }
62452
62453+#ifdef CONFIG_PAX_REFCOUNT
62454+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
62455+{
62456+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62457+
62458+ atomic64_inc_unchecked(v);
62459+}
62460+#endif
62461+
62462 static inline void atomic_long_dec(atomic_long_t *l)
62463 {
62464 atomic64_t *v = (atomic64_t *)l;
62465@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
62466 atomic64_dec(v);
62467 }
62468
62469+#ifdef CONFIG_PAX_REFCOUNT
62470+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
62471+{
62472+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62473+
62474+ atomic64_dec_unchecked(v);
62475+}
62476+#endif
62477+
62478 static inline void atomic_long_add(long i, atomic_long_t *l)
62479 {
62480 atomic64_t *v = (atomic64_t *)l;
62481@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
62482 atomic64_add(i, v);
62483 }
62484
62485+#ifdef CONFIG_PAX_REFCOUNT
62486+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
62487+{
62488+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62489+
62490+ atomic64_add_unchecked(i, v);
62491+}
62492+#endif
62493+
62494 static inline void atomic_long_sub(long i, atomic_long_t *l)
62495 {
62496 atomic64_t *v = (atomic64_t *)l;
62497@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
62498 atomic64_sub(i, v);
62499 }
62500
62501+#ifdef CONFIG_PAX_REFCOUNT
62502+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
62503+{
62504+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62505+
62506+ atomic64_sub_unchecked(i, v);
62507+}
62508+#endif
62509+
62510 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
62511 {
62512 atomic64_t *v = (atomic64_t *)l;
62513@@ -101,6 +161,15 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
62514 return (long)atomic64_add_return(i, v);
62515 }
62516
62517+#ifdef CONFIG_PAX_REFCOUNT
62518+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
62519+{
62520+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62521+
62522+ return (long)atomic64_add_return_unchecked(i, v);
62523+}
62524+#endif
62525+
62526 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
62527 {
62528 atomic64_t *v = (atomic64_t *)l;
62529@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
62530 return (long)atomic64_inc_return(v);
62531 }
62532
62533+#ifdef CONFIG_PAX_REFCOUNT
62534+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
62535+{
62536+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62537+
62538+ return (long)atomic64_inc_return_unchecked(v);
62539+}
62540+#endif
62541+
62542 static inline long atomic_long_dec_return(atomic_long_t *l)
62543 {
62544 atomic64_t *v = (atomic64_t *)l;
62545@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
62546
62547 typedef atomic_t atomic_long_t;
62548
62549+#ifdef CONFIG_PAX_REFCOUNT
62550+typedef atomic_unchecked_t atomic_long_unchecked_t;
62551+#else
62552+typedef atomic_t atomic_long_unchecked_t;
62553+#endif
62554+
62555 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
62556 static inline long atomic_long_read(atomic_long_t *l)
62557 {
62558@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
62559 return (long)atomic_read(v);
62560 }
62561
62562+#ifdef CONFIG_PAX_REFCOUNT
62563+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
62564+{
62565+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62566+
62567+ return (long)atomic_read_unchecked(v);
62568+}
62569+#endif
62570+
62571 static inline void atomic_long_set(atomic_long_t *l, long i)
62572 {
62573 atomic_t *v = (atomic_t *)l;
62574@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
62575 atomic_set(v, i);
62576 }
62577
62578+#ifdef CONFIG_PAX_REFCOUNT
62579+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
62580+{
62581+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62582+
62583+ atomic_set_unchecked(v, i);
62584+}
62585+#endif
62586+
62587 static inline void atomic_long_inc(atomic_long_t *l)
62588 {
62589 atomic_t *v = (atomic_t *)l;
62590@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
62591 atomic_inc(v);
62592 }
62593
62594+#ifdef CONFIG_PAX_REFCOUNT
62595+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
62596+{
62597+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62598+
62599+ atomic_inc_unchecked(v);
62600+}
62601+#endif
62602+
62603 static inline void atomic_long_dec(atomic_long_t *l)
62604 {
62605 atomic_t *v = (atomic_t *)l;
62606@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
62607 atomic_dec(v);
62608 }
62609
62610+#ifdef CONFIG_PAX_REFCOUNT
62611+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
62612+{
62613+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62614+
62615+ atomic_dec_unchecked(v);
62616+}
62617+#endif
62618+
62619 static inline void atomic_long_add(long i, atomic_long_t *l)
62620 {
62621 atomic_t *v = (atomic_t *)l;
62622@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
62623 atomic_add(i, v);
62624 }
62625
62626+#ifdef CONFIG_PAX_REFCOUNT
62627+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
62628+{
62629+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62630+
62631+ atomic_add_unchecked(i, v);
62632+}
62633+#endif
62634+
62635 static inline void atomic_long_sub(long i, atomic_long_t *l)
62636 {
62637 atomic_t *v = (atomic_t *)l;
62638@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
62639 atomic_sub(i, v);
62640 }
62641
62642+#ifdef CONFIG_PAX_REFCOUNT
62643+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
62644+{
62645+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62646+
62647+ atomic_sub_unchecked(i, v);
62648+}
62649+#endif
62650+
62651 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
62652 {
62653 atomic_t *v = (atomic_t *)l;
62654@@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
62655 return (long)atomic_add_return(i, v);
62656 }
62657
62658+#ifdef CONFIG_PAX_REFCOUNT
62659+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
62660+{
62661+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62662+
62663+ return (long)atomic_add_return_unchecked(i, v);
62664+}
62665+
62666+#endif
62667+
62668 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
62669 {
62670 atomic_t *v = (atomic_t *)l;
62671@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
62672 return (long)atomic_inc_return(v);
62673 }
62674
62675+#ifdef CONFIG_PAX_REFCOUNT
62676+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
62677+{
62678+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62679+
62680+ return (long)atomic_inc_return_unchecked(v);
62681+}
62682+#endif
62683+
62684 static inline long atomic_long_dec_return(atomic_long_t *l)
62685 {
62686 atomic_t *v = (atomic_t *)l;
62687@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
62688
62689 #endif /* BITS_PER_LONG == 64 */
62690
62691+#ifdef CONFIG_PAX_REFCOUNT
62692+static inline void pax_refcount_needs_these_functions(void)
62693+{
62694+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
62695+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
62696+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
62697+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
62698+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
62699+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
62700+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
62701+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
62702+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
62703+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
62704+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
62705+#ifdef CONFIG_X86
62706+ atomic_clear_mask_unchecked(0, NULL);
62707+ atomic_set_mask_unchecked(0, NULL);
62708+#endif
62709+
62710+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
62711+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
62712+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
62713+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
62714+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
62715+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
62716+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
62717+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
62718+}
62719+#else
62720+#define atomic_read_unchecked(v) atomic_read(v)
62721+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
62722+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
62723+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
62724+#define atomic_inc_unchecked(v) atomic_inc(v)
62725+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
62726+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
62727+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
62728+#define atomic_dec_unchecked(v) atomic_dec(v)
62729+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
62730+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
62731+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
62732+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
62733+
62734+#define atomic_long_read_unchecked(v) atomic_long_read(v)
62735+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
62736+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
62737+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
62738+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
62739+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
62740+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
62741+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
62742+#endif
62743+
62744 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
62745diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
62746index 1ced641..c896ee8 100644
62747--- a/include/asm-generic/atomic.h
62748+++ b/include/asm-generic/atomic.h
62749@@ -159,7 +159,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
62750 * Atomically clears the bits set in @mask from @v
62751 */
62752 #ifndef atomic_clear_mask
62753-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
62754+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
62755 {
62756 unsigned long flags;
62757
62758diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
62759index b18ce4f..2ee2843 100644
62760--- a/include/asm-generic/atomic64.h
62761+++ b/include/asm-generic/atomic64.h
62762@@ -16,6 +16,8 @@ typedef struct {
62763 long long counter;
62764 } atomic64_t;
62765
62766+typedef atomic64_t atomic64_unchecked_t;
62767+
62768 #define ATOMIC64_INIT(i) { (i) }
62769
62770 extern long long atomic64_read(const atomic64_t *v);
62771@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
62772 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
62773 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
62774
62775+#define atomic64_read_unchecked(v) atomic64_read(v)
62776+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
62777+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
62778+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
62779+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
62780+#define atomic64_inc_unchecked(v) atomic64_inc(v)
62781+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
62782+#define atomic64_dec_unchecked(v) atomic64_dec(v)
62783+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
62784+
62785 #endif /* _ASM_GENERIC_ATOMIC64_H */
62786diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
62787index 1bfcfe5..e04c5c9 100644
62788--- a/include/asm-generic/cache.h
62789+++ b/include/asm-generic/cache.h
62790@@ -6,7 +6,7 @@
62791 * cache lines need to provide their own cache.h.
62792 */
62793
62794-#define L1_CACHE_SHIFT 5
62795-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
62796+#define L1_CACHE_SHIFT 5UL
62797+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
62798
62799 #endif /* __ASM_GENERIC_CACHE_H */
62800diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
62801index 0d68a1e..b74a761 100644
62802--- a/include/asm-generic/emergency-restart.h
62803+++ b/include/asm-generic/emergency-restart.h
62804@@ -1,7 +1,7 @@
62805 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
62806 #define _ASM_GENERIC_EMERGENCY_RESTART_H
62807
62808-static inline void machine_emergency_restart(void)
62809+static inline __noreturn void machine_emergency_restart(void)
62810 {
62811 machine_restart(NULL);
62812 }
62813diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
62814index 90f99c7..00ce236 100644
62815--- a/include/asm-generic/kmap_types.h
62816+++ b/include/asm-generic/kmap_types.h
62817@@ -2,9 +2,9 @@
62818 #define _ASM_GENERIC_KMAP_TYPES_H
62819
62820 #ifdef __WITH_KM_FENCE
62821-# define KM_TYPE_NR 41
62822+# define KM_TYPE_NR 42
62823 #else
62824-# define KM_TYPE_NR 20
62825+# define KM_TYPE_NR 21
62826 #endif
62827
62828 #endif
62829diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
62830index 9ceb03b..62b0b8f 100644
62831--- a/include/asm-generic/local.h
62832+++ b/include/asm-generic/local.h
62833@@ -23,24 +23,37 @@ typedef struct
62834 atomic_long_t a;
62835 } local_t;
62836
62837+typedef struct {
62838+ atomic_long_unchecked_t a;
62839+} local_unchecked_t;
62840+
62841 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
62842
62843 #define local_read(l) atomic_long_read(&(l)->a)
62844+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
62845 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
62846+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
62847 #define local_inc(l) atomic_long_inc(&(l)->a)
62848+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
62849 #define local_dec(l) atomic_long_dec(&(l)->a)
62850+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
62851 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
62852+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
62853 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
62854+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
62855
62856 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
62857 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
62858 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
62859 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
62860 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
62861+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
62862 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
62863 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
62864+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
62865
62866 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
62867+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
62868 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
62869 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
62870 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
62871diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
62872index 725612b..9cc513a 100644
62873--- a/include/asm-generic/pgtable-nopmd.h
62874+++ b/include/asm-generic/pgtable-nopmd.h
62875@@ -1,14 +1,19 @@
62876 #ifndef _PGTABLE_NOPMD_H
62877 #define _PGTABLE_NOPMD_H
62878
62879-#ifndef __ASSEMBLY__
62880-
62881 #include <asm-generic/pgtable-nopud.h>
62882
62883-struct mm_struct;
62884-
62885 #define __PAGETABLE_PMD_FOLDED
62886
62887+#define PMD_SHIFT PUD_SHIFT
62888+#define PTRS_PER_PMD 1
62889+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
62890+#define PMD_MASK (~(PMD_SIZE-1))
62891+
62892+#ifndef __ASSEMBLY__
62893+
62894+struct mm_struct;
62895+
62896 /*
62897 * Having the pmd type consist of a pud gets the size right, and allows
62898 * us to conceptually access the pud entry that this pmd is folded into
62899@@ -16,11 +21,6 @@ struct mm_struct;
62900 */
62901 typedef struct { pud_t pud; } pmd_t;
62902
62903-#define PMD_SHIFT PUD_SHIFT
62904-#define PTRS_PER_PMD 1
62905-#define PMD_SIZE (1UL << PMD_SHIFT)
62906-#define PMD_MASK (~(PMD_SIZE-1))
62907-
62908 /*
62909 * The "pud_xxx()" functions here are trivial for a folded two-level
62910 * setup: the pmd is never bad, and a pmd always exists (as it's folded
62911diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
62912index 810431d..0ec4804f 100644
62913--- a/include/asm-generic/pgtable-nopud.h
62914+++ b/include/asm-generic/pgtable-nopud.h
62915@@ -1,10 +1,15 @@
62916 #ifndef _PGTABLE_NOPUD_H
62917 #define _PGTABLE_NOPUD_H
62918
62919-#ifndef __ASSEMBLY__
62920-
62921 #define __PAGETABLE_PUD_FOLDED
62922
62923+#define PUD_SHIFT PGDIR_SHIFT
62924+#define PTRS_PER_PUD 1
62925+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
62926+#define PUD_MASK (~(PUD_SIZE-1))
62927+
62928+#ifndef __ASSEMBLY__
62929+
62930 /*
62931 * Having the pud type consist of a pgd gets the size right, and allows
62932 * us to conceptually access the pgd entry that this pud is folded into
62933@@ -12,11 +17,6 @@
62934 */
62935 typedef struct { pgd_t pgd; } pud_t;
62936
62937-#define PUD_SHIFT PGDIR_SHIFT
62938-#define PTRS_PER_PUD 1
62939-#define PUD_SIZE (1UL << PUD_SHIFT)
62940-#define PUD_MASK (~(PUD_SIZE-1))
62941-
62942 /*
62943 * The "pgd_xxx()" functions here are trivial for a folded two-level
62944 * setup: the pud is never bad, and a pud always exists (as it's folded
62945@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
62946 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
62947
62948 #define pgd_populate(mm, pgd, pud) do { } while (0)
62949+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
62950 /*
62951 * (puds are folded into pgds so this doesn't get actually called,
62952 * but the define is needed for a generic inline function.)
62953diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
62954index b36ce40..019426d 100644
62955--- a/include/asm-generic/pgtable.h
62956+++ b/include/asm-generic/pgtable.h
62957@@ -554,6 +554,14 @@ static inline int pmd_trans_unstable(pmd_t *pmd)
62958 #endif
62959 }
62960
62961+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
62962+static inline unsigned long pax_open_kernel(void) { return 0; }
62963+#endif
62964+
62965+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
62966+static inline unsigned long pax_close_kernel(void) { return 0; }
62967+#endif
62968+
62969 #endif /* CONFIG_MMU */
62970
62971 #endif /* !__ASSEMBLY__ */
62972diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
62973index d1ea7ce..b1ebf2a 100644
62974--- a/include/asm-generic/vmlinux.lds.h
62975+++ b/include/asm-generic/vmlinux.lds.h
62976@@ -218,6 +218,7 @@
62977 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
62978 VMLINUX_SYMBOL(__start_rodata) = .; \
62979 *(.rodata) *(.rodata.*) \
62980+ *(.data..read_only) \
62981 *(__vermagic) /* Kernel version magic */ \
62982 . = ALIGN(8); \
62983 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
62984@@ -725,17 +726,18 @@
62985 * section in the linker script will go there too. @phdr should have
62986 * a leading colon.
62987 *
62988- * Note that this macros defines __per_cpu_load as an absolute symbol.
62989+ * Note that this macros defines per_cpu_load as an absolute symbol.
62990 * If there is no need to put the percpu section at a predetermined
62991 * address, use PERCPU_SECTION.
62992 */
62993 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
62994- VMLINUX_SYMBOL(__per_cpu_load) = .; \
62995- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
62996+ per_cpu_load = .; \
62997+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
62998 - LOAD_OFFSET) { \
62999+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
63000 PERCPU_INPUT(cacheline) \
63001 } phdr \
63002- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
63003+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
63004
63005 /**
63006 * PERCPU_SECTION - define output section for percpu area, simple version
63007diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
63008index 418d270..bfd2794 100644
63009--- a/include/crypto/algapi.h
63010+++ b/include/crypto/algapi.h
63011@@ -34,7 +34,7 @@ struct crypto_type {
63012 unsigned int maskclear;
63013 unsigned int maskset;
63014 unsigned int tfmsize;
63015-};
63016+} __do_const;
63017
63018 struct crypto_instance {
63019 struct crypto_alg alg;
63020diff --git a/include/drm/drmP.h b/include/drm/drmP.h
63021index 3fd8280..2b3c415 100644
63022--- a/include/drm/drmP.h
63023+++ b/include/drm/drmP.h
63024@@ -72,6 +72,7 @@
63025 #include <linux/workqueue.h>
63026 #include <linux/poll.h>
63027 #include <asm/pgalloc.h>
63028+#include <asm/local.h>
63029 #include <drm/drm.h>
63030 #include <drm/drm_sarea.h>
63031
63032@@ -1068,7 +1069,7 @@ struct drm_device {
63033
63034 /** \name Usage Counters */
63035 /*@{ */
63036- int open_count; /**< Outstanding files open */
63037+ local_t open_count; /**< Outstanding files open */
63038 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
63039 atomic_t vma_count; /**< Outstanding vma areas open */
63040 int buf_use; /**< Buffers in use -- cannot alloc */
63041@@ -1079,7 +1080,7 @@ struct drm_device {
63042 /*@{ */
63043 unsigned long counters;
63044 enum drm_stat_type types[15];
63045- atomic_t counts[15];
63046+ atomic_unchecked_t counts[15];
63047 /*@} */
63048
63049 struct list_head filelist;
63050diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
63051index e01cc80..6fb6f25 100644
63052--- a/include/drm/drm_crtc_helper.h
63053+++ b/include/drm/drm_crtc_helper.h
63054@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
63055 struct drm_connector *connector);
63056 /* disable encoder when not in use - more explicit than dpms off */
63057 void (*disable)(struct drm_encoder *encoder);
63058-};
63059+} __no_const;
63060
63061 /**
63062 * drm_connector_helper_funcs - helper operations for connectors
63063diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
63064index d6d1da4..fdd1ac5 100644
63065--- a/include/drm/ttm/ttm_memory.h
63066+++ b/include/drm/ttm/ttm_memory.h
63067@@ -48,7 +48,7 @@
63068
63069 struct ttm_mem_shrink {
63070 int (*do_shrink) (struct ttm_mem_shrink *);
63071-};
63072+} __no_const;
63073
63074 /**
63075 * struct ttm_mem_global - Global memory accounting structure.
63076diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
63077index 22ef21c..75904ba 100644
63078--- a/include/linux/atmdev.h
63079+++ b/include/linux/atmdev.h
63080@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
63081 #endif
63082
63083 struct k_atm_aal_stats {
63084-#define __HANDLE_ITEM(i) atomic_t i
63085+#define __HANDLE_ITEM(i) atomic_unchecked_t i
63086 __AAL_STAT_ITEMS
63087 #undef __HANDLE_ITEM
63088 };
63089diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
63090index de0628e..38f42eb 100644
63091--- a/include/linux/binfmts.h
63092+++ b/include/linux/binfmts.h
63093@@ -75,6 +75,7 @@ struct linux_binfmt {
63094 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
63095 int (*load_shlib)(struct file *);
63096 int (*core_dump)(struct coredump_params *cprm);
63097+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
63098 unsigned long min_coredump; /* minimal dump size */
63099 };
63100
63101diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
63102index 1756001..ab117ec 100644
63103--- a/include/linux/blkdev.h
63104+++ b/include/linux/blkdev.h
63105@@ -1478,7 +1478,7 @@ struct block_device_operations {
63106 /* this callback is with swap_lock and sometimes page table lock held */
63107 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
63108 struct module *owner;
63109-};
63110+} __do_const;
63111
63112 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
63113 unsigned long);
63114diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
63115index 7c2e030..b72475d 100644
63116--- a/include/linux/blktrace_api.h
63117+++ b/include/linux/blktrace_api.h
63118@@ -23,7 +23,7 @@ struct blk_trace {
63119 struct dentry *dir;
63120 struct dentry *dropped_file;
63121 struct dentry *msg_file;
63122- atomic_t dropped;
63123+ atomic_unchecked_t dropped;
63124 };
63125
63126 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
63127diff --git a/include/linux/cache.h b/include/linux/cache.h
63128index 4c57065..4307975 100644
63129--- a/include/linux/cache.h
63130+++ b/include/linux/cache.h
63131@@ -16,6 +16,10 @@
63132 #define __read_mostly
63133 #endif
63134
63135+#ifndef __read_only
63136+#define __read_only __read_mostly
63137+#endif
63138+
63139 #ifndef ____cacheline_aligned
63140 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
63141 #endif
63142diff --git a/include/linux/capability.h b/include/linux/capability.h
63143index 98503b7..cc36d18 100644
63144--- a/include/linux/capability.h
63145+++ b/include/linux/capability.h
63146@@ -211,8 +211,13 @@ extern bool capable(int cap);
63147 extern bool ns_capable(struct user_namespace *ns, int cap);
63148 extern bool nsown_capable(int cap);
63149 extern bool inode_capable(const struct inode *inode, int cap);
63150+extern bool capable_nolog(int cap);
63151+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
63152+extern bool inode_capable_nolog(const struct inode *inode, int cap);
63153
63154 /* audit system wants to get cap info from files as well */
63155 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
63156
63157+extern int is_privileged_binary(const struct dentry *dentry);
63158+
63159 #endif /* !_LINUX_CAPABILITY_H */
63160diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
63161index 8609d57..86e4d79 100644
63162--- a/include/linux/cdrom.h
63163+++ b/include/linux/cdrom.h
63164@@ -87,7 +87,6 @@ struct cdrom_device_ops {
63165
63166 /* driver specifications */
63167 const int capability; /* capability flags */
63168- int n_minors; /* number of active minor devices */
63169 /* handle uniform packets for scsi type devices (scsi,atapi) */
63170 int (*generic_packet) (struct cdrom_device_info *,
63171 struct packet_command *);
63172diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
63173index 42e55de..1cd0e66 100644
63174--- a/include/linux/cleancache.h
63175+++ b/include/linux/cleancache.h
63176@@ -31,7 +31,7 @@ struct cleancache_ops {
63177 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
63178 void (*invalidate_inode)(int, struct cleancache_filekey);
63179 void (*invalidate_fs)(int);
63180-};
63181+} __no_const;
63182
63183 extern struct cleancache_ops
63184 cleancache_register_ops(struct cleancache_ops *ops);
63185diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
63186index 412bc6c..c31666e 100644
63187--- a/include/linux/compiler-gcc4.h
63188+++ b/include/linux/compiler-gcc4.h
63189@@ -32,6 +32,21 @@
63190 #define __linktime_error(message) __attribute__((__error__(message)))
63191
63192 #if __GNUC_MINOR__ >= 5
63193+
63194+#ifdef CONSTIFY_PLUGIN
63195+#define __no_const __attribute__((no_const))
63196+#define __do_const __attribute__((do_const))
63197+#endif
63198+
63199+#ifdef SIZE_OVERFLOW_PLUGIN
63200+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
63201+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
63202+#endif
63203+
63204+#ifdef LATENT_ENTROPY_PLUGIN
63205+#define __latent_entropy __attribute__((latent_entropy))
63206+#endif
63207+
63208 /*
63209 * Mark a position in code as unreachable. This can be used to
63210 * suppress control flow warnings after asm blocks that transfer
63211@@ -47,6 +62,11 @@
63212 #define __noclone __attribute__((__noclone__))
63213
63214 #endif
63215+
63216+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
63217+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
63218+#define __bos0(ptr) __bos((ptr), 0)
63219+#define __bos1(ptr) __bos((ptr), 1)
63220 #endif
63221
63222 #if __GNUC_MINOR__ >= 6
63223diff --git a/include/linux/compiler.h b/include/linux/compiler.h
63224index f430e41..38be90f 100644
63225--- a/include/linux/compiler.h
63226+++ b/include/linux/compiler.h
63227@@ -5,31 +5,62 @@
63228
63229 #ifdef __CHECKER__
63230 # define __user __attribute__((noderef, address_space(1)))
63231+# define __force_user __force __user
63232 # define __kernel __attribute__((address_space(0)))
63233+# define __force_kernel __force __kernel
63234 # define __safe __attribute__((safe))
63235 # define __force __attribute__((force))
63236 # define __nocast __attribute__((nocast))
63237 # define __iomem __attribute__((noderef, address_space(2)))
63238+# define __force_iomem __force __iomem
63239 # define __acquires(x) __attribute__((context(x,0,1)))
63240 # define __releases(x) __attribute__((context(x,1,0)))
63241 # define __acquire(x) __context__(x,1)
63242 # define __release(x) __context__(x,-1)
63243 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
63244 # define __percpu __attribute__((noderef, address_space(3)))
63245+# define __force_percpu __force __percpu
63246 #ifdef CONFIG_SPARSE_RCU_POINTER
63247 # define __rcu __attribute__((noderef, address_space(4)))
63248+# define __force_rcu __force __rcu
63249 #else
63250 # define __rcu
63251+# define __force_rcu
63252 #endif
63253 extern void __chk_user_ptr(const volatile void __user *);
63254 extern void __chk_io_ptr(const volatile void __iomem *);
63255+#elif defined(CHECKER_PLUGIN)
63256+//# define __user
63257+//# define __force_user
63258+//# define __kernel
63259+//# define __force_kernel
63260+# define __safe
63261+# define __force
63262+# define __nocast
63263+# define __iomem
63264+# define __force_iomem
63265+# define __chk_user_ptr(x) (void)0
63266+# define __chk_io_ptr(x) (void)0
63267+# define __builtin_warning(x, y...) (1)
63268+# define __acquires(x)
63269+# define __releases(x)
63270+# define __acquire(x) (void)0
63271+# define __release(x) (void)0
63272+# define __cond_lock(x,c) (c)
63273+# define __percpu
63274+# define __force_percpu
63275+# define __rcu
63276+# define __force_rcu
63277 #else
63278 # define __user
63279+# define __force_user
63280 # define __kernel
63281+# define __force_kernel
63282 # define __safe
63283 # define __force
63284 # define __nocast
63285 # define __iomem
63286+# define __force_iomem
63287 # define __chk_user_ptr(x) (void)0
63288 # define __chk_io_ptr(x) (void)0
63289 # define __builtin_warning(x, y...) (1)
63290@@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
63291 # define __release(x) (void)0
63292 # define __cond_lock(x,c) (c)
63293 # define __percpu
63294+# define __force_percpu
63295 # define __rcu
63296+# define __force_rcu
63297 #endif
63298
63299 #ifdef __KERNEL__
63300@@ -264,6 +297,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
63301 # define __attribute_const__ /* unimplemented */
63302 #endif
63303
63304+#ifndef __no_const
63305+# define __no_const
63306+#endif
63307+
63308+#ifndef __do_const
63309+# define __do_const
63310+#endif
63311+
63312+#ifndef __size_overflow
63313+# define __size_overflow(...)
63314+#endif
63315+
63316+#ifndef __intentional_overflow
63317+# define __intentional_overflow(...)
63318+#endif
63319+
63320+#ifndef __latent_entropy
63321+# define __latent_entropy
63322+#endif
63323+
63324 /*
63325 * Tell gcc if a function is cold. The compiler will assume any path
63326 * directly leading to the call is unlikely.
63327@@ -273,6 +326,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
63328 #define __cold
63329 #endif
63330
63331+#ifndef __alloc_size
63332+#define __alloc_size(...)
63333+#endif
63334+
63335+#ifndef __bos
63336+#define __bos(ptr, arg)
63337+#endif
63338+
63339+#ifndef __bos0
63340+#define __bos0(ptr)
63341+#endif
63342+
63343+#ifndef __bos1
63344+#define __bos1(ptr)
63345+#endif
63346+
63347 /* Simple shorthand for a section definition */
63348 #ifndef __section
63349 # define __section(S) __attribute__ ((__section__(#S)))
63350@@ -312,6 +381,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
63351 * use is to mediate communication between process-level code and irq/NMI
63352 * handlers, all running on the same CPU.
63353 */
63354-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
63355+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
63356+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
63357
63358 #endif /* __LINUX_COMPILER_H */
63359diff --git a/include/linux/cred.h b/include/linux/cred.h
63360index ebbed2c..908cc2c 100644
63361--- a/include/linux/cred.h
63362+++ b/include/linux/cred.h
63363@@ -208,6 +208,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
63364 static inline void validate_process_creds(void)
63365 {
63366 }
63367+static inline void validate_task_creds(struct task_struct *task)
63368+{
63369+}
63370 #endif
63371
63372 /**
63373diff --git a/include/linux/crypto.h b/include/linux/crypto.h
63374index b92eadf..b4ecdc1 100644
63375--- a/include/linux/crypto.h
63376+++ b/include/linux/crypto.h
63377@@ -373,7 +373,7 @@ struct cipher_tfm {
63378 const u8 *key, unsigned int keylen);
63379 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
63380 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
63381-};
63382+} __no_const;
63383
63384 struct hash_tfm {
63385 int (*init)(struct hash_desc *desc);
63386@@ -394,13 +394,13 @@ struct compress_tfm {
63387 int (*cot_decompress)(struct crypto_tfm *tfm,
63388 const u8 *src, unsigned int slen,
63389 u8 *dst, unsigned int *dlen);
63390-};
63391+} __no_const;
63392
63393 struct rng_tfm {
63394 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
63395 unsigned int dlen);
63396 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
63397-};
63398+} __no_const;
63399
63400 #define crt_ablkcipher crt_u.ablkcipher
63401 #define crt_aead crt_u.aead
63402diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
63403index 7925bf0..d5143d2 100644
63404--- a/include/linux/decompress/mm.h
63405+++ b/include/linux/decompress/mm.h
63406@@ -77,7 +77,7 @@ static void free(void *where)
63407 * warnings when not needed (indeed large_malloc / large_free are not
63408 * needed by inflate */
63409
63410-#define malloc(a) kmalloc(a, GFP_KERNEL)
63411+#define malloc(a) kmalloc((a), GFP_KERNEL)
63412 #define free(a) kfree(a)
63413
63414 #define large_malloc(a) vmalloc(a)
63415diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
63416index 94af418..b1ca7a2 100644
63417--- a/include/linux/dma-mapping.h
63418+++ b/include/linux/dma-mapping.h
63419@@ -54,7 +54,7 @@ struct dma_map_ops {
63420 u64 (*get_required_mask)(struct device *dev);
63421 #endif
63422 int is_phys;
63423-};
63424+} __do_const;
63425
63426 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
63427
63428diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
63429index d3201e4..8281e63 100644
63430--- a/include/linux/dmaengine.h
63431+++ b/include/linux/dmaengine.h
63432@@ -1018,9 +1018,9 @@ struct dma_pinned_list {
63433 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
63434 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
63435
63436-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
63437+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
63438 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
63439-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
63440+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
63441 struct dma_pinned_list *pinned_list, struct page *page,
63442 unsigned int offset, size_t len);
63443
63444diff --git a/include/linux/elf.h b/include/linux/elf.h
63445index 8c9048e..16a4665 100644
63446--- a/include/linux/elf.h
63447+++ b/include/linux/elf.h
63448@@ -20,6 +20,7 @@ extern Elf32_Dyn _DYNAMIC [];
63449 #define elf_note elf32_note
63450 #define elf_addr_t Elf32_Off
63451 #define Elf_Half Elf32_Half
63452+#define elf_dyn Elf32_Dyn
63453
63454 #else
63455
63456@@ -30,6 +31,7 @@ extern Elf64_Dyn _DYNAMIC [];
63457 #define elf_note elf64_note
63458 #define elf_addr_t Elf64_Off
63459 #define Elf_Half Elf64_Half
63460+#define elf_dyn Elf64_Dyn
63461
63462 #endif
63463
63464diff --git a/include/linux/filter.h b/include/linux/filter.h
63465index 24d251f..7afb83d 100644
63466--- a/include/linux/filter.h
63467+++ b/include/linux/filter.h
63468@@ -20,6 +20,7 @@ struct compat_sock_fprog {
63469
63470 struct sk_buff;
63471 struct sock;
63472+struct bpf_jit_work;
63473
63474 struct sk_filter
63475 {
63476@@ -27,6 +28,9 @@ struct sk_filter
63477 unsigned int len; /* Number of filter blocks */
63478 unsigned int (*bpf_func)(const struct sk_buff *skb,
63479 const struct sock_filter *filter);
63480+#ifdef CONFIG_BPF_JIT
63481+ struct bpf_jit_work *work;
63482+#endif
63483 struct rcu_head rcu;
63484 struct sock_filter insns[0];
63485 };
63486diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
63487index 3044254..9767f41 100644
63488--- a/include/linux/frontswap.h
63489+++ b/include/linux/frontswap.h
63490@@ -11,7 +11,7 @@ struct frontswap_ops {
63491 int (*load)(unsigned, pgoff_t, struct page *);
63492 void (*invalidate_page)(unsigned, pgoff_t);
63493 void (*invalidate_area)(unsigned);
63494-};
63495+} __no_const;
63496
63497 extern bool frontswap_enabled;
63498 extern struct frontswap_ops
63499diff --git a/include/linux/fs.h b/include/linux/fs.h
63500index 75fe9a1..8417cac 100644
63501--- a/include/linux/fs.h
63502+++ b/include/linux/fs.h
63503@@ -1543,7 +1543,8 @@ struct file_operations {
63504 int (*setlease)(struct file *, long, struct file_lock **);
63505 long (*fallocate)(struct file *file, int mode, loff_t offset,
63506 loff_t len);
63507-};
63508+} __do_const;
63509+typedef struct file_operations __no_const file_operations_no_const;
63510
63511 struct inode_operations {
63512 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
63513@@ -2667,4 +2668,14 @@ static inline void inode_has_no_xattr(struct inode *inode)
63514 inode->i_flags |= S_NOSEC;
63515 }
63516
63517+static inline bool is_sidechannel_device(const struct inode *inode)
63518+{
63519+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
63520+ umode_t mode = inode->i_mode;
63521+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
63522+#else
63523+ return false;
63524+#endif
63525+}
63526+
63527 #endif /* _LINUX_FS_H */
63528diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
63529index 003dc0f..3c4ea97 100644
63530--- a/include/linux/fs_struct.h
63531+++ b/include/linux/fs_struct.h
63532@@ -6,7 +6,7 @@
63533 #include <linux/seqlock.h>
63534
63535 struct fs_struct {
63536- int users;
63537+ atomic_t users;
63538 spinlock_t lock;
63539 seqcount_t seq;
63540 int umask;
63541diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
63542index ce31408..b1ad003 100644
63543--- a/include/linux/fscache-cache.h
63544+++ b/include/linux/fscache-cache.h
63545@@ -102,7 +102,7 @@ struct fscache_operation {
63546 fscache_operation_release_t release;
63547 };
63548
63549-extern atomic_t fscache_op_debug_id;
63550+extern atomic_unchecked_t fscache_op_debug_id;
63551 extern void fscache_op_work_func(struct work_struct *work);
63552
63553 extern void fscache_enqueue_operation(struct fscache_operation *);
63554@@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
63555 {
63556 INIT_WORK(&op->work, fscache_op_work_func);
63557 atomic_set(&op->usage, 1);
63558- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
63559+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
63560 op->processor = processor;
63561 op->release = release;
63562 INIT_LIST_HEAD(&op->pend_link);
63563diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
63564index 0fbfb46..508eb0d 100644
63565--- a/include/linux/fsnotify.h
63566+++ b/include/linux/fsnotify.h
63567@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
63568 struct inode *inode = path->dentry->d_inode;
63569 __u32 mask = FS_ACCESS;
63570
63571+ if (is_sidechannel_device(inode))
63572+ return;
63573+
63574 if (S_ISDIR(inode->i_mode))
63575 mask |= FS_ISDIR;
63576
63577@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
63578 struct inode *inode = path->dentry->d_inode;
63579 __u32 mask = FS_MODIFY;
63580
63581+ if (is_sidechannel_device(inode))
63582+ return;
63583+
63584 if (S_ISDIR(inode->i_mode))
63585 mask |= FS_ISDIR;
63586
63587@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
63588 */
63589 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
63590 {
63591- return kstrdup(name, GFP_KERNEL);
63592+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
63593 }
63594
63595 /*
63596diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
63597index 642928c..93afe6a 100644
63598--- a/include/linux/ftrace_event.h
63599+++ b/include/linux/ftrace_event.h
63600@@ -266,7 +266,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
63601 extern int trace_add_event_call(struct ftrace_event_call *call);
63602 extern void trace_remove_event_call(struct ftrace_event_call *call);
63603
63604-#define is_signed_type(type) (((type)(-1)) < 0)
63605+#define is_signed_type(type) (((type)(-1)) < (type)1)
63606
63607 int trace_set_clr_event(const char *system, const char *event, int set);
63608
63609diff --git a/include/linux/genhd.h b/include/linux/genhd.h
63610index 4f440b3..342233a 100644
63611--- a/include/linux/genhd.h
63612+++ b/include/linux/genhd.h
63613@@ -190,7 +190,7 @@ struct gendisk {
63614 struct kobject *slave_dir;
63615
63616 struct timer_rand_state *random;
63617- atomic_t sync_io; /* RAID */
63618+ atomic_unchecked_t sync_io; /* RAID */
63619 struct disk_events *ev;
63620 #ifdef CONFIG_BLK_DEV_INTEGRITY
63621 struct blk_integrity *integrity;
63622diff --git a/include/linux/gfp.h b/include/linux/gfp.h
63623index d0a7967..63c4c47 100644
63624--- a/include/linux/gfp.h
63625+++ b/include/linux/gfp.h
63626@@ -35,6 +35,12 @@ struct vm_area_struct;
63627 #define ___GFP_OTHER_NODE 0x800000u
63628 #define ___GFP_WRITE 0x1000000u
63629
63630+#ifdef CONFIG_PAX_USERCOPY_SLABS
63631+#define ___GFP_USERCOPY 0x2000000u
63632+#else
63633+#define ___GFP_USERCOPY 0
63634+#endif
63635+
63636 /*
63637 * GFP bitmasks..
63638 *
63639@@ -89,6 +95,7 @@ struct vm_area_struct;
63640 #define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)
63641 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
63642 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
63643+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
63644
63645 /*
63646 * This may seem redundant, but it's a way of annotating false positives vs.
63647@@ -96,7 +103,7 @@ struct vm_area_struct;
63648 */
63649 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
63650
63651-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
63652+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
63653 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
63654
63655 /* This equals 0, but use constants in case they ever change */
63656@@ -150,6 +157,8 @@ struct vm_area_struct;
63657 /* 4GB DMA on some platforms */
63658 #define GFP_DMA32 __GFP_DMA32
63659
63660+#define GFP_USERCOPY __GFP_USERCOPY
63661+
63662 /* Convert GFP flags to their corresponding migrate type */
63663 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
63664 {
63665diff --git a/include/linux/gracl.h b/include/linux/gracl.h
63666new file mode 100644
63667index 0000000..ebe6d72
63668--- /dev/null
63669+++ b/include/linux/gracl.h
63670@@ -0,0 +1,319 @@
63671+#ifndef GR_ACL_H
63672+#define GR_ACL_H
63673+
63674+#include <linux/grdefs.h>
63675+#include <linux/resource.h>
63676+#include <linux/capability.h>
63677+#include <linux/dcache.h>
63678+#include <asm/resource.h>
63679+
63680+/* Major status information */
63681+
63682+#define GR_VERSION "grsecurity 2.9.1"
63683+#define GRSECURITY_VERSION 0x2901
63684+
63685+enum {
63686+ GR_SHUTDOWN = 0,
63687+ GR_ENABLE = 1,
63688+ GR_SPROLE = 2,
63689+ GR_RELOAD = 3,
63690+ GR_SEGVMOD = 4,
63691+ GR_STATUS = 5,
63692+ GR_UNSPROLE = 6,
63693+ GR_PASSSET = 7,
63694+ GR_SPROLEPAM = 8,
63695+};
63696+
63697+/* Password setup definitions
63698+ * kernel/grhash.c */
63699+enum {
63700+ GR_PW_LEN = 128,
63701+ GR_SALT_LEN = 16,
63702+ GR_SHA_LEN = 32,
63703+};
63704+
63705+enum {
63706+ GR_SPROLE_LEN = 64,
63707+};
63708+
63709+enum {
63710+ GR_NO_GLOB = 0,
63711+ GR_REG_GLOB,
63712+ GR_CREATE_GLOB
63713+};
63714+
63715+#define GR_NLIMITS 32
63716+
63717+/* Begin Data Structures */
63718+
63719+struct sprole_pw {
63720+ unsigned char *rolename;
63721+ unsigned char salt[GR_SALT_LEN];
63722+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
63723+};
63724+
63725+struct name_entry {
63726+ __u32 key;
63727+ ino_t inode;
63728+ dev_t device;
63729+ char *name;
63730+ __u16 len;
63731+ __u8 deleted;
63732+ struct name_entry *prev;
63733+ struct name_entry *next;
63734+};
63735+
63736+struct inodev_entry {
63737+ struct name_entry *nentry;
63738+ struct inodev_entry *prev;
63739+ struct inodev_entry *next;
63740+};
63741+
63742+struct acl_role_db {
63743+ struct acl_role_label **r_hash;
63744+ __u32 r_size;
63745+};
63746+
63747+struct inodev_db {
63748+ struct inodev_entry **i_hash;
63749+ __u32 i_size;
63750+};
63751+
63752+struct name_db {
63753+ struct name_entry **n_hash;
63754+ __u32 n_size;
63755+};
63756+
63757+struct crash_uid {
63758+ uid_t uid;
63759+ unsigned long expires;
63760+};
63761+
63762+struct gr_hash_struct {
63763+ void **table;
63764+ void **nametable;
63765+ void *first;
63766+ __u32 table_size;
63767+ __u32 used_size;
63768+ int type;
63769+};
63770+
63771+/* Userspace Grsecurity ACL data structures */
63772+
63773+struct acl_subject_label {
63774+ char *filename;
63775+ ino_t inode;
63776+ dev_t device;
63777+ __u32 mode;
63778+ kernel_cap_t cap_mask;
63779+ kernel_cap_t cap_lower;
63780+ kernel_cap_t cap_invert_audit;
63781+
63782+ struct rlimit res[GR_NLIMITS];
63783+ __u32 resmask;
63784+
63785+ __u8 user_trans_type;
63786+ __u8 group_trans_type;
63787+ uid_t *user_transitions;
63788+ gid_t *group_transitions;
63789+ __u16 user_trans_num;
63790+ __u16 group_trans_num;
63791+
63792+ __u32 sock_families[2];
63793+ __u32 ip_proto[8];
63794+ __u32 ip_type;
63795+ struct acl_ip_label **ips;
63796+ __u32 ip_num;
63797+ __u32 inaddr_any_override;
63798+
63799+ __u32 crashes;
63800+ unsigned long expires;
63801+
63802+ struct acl_subject_label *parent_subject;
63803+ struct gr_hash_struct *hash;
63804+ struct acl_subject_label *prev;
63805+ struct acl_subject_label *next;
63806+
63807+ struct acl_object_label **obj_hash;
63808+ __u32 obj_hash_size;
63809+ __u16 pax_flags;
63810+};
63811+
63812+struct role_allowed_ip {
63813+ __u32 addr;
63814+ __u32 netmask;
63815+
63816+ struct role_allowed_ip *prev;
63817+ struct role_allowed_ip *next;
63818+};
63819+
63820+struct role_transition {
63821+ char *rolename;
63822+
63823+ struct role_transition *prev;
63824+ struct role_transition *next;
63825+};
63826+
63827+struct acl_role_label {
63828+ char *rolename;
63829+ uid_t uidgid;
63830+ __u16 roletype;
63831+
63832+ __u16 auth_attempts;
63833+ unsigned long expires;
63834+
63835+ struct acl_subject_label *root_label;
63836+ struct gr_hash_struct *hash;
63837+
63838+ struct acl_role_label *prev;
63839+ struct acl_role_label *next;
63840+
63841+ struct role_transition *transitions;
63842+ struct role_allowed_ip *allowed_ips;
63843+ uid_t *domain_children;
63844+ __u16 domain_child_num;
63845+
63846+ umode_t umask;
63847+
63848+ struct acl_subject_label **subj_hash;
63849+ __u32 subj_hash_size;
63850+};
63851+
63852+struct user_acl_role_db {
63853+ struct acl_role_label **r_table;
63854+ __u32 num_pointers; /* Number of allocations to track */
63855+ __u32 num_roles; /* Number of roles */
63856+ __u32 num_domain_children; /* Number of domain children */
63857+ __u32 num_subjects; /* Number of subjects */
63858+ __u32 num_objects; /* Number of objects */
63859+};
63860+
63861+struct acl_object_label {
63862+ char *filename;
63863+ ino_t inode;
63864+ dev_t device;
63865+ __u32 mode;
63866+
63867+ struct acl_subject_label *nested;
63868+ struct acl_object_label *globbed;
63869+
63870+ /* next two structures not used */
63871+
63872+ struct acl_object_label *prev;
63873+ struct acl_object_label *next;
63874+};
63875+
63876+struct acl_ip_label {
63877+ char *iface;
63878+ __u32 addr;
63879+ __u32 netmask;
63880+ __u16 low, high;
63881+ __u8 mode;
63882+ __u32 type;
63883+ __u32 proto[8];
63884+
63885+ /* next two structures not used */
63886+
63887+ struct acl_ip_label *prev;
63888+ struct acl_ip_label *next;
63889+};
63890+
63891+struct gr_arg {
63892+ struct user_acl_role_db role_db;
63893+ unsigned char pw[GR_PW_LEN];
63894+ unsigned char salt[GR_SALT_LEN];
63895+ unsigned char sum[GR_SHA_LEN];
63896+ unsigned char sp_role[GR_SPROLE_LEN];
63897+ struct sprole_pw *sprole_pws;
63898+ dev_t segv_device;
63899+ ino_t segv_inode;
63900+ uid_t segv_uid;
63901+ __u16 num_sprole_pws;
63902+ __u16 mode;
63903+};
63904+
63905+struct gr_arg_wrapper {
63906+ struct gr_arg *arg;
63907+ __u32 version;
63908+ __u32 size;
63909+};
63910+
63911+struct subject_map {
63912+ struct acl_subject_label *user;
63913+ struct acl_subject_label *kernel;
63914+ struct subject_map *prev;
63915+ struct subject_map *next;
63916+};
63917+
63918+struct acl_subj_map_db {
63919+ struct subject_map **s_hash;
63920+ __u32 s_size;
63921+};
63922+
63923+/* End Data Structures Section */
63924+
63925+/* Hash functions generated by empirical testing by Brad Spengler
63926+ Makes good use of the low bits of the inode. Generally 0-1 times
63927+ in loop for successful match. 0-3 for unsuccessful match.
63928+ Shift/add algorithm with modulus of table size and an XOR*/
63929+
63930+static __inline__ unsigned int
63931+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
63932+{
63933+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
63934+}
63935+
63936+ static __inline__ unsigned int
63937+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
63938+{
63939+ return ((const unsigned long)userp % sz);
63940+}
63941+
63942+static __inline__ unsigned int
63943+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
63944+{
63945+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
63946+}
63947+
63948+static __inline__ unsigned int
63949+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
63950+{
63951+ return full_name_hash((const unsigned char *)name, len) % sz;
63952+}
63953+
63954+#define FOR_EACH_ROLE_START(role) \
63955+ role = role_list; \
63956+ while (role) {
63957+
63958+#define FOR_EACH_ROLE_END(role) \
63959+ role = role->prev; \
63960+ }
63961+
63962+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
63963+ subj = NULL; \
63964+ iter = 0; \
63965+ while (iter < role->subj_hash_size) { \
63966+ if (subj == NULL) \
63967+ subj = role->subj_hash[iter]; \
63968+ if (subj == NULL) { \
63969+ iter++; \
63970+ continue; \
63971+ }
63972+
63973+#define FOR_EACH_SUBJECT_END(subj,iter) \
63974+ subj = subj->next; \
63975+ if (subj == NULL) \
63976+ iter++; \
63977+ }
63978+
63979+
63980+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
63981+ subj = role->hash->first; \
63982+ while (subj != NULL) {
63983+
63984+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
63985+ subj = subj->next; \
63986+ }
63987+
63988+#endif
63989+
63990diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
63991new file mode 100644
63992index 0000000..323ecf2
63993--- /dev/null
63994+++ b/include/linux/gralloc.h
63995@@ -0,0 +1,9 @@
63996+#ifndef __GRALLOC_H
63997+#define __GRALLOC_H
63998+
63999+void acl_free_all(void);
64000+int acl_alloc_stack_init(unsigned long size);
64001+void *acl_alloc(unsigned long len);
64002+void *acl_alloc_num(unsigned long num, unsigned long len);
64003+
64004+#endif
64005diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
64006new file mode 100644
64007index 0000000..be66033
64008--- /dev/null
64009+++ b/include/linux/grdefs.h
64010@@ -0,0 +1,140 @@
64011+#ifndef GRDEFS_H
64012+#define GRDEFS_H
64013+
64014+/* Begin grsecurity status declarations */
64015+
64016+enum {
64017+ GR_READY = 0x01,
64018+ GR_STATUS_INIT = 0x00 // disabled state
64019+};
64020+
64021+/* Begin ACL declarations */
64022+
64023+/* Role flags */
64024+
64025+enum {
64026+ GR_ROLE_USER = 0x0001,
64027+ GR_ROLE_GROUP = 0x0002,
64028+ GR_ROLE_DEFAULT = 0x0004,
64029+ GR_ROLE_SPECIAL = 0x0008,
64030+ GR_ROLE_AUTH = 0x0010,
64031+ GR_ROLE_NOPW = 0x0020,
64032+ GR_ROLE_GOD = 0x0040,
64033+ GR_ROLE_LEARN = 0x0080,
64034+ GR_ROLE_TPE = 0x0100,
64035+ GR_ROLE_DOMAIN = 0x0200,
64036+ GR_ROLE_PAM = 0x0400,
64037+ GR_ROLE_PERSIST = 0x0800
64038+};
64039+
64040+/* ACL Subject and Object mode flags */
64041+enum {
64042+ GR_DELETED = 0x80000000
64043+};
64044+
64045+/* ACL Object-only mode flags */
64046+enum {
64047+ GR_READ = 0x00000001,
64048+ GR_APPEND = 0x00000002,
64049+ GR_WRITE = 0x00000004,
64050+ GR_EXEC = 0x00000008,
64051+ GR_FIND = 0x00000010,
64052+ GR_INHERIT = 0x00000020,
64053+ GR_SETID = 0x00000040,
64054+ GR_CREATE = 0x00000080,
64055+ GR_DELETE = 0x00000100,
64056+ GR_LINK = 0x00000200,
64057+ GR_AUDIT_READ = 0x00000400,
64058+ GR_AUDIT_APPEND = 0x00000800,
64059+ GR_AUDIT_WRITE = 0x00001000,
64060+ GR_AUDIT_EXEC = 0x00002000,
64061+ GR_AUDIT_FIND = 0x00004000,
64062+ GR_AUDIT_INHERIT= 0x00008000,
64063+ GR_AUDIT_SETID = 0x00010000,
64064+ GR_AUDIT_CREATE = 0x00020000,
64065+ GR_AUDIT_DELETE = 0x00040000,
64066+ GR_AUDIT_LINK = 0x00080000,
64067+ GR_PTRACERD = 0x00100000,
64068+ GR_NOPTRACE = 0x00200000,
64069+ GR_SUPPRESS = 0x00400000,
64070+ GR_NOLEARN = 0x00800000,
64071+ GR_INIT_TRANSFER= 0x01000000
64072+};
64073+
64074+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
64075+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
64076+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
64077+
64078+/* ACL subject-only mode flags */
64079+enum {
64080+ GR_KILL = 0x00000001,
64081+ GR_VIEW = 0x00000002,
64082+ GR_PROTECTED = 0x00000004,
64083+ GR_LEARN = 0x00000008,
64084+ GR_OVERRIDE = 0x00000010,
64085+ /* just a placeholder, this mode is only used in userspace */
64086+ GR_DUMMY = 0x00000020,
64087+ GR_PROTSHM = 0x00000040,
64088+ GR_KILLPROC = 0x00000080,
64089+ GR_KILLIPPROC = 0x00000100,
64090+ /* just a placeholder, this mode is only used in userspace */
64091+ GR_NOTROJAN = 0x00000200,
64092+ GR_PROTPROCFD = 0x00000400,
64093+ GR_PROCACCT = 0x00000800,
64094+ GR_RELAXPTRACE = 0x00001000,
64095+ //GR_NESTED = 0x00002000,
64096+ GR_INHERITLEARN = 0x00004000,
64097+ GR_PROCFIND = 0x00008000,
64098+ GR_POVERRIDE = 0x00010000,
64099+ GR_KERNELAUTH = 0x00020000,
64100+ GR_ATSECURE = 0x00040000,
64101+ GR_SHMEXEC = 0x00080000
64102+};
64103+
64104+enum {
64105+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
64106+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
64107+ GR_PAX_ENABLE_MPROTECT = 0x0004,
64108+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
64109+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
64110+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
64111+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
64112+ GR_PAX_DISABLE_MPROTECT = 0x0400,
64113+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
64114+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
64115+};
64116+
64117+enum {
64118+ GR_ID_USER = 0x01,
64119+ GR_ID_GROUP = 0x02,
64120+};
64121+
64122+enum {
64123+ GR_ID_ALLOW = 0x01,
64124+ GR_ID_DENY = 0x02,
64125+};
64126+
64127+#define GR_CRASH_RES 31
64128+#define GR_UIDTABLE_MAX 500
64129+
64130+/* begin resource learning section */
64131+enum {
64132+ GR_RLIM_CPU_BUMP = 60,
64133+ GR_RLIM_FSIZE_BUMP = 50000,
64134+ GR_RLIM_DATA_BUMP = 10000,
64135+ GR_RLIM_STACK_BUMP = 1000,
64136+ GR_RLIM_CORE_BUMP = 10000,
64137+ GR_RLIM_RSS_BUMP = 500000,
64138+ GR_RLIM_NPROC_BUMP = 1,
64139+ GR_RLIM_NOFILE_BUMP = 5,
64140+ GR_RLIM_MEMLOCK_BUMP = 50000,
64141+ GR_RLIM_AS_BUMP = 500000,
64142+ GR_RLIM_LOCKS_BUMP = 2,
64143+ GR_RLIM_SIGPENDING_BUMP = 5,
64144+ GR_RLIM_MSGQUEUE_BUMP = 10000,
64145+ GR_RLIM_NICE_BUMP = 1,
64146+ GR_RLIM_RTPRIO_BUMP = 1,
64147+ GR_RLIM_RTTIME_BUMP = 1000000
64148+};
64149+
64150+#endif
64151diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
64152new file mode 100644
64153index 0000000..baa6e96
64154--- /dev/null
64155+++ b/include/linux/grinternal.h
64156@@ -0,0 +1,215 @@
64157+#ifndef __GRINTERNAL_H
64158+#define __GRINTERNAL_H
64159+
64160+#ifdef CONFIG_GRKERNSEC
64161+
64162+#include <linux/fs.h>
64163+#include <linux/mnt_namespace.h>
64164+#include <linux/nsproxy.h>
64165+#include <linux/gracl.h>
64166+#include <linux/grdefs.h>
64167+#include <linux/grmsg.h>
64168+
64169+void gr_add_learn_entry(const char *fmt, ...)
64170+ __attribute__ ((format (printf, 1, 2)));
64171+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
64172+ const struct vfsmount *mnt);
64173+__u32 gr_check_create(const struct dentry *new_dentry,
64174+ const struct dentry *parent,
64175+ const struct vfsmount *mnt, const __u32 mode);
64176+int gr_check_protected_task(const struct task_struct *task);
64177+__u32 to_gr_audit(const __u32 reqmode);
64178+int gr_set_acls(const int type);
64179+int gr_apply_subject_to_task(struct task_struct *task);
64180+int gr_acl_is_enabled(void);
64181+char gr_roletype_to_char(void);
64182+
64183+void gr_handle_alertkill(struct task_struct *task);
64184+char *gr_to_filename(const struct dentry *dentry,
64185+ const struct vfsmount *mnt);
64186+char *gr_to_filename1(const struct dentry *dentry,
64187+ const struct vfsmount *mnt);
64188+char *gr_to_filename2(const struct dentry *dentry,
64189+ const struct vfsmount *mnt);
64190+char *gr_to_filename3(const struct dentry *dentry,
64191+ const struct vfsmount *mnt);
64192+
64193+extern int grsec_enable_ptrace_readexec;
64194+extern int grsec_enable_harden_ptrace;
64195+extern int grsec_enable_link;
64196+extern int grsec_enable_fifo;
64197+extern int grsec_enable_execve;
64198+extern int grsec_enable_shm;
64199+extern int grsec_enable_execlog;
64200+extern int grsec_enable_signal;
64201+extern int grsec_enable_audit_ptrace;
64202+extern int grsec_enable_forkfail;
64203+extern int grsec_enable_time;
64204+extern int grsec_enable_rofs;
64205+extern int grsec_enable_chroot_shmat;
64206+extern int grsec_enable_chroot_mount;
64207+extern int grsec_enable_chroot_double;
64208+extern int grsec_enable_chroot_pivot;
64209+extern int grsec_enable_chroot_chdir;
64210+extern int grsec_enable_chroot_chmod;
64211+extern int grsec_enable_chroot_mknod;
64212+extern int grsec_enable_chroot_fchdir;
64213+extern int grsec_enable_chroot_nice;
64214+extern int grsec_enable_chroot_execlog;
64215+extern int grsec_enable_chroot_caps;
64216+extern int grsec_enable_chroot_sysctl;
64217+extern int grsec_enable_chroot_unix;
64218+extern int grsec_enable_symlinkown;
64219+extern int grsec_symlinkown_gid;
64220+extern int grsec_enable_tpe;
64221+extern int grsec_tpe_gid;
64222+extern int grsec_enable_tpe_all;
64223+extern int grsec_enable_tpe_invert;
64224+extern int grsec_enable_socket_all;
64225+extern int grsec_socket_all_gid;
64226+extern int grsec_enable_socket_client;
64227+extern int grsec_socket_client_gid;
64228+extern int grsec_enable_socket_server;
64229+extern int grsec_socket_server_gid;
64230+extern int grsec_audit_gid;
64231+extern int grsec_enable_group;
64232+extern int grsec_enable_audit_textrel;
64233+extern int grsec_enable_log_rwxmaps;
64234+extern int grsec_enable_mount;
64235+extern int grsec_enable_chdir;
64236+extern int grsec_resource_logging;
64237+extern int grsec_enable_blackhole;
64238+extern int grsec_lastack_retries;
64239+extern int grsec_enable_brute;
64240+extern int grsec_lock;
64241+
64242+extern spinlock_t grsec_alert_lock;
64243+extern unsigned long grsec_alert_wtime;
64244+extern unsigned long grsec_alert_fyet;
64245+
64246+extern spinlock_t grsec_audit_lock;
64247+
64248+extern rwlock_t grsec_exec_file_lock;
64249+
64250+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
64251+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
64252+ (tsk)->exec_file->f_vfsmnt) : "/")
64253+
64254+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
64255+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
64256+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
64257+
64258+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
64259+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
64260+ (tsk)->exec_file->f_vfsmnt) : "/")
64261+
64262+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
64263+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
64264+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
64265+
64266+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
64267+
64268+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
64269+
64270+#define GR_CHROOT_CAPS {{ \
64271+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
64272+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
64273+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
64274+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
64275+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
64276+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
64277+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
64278+
64279+#define security_learn(normal_msg,args...) \
64280+({ \
64281+ read_lock(&grsec_exec_file_lock); \
64282+ gr_add_learn_entry(normal_msg "\n", ## args); \
64283+ read_unlock(&grsec_exec_file_lock); \
64284+})
64285+
64286+enum {
64287+ GR_DO_AUDIT,
64288+ GR_DONT_AUDIT,
64289+ /* used for non-audit messages that we shouldn't kill the task on */
64290+ GR_DONT_AUDIT_GOOD
64291+};
64292+
64293+enum {
64294+ GR_TTYSNIFF,
64295+ GR_RBAC,
64296+ GR_RBAC_STR,
64297+ GR_STR_RBAC,
64298+ GR_RBAC_MODE2,
64299+ GR_RBAC_MODE3,
64300+ GR_FILENAME,
64301+ GR_SYSCTL_HIDDEN,
64302+ GR_NOARGS,
64303+ GR_ONE_INT,
64304+ GR_ONE_INT_TWO_STR,
64305+ GR_ONE_STR,
64306+ GR_STR_INT,
64307+ GR_TWO_STR_INT,
64308+ GR_TWO_INT,
64309+ GR_TWO_U64,
64310+ GR_THREE_INT,
64311+ GR_FIVE_INT_TWO_STR,
64312+ GR_TWO_STR,
64313+ GR_THREE_STR,
64314+ GR_FOUR_STR,
64315+ GR_STR_FILENAME,
64316+ GR_FILENAME_STR,
64317+ GR_FILENAME_TWO_INT,
64318+ GR_FILENAME_TWO_INT_STR,
64319+ GR_TEXTREL,
64320+ GR_PTRACE,
64321+ GR_RESOURCE,
64322+ GR_CAP,
64323+ GR_SIG,
64324+ GR_SIG2,
64325+ GR_CRASH1,
64326+ GR_CRASH2,
64327+ GR_PSACCT,
64328+ GR_RWXMAP
64329+};
64330+
64331+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
64332+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
64333+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
64334+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
64335+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
64336+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
64337+#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)
64338+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
64339+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
64340+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
64341+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
64342+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
64343+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
64344+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
64345+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
64346+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
64347+#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)
64348+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
64349+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
64350+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
64351+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
64352+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
64353+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
64354+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
64355+#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)
64356+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
64357+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
64358+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
64359+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
64360+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
64361+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
64362+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
64363+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
64364+#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)
64365+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
64366+
64367+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
64368+
64369+#endif
64370+
64371+#endif
64372diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
64373new file mode 100644
64374index 0000000..2bd4c8d
64375--- /dev/null
64376+++ b/include/linux/grmsg.h
64377@@ -0,0 +1,111 @@
64378+#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"
64379+#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"
64380+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
64381+#define GR_STOPMOD_MSG "denied modification of module state by "
64382+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
64383+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
64384+#define GR_IOPERM_MSG "denied use of ioperm() by "
64385+#define GR_IOPL_MSG "denied use of iopl() by "
64386+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
64387+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
64388+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
64389+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
64390+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
64391+#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"
64392+#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"
64393+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
64394+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
64395+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
64396+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
64397+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
64398+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
64399+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
64400+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
64401+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
64402+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
64403+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
64404+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
64405+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
64406+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
64407+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
64408+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
64409+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
64410+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
64411+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
64412+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
64413+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
64414+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
64415+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
64416+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
64417+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
64418+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
64419+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
64420+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
64421+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
64422+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
64423+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
64424+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
64425+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
64426+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
64427+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
64428+#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"
64429+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
64430+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
64431+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
64432+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
64433+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
64434+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
64435+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
64436+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
64437+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
64438+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
64439+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
64440+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
64441+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
64442+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
64443+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
64444+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
64445+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
64446+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
64447+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
64448+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
64449+#define GR_FAILFORK_MSG "failed fork with errno %s by "
64450+#define GR_NICE_CHROOT_MSG "denied priority change by "
64451+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
64452+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
64453+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
64454+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
64455+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
64456+#define GR_TIME_MSG "time set by "
64457+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
64458+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
64459+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
64460+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
64461+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
64462+#define GR_BIND_MSG "denied bind() by "
64463+#define GR_CONNECT_MSG "denied connect() by "
64464+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
64465+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
64466+#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"
64467+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
64468+#define GR_CAP_ACL_MSG "use of %s denied for "
64469+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
64470+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
64471+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
64472+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
64473+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
64474+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
64475+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
64476+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
64477+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
64478+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
64479+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
64480+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
64481+#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
64482+#define GR_VM86_MSG "denied use of vm86 by "
64483+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
64484+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
64485+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
64486+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
64487+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
64488+#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 "
64489diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
64490new file mode 100644
64491index 0000000..c5e5913
64492--- /dev/null
64493+++ b/include/linux/grsecurity.h
64494@@ -0,0 +1,257 @@
64495+#ifndef GR_SECURITY_H
64496+#define GR_SECURITY_H
64497+#include <linux/fs.h>
64498+#include <linux/fs_struct.h>
64499+#include <linux/binfmts.h>
64500+#include <linux/gracl.h>
64501+
64502+/* notify of brain-dead configs */
64503+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64504+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
64505+#endif
64506+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
64507+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
64508+#endif
64509+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
64510+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
64511+#endif
64512+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
64513+#error "CONFIG_PAX enabled, but no PaX options are enabled."
64514+#endif
64515+
64516+#include <linux/compat.h>
64517+
64518+struct user_arg_ptr {
64519+#ifdef CONFIG_COMPAT
64520+ bool is_compat;
64521+#endif
64522+ union {
64523+ const char __user *const __user *native;
64524+#ifdef CONFIG_COMPAT
64525+ const compat_uptr_t __user *compat;
64526+#endif
64527+ } ptr;
64528+};
64529+
64530+void gr_handle_brute_attach(unsigned long mm_flags);
64531+void gr_handle_brute_check(void);
64532+void gr_handle_kernel_exploit(void);
64533+int gr_process_user_ban(void);
64534+
64535+char gr_roletype_to_char(void);
64536+
64537+int gr_acl_enable_at_secure(void);
64538+
64539+int gr_check_user_change(int real, int effective, int fs);
64540+int gr_check_group_change(int real, int effective, int fs);
64541+
64542+void gr_del_task_from_ip_table(struct task_struct *p);
64543+
64544+int gr_pid_is_chrooted(struct task_struct *p);
64545+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
64546+int gr_handle_chroot_nice(void);
64547+int gr_handle_chroot_sysctl(const int op);
64548+int gr_handle_chroot_setpriority(struct task_struct *p,
64549+ const int niceval);
64550+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
64551+int gr_handle_chroot_chroot(const struct dentry *dentry,
64552+ const struct vfsmount *mnt);
64553+void gr_handle_chroot_chdir(struct path *path);
64554+int gr_handle_chroot_chmod(const struct dentry *dentry,
64555+ const struct vfsmount *mnt, const int mode);
64556+int gr_handle_chroot_mknod(const struct dentry *dentry,
64557+ const struct vfsmount *mnt, const int mode);
64558+int gr_handle_chroot_mount(const struct dentry *dentry,
64559+ const struct vfsmount *mnt,
64560+ const char *dev_name);
64561+int gr_handle_chroot_pivot(void);
64562+int gr_handle_chroot_unix(const pid_t pid);
64563+
64564+int gr_handle_rawio(const struct inode *inode);
64565+
64566+void gr_handle_ioperm(void);
64567+void gr_handle_iopl(void);
64568+
64569+umode_t gr_acl_umask(void);
64570+
64571+int gr_tpe_allow(const struct file *file);
64572+
64573+void gr_set_chroot_entries(struct task_struct *task, struct path *path);
64574+void gr_clear_chroot_entries(struct task_struct *task);
64575+
64576+void gr_log_forkfail(const int retval);
64577+void gr_log_timechange(void);
64578+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
64579+void gr_log_chdir(const struct dentry *dentry,
64580+ const struct vfsmount *mnt);
64581+void gr_log_chroot_exec(const struct dentry *dentry,
64582+ const struct vfsmount *mnt);
64583+void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
64584+void gr_log_remount(const char *devname, const int retval);
64585+void gr_log_unmount(const char *devname, const int retval);
64586+void gr_log_mount(const char *from, const char *to, const int retval);
64587+void gr_log_textrel(struct vm_area_struct *vma);
64588+void gr_log_rwxmmap(struct file *file);
64589+void gr_log_rwxmprotect(struct file *file);
64590+
64591+int gr_handle_follow_link(const struct inode *parent,
64592+ const struct inode *inode,
64593+ const struct dentry *dentry,
64594+ const struct vfsmount *mnt);
64595+int gr_handle_fifo(const struct dentry *dentry,
64596+ const struct vfsmount *mnt,
64597+ const struct dentry *dir, const int flag,
64598+ const int acc_mode);
64599+int gr_handle_hardlink(const struct dentry *dentry,
64600+ const struct vfsmount *mnt,
64601+ struct inode *inode,
64602+ const int mode, const struct filename *to);
64603+
64604+int gr_is_capable(const int cap);
64605+int gr_is_capable_nolog(const int cap);
64606+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
64607+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
64608+
64609+void gr_copy_label(struct task_struct *tsk);
64610+void gr_handle_crash(struct task_struct *task, const int sig);
64611+int gr_handle_signal(const struct task_struct *p, const int sig);
64612+int gr_check_crash_uid(const uid_t uid);
64613+int gr_check_protected_task(const struct task_struct *task);
64614+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
64615+int gr_acl_handle_mmap(const struct file *file,
64616+ const unsigned long prot);
64617+int gr_acl_handle_mprotect(const struct file *file,
64618+ const unsigned long prot);
64619+int gr_check_hidden_task(const struct task_struct *tsk);
64620+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
64621+ const struct vfsmount *mnt);
64622+__u32 gr_acl_handle_utime(const struct dentry *dentry,
64623+ const struct vfsmount *mnt);
64624+__u32 gr_acl_handle_access(const struct dentry *dentry,
64625+ const struct vfsmount *mnt, const int fmode);
64626+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
64627+ const struct vfsmount *mnt, umode_t *mode);
64628+__u32 gr_acl_handle_chown(const struct dentry *dentry,
64629+ const struct vfsmount *mnt);
64630+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
64631+ const struct vfsmount *mnt);
64632+int gr_handle_ptrace(struct task_struct *task, const long request);
64633+int gr_handle_proc_ptrace(struct task_struct *task);
64634+__u32 gr_acl_handle_execve(const struct dentry *dentry,
64635+ const struct vfsmount *mnt);
64636+int gr_check_crash_exec(const struct file *filp);
64637+int gr_acl_is_enabled(void);
64638+void gr_set_kernel_label(struct task_struct *task);
64639+void gr_set_role_label(struct task_struct *task, const uid_t uid,
64640+ const gid_t gid);
64641+int gr_set_proc_label(const struct dentry *dentry,
64642+ const struct vfsmount *mnt,
64643+ const int unsafe_flags);
64644+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
64645+ const struct vfsmount *mnt);
64646+__u32 gr_acl_handle_open(const struct dentry *dentry,
64647+ const struct vfsmount *mnt, int acc_mode);
64648+__u32 gr_acl_handle_creat(const struct dentry *dentry,
64649+ const struct dentry *p_dentry,
64650+ const struct vfsmount *p_mnt,
64651+ int open_flags, int acc_mode, const int imode);
64652+void gr_handle_create(const struct dentry *dentry,
64653+ const struct vfsmount *mnt);
64654+void gr_handle_proc_create(const struct dentry *dentry,
64655+ const struct inode *inode);
64656+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
64657+ const struct dentry *parent_dentry,
64658+ const struct vfsmount *parent_mnt,
64659+ const int mode);
64660+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
64661+ const struct dentry *parent_dentry,
64662+ const struct vfsmount *parent_mnt);
64663+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
64664+ const struct vfsmount *mnt);
64665+void gr_handle_delete(const ino_t ino, const dev_t dev);
64666+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
64667+ const struct vfsmount *mnt);
64668+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
64669+ const struct dentry *parent_dentry,
64670+ const struct vfsmount *parent_mnt,
64671+ const struct filename *from);
64672+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
64673+ const struct dentry *parent_dentry,
64674+ const struct vfsmount *parent_mnt,
64675+ const struct dentry *old_dentry,
64676+ const struct vfsmount *old_mnt, const struct filename *to);
64677+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
64678+int gr_acl_handle_rename(struct dentry *new_dentry,
64679+ struct dentry *parent_dentry,
64680+ const struct vfsmount *parent_mnt,
64681+ struct dentry *old_dentry,
64682+ struct inode *old_parent_inode,
64683+ struct vfsmount *old_mnt, const struct filename *newname);
64684+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
64685+ struct dentry *old_dentry,
64686+ struct dentry *new_dentry,
64687+ struct vfsmount *mnt, const __u8 replace);
64688+__u32 gr_check_link(const struct dentry *new_dentry,
64689+ const struct dentry *parent_dentry,
64690+ const struct vfsmount *parent_mnt,
64691+ const struct dentry *old_dentry,
64692+ const struct vfsmount *old_mnt);
64693+int gr_acl_handle_filldir(const struct file *file, const char *name,
64694+ const unsigned int namelen, const ino_t ino);
64695+
64696+__u32 gr_acl_handle_unix(const struct dentry *dentry,
64697+ const struct vfsmount *mnt);
64698+void gr_acl_handle_exit(void);
64699+void gr_acl_handle_psacct(struct task_struct *task, const long code);
64700+int gr_acl_handle_procpidmem(const struct task_struct *task);
64701+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
64702+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
64703+void gr_audit_ptrace(struct task_struct *task);
64704+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
64705+void gr_put_exec_file(struct task_struct *task);
64706+
64707+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
64708+
64709+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
64710+extern void gr_learn_resource(const struct task_struct *task, const int res,
64711+ const unsigned long wanted, const int gt);
64712+#else
64713+static inline void gr_learn_resource(const struct task_struct *task, const int res,
64714+ const unsigned long wanted, const int gt)
64715+{
64716+}
64717+#endif
64718+
64719+#ifdef CONFIG_GRKERNSEC_RESLOG
64720+extern void gr_log_resource(const struct task_struct *task, const int res,
64721+ const unsigned long wanted, const int gt);
64722+#else
64723+static inline void gr_log_resource(const struct task_struct *task, const int res,
64724+ const unsigned long wanted, const int gt)
64725+{
64726+}
64727+#endif
64728+
64729+#ifdef CONFIG_GRKERNSEC
64730+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
64731+void gr_handle_vm86(void);
64732+void gr_handle_mem_readwrite(u64 from, u64 to);
64733+
64734+void gr_log_badprocpid(const char *entry);
64735+
64736+extern int grsec_enable_dmesg;
64737+extern int grsec_disable_privio;
64738+
64739+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
64740+extern int grsec_proc_gid;
64741+#endif
64742+
64743+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
64744+extern int grsec_enable_chroot_findtask;
64745+#endif
64746+#ifdef CONFIG_GRKERNSEC_SETXID
64747+extern int grsec_enable_setxid;
64748+#endif
64749+#endif
64750+
64751+#endif
64752diff --git a/include/linux/grsock.h b/include/linux/grsock.h
64753new file mode 100644
64754index 0000000..e7ffaaf
64755--- /dev/null
64756+++ b/include/linux/grsock.h
64757@@ -0,0 +1,19 @@
64758+#ifndef __GRSOCK_H
64759+#define __GRSOCK_H
64760+
64761+extern void gr_attach_curr_ip(const struct sock *sk);
64762+extern int gr_handle_sock_all(const int family, const int type,
64763+ const int protocol);
64764+extern int gr_handle_sock_server(const struct sockaddr *sck);
64765+extern int gr_handle_sock_server_other(const struct sock *sck);
64766+extern int gr_handle_sock_client(const struct sockaddr *sck);
64767+extern int gr_search_connect(struct socket * sock,
64768+ struct sockaddr_in * addr);
64769+extern int gr_search_bind(struct socket * sock,
64770+ struct sockaddr_in * addr);
64771+extern int gr_search_listen(struct socket * sock);
64772+extern int gr_search_accept(struct socket * sock);
64773+extern int gr_search_socket(const int domain, const int type,
64774+ const int protocol);
64775+
64776+#endif
64777diff --git a/include/linux/highmem.h b/include/linux/highmem.h
64778index ef788b5..ac41b7b 100644
64779--- a/include/linux/highmem.h
64780+++ b/include/linux/highmem.h
64781@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
64782 kunmap_atomic(kaddr);
64783 }
64784
64785+static inline void sanitize_highpage(struct page *page)
64786+{
64787+ void *kaddr;
64788+ unsigned long flags;
64789+
64790+ local_irq_save(flags);
64791+ kaddr = kmap_atomic(page);
64792+ clear_page(kaddr);
64793+ kunmap_atomic(kaddr);
64794+ local_irq_restore(flags);
64795+}
64796+
64797 static inline void zero_user_segments(struct page *page,
64798 unsigned start1, unsigned end1,
64799 unsigned start2, unsigned end2)
64800diff --git a/include/linux/i2c.h b/include/linux/i2c.h
64801index 800de22..7a2fa46 100644
64802--- a/include/linux/i2c.h
64803+++ b/include/linux/i2c.h
64804@@ -367,6 +367,7 @@ struct i2c_algorithm {
64805 /* To determine what the adapter supports */
64806 u32 (*functionality) (struct i2c_adapter *);
64807 };
64808+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
64809
64810 /*
64811 * i2c_adapter is the structure used to identify a physical i2c bus along
64812diff --git a/include/linux/i2o.h b/include/linux/i2o.h
64813index d23c3c2..eb63c81 100644
64814--- a/include/linux/i2o.h
64815+++ b/include/linux/i2o.h
64816@@ -565,7 +565,7 @@ struct i2o_controller {
64817 struct i2o_device *exec; /* Executive */
64818 #if BITS_PER_LONG == 64
64819 spinlock_t context_list_lock; /* lock for context_list */
64820- atomic_t context_list_counter; /* needed for unique contexts */
64821+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
64822 struct list_head context_list; /* list of context id's
64823 and pointers */
64824 #endif
64825diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
64826index aff7ad8..3942bbd 100644
64827--- a/include/linux/if_pppox.h
64828+++ b/include/linux/if_pppox.h
64829@@ -76,7 +76,7 @@ struct pppox_proto {
64830 int (*ioctl)(struct socket *sock, unsigned int cmd,
64831 unsigned long arg);
64832 struct module *owner;
64833-};
64834+} __do_const;
64835
64836 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
64837 extern void unregister_pppox_proto(int proto_num);
64838diff --git a/include/linux/init.h b/include/linux/init.h
64839index e59041e..df0a975 100644
64840--- a/include/linux/init.h
64841+++ b/include/linux/init.h
64842@@ -39,9 +39,36 @@
64843 * Also note, that this data cannot be "const".
64844 */
64845
64846+#ifdef MODULE
64847+#define add_init_latent_entropy
64848+#define add_devinit_latent_entropy
64849+#define add_cpuinit_latent_entropy
64850+#define add_meminit_latent_entropy
64851+#else
64852+#define add_init_latent_entropy __latent_entropy
64853+
64854+#ifdef CONFIG_HOTPLUG
64855+#define add_devinit_latent_entropy
64856+#else
64857+#define add_devinit_latent_entropy __latent_entropy
64858+#endif
64859+
64860+#ifdef CONFIG_HOTPLUG_CPU
64861+#define add_cpuinit_latent_entropy
64862+#else
64863+#define add_cpuinit_latent_entropy __latent_entropy
64864+#endif
64865+
64866+#ifdef CONFIG_MEMORY_HOTPLUG
64867+#define add_meminit_latent_entropy
64868+#else
64869+#define add_meminit_latent_entropy __latent_entropy
64870+#endif
64871+#endif
64872+
64873 /* These are for everybody (although not all archs will actually
64874 discard it in modules) */
64875-#define __init __section(.init.text) __cold notrace
64876+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
64877 #define __initdata __section(.init.data)
64878 #define __initconst __constsection(.init.rodata)
64879 #define __exitdata __section(.exit.data)
64880@@ -94,7 +121,7 @@
64881 #define __exit __section(.exit.text) __exitused __cold notrace
64882
64883 /* Used for HOTPLUG */
64884-#define __devinit __section(.devinit.text) __cold notrace
64885+#define __devinit __section(.devinit.text) __cold notrace add_devinit_latent_entropy
64886 #define __devinitdata __section(.devinit.data)
64887 #define __devinitconst __constsection(.devinit.rodata)
64888 #define __devexit __section(.devexit.text) __exitused __cold notrace
64889@@ -102,7 +129,7 @@
64890 #define __devexitconst __constsection(.devexit.rodata)
64891
64892 /* Used for HOTPLUG_CPU */
64893-#define __cpuinit __section(.cpuinit.text) __cold notrace
64894+#define __cpuinit __section(.cpuinit.text) __cold notrace add_cpuinit_latent_entropy
64895 #define __cpuinitdata __section(.cpuinit.data)
64896 #define __cpuinitconst __constsection(.cpuinit.rodata)
64897 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
64898@@ -110,7 +137,7 @@
64899 #define __cpuexitconst __constsection(.cpuexit.rodata)
64900
64901 /* Used for MEMORY_HOTPLUG */
64902-#define __meminit __section(.meminit.text) __cold notrace
64903+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
64904 #define __meminitdata __section(.meminit.data)
64905 #define __meminitconst __constsection(.meminit.rodata)
64906 #define __memexit __section(.memexit.text) __exitused __cold notrace
64907diff --git a/include/linux/init_task.h b/include/linux/init_task.h
64908index 6d087c5..401cab8 100644
64909--- a/include/linux/init_task.h
64910+++ b/include/linux/init_task.h
64911@@ -143,6 +143,12 @@ extern struct task_group root_task_group;
64912
64913 #define INIT_TASK_COMM "swapper"
64914
64915+#ifdef CONFIG_X86
64916+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
64917+#else
64918+#define INIT_TASK_THREAD_INFO
64919+#endif
64920+
64921 /*
64922 * INIT_TASK is used to set up the first task table, touch at
64923 * your own risk!. Base=0, limit=0x1fffff (=2MB)
64924@@ -182,6 +188,7 @@ extern struct task_group root_task_group;
64925 RCU_POINTER_INITIALIZER(cred, &init_cred), \
64926 .comm = INIT_TASK_COMM, \
64927 .thread = INIT_THREAD, \
64928+ INIT_TASK_THREAD_INFO \
64929 .fs = &init_fs, \
64930 .files = &init_files, \
64931 .signal = &init_signals, \
64932diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
64933index 5e4e617..eee383d 100644
64934--- a/include/linux/interrupt.h
64935+++ b/include/linux/interrupt.h
64936@@ -435,7 +435,7 @@ enum
64937 /* map softirq index to softirq name. update 'softirq_to_name' in
64938 * kernel/softirq.c when adding a new softirq.
64939 */
64940-extern char *softirq_to_name[NR_SOFTIRQS];
64941+extern const char * const softirq_to_name[NR_SOFTIRQS];
64942
64943 /* softirq mask and active fields moved to irq_cpustat_t in
64944 * asm/hardirq.h to get better cache usage. KAO
64945@@ -443,12 +443,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
64946
64947 struct softirq_action
64948 {
64949- void (*action)(struct softirq_action *);
64950+ void (*action)(void);
64951 };
64952
64953 asmlinkage void do_softirq(void);
64954 asmlinkage void __do_softirq(void);
64955-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
64956+extern void open_softirq(int nr, void (*action)(void));
64957 extern void softirq_init(void);
64958 extern void __raise_softirq_irqoff(unsigned int nr);
64959
64960diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
64961index 6883e19..06992b1 100644
64962--- a/include/linux/kallsyms.h
64963+++ b/include/linux/kallsyms.h
64964@@ -15,7 +15,8 @@
64965
64966 struct module;
64967
64968-#ifdef CONFIG_KALLSYMS
64969+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
64970+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
64971 /* Lookup the address for a symbol. Returns 0 if not found. */
64972 unsigned long kallsyms_lookup_name(const char *name);
64973
64974@@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
64975 /* Stupid that this does nothing, but I didn't create this mess. */
64976 #define __print_symbol(fmt, addr)
64977 #endif /*CONFIG_KALLSYMS*/
64978+#else /* when included by kallsyms.c, vsnprintf.c, or
64979+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
64980+extern void __print_symbol(const char *fmt, unsigned long address);
64981+extern int sprint_backtrace(char *buffer, unsigned long address);
64982+extern int sprint_symbol(char *buffer, unsigned long address);
64983+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
64984+const char *kallsyms_lookup(unsigned long addr,
64985+ unsigned long *symbolsize,
64986+ unsigned long *offset,
64987+ char **modname, char *namebuf);
64988+#endif
64989
64990 /* This macro allows us to keep printk typechecking */
64991 static __printf(1, 2)
64992diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
64993index 4dff0c6..1ca9b72 100644
64994--- a/include/linux/kgdb.h
64995+++ b/include/linux/kgdb.h
64996@@ -53,7 +53,7 @@ extern int kgdb_connected;
64997 extern int kgdb_io_module_registered;
64998
64999 extern atomic_t kgdb_setting_breakpoint;
65000-extern atomic_t kgdb_cpu_doing_single_step;
65001+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
65002
65003 extern struct task_struct *kgdb_usethread;
65004 extern struct task_struct *kgdb_contthread;
65005@@ -255,7 +255,7 @@ struct kgdb_arch {
65006 void (*correct_hw_break)(void);
65007
65008 void (*enable_nmi)(bool on);
65009-};
65010+} __do_const;
65011
65012 /**
65013 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
65014@@ -280,7 +280,7 @@ struct kgdb_io {
65015 void (*pre_exception) (void);
65016 void (*post_exception) (void);
65017 int is_console;
65018-};
65019+} __do_const;
65020
65021 extern struct kgdb_arch arch_kgdb_ops;
65022
65023diff --git a/include/linux/kmod.h b/include/linux/kmod.h
65024index 5398d58..5883a34 100644
65025--- a/include/linux/kmod.h
65026+++ b/include/linux/kmod.h
65027@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
65028 * usually useless though. */
65029 extern __printf(2, 3)
65030 int __request_module(bool wait, const char *name, ...);
65031+extern __printf(3, 4)
65032+int ___request_module(bool wait, char *param_name, const char *name, ...);
65033 #define request_module(mod...) __request_module(true, mod)
65034 #define request_module_nowait(mod...) __request_module(false, mod)
65035 #define try_then_request_module(x, mod...) \
65036diff --git a/include/linux/kobject.h b/include/linux/kobject.h
65037index 1e57449..4fede7b 100644
65038--- a/include/linux/kobject.h
65039+++ b/include/linux/kobject.h
65040@@ -111,7 +111,7 @@ struct kobj_type {
65041 struct attribute **default_attrs;
65042 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
65043 const void *(*namespace)(struct kobject *kobj);
65044-};
65045+} __do_const;
65046
65047 struct kobj_uevent_env {
65048 char *envp[UEVENT_NUM_ENVP];
65049diff --git a/include/linux/kref.h b/include/linux/kref.h
65050index 65af688..0592677 100644
65051--- a/include/linux/kref.h
65052+++ b/include/linux/kref.h
65053@@ -64,7 +64,7 @@ static inline void kref_get(struct kref *kref)
65054 static inline int kref_sub(struct kref *kref, unsigned int count,
65055 void (*release)(struct kref *kref))
65056 {
65057- WARN_ON(release == NULL);
65058+ BUG_ON(release == NULL);
65059
65060 if (atomic_sub_and_test((int) count, &kref->refcount)) {
65061 release(kref);
65062diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
65063index ecc5543..0e96bcc 100644
65064--- a/include/linux/kvm_host.h
65065+++ b/include/linux/kvm_host.h
65066@@ -403,7 +403,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
65067 int __must_check vcpu_load(struct kvm_vcpu *vcpu);
65068 void vcpu_put(struct kvm_vcpu *vcpu);
65069
65070-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
65071+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
65072 struct module *module);
65073 void kvm_exit(void);
65074
65075@@ -558,7 +558,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
65076 struct kvm_guest_debug *dbg);
65077 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
65078
65079-int kvm_arch_init(void *opaque);
65080+int kvm_arch_init(const void *opaque);
65081 void kvm_arch_exit(void);
65082
65083 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
65084diff --git a/include/linux/libata.h b/include/linux/libata.h
65085index 1e36c63..0c5046e 100644
65086--- a/include/linux/libata.h
65087+++ b/include/linux/libata.h
65088@@ -915,7 +915,7 @@ struct ata_port_operations {
65089 * fields must be pointers.
65090 */
65091 const struct ata_port_operations *inherits;
65092-};
65093+} __do_const;
65094
65095 struct ata_port_info {
65096 unsigned long flags;
65097diff --git a/include/linux/list.h b/include/linux/list.h
65098index cc6d2aa..71febca 100644
65099--- a/include/linux/list.h
65100+++ b/include/linux/list.h
65101@@ -112,6 +112,9 @@ extern void __list_del_entry(struct list_head *entry);
65102 extern void list_del(struct list_head *entry);
65103 #endif
65104
65105+extern void pax_list_add_tail(struct list_head *new, struct list_head *head);
65106+extern void pax_list_del(struct list_head *entry);
65107+
65108 /**
65109 * list_replace - replace old entry by new one
65110 * @old : the element to be replaced
65111diff --git a/include/linux/mm.h b/include/linux/mm.h
65112index 280dae5..39046ec 100644
65113--- a/include/linux/mm.h
65114+++ b/include/linux/mm.h
65115@@ -101,6 +101,11 @@ extern unsigned int kobjsize(const void *objp);
65116 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
65117 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
65118 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
65119+
65120+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
65121+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
65122+#endif
65123+
65124 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
65125
65126 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
65127@@ -1039,34 +1044,6 @@ int set_page_dirty(struct page *page);
65128 int set_page_dirty_lock(struct page *page);
65129 int clear_page_dirty_for_io(struct page *page);
65130
65131-/* Is the vma a continuation of the stack vma above it? */
65132-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
65133-{
65134- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
65135-}
65136-
65137-static inline int stack_guard_page_start(struct vm_area_struct *vma,
65138- unsigned long addr)
65139-{
65140- return (vma->vm_flags & VM_GROWSDOWN) &&
65141- (vma->vm_start == addr) &&
65142- !vma_growsdown(vma->vm_prev, addr);
65143-}
65144-
65145-/* Is the vma a continuation of the stack vma below it? */
65146-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
65147-{
65148- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
65149-}
65150-
65151-static inline int stack_guard_page_end(struct vm_area_struct *vma,
65152- unsigned long addr)
65153-{
65154- return (vma->vm_flags & VM_GROWSUP) &&
65155- (vma->vm_end == addr) &&
65156- !vma_growsup(vma->vm_next, addr);
65157-}
65158-
65159 extern pid_t
65160 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
65161
65162@@ -1166,6 +1143,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
65163 }
65164 #endif
65165
65166+#ifdef CONFIG_MMU
65167+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
65168+#else
65169+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
65170+{
65171+ return __pgprot(0);
65172+}
65173+#endif
65174+
65175 int vma_wants_writenotify(struct vm_area_struct *vma);
65176
65177 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
65178@@ -1184,8 +1170,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
65179 {
65180 return 0;
65181 }
65182+
65183+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
65184+ unsigned long address)
65185+{
65186+ return 0;
65187+}
65188 #else
65189 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
65190+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
65191 #endif
65192
65193 #ifdef __PAGETABLE_PMD_FOLDED
65194@@ -1194,8 +1187,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
65195 {
65196 return 0;
65197 }
65198+
65199+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
65200+ unsigned long address)
65201+{
65202+ return 0;
65203+}
65204 #else
65205 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
65206+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
65207 #endif
65208
65209 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
65210@@ -1213,11 +1213,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
65211 NULL: pud_offset(pgd, address);
65212 }
65213
65214+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
65215+{
65216+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
65217+ NULL: pud_offset(pgd, address);
65218+}
65219+
65220 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
65221 {
65222 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
65223 NULL: pmd_offset(pud, address);
65224 }
65225+
65226+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
65227+{
65228+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
65229+ NULL: pmd_offset(pud, address);
65230+}
65231 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
65232
65233 #if USE_SPLIT_PTLOCKS
65234@@ -1447,6 +1459,7 @@ extern unsigned long do_mmap_pgoff(struct file *, unsigned long,
65235 unsigned long, unsigned long,
65236 unsigned long, unsigned long);
65237 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
65238+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
65239
65240 /* These take the mm semaphore themselves */
65241 extern unsigned long vm_brk(unsigned long, unsigned long);
65242@@ -1510,6 +1523,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
65243 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
65244 struct vm_area_struct **pprev);
65245
65246+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
65247+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
65248+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
65249+
65250 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
65251 NULL if none. Assume start_addr < end_addr. */
65252 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
65253@@ -1538,15 +1555,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
65254 return vma;
65255 }
65256
65257-#ifdef CONFIG_MMU
65258-pgprot_t vm_get_page_prot(unsigned long vm_flags);
65259-#else
65260-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
65261-{
65262- return __pgprot(0);
65263-}
65264-#endif
65265-
65266 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
65267 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
65268 unsigned long pfn, unsigned long size, pgprot_t);
65269@@ -1652,7 +1660,7 @@ extern int unpoison_memory(unsigned long pfn);
65270 extern int sysctl_memory_failure_early_kill;
65271 extern int sysctl_memory_failure_recovery;
65272 extern void shake_page(struct page *p, int access);
65273-extern atomic_long_t mce_bad_pages;
65274+extern atomic_long_unchecked_t mce_bad_pages;
65275 extern int soft_offline_page(struct page *page, int flags);
65276
65277 extern void dump_page(struct page *page);
65278@@ -1683,5 +1691,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
65279 static inline bool page_is_guard(struct page *page) { return false; }
65280 #endif /* CONFIG_DEBUG_PAGEALLOC */
65281
65282+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
65283+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
65284+#else
65285+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
65286+#endif
65287+
65288 #endif /* __KERNEL__ */
65289 #endif /* _LINUX_MM_H */
65290diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
65291index 31f8a3a..499f1db 100644
65292--- a/include/linux/mm_types.h
65293+++ b/include/linux/mm_types.h
65294@@ -275,6 +275,8 @@ struct vm_area_struct {
65295 #ifdef CONFIG_NUMA
65296 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
65297 #endif
65298+
65299+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
65300 };
65301
65302 struct core_thread {
65303@@ -348,7 +350,7 @@ struct mm_struct {
65304 unsigned long def_flags;
65305 unsigned long nr_ptes; /* Page table pages */
65306 unsigned long start_code, end_code, start_data, end_data;
65307- unsigned long start_brk, brk, start_stack;
65308+ unsigned long brk_gap, start_brk, brk, start_stack;
65309 unsigned long arg_start, arg_end, env_start, env_end;
65310
65311 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
65312@@ -399,6 +401,24 @@ struct mm_struct {
65313 struct cpumask cpumask_allocation;
65314 #endif
65315 struct uprobes_state uprobes_state;
65316+
65317+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
65318+ unsigned long pax_flags;
65319+#endif
65320+
65321+#ifdef CONFIG_PAX_DLRESOLVE
65322+ unsigned long call_dl_resolve;
65323+#endif
65324+
65325+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
65326+ unsigned long call_syscall;
65327+#endif
65328+
65329+#ifdef CONFIG_PAX_ASLR
65330+ unsigned long delta_mmap; /* randomized offset */
65331+ unsigned long delta_stack; /* randomized offset */
65332+#endif
65333+
65334 };
65335
65336 static inline void mm_init_cpumask(struct mm_struct *mm)
65337diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
65338index c5d5278..f0b68c8 100644
65339--- a/include/linux/mmiotrace.h
65340+++ b/include/linux/mmiotrace.h
65341@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
65342 /* Called from ioremap.c */
65343 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
65344 void __iomem *addr);
65345-extern void mmiotrace_iounmap(volatile void __iomem *addr);
65346+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
65347
65348 /* For anyone to insert markers. Remember trailing newline. */
65349 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
65350@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
65351 {
65352 }
65353
65354-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
65355+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
65356 {
65357 }
65358
65359diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
65360index a23923b..073fee4 100644
65361--- a/include/linux/mmzone.h
65362+++ b/include/linux/mmzone.h
65363@@ -421,7 +421,7 @@ struct zone {
65364 unsigned long flags; /* zone flags, see below */
65365
65366 /* Zone statistics */
65367- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
65368+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
65369
65370 /*
65371 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
65372diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
65373index fed3def..7cc3f93 100644
65374--- a/include/linux/mod_devicetable.h
65375+++ b/include/linux/mod_devicetable.h
65376@@ -12,7 +12,7 @@
65377 typedef unsigned long kernel_ulong_t;
65378 #endif
65379
65380-#define PCI_ANY_ID (~0)
65381+#define PCI_ANY_ID ((__u16)~0)
65382
65383 struct pci_device_id {
65384 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
65385@@ -139,7 +139,7 @@ struct usb_device_id {
65386 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
65387 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
65388
65389-#define HID_ANY_ID (~0)
65390+#define HID_ANY_ID (~0U)
65391 #define HID_BUS_ANY 0xffff
65392 #define HID_GROUP_ANY 0x0000
65393
65394diff --git a/include/linux/module.h b/include/linux/module.h
65395index 1375ee3..d631af0 100644
65396--- a/include/linux/module.h
65397+++ b/include/linux/module.h
65398@@ -17,9 +17,11 @@
65399 #include <linux/moduleparam.h>
65400 #include <linux/tracepoint.h>
65401 #include <linux/export.h>
65402+#include <linux/fs.h>
65403
65404 #include <linux/percpu.h>
65405 #include <asm/module.h>
65406+#include <asm/pgtable.h>
65407
65408 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
65409 #define MODULE_SIG_STRING "~Module signature appended~\n"
65410@@ -281,19 +283,16 @@ struct module
65411 int (*init)(void);
65412
65413 /* If this is non-NULL, vfree after init() returns */
65414- void *module_init;
65415+ void *module_init_rx, *module_init_rw;
65416
65417 /* Here is the actual code + data, vfree'd on unload. */
65418- void *module_core;
65419+ void *module_core_rx, *module_core_rw;
65420
65421 /* Here are the sizes of the init and core sections */
65422- unsigned int init_size, core_size;
65423+ unsigned int init_size_rw, core_size_rw;
65424
65425 /* The size of the executable code in each section. */
65426- unsigned int init_text_size, core_text_size;
65427-
65428- /* Size of RO sections of the module (text+rodata) */
65429- unsigned int init_ro_size, core_ro_size;
65430+ unsigned int init_size_rx, core_size_rx;
65431
65432 /* Arch-specific module values */
65433 struct mod_arch_specific arch;
65434@@ -349,6 +348,10 @@ struct module
65435 #ifdef CONFIG_EVENT_TRACING
65436 struct ftrace_event_call **trace_events;
65437 unsigned int num_trace_events;
65438+ struct file_operations trace_id;
65439+ struct file_operations trace_enable;
65440+ struct file_operations trace_format;
65441+ struct file_operations trace_filter;
65442 #endif
65443 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
65444 unsigned int num_ftrace_callsites;
65445@@ -396,16 +399,46 @@ bool is_module_address(unsigned long addr);
65446 bool is_module_percpu_address(unsigned long addr);
65447 bool is_module_text_address(unsigned long addr);
65448
65449+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
65450+{
65451+
65452+#ifdef CONFIG_PAX_KERNEXEC
65453+ if (ktla_ktva(addr) >= (unsigned long)start &&
65454+ ktla_ktva(addr) < (unsigned long)start + size)
65455+ return 1;
65456+#endif
65457+
65458+ return ((void *)addr >= start && (void *)addr < start + size);
65459+}
65460+
65461+static inline int within_module_core_rx(unsigned long addr, struct module *mod)
65462+{
65463+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
65464+}
65465+
65466+static inline int within_module_core_rw(unsigned long addr, struct module *mod)
65467+{
65468+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
65469+}
65470+
65471+static inline int within_module_init_rx(unsigned long addr, struct module *mod)
65472+{
65473+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
65474+}
65475+
65476+static inline int within_module_init_rw(unsigned long addr, struct module *mod)
65477+{
65478+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
65479+}
65480+
65481 static inline int within_module_core(unsigned long addr, struct module *mod)
65482 {
65483- return (unsigned long)mod->module_core <= addr &&
65484- addr < (unsigned long)mod->module_core + mod->core_size;
65485+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
65486 }
65487
65488 static inline int within_module_init(unsigned long addr, struct module *mod)
65489 {
65490- return (unsigned long)mod->module_init <= addr &&
65491- addr < (unsigned long)mod->module_init + mod->init_size;
65492+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
65493 }
65494
65495 /* Search for module by name: must hold module_mutex. */
65496diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
65497index 560ca53..5ee8d73 100644
65498--- a/include/linux/moduleloader.h
65499+++ b/include/linux/moduleloader.h
65500@@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
65501
65502 /* Allocator used for allocating struct module, core sections and init
65503 sections. Returns NULL on failure. */
65504-void *module_alloc(unsigned long size);
65505+void *module_alloc(unsigned long size) __size_overflow(1);
65506+
65507+#ifdef CONFIG_PAX_KERNEXEC
65508+void *module_alloc_exec(unsigned long size) __size_overflow(1);
65509+#else
65510+#define module_alloc_exec(x) module_alloc(x)
65511+#endif
65512
65513 /* Free memory returned from module_alloc. */
65514 void module_free(struct module *mod, void *module_region);
65515
65516+#ifdef CONFIG_PAX_KERNEXEC
65517+void module_free_exec(struct module *mod, void *module_region);
65518+#else
65519+#define module_free_exec(x, y) module_free((x), (y))
65520+#endif
65521+
65522 /*
65523 * Apply the given relocation to the (simplified) ELF. Return -error
65524 * or 0.
65525@@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
65526 unsigned int relsec,
65527 struct module *me)
65528 {
65529+#ifdef CONFIG_MODULES
65530 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
65531+#endif
65532 return -ENOEXEC;
65533 }
65534 #endif
65535@@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
65536 unsigned int relsec,
65537 struct module *me)
65538 {
65539+#ifdef CONFIG_MODULES
65540 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
65541+#endif
65542 return -ENOEXEC;
65543 }
65544 #endif
65545diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
65546index d6a5806..7c13347 100644
65547--- a/include/linux/moduleparam.h
65548+++ b/include/linux/moduleparam.h
65549@@ -286,7 +286,7 @@ static inline void __kernel_param_unlock(void)
65550 * @len is usually just sizeof(string).
65551 */
65552 #define module_param_string(name, string, len, perm) \
65553- static const struct kparam_string __param_string_##name \
65554+ static const struct kparam_string __param_string_##name __used \
65555 = { len, string }; \
65556 __module_param_call(MODULE_PARAM_PREFIX, name, \
65557 &param_ops_string, \
65558@@ -425,7 +425,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
65559 */
65560 #define module_param_array_named(name, array, type, nump, perm) \
65561 param_check_##type(name, &(array)[0]); \
65562- static const struct kparam_array __param_arr_##name \
65563+ static const struct kparam_array __param_arr_##name __used \
65564 = { .max = ARRAY_SIZE(array), .num = nump, \
65565 .ops = &param_ops_##type, \
65566 .elemsize = sizeof(array[0]), .elem = array }; \
65567diff --git a/include/linux/namei.h b/include/linux/namei.h
65568index 4bf19d8..5268cea 100644
65569--- a/include/linux/namei.h
65570+++ b/include/linux/namei.h
65571@@ -18,7 +18,7 @@ struct nameidata {
65572 unsigned seq;
65573 int last_type;
65574 unsigned depth;
65575- char *saved_names[MAX_NESTED_LINKS + 1];
65576+ const char *saved_names[MAX_NESTED_LINKS + 1];
65577 };
65578
65579 /*
65580@@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
65581
65582 extern void nd_jump_link(struct nameidata *nd, struct path *path);
65583
65584-static inline void nd_set_link(struct nameidata *nd, char *path)
65585+static inline void nd_set_link(struct nameidata *nd, const char *path)
65586 {
65587 nd->saved_names[nd->depth] = path;
65588 }
65589
65590-static inline char *nd_get_link(struct nameidata *nd)
65591+static inline const char *nd_get_link(const struct nameidata *nd)
65592 {
65593 return nd->saved_names[nd->depth];
65594 }
65595diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
65596index a848ffc..3bbbaee 100644
65597--- a/include/linux/netdevice.h
65598+++ b/include/linux/netdevice.h
65599@@ -999,6 +999,7 @@ struct net_device_ops {
65600 struct net_device *dev,
65601 int idx);
65602 };
65603+typedef struct net_device_ops __no_const net_device_ops_no_const;
65604
65605 /*
65606 * The DEVICE structure.
65607@@ -1059,7 +1060,7 @@ struct net_device {
65608 int iflink;
65609
65610 struct net_device_stats stats;
65611- atomic_long_t rx_dropped; /* dropped packets by core network
65612+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
65613 * Do not use this in drivers.
65614 */
65615
65616diff --git a/include/linux/netfilter/ipset/ip_set.h b/include/linux/netfilter/ipset/ip_set.h
65617index 7958e84..ed74d7a 100644
65618--- a/include/linux/netfilter/ipset/ip_set.h
65619+++ b/include/linux/netfilter/ipset/ip_set.h
65620@@ -98,7 +98,7 @@ struct ip_set_type_variant {
65621 /* Return true if "b" set is the same as "a"
65622 * according to the create set parameters */
65623 bool (*same_set)(const struct ip_set *a, const struct ip_set *b);
65624-};
65625+} __do_const;
65626
65627 /* The core set type structure */
65628 struct ip_set_type {
65629diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
65630index 4966dde..7d8ce06 100644
65631--- a/include/linux/netfilter/nfnetlink.h
65632+++ b/include/linux/netfilter/nfnetlink.h
65633@@ -16,7 +16,7 @@ struct nfnl_callback {
65634 const struct nlattr * const cda[]);
65635 const struct nla_policy *policy; /* netlink attribute policy */
65636 const u_int16_t attr_count; /* number of nlattr's */
65637-};
65638+} __do_const;
65639
65640 struct nfnetlink_subsystem {
65641 const char *name;
65642diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
65643new file mode 100644
65644index 0000000..33f4af8
65645--- /dev/null
65646+++ b/include/linux/netfilter/xt_gradm.h
65647@@ -0,0 +1,9 @@
65648+#ifndef _LINUX_NETFILTER_XT_GRADM_H
65649+#define _LINUX_NETFILTER_XT_GRADM_H 1
65650+
65651+struct xt_gradm_mtinfo {
65652+ __u16 flags;
65653+ __u16 invflags;
65654+};
65655+
65656+#endif
65657diff --git a/include/linux/notifier.h b/include/linux/notifier.h
65658index d65746e..62e72c2 100644
65659--- a/include/linux/notifier.h
65660+++ b/include/linux/notifier.h
65661@@ -51,7 +51,8 @@ struct notifier_block {
65662 int (*notifier_call)(struct notifier_block *, unsigned long, void *);
65663 struct notifier_block __rcu *next;
65664 int priority;
65665-};
65666+} __do_const;
65667+typedef struct notifier_block __no_const notifier_block_no_const;
65668
65669 struct atomic_notifier_head {
65670 spinlock_t lock;
65671diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
65672index a4c5624..79d6d88 100644
65673--- a/include/linux/oprofile.h
65674+++ b/include/linux/oprofile.h
65675@@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
65676 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
65677 char const * name, ulong * val);
65678
65679-/** Create a file for read-only access to an atomic_t. */
65680+/** Create a file for read-only access to an atomic_unchecked_t. */
65681 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
65682- char const * name, atomic_t * val);
65683+ char const * name, atomic_unchecked_t * val);
65684
65685 /** create a directory */
65686 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
65687diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
65688index 6bfb2faa..1204767 100644
65689--- a/include/linux/perf_event.h
65690+++ b/include/linux/perf_event.h
65691@@ -328,8 +328,8 @@ struct perf_event {
65692
65693 enum perf_event_active_state state;
65694 unsigned int attach_state;
65695- local64_t count;
65696- atomic64_t child_count;
65697+ local64_t count; /* PaX: fix it one day */
65698+ atomic64_unchecked_t child_count;
65699
65700 /*
65701 * These are the total time in nanoseconds that the event
65702@@ -380,8 +380,8 @@ struct perf_event {
65703 * These accumulate total time (in nanoseconds) that children
65704 * events have been enabled and running, respectively.
65705 */
65706- atomic64_t child_total_time_enabled;
65707- atomic64_t child_total_time_running;
65708+ atomic64_unchecked_t child_total_time_enabled;
65709+ atomic64_unchecked_t child_total_time_running;
65710
65711 /*
65712 * Protect attach/detach and child_list:
65713diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
65714index ad1a427..6419649 100644
65715--- a/include/linux/pipe_fs_i.h
65716+++ b/include/linux/pipe_fs_i.h
65717@@ -45,9 +45,9 @@ struct pipe_buffer {
65718 struct pipe_inode_info {
65719 wait_queue_head_t wait;
65720 unsigned int nrbufs, curbuf, buffers;
65721- unsigned int readers;
65722- unsigned int writers;
65723- unsigned int waiting_writers;
65724+ atomic_t readers;
65725+ atomic_t writers;
65726+ atomic_t waiting_writers;
65727 unsigned int r_counter;
65728 unsigned int w_counter;
65729 struct page *tmp_page;
65730diff --git a/include/linux/platform_data/usb-ehci-s5p.h b/include/linux/platform_data/usb-ehci-s5p.h
65731index 5f28cae..3d23723 100644
65732--- a/include/linux/platform_data/usb-ehci-s5p.h
65733+++ b/include/linux/platform_data/usb-ehci-s5p.h
65734@@ -14,7 +14,7 @@
65735 struct s5p_ehci_platdata {
65736 int (*phy_init)(struct platform_device *pdev, int type);
65737 int (*phy_exit)(struct platform_device *pdev, int type);
65738-};
65739+} __no_const;
65740
65741 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
65742
65743diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
65744index f271860..6b3bec5 100644
65745--- a/include/linux/pm_runtime.h
65746+++ b/include/linux/pm_runtime.h
65747@@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
65748
65749 static inline void pm_runtime_mark_last_busy(struct device *dev)
65750 {
65751- ACCESS_ONCE(dev->power.last_busy) = jiffies;
65752+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
65753 }
65754
65755 #else /* !CONFIG_PM_RUNTIME */
65756diff --git a/include/linux/poison.h b/include/linux/poison.h
65757index 2110a81..13a11bb 100644
65758--- a/include/linux/poison.h
65759+++ b/include/linux/poison.h
65760@@ -19,8 +19,8 @@
65761 * under normal circumstances, used to verify that nobody uses
65762 * non-initialized list entries.
65763 */
65764-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
65765-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
65766+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
65767+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
65768
65769 /********** include/linux/timer.h **********/
65770 /*
65771diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
65772index 4a496eb..d9c5659 100644
65773--- a/include/linux/power/smartreflex.h
65774+++ b/include/linux/power/smartreflex.h
65775@@ -238,7 +238,7 @@ struct omap_sr_class_data {
65776 int (*notify)(struct omap_sr *sr, u32 status);
65777 u8 notify_flags;
65778 u8 class_type;
65779-};
65780+} __do_const;
65781
65782 /**
65783 * struct omap_sr_nvalue_table - Smartreflex n-target value info
65784diff --git a/include/linux/printk.h b/include/linux/printk.h
65785index 9afc01e..92c32e8 100644
65786--- a/include/linux/printk.h
65787+++ b/include/linux/printk.h
65788@@ -101,6 +101,8 @@ void early_printk(const char *fmt, ...);
65789 extern int printk_needs_cpu(int cpu);
65790 extern void printk_tick(void);
65791
65792+extern int kptr_restrict;
65793+
65794 #ifdef CONFIG_PRINTK
65795 asmlinkage __printf(5, 0)
65796 int vprintk_emit(int facility, int level,
65797@@ -135,7 +137,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
65798
65799 extern int printk_delay_msec;
65800 extern int dmesg_restrict;
65801-extern int kptr_restrict;
65802
65803 void log_buf_kexec_setup(void);
65804 void __init setup_log_buf(int early);
65805diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
65806index 3fd2e87..75db910 100644
65807--- a/include/linux/proc_fs.h
65808+++ b/include/linux/proc_fs.h
65809@@ -155,6 +155,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
65810 return proc_create_data(name, mode, parent, proc_fops, NULL);
65811 }
65812
65813+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
65814+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
65815+{
65816+#ifdef CONFIG_GRKERNSEC_PROC_USER
65817+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
65818+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65819+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
65820+#else
65821+ return proc_create_data(name, mode, parent, proc_fops, NULL);
65822+#endif
65823+}
65824+
65825 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
65826 umode_t mode, struct proc_dir_entry *base,
65827 read_proc_t *read_proc, void * data)
65828diff --git a/include/linux/random.h b/include/linux/random.h
65829index 6330ed4..419c6c3 100644
65830--- a/include/linux/random.h
65831+++ b/include/linux/random.h
65832@@ -30,12 +30,17 @@ void srandom32(u32 seed);
65833
65834 u32 prandom32(struct rnd_state *);
65835
65836+static inline unsigned long pax_get_random_long(void)
65837+{
65838+ return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
65839+}
65840+
65841 /*
65842 * Handle minimum values for seeds
65843 */
65844 static inline u32 __seed(u32 x, u32 m)
65845 {
65846- return (x < m) ? x + m : x;
65847+ return (x <= m) ? x + m + 1 : x;
65848 }
65849
65850 /**
65851diff --git a/include/linux/reboot.h b/include/linux/reboot.h
65852index 23b3630..e1bc12b 100644
65853--- a/include/linux/reboot.h
65854+++ b/include/linux/reboot.h
65855@@ -18,9 +18,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
65856 * Architecture-specific implementations of sys_reboot commands.
65857 */
65858
65859-extern void machine_restart(char *cmd);
65860-extern void machine_halt(void);
65861-extern void machine_power_off(void);
65862+extern void machine_restart(char *cmd) __noreturn;
65863+extern void machine_halt(void) __noreturn;
65864+extern void machine_power_off(void) __noreturn;
65865
65866 extern void machine_shutdown(void);
65867 struct pt_regs;
65868@@ -31,9 +31,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
65869 */
65870
65871 extern void kernel_restart_prepare(char *cmd);
65872-extern void kernel_restart(char *cmd);
65873-extern void kernel_halt(void);
65874-extern void kernel_power_off(void);
65875+extern void kernel_restart(char *cmd) __noreturn;
65876+extern void kernel_halt(void) __noreturn;
65877+extern void kernel_power_off(void) __noreturn;
65878
65879 extern int C_A_D; /* for sysctl */
65880 void ctrl_alt_del(void);
65881@@ -47,7 +47,7 @@ extern int orderly_poweroff(bool force);
65882 * Emergency restart, callable from an interrupt handler.
65883 */
65884
65885-extern void emergency_restart(void);
65886+extern void emergency_restart(void) __noreturn;
65887 #include <asm/emergency-restart.h>
65888
65889 #endif /* _LINUX_REBOOT_H */
65890diff --git a/include/linux/regset.h b/include/linux/regset.h
65891index 8e0c9fe..fdb64bc 100644
65892--- a/include/linux/regset.h
65893+++ b/include/linux/regset.h
65894@@ -161,7 +161,7 @@ struct user_regset {
65895 unsigned int align;
65896 unsigned int bias;
65897 unsigned int core_note_type;
65898-};
65899+} __do_const;
65900
65901 /**
65902 * struct user_regset_view - available regsets
65903diff --git a/include/linux/relay.h b/include/linux/relay.h
65904index 91cacc3..b55ff74 100644
65905--- a/include/linux/relay.h
65906+++ b/include/linux/relay.h
65907@@ -160,7 +160,7 @@ struct rchan_callbacks
65908 * The callback should return 0 if successful, negative if not.
65909 */
65910 int (*remove_buf_file)(struct dentry *dentry);
65911-};
65912+} __no_const;
65913
65914 /*
65915 * CONFIG_RELAY kernel API, kernel/relay.c
65916diff --git a/include/linux/rio.h b/include/linux/rio.h
65917index a3e7842..d973ca6 100644
65918--- a/include/linux/rio.h
65919+++ b/include/linux/rio.h
65920@@ -339,7 +339,7 @@ struct rio_ops {
65921 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
65922 u64 rstart, u32 size, u32 flags);
65923 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
65924-};
65925+} __no_const;
65926
65927 #define RIO_RESOURCE_MEM 0x00000100
65928 #define RIO_RESOURCE_DOORBELL 0x00000200
65929diff --git a/include/linux/rmap.h b/include/linux/rmap.h
65930index bfe1f47..6a33ee3 100644
65931--- a/include/linux/rmap.h
65932+++ b/include/linux/rmap.h
65933@@ -134,8 +134,8 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
65934 void anon_vma_init(void); /* create anon_vma_cachep */
65935 int anon_vma_prepare(struct vm_area_struct *);
65936 void unlink_anon_vmas(struct vm_area_struct *);
65937-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
65938-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
65939+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
65940+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
65941
65942 static inline void anon_vma_merge(struct vm_area_struct *vma,
65943 struct vm_area_struct *next)
65944diff --git a/include/linux/sched.h b/include/linux/sched.h
65945index 3e63925..6c93b17 100644
65946--- a/include/linux/sched.h
65947+++ b/include/linux/sched.h
65948@@ -61,6 +61,7 @@ struct bio_list;
65949 struct fs_struct;
65950 struct perf_event_context;
65951 struct blk_plug;
65952+struct linux_binprm;
65953
65954 /*
65955 * List of flags we want to share for kernel threads,
65956@@ -344,10 +345,23 @@ struct user_namespace;
65957 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
65958
65959 extern int sysctl_max_map_count;
65960+extern unsigned long sysctl_heap_stack_gap;
65961
65962 #include <linux/aio.h>
65963
65964 #ifdef CONFIG_MMU
65965+
65966+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
65967+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
65968+#else
65969+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
65970+{
65971+ return 0;
65972+}
65973+#endif
65974+
65975+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
65976+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
65977 extern void arch_pick_mmap_layout(struct mm_struct *mm);
65978 extern unsigned long
65979 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
65980@@ -614,6 +628,17 @@ struct signal_struct {
65981 #ifdef CONFIG_TASKSTATS
65982 struct taskstats *stats;
65983 #endif
65984+
65985+#ifdef CONFIG_GRKERNSEC
65986+ u32 curr_ip;
65987+ u32 saved_ip;
65988+ u32 gr_saddr;
65989+ u32 gr_daddr;
65990+ u16 gr_sport;
65991+ u16 gr_dport;
65992+ u8 used_accept:1;
65993+#endif
65994+
65995 #ifdef CONFIG_AUDIT
65996 unsigned audit_tty;
65997 struct tty_audit_buf *tty_audit_buf;
65998@@ -691,6 +716,11 @@ struct user_struct {
65999 struct key *session_keyring; /* UID's default session keyring */
66000 #endif
66001
66002+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
66003+ unsigned int banned;
66004+ unsigned long ban_expires;
66005+#endif
66006+
66007 /* Hash table maintenance information */
66008 struct hlist_node uidhash_node;
66009 kuid_t uid;
66010@@ -1312,8 +1342,8 @@ struct task_struct {
66011 struct list_head thread_group;
66012
66013 struct completion *vfork_done; /* for vfork() */
66014- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
66015- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
66016+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
66017+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
66018
66019 cputime_t utime, stime, utimescaled, stimescaled;
66020 cputime_t gtime;
66021@@ -1329,11 +1359,6 @@ struct task_struct {
66022 struct task_cputime cputime_expires;
66023 struct list_head cpu_timers[3];
66024
66025-/* process credentials */
66026- const struct cred __rcu *real_cred; /* objective and real subjective task
66027- * credentials (COW) */
66028- const struct cred __rcu *cred; /* effective (overridable) subjective task
66029- * credentials (COW) */
66030 char comm[TASK_COMM_LEN]; /* executable name excluding path
66031 - access with [gs]et_task_comm (which lock
66032 it with task_lock())
66033@@ -1350,6 +1375,10 @@ struct task_struct {
66034 #endif
66035 /* CPU-specific state of this task */
66036 struct thread_struct thread;
66037+/* thread_info moved to task_struct */
66038+#ifdef CONFIG_X86
66039+ struct thread_info tinfo;
66040+#endif
66041 /* filesystem information */
66042 struct fs_struct *fs;
66043 /* open file information */
66044@@ -1423,6 +1452,10 @@ struct task_struct {
66045 gfp_t lockdep_reclaim_gfp;
66046 #endif
66047
66048+/* process credentials */
66049+ const struct cred __rcu *real_cred; /* objective and real subjective task
66050+ * credentials (COW) */
66051+
66052 /* journalling filesystem info */
66053 void *journal_info;
66054
66055@@ -1461,6 +1494,10 @@ struct task_struct {
66056 /* cg_list protected by css_set_lock and tsk->alloc_lock */
66057 struct list_head cg_list;
66058 #endif
66059+
66060+ const struct cred __rcu *cred; /* effective (overridable) subjective task
66061+ * credentials (COW) */
66062+
66063 #ifdef CONFIG_FUTEX
66064 struct robust_list_head __user *robust_list;
66065 #ifdef CONFIG_COMPAT
66066@@ -1548,8 +1585,74 @@ struct task_struct {
66067 #ifdef CONFIG_UPROBES
66068 struct uprobe_task *utask;
66069 #endif
66070+
66071+#ifdef CONFIG_GRKERNSEC
66072+ /* grsecurity */
66073+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66074+ u64 exec_id;
66075+#endif
66076+#ifdef CONFIG_GRKERNSEC_SETXID
66077+ const struct cred *delayed_cred;
66078+#endif
66079+ struct dentry *gr_chroot_dentry;
66080+ struct acl_subject_label *acl;
66081+ struct acl_role_label *role;
66082+ struct file *exec_file;
66083+ unsigned long brute_expires;
66084+ u16 acl_role_id;
66085+ /* is this the task that authenticated to the special role */
66086+ u8 acl_sp_role;
66087+ u8 is_writable;
66088+ u8 brute;
66089+ u8 gr_is_chrooted;
66090+#endif
66091+
66092 };
66093
66094+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
66095+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
66096+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
66097+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
66098+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
66099+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
66100+
66101+#ifdef CONFIG_PAX_SOFTMODE
66102+extern int pax_softmode;
66103+#endif
66104+
66105+extern int pax_check_flags(unsigned long *);
66106+
66107+/* if tsk != current then task_lock must be held on it */
66108+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
66109+static inline unsigned long pax_get_flags(struct task_struct *tsk)
66110+{
66111+ if (likely(tsk->mm))
66112+ return tsk->mm->pax_flags;
66113+ else
66114+ return 0UL;
66115+}
66116+
66117+/* if tsk != current then task_lock must be held on it */
66118+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
66119+{
66120+ if (likely(tsk->mm)) {
66121+ tsk->mm->pax_flags = flags;
66122+ return 0;
66123+ }
66124+ return -EINVAL;
66125+}
66126+#endif
66127+
66128+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
66129+extern void pax_set_initial_flags(struct linux_binprm *bprm);
66130+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
66131+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
66132+#endif
66133+
66134+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
66135+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
66136+extern void pax_report_refcount_overflow(struct pt_regs *regs);
66137+
66138 /* Future-safe accessor for struct task_struct's cpus_allowed. */
66139 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
66140
66141@@ -2092,7 +2195,9 @@ void yield(void);
66142 extern struct exec_domain default_exec_domain;
66143
66144 union thread_union {
66145+#ifndef CONFIG_X86
66146 struct thread_info thread_info;
66147+#endif
66148 unsigned long stack[THREAD_SIZE/sizeof(long)];
66149 };
66150
66151@@ -2125,6 +2230,7 @@ extern struct pid_namespace init_pid_ns;
66152 */
66153
66154 extern struct task_struct *find_task_by_vpid(pid_t nr);
66155+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
66156 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
66157 struct pid_namespace *ns);
66158
66159@@ -2281,7 +2387,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
66160 extern void exit_itimers(struct signal_struct *);
66161 extern void flush_itimer_signals(void);
66162
66163-extern void do_group_exit(int);
66164+extern __noreturn void do_group_exit(int);
66165
66166 extern void daemonize(const char *, ...);
66167 extern int allow_signal(int);
66168@@ -2485,9 +2591,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
66169
66170 #endif
66171
66172-static inline int object_is_on_stack(void *obj)
66173+static inline int object_starts_on_stack(void *obj)
66174 {
66175- void *stack = task_stack_page(current);
66176+ const void *stack = task_stack_page(current);
66177
66178 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
66179 }
66180diff --git a/include/linux/security.h b/include/linux/security.h
66181index 05e88bd..5cda002 100644
66182--- a/include/linux/security.h
66183+++ b/include/linux/security.h
66184@@ -26,6 +26,7 @@
66185 #include <linux/capability.h>
66186 #include <linux/slab.h>
66187 #include <linux/err.h>
66188+#include <linux/grsecurity.h>
66189
66190 struct linux_binprm;
66191 struct cred;
66192diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
66193index 68a04a3..866e6a1 100644
66194--- a/include/linux/seq_file.h
66195+++ b/include/linux/seq_file.h
66196@@ -26,6 +26,9 @@ struct seq_file {
66197 struct mutex lock;
66198 const struct seq_operations *op;
66199 int poll_event;
66200+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66201+ u64 exec_id;
66202+#endif
66203 #ifdef CONFIG_USER_NS
66204 struct user_namespace *user_ns;
66205 #endif
66206@@ -38,6 +41,7 @@ struct seq_operations {
66207 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
66208 int (*show) (struct seq_file *m, void *v);
66209 };
66210+typedef struct seq_operations __no_const seq_operations_no_const;
66211
66212 #define SEQ_SKIP 1
66213
66214diff --git a/include/linux/shm.h b/include/linux/shm.h
66215index bcf8a6a..4d0af77 100644
66216--- a/include/linux/shm.h
66217+++ b/include/linux/shm.h
66218@@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
66219
66220 /* The task created the shm object. NULL if the task is dead. */
66221 struct task_struct *shm_creator;
66222+#ifdef CONFIG_GRKERNSEC
66223+ time_t shm_createtime;
66224+ pid_t shm_lapid;
66225+#endif
66226 };
66227
66228 /* shm_mode upper byte flags */
66229diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
66230index 6a2c34e..a1f320f 100644
66231--- a/include/linux/skbuff.h
66232+++ b/include/linux/skbuff.h
66233@@ -577,7 +577,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
66234 extern struct sk_buff *__alloc_skb(unsigned int size,
66235 gfp_t priority, int flags, int node);
66236 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
66237-static inline struct sk_buff *alloc_skb(unsigned int size,
66238+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
66239 gfp_t priority)
66240 {
66241 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
66242@@ -687,7 +687,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
66243 */
66244 static inline int skb_queue_empty(const struct sk_buff_head *list)
66245 {
66246- return list->next == (struct sk_buff *)list;
66247+ return list->next == (const struct sk_buff *)list;
66248 }
66249
66250 /**
66251@@ -700,7 +700,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
66252 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
66253 const struct sk_buff *skb)
66254 {
66255- return skb->next == (struct sk_buff *)list;
66256+ return skb->next == (const struct sk_buff *)list;
66257 }
66258
66259 /**
66260@@ -713,7 +713,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
66261 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
66262 const struct sk_buff *skb)
66263 {
66264- return skb->prev == (struct sk_buff *)list;
66265+ return skb->prev == (const struct sk_buff *)list;
66266 }
66267
66268 /**
66269@@ -1626,7 +1626,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
66270 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
66271 */
66272 #ifndef NET_SKB_PAD
66273-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
66274+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
66275 #endif
66276
66277 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
66278@@ -2204,7 +2204,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
66279 int noblock, int *err);
66280 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
66281 struct poll_table_struct *wait);
66282-extern int skb_copy_datagram_iovec(const struct sk_buff *from,
66283+extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
66284 int offset, struct iovec *to,
66285 int size);
66286 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
66287diff --git a/include/linux/slab.h b/include/linux/slab.h
66288index 83d1a14..e23d723 100644
66289--- a/include/linux/slab.h
66290+++ b/include/linux/slab.h
66291@@ -11,12 +11,20 @@
66292
66293 #include <linux/gfp.h>
66294 #include <linux/types.h>
66295+#include <linux/err.h>
66296
66297 /*
66298 * Flags to pass to kmem_cache_create().
66299 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
66300 */
66301 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
66302+
66303+#ifdef CONFIG_PAX_USERCOPY_SLABS
66304+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
66305+#else
66306+#define SLAB_USERCOPY 0x00000000UL
66307+#endif
66308+
66309 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
66310 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
66311 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
66312@@ -87,10 +95,13 @@
66313 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
66314 * Both make kfree a no-op.
66315 */
66316-#define ZERO_SIZE_PTR ((void *)16)
66317+#define ZERO_SIZE_PTR \
66318+({ \
66319+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
66320+ (void *)(-MAX_ERRNO-1L); \
66321+})
66322
66323-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
66324- (unsigned long)ZERO_SIZE_PTR)
66325+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
66326
66327 /*
66328 * Common fields provided in kmem_cache by all slab allocators
66329@@ -110,7 +121,7 @@ struct kmem_cache {
66330 unsigned int align; /* Alignment as calculated */
66331 unsigned long flags; /* Active flags on the slab */
66332 const char *name; /* Slab name for sysfs */
66333- int refcount; /* Use counter */
66334+ atomic_t refcount; /* Use counter */
66335 void (*ctor)(void *); /* Called on object slot creation */
66336 struct list_head list; /* List of all slab caches on the system */
66337 };
66338@@ -185,6 +196,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
66339 void kfree(const void *);
66340 void kzfree(const void *);
66341 size_t ksize(const void *);
66342+const char *check_heap_object(const void *ptr, unsigned long n);
66343+bool is_usercopy_object(const void *ptr);
66344
66345 /*
66346 * Allocator specific definitions. These are mainly used to establish optimized
66347@@ -264,8 +277,18 @@ size_t ksize(const void *);
66348 * for general use, and so are not documented here. For a full list of
66349 * potential flags, always refer to linux/gfp.h.
66350 */
66351+
66352+extern void kmalloc_array_error(void)
66353+#if defined(CONFIG_GCOV_KERNEL) && defined(CONFIG_PAX_SIZE_OVERFLOW)
66354+__compiletime_warning("kmalloc_array called with swapped arguments?");
66355+#else
66356+__compiletime_error("kmalloc_array called with swapped arguments?");
66357+#endif
66358+
66359 static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
66360 {
66361+ if (__builtin_constant_p(n) && !__builtin_constant_p(size))
66362+ kmalloc_array_error();
66363 if (size != 0 && n > SIZE_MAX / size)
66364 return NULL;
66365 return __kmalloc(n * size, flags);
66366@@ -323,7 +346,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
66367 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
66368 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
66369 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
66370-extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
66371+extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
66372 #define kmalloc_track_caller(size, flags) \
66373 __kmalloc_track_caller(size, flags, _RET_IP_)
66374 #else
66375@@ -343,7 +366,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
66376 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
66377 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
66378 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
66379-extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
66380+extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
66381 #define kmalloc_node_track_caller(size, flags, node) \
66382 __kmalloc_node_track_caller(size, flags, node, \
66383 _RET_IP_)
66384diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
66385index cc290f0..0ba60931 100644
66386--- a/include/linux/slab_def.h
66387+++ b/include/linux/slab_def.h
66388@@ -52,7 +52,7 @@ struct kmem_cache {
66389 /* 4) cache creation/removal */
66390 const char *name;
66391 struct list_head list;
66392- int refcount;
66393+ atomic_t refcount;
66394 int object_size;
66395 int align;
66396
66397@@ -68,10 +68,10 @@ struct kmem_cache {
66398 unsigned long node_allocs;
66399 unsigned long node_frees;
66400 unsigned long node_overflow;
66401- atomic_t allochit;
66402- atomic_t allocmiss;
66403- atomic_t freehit;
66404- atomic_t freemiss;
66405+ atomic_unchecked_t allochit;
66406+ atomic_unchecked_t allocmiss;
66407+ atomic_unchecked_t freehit;
66408+ atomic_unchecked_t freemiss;
66409
66410 /*
66411 * If debugging is enabled, then the allocator can add additional
66412@@ -104,11 +104,16 @@ struct cache_sizes {
66413 #ifdef CONFIG_ZONE_DMA
66414 struct kmem_cache *cs_dmacachep;
66415 #endif
66416+
66417+#ifdef CONFIG_PAX_USERCOPY_SLABS
66418+ struct kmem_cache *cs_usercopycachep;
66419+#endif
66420+
66421 };
66422 extern struct cache_sizes malloc_sizes[];
66423
66424 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
66425-void *__kmalloc(size_t size, gfp_t flags);
66426+void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
66427
66428 #ifdef CONFIG_TRACING
66429 extern void *kmem_cache_alloc_trace(struct kmem_cache *, gfp_t, size_t);
66430@@ -145,6 +150,13 @@ found:
66431 cachep = malloc_sizes[i].cs_dmacachep;
66432 else
66433 #endif
66434+
66435+#ifdef CONFIG_PAX_USERCOPY_SLABS
66436+ if (flags & GFP_USERCOPY)
66437+ cachep = malloc_sizes[i].cs_usercopycachep;
66438+ else
66439+#endif
66440+
66441 cachep = malloc_sizes[i].cs_cachep;
66442
66443 ret = kmem_cache_alloc_trace(cachep, flags, size);
66444@@ -155,7 +167,7 @@ found:
66445 }
66446
66447 #ifdef CONFIG_NUMA
66448-extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
66449+extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
66450 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
66451
66452 #ifdef CONFIG_TRACING
66453@@ -198,6 +210,13 @@ found:
66454 cachep = malloc_sizes[i].cs_dmacachep;
66455 else
66456 #endif
66457+
66458+#ifdef CONFIG_PAX_USERCOPY_SLABS
66459+ if (flags & GFP_USERCOPY)
66460+ cachep = malloc_sizes[i].cs_usercopycachep;
66461+ else
66462+#endif
66463+
66464 cachep = malloc_sizes[i].cs_cachep;
66465
66466 return kmem_cache_alloc_node_trace(cachep, flags, node, size);
66467diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
66468index f28e14a..7831211 100644
66469--- a/include/linux/slob_def.h
66470+++ b/include/linux/slob_def.h
66471@@ -11,7 +11,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
66472 return kmem_cache_alloc_node(cachep, flags, NUMA_NO_NODE);
66473 }
66474
66475-void *__kmalloc_node(size_t size, gfp_t flags, int node);
66476+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
66477
66478 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
66479 {
66480@@ -31,7 +31,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
66481 return __kmalloc_node(size, flags, NUMA_NO_NODE);
66482 }
66483
66484-static __always_inline void *__kmalloc(size_t size, gfp_t flags)
66485+static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
66486 {
66487 return kmalloc(size, flags);
66488 }
66489diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
66490index df448ad..b99e7f6 100644
66491--- a/include/linux/slub_def.h
66492+++ b/include/linux/slub_def.h
66493@@ -91,7 +91,7 @@ struct kmem_cache {
66494 struct kmem_cache_order_objects max;
66495 struct kmem_cache_order_objects min;
66496 gfp_t allocflags; /* gfp flags to use on each alloc */
66497- int refcount; /* Refcount for slab cache destroy */
66498+ atomic_t refcount; /* Refcount for slab cache destroy */
66499 void (*ctor)(void *);
66500 int inuse; /* Offset to metadata */
66501 int align; /* Alignment */
66502@@ -152,7 +152,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
66503 * Sorry that the following has to be that ugly but some versions of GCC
66504 * have trouble with constant propagation and loops.
66505 */
66506-static __always_inline int kmalloc_index(size_t size)
66507+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
66508 {
66509 if (!size)
66510 return 0;
66511@@ -217,7 +217,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
66512 }
66513
66514 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
66515-void *__kmalloc(size_t size, gfp_t flags);
66516+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
66517
66518 static __always_inline void *
66519 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
66520@@ -258,7 +258,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
66521 }
66522 #endif
66523
66524-static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
66525+static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
66526 {
66527 unsigned int order = get_order(size);
66528 return kmalloc_order_trace(size, flags, order);
66529@@ -283,7 +283,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
66530 }
66531
66532 #ifdef CONFIG_NUMA
66533-void *__kmalloc_node(size_t size, gfp_t flags, int node);
66534+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
66535 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
66536
66537 #ifdef CONFIG_TRACING
66538diff --git a/include/linux/sonet.h b/include/linux/sonet.h
66539index 680f9a3..f13aeb0 100644
66540--- a/include/linux/sonet.h
66541+++ b/include/linux/sonet.h
66542@@ -7,7 +7,7 @@
66543 #include <uapi/linux/sonet.h>
66544
66545 struct k_sonet_stats {
66546-#define __HANDLE_ITEM(i) atomic_t i
66547+#define __HANDLE_ITEM(i) atomic_unchecked_t i
66548 __SONET_ITEMS
66549 #undef __HANDLE_ITEM
66550 };
66551diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
66552index 34206b8..f019e06 100644
66553--- a/include/linux/sunrpc/clnt.h
66554+++ b/include/linux/sunrpc/clnt.h
66555@@ -176,9 +176,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
66556 {
66557 switch (sap->sa_family) {
66558 case AF_INET:
66559- return ntohs(((struct sockaddr_in *)sap)->sin_port);
66560+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
66561 case AF_INET6:
66562- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
66563+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
66564 }
66565 return 0;
66566 }
66567@@ -211,7 +211,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
66568 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
66569 const struct sockaddr *src)
66570 {
66571- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
66572+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
66573 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
66574
66575 dsin->sin_family = ssin->sin_family;
66576@@ -314,7 +314,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
66577 if (sa->sa_family != AF_INET6)
66578 return 0;
66579
66580- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
66581+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
66582 }
66583
66584 #endif /* __KERNEL__ */
66585diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
66586index 0b8e3e6..33e0a01 100644
66587--- a/include/linux/sunrpc/svc_rdma.h
66588+++ b/include/linux/sunrpc/svc_rdma.h
66589@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
66590 extern unsigned int svcrdma_max_requests;
66591 extern unsigned int svcrdma_max_req_size;
66592
66593-extern atomic_t rdma_stat_recv;
66594-extern atomic_t rdma_stat_read;
66595-extern atomic_t rdma_stat_write;
66596-extern atomic_t rdma_stat_sq_starve;
66597-extern atomic_t rdma_stat_rq_starve;
66598-extern atomic_t rdma_stat_rq_poll;
66599-extern atomic_t rdma_stat_rq_prod;
66600-extern atomic_t rdma_stat_sq_poll;
66601-extern atomic_t rdma_stat_sq_prod;
66602+extern atomic_unchecked_t rdma_stat_recv;
66603+extern atomic_unchecked_t rdma_stat_read;
66604+extern atomic_unchecked_t rdma_stat_write;
66605+extern atomic_unchecked_t rdma_stat_sq_starve;
66606+extern atomic_unchecked_t rdma_stat_rq_starve;
66607+extern atomic_unchecked_t rdma_stat_rq_poll;
66608+extern atomic_unchecked_t rdma_stat_rq_prod;
66609+extern atomic_unchecked_t rdma_stat_sq_poll;
66610+extern atomic_unchecked_t rdma_stat_sq_prod;
66611
66612 #define RPCRDMA_VERSION 1
66613
66614diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
66615index cd844a6..3ca3592 100644
66616--- a/include/linux/sysctl.h
66617+++ b/include/linux/sysctl.h
66618@@ -41,6 +41,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
66619
66620 extern int proc_dostring(struct ctl_table *, int,
66621 void __user *, size_t *, loff_t *);
66622+extern int proc_dostring_modpriv(struct ctl_table *, int,
66623+ void __user *, size_t *, loff_t *);
66624 extern int proc_dointvec(struct ctl_table *, int,
66625 void __user *, size_t *, loff_t *);
66626 extern int proc_dointvec_minmax(struct ctl_table *, int,
66627diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
66628index 7faf933..eb6f5e3 100644
66629--- a/include/linux/sysrq.h
66630+++ b/include/linux/sysrq.h
66631@@ -36,7 +36,7 @@ struct sysrq_key_op {
66632 char *help_msg;
66633 char *action_msg;
66634 int enable_mask;
66635-};
66636+} __do_const;
66637
66638 #ifdef CONFIG_MAGIC_SYSRQ
66639
66640diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
66641index ccc1899..b1aaceb 100644
66642--- a/include/linux/thread_info.h
66643+++ b/include/linux/thread_info.h
66644@@ -146,6 +146,15 @@ static inline bool test_and_clear_restore_sigmask(void)
66645 #error "no set_restore_sigmask() provided and default one won't work"
66646 #endif
66647
66648+extern void __check_object_size(const void *ptr, unsigned long n, bool to);
66649+static inline void check_object_size(const void *ptr, unsigned long n, bool to)
66650+{
66651+#ifndef CONFIG_PAX_USERCOPY_DEBUG
66652+ if (!__builtin_constant_p(n))
66653+#endif
66654+ __check_object_size(ptr, n, to);
66655+}
66656+
66657 #endif /* __KERNEL__ */
66658
66659 #endif /* _LINUX_THREAD_INFO_H */
66660diff --git a/include/linux/tty.h b/include/linux/tty.h
66661index f0b4eb4..1c4854e 100644
66662--- a/include/linux/tty.h
66663+++ b/include/linux/tty.h
66664@@ -192,7 +192,7 @@ struct tty_port {
66665 const struct tty_port_operations *ops; /* Port operations */
66666 spinlock_t lock; /* Lock protecting tty field */
66667 int blocked_open; /* Waiting to open */
66668- int count; /* Usage count */
66669+ atomic_t count; /* Usage count */
66670 wait_queue_head_t open_wait; /* Open waiters */
66671 wait_queue_head_t close_wait; /* Close waiters */
66672 wait_queue_head_t delta_msr_wait; /* Modem status change */
66673@@ -513,7 +513,7 @@ extern int tty_port_open(struct tty_port *port,
66674 struct tty_struct *tty, struct file *filp);
66675 static inline int tty_port_users(struct tty_port *port)
66676 {
66677- return port->count + port->blocked_open;
66678+ return atomic_read(&port->count) + port->blocked_open;
66679 }
66680
66681 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
66682diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
66683index dd976cf..e272742 100644
66684--- a/include/linux/tty_driver.h
66685+++ b/include/linux/tty_driver.h
66686@@ -284,7 +284,7 @@ struct tty_operations {
66687 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
66688 #endif
66689 const struct file_operations *proc_fops;
66690-};
66691+} __do_const;
66692
66693 struct tty_driver {
66694 int magic; /* magic number for this structure */
66695diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
66696index fb79dd8d..07d4773 100644
66697--- a/include/linux/tty_ldisc.h
66698+++ b/include/linux/tty_ldisc.h
66699@@ -149,7 +149,7 @@ struct tty_ldisc_ops {
66700
66701 struct module *owner;
66702
66703- int refcount;
66704+ atomic_t refcount;
66705 };
66706
66707 struct tty_ldisc {
66708diff --git a/include/linux/types.h b/include/linux/types.h
66709index 1cc0e4b..0d50edf 100644
66710--- a/include/linux/types.h
66711+++ b/include/linux/types.h
66712@@ -175,10 +175,26 @@ typedef struct {
66713 int counter;
66714 } atomic_t;
66715
66716+#ifdef CONFIG_PAX_REFCOUNT
66717+typedef struct {
66718+ int counter;
66719+} atomic_unchecked_t;
66720+#else
66721+typedef atomic_t atomic_unchecked_t;
66722+#endif
66723+
66724 #ifdef CONFIG_64BIT
66725 typedef struct {
66726 long counter;
66727 } atomic64_t;
66728+
66729+#ifdef CONFIG_PAX_REFCOUNT
66730+typedef struct {
66731+ long counter;
66732+} atomic64_unchecked_t;
66733+#else
66734+typedef atomic64_t atomic64_unchecked_t;
66735+#endif
66736 #endif
66737
66738 struct list_head {
66739diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
66740index 5ca0951..ab496a5 100644
66741--- a/include/linux/uaccess.h
66742+++ b/include/linux/uaccess.h
66743@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
66744 long ret; \
66745 mm_segment_t old_fs = get_fs(); \
66746 \
66747- set_fs(KERNEL_DS); \
66748 pagefault_disable(); \
66749- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
66750- pagefault_enable(); \
66751+ set_fs(KERNEL_DS); \
66752+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
66753 set_fs(old_fs); \
66754+ pagefault_enable(); \
66755 ret; \
66756 })
66757
66758diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
66759index 99c1b4d..bb94261 100644
66760--- a/include/linux/unaligned/access_ok.h
66761+++ b/include/linux/unaligned/access_ok.h
66762@@ -6,32 +6,32 @@
66763
66764 static inline u16 get_unaligned_le16(const void *p)
66765 {
66766- return le16_to_cpup((__le16 *)p);
66767+ return le16_to_cpup((const __le16 *)p);
66768 }
66769
66770 static inline u32 get_unaligned_le32(const void *p)
66771 {
66772- return le32_to_cpup((__le32 *)p);
66773+ return le32_to_cpup((const __le32 *)p);
66774 }
66775
66776 static inline u64 get_unaligned_le64(const void *p)
66777 {
66778- return le64_to_cpup((__le64 *)p);
66779+ return le64_to_cpup((const __le64 *)p);
66780 }
66781
66782 static inline u16 get_unaligned_be16(const void *p)
66783 {
66784- return be16_to_cpup((__be16 *)p);
66785+ return be16_to_cpup((const __be16 *)p);
66786 }
66787
66788 static inline u32 get_unaligned_be32(const void *p)
66789 {
66790- return be32_to_cpup((__be32 *)p);
66791+ return be32_to_cpup((const __be32 *)p);
66792 }
66793
66794 static inline u64 get_unaligned_be64(const void *p)
66795 {
66796- return be64_to_cpup((__be64 *)p);
66797+ return be64_to_cpup((const __be64 *)p);
66798 }
66799
66800 static inline void put_unaligned_le16(u16 val, void *p)
66801diff --git a/include/linux/usb.h b/include/linux/usb.h
66802index 10278d1..e21ec3c 100644
66803--- a/include/linux/usb.h
66804+++ b/include/linux/usb.h
66805@@ -551,7 +551,7 @@ struct usb_device {
66806 int maxchild;
66807
66808 u32 quirks;
66809- atomic_t urbnum;
66810+ atomic_unchecked_t urbnum;
66811
66812 unsigned long active_duration;
66813
66814diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
66815index c5d36c6..108f4f9 100644
66816--- a/include/linux/usb/renesas_usbhs.h
66817+++ b/include/linux/usb/renesas_usbhs.h
66818@@ -39,7 +39,7 @@ enum {
66819 */
66820 struct renesas_usbhs_driver_callback {
66821 int (*notify_hotplug)(struct platform_device *pdev);
66822-};
66823+} __no_const;
66824
66825 /*
66826 * callback functions for platform
66827diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
66828index 6f8fbcf..8259001 100644
66829--- a/include/linux/vermagic.h
66830+++ b/include/linux/vermagic.h
66831@@ -25,9 +25,35 @@
66832 #define MODULE_ARCH_VERMAGIC ""
66833 #endif
66834
66835+#ifdef CONFIG_PAX_REFCOUNT
66836+#define MODULE_PAX_REFCOUNT "REFCOUNT "
66837+#else
66838+#define MODULE_PAX_REFCOUNT ""
66839+#endif
66840+
66841+#ifdef CONSTIFY_PLUGIN
66842+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
66843+#else
66844+#define MODULE_CONSTIFY_PLUGIN ""
66845+#endif
66846+
66847+#ifdef STACKLEAK_PLUGIN
66848+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
66849+#else
66850+#define MODULE_STACKLEAK_PLUGIN ""
66851+#endif
66852+
66853+#ifdef CONFIG_GRKERNSEC
66854+#define MODULE_GRSEC "GRSEC "
66855+#else
66856+#define MODULE_GRSEC ""
66857+#endif
66858+
66859 #define VERMAGIC_STRING \
66860 UTS_RELEASE " " \
66861 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
66862 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
66863- MODULE_ARCH_VERMAGIC
66864+ MODULE_ARCH_VERMAGIC \
66865+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
66866+ MODULE_GRSEC
66867
66868diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
66869index 6071e91..ca6a489 100644
66870--- a/include/linux/vmalloc.h
66871+++ b/include/linux/vmalloc.h
66872@@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
66873 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
66874 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
66875 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
66876+
66877+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
66878+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
66879+#endif
66880+
66881 /* bits [20..32] reserved for arch specific ioremap internals */
66882
66883 /*
66884@@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
66885 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
66886 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
66887 unsigned long start, unsigned long end, gfp_t gfp_mask,
66888- pgprot_t prot, int node, const void *caller);
66889+ pgprot_t prot, int node, const void *caller) __size_overflow(1);
66890 extern void vfree(const void *addr);
66891
66892 extern void *vmap(struct page **pages, unsigned int count,
66893@@ -124,8 +129,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
66894 extern void free_vm_area(struct vm_struct *area);
66895
66896 /* for /dev/kmem */
66897-extern long vread(char *buf, char *addr, unsigned long count);
66898-extern long vwrite(char *buf, char *addr, unsigned long count);
66899+extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
66900+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
66901
66902 /*
66903 * Internals. Dont't use..
66904diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
66905index 92a86b2..1d9eb3c 100644
66906--- a/include/linux/vmstat.h
66907+++ b/include/linux/vmstat.h
66908@@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
66909 /*
66910 * Zone based page accounting with per cpu differentials.
66911 */
66912-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
66913+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
66914
66915 static inline void zone_page_state_add(long x, struct zone *zone,
66916 enum zone_stat_item item)
66917 {
66918- atomic_long_add(x, &zone->vm_stat[item]);
66919- atomic_long_add(x, &vm_stat[item]);
66920+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
66921+ atomic_long_add_unchecked(x, &vm_stat[item]);
66922 }
66923
66924 static inline unsigned long global_page_state(enum zone_stat_item item)
66925 {
66926- long x = atomic_long_read(&vm_stat[item]);
66927+ long x = atomic_long_read_unchecked(&vm_stat[item]);
66928 #ifdef CONFIG_SMP
66929 if (x < 0)
66930 x = 0;
66931@@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
66932 static inline unsigned long zone_page_state(struct zone *zone,
66933 enum zone_stat_item item)
66934 {
66935- long x = atomic_long_read(&zone->vm_stat[item]);
66936+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
66937 #ifdef CONFIG_SMP
66938 if (x < 0)
66939 x = 0;
66940@@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
66941 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
66942 enum zone_stat_item item)
66943 {
66944- long x = atomic_long_read(&zone->vm_stat[item]);
66945+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
66946
66947 #ifdef CONFIG_SMP
66948 int cpu;
66949@@ -218,8 +218,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
66950
66951 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
66952 {
66953- atomic_long_inc(&zone->vm_stat[item]);
66954- atomic_long_inc(&vm_stat[item]);
66955+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
66956+ atomic_long_inc_unchecked(&vm_stat[item]);
66957 }
66958
66959 static inline void __inc_zone_page_state(struct page *page,
66960@@ -230,8 +230,8 @@ static inline void __inc_zone_page_state(struct page *page,
66961
66962 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
66963 {
66964- atomic_long_dec(&zone->vm_stat[item]);
66965- atomic_long_dec(&vm_stat[item]);
66966+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
66967+ atomic_long_dec_unchecked(&vm_stat[item]);
66968 }
66969
66970 static inline void __dec_zone_page_state(struct page *page,
66971diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
66972index 95d1c91..6798cca 100644
66973--- a/include/media/v4l2-dev.h
66974+++ b/include/media/v4l2-dev.h
66975@@ -76,7 +76,7 @@ struct v4l2_file_operations {
66976 int (*mmap) (struct file *, struct vm_area_struct *);
66977 int (*open) (struct file *);
66978 int (*release) (struct file *);
66979-};
66980+} __do_const;
66981
66982 /*
66983 * Newer version of video_device, handled by videodev2.c
66984diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
66985index e48b571..7e40de4 100644
66986--- a/include/media/v4l2-ioctl.h
66987+++ b/include/media/v4l2-ioctl.h
66988@@ -282,7 +282,6 @@ struct v4l2_ioctl_ops {
66989 bool valid_prio, int cmd, void *arg);
66990 };
66991
66992-
66993 /* v4l debugging and diagnostics */
66994
66995 /* Debug bitmask flags to be used on V4L2 */
66996diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
66997index 9e5425b..8136ffc 100644
66998--- a/include/net/caif/cfctrl.h
66999+++ b/include/net/caif/cfctrl.h
67000@@ -52,7 +52,7 @@ struct cfctrl_rsp {
67001 void (*radioset_rsp)(void);
67002 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
67003 struct cflayer *client_layer);
67004-};
67005+} __no_const;
67006
67007 /* Link Setup Parameters for CAIF-Links. */
67008 struct cfctrl_link_param {
67009@@ -101,8 +101,8 @@ struct cfctrl_request_info {
67010 struct cfctrl {
67011 struct cfsrvl serv;
67012 struct cfctrl_rsp res;
67013- atomic_t req_seq_no;
67014- atomic_t rsp_seq_no;
67015+ atomic_unchecked_t req_seq_no;
67016+ atomic_unchecked_t rsp_seq_no;
67017 struct list_head list;
67018 /* Protects from simultaneous access to first_req list */
67019 spinlock_t info_list_lock;
67020diff --git a/include/net/flow.h b/include/net/flow.h
67021index 628e11b..4c475df 100644
67022--- a/include/net/flow.h
67023+++ b/include/net/flow.h
67024@@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
67025
67026 extern void flow_cache_flush(void);
67027 extern void flow_cache_flush_deferred(void);
67028-extern atomic_t flow_cache_genid;
67029+extern atomic_unchecked_t flow_cache_genid;
67030
67031 #endif
67032diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
67033index e5062c9..48a9a4b 100644
67034--- a/include/net/gro_cells.h
67035+++ b/include/net/gro_cells.h
67036@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
67037 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
67038
67039 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
67040- atomic_long_inc(&dev->rx_dropped);
67041+ atomic_long_inc_unchecked(&dev->rx_dropped);
67042 kfree_skb(skb);
67043 return;
67044 }
67045@@ -73,8 +73,8 @@ static inline int gro_cells_init(struct gro_cells *gcells, struct net_device *de
67046 int i;
67047
67048 gcells->gro_cells_mask = roundup_pow_of_two(netif_get_num_default_rss_queues()) - 1;
67049- gcells->cells = kcalloc(sizeof(struct gro_cell),
67050- gcells->gro_cells_mask + 1,
67051+ gcells->cells = kcalloc(gcells->gro_cells_mask + 1,
67052+ sizeof(struct gro_cell),
67053 GFP_KERNEL);
67054 if (!gcells->cells)
67055 return -ENOMEM;
67056diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
67057index 1832927..ce39aea 100644
67058--- a/include/net/inet_connection_sock.h
67059+++ b/include/net/inet_connection_sock.h
67060@@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
67061 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
67062 int (*bind_conflict)(const struct sock *sk,
67063 const struct inet_bind_bucket *tb, bool relax);
67064-};
67065+} __do_const;
67066
67067 /** inet_connection_sock - INET connection oriented sock
67068 *
67069diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
67070index 53f464d..ba76aaa 100644
67071--- a/include/net/inetpeer.h
67072+++ b/include/net/inetpeer.h
67073@@ -47,8 +47,8 @@ struct inet_peer {
67074 */
67075 union {
67076 struct {
67077- atomic_t rid; /* Frag reception counter */
67078- atomic_t ip_id_count; /* IP ID for the next packet */
67079+ atomic_unchecked_t rid; /* Frag reception counter */
67080+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
67081 };
67082 struct rcu_head rcu;
67083 struct inet_peer *gc_next;
67084@@ -182,11 +182,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
67085 more++;
67086 inet_peer_refcheck(p);
67087 do {
67088- old = atomic_read(&p->ip_id_count);
67089+ old = atomic_read_unchecked(&p->ip_id_count);
67090 new = old + more;
67091 if (!new)
67092 new = 1;
67093- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
67094+ } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
67095 return new;
67096 }
67097
67098diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
67099index 9497be1..5a4fafe 100644
67100--- a/include/net/ip_fib.h
67101+++ b/include/net/ip_fib.h
67102@@ -169,7 +169,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
67103
67104 #define FIB_RES_SADDR(net, res) \
67105 ((FIB_RES_NH(res).nh_saddr_genid == \
67106- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
67107+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
67108 FIB_RES_NH(res).nh_saddr : \
67109 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
67110 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
67111diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
67112index ee75ccd..2cc2b95 100644
67113--- a/include/net/ip_vs.h
67114+++ b/include/net/ip_vs.h
67115@@ -510,7 +510,7 @@ struct ip_vs_conn {
67116 struct ip_vs_conn *control; /* Master control connection */
67117 atomic_t n_control; /* Number of controlled ones */
67118 struct ip_vs_dest *dest; /* real server */
67119- atomic_t in_pkts; /* incoming packet counter */
67120+ atomic_unchecked_t in_pkts; /* incoming packet counter */
67121
67122 /* packet transmitter for different forwarding methods. If it
67123 mangles the packet, it must return NF_DROP or better NF_STOLEN,
67124@@ -648,7 +648,7 @@ struct ip_vs_dest {
67125 __be16 port; /* port number of the server */
67126 union nf_inet_addr addr; /* IP address of the server */
67127 volatile unsigned int flags; /* dest status flags */
67128- atomic_t conn_flags; /* flags to copy to conn */
67129+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
67130 atomic_t weight; /* server weight */
67131
67132 atomic_t refcnt; /* reference counter */
67133diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
67134index 80ffde3..968b0f4 100644
67135--- a/include/net/irda/ircomm_tty.h
67136+++ b/include/net/irda/ircomm_tty.h
67137@@ -35,6 +35,7 @@
67138 #include <linux/termios.h>
67139 #include <linux/timer.h>
67140 #include <linux/tty.h> /* struct tty_struct */
67141+#include <asm/local.h>
67142
67143 #include <net/irda/irias_object.h>
67144 #include <net/irda/ircomm_core.h>
67145diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
67146index cc7c197..9f2da2a 100644
67147--- a/include/net/iucv/af_iucv.h
67148+++ b/include/net/iucv/af_iucv.h
67149@@ -141,7 +141,7 @@ struct iucv_sock {
67150 struct iucv_sock_list {
67151 struct hlist_head head;
67152 rwlock_t lock;
67153- atomic_t autobind_name;
67154+ atomic_unchecked_t autobind_name;
67155 };
67156
67157 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
67158diff --git a/include/net/neighbour.h b/include/net/neighbour.h
67159index 0dab173..1b76af0 100644
67160--- a/include/net/neighbour.h
67161+++ b/include/net/neighbour.h
67162@@ -123,7 +123,7 @@ struct neigh_ops {
67163 void (*error_report)(struct neighbour *, struct sk_buff *);
67164 int (*output)(struct neighbour *, struct sk_buff *);
67165 int (*connected_output)(struct neighbour *, struct sk_buff *);
67166-};
67167+} __do_const;
67168
67169 struct pneigh_entry {
67170 struct pneigh_entry *next;
67171diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
67172index 95e6466..251016d 100644
67173--- a/include/net/net_namespace.h
67174+++ b/include/net/net_namespace.h
67175@@ -110,7 +110,7 @@ struct net {
67176 #endif
67177 struct netns_ipvs *ipvs;
67178 struct sock *diag_nlsk;
67179- atomic_t rt_genid;
67180+ atomic_unchecked_t rt_genid;
67181 };
67182
67183 /*
67184@@ -320,12 +320,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
67185
67186 static inline int rt_genid(struct net *net)
67187 {
67188- return atomic_read(&net->rt_genid);
67189+ return atomic_read_unchecked(&net->rt_genid);
67190 }
67191
67192 static inline void rt_genid_bump(struct net *net)
67193 {
67194- atomic_inc(&net->rt_genid);
67195+ atomic_inc_unchecked(&net->rt_genid);
67196 }
67197
67198 #endif /* __NET_NET_NAMESPACE_H */
67199diff --git a/include/net/netdma.h b/include/net/netdma.h
67200index 8ba8ce2..99b7fff 100644
67201--- a/include/net/netdma.h
67202+++ b/include/net/netdma.h
67203@@ -24,7 +24,7 @@
67204 #include <linux/dmaengine.h>
67205 #include <linux/skbuff.h>
67206
67207-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
67208+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
67209 struct sk_buff *skb, int offset, struct iovec *to,
67210 size_t len, struct dma_pinned_list *pinned_list);
67211
67212diff --git a/include/net/netfilter/nf_queue.h b/include/net/netfilter/nf_queue.h
67213index 252fd10..aa1421f 100644
67214--- a/include/net/netfilter/nf_queue.h
67215+++ b/include/net/netfilter/nf_queue.h
67216@@ -22,7 +22,7 @@ struct nf_queue_handler {
67217 int (*outfn)(struct nf_queue_entry *entry,
67218 unsigned int queuenum);
67219 char *name;
67220-};
67221+} __do_const;
67222
67223 extern int nf_register_queue_handler(u_int8_t pf,
67224 const struct nf_queue_handler *qh);
67225diff --git a/include/net/netlink.h b/include/net/netlink.h
67226index 9690b0f..87aded7 100644
67227--- a/include/net/netlink.h
67228+++ b/include/net/netlink.h
67229@@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
67230 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
67231 {
67232 if (mark)
67233- skb_trim(skb, (unsigned char *) mark - skb->data);
67234+ skb_trim(skb, (const unsigned char *) mark - skb->data);
67235 }
67236
67237 /**
67238diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
67239index 2ae2b83..dbdc85e 100644
67240--- a/include/net/netns/ipv4.h
67241+++ b/include/net/netns/ipv4.h
67242@@ -64,7 +64,7 @@ struct netns_ipv4 {
67243 kgid_t sysctl_ping_group_range[2];
67244 long sysctl_tcp_mem[3];
67245
67246- atomic_t dev_addr_genid;
67247+ atomic_unchecked_t dev_addr_genid;
67248
67249 #ifdef CONFIG_IP_MROUTE
67250 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
67251diff --git a/include/net/protocol.h b/include/net/protocol.h
67252index 929528c..c84d4f6 100644
67253--- a/include/net/protocol.h
67254+++ b/include/net/protocol.h
67255@@ -48,7 +48,7 @@ struct net_protocol {
67256 int (*gro_complete)(struct sk_buff *skb);
67257 unsigned int no_policy:1,
67258 netns_ok:1;
67259-};
67260+} __do_const;
67261
67262 #if IS_ENABLED(CONFIG_IPV6)
67263 struct inet6_protocol {
67264@@ -69,7 +69,7 @@ struct inet6_protocol {
67265 int (*gro_complete)(struct sk_buff *skb);
67266
67267 unsigned int flags; /* INET6_PROTO_xxx */
67268-};
67269+} __do_const;
67270
67271 #define INET6_PROTO_NOPOLICY 0x1
67272 #define INET6_PROTO_FINAL 0x2
67273diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
67274index 9c6414f..fbd0524 100644
67275--- a/include/net/sctp/sctp.h
67276+++ b/include/net/sctp/sctp.h
67277@@ -318,9 +318,9 @@ do { \
67278
67279 #else /* SCTP_DEBUG */
67280
67281-#define SCTP_DEBUG_PRINTK(whatever...)
67282-#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
67283-#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
67284+#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
67285+#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
67286+#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
67287 #define SCTP_ENABLE_DEBUG
67288 #define SCTP_DISABLE_DEBUG
67289 #define SCTP_ASSERT(expr, str, func)
67290diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
67291index 64158aa..b65533c 100644
67292--- a/include/net/sctp/structs.h
67293+++ b/include/net/sctp/structs.h
67294@@ -496,7 +496,7 @@ struct sctp_af {
67295 int sockaddr_len;
67296 sa_family_t sa_family;
67297 struct list_head list;
67298-};
67299+} __do_const;
67300
67301 struct sctp_af *sctp_get_af_specific(sa_family_t);
67302 int sctp_register_af(struct sctp_af *);
67303@@ -516,7 +516,7 @@ struct sctp_pf {
67304 struct sctp_association *asoc);
67305 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
67306 struct sctp_af *af;
67307-};
67308+} __do_const;
67309
67310
67311 /* Structure to track chunk fragments that have been acked, but peer
67312diff --git a/include/net/sock.h b/include/net/sock.h
67313index c945fba..e162e56 100644
67314--- a/include/net/sock.h
67315+++ b/include/net/sock.h
67316@@ -304,7 +304,7 @@ struct sock {
67317 #ifdef CONFIG_RPS
67318 __u32 sk_rxhash;
67319 #endif
67320- atomic_t sk_drops;
67321+ atomic_unchecked_t sk_drops;
67322 int sk_rcvbuf;
67323
67324 struct sk_filter __rcu *sk_filter;
67325@@ -1763,7 +1763,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
67326 }
67327
67328 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
67329- char __user *from, char *to,
67330+ char __user *from, unsigned char *to,
67331 int copy, int offset)
67332 {
67333 if (skb->ip_summed == CHECKSUM_NONE) {
67334@@ -2022,7 +2022,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
67335 }
67336 }
67337
67338-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
67339+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
67340
67341 /**
67342 * sk_page_frag - return an appropriate page_frag
67343diff --git a/include/net/tcp.h b/include/net/tcp.h
67344index 4af45e3..af97861 100644
67345--- a/include/net/tcp.h
67346+++ b/include/net/tcp.h
67347@@ -531,7 +531,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
67348 extern void tcp_xmit_retransmit_queue(struct sock *);
67349 extern void tcp_simple_retransmit(struct sock *);
67350 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
67351-extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
67352+extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
67353
67354 extern void tcp_send_probe0(struct sock *);
67355 extern void tcp_send_partial(struct sock *);
67356@@ -702,8 +702,8 @@ struct tcp_skb_cb {
67357 struct inet6_skb_parm h6;
67358 #endif
67359 } header; /* For incoming frames */
67360- __u32 seq; /* Starting sequence number */
67361- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
67362+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
67363+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
67364 __u32 when; /* used to compute rtt's */
67365 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
67366
67367@@ -717,7 +717,7 @@ struct tcp_skb_cb {
67368
67369 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
67370 /* 1 byte hole */
67371- __u32 ack_seq; /* Sequence number ACK'd */
67372+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
67373 };
67374
67375 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
67376diff --git a/include/net/xfrm.h b/include/net/xfrm.h
67377index 63445ed..74ef61d 100644
67378--- a/include/net/xfrm.h
67379+++ b/include/net/xfrm.h
67380@@ -423,7 +423,7 @@ struct xfrm_mode {
67381 struct module *owner;
67382 unsigned int encap;
67383 int flags;
67384-};
67385+} __do_const;
67386
67387 /* Flags for xfrm_mode. */
67388 enum {
67389@@ -514,7 +514,7 @@ struct xfrm_policy {
67390 struct timer_list timer;
67391
67392 struct flow_cache_object flo;
67393- atomic_t genid;
67394+ atomic_unchecked_t genid;
67395 u32 priority;
67396 u32 index;
67397 struct xfrm_mark mark;
67398diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
67399index 1a046b1..ee0bef0 100644
67400--- a/include/rdma/iw_cm.h
67401+++ b/include/rdma/iw_cm.h
67402@@ -122,7 +122,7 @@ struct iw_cm_verbs {
67403 int backlog);
67404
67405 int (*destroy_listen)(struct iw_cm_id *cm_id);
67406-};
67407+} __no_const;
67408
67409 /**
67410 * iw_create_cm_id - Create an IW CM identifier.
67411diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
67412index 399162b..b337f1a 100644
67413--- a/include/scsi/libfc.h
67414+++ b/include/scsi/libfc.h
67415@@ -762,6 +762,7 @@ struct libfc_function_template {
67416 */
67417 void (*disc_stop_final) (struct fc_lport *);
67418 };
67419+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
67420
67421 /**
67422 * struct fc_disc - Discovery context
67423@@ -866,7 +867,7 @@ struct fc_lport {
67424 struct fc_vport *vport;
67425
67426 /* Operational Information */
67427- struct libfc_function_template tt;
67428+ libfc_function_template_no_const tt;
67429 u8 link_up;
67430 u8 qfull;
67431 enum fc_lport_state state;
67432diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
67433index 55367b0..d97bd2a 100644
67434--- a/include/scsi/scsi_device.h
67435+++ b/include/scsi/scsi_device.h
67436@@ -169,9 +169,9 @@ struct scsi_device {
67437 unsigned int max_device_blocked; /* what device_blocked counts down from */
67438 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
67439
67440- atomic_t iorequest_cnt;
67441- atomic_t iodone_cnt;
67442- atomic_t ioerr_cnt;
67443+ atomic_unchecked_t iorequest_cnt;
67444+ atomic_unchecked_t iodone_cnt;
67445+ atomic_unchecked_t ioerr_cnt;
67446
67447 struct device sdev_gendev,
67448 sdev_dev;
67449diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
67450index b797e8f..8e2c3aa 100644
67451--- a/include/scsi/scsi_transport_fc.h
67452+++ b/include/scsi/scsi_transport_fc.h
67453@@ -751,7 +751,8 @@ struct fc_function_template {
67454 unsigned long show_host_system_hostname:1;
67455
67456 unsigned long disable_target_scan:1;
67457-};
67458+} __do_const;
67459+typedef struct fc_function_template __no_const fc_function_template_no_const;
67460
67461
67462 /**
67463diff --git a/include/sound/soc.h b/include/sound/soc.h
67464index 91244a0..89ca1a7 100644
67465--- a/include/sound/soc.h
67466+++ b/include/sound/soc.h
67467@@ -769,7 +769,7 @@ struct snd_soc_codec_driver {
67468 /* probe ordering - for components with runtime dependencies */
67469 int probe_order;
67470 int remove_order;
67471-};
67472+} __do_const;
67473
67474 /* SoC platform interface */
67475 struct snd_soc_platform_driver {
67476@@ -815,7 +815,7 @@ struct snd_soc_platform_driver {
67477 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
67478 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
67479 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
67480-};
67481+} __do_const;
67482
67483 struct snd_soc_platform {
67484 const char *name;
67485diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
67486index fca8bbe..c0242ea 100644
67487--- a/include/target/target_core_base.h
67488+++ b/include/target/target_core_base.h
67489@@ -760,7 +760,7 @@ struct se_device {
67490 spinlock_t stats_lock;
67491 /* Active commands on this virtual SE device */
67492 atomic_t simple_cmds;
67493- atomic_t dev_ordered_id;
67494+ atomic_unchecked_t dev_ordered_id;
67495 atomic_t dev_ordered_sync;
67496 atomic_t dev_qf_count;
67497 struct se_obj dev_obj;
67498diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
67499new file mode 100644
67500index 0000000..fb634b7
67501--- /dev/null
67502+++ b/include/trace/events/fs.h
67503@@ -0,0 +1,53 @@
67504+#undef TRACE_SYSTEM
67505+#define TRACE_SYSTEM fs
67506+
67507+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
67508+#define _TRACE_FS_H
67509+
67510+#include <linux/fs.h>
67511+#include <linux/tracepoint.h>
67512+
67513+TRACE_EVENT(do_sys_open,
67514+
67515+ TP_PROTO(const char *filename, int flags, int mode),
67516+
67517+ TP_ARGS(filename, flags, mode),
67518+
67519+ TP_STRUCT__entry(
67520+ __string( filename, filename )
67521+ __field( int, flags )
67522+ __field( int, mode )
67523+ ),
67524+
67525+ TP_fast_assign(
67526+ __assign_str(filename, filename);
67527+ __entry->flags = flags;
67528+ __entry->mode = mode;
67529+ ),
67530+
67531+ TP_printk("\"%s\" %x %o",
67532+ __get_str(filename), __entry->flags, __entry->mode)
67533+);
67534+
67535+TRACE_EVENT(open_exec,
67536+
67537+ TP_PROTO(const char *filename),
67538+
67539+ TP_ARGS(filename),
67540+
67541+ TP_STRUCT__entry(
67542+ __string( filename, filename )
67543+ ),
67544+
67545+ TP_fast_assign(
67546+ __assign_str(filename, filename);
67547+ ),
67548+
67549+ TP_printk("\"%s\"",
67550+ __get_str(filename))
67551+);
67552+
67553+#endif /* _TRACE_FS_H */
67554+
67555+/* This part must be outside protection */
67556+#include <trace/define_trace.h>
67557diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
67558index 1c09820..7f5ec79 100644
67559--- a/include/trace/events/irq.h
67560+++ b/include/trace/events/irq.h
67561@@ -36,7 +36,7 @@ struct softirq_action;
67562 */
67563 TRACE_EVENT(irq_handler_entry,
67564
67565- TP_PROTO(int irq, struct irqaction *action),
67566+ TP_PROTO(int irq, const struct irqaction *action),
67567
67568 TP_ARGS(irq, action),
67569
67570@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
67571 */
67572 TRACE_EVENT(irq_handler_exit,
67573
67574- TP_PROTO(int irq, struct irqaction *action, int ret),
67575+ TP_PROTO(int irq, const struct irqaction *action, int ret),
67576
67577 TP_ARGS(irq, action, ret),
67578
67579diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
67580index 7caf44c..23c6f27 100644
67581--- a/include/uapi/linux/a.out.h
67582+++ b/include/uapi/linux/a.out.h
67583@@ -39,6 +39,14 @@ enum machine_type {
67584 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
67585 };
67586
67587+/* Constants for the N_FLAGS field */
67588+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
67589+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
67590+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
67591+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
67592+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
67593+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
67594+
67595 #if !defined (N_MAGIC)
67596 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
67597 #endif
67598diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
67599index d876736..b36014e 100644
67600--- a/include/uapi/linux/byteorder/little_endian.h
67601+++ b/include/uapi/linux/byteorder/little_endian.h
67602@@ -42,51 +42,51 @@
67603
67604 static inline __le64 __cpu_to_le64p(const __u64 *p)
67605 {
67606- return (__force __le64)*p;
67607+ return (__force const __le64)*p;
67608 }
67609 static inline __u64 __le64_to_cpup(const __le64 *p)
67610 {
67611- return (__force __u64)*p;
67612+ return (__force const __u64)*p;
67613 }
67614 static inline __le32 __cpu_to_le32p(const __u32 *p)
67615 {
67616- return (__force __le32)*p;
67617+ return (__force const __le32)*p;
67618 }
67619 static inline __u32 __le32_to_cpup(const __le32 *p)
67620 {
67621- return (__force __u32)*p;
67622+ return (__force const __u32)*p;
67623 }
67624 static inline __le16 __cpu_to_le16p(const __u16 *p)
67625 {
67626- return (__force __le16)*p;
67627+ return (__force const __le16)*p;
67628 }
67629 static inline __u16 __le16_to_cpup(const __le16 *p)
67630 {
67631- return (__force __u16)*p;
67632+ return (__force const __u16)*p;
67633 }
67634 static inline __be64 __cpu_to_be64p(const __u64 *p)
67635 {
67636- return (__force __be64)__swab64p(p);
67637+ return (__force const __be64)__swab64p(p);
67638 }
67639 static inline __u64 __be64_to_cpup(const __be64 *p)
67640 {
67641- return __swab64p((__u64 *)p);
67642+ return __swab64p((const __u64 *)p);
67643 }
67644 static inline __be32 __cpu_to_be32p(const __u32 *p)
67645 {
67646- return (__force __be32)__swab32p(p);
67647+ return (__force const __be32)__swab32p(p);
67648 }
67649 static inline __u32 __be32_to_cpup(const __be32 *p)
67650 {
67651- return __swab32p((__u32 *)p);
67652+ return __swab32p((const __u32 *)p);
67653 }
67654 static inline __be16 __cpu_to_be16p(const __u16 *p)
67655 {
67656- return (__force __be16)__swab16p(p);
67657+ return (__force const __be16)__swab16p(p);
67658 }
67659 static inline __u16 __be16_to_cpup(const __be16 *p)
67660 {
67661- return __swab16p((__u16 *)p);
67662+ return __swab16p((const __u16 *)p);
67663 }
67664 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
67665 #define __le64_to_cpus(x) do { (void)(x); } while (0)
67666diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
67667index 126a817..d522bd1 100644
67668--- a/include/uapi/linux/elf.h
67669+++ b/include/uapi/linux/elf.h
67670@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
67671 #define PT_GNU_EH_FRAME 0x6474e550
67672
67673 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
67674+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
67675+
67676+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
67677+
67678+/* Constants for the e_flags field */
67679+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
67680+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
67681+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
67682+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
67683+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
67684+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
67685
67686 /*
67687 * Extended Numbering
67688@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
67689 #define DT_DEBUG 21
67690 #define DT_TEXTREL 22
67691 #define DT_JMPREL 23
67692+#define DT_FLAGS 30
67693+ #define DF_TEXTREL 0x00000004
67694 #define DT_ENCODING 32
67695 #define OLD_DT_LOOS 0x60000000
67696 #define DT_LOOS 0x6000000d
67697@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
67698 #define PF_W 0x2
67699 #define PF_X 0x1
67700
67701+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
67702+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
67703+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
67704+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
67705+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
67706+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
67707+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
67708+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
67709+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
67710+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
67711+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
67712+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
67713+
67714 typedef struct elf32_phdr{
67715 Elf32_Word p_type;
67716 Elf32_Off p_offset;
67717@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
67718 #define EI_OSABI 7
67719 #define EI_PAD 8
67720
67721+#define EI_PAX 14
67722+
67723 #define ELFMAG0 0x7f /* EI_MAG */
67724 #define ELFMAG1 'E'
67725 #define ELFMAG2 'L'
67726diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
67727index aa169c4..6a2771d 100644
67728--- a/include/uapi/linux/personality.h
67729+++ b/include/uapi/linux/personality.h
67730@@ -30,6 +30,7 @@ enum {
67731 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
67732 ADDR_NO_RANDOMIZE | \
67733 ADDR_COMPAT_LAYOUT | \
67734+ ADDR_LIMIT_3GB | \
67735 MMAP_PAGE_ZERO)
67736
67737 /*
67738diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
67739index 7530e74..e714828 100644
67740--- a/include/uapi/linux/screen_info.h
67741+++ b/include/uapi/linux/screen_info.h
67742@@ -43,7 +43,8 @@ struct screen_info {
67743 __u16 pages; /* 0x32 */
67744 __u16 vesa_attributes; /* 0x34 */
67745 __u32 capabilities; /* 0x36 */
67746- __u8 _reserved[6]; /* 0x3a */
67747+ __u16 vesapm_size; /* 0x3a */
67748+ __u8 _reserved[4]; /* 0x3c */
67749 } __attribute__((packed));
67750
67751 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
67752diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
67753index 6d67213..8dab561 100644
67754--- a/include/uapi/linux/sysctl.h
67755+++ b/include/uapi/linux/sysctl.h
67756@@ -155,7 +155,11 @@ enum
67757 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
67758 };
67759
67760-
67761+#ifdef CONFIG_PAX_SOFTMODE
67762+enum {
67763+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
67764+};
67765+#endif
67766
67767 /* CTL_VM names: */
67768 enum
67769diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
67770index 26607bd..588b65f 100644
67771--- a/include/uapi/linux/xattr.h
67772+++ b/include/uapi/linux/xattr.h
67773@@ -60,5 +60,9 @@
67774 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
67775 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
67776
67777+/* User namespace */
67778+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
67779+#define XATTR_PAX_FLAGS_SUFFIX "flags"
67780+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
67781
67782 #endif /* _UAPI_LINUX_XATTR_H */
67783diff --git a/include/video/udlfb.h b/include/video/udlfb.h
67784index f9466fa..f4e2b81 100644
67785--- a/include/video/udlfb.h
67786+++ b/include/video/udlfb.h
67787@@ -53,10 +53,10 @@ struct dlfb_data {
67788 u32 pseudo_palette[256];
67789 int blank_mode; /*one of FB_BLANK_ */
67790 /* blit-only rendering path metrics, exposed through sysfs */
67791- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
67792- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
67793- atomic_t bytes_sent; /* to usb, after compression including overhead */
67794- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
67795+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
67796+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
67797+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
67798+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
67799 };
67800
67801 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
67802diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
67803index 0993a22..32ba2fe 100644
67804--- a/include/video/uvesafb.h
67805+++ b/include/video/uvesafb.h
67806@@ -177,6 +177,7 @@ struct uvesafb_par {
67807 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
67808 u8 pmi_setpal; /* PMI for palette changes */
67809 u16 *pmi_base; /* protected mode interface location */
67810+ u8 *pmi_code; /* protected mode code location */
67811 void *pmi_start;
67812 void *pmi_pal;
67813 u8 *vbe_state_orig; /*
67814diff --git a/init/Kconfig b/init/Kconfig
67815index 6fdd6e3..5b01610 100644
67816--- a/init/Kconfig
67817+++ b/init/Kconfig
67818@@ -925,6 +925,7 @@ endif # CGROUPS
67819
67820 config CHECKPOINT_RESTORE
67821 bool "Checkpoint/restore support" if EXPERT
67822+ depends on !GRKERNSEC
67823 default n
67824 help
67825 Enables additional kernel features in a sake of checkpoint/restore.
67826@@ -1016,6 +1017,8 @@ config UIDGID_CONVERTED
67827 depends on OCFS2_FS = n
67828 depends on XFS_FS = n
67829
67830+ depends on GRKERNSEC = n
67831+
67832 config UIDGID_STRICT_TYPE_CHECKS
67833 bool "Require conversions between uid/gids and their internal representation"
67834 depends on UIDGID_CONVERTED
67835@@ -1405,7 +1408,7 @@ config SLUB_DEBUG
67836
67837 config COMPAT_BRK
67838 bool "Disable heap randomization"
67839- default y
67840+ default n
67841 help
67842 Randomizing heap placement makes heap exploits harder, but it
67843 also breaks ancient binaries (including anything libc5 based).
67844@@ -1648,7 +1651,7 @@ config INIT_ALL_POSSIBLE
67845 config STOP_MACHINE
67846 bool
67847 default y
67848- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
67849+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
67850 help
67851 Need stop_machine() primitive.
67852
67853diff --git a/init/Makefile b/init/Makefile
67854index 7bc47ee..6da2dc7 100644
67855--- a/init/Makefile
67856+++ b/init/Makefile
67857@@ -2,6 +2,9 @@
67858 # Makefile for the linux kernel.
67859 #
67860
67861+ccflags-y := $(GCC_PLUGINS_CFLAGS)
67862+asflags-y := $(GCC_PLUGINS_AFLAGS)
67863+
67864 obj-y := main.o version.o mounts.o
67865 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
67866 obj-y += noinitramfs.o
67867diff --git a/init/do_mounts.c b/init/do_mounts.c
67868index f8a6642..4e5ee1b 100644
67869--- a/init/do_mounts.c
67870+++ b/init/do_mounts.c
67871@@ -336,11 +336,11 @@ static void __init get_fs_names(char *page)
67872 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
67873 {
67874 struct super_block *s;
67875- int err = sys_mount(name, "/root", fs, flags, data);
67876+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
67877 if (err)
67878 return err;
67879
67880- sys_chdir("/root");
67881+ sys_chdir((const char __force_user *)"/root");
67882 s = current->fs->pwd.dentry->d_sb;
67883 ROOT_DEV = s->s_dev;
67884 printk(KERN_INFO
67885@@ -461,18 +461,18 @@ void __init change_floppy(char *fmt, ...)
67886 va_start(args, fmt);
67887 vsprintf(buf, fmt, args);
67888 va_end(args);
67889- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
67890+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
67891 if (fd >= 0) {
67892 sys_ioctl(fd, FDEJECT, 0);
67893 sys_close(fd);
67894 }
67895 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
67896- fd = sys_open("/dev/console", O_RDWR, 0);
67897+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
67898 if (fd >= 0) {
67899 sys_ioctl(fd, TCGETS, (long)&termios);
67900 termios.c_lflag &= ~ICANON;
67901 sys_ioctl(fd, TCSETSF, (long)&termios);
67902- sys_read(fd, &c, 1);
67903+ sys_read(fd, (char __user *)&c, 1);
67904 termios.c_lflag |= ICANON;
67905 sys_ioctl(fd, TCSETSF, (long)&termios);
67906 sys_close(fd);
67907@@ -566,6 +566,6 @@ void __init prepare_namespace(void)
67908 mount_root();
67909 out:
67910 devtmpfs_mount("dev");
67911- sys_mount(".", "/", NULL, MS_MOVE, NULL);
67912- sys_chroot(".");
67913+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
67914+ sys_chroot((const char __force_user *)".");
67915 }
67916diff --git a/init/do_mounts.h b/init/do_mounts.h
67917index f5b978a..69dbfe8 100644
67918--- a/init/do_mounts.h
67919+++ b/init/do_mounts.h
67920@@ -15,15 +15,15 @@ extern int root_mountflags;
67921
67922 static inline int create_dev(char *name, dev_t dev)
67923 {
67924- sys_unlink(name);
67925- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
67926+ sys_unlink((char __force_user *)name);
67927+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
67928 }
67929
67930 #if BITS_PER_LONG == 32
67931 static inline u32 bstat(char *name)
67932 {
67933 struct stat64 stat;
67934- if (sys_stat64(name, &stat) != 0)
67935+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
67936 return 0;
67937 if (!S_ISBLK(stat.st_mode))
67938 return 0;
67939@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
67940 static inline u32 bstat(char *name)
67941 {
67942 struct stat stat;
67943- if (sys_newstat(name, &stat) != 0)
67944+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
67945 return 0;
67946 if (!S_ISBLK(stat.st_mode))
67947 return 0;
67948diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
67949index f9acf71..1e19144 100644
67950--- a/init/do_mounts_initrd.c
67951+++ b/init/do_mounts_initrd.c
67952@@ -58,8 +58,8 @@ static void __init handle_initrd(void)
67953 create_dev("/dev/root.old", Root_RAM0);
67954 /* mount initrd on rootfs' /root */
67955 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
67956- sys_mkdir("/old", 0700);
67957- sys_chdir("/old");
67958+ sys_mkdir((const char __force_user *)"/old", 0700);
67959+ sys_chdir((const char __force_user *)"/old");
67960
67961 /*
67962 * In case that a resume from disk is carried out by linuxrc or one of
67963@@ -73,31 +73,31 @@ static void __init handle_initrd(void)
67964 current->flags &= ~PF_FREEZER_SKIP;
67965
67966 /* move initrd to rootfs' /old */
67967- sys_mount("..", ".", NULL, MS_MOVE, NULL);
67968+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
67969 /* switch root and cwd back to / of rootfs */
67970- sys_chroot("..");
67971+ sys_chroot((const char __force_user *)"..");
67972
67973 if (new_decode_dev(real_root_dev) == Root_RAM0) {
67974- sys_chdir("/old");
67975+ sys_chdir((const char __force_user *)"/old");
67976 return;
67977 }
67978
67979- sys_chdir("/");
67980+ sys_chdir((const char __force_user *)"/");
67981 ROOT_DEV = new_decode_dev(real_root_dev);
67982 mount_root();
67983
67984 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
67985- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
67986+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
67987 if (!error)
67988 printk("okay\n");
67989 else {
67990- int fd = sys_open("/dev/root.old", O_RDWR, 0);
67991+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
67992 if (error == -ENOENT)
67993 printk("/initrd does not exist. Ignored.\n");
67994 else
67995 printk("failed\n");
67996 printk(KERN_NOTICE "Unmounting old root\n");
67997- sys_umount("/old", MNT_DETACH);
67998+ sys_umount((char __force_user *)"/old", MNT_DETACH);
67999 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
68000 if (fd < 0) {
68001 error = fd;
68002@@ -120,11 +120,11 @@ int __init initrd_load(void)
68003 * mounted in the normal path.
68004 */
68005 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
68006- sys_unlink("/initrd.image");
68007+ sys_unlink((const char __force_user *)"/initrd.image");
68008 handle_initrd();
68009 return 1;
68010 }
68011 }
68012- sys_unlink("/initrd.image");
68013+ sys_unlink((const char __force_user *)"/initrd.image");
68014 return 0;
68015 }
68016diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
68017index 8cb6db5..d729f50 100644
68018--- a/init/do_mounts_md.c
68019+++ b/init/do_mounts_md.c
68020@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
68021 partitioned ? "_d" : "", minor,
68022 md_setup_args[ent].device_names);
68023
68024- fd = sys_open(name, 0, 0);
68025+ fd = sys_open((char __force_user *)name, 0, 0);
68026 if (fd < 0) {
68027 printk(KERN_ERR "md: open failed - cannot start "
68028 "array %s\n", name);
68029@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
68030 * array without it
68031 */
68032 sys_close(fd);
68033- fd = sys_open(name, 0, 0);
68034+ fd = sys_open((char __force_user *)name, 0, 0);
68035 sys_ioctl(fd, BLKRRPART, 0);
68036 }
68037 sys_close(fd);
68038@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
68039
68040 wait_for_device_probe();
68041
68042- fd = sys_open("/dev/md0", 0, 0);
68043+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
68044 if (fd >= 0) {
68045 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
68046 sys_close(fd);
68047diff --git a/init/init_task.c b/init/init_task.c
68048index 8b2f399..f0797c9 100644
68049--- a/init/init_task.c
68050+++ b/init/init_task.c
68051@@ -20,5 +20,9 @@ EXPORT_SYMBOL(init_task);
68052 * Initial thread structure. Alignment of this is handled by a special
68053 * linker map entry.
68054 */
68055+#ifdef CONFIG_X86
68056+union thread_union init_thread_union __init_task_data;
68057+#else
68058 union thread_union init_thread_union __init_task_data =
68059 { INIT_THREAD_INFO(init_task) };
68060+#endif
68061diff --git a/init/initramfs.c b/init/initramfs.c
68062index 84c6bf1..8899338 100644
68063--- a/init/initramfs.c
68064+++ b/init/initramfs.c
68065@@ -84,7 +84,7 @@ static void __init free_hash(void)
68066 }
68067 }
68068
68069-static long __init do_utime(char *filename, time_t mtime)
68070+static long __init do_utime(char __force_user *filename, time_t mtime)
68071 {
68072 struct timespec t[2];
68073
68074@@ -119,7 +119,7 @@ static void __init dir_utime(void)
68075 struct dir_entry *de, *tmp;
68076 list_for_each_entry_safe(de, tmp, &dir_list, list) {
68077 list_del(&de->list);
68078- do_utime(de->name, de->mtime);
68079+ do_utime((char __force_user *)de->name, de->mtime);
68080 kfree(de->name);
68081 kfree(de);
68082 }
68083@@ -281,7 +281,7 @@ static int __init maybe_link(void)
68084 if (nlink >= 2) {
68085 char *old = find_link(major, minor, ino, mode, collected);
68086 if (old)
68087- return (sys_link(old, collected) < 0) ? -1 : 1;
68088+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
68089 }
68090 return 0;
68091 }
68092@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
68093 {
68094 struct stat st;
68095
68096- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
68097+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
68098 if (S_ISDIR(st.st_mode))
68099- sys_rmdir(path);
68100+ sys_rmdir((char __force_user *)path);
68101 else
68102- sys_unlink(path);
68103+ sys_unlink((char __force_user *)path);
68104 }
68105 }
68106
68107@@ -315,7 +315,7 @@ static int __init do_name(void)
68108 int openflags = O_WRONLY|O_CREAT;
68109 if (ml != 1)
68110 openflags |= O_TRUNC;
68111- wfd = sys_open(collected, openflags, mode);
68112+ wfd = sys_open((char __force_user *)collected, openflags, mode);
68113
68114 if (wfd >= 0) {
68115 sys_fchown(wfd, uid, gid);
68116@@ -327,17 +327,17 @@ static int __init do_name(void)
68117 }
68118 }
68119 } else if (S_ISDIR(mode)) {
68120- sys_mkdir(collected, mode);
68121- sys_chown(collected, uid, gid);
68122- sys_chmod(collected, mode);
68123+ sys_mkdir((char __force_user *)collected, mode);
68124+ sys_chown((char __force_user *)collected, uid, gid);
68125+ sys_chmod((char __force_user *)collected, mode);
68126 dir_add(collected, mtime);
68127 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
68128 S_ISFIFO(mode) || S_ISSOCK(mode)) {
68129 if (maybe_link() == 0) {
68130- sys_mknod(collected, mode, rdev);
68131- sys_chown(collected, uid, gid);
68132- sys_chmod(collected, mode);
68133- do_utime(collected, mtime);
68134+ sys_mknod((char __force_user *)collected, mode, rdev);
68135+ sys_chown((char __force_user *)collected, uid, gid);
68136+ sys_chmod((char __force_user *)collected, mode);
68137+ do_utime((char __force_user *)collected, mtime);
68138 }
68139 }
68140 return 0;
68141@@ -346,15 +346,15 @@ static int __init do_name(void)
68142 static int __init do_copy(void)
68143 {
68144 if (count >= body_len) {
68145- sys_write(wfd, victim, body_len);
68146+ sys_write(wfd, (char __force_user *)victim, body_len);
68147 sys_close(wfd);
68148- do_utime(vcollected, mtime);
68149+ do_utime((char __force_user *)vcollected, mtime);
68150 kfree(vcollected);
68151 eat(body_len);
68152 state = SkipIt;
68153 return 0;
68154 } else {
68155- sys_write(wfd, victim, count);
68156+ sys_write(wfd, (char __force_user *)victim, count);
68157 body_len -= count;
68158 eat(count);
68159 return 1;
68160@@ -365,9 +365,9 @@ static int __init do_symlink(void)
68161 {
68162 collected[N_ALIGN(name_len) + body_len] = '\0';
68163 clean_path(collected, 0);
68164- sys_symlink(collected + N_ALIGN(name_len), collected);
68165- sys_lchown(collected, uid, gid);
68166- do_utime(collected, mtime);
68167+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
68168+ sys_lchown((char __force_user *)collected, uid, gid);
68169+ do_utime((char __force_user *)collected, mtime);
68170 state = SkipIt;
68171 next_state = Reset;
68172 return 0;
68173diff --git a/init/main.c b/init/main.c
68174index 857166f..9df1d8e 100644
68175--- a/init/main.c
68176+++ b/init/main.c
68177@@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
68178 extern void tc_init(void);
68179 #endif
68180
68181+extern void grsecurity_init(void);
68182+
68183 /*
68184 * Debug helper: via this flag we know that we are in 'early bootup code'
68185 * where only the boot processor is running with IRQ disabled. This means
68186@@ -149,6 +151,61 @@ static int __init set_reset_devices(char *str)
68187
68188 __setup("reset_devices", set_reset_devices);
68189
68190+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
68191+int grsec_proc_gid = CONFIG_GRKERNSEC_PROC_GID;
68192+static int __init setup_grsec_proc_gid(char *str)
68193+{
68194+ grsec_proc_gid = (int)simple_strtol(str, NULL, 0);
68195+ return 1;
68196+}
68197+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
68198+#endif
68199+
68200+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
68201+extern char pax_enter_kernel_user[];
68202+extern char pax_exit_kernel_user[];
68203+extern pgdval_t clone_pgd_mask;
68204+#endif
68205+
68206+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
68207+static int __init setup_pax_nouderef(char *str)
68208+{
68209+#ifdef CONFIG_X86_32
68210+ unsigned int cpu;
68211+ struct desc_struct *gdt;
68212+
68213+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
68214+ gdt = get_cpu_gdt_table(cpu);
68215+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
68216+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
68217+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
68218+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
68219+ }
68220+ loadsegment(ds, __KERNEL_DS);
68221+ loadsegment(es, __KERNEL_DS);
68222+ loadsegment(ss, __KERNEL_DS);
68223+#else
68224+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
68225+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
68226+ clone_pgd_mask = ~(pgdval_t)0UL;
68227+#endif
68228+
68229+ return 0;
68230+}
68231+early_param("pax_nouderef", setup_pax_nouderef);
68232+#endif
68233+
68234+#ifdef CONFIG_PAX_SOFTMODE
68235+int pax_softmode;
68236+
68237+static int __init setup_pax_softmode(char *str)
68238+{
68239+ get_option(&str, &pax_softmode);
68240+ return 1;
68241+}
68242+__setup("pax_softmode=", setup_pax_softmode);
68243+#endif
68244+
68245 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
68246 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
68247 static const char *panic_later, *panic_param;
68248@@ -681,6 +738,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
68249 {
68250 int count = preempt_count();
68251 int ret;
68252+ const char *msg1 = "", *msg2 = "";
68253
68254 if (initcall_debug)
68255 ret = do_one_initcall_debug(fn);
68256@@ -693,15 +751,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
68257 sprintf(msgbuf, "error code %d ", ret);
68258
68259 if (preempt_count() != count) {
68260- strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
68261+ msg1 = " preemption imbalance";
68262 preempt_count() = count;
68263 }
68264 if (irqs_disabled()) {
68265- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
68266+ msg2 = " disabled interrupts";
68267 local_irq_enable();
68268 }
68269- if (msgbuf[0]) {
68270- printk("initcall %pF returned with %s\n", fn, msgbuf);
68271+ if (msgbuf[0] || *msg1 || *msg2) {
68272+ printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
68273 }
68274
68275 return ret;
68276@@ -743,6 +801,10 @@ static char *initcall_level_names[] __initdata = {
68277 "late",
68278 };
68279
68280+#ifdef CONFIG_PAX_LATENT_ENTROPY
68281+u64 latent_entropy;
68282+#endif
68283+
68284 static void __init do_initcall_level(int level)
68285 {
68286 extern const struct kernel_param __start___param[], __stop___param[];
68287@@ -755,8 +817,14 @@ static void __init do_initcall_level(int level)
68288 level, level,
68289 &repair_env_string);
68290
68291- for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
68292+ for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
68293 do_one_initcall(*fn);
68294+
68295+#ifdef CONFIG_PAX_LATENT_ENTROPY
68296+ add_device_randomness(&latent_entropy, sizeof(latent_entropy));
68297+#endif
68298+
68299+ }
68300 }
68301
68302 static void __init do_initcalls(void)
68303@@ -790,8 +858,14 @@ static void __init do_pre_smp_initcalls(void)
68304 {
68305 initcall_t *fn;
68306
68307- for (fn = __initcall_start; fn < __initcall0_start; fn++)
68308+ for (fn = __initcall_start; fn < __initcall0_start; fn++) {
68309 do_one_initcall(*fn);
68310+
68311+#ifdef CONFIG_PAX_LATENT_ENTROPY
68312+ add_device_randomness(&latent_entropy, sizeof(latent_entropy));
68313+#endif
68314+
68315+ }
68316 }
68317
68318 static int run_init_process(const char *init_filename)
68319@@ -876,7 +950,7 @@ static noinline void __init kernel_init_freeable(void)
68320 do_basic_setup();
68321
68322 /* Open the /dev/console on the rootfs, this should never fail */
68323- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
68324+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
68325 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
68326
68327 (void) sys_dup(0);
68328@@ -889,11 +963,13 @@ static noinline void __init kernel_init_freeable(void)
68329 if (!ramdisk_execute_command)
68330 ramdisk_execute_command = "/init";
68331
68332- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
68333+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
68334 ramdisk_execute_command = NULL;
68335 prepare_namespace();
68336 }
68337
68338+ grsecurity_init();
68339+
68340 /*
68341 * Ok, we have completed the initial bootup, and
68342 * we're essentially up and running. Get rid of the
68343diff --git a/ipc/mqueue.c b/ipc/mqueue.c
68344index 71a3ca1..cc330ee 100644
68345--- a/ipc/mqueue.c
68346+++ b/ipc/mqueue.c
68347@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
68348 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
68349 info->attr.mq_msgsize);
68350
68351+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
68352 spin_lock(&mq_lock);
68353 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
68354 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
68355diff --git a/ipc/msg.c b/ipc/msg.c
68356index a71af5a..a90a110 100644
68357--- a/ipc/msg.c
68358+++ b/ipc/msg.c
68359@@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
68360 return security_msg_queue_associate(msq, msgflg);
68361 }
68362
68363+static struct ipc_ops msg_ops = {
68364+ .getnew = newque,
68365+ .associate = msg_security,
68366+ .more_checks = NULL
68367+};
68368+
68369 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
68370 {
68371 struct ipc_namespace *ns;
68372- struct ipc_ops msg_ops;
68373 struct ipc_params msg_params;
68374
68375 ns = current->nsproxy->ipc_ns;
68376
68377- msg_ops.getnew = newque;
68378- msg_ops.associate = msg_security;
68379- msg_ops.more_checks = NULL;
68380-
68381 msg_params.key = key;
68382 msg_params.flg = msgflg;
68383
68384diff --git a/ipc/sem.c b/ipc/sem.c
68385index 58d31f1..cce7a55 100644
68386--- a/ipc/sem.c
68387+++ b/ipc/sem.c
68388@@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
68389 return 0;
68390 }
68391
68392+static struct ipc_ops sem_ops = {
68393+ .getnew = newary,
68394+ .associate = sem_security,
68395+ .more_checks = sem_more_checks
68396+};
68397+
68398 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
68399 {
68400 struct ipc_namespace *ns;
68401- struct ipc_ops sem_ops;
68402 struct ipc_params sem_params;
68403
68404 ns = current->nsproxy->ipc_ns;
68405@@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
68406 if (nsems < 0 || nsems > ns->sc_semmsl)
68407 return -EINVAL;
68408
68409- sem_ops.getnew = newary;
68410- sem_ops.associate = sem_security;
68411- sem_ops.more_checks = sem_more_checks;
68412-
68413 sem_params.key = key;
68414 sem_params.flg = semflg;
68415 sem_params.u.nsems = nsems;
68416diff --git a/ipc/shm.c b/ipc/shm.c
68417index dff40c9..9450e27 100644
68418--- a/ipc/shm.c
68419+++ b/ipc/shm.c
68420@@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
68421 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
68422 #endif
68423
68424+#ifdef CONFIG_GRKERNSEC
68425+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
68426+ const time_t shm_createtime, const uid_t cuid,
68427+ const int shmid);
68428+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
68429+ const time_t shm_createtime);
68430+#endif
68431+
68432 void shm_init_ns(struct ipc_namespace *ns)
68433 {
68434 ns->shm_ctlmax = SHMMAX;
68435@@ -520,6 +528,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
68436 shp->shm_lprid = 0;
68437 shp->shm_atim = shp->shm_dtim = 0;
68438 shp->shm_ctim = get_seconds();
68439+#ifdef CONFIG_GRKERNSEC
68440+ {
68441+ struct timespec timeval;
68442+ do_posix_clock_monotonic_gettime(&timeval);
68443+
68444+ shp->shm_createtime = timeval.tv_sec;
68445+ }
68446+#endif
68447 shp->shm_segsz = size;
68448 shp->shm_nattch = 0;
68449 shp->shm_file = file;
68450@@ -571,18 +587,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
68451 return 0;
68452 }
68453
68454+static struct ipc_ops shm_ops = {
68455+ .getnew = newseg,
68456+ .associate = shm_security,
68457+ .more_checks = shm_more_checks
68458+};
68459+
68460 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
68461 {
68462 struct ipc_namespace *ns;
68463- struct ipc_ops shm_ops;
68464 struct ipc_params shm_params;
68465
68466 ns = current->nsproxy->ipc_ns;
68467
68468- shm_ops.getnew = newseg;
68469- shm_ops.associate = shm_security;
68470- shm_ops.more_checks = shm_more_checks;
68471-
68472 shm_params.key = key;
68473 shm_params.flg = shmflg;
68474 shm_params.u.size = size;
68475@@ -1003,6 +1020,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
68476 f_mode = FMODE_READ | FMODE_WRITE;
68477 }
68478 if (shmflg & SHM_EXEC) {
68479+
68480+#ifdef CONFIG_PAX_MPROTECT
68481+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
68482+ goto out;
68483+#endif
68484+
68485 prot |= PROT_EXEC;
68486 acc_mode |= S_IXUGO;
68487 }
68488@@ -1026,9 +1049,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
68489 if (err)
68490 goto out_unlock;
68491
68492+#ifdef CONFIG_GRKERNSEC
68493+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
68494+ shp->shm_perm.cuid, shmid) ||
68495+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
68496+ err = -EACCES;
68497+ goto out_unlock;
68498+ }
68499+#endif
68500+
68501 path = shp->shm_file->f_path;
68502 path_get(&path);
68503 shp->shm_nattch++;
68504+#ifdef CONFIG_GRKERNSEC
68505+ shp->shm_lapid = current->pid;
68506+#endif
68507 size = i_size_read(path.dentry->d_inode);
68508 shm_unlock(shp);
68509
68510diff --git a/kernel/acct.c b/kernel/acct.c
68511index 051e071..15e0920 100644
68512--- a/kernel/acct.c
68513+++ b/kernel/acct.c
68514@@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
68515 */
68516 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
68517 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
68518- file->f_op->write(file, (char *)&ac,
68519+ file->f_op->write(file, (char __force_user *)&ac,
68520 sizeof(acct_t), &file->f_pos);
68521 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
68522 set_fs(fs);
68523diff --git a/kernel/audit.c b/kernel/audit.c
68524index 40414e9..c920b72 100644
68525--- a/kernel/audit.c
68526+++ b/kernel/audit.c
68527@@ -116,7 +116,7 @@ u32 audit_sig_sid = 0;
68528 3) suppressed due to audit_rate_limit
68529 4) suppressed due to audit_backlog_limit
68530 */
68531-static atomic_t audit_lost = ATOMIC_INIT(0);
68532+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
68533
68534 /* The netlink socket. */
68535 static struct sock *audit_sock;
68536@@ -238,7 +238,7 @@ void audit_log_lost(const char *message)
68537 unsigned long now;
68538 int print;
68539
68540- atomic_inc(&audit_lost);
68541+ atomic_inc_unchecked(&audit_lost);
68542
68543 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
68544
68545@@ -257,7 +257,7 @@ void audit_log_lost(const char *message)
68546 printk(KERN_WARNING
68547 "audit: audit_lost=%d audit_rate_limit=%d "
68548 "audit_backlog_limit=%d\n",
68549- atomic_read(&audit_lost),
68550+ atomic_read_unchecked(&audit_lost),
68551 audit_rate_limit,
68552 audit_backlog_limit);
68553 audit_panic(message);
68554@@ -677,7 +677,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
68555 status_set.pid = audit_pid;
68556 status_set.rate_limit = audit_rate_limit;
68557 status_set.backlog_limit = audit_backlog_limit;
68558- status_set.lost = atomic_read(&audit_lost);
68559+ status_set.lost = atomic_read_unchecked(&audit_lost);
68560 status_set.backlog = skb_queue_len(&audit_skb_queue);
68561 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
68562 &status_set, sizeof(status_set));
68563diff --git a/kernel/auditsc.c b/kernel/auditsc.c
68564index 157e989..b28b365 100644
68565--- a/kernel/auditsc.c
68566+++ b/kernel/auditsc.c
68567@@ -2352,7 +2352,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
68568 }
68569
68570 /* global counter which is incremented every time something logs in */
68571-static atomic_t session_id = ATOMIC_INIT(0);
68572+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
68573
68574 /**
68575 * audit_set_loginuid - set current task's audit_context loginuid
68576@@ -2376,7 +2376,7 @@ int audit_set_loginuid(kuid_t loginuid)
68577 return -EPERM;
68578 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
68579
68580- sessionid = atomic_inc_return(&session_id);
68581+ sessionid = atomic_inc_return_unchecked(&session_id);
68582 if (context && context->in_syscall) {
68583 struct audit_buffer *ab;
68584
68585diff --git a/kernel/capability.c b/kernel/capability.c
68586index 493d972..ea17248 100644
68587--- a/kernel/capability.c
68588+++ b/kernel/capability.c
68589@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
68590 * before modification is attempted and the application
68591 * fails.
68592 */
68593+ if (tocopy > ARRAY_SIZE(kdata))
68594+ return -EFAULT;
68595+
68596 if (copy_to_user(dataptr, kdata, tocopy
68597 * sizeof(struct __user_cap_data_struct))) {
68598 return -EFAULT;
68599@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
68600 int ret;
68601
68602 rcu_read_lock();
68603- ret = security_capable(__task_cred(t), ns, cap);
68604+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
68605+ gr_task_is_capable(t, __task_cred(t), cap);
68606 rcu_read_unlock();
68607
68608- return (ret == 0);
68609+ return ret;
68610 }
68611
68612 /**
68613@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
68614 int ret;
68615
68616 rcu_read_lock();
68617- ret = security_capable_noaudit(__task_cred(t), ns, cap);
68618+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
68619 rcu_read_unlock();
68620
68621- return (ret == 0);
68622+ return ret;
68623 }
68624
68625 /**
68626@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
68627 BUG();
68628 }
68629
68630- if (security_capable(current_cred(), ns, cap) == 0) {
68631+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
68632 current->flags |= PF_SUPERPRIV;
68633 return true;
68634 }
68635@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
68636 }
68637 EXPORT_SYMBOL(ns_capable);
68638
68639+bool ns_capable_nolog(struct user_namespace *ns, int cap)
68640+{
68641+ if (unlikely(!cap_valid(cap))) {
68642+ printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
68643+ BUG();
68644+ }
68645+
68646+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
68647+ current->flags |= PF_SUPERPRIV;
68648+ return true;
68649+ }
68650+ return false;
68651+}
68652+EXPORT_SYMBOL(ns_capable_nolog);
68653+
68654 /**
68655 * capable - Determine if the current task has a superior capability in effect
68656 * @cap: The capability to be tested for
68657@@ -408,6 +427,12 @@ bool capable(int cap)
68658 }
68659 EXPORT_SYMBOL(capable);
68660
68661+bool capable_nolog(int cap)
68662+{
68663+ return ns_capable_nolog(&init_user_ns, cap);
68664+}
68665+EXPORT_SYMBOL(capable_nolog);
68666+
68667 /**
68668 * nsown_capable - Check superior capability to one's own user_ns
68669 * @cap: The capability in question
68670@@ -440,3 +465,10 @@ bool inode_capable(const struct inode *inode, int cap)
68671
68672 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
68673 }
68674+
68675+bool inode_capable_nolog(const struct inode *inode, int cap)
68676+{
68677+ struct user_namespace *ns = current_user_ns();
68678+
68679+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
68680+}
68681diff --git a/kernel/cgroup.c b/kernel/cgroup.c
68682index ad99830..992d8a7 100644
68683--- a/kernel/cgroup.c
68684+++ b/kernel/cgroup.c
68685@@ -5514,7 +5514,7 @@ static int cgroup_css_links_read(struct cgroup *cont,
68686 struct css_set *cg = link->cg;
68687 struct task_struct *task;
68688 int count = 0;
68689- seq_printf(seq, "css_set %p\n", cg);
68690+ seq_printf(seq, "css_set %pK\n", cg);
68691 list_for_each_entry(task, &cg->tasks, cg_list) {
68692 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
68693 seq_puts(seq, " ...\n");
68694diff --git a/kernel/compat.c b/kernel/compat.c
68695index c28a306..b4d0cf3 100644
68696--- a/kernel/compat.c
68697+++ b/kernel/compat.c
68698@@ -13,6 +13,7 @@
68699
68700 #include <linux/linkage.h>
68701 #include <linux/compat.h>
68702+#include <linux/module.h>
68703 #include <linux/errno.h>
68704 #include <linux/time.h>
68705 #include <linux/signal.h>
68706@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
68707 mm_segment_t oldfs;
68708 long ret;
68709
68710- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
68711+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
68712 oldfs = get_fs();
68713 set_fs(KERNEL_DS);
68714 ret = hrtimer_nanosleep_restart(restart);
68715@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
68716 oldfs = get_fs();
68717 set_fs(KERNEL_DS);
68718 ret = hrtimer_nanosleep(&tu,
68719- rmtp ? (struct timespec __user *)&rmt : NULL,
68720+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
68721 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
68722 set_fs(oldfs);
68723
68724@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
68725 mm_segment_t old_fs = get_fs();
68726
68727 set_fs(KERNEL_DS);
68728- ret = sys_sigpending((old_sigset_t __user *) &s);
68729+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
68730 set_fs(old_fs);
68731 if (ret == 0)
68732 ret = put_user(s, set);
68733@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
68734 mm_segment_t old_fs = get_fs();
68735
68736 set_fs(KERNEL_DS);
68737- ret = sys_old_getrlimit(resource, &r);
68738+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
68739 set_fs(old_fs);
68740
68741 if (!ret) {
68742@@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
68743 mm_segment_t old_fs = get_fs();
68744
68745 set_fs(KERNEL_DS);
68746- ret = sys_getrusage(who, (struct rusage __user *) &r);
68747+ ret = sys_getrusage(who, (struct rusage __force_user *) &r);
68748 set_fs(old_fs);
68749
68750 if (ret)
68751@@ -550,8 +551,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
68752 set_fs (KERNEL_DS);
68753 ret = sys_wait4(pid,
68754 (stat_addr ?
68755- (unsigned int __user *) &status : NULL),
68756- options, (struct rusage __user *) &r);
68757+ (unsigned int __force_user *) &status : NULL),
68758+ options, (struct rusage __force_user *) &r);
68759 set_fs (old_fs);
68760
68761 if (ret > 0) {
68762@@ -576,8 +577,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
68763 memset(&info, 0, sizeof(info));
68764
68765 set_fs(KERNEL_DS);
68766- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
68767- uru ? (struct rusage __user *)&ru : NULL);
68768+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
68769+ uru ? (struct rusage __force_user *)&ru : NULL);
68770 set_fs(old_fs);
68771
68772 if ((ret < 0) || (info.si_signo == 0))
68773@@ -707,8 +708,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
68774 oldfs = get_fs();
68775 set_fs(KERNEL_DS);
68776 err = sys_timer_settime(timer_id, flags,
68777- (struct itimerspec __user *) &newts,
68778- (struct itimerspec __user *) &oldts);
68779+ (struct itimerspec __force_user *) &newts,
68780+ (struct itimerspec __force_user *) &oldts);
68781 set_fs(oldfs);
68782 if (!err && old && put_compat_itimerspec(old, &oldts))
68783 return -EFAULT;
68784@@ -725,7 +726,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
68785 oldfs = get_fs();
68786 set_fs(KERNEL_DS);
68787 err = sys_timer_gettime(timer_id,
68788- (struct itimerspec __user *) &ts);
68789+ (struct itimerspec __force_user *) &ts);
68790 set_fs(oldfs);
68791 if (!err && put_compat_itimerspec(setting, &ts))
68792 return -EFAULT;
68793@@ -744,7 +745,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
68794 oldfs = get_fs();
68795 set_fs(KERNEL_DS);
68796 err = sys_clock_settime(which_clock,
68797- (struct timespec __user *) &ts);
68798+ (struct timespec __force_user *) &ts);
68799 set_fs(oldfs);
68800 return err;
68801 }
68802@@ -759,7 +760,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
68803 oldfs = get_fs();
68804 set_fs(KERNEL_DS);
68805 err = sys_clock_gettime(which_clock,
68806- (struct timespec __user *) &ts);
68807+ (struct timespec __force_user *) &ts);
68808 set_fs(oldfs);
68809 if (!err && put_compat_timespec(&ts, tp))
68810 return -EFAULT;
68811@@ -779,7 +780,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
68812
68813 oldfs = get_fs();
68814 set_fs(KERNEL_DS);
68815- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
68816+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
68817 set_fs(oldfs);
68818
68819 err = compat_put_timex(utp, &txc);
68820@@ -799,7 +800,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
68821 oldfs = get_fs();
68822 set_fs(KERNEL_DS);
68823 err = sys_clock_getres(which_clock,
68824- (struct timespec __user *) &ts);
68825+ (struct timespec __force_user *) &ts);
68826 set_fs(oldfs);
68827 if (!err && tp && put_compat_timespec(&ts, tp))
68828 return -EFAULT;
68829@@ -811,9 +812,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
68830 long err;
68831 mm_segment_t oldfs;
68832 struct timespec tu;
68833- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
68834+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
68835
68836- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
68837+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
68838 oldfs = get_fs();
68839 set_fs(KERNEL_DS);
68840 err = clock_nanosleep_restart(restart);
68841@@ -845,8 +846,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
68842 oldfs = get_fs();
68843 set_fs(KERNEL_DS);
68844 err = sys_clock_nanosleep(which_clock, flags,
68845- (struct timespec __user *) &in,
68846- (struct timespec __user *) &out);
68847+ (struct timespec __force_user *) &in,
68848+ (struct timespec __force_user *) &out);
68849 set_fs(oldfs);
68850
68851 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
68852diff --git a/kernel/configs.c b/kernel/configs.c
68853index 42e8fa0..9e7406b 100644
68854--- a/kernel/configs.c
68855+++ b/kernel/configs.c
68856@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
68857 struct proc_dir_entry *entry;
68858
68859 /* create the current config file */
68860+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
68861+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
68862+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
68863+ &ikconfig_file_ops);
68864+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68865+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
68866+ &ikconfig_file_ops);
68867+#endif
68868+#else
68869 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
68870 &ikconfig_file_ops);
68871+#endif
68872+
68873 if (!entry)
68874 return -ENOMEM;
68875
68876diff --git a/kernel/cred.c b/kernel/cred.c
68877index 48cea3d..3476734 100644
68878--- a/kernel/cred.c
68879+++ b/kernel/cred.c
68880@@ -207,6 +207,16 @@ void exit_creds(struct task_struct *tsk)
68881 validate_creds(cred);
68882 alter_cred_subscribers(cred, -1);
68883 put_cred(cred);
68884+
68885+#ifdef CONFIG_GRKERNSEC_SETXID
68886+ cred = (struct cred *) tsk->delayed_cred;
68887+ if (cred != NULL) {
68888+ tsk->delayed_cred = NULL;
68889+ validate_creds(cred);
68890+ alter_cred_subscribers(cred, -1);
68891+ put_cred(cred);
68892+ }
68893+#endif
68894 }
68895
68896 /**
68897@@ -469,7 +479,7 @@ error_put:
68898 * Always returns 0 thus allowing this function to be tail-called at the end
68899 * of, say, sys_setgid().
68900 */
68901-int commit_creds(struct cred *new)
68902+static int __commit_creds(struct cred *new)
68903 {
68904 struct task_struct *task = current;
68905 const struct cred *old = task->real_cred;
68906@@ -488,6 +498,8 @@ int commit_creds(struct cred *new)
68907
68908 get_cred(new); /* we will require a ref for the subj creds too */
68909
68910+ gr_set_role_label(task, new->uid, new->gid);
68911+
68912 /* dumpability changes */
68913 if (!uid_eq(old->euid, new->euid) ||
68914 !gid_eq(old->egid, new->egid) ||
68915@@ -537,6 +549,101 @@ int commit_creds(struct cred *new)
68916 put_cred(old);
68917 return 0;
68918 }
68919+#ifdef CONFIG_GRKERNSEC_SETXID
68920+extern int set_user(struct cred *new);
68921+
68922+void gr_delayed_cred_worker(void)
68923+{
68924+ const struct cred *new = current->delayed_cred;
68925+ struct cred *ncred;
68926+
68927+ current->delayed_cred = NULL;
68928+
68929+ if (current_uid() && new != NULL) {
68930+ // from doing get_cred on it when queueing this
68931+ put_cred(new);
68932+ return;
68933+ } else if (new == NULL)
68934+ return;
68935+
68936+ ncred = prepare_creds();
68937+ if (!ncred)
68938+ goto die;
68939+ // uids
68940+ ncred->uid = new->uid;
68941+ ncred->euid = new->euid;
68942+ ncred->suid = new->suid;
68943+ ncred->fsuid = new->fsuid;
68944+ // gids
68945+ ncred->gid = new->gid;
68946+ ncred->egid = new->egid;
68947+ ncred->sgid = new->sgid;
68948+ ncred->fsgid = new->fsgid;
68949+ // groups
68950+ if (set_groups(ncred, new->group_info) < 0) {
68951+ abort_creds(ncred);
68952+ goto die;
68953+ }
68954+ // caps
68955+ ncred->securebits = new->securebits;
68956+ ncred->cap_inheritable = new->cap_inheritable;
68957+ ncred->cap_permitted = new->cap_permitted;
68958+ ncred->cap_effective = new->cap_effective;
68959+ ncred->cap_bset = new->cap_bset;
68960+
68961+ if (set_user(ncred)) {
68962+ abort_creds(ncred);
68963+ goto die;
68964+ }
68965+
68966+ // from doing get_cred on it when queueing this
68967+ put_cred(new);
68968+
68969+ __commit_creds(ncred);
68970+ return;
68971+die:
68972+ // from doing get_cred on it when queueing this
68973+ put_cred(new);
68974+ do_group_exit(SIGKILL);
68975+}
68976+#endif
68977+
68978+int commit_creds(struct cred *new)
68979+{
68980+#ifdef CONFIG_GRKERNSEC_SETXID
68981+ int ret;
68982+ int schedule_it = 0;
68983+ struct task_struct *t;
68984+
68985+ /* we won't get called with tasklist_lock held for writing
68986+ and interrupts disabled as the cred struct in that case is
68987+ init_cred
68988+ */
68989+ if (grsec_enable_setxid && !current_is_single_threaded() &&
68990+ !current_uid() && new->uid) {
68991+ schedule_it = 1;
68992+ }
68993+ ret = __commit_creds(new);
68994+ if (schedule_it) {
68995+ rcu_read_lock();
68996+ read_lock(&tasklist_lock);
68997+ for (t = next_thread(current); t != current;
68998+ t = next_thread(t)) {
68999+ if (t->delayed_cred == NULL) {
69000+ t->delayed_cred = get_cred(new);
69001+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
69002+ set_tsk_need_resched(t);
69003+ }
69004+ }
69005+ read_unlock(&tasklist_lock);
69006+ rcu_read_unlock();
69007+ }
69008+ return ret;
69009+#else
69010+ return __commit_creds(new);
69011+#endif
69012+}
69013+
69014 EXPORT_SYMBOL(commit_creds);
69015
69016 /**
69017diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
69018index 9a61738..c5c8f3a 100644
69019--- a/kernel/debug/debug_core.c
69020+++ b/kernel/debug/debug_core.c
69021@@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
69022 */
69023 static atomic_t masters_in_kgdb;
69024 static atomic_t slaves_in_kgdb;
69025-static atomic_t kgdb_break_tasklet_var;
69026+static atomic_unchecked_t kgdb_break_tasklet_var;
69027 atomic_t kgdb_setting_breakpoint;
69028
69029 struct task_struct *kgdb_usethread;
69030@@ -132,7 +132,7 @@ int kgdb_single_step;
69031 static pid_t kgdb_sstep_pid;
69032
69033 /* to keep track of the CPU which is doing the single stepping*/
69034-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
69035+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
69036
69037 /*
69038 * If you are debugging a problem where roundup (the collection of
69039@@ -540,7 +540,7 @@ return_normal:
69040 * kernel will only try for the value of sstep_tries before
69041 * giving up and continuing on.
69042 */
69043- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
69044+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
69045 (kgdb_info[cpu].task &&
69046 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
69047 atomic_set(&kgdb_active, -1);
69048@@ -634,8 +634,8 @@ cpu_master_loop:
69049 }
69050
69051 kgdb_restore:
69052- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
69053- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
69054+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
69055+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
69056 if (kgdb_info[sstep_cpu].task)
69057 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
69058 else
69059@@ -887,18 +887,18 @@ static void kgdb_unregister_callbacks(void)
69060 static void kgdb_tasklet_bpt(unsigned long ing)
69061 {
69062 kgdb_breakpoint();
69063- atomic_set(&kgdb_break_tasklet_var, 0);
69064+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
69065 }
69066
69067 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
69068
69069 void kgdb_schedule_breakpoint(void)
69070 {
69071- if (atomic_read(&kgdb_break_tasklet_var) ||
69072+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
69073 atomic_read(&kgdb_active) != -1 ||
69074 atomic_read(&kgdb_setting_breakpoint))
69075 return;
69076- atomic_inc(&kgdb_break_tasklet_var);
69077+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
69078 tasklet_schedule(&kgdb_tasklet_breakpoint);
69079 }
69080 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
69081diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
69082index 8875254..7cf4928 100644
69083--- a/kernel/debug/kdb/kdb_main.c
69084+++ b/kernel/debug/kdb/kdb_main.c
69085@@ -1974,7 +1974,7 @@ static int kdb_lsmod(int argc, const char **argv)
69086 continue;
69087
69088 kdb_printf("%-20s%8u 0x%p ", mod->name,
69089- mod->core_size, (void *)mod);
69090+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
69091 #ifdef CONFIG_MODULE_UNLOAD
69092 kdb_printf("%4ld ", module_refcount(mod));
69093 #endif
69094@@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
69095 kdb_printf(" (Loading)");
69096 else
69097 kdb_printf(" (Live)");
69098- kdb_printf(" 0x%p", mod->module_core);
69099+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
69100
69101 #ifdef CONFIG_MODULE_UNLOAD
69102 {
69103diff --git a/kernel/events/core.c b/kernel/events/core.c
69104index dbccf83..8c66482 100644
69105--- a/kernel/events/core.c
69106+++ b/kernel/events/core.c
69107@@ -182,7 +182,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
69108 return 0;
69109 }
69110
69111-static atomic64_t perf_event_id;
69112+static atomic64_unchecked_t perf_event_id;
69113
69114 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
69115 enum event_type_t event_type);
69116@@ -2668,7 +2668,7 @@ static void __perf_event_read(void *info)
69117
69118 static inline u64 perf_event_count(struct perf_event *event)
69119 {
69120- return local64_read(&event->count) + atomic64_read(&event->child_count);
69121+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
69122 }
69123
69124 static u64 perf_event_read(struct perf_event *event)
69125@@ -2998,9 +2998,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
69126 mutex_lock(&event->child_mutex);
69127 total += perf_event_read(event);
69128 *enabled += event->total_time_enabled +
69129- atomic64_read(&event->child_total_time_enabled);
69130+ atomic64_read_unchecked(&event->child_total_time_enabled);
69131 *running += event->total_time_running +
69132- atomic64_read(&event->child_total_time_running);
69133+ atomic64_read_unchecked(&event->child_total_time_running);
69134
69135 list_for_each_entry(child, &event->child_list, child_list) {
69136 total += perf_event_read(child);
69137@@ -3403,10 +3403,10 @@ void perf_event_update_userpage(struct perf_event *event)
69138 userpg->offset -= local64_read(&event->hw.prev_count);
69139
69140 userpg->time_enabled = enabled +
69141- atomic64_read(&event->child_total_time_enabled);
69142+ atomic64_read_unchecked(&event->child_total_time_enabled);
69143
69144 userpg->time_running = running +
69145- atomic64_read(&event->child_total_time_running);
69146+ atomic64_read_unchecked(&event->child_total_time_running);
69147
69148 arch_perf_update_userpage(userpg, now);
69149
69150@@ -3965,11 +3965,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
69151 values[n++] = perf_event_count(event);
69152 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
69153 values[n++] = enabled +
69154- atomic64_read(&event->child_total_time_enabled);
69155+ atomic64_read_unchecked(&event->child_total_time_enabled);
69156 }
69157 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
69158 values[n++] = running +
69159- atomic64_read(&event->child_total_time_running);
69160+ atomic64_read_unchecked(&event->child_total_time_running);
69161 }
69162 if (read_format & PERF_FORMAT_ID)
69163 values[n++] = primary_event_id(event);
69164@@ -4712,12 +4712,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
69165 * need to add enough zero bytes after the string to handle
69166 * the 64bit alignment we do later.
69167 */
69168- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
69169+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
69170 if (!buf) {
69171 name = strncpy(tmp, "//enomem", sizeof(tmp));
69172 goto got_name;
69173 }
69174- name = d_path(&file->f_path, buf, PATH_MAX);
69175+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
69176 if (IS_ERR(name)) {
69177 name = strncpy(tmp, "//toolong", sizeof(tmp));
69178 goto got_name;
69179@@ -6156,7 +6156,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
69180 event->parent = parent_event;
69181
69182 event->ns = get_pid_ns(current->nsproxy->pid_ns);
69183- event->id = atomic64_inc_return(&perf_event_id);
69184+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
69185
69186 event->state = PERF_EVENT_STATE_INACTIVE;
69187
69188@@ -6774,10 +6774,10 @@ static void sync_child_event(struct perf_event *child_event,
69189 /*
69190 * Add back the child's count to the parent's count:
69191 */
69192- atomic64_add(child_val, &parent_event->child_count);
69193- atomic64_add(child_event->total_time_enabled,
69194+ atomic64_add_unchecked(child_val, &parent_event->child_count);
69195+ atomic64_add_unchecked(child_event->total_time_enabled,
69196 &parent_event->child_total_time_enabled);
69197- atomic64_add(child_event->total_time_running,
69198+ atomic64_add_unchecked(child_event->total_time_running,
69199 &parent_event->child_total_time_running);
69200
69201 /*
69202diff --git a/kernel/exit.c b/kernel/exit.c
69203index 346616c..f103b28 100644
69204--- a/kernel/exit.c
69205+++ b/kernel/exit.c
69206@@ -182,6 +182,10 @@ void release_task(struct task_struct * p)
69207 struct task_struct *leader;
69208 int zap_leader;
69209 repeat:
69210+#ifdef CONFIG_NET
69211+ gr_del_task_from_ip_table(p);
69212+#endif
69213+
69214 /* don't need to get the RCU readlock here - the process is dead and
69215 * can't be modifying its own credentials. But shut RCU-lockdep up */
69216 rcu_read_lock();
69217@@ -394,7 +398,7 @@ int allow_signal(int sig)
69218 * know it'll be handled, so that they don't get converted to
69219 * SIGKILL or just silently dropped.
69220 */
69221- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
69222+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
69223 recalc_sigpending();
69224 spin_unlock_irq(&current->sighand->siglock);
69225 return 0;
69226@@ -430,6 +434,9 @@ void daemonize(const char *name, ...)
69227 vsnprintf(current->comm, sizeof(current->comm), name, args);
69228 va_end(args);
69229
69230+ gr_put_exec_file(current);
69231+ gr_set_kernel_label(current);
69232+
69233 /*
69234 * If we were started as result of loading a module, close all of the
69235 * user space pages. We don't need them, and if we didn't close them
69236@@ -812,6 +819,8 @@ void do_exit(long code)
69237 struct task_struct *tsk = current;
69238 int group_dead;
69239
69240+ set_fs(USER_DS);
69241+
69242 profile_task_exit(tsk);
69243
69244 WARN_ON(blk_needs_flush_plug(tsk));
69245@@ -828,7 +837,6 @@ void do_exit(long code)
69246 * mm_release()->clear_child_tid() from writing to a user-controlled
69247 * kernel address.
69248 */
69249- set_fs(USER_DS);
69250
69251 ptrace_event(PTRACE_EVENT_EXIT, code);
69252
69253@@ -887,6 +895,9 @@ void do_exit(long code)
69254 tsk->exit_code = code;
69255 taskstats_exit(tsk, group_dead);
69256
69257+ gr_acl_handle_psacct(tsk, code);
69258+ gr_acl_handle_exit();
69259+
69260 exit_mm(tsk);
69261
69262 if (group_dead)
69263@@ -1007,7 +1018,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
69264 * Take down every thread in the group. This is called by fatal signals
69265 * as well as by sys_exit_group (below).
69266 */
69267-void
69268+__noreturn void
69269 do_group_exit(int exit_code)
69270 {
69271 struct signal_struct *sig = current->signal;
69272diff --git a/kernel/fork.c b/kernel/fork.c
69273index acc4cb6..b524cb5 100644
69274--- a/kernel/fork.c
69275+++ b/kernel/fork.c
69276@@ -318,7 +318,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
69277 *stackend = STACK_END_MAGIC; /* for overflow detection */
69278
69279 #ifdef CONFIG_CC_STACKPROTECTOR
69280- tsk->stack_canary = get_random_int();
69281+ tsk->stack_canary = pax_get_random_long();
69282 #endif
69283
69284 /*
69285@@ -344,13 +344,81 @@ free_tsk:
69286 }
69287
69288 #ifdef CONFIG_MMU
69289+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
69290+{
69291+ struct vm_area_struct *tmp;
69292+ unsigned long charge;
69293+ struct mempolicy *pol;
69294+ struct file *file;
69295+
69296+ charge = 0;
69297+ if (mpnt->vm_flags & VM_ACCOUNT) {
69298+ unsigned long len = vma_pages(mpnt);
69299+
69300+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
69301+ goto fail_nomem;
69302+ charge = len;
69303+ }
69304+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
69305+ if (!tmp)
69306+ goto fail_nomem;
69307+ *tmp = *mpnt;
69308+ tmp->vm_mm = mm;
69309+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
69310+ pol = mpol_dup(vma_policy(mpnt));
69311+ if (IS_ERR(pol))
69312+ goto fail_nomem_policy;
69313+ vma_set_policy(tmp, pol);
69314+ if (anon_vma_fork(tmp, mpnt))
69315+ goto fail_nomem_anon_vma_fork;
69316+ tmp->vm_flags &= ~VM_LOCKED;
69317+ tmp->vm_next = tmp->vm_prev = NULL;
69318+ tmp->vm_mirror = NULL;
69319+ file = tmp->vm_file;
69320+ if (file) {
69321+ struct inode *inode = file->f_path.dentry->d_inode;
69322+ struct address_space *mapping = file->f_mapping;
69323+
69324+ get_file(file);
69325+ if (tmp->vm_flags & VM_DENYWRITE)
69326+ atomic_dec(&inode->i_writecount);
69327+ mutex_lock(&mapping->i_mmap_mutex);
69328+ if (tmp->vm_flags & VM_SHARED)
69329+ mapping->i_mmap_writable++;
69330+ flush_dcache_mmap_lock(mapping);
69331+ /* insert tmp into the share list, just after mpnt */
69332+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
69333+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
69334+ else
69335+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
69336+ flush_dcache_mmap_unlock(mapping);
69337+ mutex_unlock(&mapping->i_mmap_mutex);
69338+ }
69339+
69340+ /*
69341+ * Clear hugetlb-related page reserves for children. This only
69342+ * affects MAP_PRIVATE mappings. Faults generated by the child
69343+ * are not guaranteed to succeed, even if read-only
69344+ */
69345+ if (is_vm_hugetlb_page(tmp))
69346+ reset_vma_resv_huge_pages(tmp);
69347+
69348+ return tmp;
69349+
69350+fail_nomem_anon_vma_fork:
69351+ mpol_put(pol);
69352+fail_nomem_policy:
69353+ kmem_cache_free(vm_area_cachep, tmp);
69354+fail_nomem:
69355+ vm_unacct_memory(charge);
69356+ return NULL;
69357+}
69358+
69359 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
69360 {
69361 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
69362 struct rb_node **rb_link, *rb_parent;
69363 int retval;
69364- unsigned long charge;
69365- struct mempolicy *pol;
69366
69367 down_write(&oldmm->mmap_sem);
69368 flush_cache_dup_mm(oldmm);
69369@@ -363,8 +431,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
69370 mm->locked_vm = 0;
69371 mm->mmap = NULL;
69372 mm->mmap_cache = NULL;
69373- mm->free_area_cache = oldmm->mmap_base;
69374- mm->cached_hole_size = ~0UL;
69375+ mm->free_area_cache = oldmm->free_area_cache;
69376+ mm->cached_hole_size = oldmm->cached_hole_size;
69377 mm->map_count = 0;
69378 cpumask_clear(mm_cpumask(mm));
69379 mm->mm_rb = RB_ROOT;
69380@@ -380,57 +448,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
69381
69382 prev = NULL;
69383 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
69384- struct file *file;
69385-
69386 if (mpnt->vm_flags & VM_DONTCOPY) {
69387 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
69388 -vma_pages(mpnt));
69389 continue;
69390 }
69391- charge = 0;
69392- if (mpnt->vm_flags & VM_ACCOUNT) {
69393- unsigned long len = vma_pages(mpnt);
69394-
69395- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
69396- goto fail_nomem;
69397- charge = len;
69398- }
69399- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
69400- if (!tmp)
69401- goto fail_nomem;
69402- *tmp = *mpnt;
69403- INIT_LIST_HEAD(&tmp->anon_vma_chain);
69404- pol = mpol_dup(vma_policy(mpnt));
69405- retval = PTR_ERR(pol);
69406- if (IS_ERR(pol))
69407- goto fail_nomem_policy;
69408- vma_set_policy(tmp, pol);
69409- tmp->vm_mm = mm;
69410- if (anon_vma_fork(tmp, mpnt))
69411- goto fail_nomem_anon_vma_fork;
69412- tmp->vm_flags &= ~VM_LOCKED;
69413- tmp->vm_next = tmp->vm_prev = NULL;
69414- file = tmp->vm_file;
69415- if (file) {
69416- struct inode *inode = file->f_path.dentry->d_inode;
69417- struct address_space *mapping = file->f_mapping;
69418-
69419- get_file(file);
69420- if (tmp->vm_flags & VM_DENYWRITE)
69421- atomic_dec(&inode->i_writecount);
69422- mutex_lock(&mapping->i_mmap_mutex);
69423- if (tmp->vm_flags & VM_SHARED)
69424- mapping->i_mmap_writable++;
69425- flush_dcache_mmap_lock(mapping);
69426- /* insert tmp into the share list, just after mpnt */
69427- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
69428- vma_nonlinear_insert(tmp,
69429- &mapping->i_mmap_nonlinear);
69430- else
69431- vma_interval_tree_insert_after(tmp, mpnt,
69432- &mapping->i_mmap);
69433- flush_dcache_mmap_unlock(mapping);
69434- mutex_unlock(&mapping->i_mmap_mutex);
69435+ tmp = dup_vma(mm, oldmm, mpnt);
69436+ if (!tmp) {
69437+ retval = -ENOMEM;
69438+ goto out;
69439 }
69440
69441 /*
69442@@ -462,6 +488,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
69443 if (retval)
69444 goto out;
69445 }
69446+
69447+#ifdef CONFIG_PAX_SEGMEXEC
69448+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
69449+ struct vm_area_struct *mpnt_m;
69450+
69451+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
69452+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
69453+
69454+ if (!mpnt->vm_mirror)
69455+ continue;
69456+
69457+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
69458+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
69459+ mpnt->vm_mirror = mpnt_m;
69460+ } else {
69461+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
69462+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
69463+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
69464+ mpnt->vm_mirror->vm_mirror = mpnt;
69465+ }
69466+ }
69467+ BUG_ON(mpnt_m);
69468+ }
69469+#endif
69470+
69471 /* a new mm has just been created */
69472 arch_dup_mmap(oldmm, mm);
69473 retval = 0;
69474@@ -470,14 +521,6 @@ out:
69475 flush_tlb_mm(oldmm);
69476 up_write(&oldmm->mmap_sem);
69477 return retval;
69478-fail_nomem_anon_vma_fork:
69479- mpol_put(pol);
69480-fail_nomem_policy:
69481- kmem_cache_free(vm_area_cachep, tmp);
69482-fail_nomem:
69483- retval = -ENOMEM;
69484- vm_unacct_memory(charge);
69485- goto out;
69486 }
69487
69488 static inline int mm_alloc_pgd(struct mm_struct *mm)
69489@@ -692,8 +735,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
69490 return ERR_PTR(err);
69491
69492 mm = get_task_mm(task);
69493- if (mm && mm != current->mm &&
69494- !ptrace_may_access(task, mode)) {
69495+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
69496+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
69497 mmput(mm);
69498 mm = ERR_PTR(-EACCES);
69499 }
69500@@ -912,13 +955,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
69501 spin_unlock(&fs->lock);
69502 return -EAGAIN;
69503 }
69504- fs->users++;
69505+ atomic_inc(&fs->users);
69506 spin_unlock(&fs->lock);
69507 return 0;
69508 }
69509 tsk->fs = copy_fs_struct(fs);
69510 if (!tsk->fs)
69511 return -ENOMEM;
69512+ /* Carry through gr_chroot_dentry and is_chrooted instead
69513+ of recomputing it here. Already copied when the task struct
69514+ is duplicated. This allows pivot_root to not be treated as
69515+ a chroot
69516+ */
69517+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
69518+
69519 return 0;
69520 }
69521
69522@@ -1183,6 +1233,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
69523 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
69524 #endif
69525 retval = -EAGAIN;
69526+
69527+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
69528+
69529 if (atomic_read(&p->real_cred->user->processes) >=
69530 task_rlimit(p, RLIMIT_NPROC)) {
69531 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
69532@@ -1422,6 +1475,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
69533 goto bad_fork_free_pid;
69534 }
69535
69536+ /* synchronizes with gr_set_acls()
69537+ we need to call this past the point of no return for fork()
69538+ */
69539+ gr_copy_label(p);
69540+
69541 if (clone_flags & CLONE_THREAD) {
69542 current->signal->nr_threads++;
69543 atomic_inc(&current->signal->live);
69544@@ -1505,6 +1563,8 @@ bad_fork_cleanup_count:
69545 bad_fork_free:
69546 free_task(p);
69547 fork_out:
69548+ gr_log_forkfail(retval);
69549+
69550 return ERR_PTR(retval);
69551 }
69552
69553@@ -1605,6 +1665,8 @@ long do_fork(unsigned long clone_flags,
69554 if (clone_flags & CLONE_PARENT_SETTID)
69555 put_user(nr, parent_tidptr);
69556
69557+ gr_handle_brute_check();
69558+
69559 if (clone_flags & CLONE_VFORK) {
69560 p->vfork_done = &vfork;
69561 init_completion(&vfork);
69562@@ -1714,7 +1776,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
69563 return 0;
69564
69565 /* don't need lock here; in the worst case we'll do useless copy */
69566- if (fs->users == 1)
69567+ if (atomic_read(&fs->users) == 1)
69568 return 0;
69569
69570 *new_fsp = copy_fs_struct(fs);
69571@@ -1803,7 +1865,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
69572 fs = current->fs;
69573 spin_lock(&fs->lock);
69574 current->fs = new_fs;
69575- if (--fs->users)
69576+ gr_set_chroot_entries(current, &current->fs->root);
69577+ if (atomic_dec_return(&fs->users))
69578 new_fs = NULL;
69579 else
69580 new_fs = fs;
69581diff --git a/kernel/futex.c b/kernel/futex.c
69582index 19eb089..b8c65ea 100644
69583--- a/kernel/futex.c
69584+++ b/kernel/futex.c
69585@@ -54,6 +54,7 @@
69586 #include <linux/mount.h>
69587 #include <linux/pagemap.h>
69588 #include <linux/syscalls.h>
69589+#include <linux/ptrace.h>
69590 #include <linux/signal.h>
69591 #include <linux/export.h>
69592 #include <linux/magic.h>
69593@@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
69594 struct page *page, *page_head;
69595 int err, ro = 0;
69596
69597+#ifdef CONFIG_PAX_SEGMEXEC
69598+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
69599+ return -EFAULT;
69600+#endif
69601+
69602 /*
69603 * The futex address must be "naturally" aligned.
69604 */
69605@@ -2733,6 +2739,7 @@ static int __init futex_init(void)
69606 {
69607 u32 curval;
69608 int i;
69609+ mm_segment_t oldfs;
69610
69611 /*
69612 * This will fail and we want it. Some arch implementations do
69613@@ -2744,8 +2751,11 @@ static int __init futex_init(void)
69614 * implementation, the non-functional ones will return
69615 * -ENOSYS.
69616 */
69617+ oldfs = get_fs();
69618+ set_fs(USER_DS);
69619 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
69620 futex_cmpxchg_enabled = 1;
69621+ set_fs(oldfs);
69622
69623 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
69624 plist_head_init(&futex_queues[i].chain);
69625diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
69626index 9b22d03..6295b62 100644
69627--- a/kernel/gcov/base.c
69628+++ b/kernel/gcov/base.c
69629@@ -102,11 +102,6 @@ void gcov_enable_events(void)
69630 }
69631
69632 #ifdef CONFIG_MODULES
69633-static inline int within(void *addr, void *start, unsigned long size)
69634-{
69635- return ((addr >= start) && (addr < start + size));
69636-}
69637-
69638 /* Update list and generate events when modules are unloaded. */
69639 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
69640 void *data)
69641@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
69642 prev = NULL;
69643 /* Remove entries located in module from linked list. */
69644 for (info = gcov_info_head; info; info = info->next) {
69645- if (within(info, mod->module_core, mod->core_size)) {
69646+ if (within_module_core_rw((unsigned long)info, mod)) {
69647 if (prev)
69648 prev->next = info->next;
69649 else
69650diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
69651index 6db7a5e..25b6648 100644
69652--- a/kernel/hrtimer.c
69653+++ b/kernel/hrtimer.c
69654@@ -1407,7 +1407,7 @@ void hrtimer_peek_ahead_timers(void)
69655 local_irq_restore(flags);
69656 }
69657
69658-static void run_hrtimer_softirq(struct softirq_action *h)
69659+static void run_hrtimer_softirq(void)
69660 {
69661 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
69662
69663diff --git a/kernel/jump_label.c b/kernel/jump_label.c
69664index 60f48fa..7f3a770 100644
69665--- a/kernel/jump_label.c
69666+++ b/kernel/jump_label.c
69667@@ -13,6 +13,7 @@
69668 #include <linux/sort.h>
69669 #include <linux/err.h>
69670 #include <linux/static_key.h>
69671+#include <linux/mm.h>
69672
69673 #ifdef HAVE_JUMP_LABEL
69674
69675@@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
69676
69677 size = (((unsigned long)stop - (unsigned long)start)
69678 / sizeof(struct jump_entry));
69679+ pax_open_kernel();
69680 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
69681+ pax_close_kernel();
69682 }
69683
69684 static void jump_label_update(struct static_key *key, int enable);
69685@@ -357,10 +360,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
69686 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
69687 struct jump_entry *iter;
69688
69689+ pax_open_kernel();
69690 for (iter = iter_start; iter < iter_stop; iter++) {
69691 if (within_module_init(iter->code, mod))
69692 iter->code = 0;
69693 }
69694+ pax_close_kernel();
69695 }
69696
69697 static int
69698diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
69699index 2169fee..45c017a 100644
69700--- a/kernel/kallsyms.c
69701+++ b/kernel/kallsyms.c
69702@@ -11,6 +11,9 @@
69703 * Changed the compression method from stem compression to "table lookup"
69704 * compression (see scripts/kallsyms.c for a more complete description)
69705 */
69706+#ifdef CONFIG_GRKERNSEC_HIDESYM
69707+#define __INCLUDED_BY_HIDESYM 1
69708+#endif
69709 #include <linux/kallsyms.h>
69710 #include <linux/module.h>
69711 #include <linux/init.h>
69712@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
69713
69714 static inline int is_kernel_inittext(unsigned long addr)
69715 {
69716+ if (system_state != SYSTEM_BOOTING)
69717+ return 0;
69718+
69719 if (addr >= (unsigned long)_sinittext
69720 && addr <= (unsigned long)_einittext)
69721 return 1;
69722 return 0;
69723 }
69724
69725+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
69726+#ifdef CONFIG_MODULES
69727+static inline int is_module_text(unsigned long addr)
69728+{
69729+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
69730+ return 1;
69731+
69732+ addr = ktla_ktva(addr);
69733+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
69734+}
69735+#else
69736+static inline int is_module_text(unsigned long addr)
69737+{
69738+ return 0;
69739+}
69740+#endif
69741+#endif
69742+
69743 static inline int is_kernel_text(unsigned long addr)
69744 {
69745 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
69746@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
69747
69748 static inline int is_kernel(unsigned long addr)
69749 {
69750+
69751+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
69752+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
69753+ return 1;
69754+
69755+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
69756+#else
69757 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
69758+#endif
69759+
69760 return 1;
69761 return in_gate_area_no_mm(addr);
69762 }
69763
69764 static int is_ksym_addr(unsigned long addr)
69765 {
69766+
69767+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
69768+ if (is_module_text(addr))
69769+ return 0;
69770+#endif
69771+
69772 if (all_var)
69773 return is_kernel(addr);
69774
69775@@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
69776
69777 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
69778 {
69779- iter->name[0] = '\0';
69780 iter->nameoff = get_symbol_offset(new_pos);
69781 iter->pos = new_pos;
69782 }
69783@@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
69784 {
69785 struct kallsym_iter *iter = m->private;
69786
69787+#ifdef CONFIG_GRKERNSEC_HIDESYM
69788+ if (current_uid())
69789+ return 0;
69790+#endif
69791+
69792 /* Some debugging symbols have no name. Ignore them. */
69793 if (!iter->name[0])
69794 return 0;
69795@@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
69796 */
69797 type = iter->exported ? toupper(iter->type) :
69798 tolower(iter->type);
69799+
69800 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
69801 type, iter->name, iter->module_name);
69802 } else
69803@@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
69804 struct kallsym_iter *iter;
69805 int ret;
69806
69807- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
69808+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
69809 if (!iter)
69810 return -ENOMEM;
69811 reset_iter(iter, 0);
69812diff --git a/kernel/kcmp.c b/kernel/kcmp.c
69813index 30b7b22..c726387 100644
69814--- a/kernel/kcmp.c
69815+++ b/kernel/kcmp.c
69816@@ -98,6 +98,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
69817 struct task_struct *task1, *task2;
69818 int ret;
69819
69820+#ifdef CONFIG_GRKERNSEC
69821+ return -ENOSYS;
69822+#endif
69823+
69824 rcu_read_lock();
69825
69826 /*
69827diff --git a/kernel/kexec.c b/kernel/kexec.c
69828index 5e4bd78..00c5b91 100644
69829--- a/kernel/kexec.c
69830+++ b/kernel/kexec.c
69831@@ -1045,7 +1045,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
69832 unsigned long flags)
69833 {
69834 struct compat_kexec_segment in;
69835- struct kexec_segment out, __user *ksegments;
69836+ struct kexec_segment out;
69837+ struct kexec_segment __user *ksegments;
69838 unsigned long i, result;
69839
69840 /* Don't allow clients that don't understand the native
69841diff --git a/kernel/kmod.c b/kernel/kmod.c
69842index 1c317e3..4a92a55 100644
69843--- a/kernel/kmod.c
69844+++ b/kernel/kmod.c
69845@@ -74,7 +74,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
69846 kfree(info->argv);
69847 }
69848
69849-static int call_modprobe(char *module_name, int wait)
69850+static int call_modprobe(char *module_name, char *module_param, int wait)
69851 {
69852 static char *envp[] = {
69853 "HOME=/",
69854@@ -83,7 +83,7 @@ static int call_modprobe(char *module_name, int wait)
69855 NULL
69856 };
69857
69858- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
69859+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
69860 if (!argv)
69861 goto out;
69862
69863@@ -95,7 +95,8 @@ static int call_modprobe(char *module_name, int wait)
69864 argv[1] = "-q";
69865 argv[2] = "--";
69866 argv[3] = module_name; /* check free_modprobe_argv() */
69867- argv[4] = NULL;
69868+ argv[4] = module_param;
69869+ argv[5] = NULL;
69870
69871 return call_usermodehelper_fns(modprobe_path, argv, envp,
69872 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
69873@@ -120,9 +121,8 @@ out:
69874 * If module auto-loading support is disabled then this function
69875 * becomes a no-operation.
69876 */
69877-int __request_module(bool wait, const char *fmt, ...)
69878+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
69879 {
69880- va_list args;
69881 char module_name[MODULE_NAME_LEN];
69882 unsigned int max_modprobes;
69883 int ret;
69884@@ -130,9 +130,7 @@ int __request_module(bool wait, const char *fmt, ...)
69885 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
69886 static int kmod_loop_msg;
69887
69888- va_start(args, fmt);
69889- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
69890- va_end(args);
69891+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
69892 if (ret >= MODULE_NAME_LEN)
69893 return -ENAMETOOLONG;
69894
69895@@ -140,6 +138,20 @@ int __request_module(bool wait, const char *fmt, ...)
69896 if (ret)
69897 return ret;
69898
69899+#ifdef CONFIG_GRKERNSEC_MODHARDEN
69900+ if (!current_uid()) {
69901+ /* hack to workaround consolekit/udisks stupidity */
69902+ read_lock(&tasklist_lock);
69903+ if (!strcmp(current->comm, "mount") &&
69904+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
69905+ read_unlock(&tasklist_lock);
69906+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
69907+ return -EPERM;
69908+ }
69909+ read_unlock(&tasklist_lock);
69910+ }
69911+#endif
69912+
69913 /* If modprobe needs a service that is in a module, we get a recursive
69914 * loop. Limit the number of running kmod threads to max_threads/2 or
69915 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
69916@@ -168,11 +180,52 @@ int __request_module(bool wait, const char *fmt, ...)
69917
69918 trace_module_request(module_name, wait, _RET_IP_);
69919
69920- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
69921+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
69922
69923 atomic_dec(&kmod_concurrent);
69924 return ret;
69925 }
69926+
69927+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
69928+{
69929+ va_list args;
69930+ int ret;
69931+
69932+ va_start(args, fmt);
69933+ ret = ____request_module(wait, module_param, fmt, args);
69934+ va_end(args);
69935+
69936+ return ret;
69937+}
69938+
69939+int __request_module(bool wait, const char *fmt, ...)
69940+{
69941+ va_list args;
69942+ int ret;
69943+
69944+#ifdef CONFIG_GRKERNSEC_MODHARDEN
69945+ if (current_uid()) {
69946+ char module_param[MODULE_NAME_LEN];
69947+
69948+ memset(module_param, 0, sizeof(module_param));
69949+
69950+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
69951+
69952+ va_start(args, fmt);
69953+ ret = ____request_module(wait, module_param, fmt, args);
69954+ va_end(args);
69955+
69956+ return ret;
69957+ }
69958+#endif
69959+
69960+ va_start(args, fmt);
69961+ ret = ____request_module(wait, NULL, fmt, args);
69962+ va_end(args);
69963+
69964+ return ret;
69965+}
69966+
69967 EXPORT_SYMBOL(__request_module);
69968 #endif /* CONFIG_MODULES */
69969
69970@@ -283,7 +336,7 @@ static int wait_for_helper(void *data)
69971 *
69972 * Thus the __user pointer cast is valid here.
69973 */
69974- sys_wait4(pid, (int __user *)&ret, 0, NULL);
69975+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
69976
69977 /*
69978 * If ret is 0, either ____call_usermodehelper failed and the
69979diff --git a/kernel/kprobes.c b/kernel/kprobes.c
69980index 098f396..fe85ff1 100644
69981--- a/kernel/kprobes.c
69982+++ b/kernel/kprobes.c
69983@@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
69984 * kernel image and loaded module images reside. This is required
69985 * so x86_64 can correctly handle the %rip-relative fixups.
69986 */
69987- kip->insns = module_alloc(PAGE_SIZE);
69988+ kip->insns = module_alloc_exec(PAGE_SIZE);
69989 if (!kip->insns) {
69990 kfree(kip);
69991 return NULL;
69992@@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
69993 */
69994 if (!list_is_singular(&kip->list)) {
69995 list_del(&kip->list);
69996- module_free(NULL, kip->insns);
69997+ module_free_exec(NULL, kip->insns);
69998 kfree(kip);
69999 }
70000 return 1;
70001@@ -2063,7 +2063,7 @@ static int __init init_kprobes(void)
70002 {
70003 int i, err = 0;
70004 unsigned long offset = 0, size = 0;
70005- char *modname, namebuf[128];
70006+ char *modname, namebuf[KSYM_NAME_LEN];
70007 const char *symbol_name;
70008 void *addr;
70009 struct kprobe_blackpoint *kb;
70010@@ -2148,11 +2148,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
70011 kprobe_type = "k";
70012
70013 if (sym)
70014- seq_printf(pi, "%p %s %s+0x%x %s ",
70015+ seq_printf(pi, "%pK %s %s+0x%x %s ",
70016 p->addr, kprobe_type, sym, offset,
70017 (modname ? modname : " "));
70018 else
70019- seq_printf(pi, "%p %s %p ",
70020+ seq_printf(pi, "%pK %s %pK ",
70021 p->addr, kprobe_type, p->addr);
70022
70023 if (!pp)
70024@@ -2190,7 +2190,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
70025 const char *sym = NULL;
70026 unsigned int i = *(loff_t *) v;
70027 unsigned long offset = 0;
70028- char *modname, namebuf[128];
70029+ char *modname, namebuf[KSYM_NAME_LEN];
70030
70031 head = &kprobe_table[i];
70032 preempt_disable();
70033diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
70034index 4e316e1..5501eef 100644
70035--- a/kernel/ksysfs.c
70036+++ b/kernel/ksysfs.c
70037@@ -47,6 +47,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
70038 {
70039 if (count+1 > UEVENT_HELPER_PATH_LEN)
70040 return -ENOENT;
70041+ if (!capable(CAP_SYS_ADMIN))
70042+ return -EPERM;
70043 memcpy(uevent_helper, buf, count);
70044 uevent_helper[count] = '\0';
70045 if (count && uevent_helper[count-1] == '\n')
70046diff --git a/kernel/lockdep.c b/kernel/lockdep.c
70047index 7981e5b..7f2105c 100644
70048--- a/kernel/lockdep.c
70049+++ b/kernel/lockdep.c
70050@@ -590,6 +590,10 @@ static int static_obj(void *obj)
70051 end = (unsigned long) &_end,
70052 addr = (unsigned long) obj;
70053
70054+#ifdef CONFIG_PAX_KERNEXEC
70055+ start = ktla_ktva(start);
70056+#endif
70057+
70058 /*
70059 * static variable?
70060 */
70061@@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
70062 if (!static_obj(lock->key)) {
70063 debug_locks_off();
70064 printk("INFO: trying to register non-static key.\n");
70065+ printk("lock:%pS key:%pS.\n", lock, lock->key);
70066 printk("the code is fine but needs lockdep annotation.\n");
70067 printk("turning off the locking correctness validator.\n");
70068 dump_stack();
70069@@ -3078,7 +3083,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
70070 if (!class)
70071 return 0;
70072 }
70073- atomic_inc((atomic_t *)&class->ops);
70074+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
70075 if (very_verbose(class)) {
70076 printk("\nacquire class [%p] %s", class->key, class->name);
70077 if (class->name_version > 1)
70078diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
70079index 91c32a0..7b88d63 100644
70080--- a/kernel/lockdep_proc.c
70081+++ b/kernel/lockdep_proc.c
70082@@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
70083
70084 static void print_name(struct seq_file *m, struct lock_class *class)
70085 {
70086- char str[128];
70087+ char str[KSYM_NAME_LEN];
70088 const char *name = class->name;
70089
70090 if (!name) {
70091@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
70092 return 0;
70093 }
70094
70095- seq_printf(m, "%p", class->key);
70096+ seq_printf(m, "%pK", class->key);
70097 #ifdef CONFIG_DEBUG_LOCKDEP
70098 seq_printf(m, " OPS:%8ld", class->ops);
70099 #endif
70100@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
70101
70102 list_for_each_entry(entry, &class->locks_after, entry) {
70103 if (entry->distance == 1) {
70104- seq_printf(m, " -> [%p] ", entry->class->key);
70105+ seq_printf(m, " -> [%pK] ", entry->class->key);
70106 print_name(m, entry->class);
70107 seq_puts(m, "\n");
70108 }
70109@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
70110 if (!class->key)
70111 continue;
70112
70113- seq_printf(m, "[%p] ", class->key);
70114+ seq_printf(m, "[%pK] ", class->key);
70115 print_name(m, class);
70116 seq_puts(m, "\n");
70117 }
70118@@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
70119 if (!i)
70120 seq_line(m, '-', 40-namelen, namelen);
70121
70122- snprintf(ip, sizeof(ip), "[<%p>]",
70123+ snprintf(ip, sizeof(ip), "[<%pK>]",
70124 (void *)class->contention_point[i]);
70125 seq_printf(m, "%40s %14lu %29s %pS\n",
70126 name, stats->contention_point[i],
70127@@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
70128 if (!i)
70129 seq_line(m, '-', 40-namelen, namelen);
70130
70131- snprintf(ip, sizeof(ip), "[<%p>]",
70132+ snprintf(ip, sizeof(ip), "[<%pK>]",
70133 (void *)class->contending_point[i]);
70134 seq_printf(m, "%40s %14lu %29s %pS\n",
70135 name, stats->contending_point[i],
70136diff --git a/kernel/module.c b/kernel/module.c
70137index 3e544f4..34c3008 100644
70138--- a/kernel/module.c
70139+++ b/kernel/module.c
70140@@ -59,6 +59,7 @@
70141 #include <linux/pfn.h>
70142 #include <linux/bsearch.h>
70143 #include <linux/fips.h>
70144+#include <linux/grsecurity.h>
70145 #include "module-internal.h"
70146
70147 #define CREATE_TRACE_POINTS
70148@@ -153,7 +154,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
70149
70150 /* Bounds of module allocation, for speeding __module_address.
70151 * Protected by module_mutex. */
70152-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
70153+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
70154+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
70155
70156 int register_module_notifier(struct notifier_block * nb)
70157 {
70158@@ -319,7 +321,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
70159 return true;
70160
70161 list_for_each_entry_rcu(mod, &modules, list) {
70162- struct symsearch arr[] = {
70163+ struct symsearch modarr[] = {
70164 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
70165 NOT_GPL_ONLY, false },
70166 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
70167@@ -344,7 +346,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
70168 if (mod->state == MODULE_STATE_UNFORMED)
70169 continue;
70170
70171- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
70172+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
70173 return true;
70174 }
70175 return false;
70176@@ -484,7 +486,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
70177 static int percpu_modalloc(struct module *mod,
70178 unsigned long size, unsigned long align)
70179 {
70180- if (align > PAGE_SIZE) {
70181+ if (align-1 >= PAGE_SIZE) {
70182 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
70183 mod->name, align, PAGE_SIZE);
70184 align = PAGE_SIZE;
70185@@ -1088,7 +1090,7 @@ struct module_attribute module_uevent =
70186 static ssize_t show_coresize(struct module_attribute *mattr,
70187 struct module_kobject *mk, char *buffer)
70188 {
70189- return sprintf(buffer, "%u\n", mk->mod->core_size);
70190+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
70191 }
70192
70193 static struct module_attribute modinfo_coresize =
70194@@ -1097,7 +1099,7 @@ static struct module_attribute modinfo_coresize =
70195 static ssize_t show_initsize(struct module_attribute *mattr,
70196 struct module_kobject *mk, char *buffer)
70197 {
70198- return sprintf(buffer, "%u\n", mk->mod->init_size);
70199+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
70200 }
70201
70202 static struct module_attribute modinfo_initsize =
70203@@ -1311,7 +1313,7 @@ resolve_symbol_wait(struct module *mod,
70204 */
70205 #ifdef CONFIG_SYSFS
70206
70207-#ifdef CONFIG_KALLSYMS
70208+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
70209 static inline bool sect_empty(const Elf_Shdr *sect)
70210 {
70211 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
70212@@ -1777,21 +1779,21 @@ static void set_section_ro_nx(void *base,
70213
70214 static void unset_module_core_ro_nx(struct module *mod)
70215 {
70216- set_page_attributes(mod->module_core + mod->core_text_size,
70217- mod->module_core + mod->core_size,
70218+ set_page_attributes(mod->module_core_rw,
70219+ mod->module_core_rw + mod->core_size_rw,
70220 set_memory_x);
70221- set_page_attributes(mod->module_core,
70222- mod->module_core + mod->core_ro_size,
70223+ set_page_attributes(mod->module_core_rx,
70224+ mod->module_core_rx + mod->core_size_rx,
70225 set_memory_rw);
70226 }
70227
70228 static void unset_module_init_ro_nx(struct module *mod)
70229 {
70230- set_page_attributes(mod->module_init + mod->init_text_size,
70231- mod->module_init + mod->init_size,
70232+ set_page_attributes(mod->module_init_rw,
70233+ mod->module_init_rw + mod->init_size_rw,
70234 set_memory_x);
70235- set_page_attributes(mod->module_init,
70236- mod->module_init + mod->init_ro_size,
70237+ set_page_attributes(mod->module_init_rx,
70238+ mod->module_init_rx + mod->init_size_rx,
70239 set_memory_rw);
70240 }
70241
70242@@ -1804,14 +1806,14 @@ void set_all_modules_text_rw(void)
70243 list_for_each_entry_rcu(mod, &modules, list) {
70244 if (mod->state == MODULE_STATE_UNFORMED)
70245 continue;
70246- if ((mod->module_core) && (mod->core_text_size)) {
70247- set_page_attributes(mod->module_core,
70248- mod->module_core + mod->core_text_size,
70249+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
70250+ set_page_attributes(mod->module_core_rx,
70251+ mod->module_core_rx + mod->core_size_rx,
70252 set_memory_rw);
70253 }
70254- if ((mod->module_init) && (mod->init_text_size)) {
70255- set_page_attributes(mod->module_init,
70256- mod->module_init + mod->init_text_size,
70257+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
70258+ set_page_attributes(mod->module_init_rx,
70259+ mod->module_init_rx + mod->init_size_rx,
70260 set_memory_rw);
70261 }
70262 }
70263@@ -1827,14 +1829,14 @@ void set_all_modules_text_ro(void)
70264 list_for_each_entry_rcu(mod, &modules, list) {
70265 if (mod->state == MODULE_STATE_UNFORMED)
70266 continue;
70267- if ((mod->module_core) && (mod->core_text_size)) {
70268- set_page_attributes(mod->module_core,
70269- mod->module_core + mod->core_text_size,
70270+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
70271+ set_page_attributes(mod->module_core_rx,
70272+ mod->module_core_rx + mod->core_size_rx,
70273 set_memory_ro);
70274 }
70275- if ((mod->module_init) && (mod->init_text_size)) {
70276- set_page_attributes(mod->module_init,
70277- mod->module_init + mod->init_text_size,
70278+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
70279+ set_page_attributes(mod->module_init_rx,
70280+ mod->module_init_rx + mod->init_size_rx,
70281 set_memory_ro);
70282 }
70283 }
70284@@ -1880,16 +1882,19 @@ static void free_module(struct module *mod)
70285
70286 /* This may be NULL, but that's OK */
70287 unset_module_init_ro_nx(mod);
70288- module_free(mod, mod->module_init);
70289+ module_free(mod, mod->module_init_rw);
70290+ module_free_exec(mod, mod->module_init_rx);
70291 kfree(mod->args);
70292 percpu_modfree(mod);
70293
70294 /* Free lock-classes: */
70295- lockdep_free_key_range(mod->module_core, mod->core_size);
70296+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
70297+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
70298
70299 /* Finally, free the core (containing the module structure) */
70300 unset_module_core_ro_nx(mod);
70301- module_free(mod, mod->module_core);
70302+ module_free_exec(mod, mod->module_core_rx);
70303+ module_free(mod, mod->module_core_rw);
70304
70305 #ifdef CONFIG_MPU
70306 update_protections(current->mm);
70307@@ -1959,9 +1964,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
70308 int ret = 0;
70309 const struct kernel_symbol *ksym;
70310
70311+#ifdef CONFIG_GRKERNSEC_MODHARDEN
70312+ int is_fs_load = 0;
70313+ int register_filesystem_found = 0;
70314+ char *p;
70315+
70316+ p = strstr(mod->args, "grsec_modharden_fs");
70317+ if (p) {
70318+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
70319+ /* copy \0 as well */
70320+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
70321+ is_fs_load = 1;
70322+ }
70323+#endif
70324+
70325 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
70326 const char *name = info->strtab + sym[i].st_name;
70327
70328+#ifdef CONFIG_GRKERNSEC_MODHARDEN
70329+ /* it's a real shame this will never get ripped and copied
70330+ upstream! ;(
70331+ */
70332+ if (is_fs_load && !strcmp(name, "register_filesystem"))
70333+ register_filesystem_found = 1;
70334+#endif
70335+
70336 switch (sym[i].st_shndx) {
70337 case SHN_COMMON:
70338 /* We compiled with -fno-common. These are not
70339@@ -1982,7 +2009,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
70340 ksym = resolve_symbol_wait(mod, info, name);
70341 /* Ok if resolved. */
70342 if (ksym && !IS_ERR(ksym)) {
70343+ pax_open_kernel();
70344 sym[i].st_value = ksym->value;
70345+ pax_close_kernel();
70346 break;
70347 }
70348
70349@@ -2001,11 +2030,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
70350 secbase = (unsigned long)mod_percpu(mod);
70351 else
70352 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
70353+ pax_open_kernel();
70354 sym[i].st_value += secbase;
70355+ pax_close_kernel();
70356 break;
70357 }
70358 }
70359
70360+#ifdef CONFIG_GRKERNSEC_MODHARDEN
70361+ if (is_fs_load && !register_filesystem_found) {
70362+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
70363+ ret = -EPERM;
70364+ }
70365+#endif
70366+
70367 return ret;
70368 }
70369
70370@@ -2089,22 +2127,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
70371 || s->sh_entsize != ~0UL
70372 || strstarts(sname, ".init"))
70373 continue;
70374- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
70375+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
70376+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
70377+ else
70378+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
70379 pr_debug("\t%s\n", sname);
70380 }
70381- switch (m) {
70382- case 0: /* executable */
70383- mod->core_size = debug_align(mod->core_size);
70384- mod->core_text_size = mod->core_size;
70385- break;
70386- case 1: /* RO: text and ro-data */
70387- mod->core_size = debug_align(mod->core_size);
70388- mod->core_ro_size = mod->core_size;
70389- break;
70390- case 3: /* whole core */
70391- mod->core_size = debug_align(mod->core_size);
70392- break;
70393- }
70394 }
70395
70396 pr_debug("Init section allocation order:\n");
70397@@ -2118,23 +2146,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
70398 || s->sh_entsize != ~0UL
70399 || !strstarts(sname, ".init"))
70400 continue;
70401- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
70402- | INIT_OFFSET_MASK);
70403+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
70404+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
70405+ else
70406+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
70407+ s->sh_entsize |= INIT_OFFSET_MASK;
70408 pr_debug("\t%s\n", sname);
70409 }
70410- switch (m) {
70411- case 0: /* executable */
70412- mod->init_size = debug_align(mod->init_size);
70413- mod->init_text_size = mod->init_size;
70414- break;
70415- case 1: /* RO: text and ro-data */
70416- mod->init_size = debug_align(mod->init_size);
70417- mod->init_ro_size = mod->init_size;
70418- break;
70419- case 3: /* whole init */
70420- mod->init_size = debug_align(mod->init_size);
70421- break;
70422- }
70423 }
70424 }
70425
70426@@ -2306,7 +2324,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
70427
70428 /* Put symbol section at end of init part of module. */
70429 symsect->sh_flags |= SHF_ALLOC;
70430- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
70431+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
70432 info->index.sym) | INIT_OFFSET_MASK;
70433 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
70434
70435@@ -2326,13 +2344,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
70436 }
70437
70438 /* Append room for core symbols at end of core part. */
70439- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
70440- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
70441- mod->core_size += strtab_size;
70442+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
70443+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
70444+ mod->core_size_rx += strtab_size;
70445
70446 /* Put string table section at end of init part of module. */
70447 strsect->sh_flags |= SHF_ALLOC;
70448- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
70449+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
70450 info->index.str) | INIT_OFFSET_MASK;
70451 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
70452 }
70453@@ -2350,12 +2368,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
70454 /* Make sure we get permanent strtab: don't use info->strtab. */
70455 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
70456
70457+ pax_open_kernel();
70458+
70459 /* Set types up while we still have access to sections. */
70460 for (i = 0; i < mod->num_symtab; i++)
70461 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
70462
70463- mod->core_symtab = dst = mod->module_core + info->symoffs;
70464- mod->core_strtab = s = mod->module_core + info->stroffs;
70465+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
70466+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
70467 src = mod->symtab;
70468 *s++ = 0;
70469 for (ndst = i = 0; i < mod->num_symtab; i++) {
70470@@ -2368,6 +2388,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
70471 }
70472 }
70473 mod->core_num_syms = ndst;
70474+
70475+ pax_close_kernel();
70476 }
70477 #else
70478 static inline void layout_symtab(struct module *mod, struct load_info *info)
70479@@ -2401,17 +2423,33 @@ void * __weak module_alloc(unsigned long size)
70480 return size == 0 ? NULL : vmalloc_exec(size);
70481 }
70482
70483-static void *module_alloc_update_bounds(unsigned long size)
70484+static void *module_alloc_update_bounds_rw(unsigned long size)
70485 {
70486 void *ret = module_alloc(size);
70487
70488 if (ret) {
70489 mutex_lock(&module_mutex);
70490 /* Update module bounds. */
70491- if ((unsigned long)ret < module_addr_min)
70492- module_addr_min = (unsigned long)ret;
70493- if ((unsigned long)ret + size > module_addr_max)
70494- module_addr_max = (unsigned long)ret + size;
70495+ if ((unsigned long)ret < module_addr_min_rw)
70496+ module_addr_min_rw = (unsigned long)ret;
70497+ if ((unsigned long)ret + size > module_addr_max_rw)
70498+ module_addr_max_rw = (unsigned long)ret + size;
70499+ mutex_unlock(&module_mutex);
70500+ }
70501+ return ret;
70502+}
70503+
70504+static void *module_alloc_update_bounds_rx(unsigned long size)
70505+{
70506+ void *ret = module_alloc_exec(size);
70507+
70508+ if (ret) {
70509+ mutex_lock(&module_mutex);
70510+ /* Update module bounds. */
70511+ if ((unsigned long)ret < module_addr_min_rx)
70512+ module_addr_min_rx = (unsigned long)ret;
70513+ if ((unsigned long)ret + size > module_addr_max_rx)
70514+ module_addr_max_rx = (unsigned long)ret + size;
70515 mutex_unlock(&module_mutex);
70516 }
70517 return ret;
70518@@ -2630,8 +2668,14 @@ static struct module *setup_load_info(struct load_info *info)
70519 static int check_modinfo(struct module *mod, struct load_info *info)
70520 {
70521 const char *modmagic = get_modinfo(info, "vermagic");
70522+ const char *license = get_modinfo(info, "license");
70523 int err;
70524
70525+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
70526+ if (!license || !license_is_gpl_compatible(license))
70527+ return -ENOEXEC;
70528+#endif
70529+
70530 /* This is allowed: modprobe --force will invalidate it. */
70531 if (!modmagic) {
70532 err = try_to_force_load(mod, "bad vermagic");
70533@@ -2654,7 +2698,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
70534 }
70535
70536 /* Set up license info based on the info section */
70537- set_license(mod, get_modinfo(info, "license"));
70538+ set_license(mod, license);
70539
70540 return 0;
70541 }
70542@@ -2748,7 +2792,7 @@ static int move_module(struct module *mod, struct load_info *info)
70543 void *ptr;
70544
70545 /* Do the allocs. */
70546- ptr = module_alloc_update_bounds(mod->core_size);
70547+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
70548 /*
70549 * The pointer to this block is stored in the module structure
70550 * which is inside the block. Just mark it as not being a
70551@@ -2758,10 +2802,10 @@ static int move_module(struct module *mod, struct load_info *info)
70552 if (!ptr)
70553 return -ENOMEM;
70554
70555- memset(ptr, 0, mod->core_size);
70556- mod->module_core = ptr;
70557+ memset(ptr, 0, mod->core_size_rw);
70558+ mod->module_core_rw = ptr;
70559
70560- ptr = module_alloc_update_bounds(mod->init_size);
70561+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
70562 /*
70563 * The pointer to this block is stored in the module structure
70564 * which is inside the block. This block doesn't need to be
70565@@ -2769,12 +2813,39 @@ static int move_module(struct module *mod, struct load_info *info)
70566 * after the module is initialized.
70567 */
70568 kmemleak_ignore(ptr);
70569- if (!ptr && mod->init_size) {
70570- module_free(mod, mod->module_core);
70571+ if (!ptr && mod->init_size_rw) {
70572+ module_free(mod, mod->module_core_rw);
70573 return -ENOMEM;
70574 }
70575- memset(ptr, 0, mod->init_size);
70576- mod->module_init = ptr;
70577+ memset(ptr, 0, mod->init_size_rw);
70578+ mod->module_init_rw = ptr;
70579+
70580+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
70581+ kmemleak_not_leak(ptr);
70582+ if (!ptr) {
70583+ module_free(mod, mod->module_init_rw);
70584+ module_free(mod, mod->module_core_rw);
70585+ return -ENOMEM;
70586+ }
70587+
70588+ pax_open_kernel();
70589+ memset(ptr, 0, mod->core_size_rx);
70590+ pax_close_kernel();
70591+ mod->module_core_rx = ptr;
70592+
70593+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
70594+ kmemleak_ignore(ptr);
70595+ if (!ptr && mod->init_size_rx) {
70596+ module_free_exec(mod, mod->module_core_rx);
70597+ module_free(mod, mod->module_init_rw);
70598+ module_free(mod, mod->module_core_rw);
70599+ return -ENOMEM;
70600+ }
70601+
70602+ pax_open_kernel();
70603+ memset(ptr, 0, mod->init_size_rx);
70604+ pax_close_kernel();
70605+ mod->module_init_rx = ptr;
70606
70607 /* Transfer each section which specifies SHF_ALLOC */
70608 pr_debug("final section addresses:\n");
70609@@ -2785,16 +2856,45 @@ static int move_module(struct module *mod, struct load_info *info)
70610 if (!(shdr->sh_flags & SHF_ALLOC))
70611 continue;
70612
70613- if (shdr->sh_entsize & INIT_OFFSET_MASK)
70614- dest = mod->module_init
70615- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
70616- else
70617- dest = mod->module_core + shdr->sh_entsize;
70618+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
70619+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
70620+ dest = mod->module_init_rw
70621+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
70622+ else
70623+ dest = mod->module_init_rx
70624+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
70625+ } else {
70626+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
70627+ dest = mod->module_core_rw + shdr->sh_entsize;
70628+ else
70629+ dest = mod->module_core_rx + shdr->sh_entsize;
70630+ }
70631+
70632+ if (shdr->sh_type != SHT_NOBITS) {
70633+
70634+#ifdef CONFIG_PAX_KERNEXEC
70635+#ifdef CONFIG_X86_64
70636+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
70637+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
70638+#endif
70639+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
70640+ pax_open_kernel();
70641+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
70642+ pax_close_kernel();
70643+ } else
70644+#endif
70645
70646- if (shdr->sh_type != SHT_NOBITS)
70647 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
70648+ }
70649 /* Update sh_addr to point to copy in image. */
70650- shdr->sh_addr = (unsigned long)dest;
70651+
70652+#ifdef CONFIG_PAX_KERNEXEC
70653+ if (shdr->sh_flags & SHF_EXECINSTR)
70654+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
70655+ else
70656+#endif
70657+
70658+ shdr->sh_addr = (unsigned long)dest;
70659 pr_debug("\t0x%lx %s\n",
70660 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
70661 }
70662@@ -2849,12 +2949,12 @@ static void flush_module_icache(const struct module *mod)
70663 * Do it before processing of module parameters, so the module
70664 * can provide parameter accessor functions of its own.
70665 */
70666- if (mod->module_init)
70667- flush_icache_range((unsigned long)mod->module_init,
70668- (unsigned long)mod->module_init
70669- + mod->init_size);
70670- flush_icache_range((unsigned long)mod->module_core,
70671- (unsigned long)mod->module_core + mod->core_size);
70672+ if (mod->module_init_rx)
70673+ flush_icache_range((unsigned long)mod->module_init_rx,
70674+ (unsigned long)mod->module_init_rx
70675+ + mod->init_size_rx);
70676+ flush_icache_range((unsigned long)mod->module_core_rx,
70677+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
70678
70679 set_fs(old_fs);
70680 }
70681@@ -2924,8 +3024,10 @@ out:
70682 static void module_deallocate(struct module *mod, struct load_info *info)
70683 {
70684 percpu_modfree(mod);
70685- module_free(mod, mod->module_init);
70686- module_free(mod, mod->module_core);
70687+ module_free_exec(mod, mod->module_init_rx);
70688+ module_free_exec(mod, mod->module_core_rx);
70689+ module_free(mod, mod->module_init_rw);
70690+ module_free(mod, mod->module_core_rw);
70691 }
70692
70693 int __weak module_finalize(const Elf_Ehdr *hdr,
70694@@ -2938,7 +3040,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
70695 static int post_relocation(struct module *mod, const struct load_info *info)
70696 {
70697 /* Sort exception table now relocations are done. */
70698+ pax_open_kernel();
70699 sort_extable(mod->extable, mod->extable + mod->num_exentries);
70700+ pax_close_kernel();
70701
70702 /* Copy relocated percpu area over. */
70703 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
70704@@ -3036,9 +3140,38 @@ again:
70705 if (err)
70706 goto free_unload;
70707
70708+ /* Now copy in args */
70709+ mod->args = strndup_user(uargs, ~0UL >> 1);
70710+ if (IS_ERR(mod->args)) {
70711+ err = PTR_ERR(mod->args);
70712+ goto free_unload;
70713+ }
70714+
70715 /* Set up MODINFO_ATTR fields */
70716 setup_modinfo(mod, &info);
70717
70718+#ifdef CONFIG_GRKERNSEC_MODHARDEN
70719+ {
70720+ char *p, *p2;
70721+
70722+ if (strstr(mod->args, "grsec_modharden_netdev")) {
70723+ 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);
70724+ err = -EPERM;
70725+ goto free_modinfo;
70726+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
70727+ p += sizeof("grsec_modharden_normal") - 1;
70728+ p2 = strstr(p, "_");
70729+ if (p2) {
70730+ *p2 = '\0';
70731+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
70732+ *p2 = '_';
70733+ }
70734+ err = -EPERM;
70735+ goto free_modinfo;
70736+ }
70737+ }
70738+#endif
70739+
70740 /* Fix up syms, so that st_value is a pointer to location. */
70741 err = simplify_symbols(mod, &info);
70742 if (err < 0)
70743@@ -3104,11 +3237,11 @@ again:
70744 mutex_unlock(&module_mutex);
70745 dynamic_debug_remove(info.debug);
70746 synchronize_sched();
70747- kfree(mod->args);
70748 free_arch_cleanup:
70749 module_arch_cleanup(mod);
70750 free_modinfo:
70751 free_modinfo(mod);
70752+ kfree(mod->args);
70753 free_unload:
70754 module_unload_free(mod);
70755 unlink_mod:
70756@@ -3155,16 +3288,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
70757 MODULE_STATE_COMING, mod);
70758
70759 /* Set RO and NX regions for core */
70760- set_section_ro_nx(mod->module_core,
70761- mod->core_text_size,
70762- mod->core_ro_size,
70763- mod->core_size);
70764+ set_section_ro_nx(mod->module_core_rx,
70765+ mod->core_size_rx,
70766+ mod->core_size_rx,
70767+ mod->core_size_rx);
70768
70769 /* Set RO and NX regions for init */
70770- set_section_ro_nx(mod->module_init,
70771- mod->init_text_size,
70772- mod->init_ro_size,
70773- mod->init_size);
70774+ set_section_ro_nx(mod->module_init_rx,
70775+ mod->init_size_rx,
70776+ mod->init_size_rx,
70777+ mod->init_size_rx);
70778
70779 do_mod_ctors(mod);
70780 /* Start the module */
70781@@ -3209,11 +3342,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
70782 mod->strtab = mod->core_strtab;
70783 #endif
70784 unset_module_init_ro_nx(mod);
70785- module_free(mod, mod->module_init);
70786- mod->module_init = NULL;
70787- mod->init_size = 0;
70788- mod->init_ro_size = 0;
70789- mod->init_text_size = 0;
70790+ module_free(mod, mod->module_init_rw);
70791+ module_free_exec(mod, mod->module_init_rx);
70792+ mod->module_init_rw = NULL;
70793+ mod->module_init_rx = NULL;
70794+ mod->init_size_rw = 0;
70795+ mod->init_size_rx = 0;
70796 mutex_unlock(&module_mutex);
70797 wake_up_all(&module_wq);
70798
70799@@ -3245,10 +3379,16 @@ static const char *get_ksymbol(struct module *mod,
70800 unsigned long nextval;
70801
70802 /* At worse, next value is at end of module */
70803- if (within_module_init(addr, mod))
70804- nextval = (unsigned long)mod->module_init+mod->init_text_size;
70805+ if (within_module_init_rx(addr, mod))
70806+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
70807+ else if (within_module_init_rw(addr, mod))
70808+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
70809+ else if (within_module_core_rx(addr, mod))
70810+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
70811+ else if (within_module_core_rw(addr, mod))
70812+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
70813 else
70814- nextval = (unsigned long)mod->module_core+mod->core_text_size;
70815+ return NULL;
70816
70817 /* Scan for closest preceding symbol, and next symbol. (ELF
70818 starts real symbols at 1). */
70819@@ -3501,7 +3641,7 @@ static int m_show(struct seq_file *m, void *p)
70820 return 0;
70821
70822 seq_printf(m, "%s %u",
70823- mod->name, mod->init_size + mod->core_size);
70824+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
70825 print_unload_info(m, mod);
70826
70827 /* Informative for users. */
70828@@ -3510,7 +3650,7 @@ static int m_show(struct seq_file *m, void *p)
70829 mod->state == MODULE_STATE_COMING ? "Loading":
70830 "Live");
70831 /* Used by oprofile and other similar tools. */
70832- seq_printf(m, " 0x%pK", mod->module_core);
70833+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
70834
70835 /* Taints info */
70836 if (mod->taints)
70837@@ -3546,7 +3686,17 @@ static const struct file_operations proc_modules_operations = {
70838
70839 static int __init proc_modules_init(void)
70840 {
70841+#ifndef CONFIG_GRKERNSEC_HIDESYM
70842+#ifdef CONFIG_GRKERNSEC_PROC_USER
70843+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
70844+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
70845+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
70846+#else
70847 proc_create("modules", 0, NULL, &proc_modules_operations);
70848+#endif
70849+#else
70850+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
70851+#endif
70852 return 0;
70853 }
70854 module_init(proc_modules_init);
70855@@ -3607,14 +3757,14 @@ struct module *__module_address(unsigned long addr)
70856 {
70857 struct module *mod;
70858
70859- if (addr < module_addr_min || addr > module_addr_max)
70860+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
70861+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
70862 return NULL;
70863
70864 list_for_each_entry_rcu(mod, &modules, list) {
70865 if (mod->state == MODULE_STATE_UNFORMED)
70866 continue;
70867- if (within_module_core(addr, mod)
70868- || within_module_init(addr, mod))
70869+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
70870 return mod;
70871 }
70872 return NULL;
70873@@ -3649,11 +3799,20 @@ bool is_module_text_address(unsigned long addr)
70874 */
70875 struct module *__module_text_address(unsigned long addr)
70876 {
70877- struct module *mod = __module_address(addr);
70878+ struct module *mod;
70879+
70880+#ifdef CONFIG_X86_32
70881+ addr = ktla_ktva(addr);
70882+#endif
70883+
70884+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
70885+ return NULL;
70886+
70887+ mod = __module_address(addr);
70888+
70889 if (mod) {
70890 /* Make sure it's within the text section. */
70891- if (!within(addr, mod->module_init, mod->init_text_size)
70892- && !within(addr, mod->module_core, mod->core_text_size))
70893+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
70894 mod = NULL;
70895 }
70896 return mod;
70897diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
70898index 7e3443f..b2a1e6b 100644
70899--- a/kernel/mutex-debug.c
70900+++ b/kernel/mutex-debug.c
70901@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
70902 }
70903
70904 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
70905- struct thread_info *ti)
70906+ struct task_struct *task)
70907 {
70908 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
70909
70910 /* Mark the current thread as blocked on the lock: */
70911- ti->task->blocked_on = waiter;
70912+ task->blocked_on = waiter;
70913 }
70914
70915 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
70916- struct thread_info *ti)
70917+ struct task_struct *task)
70918 {
70919 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
70920- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
70921- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
70922- ti->task->blocked_on = NULL;
70923+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
70924+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
70925+ task->blocked_on = NULL;
70926
70927 list_del_init(&waiter->list);
70928 waiter->task = NULL;
70929diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
70930index 0799fd3..d06ae3b 100644
70931--- a/kernel/mutex-debug.h
70932+++ b/kernel/mutex-debug.h
70933@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
70934 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
70935 extern void debug_mutex_add_waiter(struct mutex *lock,
70936 struct mutex_waiter *waiter,
70937- struct thread_info *ti);
70938+ struct task_struct *task);
70939 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
70940- struct thread_info *ti);
70941+ struct task_struct *task);
70942 extern void debug_mutex_unlock(struct mutex *lock);
70943 extern void debug_mutex_init(struct mutex *lock, const char *name,
70944 struct lock_class_key *key);
70945diff --git a/kernel/mutex.c b/kernel/mutex.c
70946index a307cc9..27fd2e9 100644
70947--- a/kernel/mutex.c
70948+++ b/kernel/mutex.c
70949@@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
70950 spin_lock_mutex(&lock->wait_lock, flags);
70951
70952 debug_mutex_lock_common(lock, &waiter);
70953- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
70954+ debug_mutex_add_waiter(lock, &waiter, task);
70955
70956 /* add waiting tasks to the end of the waitqueue (FIFO): */
70957 list_add_tail(&waiter.list, &lock->wait_list);
70958@@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
70959 * TASK_UNINTERRUPTIBLE case.)
70960 */
70961 if (unlikely(signal_pending_state(state, task))) {
70962- mutex_remove_waiter(lock, &waiter,
70963- task_thread_info(task));
70964+ mutex_remove_waiter(lock, &waiter, task);
70965 mutex_release(&lock->dep_map, 1, ip);
70966 spin_unlock_mutex(&lock->wait_lock, flags);
70967
70968@@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
70969 done:
70970 lock_acquired(&lock->dep_map, ip);
70971 /* got the lock - rejoice! */
70972- mutex_remove_waiter(lock, &waiter, current_thread_info());
70973+ mutex_remove_waiter(lock, &waiter, task);
70974 mutex_set_owner(lock);
70975
70976 /* set it to 0 if there are no waiters left: */
70977diff --git a/kernel/notifier.c b/kernel/notifier.c
70978index 2d5cc4c..d9ea600 100644
70979--- a/kernel/notifier.c
70980+++ b/kernel/notifier.c
70981@@ -5,6 +5,7 @@
70982 #include <linux/rcupdate.h>
70983 #include <linux/vmalloc.h>
70984 #include <linux/reboot.h>
70985+#include <linux/mm.h>
70986
70987 /*
70988 * Notifier list for kernel code which wants to be called
70989@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
70990 while ((*nl) != NULL) {
70991 if (n->priority > (*nl)->priority)
70992 break;
70993- nl = &((*nl)->next);
70994+ nl = (struct notifier_block **)&((*nl)->next);
70995 }
70996- n->next = *nl;
70997+ pax_open_kernel();
70998+ *(const void **)&n->next = *nl;
70999 rcu_assign_pointer(*nl, n);
71000+ pax_close_kernel();
71001 return 0;
71002 }
71003
71004@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
71005 return 0;
71006 if (n->priority > (*nl)->priority)
71007 break;
71008- nl = &((*nl)->next);
71009+ nl = (struct notifier_block **)&((*nl)->next);
71010 }
71011- n->next = *nl;
71012+ pax_open_kernel();
71013+ *(const void **)&n->next = *nl;
71014 rcu_assign_pointer(*nl, n);
71015+ pax_close_kernel();
71016 return 0;
71017 }
71018
71019@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
71020 {
71021 while ((*nl) != NULL) {
71022 if ((*nl) == n) {
71023+ pax_open_kernel();
71024 rcu_assign_pointer(*nl, n->next);
71025+ pax_close_kernel();
71026 return 0;
71027 }
71028- nl = &((*nl)->next);
71029+ nl = (struct notifier_block **)&((*nl)->next);
71030 }
71031 return -ENOENT;
71032 }
71033diff --git a/kernel/panic.c b/kernel/panic.c
71034index e1b2822..5edc1d9 100644
71035--- a/kernel/panic.c
71036+++ b/kernel/panic.c
71037@@ -410,7 +410,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
71038 const char *board;
71039
71040 printk(KERN_WARNING "------------[ cut here ]------------\n");
71041- printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
71042+ printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
71043 board = dmi_get_system_info(DMI_PRODUCT_NAME);
71044 if (board)
71045 printk(KERN_WARNING "Hardware name: %s\n", board);
71046@@ -465,7 +465,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
71047 */
71048 void __stack_chk_fail(void)
71049 {
71050- panic("stack-protector: Kernel stack is corrupted in: %p\n",
71051+ dump_stack();
71052+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
71053 __builtin_return_address(0));
71054 }
71055 EXPORT_SYMBOL(__stack_chk_fail);
71056diff --git a/kernel/pid.c b/kernel/pid.c
71057index aebd4f5..1693c13 100644
71058--- a/kernel/pid.c
71059+++ b/kernel/pid.c
71060@@ -33,6 +33,7 @@
71061 #include <linux/rculist.h>
71062 #include <linux/bootmem.h>
71063 #include <linux/hash.h>
71064+#include <linux/security.h>
71065 #include <linux/pid_namespace.h>
71066 #include <linux/init_task.h>
71067 #include <linux/syscalls.h>
71068@@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
71069
71070 int pid_max = PID_MAX_DEFAULT;
71071
71072-#define RESERVED_PIDS 300
71073+#define RESERVED_PIDS 500
71074
71075 int pid_max_min = RESERVED_PIDS + 1;
71076 int pid_max_max = PID_MAX_LIMIT;
71077@@ -420,10 +421,18 @@ EXPORT_SYMBOL(pid_task);
71078 */
71079 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
71080 {
71081+ struct task_struct *task;
71082+
71083 rcu_lockdep_assert(rcu_read_lock_held(),
71084 "find_task_by_pid_ns() needs rcu_read_lock()"
71085 " protection");
71086- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
71087+
71088+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
71089+
71090+ if (gr_pid_is_chrooted(task))
71091+ return NULL;
71092+
71093+ return task;
71094 }
71095
71096 struct task_struct *find_task_by_vpid(pid_t vnr)
71097@@ -431,6 +440,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
71098 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
71099 }
71100
71101+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
71102+{
71103+ rcu_lockdep_assert(rcu_read_lock_held(),
71104+ "find_task_by_pid_ns() needs rcu_read_lock()"
71105+ " protection");
71106+ return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
71107+}
71108+
71109 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
71110 {
71111 struct pid *pid;
71112diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
71113index 125cb67..2e5c8ad 100644
71114--- a/kernel/posix-cpu-timers.c
71115+++ b/kernel/posix-cpu-timers.c
71116@@ -6,9 +6,11 @@
71117 #include <linux/posix-timers.h>
71118 #include <linux/errno.h>
71119 #include <linux/math64.h>
71120+#include <linux/security.h>
71121 #include <asm/uaccess.h>
71122 #include <linux/kernel_stat.h>
71123 #include <trace/events/timer.h>
71124+#include <linux/random.h>
71125
71126 /*
71127 * Called after updating RLIMIT_CPU to run cpu timer and update
71128@@ -494,6 +496,8 @@ static void cleanup_timers(struct list_head *head,
71129 */
71130 void posix_cpu_timers_exit(struct task_struct *tsk)
71131 {
71132+ add_device_randomness((const void*) &tsk->se.sum_exec_runtime,
71133+ sizeof(unsigned long long));
71134 cleanup_timers(tsk->cpu_timers,
71135 tsk->utime, tsk->stime, tsk->se.sum_exec_runtime);
71136
71137@@ -1578,14 +1582,14 @@ struct k_clock clock_posix_cpu = {
71138
71139 static __init int init_posix_cpu_timers(void)
71140 {
71141- struct k_clock process = {
71142+ static struct k_clock process = {
71143 .clock_getres = process_cpu_clock_getres,
71144 .clock_get = process_cpu_clock_get,
71145 .timer_create = process_cpu_timer_create,
71146 .nsleep = process_cpu_nsleep,
71147 .nsleep_restart = process_cpu_nsleep_restart,
71148 };
71149- struct k_clock thread = {
71150+ static struct k_clock thread = {
71151 .clock_getres = thread_cpu_clock_getres,
71152 .clock_get = thread_cpu_clock_get,
71153 .timer_create = thread_cpu_timer_create,
71154diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
71155index 69185ae..cc2847a 100644
71156--- a/kernel/posix-timers.c
71157+++ b/kernel/posix-timers.c
71158@@ -43,6 +43,7 @@
71159 #include <linux/idr.h>
71160 #include <linux/posix-clock.h>
71161 #include <linux/posix-timers.h>
71162+#include <linux/grsecurity.h>
71163 #include <linux/syscalls.h>
71164 #include <linux/wait.h>
71165 #include <linux/workqueue.h>
71166@@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
71167 * which we beg off on and pass to do_sys_settimeofday().
71168 */
71169
71170-static struct k_clock posix_clocks[MAX_CLOCKS];
71171+static struct k_clock *posix_clocks[MAX_CLOCKS];
71172
71173 /*
71174 * These ones are defined below.
71175@@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
71176 */
71177 static __init int init_posix_timers(void)
71178 {
71179- struct k_clock clock_realtime = {
71180+ static struct k_clock clock_realtime = {
71181 .clock_getres = hrtimer_get_res,
71182 .clock_get = posix_clock_realtime_get,
71183 .clock_set = posix_clock_realtime_set,
71184@@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
71185 .timer_get = common_timer_get,
71186 .timer_del = common_timer_del,
71187 };
71188- struct k_clock clock_monotonic = {
71189+ static struct k_clock clock_monotonic = {
71190 .clock_getres = hrtimer_get_res,
71191 .clock_get = posix_ktime_get_ts,
71192 .nsleep = common_nsleep,
71193@@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
71194 .timer_get = common_timer_get,
71195 .timer_del = common_timer_del,
71196 };
71197- struct k_clock clock_monotonic_raw = {
71198+ static struct k_clock clock_monotonic_raw = {
71199 .clock_getres = hrtimer_get_res,
71200 .clock_get = posix_get_monotonic_raw,
71201 };
71202- struct k_clock clock_realtime_coarse = {
71203+ static struct k_clock clock_realtime_coarse = {
71204 .clock_getres = posix_get_coarse_res,
71205 .clock_get = posix_get_realtime_coarse,
71206 };
71207- struct k_clock clock_monotonic_coarse = {
71208+ static struct k_clock clock_monotonic_coarse = {
71209 .clock_getres = posix_get_coarse_res,
71210 .clock_get = posix_get_monotonic_coarse,
71211 };
71212- struct k_clock clock_boottime = {
71213+ static struct k_clock clock_boottime = {
71214 .clock_getres = hrtimer_get_res,
71215 .clock_get = posix_get_boottime,
71216 .nsleep = common_nsleep,
71217@@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
71218 return;
71219 }
71220
71221- posix_clocks[clock_id] = *new_clock;
71222+ posix_clocks[clock_id] = new_clock;
71223 }
71224 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
71225
71226@@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
71227 return (id & CLOCKFD_MASK) == CLOCKFD ?
71228 &clock_posix_dynamic : &clock_posix_cpu;
71229
71230- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
71231+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
71232 return NULL;
71233- return &posix_clocks[id];
71234+ return posix_clocks[id];
71235 }
71236
71237 static int common_timer_create(struct k_itimer *new_timer)
71238@@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
71239 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
71240 return -EFAULT;
71241
71242+ /* only the CLOCK_REALTIME clock can be set, all other clocks
71243+ have their clock_set fptr set to a nosettime dummy function
71244+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
71245+ call common_clock_set, which calls do_sys_settimeofday, which
71246+ we hook
71247+ */
71248+
71249 return kc->clock_set(which_clock, &new_tp);
71250 }
71251
71252diff --git a/kernel/power/process.c b/kernel/power/process.c
71253index 87da817..30ddd13 100644
71254--- a/kernel/power/process.c
71255+++ b/kernel/power/process.c
71256@@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
71257 u64 elapsed_csecs64;
71258 unsigned int elapsed_csecs;
71259 bool wakeup = false;
71260+ bool timedout = false;
71261
71262 do_gettimeofday(&start);
71263
71264@@ -43,6 +44,8 @@ static int try_to_freeze_tasks(bool user_only)
71265
71266 while (true) {
71267 todo = 0;
71268+ if (time_after(jiffies, end_time))
71269+ timedout = true;
71270 read_lock(&tasklist_lock);
71271 do_each_thread(g, p) {
71272 if (p == current || !freeze_task(p))
71273@@ -58,9 +61,13 @@ static int try_to_freeze_tasks(bool user_only)
71274 * guaranteed that TASK_STOPPED/TRACED -> TASK_RUNNING
71275 * transition can't race with task state testing here.
71276 */
71277- if (!task_is_stopped_or_traced(p) &&
71278- !freezer_should_skip(p))
71279+ if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
71280 todo++;
71281+ if (timedout) {
71282+ printk(KERN_ERR "Task refusing to freeze:\n");
71283+ sched_show_task(p);
71284+ }
71285+ }
71286 } while_each_thread(g, p);
71287 read_unlock(&tasklist_lock);
71288
71289@@ -69,7 +76,7 @@ static int try_to_freeze_tasks(bool user_only)
71290 todo += wq_busy;
71291 }
71292
71293- if (!todo || time_after(jiffies, end_time))
71294+ if (!todo || timedout)
71295 break;
71296
71297 if (pm_wakeup_pending()) {
71298diff --git a/kernel/printk.c b/kernel/printk.c
71299index f8e0b5a..dda2a5c 100644
71300--- a/kernel/printk.c
71301+++ b/kernel/printk.c
71302@@ -817,6 +817,11 @@ static int check_syslog_permissions(int type, bool from_file)
71303 if (from_file && type != SYSLOG_ACTION_OPEN)
71304 return 0;
71305
71306+#ifdef CONFIG_GRKERNSEC_DMESG
71307+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
71308+ return -EPERM;
71309+#endif
71310+
71311 if (syslog_action_restricted(type)) {
71312 if (capable(CAP_SYSLOG))
71313 return 0;
71314diff --git a/kernel/profile.c b/kernel/profile.c
71315index 76b8e77..a2930e8 100644
71316--- a/kernel/profile.c
71317+++ b/kernel/profile.c
71318@@ -39,7 +39,7 @@ struct profile_hit {
71319 /* Oprofile timer tick hook */
71320 static int (*timer_hook)(struct pt_regs *) __read_mostly;
71321
71322-static atomic_t *prof_buffer;
71323+static atomic_unchecked_t *prof_buffer;
71324 static unsigned long prof_len, prof_shift;
71325
71326 int prof_on __read_mostly;
71327@@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
71328 hits[i].pc = 0;
71329 continue;
71330 }
71331- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
71332+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
71333 hits[i].hits = hits[i].pc = 0;
71334 }
71335 }
71336@@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
71337 * Add the current hit(s) and flush the write-queue out
71338 * to the global buffer:
71339 */
71340- atomic_add(nr_hits, &prof_buffer[pc]);
71341+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
71342 for (i = 0; i < NR_PROFILE_HIT; ++i) {
71343- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
71344+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
71345 hits[i].pc = hits[i].hits = 0;
71346 }
71347 out:
71348@@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
71349 {
71350 unsigned long pc;
71351 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
71352- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
71353+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
71354 }
71355 #endif /* !CONFIG_SMP */
71356
71357@@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
71358 return -EFAULT;
71359 buf++; p++; count--; read++;
71360 }
71361- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
71362+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
71363 if (copy_to_user(buf, (void *)pnt, count))
71364 return -EFAULT;
71365 read += count;
71366@@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
71367 }
71368 #endif
71369 profile_discard_flip_buffers();
71370- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
71371+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
71372 return count;
71373 }
71374
71375diff --git a/kernel/ptrace.c b/kernel/ptrace.c
71376index fbea91d..9bf15e8 100644
71377--- a/kernel/ptrace.c
71378+++ b/kernel/ptrace.c
71379@@ -319,7 +319,7 @@ static int ptrace_attach(struct task_struct *task, long request,
71380
71381 if (seize)
71382 flags |= PT_SEIZED;
71383- if (ns_capable(task_user_ns(task), CAP_SYS_PTRACE))
71384+ if (ns_capable_nolog(task_user_ns(task), CAP_SYS_PTRACE))
71385 flags |= PT_PTRACE_CAP;
71386 task->ptrace = flags;
71387
71388@@ -526,7 +526,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
71389 break;
71390 return -EIO;
71391 }
71392- if (copy_to_user(dst, buf, retval))
71393+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
71394 return -EFAULT;
71395 copied += retval;
71396 src += retval;
71397@@ -711,7 +711,7 @@ int ptrace_request(struct task_struct *child, long request,
71398 bool seized = child->ptrace & PT_SEIZED;
71399 int ret = -EIO;
71400 siginfo_t siginfo, *si;
71401- void __user *datavp = (void __user *) data;
71402+ void __user *datavp = (__force void __user *) data;
71403 unsigned long __user *datalp = datavp;
71404 unsigned long flags;
71405
71406@@ -913,14 +913,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
71407 goto out;
71408 }
71409
71410+ if (gr_handle_ptrace(child, request)) {
71411+ ret = -EPERM;
71412+ goto out_put_task_struct;
71413+ }
71414+
71415 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
71416 ret = ptrace_attach(child, request, addr, data);
71417 /*
71418 * Some architectures need to do book-keeping after
71419 * a ptrace attach.
71420 */
71421- if (!ret)
71422+ if (!ret) {
71423 arch_ptrace_attach(child);
71424+ gr_audit_ptrace(child);
71425+ }
71426 goto out_put_task_struct;
71427 }
71428
71429@@ -948,7 +955,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
71430 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
71431 if (copied != sizeof(tmp))
71432 return -EIO;
71433- return put_user(tmp, (unsigned long __user *)data);
71434+ return put_user(tmp, (__force unsigned long __user *)data);
71435 }
71436
71437 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
71438@@ -1058,14 +1065,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
71439 goto out;
71440 }
71441
71442+ if (gr_handle_ptrace(child, request)) {
71443+ ret = -EPERM;
71444+ goto out_put_task_struct;
71445+ }
71446+
71447 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
71448 ret = ptrace_attach(child, request, addr, data);
71449 /*
71450 * Some architectures need to do book-keeping after
71451 * a ptrace attach.
71452 */
71453- if (!ret)
71454+ if (!ret) {
71455 arch_ptrace_attach(child);
71456+ gr_audit_ptrace(child);
71457+ }
71458 goto out_put_task_struct;
71459 }
71460
71461diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
71462index e4c6a59..c86621a 100644
71463--- a/kernel/rcutiny.c
71464+++ b/kernel/rcutiny.c
71465@@ -46,7 +46,7 @@
71466 struct rcu_ctrlblk;
71467 static void invoke_rcu_callbacks(void);
71468 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
71469-static void rcu_process_callbacks(struct softirq_action *unused);
71470+static void rcu_process_callbacks(void);
71471 static void __call_rcu(struct rcu_head *head,
71472 void (*func)(struct rcu_head *rcu),
71473 struct rcu_ctrlblk *rcp);
71474@@ -310,7 +310,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
71475 rcu_is_callbacks_kthread()));
71476 }
71477
71478-static void rcu_process_callbacks(struct softirq_action *unused)
71479+static void rcu_process_callbacks(void)
71480 {
71481 __rcu_process_callbacks(&rcu_sched_ctrlblk);
71482 __rcu_process_callbacks(&rcu_bh_ctrlblk);
71483diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
71484index 3d01902..afbf46e 100644
71485--- a/kernel/rcutiny_plugin.h
71486+++ b/kernel/rcutiny_plugin.h
71487@@ -893,7 +893,7 @@ static int rcu_kthread(void *arg)
71488 have_rcu_kthread_work = morework;
71489 local_irq_restore(flags);
71490 if (work)
71491- rcu_process_callbacks(NULL);
71492+ rcu_process_callbacks();
71493 schedule_timeout_interruptible(1); /* Leave CPU for others. */
71494 }
71495
71496diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
71497index aaa7b9f..055ff1e 100644
71498--- a/kernel/rcutorture.c
71499+++ b/kernel/rcutorture.c
71500@@ -163,12 +163,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
71501 { 0 };
71502 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
71503 { 0 };
71504-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
71505-static atomic_t n_rcu_torture_alloc;
71506-static atomic_t n_rcu_torture_alloc_fail;
71507-static atomic_t n_rcu_torture_free;
71508-static atomic_t n_rcu_torture_mberror;
71509-static atomic_t n_rcu_torture_error;
71510+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
71511+static atomic_unchecked_t n_rcu_torture_alloc;
71512+static atomic_unchecked_t n_rcu_torture_alloc_fail;
71513+static atomic_unchecked_t n_rcu_torture_free;
71514+static atomic_unchecked_t n_rcu_torture_mberror;
71515+static atomic_unchecked_t n_rcu_torture_error;
71516 static long n_rcu_torture_barrier_error;
71517 static long n_rcu_torture_boost_ktrerror;
71518 static long n_rcu_torture_boost_rterror;
71519@@ -272,11 +272,11 @@ rcu_torture_alloc(void)
71520
71521 spin_lock_bh(&rcu_torture_lock);
71522 if (list_empty(&rcu_torture_freelist)) {
71523- atomic_inc(&n_rcu_torture_alloc_fail);
71524+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
71525 spin_unlock_bh(&rcu_torture_lock);
71526 return NULL;
71527 }
71528- atomic_inc(&n_rcu_torture_alloc);
71529+ atomic_inc_unchecked(&n_rcu_torture_alloc);
71530 p = rcu_torture_freelist.next;
71531 list_del_init(p);
71532 spin_unlock_bh(&rcu_torture_lock);
71533@@ -289,7 +289,7 @@ rcu_torture_alloc(void)
71534 static void
71535 rcu_torture_free(struct rcu_torture *p)
71536 {
71537- atomic_inc(&n_rcu_torture_free);
71538+ atomic_inc_unchecked(&n_rcu_torture_free);
71539 spin_lock_bh(&rcu_torture_lock);
71540 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
71541 spin_unlock_bh(&rcu_torture_lock);
71542@@ -410,7 +410,7 @@ rcu_torture_cb(struct rcu_head *p)
71543 i = rp->rtort_pipe_count;
71544 if (i > RCU_TORTURE_PIPE_LEN)
71545 i = RCU_TORTURE_PIPE_LEN;
71546- atomic_inc(&rcu_torture_wcount[i]);
71547+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
71548 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
71549 rp->rtort_mbtest = 0;
71550 rcu_torture_free(rp);
71551@@ -459,7 +459,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
71552 i = rp->rtort_pipe_count;
71553 if (i > RCU_TORTURE_PIPE_LEN)
71554 i = RCU_TORTURE_PIPE_LEN;
71555- atomic_inc(&rcu_torture_wcount[i]);
71556+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
71557 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
71558 rp->rtort_mbtest = 0;
71559 list_del(&rp->rtort_free);
71560@@ -1002,7 +1002,7 @@ rcu_torture_writer(void *arg)
71561 i = old_rp->rtort_pipe_count;
71562 if (i > RCU_TORTURE_PIPE_LEN)
71563 i = RCU_TORTURE_PIPE_LEN;
71564- atomic_inc(&rcu_torture_wcount[i]);
71565+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
71566 old_rp->rtort_pipe_count++;
71567 cur_ops->deferred_free(old_rp);
71568 }
71569@@ -1087,7 +1087,7 @@ static void rcu_torture_timer(unsigned long unused)
71570 }
71571 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
71572 if (p->rtort_mbtest == 0)
71573- atomic_inc(&n_rcu_torture_mberror);
71574+ atomic_inc_unchecked(&n_rcu_torture_mberror);
71575 spin_lock(&rand_lock);
71576 cur_ops->read_delay(&rand);
71577 n_rcu_torture_timers++;
71578@@ -1151,7 +1151,7 @@ rcu_torture_reader(void *arg)
71579 }
71580 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
71581 if (p->rtort_mbtest == 0)
71582- atomic_inc(&n_rcu_torture_mberror);
71583+ atomic_inc_unchecked(&n_rcu_torture_mberror);
71584 cur_ops->read_delay(&rand);
71585 preempt_disable();
71586 pipe_count = p->rtort_pipe_count;
71587@@ -1210,11 +1210,11 @@ rcu_torture_printk(char *page)
71588 rcu_torture_current,
71589 rcu_torture_current_version,
71590 list_empty(&rcu_torture_freelist),
71591- atomic_read(&n_rcu_torture_alloc),
71592- atomic_read(&n_rcu_torture_alloc_fail),
71593- atomic_read(&n_rcu_torture_free));
71594+ atomic_read_unchecked(&n_rcu_torture_alloc),
71595+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
71596+ atomic_read_unchecked(&n_rcu_torture_free));
71597 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
71598- atomic_read(&n_rcu_torture_mberror),
71599+ atomic_read_unchecked(&n_rcu_torture_mberror),
71600 n_rcu_torture_boost_ktrerror,
71601 n_rcu_torture_boost_rterror);
71602 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
71603@@ -1233,14 +1233,14 @@ rcu_torture_printk(char *page)
71604 n_barrier_attempts,
71605 n_rcu_torture_barrier_error);
71606 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
71607- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
71608+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
71609 n_rcu_torture_barrier_error != 0 ||
71610 n_rcu_torture_boost_ktrerror != 0 ||
71611 n_rcu_torture_boost_rterror != 0 ||
71612 n_rcu_torture_boost_failure != 0 ||
71613 i > 1) {
71614 cnt += sprintf(&page[cnt], "!!! ");
71615- atomic_inc(&n_rcu_torture_error);
71616+ atomic_inc_unchecked(&n_rcu_torture_error);
71617 WARN_ON_ONCE(1);
71618 }
71619 cnt += sprintf(&page[cnt], "Reader Pipe: ");
71620@@ -1254,7 +1254,7 @@ rcu_torture_printk(char *page)
71621 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
71622 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
71623 cnt += sprintf(&page[cnt], " %d",
71624- atomic_read(&rcu_torture_wcount[i]));
71625+ atomic_read_unchecked(&rcu_torture_wcount[i]));
71626 }
71627 cnt += sprintf(&page[cnt], "\n");
71628 if (cur_ops->stats)
71629@@ -1938,7 +1938,7 @@ rcu_torture_cleanup(void)
71630
71631 if (cur_ops->cleanup)
71632 cur_ops->cleanup();
71633- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
71634+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
71635 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
71636 else if (n_online_successes != n_online_attempts ||
71637 n_offline_successes != n_offline_attempts)
71638@@ -2007,18 +2007,18 @@ rcu_torture_init(void)
71639
71640 rcu_torture_current = NULL;
71641 rcu_torture_current_version = 0;
71642- atomic_set(&n_rcu_torture_alloc, 0);
71643- atomic_set(&n_rcu_torture_alloc_fail, 0);
71644- atomic_set(&n_rcu_torture_free, 0);
71645- atomic_set(&n_rcu_torture_mberror, 0);
71646- atomic_set(&n_rcu_torture_error, 0);
71647+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
71648+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
71649+ atomic_set_unchecked(&n_rcu_torture_free, 0);
71650+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
71651+ atomic_set_unchecked(&n_rcu_torture_error, 0);
71652 n_rcu_torture_barrier_error = 0;
71653 n_rcu_torture_boost_ktrerror = 0;
71654 n_rcu_torture_boost_rterror = 0;
71655 n_rcu_torture_boost_failure = 0;
71656 n_rcu_torture_boosts = 0;
71657 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
71658- atomic_set(&rcu_torture_wcount[i], 0);
71659+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
71660 for_each_possible_cpu(cpu) {
71661 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
71662 per_cpu(rcu_torture_count, cpu)[i] = 0;
71663diff --git a/kernel/rcutree.c b/kernel/rcutree.c
71664index 2682295..0f2297e 100644
71665--- a/kernel/rcutree.c
71666+++ b/kernel/rcutree.c
71667@@ -348,9 +348,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
71668 rcu_prepare_for_idle(smp_processor_id());
71669 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
71670 smp_mb__before_atomic_inc(); /* See above. */
71671- atomic_inc(&rdtp->dynticks);
71672+ atomic_inc_unchecked(&rdtp->dynticks);
71673 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
71674- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
71675+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
71676
71677 /*
71678 * It is illegal to enter an extended quiescent state while
71679@@ -508,10 +508,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
71680 int user)
71681 {
71682 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
71683- atomic_inc(&rdtp->dynticks);
71684+ atomic_inc_unchecked(&rdtp->dynticks);
71685 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
71686 smp_mb__after_atomic_inc(); /* See above. */
71687- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
71688+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
71689 rcu_cleanup_after_idle(smp_processor_id());
71690 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
71691 if (!user && !is_idle_task(current)) {
71692@@ -670,14 +670,14 @@ void rcu_nmi_enter(void)
71693 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
71694
71695 if (rdtp->dynticks_nmi_nesting == 0 &&
71696- (atomic_read(&rdtp->dynticks) & 0x1))
71697+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
71698 return;
71699 rdtp->dynticks_nmi_nesting++;
71700 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
71701- atomic_inc(&rdtp->dynticks);
71702+ atomic_inc_unchecked(&rdtp->dynticks);
71703 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
71704 smp_mb__after_atomic_inc(); /* See above. */
71705- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
71706+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
71707 }
71708
71709 /**
71710@@ -696,9 +696,9 @@ void rcu_nmi_exit(void)
71711 return;
71712 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
71713 smp_mb__before_atomic_inc(); /* See above. */
71714- atomic_inc(&rdtp->dynticks);
71715+ atomic_inc_unchecked(&rdtp->dynticks);
71716 smp_mb__after_atomic_inc(); /* Force delay to next write. */
71717- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
71718+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
71719 }
71720
71721 /**
71722@@ -712,7 +712,7 @@ int rcu_is_cpu_idle(void)
71723 int ret;
71724
71725 preempt_disable();
71726- ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
71727+ ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
71728 preempt_enable();
71729 return ret;
71730 }
71731@@ -795,7 +795,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
71732 */
71733 static int dyntick_save_progress_counter(struct rcu_data *rdp)
71734 {
71735- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
71736+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
71737 return (rdp->dynticks_snap & 0x1) == 0;
71738 }
71739
71740@@ -810,7 +810,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
71741 unsigned int curr;
71742 unsigned int snap;
71743
71744- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
71745+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
71746 snap = (unsigned int)rdp->dynticks_snap;
71747
71748 /*
71749@@ -858,10 +858,10 @@ static int jiffies_till_stall_check(void)
71750 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
71751 */
71752 if (till_stall_check < 3) {
71753- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
71754+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
71755 till_stall_check = 3;
71756 } else if (till_stall_check > 300) {
71757- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
71758+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
71759 till_stall_check = 300;
71760 }
71761 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
71762@@ -1589,7 +1589,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
71763 rsp->qlen += rdp->qlen;
71764 rdp->n_cbs_orphaned += rdp->qlen;
71765 rdp->qlen_lazy = 0;
71766- ACCESS_ONCE(rdp->qlen) = 0;
71767+ ACCESS_ONCE_RW(rdp->qlen) = 0;
71768 }
71769
71770 /*
71771@@ -1831,7 +1831,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
71772 }
71773 smp_mb(); /* List handling before counting for rcu_barrier(). */
71774 rdp->qlen_lazy -= count_lazy;
71775- ACCESS_ONCE(rdp->qlen) -= count;
71776+ ACCESS_ONCE_RW(rdp->qlen) -= count;
71777 rdp->n_cbs_invoked += count;
71778
71779 /* Reinstate batch limit if we have worked down the excess. */
71780@@ -2024,7 +2024,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
71781 /*
71782 * Do RCU core processing for the current CPU.
71783 */
71784-static void rcu_process_callbacks(struct softirq_action *unused)
71785+static void rcu_process_callbacks(void)
71786 {
71787 struct rcu_state *rsp;
71788
71789@@ -2136,7 +2136,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
71790 local_irq_restore(flags);
71791 return;
71792 }
71793- ACCESS_ONCE(rdp->qlen)++;
71794+ ACCESS_ONCE_RW(rdp->qlen)++;
71795 if (lazy)
71796 rdp->qlen_lazy++;
71797 else
71798@@ -2250,8 +2250,8 @@ void synchronize_rcu_bh(void)
71799 }
71800 EXPORT_SYMBOL_GPL(synchronize_rcu_bh);
71801
71802-static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
71803-static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
71804+static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
71805+static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
71806
71807 static int synchronize_sched_expedited_cpu_stop(void *data)
71808 {
71809@@ -2312,7 +2312,7 @@ void synchronize_sched_expedited(void)
71810 int firstsnap, s, snap, trycount = 0;
71811
71812 /* Note that atomic_inc_return() implies full memory barrier. */
71813- firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
71814+ firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
71815 get_online_cpus();
71816 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
71817
71818@@ -2334,7 +2334,7 @@ void synchronize_sched_expedited(void)
71819 }
71820
71821 /* Check to see if someone else did our work for us. */
71822- s = atomic_read(&sync_sched_expedited_done);
71823+ s = atomic_read_unchecked(&sync_sched_expedited_done);
71824 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
71825 smp_mb(); /* ensure test happens before caller kfree */
71826 return;
71827@@ -2349,7 +2349,7 @@ void synchronize_sched_expedited(void)
71828 * grace period works for us.
71829 */
71830 get_online_cpus();
71831- snap = atomic_read(&sync_sched_expedited_started);
71832+ snap = atomic_read_unchecked(&sync_sched_expedited_started);
71833 smp_mb(); /* ensure read is before try_stop_cpus(). */
71834 }
71835
71836@@ -2360,12 +2360,12 @@ void synchronize_sched_expedited(void)
71837 * than we did beat us to the punch.
71838 */
71839 do {
71840- s = atomic_read(&sync_sched_expedited_done);
71841+ s = atomic_read_unchecked(&sync_sched_expedited_done);
71842 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
71843 smp_mb(); /* ensure test happens before caller kfree */
71844 break;
71845 }
71846- } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
71847+ } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
71848
71849 put_online_cpus();
71850 }
71851@@ -2539,7 +2539,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
71852 * ACCESS_ONCE() to prevent the compiler from speculating
71853 * the increment to precede the early-exit check.
71854 */
71855- ACCESS_ONCE(rsp->n_barrier_done)++;
71856+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
71857 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
71858 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
71859 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
71860@@ -2581,7 +2581,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
71861
71862 /* Increment ->n_barrier_done to prevent duplicate work. */
71863 smp_mb(); /* Keep increment after above mechanism. */
71864- ACCESS_ONCE(rsp->n_barrier_done)++;
71865+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
71866 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
71867 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
71868 smp_mb(); /* Keep increment before caller's subsequent code. */
71869@@ -2626,10 +2626,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
71870 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
71871 init_callback_list(rdp);
71872 rdp->qlen_lazy = 0;
71873- ACCESS_ONCE(rdp->qlen) = 0;
71874+ ACCESS_ONCE_RW(rdp->qlen) = 0;
71875 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
71876 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
71877- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
71878+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
71879 #ifdef CONFIG_RCU_USER_QS
71880 WARN_ON_ONCE(rdp->dynticks->in_user);
71881 #endif
71882@@ -2664,8 +2664,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
71883 rdp->blimit = blimit;
71884 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
71885 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
71886- atomic_set(&rdp->dynticks->dynticks,
71887- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
71888+ atomic_set_unchecked(&rdp->dynticks->dynticks,
71889+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
71890 rcu_prepare_for_idle_init(cpu);
71891 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
71892
71893diff --git a/kernel/rcutree.h b/kernel/rcutree.h
71894index a240f03..d469618 100644
71895--- a/kernel/rcutree.h
71896+++ b/kernel/rcutree.h
71897@@ -86,7 +86,7 @@ struct rcu_dynticks {
71898 long long dynticks_nesting; /* Track irq/process nesting level. */
71899 /* Process level is worth LLONG_MAX/2. */
71900 int dynticks_nmi_nesting; /* Track NMI nesting level. */
71901- atomic_t dynticks; /* Even value for idle, else odd. */
71902+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
71903 #ifdef CONFIG_RCU_FAST_NO_HZ
71904 int dyntick_drain; /* Prepare-for-idle state variable. */
71905 unsigned long dyntick_holdoff;
71906diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
71907index f921154..34c4873 100644
71908--- a/kernel/rcutree_plugin.h
71909+++ b/kernel/rcutree_plugin.h
71910@@ -865,7 +865,7 @@ void synchronize_rcu_expedited(void)
71911
71912 /* Clean up and exit. */
71913 smp_mb(); /* ensure expedited GP seen before counter increment. */
71914- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
71915+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
71916 unlock_mb_ret:
71917 mutex_unlock(&sync_rcu_preempt_exp_mutex);
71918 mb_ret:
71919@@ -2040,7 +2040,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
71920 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
71921 printk(KERN_ERR "\t%d: (%lu %s) idle=%03x/%llx/%d %s\n",
71922 cpu, ticks_value, ticks_title,
71923- atomic_read(&rdtp->dynticks) & 0xfff,
71924+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
71925 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
71926 fast_no_hz);
71927 }
71928diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
71929index 693513b..b9f1d63 100644
71930--- a/kernel/rcutree_trace.c
71931+++ b/kernel/rcutree_trace.c
71932@@ -92,7 +92,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
71933 rdp->completed, rdp->gpnum,
71934 rdp->passed_quiesce, rdp->qs_pending);
71935 seq_printf(m, " dt=%d/%llx/%d df=%lu",
71936- atomic_read(&rdp->dynticks->dynticks),
71937+ atomic_read_unchecked(&rdp->dynticks->dynticks),
71938 rdp->dynticks->dynticks_nesting,
71939 rdp->dynticks->dynticks_nmi_nesting,
71940 rdp->dynticks_fqs);
71941@@ -154,7 +154,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
71942 rdp->completed, rdp->gpnum,
71943 rdp->passed_quiesce, rdp->qs_pending);
71944 seq_printf(m, ",%d,%llx,%d,%lu",
71945- atomic_read(&rdp->dynticks->dynticks),
71946+ atomic_read_unchecked(&rdp->dynticks->dynticks),
71947 rdp->dynticks->dynticks_nesting,
71948 rdp->dynticks->dynticks_nmi_nesting,
71949 rdp->dynticks_fqs);
71950diff --git a/kernel/resource.c b/kernel/resource.c
71951index 73f35d4..4684fc4 100644
71952--- a/kernel/resource.c
71953+++ b/kernel/resource.c
71954@@ -143,8 +143,18 @@ static const struct file_operations proc_iomem_operations = {
71955
71956 static int __init ioresources_init(void)
71957 {
71958+#ifdef CONFIG_GRKERNSEC_PROC_ADD
71959+#ifdef CONFIG_GRKERNSEC_PROC_USER
71960+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
71961+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
71962+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
71963+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
71964+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
71965+#endif
71966+#else
71967 proc_create("ioports", 0, NULL, &proc_ioports_operations);
71968 proc_create("iomem", 0, NULL, &proc_iomem_operations);
71969+#endif
71970 return 0;
71971 }
71972 __initcall(ioresources_init);
71973diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
71974index 98ec494..4241d6d 100644
71975--- a/kernel/rtmutex-tester.c
71976+++ b/kernel/rtmutex-tester.c
71977@@ -20,7 +20,7 @@
71978 #define MAX_RT_TEST_MUTEXES 8
71979
71980 static spinlock_t rttest_lock;
71981-static atomic_t rttest_event;
71982+static atomic_unchecked_t rttest_event;
71983
71984 struct test_thread_data {
71985 int opcode;
71986@@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
71987
71988 case RTTEST_LOCKCONT:
71989 td->mutexes[td->opdata] = 1;
71990- td->event = atomic_add_return(1, &rttest_event);
71991+ td->event = atomic_add_return_unchecked(1, &rttest_event);
71992 return 0;
71993
71994 case RTTEST_RESET:
71995@@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
71996 return 0;
71997
71998 case RTTEST_RESETEVENT:
71999- atomic_set(&rttest_event, 0);
72000+ atomic_set_unchecked(&rttest_event, 0);
72001 return 0;
72002
72003 default:
72004@@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
72005 return ret;
72006
72007 td->mutexes[id] = 1;
72008- td->event = atomic_add_return(1, &rttest_event);
72009+ td->event = atomic_add_return_unchecked(1, &rttest_event);
72010 rt_mutex_lock(&mutexes[id]);
72011- td->event = atomic_add_return(1, &rttest_event);
72012+ td->event = atomic_add_return_unchecked(1, &rttest_event);
72013 td->mutexes[id] = 4;
72014 return 0;
72015
72016@@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
72017 return ret;
72018
72019 td->mutexes[id] = 1;
72020- td->event = atomic_add_return(1, &rttest_event);
72021+ td->event = atomic_add_return_unchecked(1, &rttest_event);
72022 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
72023- td->event = atomic_add_return(1, &rttest_event);
72024+ td->event = atomic_add_return_unchecked(1, &rttest_event);
72025 td->mutexes[id] = ret ? 0 : 4;
72026 return ret ? -EINTR : 0;
72027
72028@@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
72029 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
72030 return ret;
72031
72032- td->event = atomic_add_return(1, &rttest_event);
72033+ td->event = atomic_add_return_unchecked(1, &rttest_event);
72034 rt_mutex_unlock(&mutexes[id]);
72035- td->event = atomic_add_return(1, &rttest_event);
72036+ td->event = atomic_add_return_unchecked(1, &rttest_event);
72037 td->mutexes[id] = 0;
72038 return 0;
72039
72040@@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
72041 break;
72042
72043 td->mutexes[dat] = 2;
72044- td->event = atomic_add_return(1, &rttest_event);
72045+ td->event = atomic_add_return_unchecked(1, &rttest_event);
72046 break;
72047
72048 default:
72049@@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
72050 return;
72051
72052 td->mutexes[dat] = 3;
72053- td->event = atomic_add_return(1, &rttest_event);
72054+ td->event = atomic_add_return_unchecked(1, &rttest_event);
72055 break;
72056
72057 case RTTEST_LOCKNOWAIT:
72058@@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
72059 return;
72060
72061 td->mutexes[dat] = 1;
72062- td->event = atomic_add_return(1, &rttest_event);
72063+ td->event = atomic_add_return_unchecked(1, &rttest_event);
72064 return;
72065
72066 default:
72067diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
72068index 15f60d0..7e50319 100644
72069--- a/kernel/sched/auto_group.c
72070+++ b/kernel/sched/auto_group.c
72071@@ -11,7 +11,7 @@
72072
72073 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
72074 static struct autogroup autogroup_default;
72075-static atomic_t autogroup_seq_nr;
72076+static atomic_unchecked_t autogroup_seq_nr;
72077
72078 void __init autogroup_init(struct task_struct *init_task)
72079 {
72080@@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
72081
72082 kref_init(&ag->kref);
72083 init_rwsem(&ag->lock);
72084- ag->id = atomic_inc_return(&autogroup_seq_nr);
72085+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
72086 ag->tg = tg;
72087 #ifdef CONFIG_RT_GROUP_SCHED
72088 /*
72089diff --git a/kernel/sched/core.c b/kernel/sched/core.c
72090index c529d00..d00b4f3 100644
72091--- a/kernel/sched/core.c
72092+++ b/kernel/sched/core.c
72093@@ -3563,6 +3563,8 @@ int can_nice(const struct task_struct *p, const int nice)
72094 /* convert nice value [19,-20] to rlimit style value [1,40] */
72095 int nice_rlim = 20 - nice;
72096
72097+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
72098+
72099 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
72100 capable(CAP_SYS_NICE));
72101 }
72102@@ -3596,7 +3598,8 @@ SYSCALL_DEFINE1(nice, int, increment)
72103 if (nice > 19)
72104 nice = 19;
72105
72106- if (increment < 0 && !can_nice(current, nice))
72107+ if (increment < 0 && (!can_nice(current, nice) ||
72108+ gr_handle_chroot_nice()))
72109 return -EPERM;
72110
72111 retval = security_task_setnice(current, nice);
72112@@ -3750,6 +3753,7 @@ recheck:
72113 unsigned long rlim_rtprio =
72114 task_rlimit(p, RLIMIT_RTPRIO);
72115
72116+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
72117 /* can't set/change the rt policy */
72118 if (policy != p->policy && !rlim_rtprio)
72119 return -EPERM;
72120diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
72121index 6b800a1..0c36227 100644
72122--- a/kernel/sched/fair.c
72123+++ b/kernel/sched/fair.c
72124@@ -4890,7 +4890,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
72125 * run_rebalance_domains is triggered when needed from the scheduler tick.
72126 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
72127 */
72128-static void run_rebalance_domains(struct softirq_action *h)
72129+static void run_rebalance_domains(void)
72130 {
72131 int this_cpu = smp_processor_id();
72132 struct rq *this_rq = cpu_rq(this_cpu);
72133diff --git a/kernel/signal.c b/kernel/signal.c
72134index 57dde52..2c561f0 100644
72135--- a/kernel/signal.c
72136+++ b/kernel/signal.c
72137@@ -49,12 +49,12 @@ static struct kmem_cache *sigqueue_cachep;
72138
72139 int print_fatal_signals __read_mostly;
72140
72141-static void __user *sig_handler(struct task_struct *t, int sig)
72142+static __sighandler_t sig_handler(struct task_struct *t, int sig)
72143 {
72144 return t->sighand->action[sig - 1].sa.sa_handler;
72145 }
72146
72147-static int sig_handler_ignored(void __user *handler, int sig)
72148+static int sig_handler_ignored(__sighandler_t handler, int sig)
72149 {
72150 /* Is it explicitly or implicitly ignored? */
72151 return handler == SIG_IGN ||
72152@@ -63,7 +63,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
72153
72154 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
72155 {
72156- void __user *handler;
72157+ __sighandler_t handler;
72158
72159 handler = sig_handler(t, sig);
72160
72161@@ -367,6 +367,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
72162 atomic_inc(&user->sigpending);
72163 rcu_read_unlock();
72164
72165+ if (!override_rlimit)
72166+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
72167+
72168 if (override_rlimit ||
72169 atomic_read(&user->sigpending) <=
72170 task_rlimit(t, RLIMIT_SIGPENDING)) {
72171@@ -491,7 +494,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
72172
72173 int unhandled_signal(struct task_struct *tsk, int sig)
72174 {
72175- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
72176+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
72177 if (is_global_init(tsk))
72178 return 1;
72179 if (handler != SIG_IGN && handler != SIG_DFL)
72180@@ -811,6 +814,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
72181 }
72182 }
72183
72184+ /* allow glibc communication via tgkill to other threads in our
72185+ thread group */
72186+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
72187+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
72188+ && gr_handle_signal(t, sig))
72189+ return -EPERM;
72190+
72191 return security_task_kill(t, info, sig, 0);
72192 }
72193
72194@@ -1192,7 +1202,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
72195 return send_signal(sig, info, p, 1);
72196 }
72197
72198-static int
72199+int
72200 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
72201 {
72202 return send_signal(sig, info, t, 0);
72203@@ -1229,6 +1239,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
72204 unsigned long int flags;
72205 int ret, blocked, ignored;
72206 struct k_sigaction *action;
72207+ int is_unhandled = 0;
72208
72209 spin_lock_irqsave(&t->sighand->siglock, flags);
72210 action = &t->sighand->action[sig-1];
72211@@ -1243,9 +1254,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
72212 }
72213 if (action->sa.sa_handler == SIG_DFL)
72214 t->signal->flags &= ~SIGNAL_UNKILLABLE;
72215+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
72216+ is_unhandled = 1;
72217 ret = specific_send_sig_info(sig, info, t);
72218 spin_unlock_irqrestore(&t->sighand->siglock, flags);
72219
72220+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
72221+ normal operation */
72222+ if (is_unhandled) {
72223+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
72224+ gr_handle_crash(t, sig);
72225+ }
72226+
72227 return ret;
72228 }
72229
72230@@ -1312,8 +1332,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
72231 ret = check_kill_permission(sig, info, p);
72232 rcu_read_unlock();
72233
72234- if (!ret && sig)
72235+ if (!ret && sig) {
72236 ret = do_send_sig_info(sig, info, p, true);
72237+ if (!ret)
72238+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
72239+ }
72240
72241 return ret;
72242 }
72243@@ -2863,7 +2886,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
72244 int error = -ESRCH;
72245
72246 rcu_read_lock();
72247- p = find_task_by_vpid(pid);
72248+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
72249+ /* allow glibc communication via tgkill to other threads in our
72250+ thread group */
72251+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
72252+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
72253+ p = find_task_by_vpid_unrestricted(pid);
72254+ else
72255+#endif
72256+ p = find_task_by_vpid(pid);
72257 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
72258 error = check_kill_permission(sig, info, p);
72259 /*
72260diff --git a/kernel/softirq.c b/kernel/softirq.c
72261index cc96bdc..8bb9750 100644
72262--- a/kernel/softirq.c
72263+++ b/kernel/softirq.c
72264@@ -57,7 +57,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
72265
72266 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
72267
72268-char *softirq_to_name[NR_SOFTIRQS] = {
72269+const char * const softirq_to_name[NR_SOFTIRQS] = {
72270 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
72271 "TASKLET", "SCHED", "HRTIMER", "RCU"
72272 };
72273@@ -244,7 +244,7 @@ restart:
72274 kstat_incr_softirqs_this_cpu(vec_nr);
72275
72276 trace_softirq_entry(vec_nr);
72277- h->action(h);
72278+ h->action();
72279 trace_softirq_exit(vec_nr);
72280 if (unlikely(prev_count != preempt_count())) {
72281 printk(KERN_ERR "huh, entered softirq %u %s %p"
72282@@ -391,9 +391,11 @@ void __raise_softirq_irqoff(unsigned int nr)
72283 or_softirq_pending(1UL << nr);
72284 }
72285
72286-void open_softirq(int nr, void (*action)(struct softirq_action *))
72287+void open_softirq(int nr, void (*action)(void))
72288 {
72289- softirq_vec[nr].action = action;
72290+ pax_open_kernel();
72291+ *(void **)&softirq_vec[nr].action = action;
72292+ pax_close_kernel();
72293 }
72294
72295 /*
72296@@ -447,7 +449,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
72297
72298 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
72299
72300-static void tasklet_action(struct softirq_action *a)
72301+static void tasklet_action(void)
72302 {
72303 struct tasklet_struct *list;
72304
72305@@ -482,7 +484,7 @@ static void tasklet_action(struct softirq_action *a)
72306 }
72307 }
72308
72309-static void tasklet_hi_action(struct softirq_action *a)
72310+static void tasklet_hi_action(void)
72311 {
72312 struct tasklet_struct *list;
72313
72314diff --git a/kernel/srcu.c b/kernel/srcu.c
72315index 97c465e..d83f3bb 100644
72316--- a/kernel/srcu.c
72317+++ b/kernel/srcu.c
72318@@ -302,9 +302,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
72319 preempt_disable();
72320 idx = rcu_dereference_index_check(sp->completed,
72321 rcu_read_lock_sched_held()) & 0x1;
72322- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
72323+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
72324 smp_mb(); /* B */ /* Avoid leaking the critical section. */
72325- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
72326+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
72327 preempt_enable();
72328 return idx;
72329 }
72330@@ -320,7 +320,7 @@ void __srcu_read_unlock(struct srcu_struct *sp, int idx)
72331 {
72332 preempt_disable();
72333 smp_mb(); /* C */ /* Avoid leaking the critical section. */
72334- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
72335+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
72336 preempt_enable();
72337 }
72338 EXPORT_SYMBOL_GPL(__srcu_read_unlock);
72339diff --git a/kernel/sys.c b/kernel/sys.c
72340index e6e0ece..1f2e413 100644
72341--- a/kernel/sys.c
72342+++ b/kernel/sys.c
72343@@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
72344 error = -EACCES;
72345 goto out;
72346 }
72347+
72348+ if (gr_handle_chroot_setpriority(p, niceval)) {
72349+ error = -EACCES;
72350+ goto out;
72351+ }
72352+
72353 no_nice = security_task_setnice(p, niceval);
72354 if (no_nice) {
72355 error = no_nice;
72356@@ -595,6 +601,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
72357 goto error;
72358 }
72359
72360+ if (gr_check_group_change(new->gid, new->egid, -1))
72361+ goto error;
72362+
72363 if (rgid != (gid_t) -1 ||
72364 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
72365 new->sgid = new->egid;
72366@@ -630,6 +639,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
72367 old = current_cred();
72368
72369 retval = -EPERM;
72370+
72371+ if (gr_check_group_change(kgid, kgid, kgid))
72372+ goto error;
72373+
72374 if (nsown_capable(CAP_SETGID))
72375 new->gid = new->egid = new->sgid = new->fsgid = kgid;
72376 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
72377@@ -647,7 +660,7 @@ error:
72378 /*
72379 * change the user struct in a credentials set to match the new UID
72380 */
72381-static int set_user(struct cred *new)
72382+int set_user(struct cred *new)
72383 {
72384 struct user_struct *new_user;
72385
72386@@ -727,6 +740,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
72387 goto error;
72388 }
72389
72390+ if (gr_check_user_change(new->uid, new->euid, -1))
72391+ goto error;
72392+
72393 if (!uid_eq(new->uid, old->uid)) {
72394 retval = set_user(new);
72395 if (retval < 0)
72396@@ -777,6 +793,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
72397 old = current_cred();
72398
72399 retval = -EPERM;
72400+
72401+ if (gr_check_crash_uid(kuid))
72402+ goto error;
72403+ if (gr_check_user_change(kuid, kuid, kuid))
72404+ goto error;
72405+
72406 if (nsown_capable(CAP_SETUID)) {
72407 new->suid = new->uid = kuid;
72408 if (!uid_eq(kuid, old->uid)) {
72409@@ -846,6 +868,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
72410 goto error;
72411 }
72412
72413+ if (gr_check_user_change(kruid, keuid, -1))
72414+ goto error;
72415+
72416 if (ruid != (uid_t) -1) {
72417 new->uid = kruid;
72418 if (!uid_eq(kruid, old->uid)) {
72419@@ -928,6 +953,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
72420 goto error;
72421 }
72422
72423+ if (gr_check_group_change(krgid, kegid, -1))
72424+ goto error;
72425+
72426 if (rgid != (gid_t) -1)
72427 new->gid = krgid;
72428 if (egid != (gid_t) -1)
72429@@ -981,6 +1009,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
72430 if (!uid_valid(kuid))
72431 return old_fsuid;
72432
72433+ if (gr_check_user_change(-1, -1, kuid))
72434+ goto error;
72435+
72436 new = prepare_creds();
72437 if (!new)
72438 return old_fsuid;
72439@@ -995,6 +1026,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
72440 }
72441 }
72442
72443+error:
72444 abort_creds(new);
72445 return old_fsuid;
72446
72447@@ -1027,12 +1059,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
72448 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
72449 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
72450 nsown_capable(CAP_SETGID)) {
72451+ if (gr_check_group_change(-1, -1, kgid))
72452+ goto error;
72453+
72454 if (!gid_eq(kgid, old->fsgid)) {
72455 new->fsgid = kgid;
72456 goto change_okay;
72457 }
72458 }
72459
72460+error:
72461 abort_creds(new);
72462 return old_fsgid;
72463
72464@@ -1340,19 +1376,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
72465 return -EFAULT;
72466
72467 down_read(&uts_sem);
72468- error = __copy_to_user(&name->sysname, &utsname()->sysname,
72469+ error = __copy_to_user(name->sysname, &utsname()->sysname,
72470 __OLD_UTS_LEN);
72471 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
72472- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
72473+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
72474 __OLD_UTS_LEN);
72475 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
72476- error |= __copy_to_user(&name->release, &utsname()->release,
72477+ error |= __copy_to_user(name->release, &utsname()->release,
72478 __OLD_UTS_LEN);
72479 error |= __put_user(0, name->release + __OLD_UTS_LEN);
72480- error |= __copy_to_user(&name->version, &utsname()->version,
72481+ error |= __copy_to_user(name->version, &utsname()->version,
72482 __OLD_UTS_LEN);
72483 error |= __put_user(0, name->version + __OLD_UTS_LEN);
72484- error |= __copy_to_user(&name->machine, &utsname()->machine,
72485+ error |= __copy_to_user(name->machine, &utsname()->machine,
72486 __OLD_UTS_LEN);
72487 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
72488 up_read(&uts_sem);
72489@@ -2026,7 +2062,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
72490 error = get_dumpable(me->mm);
72491 break;
72492 case PR_SET_DUMPABLE:
72493- if (arg2 < 0 || arg2 > 1) {
72494+ if (arg2 > 1) {
72495 error = -EINVAL;
72496 break;
72497 }
72498diff --git a/kernel/sysctl.c b/kernel/sysctl.c
72499index 26f65ea..df8e5ad 100644
72500--- a/kernel/sysctl.c
72501+++ b/kernel/sysctl.c
72502@@ -92,7 +92,6 @@
72503
72504
72505 #if defined(CONFIG_SYSCTL)
72506-
72507 /* External variables not in a header file. */
72508 extern int sysctl_overcommit_memory;
72509 extern int sysctl_overcommit_ratio;
72510@@ -172,10 +171,8 @@ static int proc_taint(struct ctl_table *table, int write,
72511 void __user *buffer, size_t *lenp, loff_t *ppos);
72512 #endif
72513
72514-#ifdef CONFIG_PRINTK
72515 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
72516 void __user *buffer, size_t *lenp, loff_t *ppos);
72517-#endif
72518
72519 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
72520 void __user *buffer, size_t *lenp, loff_t *ppos);
72521@@ -206,6 +203,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
72522
72523 #endif
72524
72525+extern struct ctl_table grsecurity_table[];
72526+
72527 static struct ctl_table kern_table[];
72528 static struct ctl_table vm_table[];
72529 static struct ctl_table fs_table[];
72530@@ -220,6 +219,20 @@ extern struct ctl_table epoll_table[];
72531 int sysctl_legacy_va_layout;
72532 #endif
72533
72534+#ifdef CONFIG_PAX_SOFTMODE
72535+static ctl_table pax_table[] = {
72536+ {
72537+ .procname = "softmode",
72538+ .data = &pax_softmode,
72539+ .maxlen = sizeof(unsigned int),
72540+ .mode = 0600,
72541+ .proc_handler = &proc_dointvec,
72542+ },
72543+
72544+ { }
72545+};
72546+#endif
72547+
72548 /* The default sysctl tables: */
72549
72550 static struct ctl_table sysctl_base_table[] = {
72551@@ -266,6 +279,22 @@ static int max_extfrag_threshold = 1000;
72552 #endif
72553
72554 static struct ctl_table kern_table[] = {
72555+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
72556+ {
72557+ .procname = "grsecurity",
72558+ .mode = 0500,
72559+ .child = grsecurity_table,
72560+ },
72561+#endif
72562+
72563+#ifdef CONFIG_PAX_SOFTMODE
72564+ {
72565+ .procname = "pax",
72566+ .mode = 0500,
72567+ .child = pax_table,
72568+ },
72569+#endif
72570+
72571 {
72572 .procname = "sched_child_runs_first",
72573 .data = &sysctl_sched_child_runs_first,
72574@@ -552,7 +581,7 @@ static struct ctl_table kern_table[] = {
72575 .data = &modprobe_path,
72576 .maxlen = KMOD_PATH_LEN,
72577 .mode = 0644,
72578- .proc_handler = proc_dostring,
72579+ .proc_handler = proc_dostring_modpriv,
72580 },
72581 {
72582 .procname = "modules_disabled",
72583@@ -719,16 +748,20 @@ static struct ctl_table kern_table[] = {
72584 .extra1 = &zero,
72585 .extra2 = &one,
72586 },
72587+#endif
72588 {
72589 .procname = "kptr_restrict",
72590 .data = &kptr_restrict,
72591 .maxlen = sizeof(int),
72592 .mode = 0644,
72593 .proc_handler = proc_dointvec_minmax_sysadmin,
72594+#ifdef CONFIG_GRKERNSEC_HIDESYM
72595+ .extra1 = &two,
72596+#else
72597 .extra1 = &zero,
72598+#endif
72599 .extra2 = &two,
72600 },
72601-#endif
72602 {
72603 .procname = "ngroups_max",
72604 .data = &ngroups_max,
72605@@ -1225,6 +1258,13 @@ static struct ctl_table vm_table[] = {
72606 .proc_handler = proc_dointvec_minmax,
72607 .extra1 = &zero,
72608 },
72609+ {
72610+ .procname = "heap_stack_gap",
72611+ .data = &sysctl_heap_stack_gap,
72612+ .maxlen = sizeof(sysctl_heap_stack_gap),
72613+ .mode = 0644,
72614+ .proc_handler = proc_doulongvec_minmax,
72615+ },
72616 #else
72617 {
72618 .procname = "nr_trim_pages",
72619@@ -1675,6 +1715,16 @@ int proc_dostring(struct ctl_table *table, int write,
72620 buffer, lenp, ppos);
72621 }
72622
72623+int proc_dostring_modpriv(struct ctl_table *table, int write,
72624+ void __user *buffer, size_t *lenp, loff_t *ppos)
72625+{
72626+ if (write && !capable(CAP_SYS_MODULE))
72627+ return -EPERM;
72628+
72629+ return _proc_do_string(table->data, table->maxlen, write,
72630+ buffer, lenp, ppos);
72631+}
72632+
72633 static size_t proc_skip_spaces(char **buf)
72634 {
72635 size_t ret;
72636@@ -1780,6 +1830,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
72637 len = strlen(tmp);
72638 if (len > *size)
72639 len = *size;
72640+ if (len > sizeof(tmp))
72641+ len = sizeof(tmp);
72642 if (copy_to_user(*buf, tmp, len))
72643 return -EFAULT;
72644 *size -= len;
72645@@ -1972,7 +2024,6 @@ static int proc_taint(struct ctl_table *table, int write,
72646 return err;
72647 }
72648
72649-#ifdef CONFIG_PRINTK
72650 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
72651 void __user *buffer, size_t *lenp, loff_t *ppos)
72652 {
72653@@ -1981,7 +2032,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
72654
72655 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
72656 }
72657-#endif
72658
72659 struct do_proc_dointvec_minmax_conv_param {
72660 int *min;
72661@@ -2128,8 +2178,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
72662 *i = val;
72663 } else {
72664 val = convdiv * (*i) / convmul;
72665- if (!first)
72666+ if (!first) {
72667 err = proc_put_char(&buffer, &left, '\t');
72668+ if (err)
72669+ break;
72670+ }
72671 err = proc_put_long(&buffer, &left, val, false);
72672 if (err)
72673 break;
72674@@ -2521,6 +2574,12 @@ int proc_dostring(struct ctl_table *table, int write,
72675 return -ENOSYS;
72676 }
72677
72678+int proc_dostring_modpriv(struct ctl_table *table, int write,
72679+ void __user *buffer, size_t *lenp, loff_t *ppos)
72680+{
72681+ return -ENOSYS;
72682+}
72683+
72684 int proc_dointvec(struct ctl_table *table, int write,
72685 void __user *buffer, size_t *lenp, loff_t *ppos)
72686 {
72687@@ -2577,5 +2636,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
72688 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
72689 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
72690 EXPORT_SYMBOL(proc_dostring);
72691+EXPORT_SYMBOL(proc_dostring_modpriv);
72692 EXPORT_SYMBOL(proc_doulongvec_minmax);
72693 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
72694diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
72695index 65bdcf1..21eb831 100644
72696--- a/kernel/sysctl_binary.c
72697+++ b/kernel/sysctl_binary.c
72698@@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
72699 int i;
72700
72701 set_fs(KERNEL_DS);
72702- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
72703+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
72704 set_fs(old_fs);
72705 if (result < 0)
72706 goto out_kfree;
72707@@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
72708 }
72709
72710 set_fs(KERNEL_DS);
72711- result = vfs_write(file, buffer, str - buffer, &pos);
72712+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
72713 set_fs(old_fs);
72714 if (result < 0)
72715 goto out_kfree;
72716@@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
72717 int i;
72718
72719 set_fs(KERNEL_DS);
72720- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
72721+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
72722 set_fs(old_fs);
72723 if (result < 0)
72724 goto out_kfree;
72725@@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
72726 }
72727
72728 set_fs(KERNEL_DS);
72729- result = vfs_write(file, buffer, str - buffer, &pos);
72730+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
72731 set_fs(old_fs);
72732 if (result < 0)
72733 goto out_kfree;
72734@@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
72735 int i;
72736
72737 set_fs(KERNEL_DS);
72738- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
72739+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
72740 set_fs(old_fs);
72741 if (result < 0)
72742 goto out;
72743@@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
72744 __le16 dnaddr;
72745
72746 set_fs(KERNEL_DS);
72747- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
72748+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
72749 set_fs(old_fs);
72750 if (result < 0)
72751 goto out;
72752@@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
72753 le16_to_cpu(dnaddr) & 0x3ff);
72754
72755 set_fs(KERNEL_DS);
72756- result = vfs_write(file, buf, len, &pos);
72757+ result = vfs_write(file, (const char __force_user *)buf, len, &pos);
72758 set_fs(old_fs);
72759 if (result < 0)
72760 goto out;
72761diff --git a/kernel/taskstats.c b/kernel/taskstats.c
72762index 145bb4d..b2aa969 100644
72763--- a/kernel/taskstats.c
72764+++ b/kernel/taskstats.c
72765@@ -28,9 +28,12 @@
72766 #include <linux/fs.h>
72767 #include <linux/file.h>
72768 #include <linux/pid_namespace.h>
72769+#include <linux/grsecurity.h>
72770 #include <net/genetlink.h>
72771 #include <linux/atomic.h>
72772
72773+extern int gr_is_taskstats_denied(int pid);
72774+
72775 /*
72776 * Maximum length of a cpumask that can be specified in
72777 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
72778@@ -570,6 +573,9 @@ err:
72779
72780 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
72781 {
72782+ if (gr_is_taskstats_denied(current->pid))
72783+ return -EACCES;
72784+
72785 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
72786 return cmd_attr_register_cpumask(info);
72787 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
72788diff --git a/kernel/time.c b/kernel/time.c
72789index d226c6a..c7c0960 100644
72790--- a/kernel/time.c
72791+++ b/kernel/time.c
72792@@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
72793 return error;
72794
72795 if (tz) {
72796+ /* we log in do_settimeofday called below, so don't log twice
72797+ */
72798+ if (!tv)
72799+ gr_log_timechange();
72800+
72801 sys_tz = *tz;
72802 update_vsyscall_tz();
72803 if (firsttime) {
72804diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
72805index f11d83b..d016d91 100644
72806--- a/kernel/time/alarmtimer.c
72807+++ b/kernel/time/alarmtimer.c
72808@@ -750,7 +750,7 @@ static int __init alarmtimer_init(void)
72809 struct platform_device *pdev;
72810 int error = 0;
72811 int i;
72812- struct k_clock alarm_clock = {
72813+ static struct k_clock alarm_clock = {
72814 .clock_getres = alarm_clock_getres,
72815 .clock_get = alarm_clock_get,
72816 .timer_create = alarm_timer_create,
72817diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
72818index f113755..ec24223 100644
72819--- a/kernel/time/tick-broadcast.c
72820+++ b/kernel/time/tick-broadcast.c
72821@@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
72822 * then clear the broadcast bit.
72823 */
72824 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
72825- int cpu = smp_processor_id();
72826+ cpu = smp_processor_id();
72827
72828 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
72829 tick_broadcast_clear_oneshot(cpu);
72830diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
72831index e424970..4c7962b 100644
72832--- a/kernel/time/timekeeping.c
72833+++ b/kernel/time/timekeeping.c
72834@@ -15,6 +15,7 @@
72835 #include <linux/init.h>
72836 #include <linux/mm.h>
72837 #include <linux/sched.h>
72838+#include <linux/grsecurity.h>
72839 #include <linux/syscore_ops.h>
72840 #include <linux/clocksource.h>
72841 #include <linux/jiffies.h>
72842@@ -368,6 +369,8 @@ int do_settimeofday(const struct timespec *tv)
72843 if (!timespec_valid_strict(tv))
72844 return -EINVAL;
72845
72846+ gr_log_timechange();
72847+
72848 write_seqlock_irqsave(&tk->lock, flags);
72849
72850 timekeeping_forward_now(tk);
72851diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
72852index af5a7e9..715611a 100644
72853--- a/kernel/time/timer_list.c
72854+++ b/kernel/time/timer_list.c
72855@@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
72856
72857 static void print_name_offset(struct seq_file *m, void *sym)
72858 {
72859+#ifdef CONFIG_GRKERNSEC_HIDESYM
72860+ SEQ_printf(m, "<%p>", NULL);
72861+#else
72862 char symname[KSYM_NAME_LEN];
72863
72864 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
72865 SEQ_printf(m, "<%pK>", sym);
72866 else
72867 SEQ_printf(m, "%s", symname);
72868+#endif
72869 }
72870
72871 static void
72872@@ -112,7 +116,11 @@ next_one:
72873 static void
72874 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
72875 {
72876+#ifdef CONFIG_GRKERNSEC_HIDESYM
72877+ SEQ_printf(m, " .base: %p\n", NULL);
72878+#else
72879 SEQ_printf(m, " .base: %pK\n", base);
72880+#endif
72881 SEQ_printf(m, " .index: %d\n",
72882 base->index);
72883 SEQ_printf(m, " .resolution: %Lu nsecs\n",
72884@@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
72885 {
72886 struct proc_dir_entry *pe;
72887
72888+#ifdef CONFIG_GRKERNSEC_PROC_ADD
72889+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
72890+#else
72891 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
72892+#endif
72893 if (!pe)
72894 return -ENOMEM;
72895 return 0;
72896diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
72897index 0b537f2..40d6c20 100644
72898--- a/kernel/time/timer_stats.c
72899+++ b/kernel/time/timer_stats.c
72900@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
72901 static unsigned long nr_entries;
72902 static struct entry entries[MAX_ENTRIES];
72903
72904-static atomic_t overflow_count;
72905+static atomic_unchecked_t overflow_count;
72906
72907 /*
72908 * The entries are in a hash-table, for fast lookup:
72909@@ -140,7 +140,7 @@ static void reset_entries(void)
72910 nr_entries = 0;
72911 memset(entries, 0, sizeof(entries));
72912 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
72913- atomic_set(&overflow_count, 0);
72914+ atomic_set_unchecked(&overflow_count, 0);
72915 }
72916
72917 static struct entry *alloc_entry(void)
72918@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
72919 if (likely(entry))
72920 entry->count++;
72921 else
72922- atomic_inc(&overflow_count);
72923+ atomic_inc_unchecked(&overflow_count);
72924
72925 out_unlock:
72926 raw_spin_unlock_irqrestore(lock, flags);
72927@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
72928
72929 static void print_name_offset(struct seq_file *m, unsigned long addr)
72930 {
72931+#ifdef CONFIG_GRKERNSEC_HIDESYM
72932+ seq_printf(m, "<%p>", NULL);
72933+#else
72934 char symname[KSYM_NAME_LEN];
72935
72936 if (lookup_symbol_name(addr, symname) < 0)
72937- seq_printf(m, "<%p>", (void *)addr);
72938+ seq_printf(m, "<%pK>", (void *)addr);
72939 else
72940 seq_printf(m, "%s", symname);
72941+#endif
72942 }
72943
72944 static int tstats_show(struct seq_file *m, void *v)
72945@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
72946
72947 seq_puts(m, "Timer Stats Version: v0.2\n");
72948 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
72949- if (atomic_read(&overflow_count))
72950+ if (atomic_read_unchecked(&overflow_count))
72951 seq_printf(m, "Overflow: %d entries\n",
72952- atomic_read(&overflow_count));
72953+ atomic_read_unchecked(&overflow_count));
72954
72955 for (i = 0; i < nr_entries; i++) {
72956 entry = entries + i;
72957@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
72958 {
72959 struct proc_dir_entry *pe;
72960
72961+#ifdef CONFIG_GRKERNSEC_PROC_ADD
72962+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
72963+#else
72964 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
72965+#endif
72966 if (!pe)
72967 return -ENOMEM;
72968 return 0;
72969diff --git a/kernel/timer.c b/kernel/timer.c
72970index 367d008..46857a0 100644
72971--- a/kernel/timer.c
72972+++ b/kernel/timer.c
72973@@ -1363,7 +1363,7 @@ void update_process_times(int user_tick)
72974 /*
72975 * This function runs timers and the timer-tq in bottom half context.
72976 */
72977-static void run_timer_softirq(struct softirq_action *h)
72978+static void run_timer_softirq(void)
72979 {
72980 struct tvec_base *base = __this_cpu_read(tvec_bases);
72981
72982@@ -1772,7 +1772,7 @@ static int __cpuinit timer_cpu_notify(struct notifier_block *self,
72983 return NOTIFY_OK;
72984 }
72985
72986-static struct notifier_block __cpuinitdata timers_nb = {
72987+static struct notifier_block __cpuinitconst timers_nb = {
72988 .notifier_call = timer_cpu_notify,
72989 };
72990
72991diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
72992index c0bd030..62a1927 100644
72993--- a/kernel/trace/blktrace.c
72994+++ b/kernel/trace/blktrace.c
72995@@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
72996 struct blk_trace *bt = filp->private_data;
72997 char buf[16];
72998
72999- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
73000+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
73001
73002 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
73003 }
73004@@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
73005 return 1;
73006
73007 bt = buf->chan->private_data;
73008- atomic_inc(&bt->dropped);
73009+ atomic_inc_unchecked(&bt->dropped);
73010 return 0;
73011 }
73012
73013@@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
73014
73015 bt->dir = dir;
73016 bt->dev = dev;
73017- atomic_set(&bt->dropped, 0);
73018+ atomic_set_unchecked(&bt->dropped, 0);
73019
73020 ret = -EIO;
73021 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
73022diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
73023index 356bc2f..7c94fc0 100644
73024--- a/kernel/trace/ftrace.c
73025+++ b/kernel/trace/ftrace.c
73026@@ -1874,12 +1874,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
73027 if (unlikely(ftrace_disabled))
73028 return 0;
73029
73030+ ret = ftrace_arch_code_modify_prepare();
73031+ FTRACE_WARN_ON(ret);
73032+ if (ret)
73033+ return 0;
73034+
73035 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
73036+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
73037 if (ret) {
73038 ftrace_bug(ret, ip);
73039- return 0;
73040 }
73041- return 1;
73042+ return ret ? 0 : 1;
73043 }
73044
73045 /*
73046@@ -2965,7 +2970,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
73047
73048 int
73049 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
73050- void *data)
73051+ void *data)
73052 {
73053 struct ftrace_func_probe *entry;
73054 struct ftrace_page *pg;
73055@@ -3832,8 +3837,10 @@ static int ftrace_process_locs(struct module *mod,
73056 if (!count)
73057 return 0;
73058
73059+ pax_open_kernel();
73060 sort(start, count, sizeof(*start),
73061 ftrace_cmp_ips, ftrace_swap_ips);
73062+ pax_close_kernel();
73063
73064 start_pg = ftrace_allocate_pages(count);
73065 if (!start_pg)
73066@@ -4541,8 +4548,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
73067 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
73068
73069 static int ftrace_graph_active;
73070-static struct notifier_block ftrace_suspend_notifier;
73071-
73072 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
73073 {
73074 return 0;
73075@@ -4686,6 +4691,10 @@ ftrace_suspend_notifier_call(struct notifier_block *bl, unsigned long state,
73076 return NOTIFY_DONE;
73077 }
73078
73079+static struct notifier_block ftrace_suspend_notifier = {
73080+ .notifier_call = ftrace_suspend_notifier_call
73081+};
73082+
73083 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
73084 trace_func_graph_ent_t entryfunc)
73085 {
73086@@ -4699,7 +4708,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
73087 goto out;
73088 }
73089
73090- ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
73091 register_pm_notifier(&ftrace_suspend_notifier);
73092
73093 ftrace_graph_active++;
73094diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
73095index 4cb5e51..e7e05d9 100644
73096--- a/kernel/trace/ring_buffer.c
73097+++ b/kernel/trace/ring_buffer.c
73098@@ -346,9 +346,9 @@ struct buffer_data_page {
73099 */
73100 struct buffer_page {
73101 struct list_head list; /* list of buffer pages */
73102- local_t write; /* index for next write */
73103+ local_unchecked_t write; /* index for next write */
73104 unsigned read; /* index for next read */
73105- local_t entries; /* entries on this page */
73106+ local_unchecked_t entries; /* entries on this page */
73107 unsigned long real_end; /* real end of data */
73108 struct buffer_data_page *page; /* Actual data page */
73109 };
73110@@ -460,8 +460,8 @@ struct ring_buffer_per_cpu {
73111 unsigned long lost_events;
73112 unsigned long last_overrun;
73113 local_t entries_bytes;
73114- local_t commit_overrun;
73115- local_t overrun;
73116+ local_unchecked_t commit_overrun;
73117+ local_unchecked_t overrun;
73118 local_t entries;
73119 local_t committing;
73120 local_t commits;
73121@@ -860,8 +860,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
73122 *
73123 * We add a counter to the write field to denote this.
73124 */
73125- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
73126- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
73127+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
73128+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
73129
73130 /*
73131 * Just make sure we have seen our old_write and synchronize
73132@@ -889,8 +889,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
73133 * cmpxchg to only update if an interrupt did not already
73134 * do it for us. If the cmpxchg fails, we don't care.
73135 */
73136- (void)local_cmpxchg(&next_page->write, old_write, val);
73137- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
73138+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
73139+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
73140
73141 /*
73142 * No need to worry about races with clearing out the commit.
73143@@ -1249,12 +1249,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
73144
73145 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
73146 {
73147- return local_read(&bpage->entries) & RB_WRITE_MASK;
73148+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
73149 }
73150
73151 static inline unsigned long rb_page_write(struct buffer_page *bpage)
73152 {
73153- return local_read(&bpage->write) & RB_WRITE_MASK;
73154+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
73155 }
73156
73157 static int
73158@@ -1349,7 +1349,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
73159 * bytes consumed in ring buffer from here.
73160 * Increment overrun to account for the lost events.
73161 */
73162- local_add(page_entries, &cpu_buffer->overrun);
73163+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
73164 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
73165 }
73166
73167@@ -1905,7 +1905,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
73168 * it is our responsibility to update
73169 * the counters.
73170 */
73171- local_add(entries, &cpu_buffer->overrun);
73172+ local_add_unchecked(entries, &cpu_buffer->overrun);
73173 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
73174
73175 /*
73176@@ -2055,7 +2055,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
73177 if (tail == BUF_PAGE_SIZE)
73178 tail_page->real_end = 0;
73179
73180- local_sub(length, &tail_page->write);
73181+ local_sub_unchecked(length, &tail_page->write);
73182 return;
73183 }
73184
73185@@ -2090,7 +2090,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
73186 rb_event_set_padding(event);
73187
73188 /* Set the write back to the previous setting */
73189- local_sub(length, &tail_page->write);
73190+ local_sub_unchecked(length, &tail_page->write);
73191 return;
73192 }
73193
73194@@ -2102,7 +2102,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
73195
73196 /* Set write to end of buffer */
73197 length = (tail + length) - BUF_PAGE_SIZE;
73198- local_sub(length, &tail_page->write);
73199+ local_sub_unchecked(length, &tail_page->write);
73200 }
73201
73202 /*
73203@@ -2128,7 +2128,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
73204 * about it.
73205 */
73206 if (unlikely(next_page == commit_page)) {
73207- local_inc(&cpu_buffer->commit_overrun);
73208+ local_inc_unchecked(&cpu_buffer->commit_overrun);
73209 goto out_reset;
73210 }
73211
73212@@ -2182,7 +2182,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
73213 cpu_buffer->tail_page) &&
73214 (cpu_buffer->commit_page ==
73215 cpu_buffer->reader_page))) {
73216- local_inc(&cpu_buffer->commit_overrun);
73217+ local_inc_unchecked(&cpu_buffer->commit_overrun);
73218 goto out_reset;
73219 }
73220 }
73221@@ -2230,7 +2230,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
73222 length += RB_LEN_TIME_EXTEND;
73223
73224 tail_page = cpu_buffer->tail_page;
73225- write = local_add_return(length, &tail_page->write);
73226+ write = local_add_return_unchecked(length, &tail_page->write);
73227
73228 /* set write to only the index of the write */
73229 write &= RB_WRITE_MASK;
73230@@ -2247,7 +2247,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
73231 kmemcheck_annotate_bitfield(event, bitfield);
73232 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
73233
73234- local_inc(&tail_page->entries);
73235+ local_inc_unchecked(&tail_page->entries);
73236
73237 /*
73238 * If this is the first commit on the page, then update
73239@@ -2280,7 +2280,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
73240
73241 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
73242 unsigned long write_mask =
73243- local_read(&bpage->write) & ~RB_WRITE_MASK;
73244+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
73245 unsigned long event_length = rb_event_length(event);
73246 /*
73247 * This is on the tail page. It is possible that
73248@@ -2290,7 +2290,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
73249 */
73250 old_index += write_mask;
73251 new_index += write_mask;
73252- index = local_cmpxchg(&bpage->write, old_index, new_index);
73253+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
73254 if (index == old_index) {
73255 /* update counters */
73256 local_sub(event_length, &cpu_buffer->entries_bytes);
73257@@ -2629,7 +2629,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
73258
73259 /* Do the likely case first */
73260 if (likely(bpage->page == (void *)addr)) {
73261- local_dec(&bpage->entries);
73262+ local_dec_unchecked(&bpage->entries);
73263 return;
73264 }
73265
73266@@ -2641,7 +2641,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
73267 start = bpage;
73268 do {
73269 if (bpage->page == (void *)addr) {
73270- local_dec(&bpage->entries);
73271+ local_dec_unchecked(&bpage->entries);
73272 return;
73273 }
73274 rb_inc_page(cpu_buffer, &bpage);
73275@@ -2923,7 +2923,7 @@ static inline unsigned long
73276 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
73277 {
73278 return local_read(&cpu_buffer->entries) -
73279- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
73280+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
73281 }
73282
73283 /**
73284@@ -3011,7 +3011,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
73285 return 0;
73286
73287 cpu_buffer = buffer->buffers[cpu];
73288- ret = local_read(&cpu_buffer->overrun);
73289+ ret = local_read_unchecked(&cpu_buffer->overrun);
73290
73291 return ret;
73292 }
73293@@ -3032,7 +3032,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
73294 return 0;
73295
73296 cpu_buffer = buffer->buffers[cpu];
73297- ret = local_read(&cpu_buffer->commit_overrun);
73298+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
73299
73300 return ret;
73301 }
73302@@ -3077,7 +3077,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
73303 /* if you care about this being correct, lock the buffer */
73304 for_each_buffer_cpu(buffer, cpu) {
73305 cpu_buffer = buffer->buffers[cpu];
73306- overruns += local_read(&cpu_buffer->overrun);
73307+ overruns += local_read_unchecked(&cpu_buffer->overrun);
73308 }
73309
73310 return overruns;
73311@@ -3253,8 +3253,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
73312 /*
73313 * Reset the reader page to size zero.
73314 */
73315- local_set(&cpu_buffer->reader_page->write, 0);
73316- local_set(&cpu_buffer->reader_page->entries, 0);
73317+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
73318+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
73319 local_set(&cpu_buffer->reader_page->page->commit, 0);
73320 cpu_buffer->reader_page->real_end = 0;
73321
73322@@ -3288,7 +3288,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
73323 * want to compare with the last_overrun.
73324 */
73325 smp_mb();
73326- overwrite = local_read(&(cpu_buffer->overrun));
73327+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
73328
73329 /*
73330 * Here's the tricky part.
73331@@ -3858,8 +3858,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
73332
73333 cpu_buffer->head_page
73334 = list_entry(cpu_buffer->pages, struct buffer_page, list);
73335- local_set(&cpu_buffer->head_page->write, 0);
73336- local_set(&cpu_buffer->head_page->entries, 0);
73337+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
73338+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
73339 local_set(&cpu_buffer->head_page->page->commit, 0);
73340
73341 cpu_buffer->head_page->read = 0;
73342@@ -3869,14 +3869,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
73343
73344 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
73345 INIT_LIST_HEAD(&cpu_buffer->new_pages);
73346- local_set(&cpu_buffer->reader_page->write, 0);
73347- local_set(&cpu_buffer->reader_page->entries, 0);
73348+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
73349+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
73350 local_set(&cpu_buffer->reader_page->page->commit, 0);
73351 cpu_buffer->reader_page->read = 0;
73352
73353- local_set(&cpu_buffer->commit_overrun, 0);
73354+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
73355 local_set(&cpu_buffer->entries_bytes, 0);
73356- local_set(&cpu_buffer->overrun, 0);
73357+ local_set_unchecked(&cpu_buffer->overrun, 0);
73358 local_set(&cpu_buffer->entries, 0);
73359 local_set(&cpu_buffer->committing, 0);
73360 local_set(&cpu_buffer->commits, 0);
73361@@ -4279,8 +4279,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
73362 rb_init_page(bpage);
73363 bpage = reader->page;
73364 reader->page = *data_page;
73365- local_set(&reader->write, 0);
73366- local_set(&reader->entries, 0);
73367+ local_set_unchecked(&reader->write, 0);
73368+ local_set_unchecked(&reader->entries, 0);
73369 reader->read = 0;
73370 *data_page = bpage;
73371
73372diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
73373index 31e4f55..62da00f 100644
73374--- a/kernel/trace/trace.c
73375+++ b/kernel/trace/trace.c
73376@@ -4436,10 +4436,9 @@ static const struct file_operations tracing_dyn_info_fops = {
73377 };
73378 #endif
73379
73380-static struct dentry *d_tracer;
73381-
73382 struct dentry *tracing_init_dentry(void)
73383 {
73384+ static struct dentry *d_tracer;
73385 static int once;
73386
73387 if (d_tracer)
73388@@ -4459,10 +4458,9 @@ struct dentry *tracing_init_dentry(void)
73389 return d_tracer;
73390 }
73391
73392-static struct dentry *d_percpu;
73393-
73394 struct dentry *tracing_dentry_percpu(void)
73395 {
73396+ static struct dentry *d_percpu;
73397 static int once;
73398 struct dentry *d_tracer;
73399
73400diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
73401index d608d09..7eddcb1 100644
73402--- a/kernel/trace/trace_events.c
73403+++ b/kernel/trace/trace_events.c
73404@@ -1320,10 +1320,6 @@ static LIST_HEAD(ftrace_module_file_list);
73405 struct ftrace_module_file_ops {
73406 struct list_head list;
73407 struct module *mod;
73408- struct file_operations id;
73409- struct file_operations enable;
73410- struct file_operations format;
73411- struct file_operations filter;
73412 };
73413
73414 static struct ftrace_module_file_ops *
73415@@ -1344,17 +1340,12 @@ trace_create_file_ops(struct module *mod)
73416
73417 file_ops->mod = mod;
73418
73419- file_ops->id = ftrace_event_id_fops;
73420- file_ops->id.owner = mod;
73421-
73422- file_ops->enable = ftrace_enable_fops;
73423- file_ops->enable.owner = mod;
73424-
73425- file_ops->filter = ftrace_event_filter_fops;
73426- file_ops->filter.owner = mod;
73427-
73428- file_ops->format = ftrace_event_format_fops;
73429- file_ops->format.owner = mod;
73430+ pax_open_kernel();
73431+ *(void **)&mod->trace_id.owner = mod;
73432+ *(void **)&mod->trace_enable.owner = mod;
73433+ *(void **)&mod->trace_filter.owner = mod;
73434+ *(void **)&mod->trace_format.owner = mod;
73435+ pax_close_kernel();
73436
73437 list_add(&file_ops->list, &ftrace_module_file_list);
73438
73439@@ -1378,8 +1369,8 @@ static void trace_module_add_events(struct module *mod)
73440
73441 for_each_event(call, start, end) {
73442 __trace_add_event_call(*call, mod,
73443- &file_ops->id, &file_ops->enable,
73444- &file_ops->filter, &file_ops->format);
73445+ &mod->trace_id, &mod->trace_enable,
73446+ &mod->trace_filter, &mod->trace_format);
73447 }
73448 }
73449
73450diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
73451index fd3c8aa..5f324a6 100644
73452--- a/kernel/trace/trace_mmiotrace.c
73453+++ b/kernel/trace/trace_mmiotrace.c
73454@@ -24,7 +24,7 @@ struct header_iter {
73455 static struct trace_array *mmio_trace_array;
73456 static bool overrun_detected;
73457 static unsigned long prev_overruns;
73458-static atomic_t dropped_count;
73459+static atomic_unchecked_t dropped_count;
73460
73461 static void mmio_reset_data(struct trace_array *tr)
73462 {
73463@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
73464
73465 static unsigned long count_overruns(struct trace_iterator *iter)
73466 {
73467- unsigned long cnt = atomic_xchg(&dropped_count, 0);
73468+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
73469 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
73470
73471 if (over > prev_overruns)
73472@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
73473 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
73474 sizeof(*entry), 0, pc);
73475 if (!event) {
73476- atomic_inc(&dropped_count);
73477+ atomic_inc_unchecked(&dropped_count);
73478 return;
73479 }
73480 entry = ring_buffer_event_data(event);
73481@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
73482 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
73483 sizeof(*entry), 0, pc);
73484 if (!event) {
73485- atomic_inc(&dropped_count);
73486+ atomic_inc_unchecked(&dropped_count);
73487 return;
73488 }
73489 entry = ring_buffer_event_data(event);
73490diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
73491index 123b189..1e9e2a6 100644
73492--- a/kernel/trace/trace_output.c
73493+++ b/kernel/trace/trace_output.c
73494@@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
73495
73496 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
73497 if (!IS_ERR(p)) {
73498- p = mangle_path(s->buffer + s->len, p, "\n");
73499+ p = mangle_path(s->buffer + s->len, p, "\n\\");
73500 if (p) {
73501 s->len = p - s->buffer;
73502 return 1;
73503@@ -824,14 +824,16 @@ int register_ftrace_event(struct trace_event *event)
73504 goto out;
73505 }
73506
73507+ pax_open_kernel();
73508 if (event->funcs->trace == NULL)
73509- event->funcs->trace = trace_nop_print;
73510+ *(void **)&event->funcs->trace = trace_nop_print;
73511 if (event->funcs->raw == NULL)
73512- event->funcs->raw = trace_nop_print;
73513+ *(void **)&event->funcs->raw = trace_nop_print;
73514 if (event->funcs->hex == NULL)
73515- event->funcs->hex = trace_nop_print;
73516+ *(void **)&event->funcs->hex = trace_nop_print;
73517 if (event->funcs->binary == NULL)
73518- event->funcs->binary = trace_nop_print;
73519+ *(void **)&event->funcs->binary = trace_nop_print;
73520+ pax_close_kernel();
73521
73522 key = event->type & (EVENT_HASHSIZE - 1);
73523
73524diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
73525index 0c1b1657..95337e9 100644
73526--- a/kernel/trace/trace_stack.c
73527+++ b/kernel/trace/trace_stack.c
73528@@ -53,7 +53,7 @@ static inline void check_stack(void)
73529 return;
73530
73531 /* we do not handle interrupt stacks yet */
73532- if (!object_is_on_stack(&this_size))
73533+ if (!object_starts_on_stack(&this_size))
73534 return;
73535
73536 local_irq_save(flags);
73537diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
73538index 28e9d6c9..50381bd 100644
73539--- a/lib/Kconfig.debug
73540+++ b/lib/Kconfig.debug
73541@@ -1278,6 +1278,7 @@ config LATENCYTOP
73542 depends on DEBUG_KERNEL
73543 depends on STACKTRACE_SUPPORT
73544 depends on PROC_FS
73545+ depends on !GRKERNSEC_HIDESYM
73546 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
73547 select KALLSYMS
73548 select KALLSYMS_ALL
73549@@ -1306,7 +1307,7 @@ config INTERVAL_TREE_TEST
73550
73551 config PROVIDE_OHCI1394_DMA_INIT
73552 bool "Remote debugging over FireWire early on boot"
73553- depends on PCI && X86
73554+ depends on PCI && X86 && !GRKERNSEC
73555 help
73556 If you want to debug problems which hang or crash the kernel early
73557 on boot and the crashing machine has a FireWire port, you can use
73558@@ -1335,7 +1336,7 @@ config PROVIDE_OHCI1394_DMA_INIT
73559
73560 config FIREWIRE_OHCI_REMOTE_DMA
73561 bool "Remote debugging over FireWire with firewire-ohci"
73562- depends on FIREWIRE_OHCI
73563+ depends on FIREWIRE_OHCI && !GRKERNSEC
73564 help
73565 This option lets you use the FireWire bus for remote debugging
73566 with help of the firewire-ohci driver. It enables unfiltered
73567diff --git a/lib/Makefile b/lib/Makefile
73568index a08b791..a3ff1eb 100644
73569--- a/lib/Makefile
73570+++ b/lib/Makefile
73571@@ -46,7 +46,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
73572
73573 obj-$(CONFIG_BTREE) += btree.o
73574 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
73575-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
73576+obj-y += list_debug.o
73577 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
73578
73579 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
73580diff --git a/lib/bitmap.c b/lib/bitmap.c
73581index 06fdfa1..97c5c7d 100644
73582--- a/lib/bitmap.c
73583+++ b/lib/bitmap.c
73584@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
73585 {
73586 int c, old_c, totaldigits, ndigits, nchunks, nbits;
73587 u32 chunk;
73588- const char __user __force *ubuf = (const char __user __force *)buf;
73589+ const char __user *ubuf = (const char __force_user *)buf;
73590
73591 bitmap_zero(maskp, nmaskbits);
73592
73593@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
73594 {
73595 if (!access_ok(VERIFY_READ, ubuf, ulen))
73596 return -EFAULT;
73597- return __bitmap_parse((const char __force *)ubuf,
73598+ return __bitmap_parse((const char __force_kernel *)ubuf,
73599 ulen, 1, maskp, nmaskbits);
73600
73601 }
73602@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
73603 {
73604 unsigned a, b;
73605 int c, old_c, totaldigits;
73606- const char __user __force *ubuf = (const char __user __force *)buf;
73607+ const char __user *ubuf = (const char __force_user *)buf;
73608 int exp_digit, in_range;
73609
73610 totaldigits = c = 0;
73611@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
73612 {
73613 if (!access_ok(VERIFY_READ, ubuf, ulen))
73614 return -EFAULT;
73615- return __bitmap_parselist((const char __force *)ubuf,
73616+ return __bitmap_parselist((const char __force_kernel *)ubuf,
73617 ulen, 1, maskp, nmaskbits);
73618 }
73619 EXPORT_SYMBOL(bitmap_parselist_user);
73620diff --git a/lib/bug.c b/lib/bug.c
73621index d0cdf14..4d07bd2 100644
73622--- a/lib/bug.c
73623+++ b/lib/bug.c
73624@@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
73625 return BUG_TRAP_TYPE_NONE;
73626
73627 bug = find_bug(bugaddr);
73628+ if (!bug)
73629+ return BUG_TRAP_TYPE_NONE;
73630
73631 file = NULL;
73632 line = 0;
73633diff --git a/lib/debugobjects.c b/lib/debugobjects.c
73634index d11808c..dc2d6f8 100644
73635--- a/lib/debugobjects.c
73636+++ b/lib/debugobjects.c
73637@@ -287,7 +287,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
73638 if (limit > 4)
73639 return;
73640
73641- is_on_stack = object_is_on_stack(addr);
73642+ is_on_stack = object_starts_on_stack(addr);
73643 if (is_on_stack == onstack)
73644 return;
73645
73646diff --git a/lib/devres.c b/lib/devres.c
73647index 80b9c76..9e32279 100644
73648--- a/lib/devres.c
73649+++ b/lib/devres.c
73650@@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
73651 void devm_iounmap(struct device *dev, void __iomem *addr)
73652 {
73653 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
73654- (void *)addr));
73655+ (void __force *)addr));
73656 iounmap(addr);
73657 }
73658 EXPORT_SYMBOL(devm_iounmap);
73659@@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
73660 {
73661 ioport_unmap(addr);
73662 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
73663- devm_ioport_map_match, (void *)addr));
73664+ devm_ioport_map_match, (void __force *)addr));
73665 }
73666 EXPORT_SYMBOL(devm_ioport_unmap);
73667
73668diff --git a/lib/dma-debug.c b/lib/dma-debug.c
73669index d84beb9..da44791 100644
73670--- a/lib/dma-debug.c
73671+++ b/lib/dma-debug.c
73672@@ -754,7 +754,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
73673
73674 void dma_debug_add_bus(struct bus_type *bus)
73675 {
73676- struct notifier_block *nb;
73677+ notifier_block_no_const *nb;
73678
73679 if (global_disable)
73680 return;
73681@@ -919,7 +919,7 @@ out:
73682
73683 static void check_for_stack(struct device *dev, void *addr)
73684 {
73685- if (object_is_on_stack(addr))
73686+ if (object_starts_on_stack(addr))
73687 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
73688 "stack [addr=%p]\n", addr);
73689 }
73690diff --git a/lib/inflate.c b/lib/inflate.c
73691index 013a761..c28f3fc 100644
73692--- a/lib/inflate.c
73693+++ b/lib/inflate.c
73694@@ -269,7 +269,7 @@ static void free(void *where)
73695 malloc_ptr = free_mem_ptr;
73696 }
73697 #else
73698-#define malloc(a) kmalloc(a, GFP_KERNEL)
73699+#define malloc(a) kmalloc((a), GFP_KERNEL)
73700 #define free(a) kfree(a)
73701 #endif
73702
73703diff --git a/lib/ioremap.c b/lib/ioremap.c
73704index 0c9216c..863bd89 100644
73705--- a/lib/ioremap.c
73706+++ b/lib/ioremap.c
73707@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
73708 unsigned long next;
73709
73710 phys_addr -= addr;
73711- pmd = pmd_alloc(&init_mm, pud, addr);
73712+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
73713 if (!pmd)
73714 return -ENOMEM;
73715 do {
73716@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
73717 unsigned long next;
73718
73719 phys_addr -= addr;
73720- pud = pud_alloc(&init_mm, pgd, addr);
73721+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
73722 if (!pud)
73723 return -ENOMEM;
73724 do {
73725diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
73726index bd2bea9..6b3c95e 100644
73727--- a/lib/is_single_threaded.c
73728+++ b/lib/is_single_threaded.c
73729@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
73730 struct task_struct *p, *t;
73731 bool ret;
73732
73733+ if (!mm)
73734+ return true;
73735+
73736 if (atomic_read(&task->signal->live) != 1)
73737 return false;
73738
73739diff --git a/lib/list_debug.c b/lib/list_debug.c
73740index c24c2f7..3fc5da0 100644
73741--- a/lib/list_debug.c
73742+++ b/lib/list_debug.c
73743@@ -11,7 +11,9 @@
73744 #include <linux/bug.h>
73745 #include <linux/kernel.h>
73746 #include <linux/rculist.h>
73747+#include <linux/mm.h>
73748
73749+#ifdef CONFIG_DEBUG_LIST
73750 /*
73751 * Insert a new entry between two known consecutive entries.
73752 *
73753@@ -19,21 +21,32 @@
73754 * the prev/next entries already!
73755 */
73756
73757-void __list_add(struct list_head *new,
73758- struct list_head *prev,
73759- struct list_head *next)
73760+static bool __list_add_debug(struct list_head *new,
73761+ struct list_head *prev,
73762+ struct list_head *next)
73763 {
73764- WARN(next->prev != prev,
73765+ if (WARN(next->prev != prev,
73766 "list_add corruption. next->prev should be "
73767 "prev (%p), but was %p. (next=%p).\n",
73768- prev, next->prev, next);
73769- WARN(prev->next != next,
73770+ prev, next->prev, next) ||
73771+ WARN(prev->next != next,
73772 "list_add corruption. prev->next should be "
73773 "next (%p), but was %p. (prev=%p).\n",
73774- next, prev->next, prev);
73775- WARN(new == prev || new == next,
73776+ next, prev->next, prev) ||
73777+ WARN(new == prev || new == next,
73778 "list_add double add: new=%p, prev=%p, next=%p.\n",
73779- new, prev, next);
73780+ new, prev, next))
73781+ return false;
73782+ return true;
73783+}
73784+
73785+void __list_add(struct list_head *new,
73786+ struct list_head *prev,
73787+ struct list_head *next)
73788+{
73789+ if (!__list_add_debug(new, prev, next))
73790+ return;
73791+
73792 next->prev = new;
73793 new->next = next;
73794 new->prev = prev;
73795@@ -41,7 +54,7 @@ void __list_add(struct list_head *new,
73796 }
73797 EXPORT_SYMBOL(__list_add);
73798
73799-void __list_del_entry(struct list_head *entry)
73800+static bool __list_del_entry_debug(struct list_head *entry)
73801 {
73802 struct list_head *prev, *next;
73803
73804@@ -60,9 +73,16 @@ void __list_del_entry(struct list_head *entry)
73805 WARN(next->prev != entry,
73806 "list_del corruption. next->prev should be %p, "
73807 "but was %p\n", entry, next->prev))
73808+ return false;
73809+ return true;
73810+}
73811+
73812+void __list_del_entry(struct list_head *entry)
73813+{
73814+ if (!__list_del_entry_debug(entry))
73815 return;
73816
73817- __list_del(prev, next);
73818+ __list_del(entry->prev, entry->next);
73819 }
73820 EXPORT_SYMBOL(__list_del_entry);
73821
73822@@ -86,15 +106,54 @@ EXPORT_SYMBOL(list_del);
73823 void __list_add_rcu(struct list_head *new,
73824 struct list_head *prev, struct list_head *next)
73825 {
73826- WARN(next->prev != prev,
73827+ if (WARN(next->prev != prev,
73828 "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
73829- prev, next->prev, next);
73830- WARN(prev->next != next,
73831+ prev, next->prev, next) ||
73832+ WARN(prev->next != next,
73833 "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
73834- next, prev->next, prev);
73835+ next, prev->next, prev))
73836+ return;
73837+
73838 new->next = next;
73839 new->prev = prev;
73840 rcu_assign_pointer(list_next_rcu(prev), new);
73841 next->prev = new;
73842 }
73843 EXPORT_SYMBOL(__list_add_rcu);
73844+#endif
73845+
73846+void pax_list_add_tail(struct list_head *new, struct list_head *head)
73847+{
73848+ struct list_head *prev, *next;
73849+
73850+ prev = head->prev;
73851+ next = head;
73852+
73853+#ifdef CONFIG_DEBUG_LIST
73854+ if (!__list_add_debug(new, prev, next))
73855+ return;
73856+#endif
73857+
73858+ pax_open_kernel();
73859+ next->prev = new;
73860+ new->next = next;
73861+ new->prev = prev;
73862+ prev->next = new;
73863+ pax_close_kernel();
73864+}
73865+EXPORT_SYMBOL(pax_list_add_tail);
73866+
73867+void pax_list_del(struct list_head *entry)
73868+{
73869+#ifdef CONFIG_DEBUG_LIST
73870+ if (!__list_del_entry_debug(entry))
73871+ return;
73872+#endif
73873+
73874+ pax_open_kernel();
73875+ __list_del(entry->prev, entry->next);
73876+ entry->next = LIST_POISON1;
73877+ entry->prev = LIST_POISON2;
73878+ pax_close_kernel();
73879+}
73880+EXPORT_SYMBOL(pax_list_del);
73881diff --git a/lib/radix-tree.c b/lib/radix-tree.c
73882index e796429..6e38f9f 100644
73883--- a/lib/radix-tree.c
73884+++ b/lib/radix-tree.c
73885@@ -92,7 +92,7 @@ struct radix_tree_preload {
73886 int nr;
73887 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
73888 };
73889-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
73890+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
73891
73892 static inline void *ptr_to_indirect(void *ptr)
73893 {
73894diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
73895index bb2b201..46abaf9 100644
73896--- a/lib/strncpy_from_user.c
73897+++ b/lib/strncpy_from_user.c
73898@@ -21,7 +21,7 @@
73899 */
73900 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
73901 {
73902- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
73903+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
73904 long res = 0;
73905
73906 /*
73907diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
73908index a28df52..3d55877 100644
73909--- a/lib/strnlen_user.c
73910+++ b/lib/strnlen_user.c
73911@@ -26,7 +26,7 @@
73912 */
73913 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
73914 {
73915- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
73916+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
73917 long align, res = 0;
73918 unsigned long c;
73919
73920diff --git a/lib/vsprintf.c b/lib/vsprintf.c
73921index 39c99fe..18f060b 100644
73922--- a/lib/vsprintf.c
73923+++ b/lib/vsprintf.c
73924@@ -16,6 +16,9 @@
73925 * - scnprintf and vscnprintf
73926 */
73927
73928+#ifdef CONFIG_GRKERNSEC_HIDESYM
73929+#define __INCLUDED_BY_HIDESYM 1
73930+#endif
73931 #include <stdarg.h>
73932 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
73933 #include <linux/types.h>
73934@@ -533,7 +536,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
73935 char sym[KSYM_SYMBOL_LEN];
73936 if (ext == 'B')
73937 sprint_backtrace(sym, value);
73938- else if (ext != 'f' && ext != 's')
73939+ else if (ext != 'f' && ext != 's' && ext != 'a')
73940 sprint_symbol(sym, value);
73941 else
73942 sprint_symbol_no_offset(sym, value);
73943@@ -966,7 +969,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
73944 return number(buf, end, *(const netdev_features_t *)addr, spec);
73945 }
73946
73947+#ifdef CONFIG_GRKERNSEC_HIDESYM
73948+int kptr_restrict __read_mostly = 2;
73949+#else
73950 int kptr_restrict __read_mostly;
73951+#endif
73952
73953 /*
73954 * Show a '%p' thing. A kernel extension is that the '%p' is followed
73955@@ -980,6 +987,8 @@ int kptr_restrict __read_mostly;
73956 * - 'S' For symbolic direct pointers with offset
73957 * - 's' For symbolic direct pointers without offset
73958 * - 'B' For backtraced symbolic direct pointers with offset
73959+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
73960+ * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
73961 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
73962 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
73963 * - 'M' For a 6-byte MAC address, it prints the address in the
73964@@ -1035,12 +1044,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
73965
73966 if (!ptr && *fmt != 'K') {
73967 /*
73968- * Print (null) with the same width as a pointer so it makes
73969+ * Print (nil) with the same width as a pointer so it makes
73970 * tabular output look nice.
73971 */
73972 if (spec.field_width == -1)
73973 spec.field_width = default_width;
73974- return string(buf, end, "(null)", spec);
73975+ return string(buf, end, "(nil)", spec);
73976 }
73977
73978 switch (*fmt) {
73979@@ -1050,6 +1059,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
73980 /* Fallthrough */
73981 case 'S':
73982 case 's':
73983+#ifdef CONFIG_GRKERNSEC_HIDESYM
73984+ break;
73985+#else
73986+ return symbol_string(buf, end, ptr, spec, *fmt);
73987+#endif
73988+ case 'A':
73989+ case 'a':
73990 case 'B':
73991 return symbol_string(buf, end, ptr, spec, *fmt);
73992 case 'R':
73993@@ -1090,6 +1106,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
73994 va_end(va);
73995 return buf;
73996 }
73997+ case 'P':
73998+ break;
73999 case 'K':
74000 /*
74001 * %pK cannot be used in IRQ context because its test
74002@@ -1113,6 +1131,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
74003 }
74004 break;
74005 }
74006+
74007+#ifdef CONFIG_GRKERNSEC_HIDESYM
74008+ /* 'P' = approved pointers to copy to userland,
74009+ as in the /proc/kallsyms case, as we make it display nothing
74010+ for non-root users, and the real contents for root users
74011+ Also ignore 'K' pointers, since we force their NULLing for non-root users
74012+ above
74013+ */
74014+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
74015+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
74016+ dump_stack();
74017+ ptr = NULL;
74018+ }
74019+#endif
74020+
74021 spec.flags |= SMALL;
74022 if (spec.field_width == -1) {
74023 spec.field_width = default_width;
74024@@ -1831,11 +1864,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
74025 typeof(type) value; \
74026 if (sizeof(type) == 8) { \
74027 args = PTR_ALIGN(args, sizeof(u32)); \
74028- *(u32 *)&value = *(u32 *)args; \
74029- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
74030+ *(u32 *)&value = *(const u32 *)args; \
74031+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
74032 } else { \
74033 args = PTR_ALIGN(args, sizeof(type)); \
74034- value = *(typeof(type) *)args; \
74035+ value = *(const typeof(type) *)args; \
74036 } \
74037 args += sizeof(type); \
74038 value; \
74039@@ -1898,7 +1931,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
74040 case FORMAT_TYPE_STR: {
74041 const char *str_arg = args;
74042 args += strlen(str_arg) + 1;
74043- str = string(str, end, (char *)str_arg, spec);
74044+ str = string(str, end, str_arg, spec);
74045 break;
74046 }
74047
74048diff --git a/localversion-grsec b/localversion-grsec
74049new file mode 100644
74050index 0000000..7cd6065
74051--- /dev/null
74052+++ b/localversion-grsec
74053@@ -0,0 +1 @@
74054+-grsec
74055diff --git a/mm/Kconfig b/mm/Kconfig
74056index a3f8ddd..f31e92e 100644
74057--- a/mm/Kconfig
74058+++ b/mm/Kconfig
74059@@ -252,10 +252,10 @@ config KSM
74060 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
74061
74062 config DEFAULT_MMAP_MIN_ADDR
74063- int "Low address space to protect from user allocation"
74064+ int "Low address space to protect from user allocation"
74065 depends on MMU
74066- default 4096
74067- help
74068+ default 65536
74069+ help
74070 This is the portion of low virtual memory which should be protected
74071 from userspace allocation. Keeping a user from writing to low pages
74072 can help reduce the impact of kernel NULL pointer bugs.
74073@@ -286,7 +286,7 @@ config MEMORY_FAILURE
74074
74075 config HWPOISON_INJECT
74076 tristate "HWPoison pages injector"
74077- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
74078+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
74079 select PROC_PAGE_MONITOR
74080
74081 config NOMMU_INITIAL_TRIM_EXCESS
74082diff --git a/mm/filemap.c b/mm/filemap.c
74083index 83efee7..3f99381 100644
74084--- a/mm/filemap.c
74085+++ b/mm/filemap.c
74086@@ -1747,7 +1747,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
74087 struct address_space *mapping = file->f_mapping;
74088
74089 if (!mapping->a_ops->readpage)
74090- return -ENOEXEC;
74091+ return -ENODEV;
74092 file_accessed(file);
74093 vma->vm_ops = &generic_file_vm_ops;
74094 return 0;
74095@@ -2087,6 +2087,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
74096 *pos = i_size_read(inode);
74097
74098 if (limit != RLIM_INFINITY) {
74099+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
74100 if (*pos >= limit) {
74101 send_sig(SIGXFSZ, current, 0);
74102 return -EFBIG;
74103diff --git a/mm/fremap.c b/mm/fremap.c
74104index a0aaf0e..20325c3 100644
74105--- a/mm/fremap.c
74106+++ b/mm/fremap.c
74107@@ -157,6 +157,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
74108 retry:
74109 vma = find_vma(mm, start);
74110
74111+#ifdef CONFIG_PAX_SEGMEXEC
74112+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
74113+ goto out;
74114+#endif
74115+
74116 /*
74117 * Make sure the vma is shared, that it supports prefaulting,
74118 * and that the remapped range is valid and fully within
74119diff --git a/mm/highmem.c b/mm/highmem.c
74120index 09fc744..3936897 100644
74121--- a/mm/highmem.c
74122+++ b/mm/highmem.c
74123@@ -138,9 +138,10 @@ static void flush_all_zero_pkmaps(void)
74124 * So no dangers, even with speculative execution.
74125 */
74126 page = pte_page(pkmap_page_table[i]);
74127+ pax_open_kernel();
74128 pte_clear(&init_mm, (unsigned long)page_address(page),
74129 &pkmap_page_table[i]);
74130-
74131+ pax_close_kernel();
74132 set_page_address(page, NULL);
74133 need_flush = 1;
74134 }
74135@@ -199,9 +200,11 @@ start:
74136 }
74137 }
74138 vaddr = PKMAP_ADDR(last_pkmap_nr);
74139+
74140+ pax_open_kernel();
74141 set_pte_at(&init_mm, vaddr,
74142 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
74143-
74144+ pax_close_kernel();
74145 pkmap_count[last_pkmap_nr] = 1;
74146 set_page_address(page, (void *)vaddr);
74147
74148diff --git a/mm/huge_memory.c b/mm/huge_memory.c
74149index 40f17c3..c1cc011 100644
74150--- a/mm/huge_memory.c
74151+++ b/mm/huge_memory.c
74152@@ -710,7 +710,7 @@ out:
74153 * run pte_offset_map on the pmd, if an huge pmd could
74154 * materialize from under us from a different thread.
74155 */
74156- if (unlikely(__pte_alloc(mm, vma, pmd, address)))
74157+ if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
74158 return VM_FAULT_OOM;
74159 /* if an huge pmd materialized from under us just retry later */
74160 if (unlikely(pmd_trans_huge(*pmd)))
74161diff --git a/mm/hugetlb.c b/mm/hugetlb.c
74162index f198aca..10e3e37 100644
74163--- a/mm/hugetlb.c
74164+++ b/mm/hugetlb.c
74165@@ -2509,6 +2509,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
74166 return 1;
74167 }
74168
74169+#ifdef CONFIG_PAX_SEGMEXEC
74170+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
74171+{
74172+ struct mm_struct *mm = vma->vm_mm;
74173+ struct vm_area_struct *vma_m;
74174+ unsigned long address_m;
74175+ pte_t *ptep_m;
74176+
74177+ vma_m = pax_find_mirror_vma(vma);
74178+ if (!vma_m)
74179+ return;
74180+
74181+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
74182+ address_m = address + SEGMEXEC_TASK_SIZE;
74183+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
74184+ get_page(page_m);
74185+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
74186+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
74187+}
74188+#endif
74189+
74190 /*
74191 * Hugetlb_cow() should be called with page lock of the original hugepage held.
74192 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
74193@@ -2627,6 +2648,11 @@ retry_avoidcopy:
74194 make_huge_pte(vma, new_page, 1));
74195 page_remove_rmap(old_page);
74196 hugepage_add_new_anon_rmap(new_page, vma, address);
74197+
74198+#ifdef CONFIG_PAX_SEGMEXEC
74199+ pax_mirror_huge_pte(vma, address, new_page);
74200+#endif
74201+
74202 /* Make the old page be freed below */
74203 new_page = old_page;
74204 }
74205@@ -2786,6 +2812,10 @@ retry:
74206 && (vma->vm_flags & VM_SHARED)));
74207 set_huge_pte_at(mm, address, ptep, new_pte);
74208
74209+#ifdef CONFIG_PAX_SEGMEXEC
74210+ pax_mirror_huge_pte(vma, address, page);
74211+#endif
74212+
74213 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
74214 /* Optimization, do the COW without a second fault */
74215 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
74216@@ -2815,6 +2845,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
74217 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
74218 struct hstate *h = hstate_vma(vma);
74219
74220+#ifdef CONFIG_PAX_SEGMEXEC
74221+ struct vm_area_struct *vma_m;
74222+#endif
74223+
74224 address &= huge_page_mask(h);
74225
74226 ptep = huge_pte_offset(mm, address);
74227@@ -2828,6 +2862,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
74228 VM_FAULT_SET_HINDEX(hstate_index(h));
74229 }
74230
74231+#ifdef CONFIG_PAX_SEGMEXEC
74232+ vma_m = pax_find_mirror_vma(vma);
74233+ if (vma_m) {
74234+ unsigned long address_m;
74235+
74236+ if (vma->vm_start > vma_m->vm_start) {
74237+ address_m = address;
74238+ address -= SEGMEXEC_TASK_SIZE;
74239+ vma = vma_m;
74240+ h = hstate_vma(vma);
74241+ } else
74242+ address_m = address + SEGMEXEC_TASK_SIZE;
74243+
74244+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
74245+ return VM_FAULT_OOM;
74246+ address_m &= HPAGE_MASK;
74247+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
74248+ }
74249+#endif
74250+
74251 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
74252 if (!ptep)
74253 return VM_FAULT_OOM;
74254@@ -3028,6 +3082,7 @@ void hugetlb_change_protection(struct vm_area_struct *vma,
74255 if (!huge_pte_none(huge_ptep_get(ptep))) {
74256 pte = huge_ptep_get_and_clear(mm, address, ptep);
74257 pte = pte_mkhuge(pte_modify(pte, newprot));
74258+ pte = arch_make_huge_pte(pte, vma, NULL, 0);
74259 set_huge_pte_at(mm, address, ptep, pte);
74260 }
74261 }
74262diff --git a/mm/internal.h b/mm/internal.h
74263index 3c5197d..08d0065 100644
74264--- a/mm/internal.h
74265+++ b/mm/internal.h
74266@@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
74267 * in mm/page_alloc.c
74268 */
74269 extern void __free_pages_bootmem(struct page *page, unsigned int order);
74270+extern void free_compound_page(struct page *page);
74271 extern void prep_compound_page(struct page *page, unsigned long order);
74272 #ifdef CONFIG_MEMORY_FAILURE
74273 extern bool is_free_buddy_page(struct page *page);
74274diff --git a/mm/kmemleak.c b/mm/kmemleak.c
74275index a217cc5..44b2b35 100644
74276--- a/mm/kmemleak.c
74277+++ b/mm/kmemleak.c
74278@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
74279
74280 for (i = 0; i < object->trace_len; i++) {
74281 void *ptr = (void *)object->trace[i];
74282- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
74283+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
74284 }
74285 }
74286
74287@@ -1852,7 +1852,7 @@ static int __init kmemleak_late_init(void)
74288 return -ENOMEM;
74289 }
74290
74291- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
74292+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
74293 &kmemleak_fops);
74294 if (!dentry)
74295 pr_warning("Failed to create the debugfs kmemleak file\n");
74296diff --git a/mm/maccess.c b/mm/maccess.c
74297index d53adf9..03a24bf 100644
74298--- a/mm/maccess.c
74299+++ b/mm/maccess.c
74300@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
74301 set_fs(KERNEL_DS);
74302 pagefault_disable();
74303 ret = __copy_from_user_inatomic(dst,
74304- (__force const void __user *)src, size);
74305+ (const void __force_user *)src, size);
74306 pagefault_enable();
74307 set_fs(old_fs);
74308
74309@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
74310
74311 set_fs(KERNEL_DS);
74312 pagefault_disable();
74313- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
74314+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
74315 pagefault_enable();
74316 set_fs(old_fs);
74317
74318diff --git a/mm/madvise.c b/mm/madvise.c
74319index 03dfa5c..b032917 100644
74320--- a/mm/madvise.c
74321+++ b/mm/madvise.c
74322@@ -48,6 +48,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
74323 pgoff_t pgoff;
74324 unsigned long new_flags = vma->vm_flags;
74325
74326+#ifdef CONFIG_PAX_SEGMEXEC
74327+ struct vm_area_struct *vma_m;
74328+#endif
74329+
74330 switch (behavior) {
74331 case MADV_NORMAL:
74332 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
74333@@ -123,6 +127,13 @@ success:
74334 /*
74335 * vm_flags is protected by the mmap_sem held in write mode.
74336 */
74337+
74338+#ifdef CONFIG_PAX_SEGMEXEC
74339+ vma_m = pax_find_mirror_vma(vma);
74340+ if (vma_m)
74341+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
74342+#endif
74343+
74344 vma->vm_flags = new_flags;
74345
74346 out:
74347@@ -181,6 +192,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
74348 struct vm_area_struct ** prev,
74349 unsigned long start, unsigned long end)
74350 {
74351+
74352+#ifdef CONFIG_PAX_SEGMEXEC
74353+ struct vm_area_struct *vma_m;
74354+#endif
74355+
74356 *prev = vma;
74357 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
74358 return -EINVAL;
74359@@ -193,6 +209,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
74360 zap_page_range(vma, start, end - start, &details);
74361 } else
74362 zap_page_range(vma, start, end - start, NULL);
74363+
74364+#ifdef CONFIG_PAX_SEGMEXEC
74365+ vma_m = pax_find_mirror_vma(vma);
74366+ if (vma_m) {
74367+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
74368+ struct zap_details details = {
74369+ .nonlinear_vma = vma_m,
74370+ .last_index = ULONG_MAX,
74371+ };
74372+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
74373+ } else
74374+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
74375+ }
74376+#endif
74377+
74378 return 0;
74379 }
74380
74381@@ -397,6 +428,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
74382 if (end < start)
74383 goto out;
74384
74385+#ifdef CONFIG_PAX_SEGMEXEC
74386+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
74387+ if (end > SEGMEXEC_TASK_SIZE)
74388+ goto out;
74389+ } else
74390+#endif
74391+
74392+ if (end > TASK_SIZE)
74393+ goto out;
74394+
74395 error = 0;
74396 if (end == start)
74397 goto out;
74398diff --git a/mm/memory-failure.c b/mm/memory-failure.c
74399index 8b20278..05dac18 100644
74400--- a/mm/memory-failure.c
74401+++ b/mm/memory-failure.c
74402@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
74403
74404 int sysctl_memory_failure_recovery __read_mostly = 1;
74405
74406-atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
74407+atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
74408
74409 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
74410
74411@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
74412 pfn, t->comm, t->pid);
74413 si.si_signo = SIGBUS;
74414 si.si_errno = 0;
74415- si.si_addr = (void *)addr;
74416+ si.si_addr = (void __user *)addr;
74417 #ifdef __ARCH_SI_TRAPNO
74418 si.si_trapno = trapno;
74419 #endif
74420@@ -1040,7 +1040,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
74421 }
74422
74423 nr_pages = 1 << compound_trans_order(hpage);
74424- atomic_long_add(nr_pages, &mce_bad_pages);
74425+ atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
74426
74427 /*
74428 * We need/can do nothing about count=0 pages.
74429@@ -1070,7 +1070,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
74430 if (!PageHWPoison(hpage)
74431 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
74432 || (p != hpage && TestSetPageHWPoison(hpage))) {
74433- atomic_long_sub(nr_pages, &mce_bad_pages);
74434+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
74435 return 0;
74436 }
74437 set_page_hwpoison_huge_page(hpage);
74438@@ -1128,7 +1128,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
74439 }
74440 if (hwpoison_filter(p)) {
74441 if (TestClearPageHWPoison(p))
74442- atomic_long_sub(nr_pages, &mce_bad_pages);
74443+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
74444 unlock_page(hpage);
74445 put_page(hpage);
74446 return 0;
74447@@ -1323,7 +1323,7 @@ int unpoison_memory(unsigned long pfn)
74448 return 0;
74449 }
74450 if (TestClearPageHWPoison(p))
74451- atomic_long_sub(nr_pages, &mce_bad_pages);
74452+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
74453 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
74454 return 0;
74455 }
74456@@ -1337,7 +1337,7 @@ int unpoison_memory(unsigned long pfn)
74457 */
74458 if (TestClearPageHWPoison(page)) {
74459 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
74460- atomic_long_sub(nr_pages, &mce_bad_pages);
74461+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
74462 freeit = 1;
74463 if (PageHuge(page))
74464 clear_page_hwpoison_huge_page(page);
74465@@ -1442,7 +1442,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
74466 }
74467 done:
74468 if (!PageHWPoison(hpage))
74469- atomic_long_add(1 << compound_trans_order(hpage),
74470+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
74471 &mce_bad_pages);
74472 set_page_hwpoison_huge_page(hpage);
74473 dequeue_hwpoisoned_huge_page(hpage);
74474@@ -1582,7 +1582,7 @@ int soft_offline_page(struct page *page, int flags)
74475 return ret;
74476
74477 done:
74478- atomic_long_add(1, &mce_bad_pages);
74479+ atomic_long_add_unchecked(1, &mce_bad_pages);
74480 SetPageHWPoison(page);
74481 /* keep elevated page count for bad page */
74482 return ret;
74483diff --git a/mm/memory.c b/mm/memory.c
74484index f2973b2..fd020a7 100644
74485--- a/mm/memory.c
74486+++ b/mm/memory.c
74487@@ -431,6 +431,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
74488 free_pte_range(tlb, pmd, addr);
74489 } while (pmd++, addr = next, addr != end);
74490
74491+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
74492 start &= PUD_MASK;
74493 if (start < floor)
74494 return;
74495@@ -445,6 +446,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
74496 pmd = pmd_offset(pud, start);
74497 pud_clear(pud);
74498 pmd_free_tlb(tlb, pmd, start);
74499+#endif
74500+
74501 }
74502
74503 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
74504@@ -464,6 +467,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
74505 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
74506 } while (pud++, addr = next, addr != end);
74507
74508+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
74509 start &= PGDIR_MASK;
74510 if (start < floor)
74511 return;
74512@@ -478,6 +482,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
74513 pud = pud_offset(pgd, start);
74514 pgd_clear(pgd);
74515 pud_free_tlb(tlb, pud, start);
74516+#endif
74517+
74518 }
74519
74520 /*
74521@@ -1626,12 +1632,6 @@ no_page_table:
74522 return page;
74523 }
74524
74525-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
74526-{
74527- return stack_guard_page_start(vma, addr) ||
74528- stack_guard_page_end(vma, addr+PAGE_SIZE);
74529-}
74530-
74531 /**
74532 * __get_user_pages() - pin user pages in memory
74533 * @tsk: task_struct of target task
74534@@ -1704,10 +1704,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
74535 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
74536 i = 0;
74537
74538- do {
74539+ while (nr_pages) {
74540 struct vm_area_struct *vma;
74541
74542- vma = find_extend_vma(mm, start);
74543+ vma = find_vma(mm, start);
74544 if (!vma && in_gate_area(mm, start)) {
74545 unsigned long pg = start & PAGE_MASK;
74546 pgd_t *pgd;
74547@@ -1755,7 +1755,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
74548 goto next_page;
74549 }
74550
74551- if (!vma ||
74552+ if (!vma || start < vma->vm_start ||
74553 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
74554 !(vm_flags & vma->vm_flags))
74555 return i ? : -EFAULT;
74556@@ -1782,11 +1782,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
74557 int ret;
74558 unsigned int fault_flags = 0;
74559
74560- /* For mlock, just skip the stack guard page. */
74561- if (foll_flags & FOLL_MLOCK) {
74562- if (stack_guard_page(vma, start))
74563- goto next_page;
74564- }
74565 if (foll_flags & FOLL_WRITE)
74566 fault_flags |= FAULT_FLAG_WRITE;
74567 if (nonblocking)
74568@@ -1860,7 +1855,7 @@ next_page:
74569 start += PAGE_SIZE;
74570 nr_pages--;
74571 } while (nr_pages && start < vma->vm_end);
74572- } while (nr_pages);
74573+ }
74574 return i;
74575 }
74576 EXPORT_SYMBOL(__get_user_pages);
74577@@ -2067,6 +2062,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
74578 page_add_file_rmap(page);
74579 set_pte_at(mm, addr, pte, mk_pte(page, prot));
74580
74581+#ifdef CONFIG_PAX_SEGMEXEC
74582+ pax_mirror_file_pte(vma, addr, page, ptl);
74583+#endif
74584+
74585 retval = 0;
74586 pte_unmap_unlock(pte, ptl);
74587 return retval;
74588@@ -2111,9 +2110,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
74589 if (!page_count(page))
74590 return -EINVAL;
74591 if (!(vma->vm_flags & VM_MIXEDMAP)) {
74592+
74593+#ifdef CONFIG_PAX_SEGMEXEC
74594+ struct vm_area_struct *vma_m;
74595+#endif
74596+
74597 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
74598 BUG_ON(vma->vm_flags & VM_PFNMAP);
74599 vma->vm_flags |= VM_MIXEDMAP;
74600+
74601+#ifdef CONFIG_PAX_SEGMEXEC
74602+ vma_m = pax_find_mirror_vma(vma);
74603+ if (vma_m)
74604+ vma_m->vm_flags |= VM_MIXEDMAP;
74605+#endif
74606+
74607 }
74608 return insert_page(vma, addr, page, vma->vm_page_prot);
74609 }
74610@@ -2196,6 +2207,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
74611 unsigned long pfn)
74612 {
74613 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
74614+ BUG_ON(vma->vm_mirror);
74615
74616 if (addr < vma->vm_start || addr >= vma->vm_end)
74617 return -EFAULT;
74618@@ -2396,7 +2408,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
74619
74620 BUG_ON(pud_huge(*pud));
74621
74622- pmd = pmd_alloc(mm, pud, addr);
74623+ pmd = (mm == &init_mm) ?
74624+ pmd_alloc_kernel(mm, pud, addr) :
74625+ pmd_alloc(mm, pud, addr);
74626 if (!pmd)
74627 return -ENOMEM;
74628 do {
74629@@ -2416,7 +2430,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
74630 unsigned long next;
74631 int err;
74632
74633- pud = pud_alloc(mm, pgd, addr);
74634+ pud = (mm == &init_mm) ?
74635+ pud_alloc_kernel(mm, pgd, addr) :
74636+ pud_alloc(mm, pgd, addr);
74637 if (!pud)
74638 return -ENOMEM;
74639 do {
74640@@ -2504,6 +2520,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
74641 copy_user_highpage(dst, src, va, vma);
74642 }
74643
74644+#ifdef CONFIG_PAX_SEGMEXEC
74645+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
74646+{
74647+ struct mm_struct *mm = vma->vm_mm;
74648+ spinlock_t *ptl;
74649+ pte_t *pte, entry;
74650+
74651+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
74652+ entry = *pte;
74653+ if (!pte_present(entry)) {
74654+ if (!pte_none(entry)) {
74655+ BUG_ON(pte_file(entry));
74656+ free_swap_and_cache(pte_to_swp_entry(entry));
74657+ pte_clear_not_present_full(mm, address, pte, 0);
74658+ }
74659+ } else {
74660+ struct page *page;
74661+
74662+ flush_cache_page(vma, address, pte_pfn(entry));
74663+ entry = ptep_clear_flush(vma, address, pte);
74664+ BUG_ON(pte_dirty(entry));
74665+ page = vm_normal_page(vma, address, entry);
74666+ if (page) {
74667+ update_hiwater_rss(mm);
74668+ if (PageAnon(page))
74669+ dec_mm_counter_fast(mm, MM_ANONPAGES);
74670+ else
74671+ dec_mm_counter_fast(mm, MM_FILEPAGES);
74672+ page_remove_rmap(page);
74673+ page_cache_release(page);
74674+ }
74675+ }
74676+ pte_unmap_unlock(pte, ptl);
74677+}
74678+
74679+/* PaX: if vma is mirrored, synchronize the mirror's PTE
74680+ *
74681+ * the ptl of the lower mapped page is held on entry and is not released on exit
74682+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
74683+ */
74684+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
74685+{
74686+ struct mm_struct *mm = vma->vm_mm;
74687+ unsigned long address_m;
74688+ spinlock_t *ptl_m;
74689+ struct vm_area_struct *vma_m;
74690+ pmd_t *pmd_m;
74691+ pte_t *pte_m, entry_m;
74692+
74693+ BUG_ON(!page_m || !PageAnon(page_m));
74694+
74695+ vma_m = pax_find_mirror_vma(vma);
74696+ if (!vma_m)
74697+ return;
74698+
74699+ BUG_ON(!PageLocked(page_m));
74700+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
74701+ address_m = address + SEGMEXEC_TASK_SIZE;
74702+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
74703+ pte_m = pte_offset_map(pmd_m, address_m);
74704+ ptl_m = pte_lockptr(mm, pmd_m);
74705+ if (ptl != ptl_m) {
74706+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
74707+ if (!pte_none(*pte_m))
74708+ goto out;
74709+ }
74710+
74711+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
74712+ page_cache_get(page_m);
74713+ page_add_anon_rmap(page_m, vma_m, address_m);
74714+ inc_mm_counter_fast(mm, MM_ANONPAGES);
74715+ set_pte_at(mm, address_m, pte_m, entry_m);
74716+ update_mmu_cache(vma_m, address_m, entry_m);
74717+out:
74718+ if (ptl != ptl_m)
74719+ spin_unlock(ptl_m);
74720+ pte_unmap(pte_m);
74721+ unlock_page(page_m);
74722+}
74723+
74724+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
74725+{
74726+ struct mm_struct *mm = vma->vm_mm;
74727+ unsigned long address_m;
74728+ spinlock_t *ptl_m;
74729+ struct vm_area_struct *vma_m;
74730+ pmd_t *pmd_m;
74731+ pte_t *pte_m, entry_m;
74732+
74733+ BUG_ON(!page_m || PageAnon(page_m));
74734+
74735+ vma_m = pax_find_mirror_vma(vma);
74736+ if (!vma_m)
74737+ return;
74738+
74739+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
74740+ address_m = address + SEGMEXEC_TASK_SIZE;
74741+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
74742+ pte_m = pte_offset_map(pmd_m, address_m);
74743+ ptl_m = pte_lockptr(mm, pmd_m);
74744+ if (ptl != ptl_m) {
74745+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
74746+ if (!pte_none(*pte_m))
74747+ goto out;
74748+ }
74749+
74750+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
74751+ page_cache_get(page_m);
74752+ page_add_file_rmap(page_m);
74753+ inc_mm_counter_fast(mm, MM_FILEPAGES);
74754+ set_pte_at(mm, address_m, pte_m, entry_m);
74755+ update_mmu_cache(vma_m, address_m, entry_m);
74756+out:
74757+ if (ptl != ptl_m)
74758+ spin_unlock(ptl_m);
74759+ pte_unmap(pte_m);
74760+}
74761+
74762+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
74763+{
74764+ struct mm_struct *mm = vma->vm_mm;
74765+ unsigned long address_m;
74766+ spinlock_t *ptl_m;
74767+ struct vm_area_struct *vma_m;
74768+ pmd_t *pmd_m;
74769+ pte_t *pte_m, entry_m;
74770+
74771+ vma_m = pax_find_mirror_vma(vma);
74772+ if (!vma_m)
74773+ return;
74774+
74775+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
74776+ address_m = address + SEGMEXEC_TASK_SIZE;
74777+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
74778+ pte_m = pte_offset_map(pmd_m, address_m);
74779+ ptl_m = pte_lockptr(mm, pmd_m);
74780+ if (ptl != ptl_m) {
74781+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
74782+ if (!pte_none(*pte_m))
74783+ goto out;
74784+ }
74785+
74786+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
74787+ set_pte_at(mm, address_m, pte_m, entry_m);
74788+out:
74789+ if (ptl != ptl_m)
74790+ spin_unlock(ptl_m);
74791+ pte_unmap(pte_m);
74792+}
74793+
74794+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
74795+{
74796+ struct page *page_m;
74797+ pte_t entry;
74798+
74799+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
74800+ goto out;
74801+
74802+ entry = *pte;
74803+ page_m = vm_normal_page(vma, address, entry);
74804+ if (!page_m)
74805+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
74806+ else if (PageAnon(page_m)) {
74807+ if (pax_find_mirror_vma(vma)) {
74808+ pte_unmap_unlock(pte, ptl);
74809+ lock_page(page_m);
74810+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
74811+ if (pte_same(entry, *pte))
74812+ pax_mirror_anon_pte(vma, address, page_m, ptl);
74813+ else
74814+ unlock_page(page_m);
74815+ }
74816+ } else
74817+ pax_mirror_file_pte(vma, address, page_m, ptl);
74818+
74819+out:
74820+ pte_unmap_unlock(pte, ptl);
74821+}
74822+#endif
74823+
74824 /*
74825 * This routine handles present pages, when users try to write
74826 * to a shared page. It is done by copying the page to a new address
74827@@ -2720,6 +2916,12 @@ gotten:
74828 */
74829 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
74830 if (likely(pte_same(*page_table, orig_pte))) {
74831+
74832+#ifdef CONFIG_PAX_SEGMEXEC
74833+ if (pax_find_mirror_vma(vma))
74834+ BUG_ON(!trylock_page(new_page));
74835+#endif
74836+
74837 if (old_page) {
74838 if (!PageAnon(old_page)) {
74839 dec_mm_counter_fast(mm, MM_FILEPAGES);
74840@@ -2771,6 +2973,10 @@ gotten:
74841 page_remove_rmap(old_page);
74842 }
74843
74844+#ifdef CONFIG_PAX_SEGMEXEC
74845+ pax_mirror_anon_pte(vma, address, new_page, ptl);
74846+#endif
74847+
74848 /* Free the old page.. */
74849 new_page = old_page;
74850 ret |= VM_FAULT_WRITE;
74851@@ -3051,6 +3257,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
74852 swap_free(entry);
74853 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
74854 try_to_free_swap(page);
74855+
74856+#ifdef CONFIG_PAX_SEGMEXEC
74857+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
74858+#endif
74859+
74860 unlock_page(page);
74861 if (swapcache) {
74862 /*
74863@@ -3074,6 +3285,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
74864
74865 /* No need to invalidate - it was non-present before */
74866 update_mmu_cache(vma, address, page_table);
74867+
74868+#ifdef CONFIG_PAX_SEGMEXEC
74869+ pax_mirror_anon_pte(vma, address, page, ptl);
74870+#endif
74871+
74872 unlock:
74873 pte_unmap_unlock(page_table, ptl);
74874 out:
74875@@ -3093,40 +3309,6 @@ out_release:
74876 }
74877
74878 /*
74879- * This is like a special single-page "expand_{down|up}wards()",
74880- * except we must first make sure that 'address{-|+}PAGE_SIZE'
74881- * doesn't hit another vma.
74882- */
74883-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
74884-{
74885- address &= PAGE_MASK;
74886- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
74887- struct vm_area_struct *prev = vma->vm_prev;
74888-
74889- /*
74890- * Is there a mapping abutting this one below?
74891- *
74892- * That's only ok if it's the same stack mapping
74893- * that has gotten split..
74894- */
74895- if (prev && prev->vm_end == address)
74896- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
74897-
74898- expand_downwards(vma, address - PAGE_SIZE);
74899- }
74900- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
74901- struct vm_area_struct *next = vma->vm_next;
74902-
74903- /* As VM_GROWSDOWN but s/below/above/ */
74904- if (next && next->vm_start == address + PAGE_SIZE)
74905- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
74906-
74907- expand_upwards(vma, address + PAGE_SIZE);
74908- }
74909- return 0;
74910-}
74911-
74912-/*
74913 * We enter with non-exclusive mmap_sem (to exclude vma changes,
74914 * but allow concurrent faults), and pte mapped but not yet locked.
74915 * We return with mmap_sem still held, but pte unmapped and unlocked.
74916@@ -3135,27 +3317,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
74917 unsigned long address, pte_t *page_table, pmd_t *pmd,
74918 unsigned int flags)
74919 {
74920- struct page *page;
74921+ struct page *page = NULL;
74922 spinlock_t *ptl;
74923 pte_t entry;
74924
74925- pte_unmap(page_table);
74926-
74927- /* Check if we need to add a guard page to the stack */
74928- if (check_stack_guard_page(vma, address) < 0)
74929- return VM_FAULT_SIGBUS;
74930-
74931- /* Use the zero-page for reads */
74932 if (!(flags & FAULT_FLAG_WRITE)) {
74933 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
74934 vma->vm_page_prot));
74935- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
74936+ ptl = pte_lockptr(mm, pmd);
74937+ spin_lock(ptl);
74938 if (!pte_none(*page_table))
74939 goto unlock;
74940 goto setpte;
74941 }
74942
74943 /* Allocate our own private page. */
74944+ pte_unmap(page_table);
74945+
74946 if (unlikely(anon_vma_prepare(vma)))
74947 goto oom;
74948 page = alloc_zeroed_user_highpage_movable(vma, address);
74949@@ -3174,6 +3352,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
74950 if (!pte_none(*page_table))
74951 goto release;
74952
74953+#ifdef CONFIG_PAX_SEGMEXEC
74954+ if (pax_find_mirror_vma(vma))
74955+ BUG_ON(!trylock_page(page));
74956+#endif
74957+
74958 inc_mm_counter_fast(mm, MM_ANONPAGES);
74959 page_add_new_anon_rmap(page, vma, address);
74960 setpte:
74961@@ -3181,6 +3364,12 @@ setpte:
74962
74963 /* No need to invalidate - it was non-present before */
74964 update_mmu_cache(vma, address, page_table);
74965+
74966+#ifdef CONFIG_PAX_SEGMEXEC
74967+ if (page)
74968+ pax_mirror_anon_pte(vma, address, page, ptl);
74969+#endif
74970+
74971 unlock:
74972 pte_unmap_unlock(page_table, ptl);
74973 return 0;
74974@@ -3324,6 +3513,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
74975 */
74976 /* Only go through if we didn't race with anybody else... */
74977 if (likely(pte_same(*page_table, orig_pte))) {
74978+
74979+#ifdef CONFIG_PAX_SEGMEXEC
74980+ if (anon && pax_find_mirror_vma(vma))
74981+ BUG_ON(!trylock_page(page));
74982+#endif
74983+
74984 flush_icache_page(vma, page);
74985 entry = mk_pte(page, vma->vm_page_prot);
74986 if (flags & FAULT_FLAG_WRITE)
74987@@ -3343,6 +3538,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
74988
74989 /* no need to invalidate: a not-present page won't be cached */
74990 update_mmu_cache(vma, address, page_table);
74991+
74992+#ifdef CONFIG_PAX_SEGMEXEC
74993+ if (anon)
74994+ pax_mirror_anon_pte(vma, address, page, ptl);
74995+ else
74996+ pax_mirror_file_pte(vma, address, page, ptl);
74997+#endif
74998+
74999 } else {
75000 if (cow_page)
75001 mem_cgroup_uncharge_page(cow_page);
75002@@ -3497,6 +3700,12 @@ int handle_pte_fault(struct mm_struct *mm,
75003 if (flags & FAULT_FLAG_WRITE)
75004 flush_tlb_fix_spurious_fault(vma, address);
75005 }
75006+
75007+#ifdef CONFIG_PAX_SEGMEXEC
75008+ pax_mirror_pte(vma, address, pte, pmd, ptl);
75009+ return 0;
75010+#endif
75011+
75012 unlock:
75013 pte_unmap_unlock(pte, ptl);
75014 return 0;
75015@@ -3513,6 +3722,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
75016 pmd_t *pmd;
75017 pte_t *pte;
75018
75019+#ifdef CONFIG_PAX_SEGMEXEC
75020+ struct vm_area_struct *vma_m;
75021+#endif
75022+
75023 __set_current_state(TASK_RUNNING);
75024
75025 count_vm_event(PGFAULT);
75026@@ -3524,6 +3737,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
75027 if (unlikely(is_vm_hugetlb_page(vma)))
75028 return hugetlb_fault(mm, vma, address, flags);
75029
75030+#ifdef CONFIG_PAX_SEGMEXEC
75031+ vma_m = pax_find_mirror_vma(vma);
75032+ if (vma_m) {
75033+ unsigned long address_m;
75034+ pgd_t *pgd_m;
75035+ pud_t *pud_m;
75036+ pmd_t *pmd_m;
75037+
75038+ if (vma->vm_start > vma_m->vm_start) {
75039+ address_m = address;
75040+ address -= SEGMEXEC_TASK_SIZE;
75041+ vma = vma_m;
75042+ } else
75043+ address_m = address + SEGMEXEC_TASK_SIZE;
75044+
75045+ pgd_m = pgd_offset(mm, address_m);
75046+ pud_m = pud_alloc(mm, pgd_m, address_m);
75047+ if (!pud_m)
75048+ return VM_FAULT_OOM;
75049+ pmd_m = pmd_alloc(mm, pud_m, address_m);
75050+ if (!pmd_m)
75051+ return VM_FAULT_OOM;
75052+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
75053+ return VM_FAULT_OOM;
75054+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
75055+ }
75056+#endif
75057+
75058 retry:
75059 pgd = pgd_offset(mm, address);
75060 pud = pud_alloc(mm, pgd, address);
75061@@ -3565,7 +3806,7 @@ retry:
75062 * run pte_offset_map on the pmd, if an huge pmd could
75063 * materialize from under us from a different thread.
75064 */
75065- if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
75066+ if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
75067 return VM_FAULT_OOM;
75068 /* if an huge pmd materialized from under us just retry later */
75069 if (unlikely(pmd_trans_huge(*pmd)))
75070@@ -3602,6 +3843,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
75071 spin_unlock(&mm->page_table_lock);
75072 return 0;
75073 }
75074+
75075+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
75076+{
75077+ pud_t *new = pud_alloc_one(mm, address);
75078+ if (!new)
75079+ return -ENOMEM;
75080+
75081+ smp_wmb(); /* See comment in __pte_alloc */
75082+
75083+ spin_lock(&mm->page_table_lock);
75084+ if (pgd_present(*pgd)) /* Another has populated it */
75085+ pud_free(mm, new);
75086+ else
75087+ pgd_populate_kernel(mm, pgd, new);
75088+ spin_unlock(&mm->page_table_lock);
75089+ return 0;
75090+}
75091 #endif /* __PAGETABLE_PUD_FOLDED */
75092
75093 #ifndef __PAGETABLE_PMD_FOLDED
75094@@ -3632,6 +3890,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
75095 spin_unlock(&mm->page_table_lock);
75096 return 0;
75097 }
75098+
75099+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
75100+{
75101+ pmd_t *new = pmd_alloc_one(mm, address);
75102+ if (!new)
75103+ return -ENOMEM;
75104+
75105+ smp_wmb(); /* See comment in __pte_alloc */
75106+
75107+ spin_lock(&mm->page_table_lock);
75108+#ifndef __ARCH_HAS_4LEVEL_HACK
75109+ if (pud_present(*pud)) /* Another has populated it */
75110+ pmd_free(mm, new);
75111+ else
75112+ pud_populate_kernel(mm, pud, new);
75113+#else
75114+ if (pgd_present(*pud)) /* Another has populated it */
75115+ pmd_free(mm, new);
75116+ else
75117+ pgd_populate_kernel(mm, pud, new);
75118+#endif /* __ARCH_HAS_4LEVEL_HACK */
75119+ spin_unlock(&mm->page_table_lock);
75120+ return 0;
75121+}
75122 #endif /* __PAGETABLE_PMD_FOLDED */
75123
75124 int make_pages_present(unsigned long addr, unsigned long end)
75125@@ -3669,7 +3951,7 @@ static int __init gate_vma_init(void)
75126 gate_vma.vm_start = FIXADDR_USER_START;
75127 gate_vma.vm_end = FIXADDR_USER_END;
75128 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
75129- gate_vma.vm_page_prot = __P101;
75130+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
75131
75132 return 0;
75133 }
75134diff --git a/mm/mempolicy.c b/mm/mempolicy.c
75135index 002c281..9429765 100644
75136--- a/mm/mempolicy.c
75137+++ b/mm/mempolicy.c
75138@@ -655,6 +655,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
75139 unsigned long vmstart;
75140 unsigned long vmend;
75141
75142+#ifdef CONFIG_PAX_SEGMEXEC
75143+ struct vm_area_struct *vma_m;
75144+#endif
75145+
75146 vma = find_vma(mm, start);
75147 if (!vma || vma->vm_start > start)
75148 return -EFAULT;
75149@@ -691,9 +695,20 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
75150 if (err)
75151 goto out;
75152 }
75153+
75154 err = vma_replace_policy(vma, new_pol);
75155 if (err)
75156 goto out;
75157+
75158+#ifdef CONFIG_PAX_SEGMEXEC
75159+ vma_m = pax_find_mirror_vma(vma);
75160+ if (vma_m) {
75161+ err = vma_replace_policy(vma_m, new_pol);
75162+ if (err)
75163+ goto out;
75164+ }
75165+#endif
75166+
75167 }
75168
75169 out:
75170@@ -1150,6 +1165,17 @@ static long do_mbind(unsigned long start, unsigned long len,
75171
75172 if (end < start)
75173 return -EINVAL;
75174+
75175+#ifdef CONFIG_PAX_SEGMEXEC
75176+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
75177+ if (end > SEGMEXEC_TASK_SIZE)
75178+ return -EINVAL;
75179+ } else
75180+#endif
75181+
75182+ if (end > TASK_SIZE)
75183+ return -EINVAL;
75184+
75185 if (end == start)
75186 return 0;
75187
75188@@ -1373,8 +1399,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
75189 */
75190 tcred = __task_cred(task);
75191 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
75192- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
75193- !capable(CAP_SYS_NICE)) {
75194+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
75195 rcu_read_unlock();
75196 err = -EPERM;
75197 goto out_put;
75198@@ -1405,6 +1430,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
75199 goto out;
75200 }
75201
75202+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
75203+ if (mm != current->mm &&
75204+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
75205+ mmput(mm);
75206+ err = -EPERM;
75207+ goto out;
75208+ }
75209+#endif
75210+
75211 err = do_migrate_pages(mm, old, new,
75212 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
75213
75214diff --git a/mm/migrate.c b/mm/migrate.c
75215index 77ed2d7..d7adff2 100644
75216--- a/mm/migrate.c
75217+++ b/mm/migrate.c
75218@@ -143,8 +143,10 @@ static int remove_migration_pte(struct page *new, struct vm_area_struct *vma,
75219 if (is_write_migration_entry(entry))
75220 pte = pte_mkwrite(pte);
75221 #ifdef CONFIG_HUGETLB_PAGE
75222- if (PageHuge(new))
75223+ if (PageHuge(new)) {
75224 pte = pte_mkhuge(pte);
75225+ pte = arch_make_huge_pte(pte, vma, new, 0);
75226+ }
75227 #endif
75228 flush_cache_page(vma, addr, pte_pfn(pte));
75229 set_pte_at(mm, addr, ptep, pte);
75230@@ -1350,8 +1352,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
75231 */
75232 tcred = __task_cred(task);
75233 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
75234- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
75235- !capable(CAP_SYS_NICE)) {
75236+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
75237 rcu_read_unlock();
75238 err = -EPERM;
75239 goto out;
75240diff --git a/mm/mlock.c b/mm/mlock.c
75241index f0b9ce5..da8d069 100644
75242--- a/mm/mlock.c
75243+++ b/mm/mlock.c
75244@@ -13,6 +13,7 @@
75245 #include <linux/pagemap.h>
75246 #include <linux/mempolicy.h>
75247 #include <linux/syscalls.h>
75248+#include <linux/security.h>
75249 #include <linux/sched.h>
75250 #include <linux/export.h>
75251 #include <linux/rmap.h>
75252@@ -369,7 +370,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
75253 {
75254 unsigned long nstart, end, tmp;
75255 struct vm_area_struct * vma, * prev;
75256- int error;
75257+ int error = 0;
75258
75259 VM_BUG_ON(start & ~PAGE_MASK);
75260 VM_BUG_ON(len != PAGE_ALIGN(len));
75261@@ -378,6 +379,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
75262 return -EINVAL;
75263 if (end == start)
75264 return 0;
75265+ if (end > TASK_SIZE)
75266+ return -EINVAL;
75267+
75268 vma = find_vma(current->mm, start);
75269 if (!vma || vma->vm_start > start)
75270 return -ENOMEM;
75271@@ -389,6 +393,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
75272 for (nstart = start ; ; ) {
75273 vm_flags_t newflags;
75274
75275+#ifdef CONFIG_PAX_SEGMEXEC
75276+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
75277+ break;
75278+#endif
75279+
75280 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
75281
75282 newflags = vma->vm_flags | VM_LOCKED;
75283@@ -494,6 +503,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
75284 lock_limit >>= PAGE_SHIFT;
75285
75286 /* check against resource limits */
75287+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
75288 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
75289 error = do_mlock(start, len, 1);
75290 up_write(&current->mm->mmap_sem);
75291@@ -517,17 +527,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
75292 static int do_mlockall(int flags)
75293 {
75294 struct vm_area_struct * vma, * prev = NULL;
75295- unsigned int def_flags = 0;
75296
75297 if (flags & MCL_FUTURE)
75298- def_flags = VM_LOCKED;
75299- current->mm->def_flags = def_flags;
75300+ current->mm->def_flags |= VM_LOCKED;
75301+ else
75302+ current->mm->def_flags &= ~VM_LOCKED;
75303 if (flags == MCL_FUTURE)
75304 goto out;
75305
75306 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
75307 vm_flags_t newflags;
75308
75309+#ifdef CONFIG_PAX_SEGMEXEC
75310+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
75311+ break;
75312+#endif
75313+
75314+ BUG_ON(vma->vm_end > TASK_SIZE);
75315 newflags = vma->vm_flags | VM_LOCKED;
75316 if (!(flags & MCL_CURRENT))
75317 newflags &= ~VM_LOCKED;
75318@@ -560,6 +576,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
75319 lock_limit >>= PAGE_SHIFT;
75320
75321 ret = -ENOMEM;
75322+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
75323 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
75324 capable(CAP_IPC_LOCK))
75325 ret = do_mlockall(flags);
75326diff --git a/mm/mmap.c b/mm/mmap.c
75327index 9a796c4..21f8e50 100644
75328--- a/mm/mmap.c
75329+++ b/mm/mmap.c
75330@@ -31,6 +31,7 @@
75331 #include <linux/audit.h>
75332 #include <linux/khugepaged.h>
75333 #include <linux/uprobes.h>
75334+#include <linux/random.h>
75335
75336 #include <asm/uaccess.h>
75337 #include <asm/cacheflush.h>
75338@@ -47,6 +48,16 @@
75339 #define arch_rebalance_pgtables(addr, len) (addr)
75340 #endif
75341
75342+static inline void verify_mm_writelocked(struct mm_struct *mm)
75343+{
75344+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
75345+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
75346+ up_read(&mm->mmap_sem);
75347+ BUG();
75348+ }
75349+#endif
75350+}
75351+
75352 static void unmap_region(struct mm_struct *mm,
75353 struct vm_area_struct *vma, struct vm_area_struct *prev,
75354 unsigned long start, unsigned long end);
75355@@ -66,22 +77,32 @@ static void unmap_region(struct mm_struct *mm,
75356 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
75357 *
75358 */
75359-pgprot_t protection_map[16] = {
75360+pgprot_t protection_map[16] __read_only = {
75361 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
75362 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
75363 };
75364
75365-pgprot_t vm_get_page_prot(unsigned long vm_flags)
75366+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
75367 {
75368- return __pgprot(pgprot_val(protection_map[vm_flags &
75369+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
75370 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
75371 pgprot_val(arch_vm_get_page_prot(vm_flags)));
75372+
75373+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
75374+ if (!(__supported_pte_mask & _PAGE_NX) &&
75375+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
75376+ (vm_flags & (VM_READ | VM_WRITE)))
75377+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
75378+#endif
75379+
75380+ return prot;
75381 }
75382 EXPORT_SYMBOL(vm_get_page_prot);
75383
75384 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
75385 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
75386 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
75387+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
75388 /*
75389 * Make sure vm_committed_as in one cacheline and not cacheline shared with
75390 * other variables. It can be updated by several CPUs frequently.
75391@@ -223,6 +244,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
75392 struct vm_area_struct *next = vma->vm_next;
75393
75394 might_sleep();
75395+ BUG_ON(vma->vm_mirror);
75396 if (vma->vm_ops && vma->vm_ops->close)
75397 vma->vm_ops->close(vma);
75398 if (vma->vm_file)
75399@@ -266,6 +288,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
75400 * not page aligned -Ram Gupta
75401 */
75402 rlim = rlimit(RLIMIT_DATA);
75403+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
75404 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
75405 (mm->end_data - mm->start_data) > rlim)
75406 goto out;
75407@@ -736,6 +759,12 @@ static int
75408 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
75409 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
75410 {
75411+
75412+#ifdef CONFIG_PAX_SEGMEXEC
75413+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
75414+ return 0;
75415+#endif
75416+
75417 if (is_mergeable_vma(vma, file, vm_flags) &&
75418 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
75419 if (vma->vm_pgoff == vm_pgoff)
75420@@ -755,6 +784,12 @@ static int
75421 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
75422 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
75423 {
75424+
75425+#ifdef CONFIG_PAX_SEGMEXEC
75426+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
75427+ return 0;
75428+#endif
75429+
75430 if (is_mergeable_vma(vma, file, vm_flags) &&
75431 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
75432 pgoff_t vm_pglen;
75433@@ -797,13 +832,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
75434 struct vm_area_struct *vma_merge(struct mm_struct *mm,
75435 struct vm_area_struct *prev, unsigned long addr,
75436 unsigned long end, unsigned long vm_flags,
75437- struct anon_vma *anon_vma, struct file *file,
75438+ struct anon_vma *anon_vma, struct file *file,
75439 pgoff_t pgoff, struct mempolicy *policy)
75440 {
75441 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
75442 struct vm_area_struct *area, *next;
75443 int err;
75444
75445+#ifdef CONFIG_PAX_SEGMEXEC
75446+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
75447+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
75448+
75449+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
75450+#endif
75451+
75452 /*
75453 * We later require that vma->vm_flags == vm_flags,
75454 * so this tests vma->vm_flags & VM_SPECIAL, too.
75455@@ -819,6 +861,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
75456 if (next && next->vm_end == end) /* cases 6, 7, 8 */
75457 next = next->vm_next;
75458
75459+#ifdef CONFIG_PAX_SEGMEXEC
75460+ if (prev)
75461+ prev_m = pax_find_mirror_vma(prev);
75462+ if (area)
75463+ area_m = pax_find_mirror_vma(area);
75464+ if (next)
75465+ next_m = pax_find_mirror_vma(next);
75466+#endif
75467+
75468 /*
75469 * Can it merge with the predecessor?
75470 */
75471@@ -838,9 +889,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
75472 /* cases 1, 6 */
75473 err = vma_adjust(prev, prev->vm_start,
75474 next->vm_end, prev->vm_pgoff, NULL);
75475- } else /* cases 2, 5, 7 */
75476+
75477+#ifdef CONFIG_PAX_SEGMEXEC
75478+ if (!err && prev_m)
75479+ err = vma_adjust(prev_m, prev_m->vm_start,
75480+ next_m->vm_end, prev_m->vm_pgoff, NULL);
75481+#endif
75482+
75483+ } else { /* cases 2, 5, 7 */
75484 err = vma_adjust(prev, prev->vm_start,
75485 end, prev->vm_pgoff, NULL);
75486+
75487+#ifdef CONFIG_PAX_SEGMEXEC
75488+ if (!err && prev_m)
75489+ err = vma_adjust(prev_m, prev_m->vm_start,
75490+ end_m, prev_m->vm_pgoff, NULL);
75491+#endif
75492+
75493+ }
75494 if (err)
75495 return NULL;
75496 khugepaged_enter_vma_merge(prev);
75497@@ -854,12 +920,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
75498 mpol_equal(policy, vma_policy(next)) &&
75499 can_vma_merge_before(next, vm_flags,
75500 anon_vma, file, pgoff+pglen)) {
75501- if (prev && addr < prev->vm_end) /* case 4 */
75502+ if (prev && addr < prev->vm_end) { /* case 4 */
75503 err = vma_adjust(prev, prev->vm_start,
75504 addr, prev->vm_pgoff, NULL);
75505- else /* cases 3, 8 */
75506+
75507+#ifdef CONFIG_PAX_SEGMEXEC
75508+ if (!err && prev_m)
75509+ err = vma_adjust(prev_m, prev_m->vm_start,
75510+ addr_m, prev_m->vm_pgoff, NULL);
75511+#endif
75512+
75513+ } else { /* cases 3, 8 */
75514 err = vma_adjust(area, addr, next->vm_end,
75515 next->vm_pgoff - pglen, NULL);
75516+
75517+#ifdef CONFIG_PAX_SEGMEXEC
75518+ if (!err && area_m)
75519+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
75520+ next_m->vm_pgoff - pglen, NULL);
75521+#endif
75522+
75523+ }
75524 if (err)
75525 return NULL;
75526 khugepaged_enter_vma_merge(area);
75527@@ -968,16 +1049,13 @@ none:
75528 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
75529 struct file *file, long pages)
75530 {
75531- const unsigned long stack_flags
75532- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
75533-
75534 mm->total_vm += pages;
75535
75536 if (file) {
75537 mm->shared_vm += pages;
75538 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
75539 mm->exec_vm += pages;
75540- } else if (flags & stack_flags)
75541+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
75542 mm->stack_vm += pages;
75543 }
75544 #endif /* CONFIG_PROC_FS */
75545@@ -1013,7 +1091,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
75546 * (the exception is when the underlying filesystem is noexec
75547 * mounted, in which case we dont add PROT_EXEC.)
75548 */
75549- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
75550+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
75551 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
75552 prot |= PROT_EXEC;
75553
75554@@ -1039,7 +1117,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
75555 /* Obtain the address to map to. we verify (or select) it and ensure
75556 * that it represents a valid section of the address space.
75557 */
75558- addr = get_unmapped_area(file, addr, len, pgoff, flags);
75559+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
75560 if (addr & ~PAGE_MASK)
75561 return addr;
75562
75563@@ -1050,6 +1128,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
75564 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
75565 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
75566
75567+#ifdef CONFIG_PAX_MPROTECT
75568+ if (mm->pax_flags & MF_PAX_MPROTECT) {
75569+#ifndef CONFIG_PAX_MPROTECT_COMPAT
75570+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
75571+ gr_log_rwxmmap(file);
75572+
75573+#ifdef CONFIG_PAX_EMUPLT
75574+ vm_flags &= ~VM_EXEC;
75575+#else
75576+ return -EPERM;
75577+#endif
75578+
75579+ }
75580+
75581+ if (!(vm_flags & VM_EXEC))
75582+ vm_flags &= ~VM_MAYEXEC;
75583+#else
75584+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
75585+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
75586+#endif
75587+ else
75588+ vm_flags &= ~VM_MAYWRITE;
75589+ }
75590+#endif
75591+
75592+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
75593+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
75594+ vm_flags &= ~VM_PAGEEXEC;
75595+#endif
75596+
75597 if (flags & MAP_LOCKED)
75598 if (!can_do_mlock())
75599 return -EPERM;
75600@@ -1061,6 +1169,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
75601 locked += mm->locked_vm;
75602 lock_limit = rlimit(RLIMIT_MEMLOCK);
75603 lock_limit >>= PAGE_SHIFT;
75604+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
75605 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
75606 return -EAGAIN;
75607 }
75608@@ -1127,6 +1236,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
75609 }
75610 }
75611
75612+ if (!gr_acl_handle_mmap(file, prot))
75613+ return -EACCES;
75614+
75615 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
75616 }
75617
75618@@ -1203,7 +1315,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
75619 vm_flags_t vm_flags = vma->vm_flags;
75620
75621 /* If it was private or non-writable, the write bit is already clear */
75622- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
75623+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
75624 return 0;
75625
75626 /* The backer wishes to know when pages are first written to? */
75627@@ -1252,13 +1364,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
75628 unsigned long charged = 0;
75629 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
75630
75631+#ifdef CONFIG_PAX_SEGMEXEC
75632+ struct vm_area_struct *vma_m = NULL;
75633+#endif
75634+
75635+ /*
75636+ * mm->mmap_sem is required to protect against another thread
75637+ * changing the mappings in case we sleep.
75638+ */
75639+ verify_mm_writelocked(mm);
75640+
75641 /* Clear old maps */
75642 error = -ENOMEM;
75643-munmap_back:
75644 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
75645 if (do_munmap(mm, addr, len))
75646 return -ENOMEM;
75647- goto munmap_back;
75648+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
75649 }
75650
75651 /* Check against address space limit. */
75652@@ -1307,6 +1428,16 @@ munmap_back:
75653 goto unacct_error;
75654 }
75655
75656+#ifdef CONFIG_PAX_SEGMEXEC
75657+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
75658+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
75659+ if (!vma_m) {
75660+ error = -ENOMEM;
75661+ goto free_vma;
75662+ }
75663+ }
75664+#endif
75665+
75666 vma->vm_mm = mm;
75667 vma->vm_start = addr;
75668 vma->vm_end = addr + len;
75669@@ -1331,6 +1462,13 @@ munmap_back:
75670 if (error)
75671 goto unmap_and_free_vma;
75672
75673+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
75674+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
75675+ vma->vm_flags |= VM_PAGEEXEC;
75676+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
75677+ }
75678+#endif
75679+
75680 /* Can addr have changed??
75681 *
75682 * Answer: Yes, several device drivers can do it in their
75683@@ -1365,6 +1503,11 @@ munmap_back:
75684 vma_link(mm, vma, prev, rb_link, rb_parent);
75685 file = vma->vm_file;
75686
75687+#ifdef CONFIG_PAX_SEGMEXEC
75688+ if (vma_m)
75689+ BUG_ON(pax_mirror_vma(vma_m, vma));
75690+#endif
75691+
75692 /* Once vma denies write, undo our temporary denial count */
75693 if (correct_wcount)
75694 atomic_inc(&inode->i_writecount);
75695@@ -1372,6 +1515,7 @@ out:
75696 perf_event_mmap(vma);
75697
75698 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
75699+ track_exec_limit(mm, addr, addr + len, vm_flags);
75700 if (vm_flags & VM_LOCKED) {
75701 if (!mlock_vma_pages_range(vma, addr, addr + len))
75702 mm->locked_vm += (len >> PAGE_SHIFT);
75703@@ -1393,6 +1537,12 @@ unmap_and_free_vma:
75704 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
75705 charged = 0;
75706 free_vma:
75707+
75708+#ifdef CONFIG_PAX_SEGMEXEC
75709+ if (vma_m)
75710+ kmem_cache_free(vm_area_cachep, vma_m);
75711+#endif
75712+
75713 kmem_cache_free(vm_area_cachep, vma);
75714 unacct_error:
75715 if (charged)
75716@@ -1400,6 +1550,62 @@ unacct_error:
75717 return error;
75718 }
75719
75720+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
75721+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
75722+{
75723+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
75724+ return (random32() & 0xFF) << PAGE_SHIFT;
75725+
75726+ return 0;
75727+}
75728+#endif
75729+
75730+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
75731+{
75732+ if (!vma) {
75733+#ifdef CONFIG_STACK_GROWSUP
75734+ if (addr > sysctl_heap_stack_gap)
75735+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
75736+ else
75737+ vma = find_vma(current->mm, 0);
75738+ if (vma && (vma->vm_flags & VM_GROWSUP))
75739+ return false;
75740+#endif
75741+ return true;
75742+ }
75743+
75744+ if (addr + len > vma->vm_start)
75745+ return false;
75746+
75747+ if (vma->vm_flags & VM_GROWSDOWN)
75748+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
75749+#ifdef CONFIG_STACK_GROWSUP
75750+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
75751+ return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
75752+#endif
75753+ else if (offset)
75754+ return offset <= vma->vm_start - addr - len;
75755+
75756+ return true;
75757+}
75758+
75759+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
75760+{
75761+ if (vma->vm_start < len)
75762+ return -ENOMEM;
75763+
75764+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
75765+ if (offset <= vma->vm_start - len)
75766+ return vma->vm_start - len - offset;
75767+ else
75768+ return -ENOMEM;
75769+ }
75770+
75771+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
75772+ return vma->vm_start - len - sysctl_heap_stack_gap;
75773+ return -ENOMEM;
75774+}
75775+
75776 /* Get an address range which is currently unmapped.
75777 * For shmat() with addr=0.
75778 *
75779@@ -1426,18 +1632,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
75780 if (flags & MAP_FIXED)
75781 return addr;
75782
75783+#ifdef CONFIG_PAX_RANDMMAP
75784+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
75785+#endif
75786+
75787 if (addr) {
75788 addr = PAGE_ALIGN(addr);
75789- vma = find_vma(mm, addr);
75790- if (TASK_SIZE - len >= addr &&
75791- (!vma || addr + len <= vma->vm_start))
75792- return addr;
75793+ if (TASK_SIZE - len >= addr) {
75794+ vma = find_vma(mm, addr);
75795+ if (check_heap_stack_gap(vma, addr, len))
75796+ return addr;
75797+ }
75798 }
75799 if (len > mm->cached_hole_size) {
75800- start_addr = addr = mm->free_area_cache;
75801+ start_addr = addr = mm->free_area_cache;
75802 } else {
75803- start_addr = addr = TASK_UNMAPPED_BASE;
75804- mm->cached_hole_size = 0;
75805+ start_addr = addr = mm->mmap_base;
75806+ mm->cached_hole_size = 0;
75807 }
75808
75809 full_search:
75810@@ -1448,34 +1659,40 @@ full_search:
75811 * Start a new search - just in case we missed
75812 * some holes.
75813 */
75814- if (start_addr != TASK_UNMAPPED_BASE) {
75815- addr = TASK_UNMAPPED_BASE;
75816- start_addr = addr;
75817+ if (start_addr != mm->mmap_base) {
75818+ start_addr = addr = mm->mmap_base;
75819 mm->cached_hole_size = 0;
75820 goto full_search;
75821 }
75822 return -ENOMEM;
75823 }
75824- if (!vma || addr + len <= vma->vm_start) {
75825- /*
75826- * Remember the place where we stopped the search:
75827- */
75828- mm->free_area_cache = addr + len;
75829- return addr;
75830- }
75831+ if (check_heap_stack_gap(vma, addr, len))
75832+ break;
75833 if (addr + mm->cached_hole_size < vma->vm_start)
75834 mm->cached_hole_size = vma->vm_start - addr;
75835 addr = vma->vm_end;
75836 }
75837+
75838+ /*
75839+ * Remember the place where we stopped the search:
75840+ */
75841+ mm->free_area_cache = addr + len;
75842+ return addr;
75843 }
75844 #endif
75845
75846 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
75847 {
75848+
75849+#ifdef CONFIG_PAX_SEGMEXEC
75850+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
75851+ return;
75852+#endif
75853+
75854 /*
75855 * Is this a new hole at the lowest possible address?
75856 */
75857- if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
75858+ if (addr >= mm->mmap_base && addr < mm->free_area_cache)
75859 mm->free_area_cache = addr;
75860 }
75861
75862@@ -1491,7 +1708,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
75863 {
75864 struct vm_area_struct *vma;
75865 struct mm_struct *mm = current->mm;
75866- unsigned long addr = addr0, start_addr;
75867+ unsigned long base = mm->mmap_base, addr = addr0, start_addr;
75868
75869 /* requested length too big for entire address space */
75870 if (len > TASK_SIZE)
75871@@ -1500,13 +1717,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
75872 if (flags & MAP_FIXED)
75873 return addr;
75874
75875+#ifdef CONFIG_PAX_RANDMMAP
75876+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
75877+#endif
75878+
75879 /* requesting a specific address */
75880 if (addr) {
75881 addr = PAGE_ALIGN(addr);
75882- vma = find_vma(mm, addr);
75883- if (TASK_SIZE - len >= addr &&
75884- (!vma || addr + len <= vma->vm_start))
75885- return addr;
75886+ if (TASK_SIZE - len >= addr) {
75887+ vma = find_vma(mm, addr);
75888+ if (check_heap_stack_gap(vma, addr, len))
75889+ return addr;
75890+ }
75891 }
75892
75893 /* check if free_area_cache is useful for us */
75894@@ -1530,7 +1752,7 @@ try_again:
75895 * return with success:
75896 */
75897 vma = find_vma(mm, addr);
75898- if (!vma || addr+len <= vma->vm_start)
75899+ if (check_heap_stack_gap(vma, addr, len))
75900 /* remember the address as a hint for next time */
75901 return (mm->free_area_cache = addr);
75902
75903@@ -1539,8 +1761,8 @@ try_again:
75904 mm->cached_hole_size = vma->vm_start - addr;
75905
75906 /* try just below the current vma->vm_start */
75907- addr = vma->vm_start-len;
75908- } while (len < vma->vm_start);
75909+ addr = skip_heap_stack_gap(vma, len);
75910+ } while (!IS_ERR_VALUE(addr));
75911
75912 fail:
75913 /*
75914@@ -1563,13 +1785,21 @@ fail:
75915 * can happen with large stack limits and large mmap()
75916 * allocations.
75917 */
75918+ mm->mmap_base = TASK_UNMAPPED_BASE;
75919+
75920+#ifdef CONFIG_PAX_RANDMMAP
75921+ if (mm->pax_flags & MF_PAX_RANDMMAP)
75922+ mm->mmap_base += mm->delta_mmap;
75923+#endif
75924+
75925+ mm->free_area_cache = mm->mmap_base;
75926 mm->cached_hole_size = ~0UL;
75927- mm->free_area_cache = TASK_UNMAPPED_BASE;
75928 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
75929 /*
75930 * Restore the topdown base:
75931 */
75932- mm->free_area_cache = mm->mmap_base;
75933+ mm->mmap_base = base;
75934+ mm->free_area_cache = base;
75935 mm->cached_hole_size = ~0UL;
75936
75937 return addr;
75938@@ -1578,6 +1808,12 @@ fail:
75939
75940 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
75941 {
75942+
75943+#ifdef CONFIG_PAX_SEGMEXEC
75944+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
75945+ return;
75946+#endif
75947+
75948 /*
75949 * Is this a new hole at the highest possible address?
75950 */
75951@@ -1585,8 +1821,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
75952 mm->free_area_cache = addr;
75953
75954 /* dont allow allocations above current base */
75955- if (mm->free_area_cache > mm->mmap_base)
75956+ if (mm->free_area_cache > mm->mmap_base) {
75957 mm->free_area_cache = mm->mmap_base;
75958+ mm->cached_hole_size = ~0UL;
75959+ }
75960 }
75961
75962 unsigned long
75963@@ -1685,6 +1923,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
75964 return vma;
75965 }
75966
75967+#ifdef CONFIG_PAX_SEGMEXEC
75968+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
75969+{
75970+ struct vm_area_struct *vma_m;
75971+
75972+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
75973+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
75974+ BUG_ON(vma->vm_mirror);
75975+ return NULL;
75976+ }
75977+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
75978+ vma_m = vma->vm_mirror;
75979+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
75980+ BUG_ON(vma->vm_file != vma_m->vm_file);
75981+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
75982+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
75983+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
75984+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
75985+ return vma_m;
75986+}
75987+#endif
75988+
75989 /*
75990 * Verify that the stack growth is acceptable and
75991 * update accounting. This is shared with both the
75992@@ -1701,6 +1961,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
75993 return -ENOMEM;
75994
75995 /* Stack limit test */
75996+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
75997 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
75998 return -ENOMEM;
75999
76000@@ -1711,6 +1972,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
76001 locked = mm->locked_vm + grow;
76002 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
76003 limit >>= PAGE_SHIFT;
76004+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
76005 if (locked > limit && !capable(CAP_IPC_LOCK))
76006 return -ENOMEM;
76007 }
76008@@ -1740,37 +2002,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
76009 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
76010 * vma is the last one with address > vma->vm_end. Have to extend vma.
76011 */
76012+#ifndef CONFIG_IA64
76013+static
76014+#endif
76015 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
76016 {
76017 int error;
76018+ bool locknext;
76019
76020 if (!(vma->vm_flags & VM_GROWSUP))
76021 return -EFAULT;
76022
76023+ /* Also guard against wrapping around to address 0. */
76024+ if (address < PAGE_ALIGN(address+1))
76025+ address = PAGE_ALIGN(address+1);
76026+ else
76027+ return -ENOMEM;
76028+
76029 /*
76030 * We must make sure the anon_vma is allocated
76031 * so that the anon_vma locking is not a noop.
76032 */
76033 if (unlikely(anon_vma_prepare(vma)))
76034 return -ENOMEM;
76035+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
76036+ if (locknext && anon_vma_prepare(vma->vm_next))
76037+ return -ENOMEM;
76038 vma_lock_anon_vma(vma);
76039+ if (locknext)
76040+ vma_lock_anon_vma(vma->vm_next);
76041
76042 /*
76043 * vma->vm_start/vm_end cannot change under us because the caller
76044 * is required to hold the mmap_sem in read mode. We need the
76045- * anon_vma lock to serialize against concurrent expand_stacks.
76046- * Also guard against wrapping around to address 0.
76047+ * anon_vma locks to serialize against concurrent expand_stacks
76048+ * and expand_upwards.
76049 */
76050- if (address < PAGE_ALIGN(address+4))
76051- address = PAGE_ALIGN(address+4);
76052- else {
76053- vma_unlock_anon_vma(vma);
76054- return -ENOMEM;
76055- }
76056 error = 0;
76057
76058 /* Somebody else might have raced and expanded it already */
76059- if (address > vma->vm_end) {
76060+ 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)
76061+ error = -ENOMEM;
76062+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
76063 unsigned long size, grow;
76064
76065 size = address - vma->vm_start;
76066@@ -1787,6 +2060,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
76067 }
76068 }
76069 }
76070+ if (locknext)
76071+ vma_unlock_anon_vma(vma->vm_next);
76072 vma_unlock_anon_vma(vma);
76073 khugepaged_enter_vma_merge(vma);
76074 validate_mm(vma->vm_mm);
76075@@ -1801,6 +2076,8 @@ int expand_downwards(struct vm_area_struct *vma,
76076 unsigned long address)
76077 {
76078 int error;
76079+ bool lockprev = false;
76080+ struct vm_area_struct *prev;
76081
76082 /*
76083 * We must make sure the anon_vma is allocated
76084@@ -1814,6 +2091,15 @@ int expand_downwards(struct vm_area_struct *vma,
76085 if (error)
76086 return error;
76087
76088+ prev = vma->vm_prev;
76089+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
76090+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
76091+#endif
76092+ if (lockprev && anon_vma_prepare(prev))
76093+ return -ENOMEM;
76094+ if (lockprev)
76095+ vma_lock_anon_vma(prev);
76096+
76097 vma_lock_anon_vma(vma);
76098
76099 /*
76100@@ -1823,9 +2109,17 @@ int expand_downwards(struct vm_area_struct *vma,
76101 */
76102
76103 /* Somebody else might have raced and expanded it already */
76104- if (address < vma->vm_start) {
76105+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
76106+ error = -ENOMEM;
76107+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
76108 unsigned long size, grow;
76109
76110+#ifdef CONFIG_PAX_SEGMEXEC
76111+ struct vm_area_struct *vma_m;
76112+
76113+ vma_m = pax_find_mirror_vma(vma);
76114+#endif
76115+
76116 size = vma->vm_end - address;
76117 grow = (vma->vm_start - address) >> PAGE_SHIFT;
76118
76119@@ -1837,6 +2131,17 @@ int expand_downwards(struct vm_area_struct *vma,
76120 vma->vm_start = address;
76121 vma->vm_pgoff -= grow;
76122 anon_vma_interval_tree_post_update_vma(vma);
76123+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
76124+
76125+#ifdef CONFIG_PAX_SEGMEXEC
76126+ if (vma_m) {
76127+ anon_vma_interval_tree_pre_update_vma(vma_m);
76128+ vma_m->vm_start -= grow << PAGE_SHIFT;
76129+ vma_m->vm_pgoff -= grow;
76130+ anon_vma_interval_tree_post_update_vma(vma_m);
76131+ }
76132+#endif
76133+
76134 perf_event_mmap(vma);
76135 }
76136 }
76137@@ -1914,6 +2219,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
76138 do {
76139 long nrpages = vma_pages(vma);
76140
76141+#ifdef CONFIG_PAX_SEGMEXEC
76142+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
76143+ vma = remove_vma(vma);
76144+ continue;
76145+ }
76146+#endif
76147+
76148 if (vma->vm_flags & VM_ACCOUNT)
76149 nr_accounted += nrpages;
76150 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
76151@@ -1959,6 +2271,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
76152 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
76153 vma->vm_prev = NULL;
76154 do {
76155+
76156+#ifdef CONFIG_PAX_SEGMEXEC
76157+ if (vma->vm_mirror) {
76158+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
76159+ vma->vm_mirror->vm_mirror = NULL;
76160+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
76161+ vma->vm_mirror = NULL;
76162+ }
76163+#endif
76164+
76165 rb_erase(&vma->vm_rb, &mm->mm_rb);
76166 mm->map_count--;
76167 tail_vma = vma;
76168@@ -1987,14 +2309,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
76169 struct vm_area_struct *new;
76170 int err = -ENOMEM;
76171
76172+#ifdef CONFIG_PAX_SEGMEXEC
76173+ struct vm_area_struct *vma_m, *new_m = NULL;
76174+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
76175+#endif
76176+
76177 if (is_vm_hugetlb_page(vma) && (addr &
76178 ~(huge_page_mask(hstate_vma(vma)))))
76179 return -EINVAL;
76180
76181+#ifdef CONFIG_PAX_SEGMEXEC
76182+ vma_m = pax_find_mirror_vma(vma);
76183+#endif
76184+
76185 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
76186 if (!new)
76187 goto out_err;
76188
76189+#ifdef CONFIG_PAX_SEGMEXEC
76190+ if (vma_m) {
76191+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
76192+ if (!new_m) {
76193+ kmem_cache_free(vm_area_cachep, new);
76194+ goto out_err;
76195+ }
76196+ }
76197+#endif
76198+
76199 /* most fields are the same, copy all, and then fixup */
76200 *new = *vma;
76201
76202@@ -2007,6 +2348,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
76203 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
76204 }
76205
76206+#ifdef CONFIG_PAX_SEGMEXEC
76207+ if (vma_m) {
76208+ *new_m = *vma_m;
76209+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
76210+ new_m->vm_mirror = new;
76211+ new->vm_mirror = new_m;
76212+
76213+ if (new_below)
76214+ new_m->vm_end = addr_m;
76215+ else {
76216+ new_m->vm_start = addr_m;
76217+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
76218+ }
76219+ }
76220+#endif
76221+
76222 pol = mpol_dup(vma_policy(vma));
76223 if (IS_ERR(pol)) {
76224 err = PTR_ERR(pol);
76225@@ -2029,6 +2386,36 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
76226 else
76227 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
76228
76229+#ifdef CONFIG_PAX_SEGMEXEC
76230+ if (!err && vma_m) {
76231+ if (anon_vma_clone(new_m, vma_m))
76232+ goto out_free_mpol;
76233+
76234+ mpol_get(pol);
76235+ vma_set_policy(new_m, pol);
76236+
76237+ if (new_m->vm_file)
76238+ get_file(new_m->vm_file);
76239+
76240+ if (new_m->vm_ops && new_m->vm_ops->open)
76241+ new_m->vm_ops->open(new_m);
76242+
76243+ if (new_below)
76244+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
76245+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
76246+ else
76247+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
76248+
76249+ if (err) {
76250+ if (new_m->vm_ops && new_m->vm_ops->close)
76251+ new_m->vm_ops->close(new_m);
76252+ if (new_m->vm_file)
76253+ fput(new_m->vm_file);
76254+ mpol_put(pol);
76255+ }
76256+ }
76257+#endif
76258+
76259 /* Success. */
76260 if (!err)
76261 return 0;
76262@@ -2038,10 +2425,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
76263 new->vm_ops->close(new);
76264 if (new->vm_file)
76265 fput(new->vm_file);
76266- unlink_anon_vmas(new);
76267 out_free_mpol:
76268 mpol_put(pol);
76269 out_free_vma:
76270+
76271+#ifdef CONFIG_PAX_SEGMEXEC
76272+ if (new_m) {
76273+ unlink_anon_vmas(new_m);
76274+ kmem_cache_free(vm_area_cachep, new_m);
76275+ }
76276+#endif
76277+
76278+ unlink_anon_vmas(new);
76279 kmem_cache_free(vm_area_cachep, new);
76280 out_err:
76281 return err;
76282@@ -2054,6 +2449,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
76283 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
76284 unsigned long addr, int new_below)
76285 {
76286+
76287+#ifdef CONFIG_PAX_SEGMEXEC
76288+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
76289+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
76290+ if (mm->map_count >= sysctl_max_map_count-1)
76291+ return -ENOMEM;
76292+ } else
76293+#endif
76294+
76295 if (mm->map_count >= sysctl_max_map_count)
76296 return -ENOMEM;
76297
76298@@ -2065,11 +2469,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
76299 * work. This now handles partial unmappings.
76300 * Jeremy Fitzhardinge <jeremy@goop.org>
76301 */
76302+#ifdef CONFIG_PAX_SEGMEXEC
76303 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
76304 {
76305+ int ret = __do_munmap(mm, start, len);
76306+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
76307+ return ret;
76308+
76309+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
76310+}
76311+
76312+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
76313+#else
76314+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
76315+#endif
76316+{
76317 unsigned long end;
76318 struct vm_area_struct *vma, *prev, *last;
76319
76320+ /*
76321+ * mm->mmap_sem is required to protect against another thread
76322+ * changing the mappings in case we sleep.
76323+ */
76324+ verify_mm_writelocked(mm);
76325+
76326 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
76327 return -EINVAL;
76328
76329@@ -2144,6 +2567,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
76330 /* Fix up all other VM information */
76331 remove_vma_list(mm, vma);
76332
76333+ track_exec_limit(mm, start, end, 0UL);
76334+
76335 return 0;
76336 }
76337
76338@@ -2152,6 +2577,13 @@ int vm_munmap(unsigned long start, size_t len)
76339 int ret;
76340 struct mm_struct *mm = current->mm;
76341
76342+
76343+#ifdef CONFIG_PAX_SEGMEXEC
76344+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
76345+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
76346+ return -EINVAL;
76347+#endif
76348+
76349 down_write(&mm->mmap_sem);
76350 ret = do_munmap(mm, start, len);
76351 up_write(&mm->mmap_sem);
76352@@ -2165,16 +2597,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
76353 return vm_munmap(addr, len);
76354 }
76355
76356-static inline void verify_mm_writelocked(struct mm_struct *mm)
76357-{
76358-#ifdef CONFIG_DEBUG_VM
76359- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
76360- WARN_ON(1);
76361- up_read(&mm->mmap_sem);
76362- }
76363-#endif
76364-}
76365-
76366 /*
76367 * this is really a simplified "do_mmap". it only handles
76368 * anonymous maps. eventually we may be able to do some
76369@@ -2188,6 +2610,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
76370 struct rb_node ** rb_link, * rb_parent;
76371 pgoff_t pgoff = addr >> PAGE_SHIFT;
76372 int error;
76373+ unsigned long charged;
76374
76375 len = PAGE_ALIGN(len);
76376 if (!len)
76377@@ -2195,16 +2618,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
76378
76379 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
76380
76381+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
76382+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
76383+ flags &= ~VM_EXEC;
76384+
76385+#ifdef CONFIG_PAX_MPROTECT
76386+ if (mm->pax_flags & MF_PAX_MPROTECT)
76387+ flags &= ~VM_MAYEXEC;
76388+#endif
76389+
76390+ }
76391+#endif
76392+
76393 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
76394 if (error & ~PAGE_MASK)
76395 return error;
76396
76397+ charged = len >> PAGE_SHIFT;
76398+
76399 /*
76400 * mlock MCL_FUTURE?
76401 */
76402 if (mm->def_flags & VM_LOCKED) {
76403 unsigned long locked, lock_limit;
76404- locked = len >> PAGE_SHIFT;
76405+ locked = charged;
76406 locked += mm->locked_vm;
76407 lock_limit = rlimit(RLIMIT_MEMLOCK);
76408 lock_limit >>= PAGE_SHIFT;
76409@@ -2221,21 +2658,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
76410 /*
76411 * Clear old maps. this also does some error checking for us
76412 */
76413- munmap_back:
76414 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
76415 if (do_munmap(mm, addr, len))
76416 return -ENOMEM;
76417- goto munmap_back;
76418+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
76419 }
76420
76421 /* Check against address space limits *after* clearing old maps... */
76422- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
76423+ if (!may_expand_vm(mm, charged))
76424 return -ENOMEM;
76425
76426 if (mm->map_count > sysctl_max_map_count)
76427 return -ENOMEM;
76428
76429- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
76430+ if (security_vm_enough_memory_mm(mm, charged))
76431 return -ENOMEM;
76432
76433 /* Can we just expand an old private anonymous mapping? */
76434@@ -2249,7 +2685,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
76435 */
76436 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
76437 if (!vma) {
76438- vm_unacct_memory(len >> PAGE_SHIFT);
76439+ vm_unacct_memory(charged);
76440 return -ENOMEM;
76441 }
76442
76443@@ -2263,11 +2699,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
76444 vma_link(mm, vma, prev, rb_link, rb_parent);
76445 out:
76446 perf_event_mmap(vma);
76447- mm->total_vm += len >> PAGE_SHIFT;
76448+ mm->total_vm += charged;
76449 if (flags & VM_LOCKED) {
76450 if (!mlock_vma_pages_range(vma, addr, addr + len))
76451- mm->locked_vm += (len >> PAGE_SHIFT);
76452+ mm->locked_vm += charged;
76453 }
76454+ track_exec_limit(mm, addr, addr + len, flags);
76455 return addr;
76456 }
76457
76458@@ -2325,6 +2762,7 @@ void exit_mmap(struct mm_struct *mm)
76459 while (vma) {
76460 if (vma->vm_flags & VM_ACCOUNT)
76461 nr_accounted += vma_pages(vma);
76462+ vma->vm_mirror = NULL;
76463 vma = remove_vma(vma);
76464 }
76465 vm_unacct_memory(nr_accounted);
76466@@ -2341,6 +2779,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
76467 struct vm_area_struct *prev;
76468 struct rb_node **rb_link, *rb_parent;
76469
76470+#ifdef CONFIG_PAX_SEGMEXEC
76471+ struct vm_area_struct *vma_m = NULL;
76472+#endif
76473+
76474+ if (security_mmap_addr(vma->vm_start))
76475+ return -EPERM;
76476+
76477 /*
76478 * The vm_pgoff of a purely anonymous vma should be irrelevant
76479 * until its first write fault, when page's anon_vma and index
76480@@ -2364,7 +2809,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
76481 security_vm_enough_memory_mm(mm, vma_pages(vma)))
76482 return -ENOMEM;
76483
76484+#ifdef CONFIG_PAX_SEGMEXEC
76485+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
76486+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
76487+ if (!vma_m)
76488+ return -ENOMEM;
76489+ }
76490+#endif
76491+
76492 vma_link(mm, vma, prev, rb_link, rb_parent);
76493+
76494+#ifdef CONFIG_PAX_SEGMEXEC
76495+ if (vma_m)
76496+ BUG_ON(pax_mirror_vma(vma_m, vma));
76497+#endif
76498+
76499 return 0;
76500 }
76501
76502@@ -2384,6 +2843,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
76503 struct mempolicy *pol;
76504 bool faulted_in_anon_vma = true;
76505
76506+ BUG_ON(vma->vm_mirror);
76507+
76508 /*
76509 * If anonymous vma has not yet been faulted, update new pgoff
76510 * to match new location, to increase its chance of merging.
76511@@ -2450,6 +2911,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
76512 return NULL;
76513 }
76514
76515+#ifdef CONFIG_PAX_SEGMEXEC
76516+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
76517+{
76518+ struct vm_area_struct *prev_m;
76519+ struct rb_node **rb_link_m, *rb_parent_m;
76520+ struct mempolicy *pol_m;
76521+
76522+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
76523+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
76524+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
76525+ *vma_m = *vma;
76526+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
76527+ if (anon_vma_clone(vma_m, vma))
76528+ return -ENOMEM;
76529+ pol_m = vma_policy(vma_m);
76530+ mpol_get(pol_m);
76531+ vma_set_policy(vma_m, pol_m);
76532+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
76533+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
76534+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
76535+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
76536+ if (vma_m->vm_file)
76537+ get_file(vma_m->vm_file);
76538+ if (vma_m->vm_ops && vma_m->vm_ops->open)
76539+ vma_m->vm_ops->open(vma_m);
76540+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
76541+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
76542+ vma_m->vm_mirror = vma;
76543+ vma->vm_mirror = vma_m;
76544+ return 0;
76545+}
76546+#endif
76547+
76548 /*
76549 * Return true if the calling process may expand its vm space by the passed
76550 * number of pages
76551@@ -2461,6 +2955,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
76552
76553 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
76554
76555+#ifdef CONFIG_PAX_RANDMMAP
76556+ if (mm->pax_flags & MF_PAX_RANDMMAP)
76557+ cur -= mm->brk_gap;
76558+#endif
76559+
76560+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
76561 if (cur + npages > lim)
76562 return 0;
76563 return 1;
76564@@ -2531,6 +3031,22 @@ int install_special_mapping(struct mm_struct *mm,
76565 vma->vm_start = addr;
76566 vma->vm_end = addr + len;
76567
76568+#ifdef CONFIG_PAX_MPROTECT
76569+ if (mm->pax_flags & MF_PAX_MPROTECT) {
76570+#ifndef CONFIG_PAX_MPROTECT_COMPAT
76571+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
76572+ return -EPERM;
76573+ if (!(vm_flags & VM_EXEC))
76574+ vm_flags &= ~VM_MAYEXEC;
76575+#else
76576+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
76577+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
76578+#endif
76579+ else
76580+ vm_flags &= ~VM_MAYWRITE;
76581+ }
76582+#endif
76583+
76584 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
76585 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
76586
76587diff --git a/mm/mprotect.c b/mm/mprotect.c
76588index a409926..8b32e6d 100644
76589--- a/mm/mprotect.c
76590+++ b/mm/mprotect.c
76591@@ -23,10 +23,17 @@
76592 #include <linux/mmu_notifier.h>
76593 #include <linux/migrate.h>
76594 #include <linux/perf_event.h>
76595+
76596+#ifdef CONFIG_PAX_MPROTECT
76597+#include <linux/elf.h>
76598+#include <linux/binfmts.h>
76599+#endif
76600+
76601 #include <asm/uaccess.h>
76602 #include <asm/pgtable.h>
76603 #include <asm/cacheflush.h>
76604 #include <asm/tlbflush.h>
76605+#include <asm/mmu_context.h>
76606
76607 #ifndef pgprot_modify
76608 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
76609@@ -141,6 +148,48 @@ static void change_protection(struct vm_area_struct *vma,
76610 flush_tlb_range(vma, start, end);
76611 }
76612
76613+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
76614+/* called while holding the mmap semaphor for writing except stack expansion */
76615+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
76616+{
76617+ unsigned long oldlimit, newlimit = 0UL;
76618+
76619+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
76620+ return;
76621+
76622+ spin_lock(&mm->page_table_lock);
76623+ oldlimit = mm->context.user_cs_limit;
76624+ if ((prot & VM_EXEC) && oldlimit < end)
76625+ /* USER_CS limit moved up */
76626+ newlimit = end;
76627+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
76628+ /* USER_CS limit moved down */
76629+ newlimit = start;
76630+
76631+ if (newlimit) {
76632+ mm->context.user_cs_limit = newlimit;
76633+
76634+#ifdef CONFIG_SMP
76635+ wmb();
76636+ cpus_clear(mm->context.cpu_user_cs_mask);
76637+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
76638+#endif
76639+
76640+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
76641+ }
76642+ spin_unlock(&mm->page_table_lock);
76643+ if (newlimit == end) {
76644+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
76645+
76646+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
76647+ if (is_vm_hugetlb_page(vma))
76648+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
76649+ else
76650+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
76651+ }
76652+}
76653+#endif
76654+
76655 int
76656 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
76657 unsigned long start, unsigned long end, unsigned long newflags)
76658@@ -153,11 +202,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
76659 int error;
76660 int dirty_accountable = 0;
76661
76662+#ifdef CONFIG_PAX_SEGMEXEC
76663+ struct vm_area_struct *vma_m = NULL;
76664+ unsigned long start_m, end_m;
76665+
76666+ start_m = start + SEGMEXEC_TASK_SIZE;
76667+ end_m = end + SEGMEXEC_TASK_SIZE;
76668+#endif
76669+
76670 if (newflags == oldflags) {
76671 *pprev = vma;
76672 return 0;
76673 }
76674
76675+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
76676+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
76677+
76678+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
76679+ return -ENOMEM;
76680+
76681+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
76682+ return -ENOMEM;
76683+ }
76684+
76685 /*
76686 * If we make a private mapping writable we increase our commit;
76687 * but (without finer accounting) cannot reduce our commit if we
76688@@ -174,6 +241,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
76689 }
76690 }
76691
76692+#ifdef CONFIG_PAX_SEGMEXEC
76693+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
76694+ if (start != vma->vm_start) {
76695+ error = split_vma(mm, vma, start, 1);
76696+ if (error)
76697+ goto fail;
76698+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
76699+ *pprev = (*pprev)->vm_next;
76700+ }
76701+
76702+ if (end != vma->vm_end) {
76703+ error = split_vma(mm, vma, end, 0);
76704+ if (error)
76705+ goto fail;
76706+ }
76707+
76708+ if (pax_find_mirror_vma(vma)) {
76709+ error = __do_munmap(mm, start_m, end_m - start_m);
76710+ if (error)
76711+ goto fail;
76712+ } else {
76713+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
76714+ if (!vma_m) {
76715+ error = -ENOMEM;
76716+ goto fail;
76717+ }
76718+ vma->vm_flags = newflags;
76719+ error = pax_mirror_vma(vma_m, vma);
76720+ if (error) {
76721+ vma->vm_flags = oldflags;
76722+ goto fail;
76723+ }
76724+ }
76725+ }
76726+#endif
76727+
76728 /*
76729 * First try to merge with previous and/or next vma.
76730 */
76731@@ -204,9 +307,21 @@ success:
76732 * vm_flags and vm_page_prot are protected by the mmap_sem
76733 * held in write mode.
76734 */
76735+
76736+#ifdef CONFIG_PAX_SEGMEXEC
76737+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
76738+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
76739+#endif
76740+
76741 vma->vm_flags = newflags;
76742+
76743+#ifdef CONFIG_PAX_MPROTECT
76744+ if (mm->binfmt && mm->binfmt->handle_mprotect)
76745+ mm->binfmt->handle_mprotect(vma, newflags);
76746+#endif
76747+
76748 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
76749- vm_get_page_prot(newflags));
76750+ vm_get_page_prot(vma->vm_flags));
76751
76752 if (vma_wants_writenotify(vma)) {
76753 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
76754@@ -248,6 +363,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
76755 end = start + len;
76756 if (end <= start)
76757 return -ENOMEM;
76758+
76759+#ifdef CONFIG_PAX_SEGMEXEC
76760+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
76761+ if (end > SEGMEXEC_TASK_SIZE)
76762+ return -EINVAL;
76763+ } else
76764+#endif
76765+
76766+ if (end > TASK_SIZE)
76767+ return -EINVAL;
76768+
76769 if (!arch_validate_prot(prot))
76770 return -EINVAL;
76771
76772@@ -255,7 +381,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
76773 /*
76774 * Does the application expect PROT_READ to imply PROT_EXEC:
76775 */
76776- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
76777+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
76778 prot |= PROT_EXEC;
76779
76780 vm_flags = calc_vm_prot_bits(prot);
76781@@ -288,6 +414,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
76782 if (start > vma->vm_start)
76783 prev = vma;
76784
76785+#ifdef CONFIG_PAX_MPROTECT
76786+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
76787+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
76788+#endif
76789+
76790 for (nstart = start ; ; ) {
76791 unsigned long newflags;
76792
76793@@ -297,6 +428,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
76794
76795 /* newflags >> 4 shift VM_MAY% in place of VM_% */
76796 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
76797+ if (prot & (PROT_WRITE | PROT_EXEC))
76798+ gr_log_rwxmprotect(vma->vm_file);
76799+
76800+ error = -EACCES;
76801+ goto out;
76802+ }
76803+
76804+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
76805 error = -EACCES;
76806 goto out;
76807 }
76808@@ -311,6 +450,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
76809 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
76810 if (error)
76811 goto out;
76812+
76813+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
76814+
76815 nstart = tmp;
76816
76817 if (nstart < prev->vm_end)
76818diff --git a/mm/mremap.c b/mm/mremap.c
76819index 1b61c2d..1cc0e3c 100644
76820--- a/mm/mremap.c
76821+++ b/mm/mremap.c
76822@@ -125,6 +125,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
76823 continue;
76824 pte = ptep_get_and_clear(mm, old_addr, old_pte);
76825 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
76826+
76827+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
76828+ if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
76829+ pte = pte_exprotect(pte);
76830+#endif
76831+
76832 set_pte_at(mm, new_addr, new_pte, pte);
76833 }
76834
76835@@ -319,6 +325,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
76836 if (is_vm_hugetlb_page(vma))
76837 goto Einval;
76838
76839+#ifdef CONFIG_PAX_SEGMEXEC
76840+ if (pax_find_mirror_vma(vma))
76841+ goto Einval;
76842+#endif
76843+
76844 /* We can't remap across vm area boundaries */
76845 if (old_len > vma->vm_end - addr)
76846 goto Efault;
76847@@ -375,20 +386,25 @@ static unsigned long mremap_to(unsigned long addr,
76848 unsigned long ret = -EINVAL;
76849 unsigned long charged = 0;
76850 unsigned long map_flags;
76851+ unsigned long pax_task_size = TASK_SIZE;
76852
76853 if (new_addr & ~PAGE_MASK)
76854 goto out;
76855
76856- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
76857+#ifdef CONFIG_PAX_SEGMEXEC
76858+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
76859+ pax_task_size = SEGMEXEC_TASK_SIZE;
76860+#endif
76861+
76862+ pax_task_size -= PAGE_SIZE;
76863+
76864+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
76865 goto out;
76866
76867 /* Check if the location we're moving into overlaps the
76868 * old location at all, and fail if it does.
76869 */
76870- if ((new_addr <= addr) && (new_addr+new_len) > addr)
76871- goto out;
76872-
76873- if ((addr <= new_addr) && (addr+old_len) > new_addr)
76874+ if (addr + old_len > new_addr && new_addr + new_len > addr)
76875 goto out;
76876
76877 ret = do_munmap(mm, new_addr, new_len);
76878@@ -456,6 +472,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
76879 struct vm_area_struct *vma;
76880 unsigned long ret = -EINVAL;
76881 unsigned long charged = 0;
76882+ unsigned long pax_task_size = TASK_SIZE;
76883
76884 down_write(&current->mm->mmap_sem);
76885
76886@@ -476,6 +493,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
76887 if (!new_len)
76888 goto out;
76889
76890+#ifdef CONFIG_PAX_SEGMEXEC
76891+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
76892+ pax_task_size = SEGMEXEC_TASK_SIZE;
76893+#endif
76894+
76895+ pax_task_size -= PAGE_SIZE;
76896+
76897+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
76898+ old_len > pax_task_size || addr > pax_task_size-old_len)
76899+ goto out;
76900+
76901 if (flags & MREMAP_FIXED) {
76902 if (flags & MREMAP_MAYMOVE)
76903 ret = mremap_to(addr, old_len, new_addr, new_len);
76904@@ -524,6 +552,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
76905 addr + new_len);
76906 }
76907 ret = addr;
76908+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
76909 goto out;
76910 }
76911 }
76912@@ -547,7 +576,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
76913 goto out;
76914 }
76915
76916+ map_flags = vma->vm_flags;
76917 ret = move_vma(vma, addr, old_len, new_len, new_addr);
76918+ if (!(ret & ~PAGE_MASK)) {
76919+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
76920+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
76921+ }
76922 }
76923 out:
76924 if (ret & ~PAGE_MASK)
76925diff --git a/mm/nommu.c b/mm/nommu.c
76926index 45131b4..c521665 100644
76927--- a/mm/nommu.c
76928+++ b/mm/nommu.c
76929@@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
76930 int sysctl_overcommit_ratio = 50; /* default is 50% */
76931 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
76932 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
76933-int heap_stack_gap = 0;
76934
76935 atomic_long_t mmap_pages_allocated;
76936
76937@@ -824,15 +823,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
76938 EXPORT_SYMBOL(find_vma);
76939
76940 /*
76941- * find a VMA
76942- * - we don't extend stack VMAs under NOMMU conditions
76943- */
76944-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
76945-{
76946- return find_vma(mm, addr);
76947-}
76948-
76949-/*
76950 * expand a stack to a given address
76951 * - not supported under NOMMU conditions
76952 */
76953@@ -1540,6 +1530,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
76954
76955 /* most fields are the same, copy all, and then fixup */
76956 *new = *vma;
76957+ INIT_LIST_HEAD(&new->anon_vma_chain);
76958 *region = *vma->vm_region;
76959 new->vm_region = region;
76960
76961diff --git a/mm/page_alloc.c b/mm/page_alloc.c
76962index ceb4168..d7774f2 100644
76963--- a/mm/page_alloc.c
76964+++ b/mm/page_alloc.c
76965@@ -340,7 +340,7 @@ out:
76966 * This usage means that zero-order pages may not be compound.
76967 */
76968
76969-static void free_compound_page(struct page *page)
76970+void free_compound_page(struct page *page)
76971 {
76972 __free_pages_ok(page, compound_order(page));
76973 }
76974@@ -693,6 +693,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
76975 int i;
76976 int bad = 0;
76977
76978+#ifdef CONFIG_PAX_MEMORY_SANITIZE
76979+ unsigned long index = 1UL << order;
76980+#endif
76981+
76982 trace_mm_page_free(page, order);
76983 kmemcheck_free_shadow(page, order);
76984
76985@@ -708,6 +712,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
76986 debug_check_no_obj_freed(page_address(page),
76987 PAGE_SIZE << order);
76988 }
76989+
76990+#ifdef CONFIG_PAX_MEMORY_SANITIZE
76991+ for (; index; --index)
76992+ sanitize_highpage(page + index - 1);
76993+#endif
76994+
76995 arch_free_page(page, order);
76996 kernel_map_pages(page, 1 << order, 0);
76997
76998@@ -849,8 +859,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
76999 arch_alloc_page(page, order);
77000 kernel_map_pages(page, 1 << order, 1);
77001
77002+#ifndef CONFIG_PAX_MEMORY_SANITIZE
77003 if (gfp_flags & __GFP_ZERO)
77004 prep_zero_page(page, order, gfp_flags);
77005+#endif
77006
77007 if (order && (gfp_flags & __GFP_COMP))
77008 prep_compound_page(page, order);
77009@@ -3684,7 +3696,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
77010 unsigned long pfn;
77011
77012 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
77013+#ifdef CONFIG_X86_32
77014+ /* boot failures in VMware 8 on 32bit vanilla since
77015+ this change */
77016+ if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
77017+#else
77018 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
77019+#endif
77020 return 1;
77021 }
77022 return 0;
77023diff --git a/mm/percpu.c b/mm/percpu.c
77024index ddc5efb..f632d2c 100644
77025--- a/mm/percpu.c
77026+++ b/mm/percpu.c
77027@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
77028 static unsigned int pcpu_high_unit_cpu __read_mostly;
77029
77030 /* the address of the first chunk which starts with the kernel static area */
77031-void *pcpu_base_addr __read_mostly;
77032+void *pcpu_base_addr __read_only;
77033 EXPORT_SYMBOL_GPL(pcpu_base_addr);
77034
77035 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
77036diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
77037index 926b466..b23df53 100644
77038--- a/mm/process_vm_access.c
77039+++ b/mm/process_vm_access.c
77040@@ -13,6 +13,7 @@
77041 #include <linux/uio.h>
77042 #include <linux/sched.h>
77043 #include <linux/highmem.h>
77044+#include <linux/security.h>
77045 #include <linux/ptrace.h>
77046 #include <linux/slab.h>
77047 #include <linux/syscalls.h>
77048@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
77049 size_t iov_l_curr_offset = 0;
77050 ssize_t iov_len;
77051
77052+ return -ENOSYS; // PaX: until properly audited
77053+
77054 /*
77055 * Work out how many pages of struct pages we're going to need
77056 * when eventually calling get_user_pages
77057 */
77058 for (i = 0; i < riovcnt; i++) {
77059 iov_len = rvec[i].iov_len;
77060- if (iov_len > 0) {
77061- nr_pages_iov = ((unsigned long)rvec[i].iov_base
77062- + iov_len)
77063- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
77064- / PAGE_SIZE + 1;
77065- nr_pages = max(nr_pages, nr_pages_iov);
77066- }
77067+ if (iov_len <= 0)
77068+ continue;
77069+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
77070+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
77071+ nr_pages = max(nr_pages, nr_pages_iov);
77072 }
77073
77074 if (nr_pages == 0)
77075@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
77076 goto free_proc_pages;
77077 }
77078
77079+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
77080+ rc = -EPERM;
77081+ goto put_task_struct;
77082+ }
77083+
77084 mm = mm_access(task, PTRACE_MODE_ATTACH);
77085 if (!mm || IS_ERR(mm)) {
77086 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
77087diff --git a/mm/rmap.c b/mm/rmap.c
77088index 2ee1ef0..2e175ba 100644
77089--- a/mm/rmap.c
77090+++ b/mm/rmap.c
77091@@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
77092 struct anon_vma *anon_vma = vma->anon_vma;
77093 struct anon_vma_chain *avc;
77094
77095+#ifdef CONFIG_PAX_SEGMEXEC
77096+ struct anon_vma_chain *avc_m = NULL;
77097+#endif
77098+
77099 might_sleep();
77100 if (unlikely(!anon_vma)) {
77101 struct mm_struct *mm = vma->vm_mm;
77102@@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
77103 if (!avc)
77104 goto out_enomem;
77105
77106+#ifdef CONFIG_PAX_SEGMEXEC
77107+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
77108+ if (!avc_m)
77109+ goto out_enomem_free_avc;
77110+#endif
77111+
77112 anon_vma = find_mergeable_anon_vma(vma);
77113 allocated = NULL;
77114 if (!anon_vma) {
77115@@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
77116 /* page_table_lock to protect against threads */
77117 spin_lock(&mm->page_table_lock);
77118 if (likely(!vma->anon_vma)) {
77119+
77120+#ifdef CONFIG_PAX_SEGMEXEC
77121+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
77122+
77123+ if (vma_m) {
77124+ BUG_ON(vma_m->anon_vma);
77125+ vma_m->anon_vma = anon_vma;
77126+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
77127+ avc_m = NULL;
77128+ }
77129+#endif
77130+
77131 vma->anon_vma = anon_vma;
77132 anon_vma_chain_link(vma, avc, anon_vma);
77133 allocated = NULL;
77134@@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
77135
77136 if (unlikely(allocated))
77137 put_anon_vma(allocated);
77138+
77139+#ifdef CONFIG_PAX_SEGMEXEC
77140+ if (unlikely(avc_m))
77141+ anon_vma_chain_free(avc_m);
77142+#endif
77143+
77144 if (unlikely(avc))
77145 anon_vma_chain_free(avc);
77146 }
77147 return 0;
77148
77149 out_enomem_free_avc:
77150+
77151+#ifdef CONFIG_PAX_SEGMEXEC
77152+ if (avc_m)
77153+ anon_vma_chain_free(avc_m);
77154+#endif
77155+
77156 anon_vma_chain_free(avc);
77157 out_enomem:
77158 return -ENOMEM;
77159@@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
77160 * Attach the anon_vmas from src to dst.
77161 * Returns 0 on success, -ENOMEM on failure.
77162 */
77163-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
77164+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
77165 {
77166 struct anon_vma_chain *avc, *pavc;
77167 struct anon_vma *root = NULL;
77168@@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
77169 * the corresponding VMA in the parent process is attached to.
77170 * Returns 0 on success, non-zero on failure.
77171 */
77172-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
77173+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
77174 {
77175 struct anon_vma_chain *avc;
77176 struct anon_vma *anon_vma;
77177diff --git a/mm/shmem.c b/mm/shmem.c
77178index 50c5b8f..0bc87f7 100644
77179--- a/mm/shmem.c
77180+++ b/mm/shmem.c
77181@@ -31,7 +31,7 @@
77182 #include <linux/export.h>
77183 #include <linux/swap.h>
77184
77185-static struct vfsmount *shm_mnt;
77186+struct vfsmount *shm_mnt;
77187
77188 #ifdef CONFIG_SHMEM
77189 /*
77190@@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
77191 #define BOGO_DIRENT_SIZE 20
77192
77193 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
77194-#define SHORT_SYMLINK_LEN 128
77195+#define SHORT_SYMLINK_LEN 64
77196
77197 /*
77198 * shmem_fallocate and shmem_writepage communicate via inode->i_private
77199@@ -2112,6 +2112,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
77200 static int shmem_xattr_validate(const char *name)
77201 {
77202 struct { const char *prefix; size_t len; } arr[] = {
77203+
77204+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
77205+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
77206+#endif
77207+
77208 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
77209 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
77210 };
77211@@ -2167,6 +2172,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
77212 if (err)
77213 return err;
77214
77215+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
77216+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
77217+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
77218+ return -EOPNOTSUPP;
77219+ if (size > 8)
77220+ return -EINVAL;
77221+ }
77222+#endif
77223+
77224 return simple_xattr_set(&info->xattrs, name, value, size, flags);
77225 }
77226
77227@@ -2466,8 +2480,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
77228 int err = -ENOMEM;
77229
77230 /* Round up to L1_CACHE_BYTES to resist false sharing */
77231- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
77232- L1_CACHE_BYTES), GFP_KERNEL);
77233+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
77234 if (!sbinfo)
77235 return -ENOMEM;
77236
77237diff --git a/mm/slab.c b/mm/slab.c
77238index 33d3363..3851c61 100644
77239--- a/mm/slab.c
77240+++ b/mm/slab.c
77241@@ -164,7 +164,7 @@ static bool pfmemalloc_active __read_mostly;
77242
77243 /* Legal flag mask for kmem_cache_create(). */
77244 #if DEBUG
77245-# define CREATE_MASK (SLAB_RED_ZONE | \
77246+# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
77247 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
77248 SLAB_CACHE_DMA | \
77249 SLAB_STORE_USER | \
77250@@ -172,7 +172,7 @@ static bool pfmemalloc_active __read_mostly;
77251 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
77252 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
77253 #else
77254-# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
77255+# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
77256 SLAB_CACHE_DMA | \
77257 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
77258 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
77259@@ -322,7 +322,7 @@ struct kmem_list3 {
77260 * Need this for bootstrapping a per node allocator.
77261 */
77262 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
77263-static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
77264+static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
77265 #define CACHE_CACHE 0
77266 #define SIZE_AC MAX_NUMNODES
77267 #define SIZE_L3 (2 * MAX_NUMNODES)
77268@@ -423,10 +423,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
77269 if ((x)->max_freeable < i) \
77270 (x)->max_freeable = i; \
77271 } while (0)
77272-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
77273-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
77274-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
77275-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
77276+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
77277+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
77278+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
77279+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
77280 #else
77281 #define STATS_INC_ACTIVE(x) do { } while (0)
77282 #define STATS_DEC_ACTIVE(x) do { } while (0)
77283@@ -534,7 +534,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
77284 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
77285 */
77286 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
77287- const struct slab *slab, void *obj)
77288+ const struct slab *slab, const void *obj)
77289 {
77290 u32 offset = (obj - slab->s_mem);
77291 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
77292@@ -555,12 +555,13 @@ EXPORT_SYMBOL(malloc_sizes);
77293 struct cache_names {
77294 char *name;
77295 char *name_dma;
77296+ char *name_usercopy;
77297 };
77298
77299 static struct cache_names __initdata cache_names[] = {
77300-#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
77301+#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
77302 #include <linux/kmalloc_sizes.h>
77303- {NULL,}
77304+ {NULL}
77305 #undef CACHE
77306 };
77307
77308@@ -721,6 +722,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
77309 if (unlikely(gfpflags & GFP_DMA))
77310 return csizep->cs_dmacachep;
77311 #endif
77312+
77313+#ifdef CONFIG_PAX_USERCOPY_SLABS
77314+ if (unlikely(gfpflags & GFP_USERCOPY))
77315+ return csizep->cs_usercopycachep;
77316+#endif
77317+
77318 return csizep->cs_cachep;
77319 }
77320
77321@@ -1676,7 +1683,7 @@ void __init kmem_cache_init(void)
77322 sizes[INDEX_AC].cs_cachep->size = sizes[INDEX_AC].cs_size;
77323 sizes[INDEX_AC].cs_cachep->object_size = sizes[INDEX_AC].cs_size;
77324 sizes[INDEX_AC].cs_cachep->align = ARCH_KMALLOC_MINALIGN;
77325- __kmem_cache_create(sizes[INDEX_AC].cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC);
77326+ __kmem_cache_create(sizes[INDEX_AC].cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY);
77327 list_add(&sizes[INDEX_AC].cs_cachep->list, &slab_caches);
77328
77329 if (INDEX_AC != INDEX_L3) {
77330@@ -1685,7 +1692,7 @@ void __init kmem_cache_init(void)
77331 sizes[INDEX_L3].cs_cachep->size = sizes[INDEX_L3].cs_size;
77332 sizes[INDEX_L3].cs_cachep->object_size = sizes[INDEX_L3].cs_size;
77333 sizes[INDEX_L3].cs_cachep->align = ARCH_KMALLOC_MINALIGN;
77334- __kmem_cache_create(sizes[INDEX_L3].cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC);
77335+ __kmem_cache_create(sizes[INDEX_L3].cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY);
77336 list_add(&sizes[INDEX_L3].cs_cachep->list, &slab_caches);
77337 }
77338
77339@@ -1705,7 +1712,7 @@ void __init kmem_cache_init(void)
77340 sizes->cs_cachep->size = sizes->cs_size;
77341 sizes->cs_cachep->object_size = sizes->cs_size;
77342 sizes->cs_cachep->align = ARCH_KMALLOC_MINALIGN;
77343- __kmem_cache_create(sizes->cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC);
77344+ __kmem_cache_create(sizes->cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY);
77345 list_add(&sizes->cs_cachep->list, &slab_caches);
77346 }
77347 #ifdef CONFIG_ZONE_DMA
77348@@ -1718,6 +1725,17 @@ void __init kmem_cache_init(void)
77349 ARCH_KMALLOC_FLAGS|SLAB_CACHE_DMA| SLAB_PANIC);
77350 list_add(&sizes->cs_dmacachep->list, &slab_caches);
77351 #endif
77352+
77353+#ifdef CONFIG_PAX_USERCOPY_SLABS
77354+ sizes->cs_usercopycachep = kmem_cache_zalloc(kmem_cache, GFP_NOWAIT);
77355+ sizes->cs_usercopycachep->name = names->name_usercopy;
77356+ sizes->cs_usercopycachep->size = sizes->cs_size;
77357+ sizes->cs_usercopycachep->object_size = sizes->cs_size;
77358+ sizes->cs_usercopycachep->align = ARCH_KMALLOC_MINALIGN;
77359+ __kmem_cache_create(sizes->cs_usercopycachep, ARCH_KMALLOC_FLAGS| SLAB_PANIC|SLAB_USERCOPY);
77360+ list_add(&sizes->cs_usercopycachep->list, &slab_caches);
77361+#endif
77362+
77363 sizes++;
77364 names++;
77365 }
77366@@ -4405,10 +4423,10 @@ static int s_show(struct seq_file *m, void *p)
77367 }
77368 /* cpu stats */
77369 {
77370- unsigned long allochit = atomic_read(&cachep->allochit);
77371- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
77372- unsigned long freehit = atomic_read(&cachep->freehit);
77373- unsigned long freemiss = atomic_read(&cachep->freemiss);
77374+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
77375+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
77376+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
77377+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
77378
77379 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
77380 allochit, allocmiss, freehit, freemiss);
77381@@ -4667,13 +4685,71 @@ static int __init slab_proc_init(void)
77382 {
77383 proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
77384 #ifdef CONFIG_DEBUG_SLAB_LEAK
77385- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
77386+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
77387 #endif
77388 return 0;
77389 }
77390 module_init(slab_proc_init);
77391 #endif
77392
77393+bool is_usercopy_object(const void *ptr)
77394+{
77395+ struct page *page;
77396+ struct kmem_cache *cachep;
77397+
77398+ if (ZERO_OR_NULL_PTR(ptr))
77399+ return false;
77400+
77401+ if (!slab_is_available())
77402+ return false;
77403+
77404+ if (!virt_addr_valid(ptr))
77405+ return false;
77406+
77407+ page = virt_to_head_page(ptr);
77408+
77409+ if (!PageSlab(page))
77410+ return false;
77411+
77412+ cachep = page->slab_cache;
77413+ return cachep->flags & SLAB_USERCOPY;
77414+}
77415+
77416+#ifdef CONFIG_PAX_USERCOPY
77417+const char *check_heap_object(const void *ptr, unsigned long n)
77418+{
77419+ struct page *page;
77420+ struct kmem_cache *cachep;
77421+ struct slab *slabp;
77422+ unsigned int objnr;
77423+ unsigned long offset;
77424+
77425+ if (ZERO_OR_NULL_PTR(ptr))
77426+ return "<null>";
77427+
77428+ if (!virt_addr_valid(ptr))
77429+ return NULL;
77430+
77431+ page = virt_to_head_page(ptr);
77432+
77433+ if (!PageSlab(page))
77434+ return NULL;
77435+
77436+ cachep = page->slab_cache;
77437+ if (!(cachep->flags & SLAB_USERCOPY))
77438+ return cachep->name;
77439+
77440+ slabp = page->slab_page;
77441+ objnr = obj_to_index(cachep, slabp, ptr);
77442+ BUG_ON(objnr >= cachep->num);
77443+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
77444+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
77445+ return NULL;
77446+
77447+ return cachep->name;
77448+}
77449+#endif
77450+
77451 /**
77452 * ksize - get the actual amount of memory allocated for a given object
77453 * @objp: Pointer to the object
77454diff --git a/mm/slab_common.c b/mm/slab_common.c
77455index 069a24e6..226a310 100644
77456--- a/mm/slab_common.c
77457+++ b/mm/slab_common.c
77458@@ -127,7 +127,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size, size_t align
77459 err = __kmem_cache_create(s, flags);
77460 if (!err) {
77461
77462- s->refcount = 1;
77463+ atomic_set(&s->refcount, 1);
77464 list_add(&s->list, &slab_caches);
77465
77466 } else {
77467@@ -163,8 +163,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
77468 {
77469 get_online_cpus();
77470 mutex_lock(&slab_mutex);
77471- s->refcount--;
77472- if (!s->refcount) {
77473+ if (atomic_dec_and_test(&s->refcount)) {
77474 list_del(&s->list);
77475
77476 if (!__kmem_cache_shutdown(s)) {
77477diff --git a/mm/slob.c b/mm/slob.c
77478index 1e921c5..1ce12c2 100644
77479--- a/mm/slob.c
77480+++ b/mm/slob.c
77481@@ -159,7 +159,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
77482 /*
77483 * Return the size of a slob block.
77484 */
77485-static slobidx_t slob_units(slob_t *s)
77486+static slobidx_t slob_units(const slob_t *s)
77487 {
77488 if (s->units > 0)
77489 return s->units;
77490@@ -169,7 +169,7 @@ static slobidx_t slob_units(slob_t *s)
77491 /*
77492 * Return the next free slob block pointer after this one.
77493 */
77494-static slob_t *slob_next(slob_t *s)
77495+static slob_t *slob_next(const slob_t *s)
77496 {
77497 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
77498 slobidx_t next;
77499@@ -184,14 +184,14 @@ static slob_t *slob_next(slob_t *s)
77500 /*
77501 * Returns true if s is the last free block in its page.
77502 */
77503-static int slob_last(slob_t *s)
77504+static int slob_last(const slob_t *s)
77505 {
77506 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
77507 }
77508
77509-static void *slob_new_pages(gfp_t gfp, int order, int node)
77510+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
77511 {
77512- void *page;
77513+ struct page *page;
77514
77515 #ifdef CONFIG_NUMA
77516 if (node != NUMA_NO_NODE)
77517@@ -203,14 +203,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
77518 if (!page)
77519 return NULL;
77520
77521- return page_address(page);
77522+ __SetPageSlab(page);
77523+ return page;
77524 }
77525
77526-static void slob_free_pages(void *b, int order)
77527+static void slob_free_pages(struct page *sp, int order)
77528 {
77529 if (current->reclaim_state)
77530 current->reclaim_state->reclaimed_slab += 1 << order;
77531- free_pages((unsigned long)b, order);
77532+ __ClearPageSlab(sp);
77533+ reset_page_mapcount(sp);
77534+ sp->private = 0;
77535+ __free_pages(sp, order);
77536 }
77537
77538 /*
77539@@ -315,15 +319,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
77540
77541 /* Not enough space: must allocate a new page */
77542 if (!b) {
77543- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
77544- if (!b)
77545+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
77546+ if (!sp)
77547 return NULL;
77548- sp = virt_to_page(b);
77549- __SetPageSlab(sp);
77550+ b = page_address(sp);
77551
77552 spin_lock_irqsave(&slob_lock, flags);
77553 sp->units = SLOB_UNITS(PAGE_SIZE);
77554 sp->freelist = b;
77555+ sp->private = 0;
77556 INIT_LIST_HEAD(&sp->list);
77557 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
77558 set_slob_page_free(sp, slob_list);
77559@@ -361,9 +365,7 @@ static void slob_free(void *block, int size)
77560 if (slob_page_free(sp))
77561 clear_slob_page_free(sp);
77562 spin_unlock_irqrestore(&slob_lock, flags);
77563- __ClearPageSlab(sp);
77564- reset_page_mapcount(sp);
77565- slob_free_pages(b, 0);
77566+ slob_free_pages(sp, 0);
77567 return;
77568 }
77569
77570@@ -426,11 +428,10 @@ out:
77571 */
77572
77573 static __always_inline void *
77574-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
77575+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
77576 {
77577- unsigned int *m;
77578- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
77579- void *ret;
77580+ slob_t *m;
77581+ void *ret = NULL;
77582
77583 gfp &= gfp_allowed_mask;
77584
77585@@ -444,20 +445,23 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
77586
77587 if (!m)
77588 return NULL;
77589- *m = size;
77590+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
77591+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
77592+ m[0].units = size;
77593+ m[1].units = align;
77594 ret = (void *)m + align;
77595
77596 trace_kmalloc_node(caller, ret,
77597 size, size + align, gfp, node);
77598 } else {
77599 unsigned int order = get_order(size);
77600+ struct page *page;
77601
77602 if (likely(order))
77603 gfp |= __GFP_COMP;
77604- ret = slob_new_pages(gfp, order, node);
77605- if (ret) {
77606- struct page *page;
77607- page = virt_to_page(ret);
77608+ page = slob_new_pages(gfp, order, node);
77609+ if (page) {
77610+ ret = page_address(page);
77611 page->private = size;
77612 }
77613
77614@@ -465,7 +469,17 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
77615 size, PAGE_SIZE << order, gfp, node);
77616 }
77617
77618- kmemleak_alloc(ret, size, 1, gfp);
77619+ return ret;
77620+}
77621+
77622+static __always_inline void *
77623+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
77624+{
77625+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
77626+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
77627+
77628+ if (!ZERO_OR_NULL_PTR(ret))
77629+ kmemleak_alloc(ret, size, 1, gfp);
77630 return ret;
77631 }
77632
77633@@ -501,15 +515,91 @@ void kfree(const void *block)
77634 kmemleak_free(block);
77635
77636 sp = virt_to_page(block);
77637- if (PageSlab(sp)) {
77638+ VM_BUG_ON(!PageSlab(sp));
77639+ if (!sp->private) {
77640 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
77641- unsigned int *m = (unsigned int *)(block - align);
77642- slob_free(m, *m + align);
77643- } else
77644+ slob_t *m = (slob_t *)(block - align);
77645+ slob_free(m, m[0].units + align);
77646+ } else {
77647+ __ClearPageSlab(sp);
77648+ reset_page_mapcount(sp);
77649+ sp->private = 0;
77650 put_page(sp);
77651+ }
77652 }
77653 EXPORT_SYMBOL(kfree);
77654
77655+bool is_usercopy_object(const void *ptr)
77656+{
77657+ if (!slab_is_available())
77658+ return false;
77659+
77660+ // PAX: TODO
77661+
77662+ return false;
77663+}
77664+
77665+#ifdef CONFIG_PAX_USERCOPY
77666+const char *check_heap_object(const void *ptr, unsigned long n)
77667+{
77668+ struct page *page;
77669+ const slob_t *free;
77670+ const void *base;
77671+ unsigned long flags;
77672+
77673+ if (ZERO_OR_NULL_PTR(ptr))
77674+ return "<null>";
77675+
77676+ if (!virt_addr_valid(ptr))
77677+ return NULL;
77678+
77679+ page = virt_to_head_page(ptr);
77680+ if (!PageSlab(page))
77681+ return NULL;
77682+
77683+ if (page->private) {
77684+ base = page;
77685+ if (base <= ptr && n <= page->private - (ptr - base))
77686+ return NULL;
77687+ return "<slob>";
77688+ }
77689+
77690+ /* some tricky double walking to find the chunk */
77691+ spin_lock_irqsave(&slob_lock, flags);
77692+ base = (void *)((unsigned long)ptr & PAGE_MASK);
77693+ free = page->freelist;
77694+
77695+ while (!slob_last(free) && (void *)free <= ptr) {
77696+ base = free + slob_units(free);
77697+ free = slob_next(free);
77698+ }
77699+
77700+ while (base < (void *)free) {
77701+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
77702+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
77703+ int offset;
77704+
77705+ if (ptr < base + align)
77706+ break;
77707+
77708+ offset = ptr - base - align;
77709+ if (offset >= m) {
77710+ base += size;
77711+ continue;
77712+ }
77713+
77714+ if (n > m - offset)
77715+ break;
77716+
77717+ spin_unlock_irqrestore(&slob_lock, flags);
77718+ return NULL;
77719+ }
77720+
77721+ spin_unlock_irqrestore(&slob_lock, flags);
77722+ return "<slob>";
77723+}
77724+#endif
77725+
77726 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
77727 size_t ksize(const void *block)
77728 {
77729@@ -520,10 +610,11 @@ size_t ksize(const void *block)
77730 return 0;
77731
77732 sp = virt_to_page(block);
77733- if (PageSlab(sp)) {
77734+ VM_BUG_ON(!PageSlab(sp));
77735+ if (!sp->private) {
77736 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
77737- unsigned int *m = (unsigned int *)(block - align);
77738- return SLOB_UNITS(*m) * SLOB_UNIT;
77739+ slob_t *m = (slob_t *)(block - align);
77740+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
77741 } else
77742 return sp->private;
77743 }
77744@@ -550,23 +641,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
77745
77746 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
77747 {
77748- void *b;
77749+ void *b = NULL;
77750
77751 flags &= gfp_allowed_mask;
77752
77753 lockdep_trace_alloc(flags);
77754
77755+#ifdef CONFIG_PAX_USERCOPY_SLABS
77756+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
77757+#else
77758 if (c->size < PAGE_SIZE) {
77759 b = slob_alloc(c->size, flags, c->align, node);
77760 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
77761 SLOB_UNITS(c->size) * SLOB_UNIT,
77762 flags, node);
77763 } else {
77764- b = slob_new_pages(flags, get_order(c->size), node);
77765+ struct page *sp;
77766+
77767+ sp = slob_new_pages(flags, get_order(c->size), node);
77768+ if (sp) {
77769+ b = page_address(sp);
77770+ sp->private = c->size;
77771+ }
77772 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
77773 PAGE_SIZE << get_order(c->size),
77774 flags, node);
77775 }
77776+#endif
77777
77778 if (c->ctor)
77779 c->ctor(b);
77780@@ -578,10 +679,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
77781
77782 static void __kmem_cache_free(void *b, int size)
77783 {
77784- if (size < PAGE_SIZE)
77785+ struct page *sp;
77786+
77787+ sp = virt_to_page(b);
77788+ BUG_ON(!PageSlab(sp));
77789+ if (!sp->private)
77790 slob_free(b, size);
77791 else
77792- slob_free_pages(b, get_order(size));
77793+ slob_free_pages(sp, get_order(size));
77794 }
77795
77796 static void kmem_rcu_free(struct rcu_head *head)
77797@@ -594,17 +699,31 @@ static void kmem_rcu_free(struct rcu_head *head)
77798
77799 void kmem_cache_free(struct kmem_cache *c, void *b)
77800 {
77801+ int size = c->size;
77802+
77803+#ifdef CONFIG_PAX_USERCOPY_SLABS
77804+ if (size + c->align < PAGE_SIZE) {
77805+ size += c->align;
77806+ b -= c->align;
77807+ }
77808+#endif
77809+
77810 kmemleak_free_recursive(b, c->flags);
77811 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
77812 struct slob_rcu *slob_rcu;
77813- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
77814- slob_rcu->size = c->size;
77815+ slob_rcu = b + (size - sizeof(struct slob_rcu));
77816+ slob_rcu->size = size;
77817 call_rcu(&slob_rcu->head, kmem_rcu_free);
77818 } else {
77819- __kmem_cache_free(b, c->size);
77820+ __kmem_cache_free(b, size);
77821 }
77822
77823+#ifdef CONFIG_PAX_USERCOPY_SLABS
77824+ trace_kfree(_RET_IP_, b);
77825+#else
77826 trace_kmem_cache_free(_RET_IP_, b);
77827+#endif
77828+
77829 }
77830 EXPORT_SYMBOL(kmem_cache_free);
77831
77832diff --git a/mm/slub.c b/mm/slub.c
77833index 321afab..9595170 100644
77834--- a/mm/slub.c
77835+++ b/mm/slub.c
77836@@ -201,7 +201,7 @@ struct track {
77837
77838 enum track_item { TRACK_ALLOC, TRACK_FREE };
77839
77840-#ifdef CONFIG_SYSFS
77841+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
77842 static int sysfs_slab_add(struct kmem_cache *);
77843 static int sysfs_slab_alias(struct kmem_cache *, const char *);
77844 static void sysfs_slab_remove(struct kmem_cache *);
77845@@ -521,7 +521,7 @@ static void print_track(const char *s, struct track *t)
77846 if (!t->addr)
77847 return;
77848
77849- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
77850+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
77851 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
77852 #ifdef CONFIG_STACKTRACE
77853 {
77854@@ -2623,6 +2623,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
77855
77856 page = virt_to_head_page(x);
77857
77858+ BUG_ON(!PageSlab(page));
77859+
77860 if (kmem_cache_debug(s) && page->slab != s) {
77861 pr_err("kmem_cache_free: Wrong slab cache. %s but object"
77862 " is from %s\n", page->slab->name, s->name);
77863@@ -2663,7 +2665,7 @@ static int slub_min_objects;
77864 * Merge control. If this is set then no merging of slab caches will occur.
77865 * (Could be removed. This was introduced to pacify the merge skeptics.)
77866 */
77867-static int slub_nomerge;
77868+static int slub_nomerge = 1;
77869
77870 /*
77871 * Calculate the order of allocation given an slab object size.
77872@@ -3225,6 +3227,10 @@ EXPORT_SYMBOL(kmalloc_caches);
77873 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
77874 #endif
77875
77876+#ifdef CONFIG_PAX_USERCOPY_SLABS
77877+static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
77878+#endif
77879+
77880 static int __init setup_slub_min_order(char *str)
77881 {
77882 get_option(&str, &slub_min_order);
77883@@ -3279,7 +3285,7 @@ static struct kmem_cache *__init create_kmalloc_cache(const char *name,
77884 if (kmem_cache_open(s, flags))
77885 goto panic;
77886
77887- s->refcount = 1;
77888+ atomic_set(&s->refcount, 1);
77889 list_add(&s->list, &slab_caches);
77890 return s;
77891
77892@@ -3343,6 +3349,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
77893 return kmalloc_dma_caches[index];
77894
77895 #endif
77896+
77897+#ifdef CONFIG_PAX_USERCOPY_SLABS
77898+ if (flags & SLAB_USERCOPY)
77899+ return kmalloc_usercopy_caches[index];
77900+
77901+#endif
77902+
77903 return kmalloc_caches[index];
77904 }
77905
77906@@ -3411,6 +3424,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
77907 EXPORT_SYMBOL(__kmalloc_node);
77908 #endif
77909
77910+bool is_usercopy_object(const void *ptr)
77911+{
77912+ struct page *page;
77913+ struct kmem_cache *s;
77914+
77915+ if (ZERO_OR_NULL_PTR(ptr))
77916+ return false;
77917+
77918+ if (!slab_is_available())
77919+ return false;
77920+
77921+ if (!virt_addr_valid(ptr))
77922+ return false;
77923+
77924+ page = virt_to_head_page(ptr);
77925+
77926+ if (!PageSlab(page))
77927+ return false;
77928+
77929+ s = page->slab;
77930+ return s->flags & SLAB_USERCOPY;
77931+}
77932+
77933+#ifdef CONFIG_PAX_USERCOPY
77934+const char *check_heap_object(const void *ptr, unsigned long n)
77935+{
77936+ struct page *page;
77937+ struct kmem_cache *s;
77938+ unsigned long offset;
77939+
77940+ if (ZERO_OR_NULL_PTR(ptr))
77941+ return "<null>";
77942+
77943+ if (!virt_addr_valid(ptr))
77944+ return NULL;
77945+
77946+ page = virt_to_head_page(ptr);
77947+
77948+ if (!PageSlab(page))
77949+ return NULL;
77950+
77951+ s = page->slab;
77952+ if (!(s->flags & SLAB_USERCOPY))
77953+ return s->name;
77954+
77955+ offset = (ptr - page_address(page)) % s->size;
77956+ if (offset <= s->object_size && n <= s->object_size - offset)
77957+ return NULL;
77958+
77959+ return s->name;
77960+}
77961+#endif
77962+
77963 size_t ksize(const void *object)
77964 {
77965 struct page *page;
77966@@ -3685,7 +3751,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
77967 int node;
77968
77969 list_add(&s->list, &slab_caches);
77970- s->refcount = -1;
77971+ atomic_set(&s->refcount, -1);
77972
77973 for_each_node_state(node, N_NORMAL_MEMORY) {
77974 struct kmem_cache_node *n = get_node(s, node);
77975@@ -3808,17 +3874,17 @@ void __init kmem_cache_init(void)
77976
77977 /* Caches that are not of the two-to-the-power-of size */
77978 if (KMALLOC_MIN_SIZE <= 32) {
77979- kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
77980+ kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
77981 caches++;
77982 }
77983
77984 if (KMALLOC_MIN_SIZE <= 64) {
77985- kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
77986+ kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
77987 caches++;
77988 }
77989
77990 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
77991- kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
77992+ kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
77993 caches++;
77994 }
77995
77996@@ -3860,6 +3926,22 @@ void __init kmem_cache_init(void)
77997 }
77998 }
77999 #endif
78000+
78001+#ifdef CONFIG_PAX_USERCOPY_SLABS
78002+ for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
78003+ struct kmem_cache *s = kmalloc_caches[i];
78004+
78005+ if (s && s->size) {
78006+ char *name = kasprintf(GFP_NOWAIT,
78007+ "usercopy-kmalloc-%d", s->object_size);
78008+
78009+ BUG_ON(!name);
78010+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
78011+ s->object_size, SLAB_USERCOPY);
78012+ }
78013+ }
78014+#endif
78015+
78016 printk(KERN_INFO
78017 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
78018 " CPUs=%d, Nodes=%d\n",
78019@@ -3886,7 +3968,7 @@ static int slab_unmergeable(struct kmem_cache *s)
78020 /*
78021 * We may have set a slab to be unmergeable during bootstrap.
78022 */
78023- if (s->refcount < 0)
78024+ if (atomic_read(&s->refcount) < 0)
78025 return 1;
78026
78027 return 0;
78028@@ -3940,7 +4022,7 @@ struct kmem_cache *__kmem_cache_alias(const char *name, size_t size,
78029
78030 s = find_mergeable(size, align, flags, name, ctor);
78031 if (s) {
78032- s->refcount++;
78033+ atomic_inc(&s->refcount);
78034 /*
78035 * Adjust the object sizes so that we clear
78036 * the complete object on kzalloc.
78037@@ -3949,7 +4031,7 @@ struct kmem_cache *__kmem_cache_alias(const char *name, size_t size,
78038 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
78039
78040 if (sysfs_slab_alias(s, name)) {
78041- s->refcount--;
78042+ atomic_dec(&s->refcount);
78043 s = NULL;
78044 }
78045 }
78046@@ -4064,7 +4146,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
78047 }
78048 #endif
78049
78050-#ifdef CONFIG_SYSFS
78051+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
78052 static int count_inuse(struct page *page)
78053 {
78054 return page->inuse;
78055@@ -4451,12 +4533,12 @@ static void resiliency_test(void)
78056 validate_slab_cache(kmalloc_caches[9]);
78057 }
78058 #else
78059-#ifdef CONFIG_SYSFS
78060+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
78061 static void resiliency_test(void) {};
78062 #endif
78063 #endif
78064
78065-#ifdef CONFIG_SYSFS
78066+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
78067 enum slab_stat_type {
78068 SL_ALL, /* All slabs */
78069 SL_PARTIAL, /* Only partially allocated slabs */
78070@@ -4700,7 +4782,7 @@ SLAB_ATTR_RO(ctor);
78071
78072 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
78073 {
78074- return sprintf(buf, "%d\n", s->refcount - 1);
78075+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
78076 }
78077 SLAB_ATTR_RO(aliases);
78078
78079@@ -5262,6 +5344,7 @@ static char *create_unique_id(struct kmem_cache *s)
78080 return name;
78081 }
78082
78083+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
78084 static int sysfs_slab_add(struct kmem_cache *s)
78085 {
78086 int err;
78087@@ -5324,6 +5407,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
78088 kobject_del(&s->kobj);
78089 kobject_put(&s->kobj);
78090 }
78091+#endif
78092
78093 /*
78094 * Need to buffer aliases during bootup until sysfs becomes
78095@@ -5337,6 +5421,7 @@ struct saved_alias {
78096
78097 static struct saved_alias *alias_list;
78098
78099+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
78100 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
78101 {
78102 struct saved_alias *al;
78103@@ -5359,6 +5444,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
78104 alias_list = al;
78105 return 0;
78106 }
78107+#endif
78108
78109 static int __init slab_sysfs_init(void)
78110 {
78111diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
78112index 1b7e22a..3fcd4f3 100644
78113--- a/mm/sparse-vmemmap.c
78114+++ b/mm/sparse-vmemmap.c
78115@@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
78116 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
78117 if (!p)
78118 return NULL;
78119- pud_populate(&init_mm, pud, p);
78120+ pud_populate_kernel(&init_mm, pud, p);
78121 }
78122 return pud;
78123 }
78124@@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
78125 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
78126 if (!p)
78127 return NULL;
78128- pgd_populate(&init_mm, pgd, p);
78129+ pgd_populate_kernel(&init_mm, pgd, p);
78130 }
78131 return pgd;
78132 }
78133diff --git a/mm/swap.c b/mm/swap.c
78134index 6310dc2..3662b3f 100644
78135--- a/mm/swap.c
78136+++ b/mm/swap.c
78137@@ -30,6 +30,7 @@
78138 #include <linux/backing-dev.h>
78139 #include <linux/memcontrol.h>
78140 #include <linux/gfp.h>
78141+#include <linux/hugetlb.h>
78142
78143 #include "internal.h"
78144
78145@@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
78146
78147 __page_cache_release(page);
78148 dtor = get_compound_page_dtor(page);
78149+ if (!PageHuge(page))
78150+ BUG_ON(dtor != free_compound_page);
78151 (*dtor)(page);
78152 }
78153
78154diff --git a/mm/swapfile.c b/mm/swapfile.c
78155index f91a255..9dcac21 100644
78156--- a/mm/swapfile.c
78157+++ b/mm/swapfile.c
78158@@ -64,7 +64,7 @@ static DEFINE_MUTEX(swapon_mutex);
78159
78160 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
78161 /* Activity counter to indicate that a swapon or swapoff has occurred */
78162-static atomic_t proc_poll_event = ATOMIC_INIT(0);
78163+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
78164
78165 static inline unsigned char swap_count(unsigned char ent)
78166 {
78167@@ -1601,7 +1601,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
78168 }
78169 filp_close(swap_file, NULL);
78170 err = 0;
78171- atomic_inc(&proc_poll_event);
78172+ atomic_inc_unchecked(&proc_poll_event);
78173 wake_up_interruptible(&proc_poll_wait);
78174
78175 out_dput:
78176@@ -1618,8 +1618,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
78177
78178 poll_wait(file, &proc_poll_wait, wait);
78179
78180- if (seq->poll_event != atomic_read(&proc_poll_event)) {
78181- seq->poll_event = atomic_read(&proc_poll_event);
78182+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
78183+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
78184 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
78185 }
78186
78187@@ -1717,7 +1717,7 @@ static int swaps_open(struct inode *inode, struct file *file)
78188 return ret;
78189
78190 seq = file->private_data;
78191- seq->poll_event = atomic_read(&proc_poll_event);
78192+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
78193 return 0;
78194 }
78195
78196@@ -2059,7 +2059,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
78197 (frontswap_map) ? "FS" : "");
78198
78199 mutex_unlock(&swapon_mutex);
78200- atomic_inc(&proc_poll_event);
78201+ atomic_inc_unchecked(&proc_poll_event);
78202 wake_up_interruptible(&proc_poll_wait);
78203
78204 if (S_ISREG(inode->i_mode))
78205diff --git a/mm/util.c b/mm/util.c
78206index dc3036c..b6c7c9d 100644
78207--- a/mm/util.c
78208+++ b/mm/util.c
78209@@ -292,6 +292,12 @@ done:
78210 void arch_pick_mmap_layout(struct mm_struct *mm)
78211 {
78212 mm->mmap_base = TASK_UNMAPPED_BASE;
78213+
78214+#ifdef CONFIG_PAX_RANDMMAP
78215+ if (mm->pax_flags & MF_PAX_RANDMMAP)
78216+ mm->mmap_base += mm->delta_mmap;
78217+#endif
78218+
78219 mm->get_unmapped_area = arch_get_unmapped_area;
78220 mm->unmap_area = arch_unmap_area;
78221 }
78222diff --git a/mm/vmalloc.c b/mm/vmalloc.c
78223index 78e0830..bc6bbd8 100644
78224--- a/mm/vmalloc.c
78225+++ b/mm/vmalloc.c
78226@@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
78227
78228 pte = pte_offset_kernel(pmd, addr);
78229 do {
78230- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
78231- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
78232+
78233+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
78234+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
78235+ BUG_ON(!pte_exec(*pte));
78236+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
78237+ continue;
78238+ }
78239+#endif
78240+
78241+ {
78242+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
78243+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
78244+ }
78245 } while (pte++, addr += PAGE_SIZE, addr != end);
78246 }
78247
78248@@ -100,16 +111,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
78249 pte = pte_alloc_kernel(pmd, addr);
78250 if (!pte)
78251 return -ENOMEM;
78252+
78253+ pax_open_kernel();
78254 do {
78255 struct page *page = pages[*nr];
78256
78257- if (WARN_ON(!pte_none(*pte)))
78258+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
78259+ if (pgprot_val(prot) & _PAGE_NX)
78260+#endif
78261+
78262+ if (!pte_none(*pte)) {
78263+ pax_close_kernel();
78264+ WARN_ON(1);
78265 return -EBUSY;
78266- if (WARN_ON(!page))
78267+ }
78268+ if (!page) {
78269+ pax_close_kernel();
78270+ WARN_ON(1);
78271 return -ENOMEM;
78272+ }
78273 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
78274 (*nr)++;
78275 } while (pte++, addr += PAGE_SIZE, addr != end);
78276+ pax_close_kernel();
78277 return 0;
78278 }
78279
78280@@ -119,7 +143,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
78281 pmd_t *pmd;
78282 unsigned long next;
78283
78284- pmd = pmd_alloc(&init_mm, pud, addr);
78285+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
78286 if (!pmd)
78287 return -ENOMEM;
78288 do {
78289@@ -136,7 +160,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
78290 pud_t *pud;
78291 unsigned long next;
78292
78293- pud = pud_alloc(&init_mm, pgd, addr);
78294+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
78295 if (!pud)
78296 return -ENOMEM;
78297 do {
78298@@ -191,11 +215,20 @@ int is_vmalloc_or_module_addr(const void *x)
78299 * and fall back on vmalloc() if that fails. Others
78300 * just put it in the vmalloc space.
78301 */
78302-#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
78303+#ifdef CONFIG_MODULES
78304+#ifdef MODULES_VADDR
78305 unsigned long addr = (unsigned long)x;
78306 if (addr >= MODULES_VADDR && addr < MODULES_END)
78307 return 1;
78308 #endif
78309+
78310+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
78311+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
78312+ return 1;
78313+#endif
78314+
78315+#endif
78316+
78317 return is_vmalloc_addr(x);
78318 }
78319
78320@@ -216,8 +249,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
78321
78322 if (!pgd_none(*pgd)) {
78323 pud_t *pud = pud_offset(pgd, addr);
78324+#ifdef CONFIG_X86
78325+ if (!pud_large(*pud))
78326+#endif
78327 if (!pud_none(*pud)) {
78328 pmd_t *pmd = pmd_offset(pud, addr);
78329+#ifdef CONFIG_X86
78330+ if (!pmd_large(*pmd))
78331+#endif
78332 if (!pmd_none(*pmd)) {
78333 pte_t *ptep, pte;
78334
78335@@ -329,7 +368,7 @@ static void purge_vmap_area_lazy(void);
78336 * Allocate a region of KVA of the specified size and alignment, within the
78337 * vstart and vend.
78338 */
78339-static struct vmap_area *alloc_vmap_area(unsigned long size,
78340+static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
78341 unsigned long align,
78342 unsigned long vstart, unsigned long vend,
78343 int node, gfp_t gfp_mask)
78344@@ -1328,6 +1367,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
78345 struct vm_struct *area;
78346
78347 BUG_ON(in_interrupt());
78348+
78349+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
78350+ if (flags & VM_KERNEXEC) {
78351+ if (start != VMALLOC_START || end != VMALLOC_END)
78352+ return NULL;
78353+ start = (unsigned long)MODULES_EXEC_VADDR;
78354+ end = (unsigned long)MODULES_EXEC_END;
78355+ }
78356+#endif
78357+
78358 if (flags & VM_IOREMAP) {
78359 int bit = fls(size);
78360
78361@@ -1568,6 +1617,11 @@ void *vmap(struct page **pages, unsigned int count,
78362 if (count > totalram_pages)
78363 return NULL;
78364
78365+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
78366+ if (!(pgprot_val(prot) & _PAGE_NX))
78367+ flags |= VM_KERNEXEC;
78368+#endif
78369+
78370 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
78371 __builtin_return_address(0));
78372 if (!area)
78373@@ -1669,6 +1723,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
78374 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
78375 goto fail;
78376
78377+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
78378+ if (!(pgprot_val(prot) & _PAGE_NX))
78379+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
78380+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
78381+ else
78382+#endif
78383+
78384 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
78385 start, end, node, gfp_mask, caller);
78386 if (!area)
78387@@ -1842,10 +1903,9 @@ EXPORT_SYMBOL(vzalloc_node);
78388 * For tight control over page level allocator and protection flags
78389 * use __vmalloc() instead.
78390 */
78391-
78392 void *vmalloc_exec(unsigned long size)
78393 {
78394- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
78395+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
78396 -1, __builtin_return_address(0));
78397 }
78398
78399@@ -2136,6 +2196,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
78400 unsigned long uaddr = vma->vm_start;
78401 unsigned long usize = vma->vm_end - vma->vm_start;
78402
78403+ BUG_ON(vma->vm_mirror);
78404+
78405 if ((PAGE_SIZE-1) & (unsigned long)addr)
78406 return -EINVAL;
78407
78408@@ -2575,7 +2637,11 @@ static int s_show(struct seq_file *m, void *p)
78409 v->addr, v->addr + v->size, v->size);
78410
78411 if (v->caller)
78412+#ifdef CONFIG_GRKERNSEC_HIDESYM
78413+ seq_printf(m, " %pK", v->caller);
78414+#else
78415 seq_printf(m, " %pS", v->caller);
78416+#endif
78417
78418 if (v->nr_pages)
78419 seq_printf(m, " pages=%d", v->nr_pages);
78420diff --git a/mm/vmstat.c b/mm/vmstat.c
78421index c737057..a49753a 100644
78422--- a/mm/vmstat.c
78423+++ b/mm/vmstat.c
78424@@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
78425 *
78426 * vm_stat contains the global counters
78427 */
78428-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
78429+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
78430 EXPORT_SYMBOL(vm_stat);
78431
78432 #ifdef CONFIG_SMP
78433@@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
78434 v = p->vm_stat_diff[i];
78435 p->vm_stat_diff[i] = 0;
78436 local_irq_restore(flags);
78437- atomic_long_add(v, &zone->vm_stat[i]);
78438+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
78439 global_diff[i] += v;
78440 #ifdef CONFIG_NUMA
78441 /* 3 seconds idle till flush */
78442@@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
78443
78444 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
78445 if (global_diff[i])
78446- atomic_long_add(global_diff[i], &vm_stat[i]);
78447+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
78448 }
78449
78450 void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
78451@@ -503,8 +503,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
78452 if (pset->vm_stat_diff[i]) {
78453 int v = pset->vm_stat_diff[i];
78454 pset->vm_stat_diff[i] = 0;
78455- atomic_long_add(v, &zone->vm_stat[i]);
78456- atomic_long_add(v, &vm_stat[i]);
78457+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
78458+ atomic_long_add_unchecked(v, &vm_stat[i]);
78459 }
78460 }
78461 #endif
78462@@ -1224,10 +1224,20 @@ static int __init setup_vmstat(void)
78463 start_cpu_timer(cpu);
78464 #endif
78465 #ifdef CONFIG_PROC_FS
78466- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
78467- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
78468- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
78469- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
78470+ {
78471+ mode_t gr_mode = S_IRUGO;
78472+#ifdef CONFIG_GRKERNSEC_PROC_ADD
78473+ gr_mode = S_IRUSR;
78474+#endif
78475+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
78476+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
78477+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
78478+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
78479+#else
78480+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
78481+#endif
78482+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
78483+ }
78484 #endif
78485 return 0;
78486 }
78487diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
78488index ee07072..593e3fd 100644
78489--- a/net/8021q/vlan.c
78490+++ b/net/8021q/vlan.c
78491@@ -484,7 +484,7 @@ out:
78492 return NOTIFY_DONE;
78493 }
78494
78495-static struct notifier_block vlan_notifier_block __read_mostly = {
78496+static struct notifier_block vlan_notifier_block = {
78497 .notifier_call = vlan_device_event,
78498 };
78499
78500@@ -559,8 +559,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
78501 err = -EPERM;
78502 if (!capable(CAP_NET_ADMIN))
78503 break;
78504- if ((args.u.name_type >= 0) &&
78505- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
78506+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
78507 struct vlan_net *vn;
78508
78509 vn = net_generic(net, vlan_net_id);
78510diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
78511index 02efb25..41541a9 100644
78512--- a/net/9p/trans_fd.c
78513+++ b/net/9p/trans_fd.c
78514@@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
78515 oldfs = get_fs();
78516 set_fs(get_ds());
78517 /* The cast to a user pointer is valid due to the set_fs() */
78518- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
78519+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
78520 set_fs(oldfs);
78521
78522 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
78523diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
78524index 876fbe8..8bbea9f 100644
78525--- a/net/atm/atm_misc.c
78526+++ b/net/atm/atm_misc.c
78527@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
78528 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
78529 return 1;
78530 atm_return(vcc, truesize);
78531- atomic_inc(&vcc->stats->rx_drop);
78532+ atomic_inc_unchecked(&vcc->stats->rx_drop);
78533 return 0;
78534 }
78535 EXPORT_SYMBOL(atm_charge);
78536@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
78537 }
78538 }
78539 atm_return(vcc, guess);
78540- atomic_inc(&vcc->stats->rx_drop);
78541+ atomic_inc_unchecked(&vcc->stats->rx_drop);
78542 return NULL;
78543 }
78544 EXPORT_SYMBOL(atm_alloc_charge);
78545@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
78546
78547 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
78548 {
78549-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
78550+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
78551 __SONET_ITEMS
78552 #undef __HANDLE_ITEM
78553 }
78554@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
78555
78556 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
78557 {
78558-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
78559+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
78560 __SONET_ITEMS
78561 #undef __HANDLE_ITEM
78562 }
78563diff --git a/net/atm/lec.h b/net/atm/lec.h
78564index a86aff9..3a0d6f6 100644
78565--- a/net/atm/lec.h
78566+++ b/net/atm/lec.h
78567@@ -48,7 +48,7 @@ struct lane2_ops {
78568 const u8 *tlvs, u32 sizeoftlvs);
78569 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
78570 const u8 *tlvs, u32 sizeoftlvs);
78571-};
78572+} __no_const;
78573
78574 /*
78575 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
78576diff --git a/net/atm/proc.c b/net/atm/proc.c
78577index 0d020de..011c7bb 100644
78578--- a/net/atm/proc.c
78579+++ b/net/atm/proc.c
78580@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
78581 const struct k_atm_aal_stats *stats)
78582 {
78583 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
78584- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
78585- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
78586- atomic_read(&stats->rx_drop));
78587+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
78588+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
78589+ atomic_read_unchecked(&stats->rx_drop));
78590 }
78591
78592 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
78593diff --git a/net/atm/resources.c b/net/atm/resources.c
78594index 0447d5d..3cf4728 100644
78595--- a/net/atm/resources.c
78596+++ b/net/atm/resources.c
78597@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
78598 static void copy_aal_stats(struct k_atm_aal_stats *from,
78599 struct atm_aal_stats *to)
78600 {
78601-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
78602+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
78603 __AAL_STAT_ITEMS
78604 #undef __HANDLE_ITEM
78605 }
78606@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
78607 static void subtract_aal_stats(struct k_atm_aal_stats *from,
78608 struct atm_aal_stats *to)
78609 {
78610-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
78611+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
78612 __AAL_STAT_ITEMS
78613 #undef __HANDLE_ITEM
78614 }
78615diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
78616index c6fcc76..1270d14 100644
78617--- a/net/batman-adv/bat_iv_ogm.c
78618+++ b/net/batman-adv/bat_iv_ogm.c
78619@@ -62,7 +62,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
78620
78621 /* randomize initial seqno to avoid collision */
78622 get_random_bytes(&random_seqno, sizeof(random_seqno));
78623- atomic_set(&hard_iface->seqno, random_seqno);
78624+ atomic_set_unchecked(&hard_iface->seqno, random_seqno);
78625
78626 hard_iface->packet_len = BATADV_OGM_HLEN;
78627 hard_iface->packet_buff = kmalloc(hard_iface->packet_len, GFP_ATOMIC);
78628@@ -608,9 +608,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
78629 batadv_ogm_packet = (struct batadv_ogm_packet *)hard_iface->packet_buff;
78630
78631 /* change sequence number to network order */
78632- seqno = (uint32_t)atomic_read(&hard_iface->seqno);
78633+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->seqno);
78634 batadv_ogm_packet->seqno = htonl(seqno);
78635- atomic_inc(&hard_iface->seqno);
78636+ atomic_inc_unchecked(&hard_iface->seqno);
78637
78638 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
78639 batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
78640@@ -1015,7 +1015,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
78641 return;
78642
78643 /* could be changed by schedule_own_packet() */
78644- if_incoming_seqno = atomic_read(&if_incoming->seqno);
78645+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
78646
78647 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
78648 has_directlink_flag = 1;
78649diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
78650index d112fd6..686a447 100644
78651--- a/net/batman-adv/hard-interface.c
78652+++ b/net/batman-adv/hard-interface.c
78653@@ -327,7 +327,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
78654 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
78655 dev_add_pack(&hard_iface->batman_adv_ptype);
78656
78657- atomic_set(&hard_iface->frag_seqno, 1);
78658+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
78659 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
78660 hard_iface->net_dev->name);
78661
78662@@ -450,7 +450,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
78663 /* This can't be called via a bat_priv callback because
78664 * we have no bat_priv yet.
78665 */
78666- atomic_set(&hard_iface->seqno, 1);
78667+ atomic_set_unchecked(&hard_iface->seqno, 1);
78668 hard_iface->packet_buff = NULL;
78669
78670 return hard_iface;
78671diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
78672index ce0684a..4a0cbf1 100644
78673--- a/net/batman-adv/soft-interface.c
78674+++ b/net/batman-adv/soft-interface.c
78675@@ -234,7 +234,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
78676 primary_if->net_dev->dev_addr, ETH_ALEN);
78677
78678 /* set broadcast sequence number */
78679- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
78680+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
78681 bcast_packet->seqno = htonl(seqno);
78682
78683 batadv_add_bcast_packet_to_list(bat_priv, skb, 1);
78684@@ -427,7 +427,7 @@ struct net_device *batadv_softif_create(const char *name)
78685 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
78686
78687 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
78688- atomic_set(&bat_priv->bcast_seqno, 1);
78689+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
78690 atomic_set(&bat_priv->tt.vn, 0);
78691 atomic_set(&bat_priv->tt.local_changes, 0);
78692 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
78693diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
78694index ac1e07a..4c846e2 100644
78695--- a/net/batman-adv/types.h
78696+++ b/net/batman-adv/types.h
78697@@ -33,8 +33,8 @@ struct batadv_hard_iface {
78698 int16_t if_num;
78699 char if_status;
78700 struct net_device *net_dev;
78701- atomic_t seqno;
78702- atomic_t frag_seqno;
78703+ atomic_unchecked_t seqno;
78704+ atomic_unchecked_t frag_seqno;
78705 unsigned char *packet_buff;
78706 int packet_len;
78707 struct kobject *hardif_obj;
78708@@ -244,7 +244,7 @@ struct batadv_priv {
78709 atomic_t orig_interval; /* uint */
78710 atomic_t hop_penalty; /* uint */
78711 atomic_t log_level; /* uint */
78712- atomic_t bcast_seqno;
78713+ atomic_unchecked_t bcast_seqno;
78714 atomic_t bcast_queue_left;
78715 atomic_t batman_queue_left;
78716 char num_ifaces;
78717diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
78718index f397232..3206a33 100644
78719--- a/net/batman-adv/unicast.c
78720+++ b/net/batman-adv/unicast.c
78721@@ -272,7 +272,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
78722 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
78723 frag2->flags = large_tail;
78724
78725- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
78726+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
78727 frag1->seqno = htons(seqno - 1);
78728 frag2->seqno = htons(seqno);
78729
78730diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
78731index 07f0739..3c42e34 100644
78732--- a/net/bluetooth/hci_sock.c
78733+++ b/net/bluetooth/hci_sock.c
78734@@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
78735 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
78736 }
78737
78738- len = min_t(unsigned int, len, sizeof(uf));
78739+ len = min((size_t)len, sizeof(uf));
78740 if (copy_from_user(&uf, optval, len)) {
78741 err = -EFAULT;
78742 break;
78743diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
78744index a91239d..d7ed533 100644
78745--- a/net/bluetooth/l2cap_core.c
78746+++ b/net/bluetooth/l2cap_core.c
78747@@ -3183,8 +3183,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
78748 break;
78749
78750 case L2CAP_CONF_RFC:
78751- if (olen == sizeof(rfc))
78752- memcpy(&rfc, (void *)val, olen);
78753+ if (olen != sizeof(rfc))
78754+ break;
78755+
78756+ memcpy(&rfc, (void *)val, olen);
78757
78758 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
78759 rfc.mode != chan->mode)
78760diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
78761index 083f2bf..799f9448 100644
78762--- a/net/bluetooth/l2cap_sock.c
78763+++ b/net/bluetooth/l2cap_sock.c
78764@@ -471,7 +471,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
78765 struct sock *sk = sock->sk;
78766 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
78767 struct l2cap_options opts;
78768- int len, err = 0;
78769+ int err = 0;
78770+ size_t len = optlen;
78771 u32 opt;
78772
78773 BT_DBG("sk %p", sk);
78774@@ -493,7 +494,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
78775 opts.max_tx = chan->max_tx;
78776 opts.txwin_size = chan->tx_win;
78777
78778- len = min_t(unsigned int, sizeof(opts), optlen);
78779+ len = min(sizeof(opts), len);
78780 if (copy_from_user((char *) &opts, optval, len)) {
78781 err = -EFAULT;
78782 break;
78783@@ -571,7 +572,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
78784 struct bt_security sec;
78785 struct bt_power pwr;
78786 struct l2cap_conn *conn;
78787- int len, err = 0;
78788+ int err = 0;
78789+ size_t len = optlen;
78790 u32 opt;
78791
78792 BT_DBG("sk %p", sk);
78793@@ -594,7 +596,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
78794
78795 sec.level = BT_SECURITY_LOW;
78796
78797- len = min_t(unsigned int, sizeof(sec), optlen);
78798+ len = min(sizeof(sec), len);
78799 if (copy_from_user((char *) &sec, optval, len)) {
78800 err = -EFAULT;
78801 break;
78802@@ -691,7 +693,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
78803
78804 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
78805
78806- len = min_t(unsigned int, sizeof(pwr), optlen);
78807+ len = min(sizeof(pwr), len);
78808 if (copy_from_user((char *) &pwr, optval, len)) {
78809 err = -EFAULT;
78810 break;
78811diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
78812index 868a909..d044bc3 100644
78813--- a/net/bluetooth/rfcomm/sock.c
78814+++ b/net/bluetooth/rfcomm/sock.c
78815@@ -667,7 +667,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
78816 struct sock *sk = sock->sk;
78817 struct bt_security sec;
78818 int err = 0;
78819- size_t len;
78820+ size_t len = optlen;
78821 u32 opt;
78822
78823 BT_DBG("sk %p", sk);
78824@@ -689,7 +689,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
78825
78826 sec.level = BT_SECURITY_LOW;
78827
78828- len = min_t(unsigned int, sizeof(sec), optlen);
78829+ len = min(sizeof(sec), len);
78830 if (copy_from_user((char *) &sec, optval, len)) {
78831 err = -EFAULT;
78832 break;
78833diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
78834index ccc2487..921073d 100644
78835--- a/net/bluetooth/rfcomm/tty.c
78836+++ b/net/bluetooth/rfcomm/tty.c
78837@@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
78838 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
78839
78840 spin_lock_irqsave(&dev->port.lock, flags);
78841- if (dev->port.count > 0) {
78842+ if (atomic_read(&dev->port.count) > 0) {
78843 spin_unlock_irqrestore(&dev->port.lock, flags);
78844 return;
78845 }
78846@@ -664,10 +664,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
78847 return -ENODEV;
78848
78849 BT_DBG("dev %p dst %s channel %d opened %d", dev, batostr(&dev->dst),
78850- dev->channel, dev->port.count);
78851+ dev->channel, atomic_read(&dev->port.count));
78852
78853 spin_lock_irqsave(&dev->port.lock, flags);
78854- if (++dev->port.count > 1) {
78855+ if (atomic_inc_return(&dev->port.count) > 1) {
78856 spin_unlock_irqrestore(&dev->port.lock, flags);
78857 return 0;
78858 }
78859@@ -732,10 +732,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
78860 return;
78861
78862 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
78863- dev->port.count);
78864+ atomic_read(&dev->port.count));
78865
78866 spin_lock_irqsave(&dev->port.lock, flags);
78867- if (!--dev->port.count) {
78868+ if (!atomic_dec_return(&dev->port.count)) {
78869 spin_unlock_irqrestore(&dev->port.lock, flags);
78870 if (dev->tty_dev->parent)
78871 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
78872diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
78873index 5fe2ff3..121d696 100644
78874--- a/net/bridge/netfilter/ebtables.c
78875+++ b/net/bridge/netfilter/ebtables.c
78876@@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
78877 tmp.valid_hooks = t->table->valid_hooks;
78878 }
78879 mutex_unlock(&ebt_mutex);
78880- if (copy_to_user(user, &tmp, *len) != 0){
78881+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
78882 BUGPRINT("c2u Didn't work\n");
78883 ret = -EFAULT;
78884 break;
78885@@ -2327,7 +2327,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
78886 goto out;
78887 tmp.valid_hooks = t->valid_hooks;
78888
78889- if (copy_to_user(user, &tmp, *len) != 0) {
78890+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
78891 ret = -EFAULT;
78892 break;
78893 }
78894@@ -2338,7 +2338,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
78895 tmp.entries_size = t->table->entries_size;
78896 tmp.valid_hooks = t->table->valid_hooks;
78897
78898- if (copy_to_user(user, &tmp, *len) != 0) {
78899+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
78900 ret = -EFAULT;
78901 break;
78902 }
78903diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
78904index 44f270f..1f5602d 100644
78905--- a/net/caif/cfctrl.c
78906+++ b/net/caif/cfctrl.c
78907@@ -10,6 +10,7 @@
78908 #include <linux/spinlock.h>
78909 #include <linux/slab.h>
78910 #include <linux/pkt_sched.h>
78911+#include <linux/sched.h>
78912 #include <net/caif/caif_layer.h>
78913 #include <net/caif/cfpkt.h>
78914 #include <net/caif/cfctrl.h>
78915@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
78916 memset(&dev_info, 0, sizeof(dev_info));
78917 dev_info.id = 0xff;
78918 cfsrvl_init(&this->serv, 0, &dev_info, false);
78919- atomic_set(&this->req_seq_no, 1);
78920- atomic_set(&this->rsp_seq_no, 1);
78921+ atomic_set_unchecked(&this->req_seq_no, 1);
78922+ atomic_set_unchecked(&this->rsp_seq_no, 1);
78923 this->serv.layer.receive = cfctrl_recv;
78924 sprintf(this->serv.layer.name, "ctrl");
78925 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
78926@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
78927 struct cfctrl_request_info *req)
78928 {
78929 spin_lock_bh(&ctrl->info_list_lock);
78930- atomic_inc(&ctrl->req_seq_no);
78931- req->sequence_no = atomic_read(&ctrl->req_seq_no);
78932+ atomic_inc_unchecked(&ctrl->req_seq_no);
78933+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
78934 list_add_tail(&req->list, &ctrl->list);
78935 spin_unlock_bh(&ctrl->info_list_lock);
78936 }
78937@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
78938 if (p != first)
78939 pr_warn("Requests are not received in order\n");
78940
78941- atomic_set(&ctrl->rsp_seq_no,
78942+ atomic_set_unchecked(&ctrl->rsp_seq_no,
78943 p->sequence_no);
78944 list_del(&p->list);
78945 goto out;
78946diff --git a/net/can/af_can.c b/net/can/af_can.c
78947index ddac1ee..3ee0a78 100644
78948--- a/net/can/af_can.c
78949+++ b/net/can/af_can.c
78950@@ -872,7 +872,7 @@ static const struct net_proto_family can_family_ops = {
78951 };
78952
78953 /* notifier block for netdevice event */
78954-static struct notifier_block can_netdev_notifier __read_mostly = {
78955+static struct notifier_block can_netdev_notifier = {
78956 .notifier_call = can_notifier,
78957 };
78958
78959diff --git a/net/can/gw.c b/net/can/gw.c
78960index 1f5c978..ef714c7 100644
78961--- a/net/can/gw.c
78962+++ b/net/can/gw.c
78963@@ -67,7 +67,6 @@ MODULE_AUTHOR("Oliver Hartkopp <oliver.hartkopp@volkswagen.de>");
78964 MODULE_ALIAS("can-gw");
78965
78966 static HLIST_HEAD(cgw_list);
78967-static struct notifier_block notifier;
78968
78969 static struct kmem_cache *cgw_cache __read_mostly;
78970
78971@@ -887,6 +886,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
78972 return err;
78973 }
78974
78975+static struct notifier_block notifier = {
78976+ .notifier_call = cgw_notifier
78977+};
78978+
78979 static __init int cgw_module_init(void)
78980 {
78981 printk(banner);
78982@@ -898,7 +901,6 @@ static __init int cgw_module_init(void)
78983 return -ENOMEM;
78984
78985 /* set notifier */
78986- notifier.notifier_call = cgw_notifier;
78987 register_netdevice_notifier(&notifier);
78988
78989 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
78990diff --git a/net/compat.c b/net/compat.c
78991index 79ae884..17c5c09 100644
78992--- a/net/compat.c
78993+++ b/net/compat.c
78994@@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
78995 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
78996 __get_user(kmsg->msg_flags, &umsg->msg_flags))
78997 return -EFAULT;
78998- kmsg->msg_name = compat_ptr(tmp1);
78999- kmsg->msg_iov = compat_ptr(tmp2);
79000- kmsg->msg_control = compat_ptr(tmp3);
79001+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
79002+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
79003+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
79004 return 0;
79005 }
79006
79007@@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
79008
79009 if (kern_msg->msg_namelen) {
79010 if (mode == VERIFY_READ) {
79011- int err = move_addr_to_kernel(kern_msg->msg_name,
79012+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
79013 kern_msg->msg_namelen,
79014 kern_address);
79015 if (err < 0)
79016@@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
79017 kern_msg->msg_name = NULL;
79018
79019 tot_len = iov_from_user_compat_to_kern(kern_iov,
79020- (struct compat_iovec __user *)kern_msg->msg_iov,
79021+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
79022 kern_msg->msg_iovlen);
79023 if (tot_len >= 0)
79024 kern_msg->msg_iov = kern_iov;
79025@@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
79026
79027 #define CMSG_COMPAT_FIRSTHDR(msg) \
79028 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
79029- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
79030+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
79031 (struct compat_cmsghdr __user *)NULL)
79032
79033 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
79034 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
79035 (ucmlen) <= (unsigned long) \
79036 ((mhdr)->msg_controllen - \
79037- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
79038+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
79039
79040 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
79041 struct compat_cmsghdr __user *cmsg, int cmsg_len)
79042 {
79043 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
79044- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
79045+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
79046 msg->msg_controllen)
79047 return NULL;
79048 return (struct compat_cmsghdr __user *)ptr;
79049@@ -219,7 +219,7 @@ Efault:
79050
79051 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
79052 {
79053- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
79054+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
79055 struct compat_cmsghdr cmhdr;
79056 struct compat_timeval ctv;
79057 struct compat_timespec cts[3];
79058@@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
79059
79060 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
79061 {
79062- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
79063+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
79064 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
79065 int fdnum = scm->fp->count;
79066 struct file **fp = scm->fp->fp;
79067@@ -363,7 +363,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
79068 return -EFAULT;
79069 old_fs = get_fs();
79070 set_fs(KERNEL_DS);
79071- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
79072+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
79073 set_fs(old_fs);
79074
79075 return err;
79076@@ -424,7 +424,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
79077 len = sizeof(ktime);
79078 old_fs = get_fs();
79079 set_fs(KERNEL_DS);
79080- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
79081+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
79082 set_fs(old_fs);
79083
79084 if (!err) {
79085@@ -567,7 +567,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
79086 case MCAST_JOIN_GROUP:
79087 case MCAST_LEAVE_GROUP:
79088 {
79089- struct compat_group_req __user *gr32 = (void *)optval;
79090+ struct compat_group_req __user *gr32 = (void __user *)optval;
79091 struct group_req __user *kgr =
79092 compat_alloc_user_space(sizeof(struct group_req));
79093 u32 interface;
79094@@ -588,7 +588,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
79095 case MCAST_BLOCK_SOURCE:
79096 case MCAST_UNBLOCK_SOURCE:
79097 {
79098- struct compat_group_source_req __user *gsr32 = (void *)optval;
79099+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
79100 struct group_source_req __user *kgsr = compat_alloc_user_space(
79101 sizeof(struct group_source_req));
79102 u32 interface;
79103@@ -609,7 +609,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
79104 }
79105 case MCAST_MSFILTER:
79106 {
79107- struct compat_group_filter __user *gf32 = (void *)optval;
79108+ struct compat_group_filter __user *gf32 = (void __user *)optval;
79109 struct group_filter __user *kgf;
79110 u32 interface, fmode, numsrc;
79111
79112@@ -647,7 +647,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
79113 char __user *optval, int __user *optlen,
79114 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
79115 {
79116- struct compat_group_filter __user *gf32 = (void *)optval;
79117+ struct compat_group_filter __user *gf32 = (void __user *)optval;
79118 struct group_filter __user *kgf;
79119 int __user *koptlen;
79120 u32 interface, fmode, numsrc;
79121@@ -796,7 +796,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
79122
79123 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
79124 return -EINVAL;
79125- if (copy_from_user(a, args, nas[call]))
79126+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
79127 return -EFAULT;
79128 a0 = a[0];
79129 a1 = a[1];
79130diff --git a/net/core/datagram.c b/net/core/datagram.c
79131index 0337e2b..47914a0 100644
79132--- a/net/core/datagram.c
79133+++ b/net/core/datagram.c
79134@@ -289,7 +289,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
79135 }
79136
79137 kfree_skb(skb);
79138- atomic_inc(&sk->sk_drops);
79139+ atomic_inc_unchecked(&sk->sk_drops);
79140 sk_mem_reclaim_partial(sk);
79141
79142 return err;
79143diff --git a/net/core/dev.c b/net/core/dev.c
79144index e5942bf..25998c3 100644
79145--- a/net/core/dev.c
79146+++ b/net/core/dev.c
79147@@ -1162,9 +1162,13 @@ void dev_load(struct net *net, const char *name)
79148 if (no_module && capable(CAP_NET_ADMIN))
79149 no_module = request_module("netdev-%s", name);
79150 if (no_module && capable(CAP_SYS_MODULE)) {
79151+#ifdef CONFIG_GRKERNSEC_MODHARDEN
79152+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
79153+#else
79154 if (!request_module("%s", name))
79155 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
79156 name);
79157+#endif
79158 }
79159 }
79160 EXPORT_SYMBOL(dev_load);
79161@@ -1627,7 +1631,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
79162 {
79163 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
79164 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
79165- atomic_long_inc(&dev->rx_dropped);
79166+ atomic_long_inc_unchecked(&dev->rx_dropped);
79167 kfree_skb(skb);
79168 return NET_RX_DROP;
79169 }
79170@@ -1637,7 +1641,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
79171 nf_reset(skb);
79172
79173 if (unlikely(!is_skb_forwardable(dev, skb))) {
79174- atomic_long_inc(&dev->rx_dropped);
79175+ atomic_long_inc_unchecked(&dev->rx_dropped);
79176 kfree_skb(skb);
79177 return NET_RX_DROP;
79178 }
79179@@ -2093,7 +2097,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
79180
79181 struct dev_gso_cb {
79182 void (*destructor)(struct sk_buff *skb);
79183-};
79184+} __no_const;
79185
79186 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
79187
79188@@ -2955,7 +2959,7 @@ enqueue:
79189
79190 local_irq_restore(flags);
79191
79192- atomic_long_inc(&skb->dev->rx_dropped);
79193+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
79194 kfree_skb(skb);
79195 return NET_RX_DROP;
79196 }
79197@@ -3027,7 +3031,7 @@ int netif_rx_ni(struct sk_buff *skb)
79198 }
79199 EXPORT_SYMBOL(netif_rx_ni);
79200
79201-static void net_tx_action(struct softirq_action *h)
79202+static void net_tx_action(void)
79203 {
79204 struct softnet_data *sd = &__get_cpu_var(softnet_data);
79205
79206@@ -3358,7 +3362,7 @@ ncls:
79207 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
79208 } else {
79209 drop:
79210- atomic_long_inc(&skb->dev->rx_dropped);
79211+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
79212 kfree_skb(skb);
79213 /* Jamal, now you will not able to escape explaining
79214 * me how you were going to use this. :-)
79215@@ -3944,7 +3948,7 @@ void netif_napi_del(struct napi_struct *napi)
79216 }
79217 EXPORT_SYMBOL(netif_napi_del);
79218
79219-static void net_rx_action(struct softirq_action *h)
79220+static void net_rx_action(void)
79221 {
79222 struct softnet_data *sd = &__get_cpu_var(softnet_data);
79223 unsigned long time_limit = jiffies + 2;
79224@@ -4423,8 +4427,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
79225 else
79226 seq_printf(seq, "%04x", ntohs(pt->type));
79227
79228+#ifdef CONFIG_GRKERNSEC_HIDESYM
79229+ seq_printf(seq, " %-8s %p\n",
79230+ pt->dev ? pt->dev->name : "", NULL);
79231+#else
79232 seq_printf(seq, " %-8s %pF\n",
79233 pt->dev ? pt->dev->name : "", pt->func);
79234+#endif
79235 }
79236
79237 return 0;
79238@@ -5987,7 +5996,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
79239 } else {
79240 netdev_stats_to_stats64(storage, &dev->stats);
79241 }
79242- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
79243+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
79244 return storage;
79245 }
79246 EXPORT_SYMBOL(dev_get_stats);
79247diff --git a/net/core/flow.c b/net/core/flow.c
79248index e318c7e..168b1d0 100644
79249--- a/net/core/flow.c
79250+++ b/net/core/flow.c
79251@@ -61,7 +61,7 @@ struct flow_cache {
79252 struct timer_list rnd_timer;
79253 };
79254
79255-atomic_t flow_cache_genid = ATOMIC_INIT(0);
79256+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
79257 EXPORT_SYMBOL(flow_cache_genid);
79258 static struct flow_cache flow_cache_global;
79259 static struct kmem_cache *flow_cachep __read_mostly;
79260@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
79261
79262 static int flow_entry_valid(struct flow_cache_entry *fle)
79263 {
79264- if (atomic_read(&flow_cache_genid) != fle->genid)
79265+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
79266 return 0;
79267 if (fle->object && !fle->object->ops->check(fle->object))
79268 return 0;
79269@@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
79270 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
79271 fcp->hash_count++;
79272 }
79273- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
79274+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
79275 flo = fle->object;
79276 if (!flo)
79277 goto ret_object;
79278@@ -280,7 +280,7 @@ nocache:
79279 }
79280 flo = resolver(net, key, family, dir, flo, ctx);
79281 if (fle) {
79282- fle->genid = atomic_read(&flow_cache_genid);
79283+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
79284 if (!IS_ERR(flo))
79285 fle->object = flo;
79286 else
79287diff --git a/net/core/iovec.c b/net/core/iovec.c
79288index 7e7aeb0..2a998cb 100644
79289--- a/net/core/iovec.c
79290+++ b/net/core/iovec.c
79291@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
79292 if (m->msg_namelen) {
79293 if (mode == VERIFY_READ) {
79294 void __user *namep;
79295- namep = (void __user __force *) m->msg_name;
79296+ namep = (void __force_user *) m->msg_name;
79297 err = move_addr_to_kernel(namep, m->msg_namelen,
79298 address);
79299 if (err < 0)
79300@@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
79301 }
79302
79303 size = m->msg_iovlen * sizeof(struct iovec);
79304- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
79305+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
79306 return -EFAULT;
79307
79308 m->msg_iov = iov;
79309diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
79310index fad649a..f2fdac4 100644
79311--- a/net/core/rtnetlink.c
79312+++ b/net/core/rtnetlink.c
79313@@ -198,14 +198,16 @@ int __rtnl_register(int protocol, int msgtype,
79314 rtnl_msg_handlers[protocol] = tab;
79315 }
79316
79317+ pax_open_kernel();
79318 if (doit)
79319- tab[msgindex].doit = doit;
79320+ *(void **)&tab[msgindex].doit = doit;
79321
79322 if (dumpit)
79323- tab[msgindex].dumpit = dumpit;
79324+ *(void **)&tab[msgindex].dumpit = dumpit;
79325
79326 if (calcit)
79327- tab[msgindex].calcit = calcit;
79328+ *(void **)&tab[msgindex].calcit = calcit;
79329+ pax_close_kernel();
79330
79331 return 0;
79332 }
79333@@ -248,8 +250,10 @@ int rtnl_unregister(int protocol, int msgtype)
79334 if (rtnl_msg_handlers[protocol] == NULL)
79335 return -ENOENT;
79336
79337- rtnl_msg_handlers[protocol][msgindex].doit = NULL;
79338- rtnl_msg_handlers[protocol][msgindex].dumpit = NULL;
79339+ pax_open_kernel();
79340+ *(void **)&rtnl_msg_handlers[protocol][msgindex].doit = NULL;
79341+ *(void **)&rtnl_msg_handlers[protocol][msgindex].dumpit = NULL;
79342+ pax_close_kernel();
79343
79344 return 0;
79345 }
79346diff --git a/net/core/scm.c b/net/core/scm.c
79347index ab57084..0190c8f 100644
79348--- a/net/core/scm.c
79349+++ b/net/core/scm.c
79350@@ -223,7 +223,7 @@ EXPORT_SYMBOL(__scm_send);
79351 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
79352 {
79353 struct cmsghdr __user *cm
79354- = (__force struct cmsghdr __user *)msg->msg_control;
79355+ = (struct cmsghdr __force_user *)msg->msg_control;
79356 struct cmsghdr cmhdr;
79357 int cmlen = CMSG_LEN(len);
79358 int err;
79359@@ -246,7 +246,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
79360 err = -EFAULT;
79361 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
79362 goto out;
79363- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
79364+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
79365 goto out;
79366 cmlen = CMSG_SPACE(len);
79367 if (msg->msg_controllen < cmlen)
79368@@ -262,7 +262,7 @@ EXPORT_SYMBOL(put_cmsg);
79369 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
79370 {
79371 struct cmsghdr __user *cm
79372- = (__force struct cmsghdr __user*)msg->msg_control;
79373+ = (struct cmsghdr __force_user *)msg->msg_control;
79374
79375 int fdmax = 0;
79376 int fdnum = scm->fp->count;
79377@@ -282,7 +282,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
79378 if (fdnum < fdmax)
79379 fdmax = fdnum;
79380
79381- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
79382+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
79383 i++, cmfptr++)
79384 {
79385 struct socket *sock;
79386diff --git a/net/core/sock.c b/net/core/sock.c
79387index 8a146cf..ee08914d 100644
79388--- a/net/core/sock.c
79389+++ b/net/core/sock.c
79390@@ -388,7 +388,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
79391 struct sk_buff_head *list = &sk->sk_receive_queue;
79392
79393 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
79394- atomic_inc(&sk->sk_drops);
79395+ atomic_inc_unchecked(&sk->sk_drops);
79396 trace_sock_rcvqueue_full(sk, skb);
79397 return -ENOMEM;
79398 }
79399@@ -398,7 +398,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
79400 return err;
79401
79402 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
79403- atomic_inc(&sk->sk_drops);
79404+ atomic_inc_unchecked(&sk->sk_drops);
79405 return -ENOBUFS;
79406 }
79407
79408@@ -418,7 +418,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
79409 skb_dst_force(skb);
79410
79411 spin_lock_irqsave(&list->lock, flags);
79412- skb->dropcount = atomic_read(&sk->sk_drops);
79413+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
79414 __skb_queue_tail(list, skb);
79415 spin_unlock_irqrestore(&list->lock, flags);
79416
79417@@ -438,7 +438,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
79418 skb->dev = NULL;
79419
79420 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
79421- atomic_inc(&sk->sk_drops);
79422+ atomic_inc_unchecked(&sk->sk_drops);
79423 goto discard_and_relse;
79424 }
79425 if (nested)
79426@@ -456,7 +456,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
79427 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
79428 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
79429 bh_unlock_sock(sk);
79430- atomic_inc(&sk->sk_drops);
79431+ atomic_inc_unchecked(&sk->sk_drops);
79432 goto discard_and_relse;
79433 }
79434
79435@@ -875,12 +875,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
79436 struct timeval tm;
79437 } v;
79438
79439- int lv = sizeof(int);
79440- int len;
79441+ unsigned int lv = sizeof(int);
79442+ unsigned int len;
79443
79444 if (get_user(len, optlen))
79445 return -EFAULT;
79446- if (len < 0)
79447+ if (len > INT_MAX)
79448 return -EINVAL;
79449
79450 memset(&v, 0, sizeof(v));
79451@@ -1028,11 +1028,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
79452
79453 case SO_PEERNAME:
79454 {
79455- char address[128];
79456+ char address[_K_SS_MAXSIZE];
79457
79458 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
79459 return -ENOTCONN;
79460- if (lv < len)
79461+ if (lv < len || sizeof address < len)
79462 return -EINVAL;
79463 if (copy_to_user(optval, address, len))
79464 return -EFAULT;
79465@@ -1080,7 +1080,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
79466
79467 if (len > lv)
79468 len = lv;
79469- if (copy_to_user(optval, &v, len))
79470+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
79471 return -EFAULT;
79472 lenout:
79473 if (put_user(len, optlen))
79474@@ -2212,7 +2212,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
79475 */
79476 smp_wmb();
79477 atomic_set(&sk->sk_refcnt, 1);
79478- atomic_set(&sk->sk_drops, 0);
79479+ atomic_set_unchecked(&sk->sk_drops, 0);
79480 }
79481 EXPORT_SYMBOL(sock_init_data);
79482
79483diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
79484index 602cd63..05c6c60 100644
79485--- a/net/core/sock_diag.c
79486+++ b/net/core/sock_diag.c
79487@@ -15,20 +15,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
79488
79489 int sock_diag_check_cookie(void *sk, __u32 *cookie)
79490 {
79491+#ifndef CONFIG_GRKERNSEC_HIDESYM
79492 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
79493 cookie[1] != INET_DIAG_NOCOOKIE) &&
79494 ((u32)(unsigned long)sk != cookie[0] ||
79495 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
79496 return -ESTALE;
79497 else
79498+#endif
79499 return 0;
79500 }
79501 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
79502
79503 void sock_diag_save_cookie(void *sk, __u32 *cookie)
79504 {
79505+#ifdef CONFIG_GRKERNSEC_HIDESYM
79506+ cookie[0] = 0;
79507+ cookie[1] = 0;
79508+#else
79509 cookie[0] = (u32)(unsigned long)sk;
79510 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
79511+#endif
79512 }
79513 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
79514
79515diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
79516index a55eecc..dd8428c 100644
79517--- a/net/decnet/sysctl_net_decnet.c
79518+++ b/net/decnet/sysctl_net_decnet.c
79519@@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
79520
79521 if (len > *lenp) len = *lenp;
79522
79523- if (copy_to_user(buffer, addr, len))
79524+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
79525 return -EFAULT;
79526
79527 *lenp = len;
79528@@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
79529
79530 if (len > *lenp) len = *lenp;
79531
79532- if (copy_to_user(buffer, devname, len))
79533+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
79534 return -EFAULT;
79535
79536 *lenp = len;
79537diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
79538index 2a6abc1..c379ba7 100644
79539--- a/net/ipv4/devinet.c
79540+++ b/net/ipv4/devinet.c
79541@@ -822,9 +822,9 @@ int devinet_ioctl(struct net *net, unsigned int cmd, void __user *arg)
79542 if (!ifa) {
79543 ret = -ENOBUFS;
79544 ifa = inet_alloc_ifa();
79545+ if (!ifa)
79546+ break;
79547 INIT_HLIST_NODE(&ifa->hash);
79548- if (!ifa)
79549- break;
79550 if (colon)
79551 memcpy(ifa->ifa_label, ifr.ifr_name, IFNAMSIZ);
79552 else
79553diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
79554index 825c608..750ff29 100644
79555--- a/net/ipv4/fib_frontend.c
79556+++ b/net/ipv4/fib_frontend.c
79557@@ -1020,12 +1020,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
79558 #ifdef CONFIG_IP_ROUTE_MULTIPATH
79559 fib_sync_up(dev);
79560 #endif
79561- atomic_inc(&net->ipv4.dev_addr_genid);
79562+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
79563 rt_cache_flush(dev_net(dev));
79564 break;
79565 case NETDEV_DOWN:
79566 fib_del_ifaddr(ifa, NULL);
79567- atomic_inc(&net->ipv4.dev_addr_genid);
79568+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
79569 if (ifa->ifa_dev->ifa_list == NULL) {
79570 /* Last address was deleted from this interface.
79571 * Disable IP.
79572@@ -1061,7 +1061,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
79573 #ifdef CONFIG_IP_ROUTE_MULTIPATH
79574 fib_sync_up(dev);
79575 #endif
79576- atomic_inc(&net->ipv4.dev_addr_genid);
79577+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
79578 rt_cache_flush(net);
79579 break;
79580 case NETDEV_DOWN:
79581diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
79582index 71b125c..f4c70b0 100644
79583--- a/net/ipv4/fib_semantics.c
79584+++ b/net/ipv4/fib_semantics.c
79585@@ -767,7 +767,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
79586 nh->nh_saddr = inet_select_addr(nh->nh_dev,
79587 nh->nh_gw,
79588 nh->nh_parent->fib_scope);
79589- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
79590+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
79591
79592 return nh->nh_saddr;
79593 }
79594diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
79595index 7880af9..70f92a3 100644
79596--- a/net/ipv4/inet_hashtables.c
79597+++ b/net/ipv4/inet_hashtables.c
79598@@ -18,12 +18,15 @@
79599 #include <linux/sched.h>
79600 #include <linux/slab.h>
79601 #include <linux/wait.h>
79602+#include <linux/security.h>
79603
79604 #include <net/inet_connection_sock.h>
79605 #include <net/inet_hashtables.h>
79606 #include <net/secure_seq.h>
79607 #include <net/ip.h>
79608
79609+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
79610+
79611 /*
79612 * Allocate and initialize a new local port bind bucket.
79613 * The bindhash mutex for snum's hash chain must be held here.
79614@@ -530,6 +533,8 @@ ok:
79615 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
79616 spin_unlock(&head->lock);
79617
79618+ gr_update_task_in_ip_table(current, inet_sk(sk));
79619+
79620 if (tw) {
79621 inet_twsk_deschedule(tw, death_row);
79622 while (twrefcnt) {
79623diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
79624index 000e3d2..5472da3 100644
79625--- a/net/ipv4/inetpeer.c
79626+++ b/net/ipv4/inetpeer.c
79627@@ -503,8 +503,8 @@ relookup:
79628 if (p) {
79629 p->daddr = *daddr;
79630 atomic_set(&p->refcnt, 1);
79631- atomic_set(&p->rid, 0);
79632- atomic_set(&p->ip_id_count,
79633+ atomic_set_unchecked(&p->rid, 0);
79634+ atomic_set_unchecked(&p->ip_id_count,
79635 (daddr->family == AF_INET) ?
79636 secure_ip_id(daddr->addr.a4) :
79637 secure_ipv6_id(daddr->addr.a6));
79638diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
79639index 8d5cc75..821fd11 100644
79640--- a/net/ipv4/ip_fragment.c
79641+++ b/net/ipv4/ip_fragment.c
79642@@ -322,7 +322,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
79643 return 0;
79644
79645 start = qp->rid;
79646- end = atomic_inc_return(&peer->rid);
79647+ end = atomic_inc_return_unchecked(&peer->rid);
79648 qp->rid = end;
79649
79650 rc = qp->q.fragments && (end - start) > max;
79651diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
79652index 14bbfcf..644f472 100644
79653--- a/net/ipv4/ip_sockglue.c
79654+++ b/net/ipv4/ip_sockglue.c
79655@@ -1151,7 +1151,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
79656 len = min_t(unsigned int, len, opt->optlen);
79657 if (put_user(len, optlen))
79658 return -EFAULT;
79659- if (copy_to_user(optval, opt->__data, len))
79660+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
79661+ copy_to_user(optval, opt->__data, len))
79662 return -EFAULT;
79663 return 0;
79664 }
79665@@ -1282,7 +1283,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
79666 if (sk->sk_type != SOCK_STREAM)
79667 return -ENOPROTOOPT;
79668
79669- msg.msg_control = optval;
79670+ msg.msg_control = (void __force_kernel *)optval;
79671 msg.msg_controllen = len;
79672 msg.msg_flags = flags;
79673
79674diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
79675index 798358b..73570b7 100644
79676--- a/net/ipv4/ipconfig.c
79677+++ b/net/ipv4/ipconfig.c
79678@@ -321,7 +321,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
79679
79680 mm_segment_t oldfs = get_fs();
79681 set_fs(get_ds());
79682- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
79683+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
79684 set_fs(oldfs);
79685 return res;
79686 }
79687@@ -332,7 +332,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
79688
79689 mm_segment_t oldfs = get_fs();
79690 set_fs(get_ds());
79691- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
79692+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
79693 set_fs(oldfs);
79694 return res;
79695 }
79696@@ -343,7 +343,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
79697
79698 mm_segment_t oldfs = get_fs();
79699 set_fs(get_ds());
79700- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
79701+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
79702 set_fs(oldfs);
79703 return res;
79704 }
79705diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
79706index 97e61ea..cac1bbb 100644
79707--- a/net/ipv4/netfilter/arp_tables.c
79708+++ b/net/ipv4/netfilter/arp_tables.c
79709@@ -879,14 +879,14 @@ static int compat_table_info(const struct xt_table_info *info,
79710 #endif
79711
79712 static int get_info(struct net *net, void __user *user,
79713- const int *len, int compat)
79714+ int len, int compat)
79715 {
79716 char name[XT_TABLE_MAXNAMELEN];
79717 struct xt_table *t;
79718 int ret;
79719
79720- if (*len != sizeof(struct arpt_getinfo)) {
79721- duprintf("length %u != %Zu\n", *len,
79722+ if (len != sizeof(struct arpt_getinfo)) {
79723+ duprintf("length %u != %Zu\n", len,
79724 sizeof(struct arpt_getinfo));
79725 return -EINVAL;
79726 }
79727@@ -923,7 +923,7 @@ static int get_info(struct net *net, void __user *user,
79728 info.size = private->size;
79729 strcpy(info.name, name);
79730
79731- if (copy_to_user(user, &info, *len) != 0)
79732+ if (copy_to_user(user, &info, len) != 0)
79733 ret = -EFAULT;
79734 else
79735 ret = 0;
79736@@ -1682,7 +1682,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
79737
79738 switch (cmd) {
79739 case ARPT_SO_GET_INFO:
79740- ret = get_info(sock_net(sk), user, len, 1);
79741+ ret = get_info(sock_net(sk), user, *len, 1);
79742 break;
79743 case ARPT_SO_GET_ENTRIES:
79744 ret = compat_get_entries(sock_net(sk), user, len);
79745@@ -1727,7 +1727,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
79746
79747 switch (cmd) {
79748 case ARPT_SO_GET_INFO:
79749- ret = get_info(sock_net(sk), user, len, 0);
79750+ ret = get_info(sock_net(sk), user, *len, 0);
79751 break;
79752
79753 case ARPT_SO_GET_ENTRIES:
79754diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
79755index 170b1fd..6105b91 100644
79756--- a/net/ipv4/netfilter/ip_tables.c
79757+++ b/net/ipv4/netfilter/ip_tables.c
79758@@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
79759 #endif
79760
79761 static int get_info(struct net *net, void __user *user,
79762- const int *len, int compat)
79763+ int len, int compat)
79764 {
79765 char name[XT_TABLE_MAXNAMELEN];
79766 struct xt_table *t;
79767 int ret;
79768
79769- if (*len != sizeof(struct ipt_getinfo)) {
79770- duprintf("length %u != %zu\n", *len,
79771+ if (len != sizeof(struct ipt_getinfo)) {
79772+ duprintf("length %u != %zu\n", len,
79773 sizeof(struct ipt_getinfo));
79774 return -EINVAL;
79775 }
79776@@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
79777 info.size = private->size;
79778 strcpy(info.name, name);
79779
79780- if (copy_to_user(user, &info, *len) != 0)
79781+ if (copy_to_user(user, &info, len) != 0)
79782 ret = -EFAULT;
79783 else
79784 ret = 0;
79785@@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
79786
79787 switch (cmd) {
79788 case IPT_SO_GET_INFO:
79789- ret = get_info(sock_net(sk), user, len, 1);
79790+ ret = get_info(sock_net(sk), user, *len, 1);
79791 break;
79792 case IPT_SO_GET_ENTRIES:
79793 ret = compat_get_entries(sock_net(sk), user, len);
79794@@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
79795
79796 switch (cmd) {
79797 case IPT_SO_GET_INFO:
79798- ret = get_info(sock_net(sk), user, len, 0);
79799+ ret = get_info(sock_net(sk), user, *len, 0);
79800 break;
79801
79802 case IPT_SO_GET_ENTRIES:
79803diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
79804index 8f3d054..c58d05d 100644
79805--- a/net/ipv4/ping.c
79806+++ b/net/ipv4/ping.c
79807@@ -843,7 +843,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
79808 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
79809 0, sock_i_ino(sp),
79810 atomic_read(&sp->sk_refcnt), sp,
79811- atomic_read(&sp->sk_drops), len);
79812+ atomic_read_unchecked(&sp->sk_drops), len);
79813 }
79814
79815 static int ping_seq_show(struct seq_file *seq, void *v)
79816diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
79817index 73d1e4d..3af0e8f 100644
79818--- a/net/ipv4/raw.c
79819+++ b/net/ipv4/raw.c
79820@@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
79821 int raw_rcv(struct sock *sk, struct sk_buff *skb)
79822 {
79823 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
79824- atomic_inc(&sk->sk_drops);
79825+ atomic_inc_unchecked(&sk->sk_drops);
79826 kfree_skb(skb);
79827 return NET_RX_DROP;
79828 }
79829@@ -747,16 +747,20 @@ static int raw_init(struct sock *sk)
79830
79831 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
79832 {
79833+ struct icmp_filter filter;
79834+
79835 if (optlen > sizeof(struct icmp_filter))
79836 optlen = sizeof(struct icmp_filter);
79837- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
79838+ if (copy_from_user(&filter, optval, optlen))
79839 return -EFAULT;
79840+ raw_sk(sk)->filter = filter;
79841 return 0;
79842 }
79843
79844 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
79845 {
79846 int len, ret = -EFAULT;
79847+ struct icmp_filter filter;
79848
79849 if (get_user(len, optlen))
79850 goto out;
79851@@ -766,8 +770,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
79852 if (len > sizeof(struct icmp_filter))
79853 len = sizeof(struct icmp_filter);
79854 ret = -EFAULT;
79855- if (put_user(len, optlen) ||
79856- copy_to_user(optval, &raw_sk(sk)->filter, len))
79857+ filter = raw_sk(sk)->filter;
79858+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
79859 goto out;
79860 ret = 0;
79861 out: return ret;
79862@@ -997,7 +1001,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
79863 0, 0L, 0,
79864 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
79865 0, sock_i_ino(sp),
79866- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
79867+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
79868 }
79869
79870 static int raw_seq_show(struct seq_file *seq, void *v)
79871diff --git a/net/ipv4/route.c b/net/ipv4/route.c
79872index df25142..e92a82a 100644
79873--- a/net/ipv4/route.c
79874+++ b/net/ipv4/route.c
79875@@ -2529,7 +2529,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
79876
79877 static __net_init int rt_genid_init(struct net *net)
79878 {
79879- atomic_set(&net->rt_genid, 0);
79880+ atomic_set_unchecked(&net->rt_genid, 0);
79881 get_random_bytes(&net->ipv4.dev_addr_genid,
79882 sizeof(net->ipv4.dev_addr_genid));
79883 return 0;
79884diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
79885index 181fc82..cc95f8c 100644
79886--- a/net/ipv4/tcp_input.c
79887+++ b/net/ipv4/tcp_input.c
79888@@ -4704,7 +4704,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
79889 * simplifies code)
79890 */
79891 static void
79892-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
79893+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
79894 struct sk_buff *head, struct sk_buff *tail,
79895 u32 start, u32 end)
79896 {
79897@@ -5536,6 +5536,9 @@ slow_path:
79898 if (len < (th->doff << 2) || tcp_checksum_complete_user(sk, skb))
79899 goto csum_error;
79900
79901+ if (!th->ack)
79902+ goto discard;
79903+
79904 /*
79905 * Standard slow path.
79906 */
79907@@ -5544,7 +5547,7 @@ slow_path:
79908 return 0;
79909
79910 step5:
79911- if (th->ack && tcp_ack(sk, skb, FLAG_SLOWPATH) < 0)
79912+ if (tcp_ack(sk, skb, FLAG_SLOWPATH) < 0)
79913 goto discard;
79914
79915 /* ts_recent update must be made after we are sure that the packet
79916@@ -5836,6 +5839,7 @@ discard:
79917 tcp_paws_reject(&tp->rx_opt, 0))
79918 goto discard_and_undo;
79919
79920+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
79921 if (th->syn) {
79922 /* We see SYN without ACK. It is attempt of
79923 * simultaneous connect with crossed SYNs.
79924@@ -5886,6 +5890,7 @@ discard:
79925 goto discard;
79926 #endif
79927 }
79928+#endif
79929 /* "fifth, if neither of the SYN or RST bits is set then
79930 * drop the segment and return."
79931 */
79932@@ -5930,7 +5935,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
79933 goto discard;
79934
79935 if (th->syn) {
79936- if (th->fin)
79937+ if (th->fin || th->urg || th->psh)
79938 goto discard;
79939 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
79940 return 1;
79941@@ -5977,11 +5982,15 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
79942 if (tcp_check_req(sk, skb, req, NULL, true) == NULL)
79943 goto discard;
79944 }
79945+
79946+ if (!th->ack)
79947+ goto discard;
79948+
79949 if (!tcp_validate_incoming(sk, skb, th, 0))
79950 return 0;
79951
79952 /* step 5: check the ACK field */
79953- if (th->ack) {
79954+ if (true) {
79955 int acceptable = tcp_ack(sk, skb, FLAG_SLOWPATH) > 0;
79956
79957 switch (sk->sk_state) {
79958@@ -6131,8 +6140,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
79959 }
79960 break;
79961 }
79962- } else
79963- goto discard;
79964+ }
79965
79966 /* ts_recent update must be made after we are sure that the packet
79967 * is in window.
79968diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
79969index bc3cb46..815ccd6 100644
79970--- a/net/ipv4/tcp_ipv4.c
79971+++ b/net/ipv4/tcp_ipv4.c
79972@@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
79973 EXPORT_SYMBOL(sysctl_tcp_low_latency);
79974
79975
79976+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79977+extern int grsec_enable_blackhole;
79978+#endif
79979+
79980 #ifdef CONFIG_TCP_MD5SIG
79981 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
79982 __be32 daddr, __be32 saddr, const struct tcphdr *th);
79983@@ -1899,6 +1903,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
79984 return 0;
79985
79986 reset:
79987+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79988+ if (!grsec_enable_blackhole)
79989+#endif
79990 tcp_v4_send_reset(rsk, skb);
79991 discard:
79992 kfree_skb(skb);
79993@@ -1999,12 +2006,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
79994 TCP_SKB_CB(skb)->sacked = 0;
79995
79996 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
79997- if (!sk)
79998+ if (!sk) {
79999+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80000+ ret = 1;
80001+#endif
80002 goto no_tcp_socket;
80003-
80004+ }
80005 process:
80006- if (sk->sk_state == TCP_TIME_WAIT)
80007+ if (sk->sk_state == TCP_TIME_WAIT) {
80008+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80009+ ret = 2;
80010+#endif
80011 goto do_time_wait;
80012+ }
80013
80014 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
80015 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
80016@@ -2055,6 +2069,10 @@ no_tcp_socket:
80017 bad_packet:
80018 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
80019 } else {
80020+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80021+ if (!grsec_enable_blackhole || (ret == 1 &&
80022+ (skb->dev->flags & IFF_LOOPBACK)))
80023+#endif
80024 tcp_v4_send_reset(NULL, skb);
80025 }
80026
80027diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
80028index a7302d9..e3ec754 100644
80029--- a/net/ipv4/tcp_minisocks.c
80030+++ b/net/ipv4/tcp_minisocks.c
80031@@ -27,6 +27,10 @@
80032 #include <net/inet_common.h>
80033 #include <net/xfrm.h>
80034
80035+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80036+extern int grsec_enable_blackhole;
80037+#endif
80038+
80039 int sysctl_tcp_syncookies __read_mostly = 1;
80040 EXPORT_SYMBOL(sysctl_tcp_syncookies);
80041
80042@@ -742,7 +746,10 @@ embryonic_reset:
80043 * avoid becoming vulnerable to outside attack aiming at
80044 * resetting legit local connections.
80045 */
80046- req->rsk_ops->send_reset(sk, skb);
80047+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80048+ if (!grsec_enable_blackhole)
80049+#endif
80050+ req->rsk_ops->send_reset(sk, skb);
80051 } else if (fastopen) { /* received a valid RST pkt */
80052 reqsk_fastopen_remove(sk, req, true);
80053 tcp_reset(sk);
80054diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
80055index 4526fe6..1a34e43 100644
80056--- a/net/ipv4/tcp_probe.c
80057+++ b/net/ipv4/tcp_probe.c
80058@@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
80059 if (cnt + width >= len)
80060 break;
80061
80062- if (copy_to_user(buf + cnt, tbuf, width))
80063+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
80064 return -EFAULT;
80065 cnt += width;
80066 }
80067diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
80068index d47c1b4..b0584de 100644
80069--- a/net/ipv4/tcp_timer.c
80070+++ b/net/ipv4/tcp_timer.c
80071@@ -22,6 +22,10 @@
80072 #include <linux/gfp.h>
80073 #include <net/tcp.h>
80074
80075+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80076+extern int grsec_lastack_retries;
80077+#endif
80078+
80079 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
80080 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
80081 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
80082@@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
80083 }
80084 }
80085
80086+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80087+ if ((sk->sk_state == TCP_LAST_ACK) &&
80088+ (grsec_lastack_retries > 0) &&
80089+ (grsec_lastack_retries < retry_until))
80090+ retry_until = grsec_lastack_retries;
80091+#endif
80092+
80093 if (retransmits_timed_out(sk, retry_until,
80094 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
80095 /* Has it gone just too far? */
80096diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
80097index 79c8dbe..aceb1b6 100644
80098--- a/net/ipv4/udp.c
80099+++ b/net/ipv4/udp.c
80100@@ -87,6 +87,7 @@
80101 #include <linux/types.h>
80102 #include <linux/fcntl.h>
80103 #include <linux/module.h>
80104+#include <linux/security.h>
80105 #include <linux/socket.h>
80106 #include <linux/sockios.h>
80107 #include <linux/igmp.h>
80108@@ -111,6 +112,10 @@
80109 #include <trace/events/skb.h>
80110 #include "udp_impl.h"
80111
80112+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80113+extern int grsec_enable_blackhole;
80114+#endif
80115+
80116 struct udp_table udp_table __read_mostly;
80117 EXPORT_SYMBOL(udp_table);
80118
80119@@ -569,6 +574,9 @@ found:
80120 return s;
80121 }
80122
80123+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
80124+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
80125+
80126 /*
80127 * This routine is called by the ICMP module when it gets some
80128 * sort of error condition. If err < 0 then the socket should
80129@@ -864,9 +872,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
80130 dport = usin->sin_port;
80131 if (dport == 0)
80132 return -EINVAL;
80133+
80134+ err = gr_search_udp_sendmsg(sk, usin);
80135+ if (err)
80136+ return err;
80137 } else {
80138 if (sk->sk_state != TCP_ESTABLISHED)
80139 return -EDESTADDRREQ;
80140+
80141+ err = gr_search_udp_sendmsg(sk, NULL);
80142+ if (err)
80143+ return err;
80144+
80145 daddr = inet->inet_daddr;
80146 dport = inet->inet_dport;
80147 /* Open fast path for connected socket.
80148@@ -1108,7 +1125,7 @@ static unsigned int first_packet_length(struct sock *sk)
80149 udp_lib_checksum_complete(skb)) {
80150 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
80151 IS_UDPLITE(sk));
80152- atomic_inc(&sk->sk_drops);
80153+ atomic_inc_unchecked(&sk->sk_drops);
80154 __skb_unlink(skb, rcvq);
80155 __skb_queue_tail(&list_kill, skb);
80156 }
80157@@ -1194,6 +1211,10 @@ try_again:
80158 if (!skb)
80159 goto out;
80160
80161+ err = gr_search_udp_recvmsg(sk, skb);
80162+ if (err)
80163+ goto out_free;
80164+
80165 ulen = skb->len - sizeof(struct udphdr);
80166 copied = len;
80167 if (copied > ulen)
80168@@ -1227,7 +1248,7 @@ try_again:
80169 if (unlikely(err)) {
80170 trace_kfree_skb(skb, udp_recvmsg);
80171 if (!peeked) {
80172- atomic_inc(&sk->sk_drops);
80173+ atomic_inc_unchecked(&sk->sk_drops);
80174 UDP_INC_STATS_USER(sock_net(sk),
80175 UDP_MIB_INERRORS, is_udplite);
80176 }
80177@@ -1510,7 +1531,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
80178
80179 drop:
80180 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
80181- atomic_inc(&sk->sk_drops);
80182+ atomic_inc_unchecked(&sk->sk_drops);
80183 kfree_skb(skb);
80184 return -1;
80185 }
80186@@ -1529,7 +1550,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
80187 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
80188
80189 if (!skb1) {
80190- atomic_inc(&sk->sk_drops);
80191+ atomic_inc_unchecked(&sk->sk_drops);
80192 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
80193 IS_UDPLITE(sk));
80194 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
80195@@ -1698,6 +1719,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
80196 goto csum_error;
80197
80198 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
80199+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80200+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
80201+#endif
80202 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
80203
80204 /*
80205@@ -2119,7 +2143,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
80206 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
80207 0, sock_i_ino(sp),
80208 atomic_read(&sp->sk_refcnt), sp,
80209- atomic_read(&sp->sk_drops), len);
80210+ atomic_read_unchecked(&sp->sk_drops), len);
80211 }
80212
80213 int udp4_seq_show(struct seq_file *seq, void *v)
80214diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
80215index 0424e4e..308dd43 100644
80216--- a/net/ipv6/addrconf.c
80217+++ b/net/ipv6/addrconf.c
80218@@ -2121,7 +2121,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
80219 p.iph.ihl = 5;
80220 p.iph.protocol = IPPROTO_IPV6;
80221 p.iph.ttl = 64;
80222- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
80223+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
80224
80225 if (ops->ndo_do_ioctl) {
80226 mm_segment_t oldfs = get_fs();
80227diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
80228index d5cb3c4..b3e38d0 100644
80229--- a/net/ipv6/ip6_gre.c
80230+++ b/net/ipv6/ip6_gre.c
80231@@ -1353,7 +1353,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
80232 }
80233
80234
80235-static struct inet6_protocol ip6gre_protocol __read_mostly = {
80236+static struct inet6_protocol ip6gre_protocol = {
80237 .handler = ip6gre_rcv,
80238 .err_handler = ip6gre_err,
80239 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
80240diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
80241index e02faed..9780f28 100644
80242--- a/net/ipv6/ipv6_sockglue.c
80243+++ b/net/ipv6/ipv6_sockglue.c
80244@@ -990,7 +990,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
80245 if (sk->sk_type != SOCK_STREAM)
80246 return -ENOPROTOOPT;
80247
80248- msg.msg_control = optval;
80249+ msg.msg_control = (void __force_kernel *)optval;
80250 msg.msg_controllen = len;
80251 msg.msg_flags = flags;
80252
80253diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
80254index d7cb045..8c0ded6 100644
80255--- a/net/ipv6/netfilter/ip6_tables.c
80256+++ b/net/ipv6/netfilter/ip6_tables.c
80257@@ -1078,14 +1078,14 @@ static int compat_table_info(const struct xt_table_info *info,
80258 #endif
80259
80260 static int get_info(struct net *net, void __user *user,
80261- const int *len, int compat)
80262+ int len, int compat)
80263 {
80264 char name[XT_TABLE_MAXNAMELEN];
80265 struct xt_table *t;
80266 int ret;
80267
80268- if (*len != sizeof(struct ip6t_getinfo)) {
80269- duprintf("length %u != %zu\n", *len,
80270+ if (len != sizeof(struct ip6t_getinfo)) {
80271+ duprintf("length %u != %zu\n", len,
80272 sizeof(struct ip6t_getinfo));
80273 return -EINVAL;
80274 }
80275@@ -1122,7 +1122,7 @@ static int get_info(struct net *net, void __user *user,
80276 info.size = private->size;
80277 strcpy(info.name, name);
80278
80279- if (copy_to_user(user, &info, *len) != 0)
80280+ if (copy_to_user(user, &info, len) != 0)
80281 ret = -EFAULT;
80282 else
80283 ret = 0;
80284@@ -1976,7 +1976,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
80285
80286 switch (cmd) {
80287 case IP6T_SO_GET_INFO:
80288- ret = get_info(sock_net(sk), user, len, 1);
80289+ ret = get_info(sock_net(sk), user, *len, 1);
80290 break;
80291 case IP6T_SO_GET_ENTRIES:
80292 ret = compat_get_entries(sock_net(sk), user, len);
80293@@ -2023,7 +2023,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
80294
80295 switch (cmd) {
80296 case IP6T_SO_GET_INFO:
80297- ret = get_info(sock_net(sk), user, len, 0);
80298+ ret = get_info(sock_net(sk), user, *len, 0);
80299 break;
80300
80301 case IP6T_SO_GET_ENTRIES:
80302diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
80303index d8e95c7..81422bc 100644
80304--- a/net/ipv6/raw.c
80305+++ b/net/ipv6/raw.c
80306@@ -379,7 +379,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
80307 {
80308 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
80309 skb_checksum_complete(skb)) {
80310- atomic_inc(&sk->sk_drops);
80311+ atomic_inc_unchecked(&sk->sk_drops);
80312 kfree_skb(skb);
80313 return NET_RX_DROP;
80314 }
80315@@ -407,7 +407,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
80316 struct raw6_sock *rp = raw6_sk(sk);
80317
80318 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
80319- atomic_inc(&sk->sk_drops);
80320+ atomic_inc_unchecked(&sk->sk_drops);
80321 kfree_skb(skb);
80322 return NET_RX_DROP;
80323 }
80324@@ -431,7 +431,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
80325
80326 if (inet->hdrincl) {
80327 if (skb_checksum_complete(skb)) {
80328- atomic_inc(&sk->sk_drops);
80329+ atomic_inc_unchecked(&sk->sk_drops);
80330 kfree_skb(skb);
80331 return NET_RX_DROP;
80332 }
80333@@ -604,7 +604,7 @@ out:
80334 return err;
80335 }
80336
80337-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
80338+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
80339 struct flowi6 *fl6, struct dst_entry **dstp,
80340 unsigned int flags)
80341 {
80342@@ -916,12 +916,15 @@ do_confirm:
80343 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
80344 char __user *optval, int optlen)
80345 {
80346+ struct icmp6_filter filter;
80347+
80348 switch (optname) {
80349 case ICMPV6_FILTER:
80350 if (optlen > sizeof(struct icmp6_filter))
80351 optlen = sizeof(struct icmp6_filter);
80352- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
80353+ if (copy_from_user(&filter, optval, optlen))
80354 return -EFAULT;
80355+ raw6_sk(sk)->filter = filter;
80356 return 0;
80357 default:
80358 return -ENOPROTOOPT;
80359@@ -934,6 +937,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
80360 char __user *optval, int __user *optlen)
80361 {
80362 int len;
80363+ struct icmp6_filter filter;
80364
80365 switch (optname) {
80366 case ICMPV6_FILTER:
80367@@ -945,7 +949,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
80368 len = sizeof(struct icmp6_filter);
80369 if (put_user(len, optlen))
80370 return -EFAULT;
80371- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
80372+ filter = raw6_sk(sk)->filter;
80373+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
80374 return -EFAULT;
80375 return 0;
80376 default:
80377@@ -1253,7 +1258,7 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
80378 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
80379 0,
80380 sock_i_ino(sp),
80381- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
80382+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
80383 }
80384
80385 static int raw6_seq_show(struct seq_file *seq, void *v)
80386diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
80387index 73f2a6b..f8049a1 100644
80388--- a/net/ipv6/tcp_ipv6.c
80389+++ b/net/ipv6/tcp_ipv6.c
80390@@ -106,6 +106,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
80391 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
80392 }
80393
80394+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80395+extern int grsec_enable_blackhole;
80396+#endif
80397+
80398 static void tcp_v6_hash(struct sock *sk)
80399 {
80400 if (sk->sk_state != TCP_CLOSE) {
80401@@ -1525,6 +1529,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
80402 return 0;
80403
80404 reset:
80405+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80406+ if (!grsec_enable_blackhole)
80407+#endif
80408 tcp_v6_send_reset(sk, skb);
80409 discard:
80410 if (opt_skb)
80411@@ -1606,12 +1613,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
80412 TCP_SKB_CB(skb)->sacked = 0;
80413
80414 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
80415- if (!sk)
80416+ if (!sk) {
80417+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80418+ ret = 1;
80419+#endif
80420 goto no_tcp_socket;
80421+ }
80422
80423 process:
80424- if (sk->sk_state == TCP_TIME_WAIT)
80425+ if (sk->sk_state == TCP_TIME_WAIT) {
80426+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80427+ ret = 2;
80428+#endif
80429 goto do_time_wait;
80430+ }
80431
80432 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
80433 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
80434@@ -1660,6 +1675,10 @@ no_tcp_socket:
80435 bad_packet:
80436 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
80437 } else {
80438+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80439+ if (!grsec_enable_blackhole || (ret == 1 &&
80440+ (skb->dev->flags & IFF_LOOPBACK)))
80441+#endif
80442 tcp_v6_send_reset(NULL, skb);
80443 }
80444
80445diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
80446index fc99972..69397e8 100644
80447--- a/net/ipv6/udp.c
80448+++ b/net/ipv6/udp.c
80449@@ -51,6 +51,10 @@
80450 #include <trace/events/skb.h>
80451 #include "udp_impl.h"
80452
80453+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80454+extern int grsec_enable_blackhole;
80455+#endif
80456+
80457 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
80458 {
80459 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
80460@@ -395,7 +399,7 @@ try_again:
80461 if (unlikely(err)) {
80462 trace_kfree_skb(skb, udpv6_recvmsg);
80463 if (!peeked) {
80464- atomic_inc(&sk->sk_drops);
80465+ atomic_inc_unchecked(&sk->sk_drops);
80466 if (is_udp4)
80467 UDP_INC_STATS_USER(sock_net(sk),
80468 UDP_MIB_INERRORS,
80469@@ -633,7 +637,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
80470 return rc;
80471 drop:
80472 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
80473- atomic_inc(&sk->sk_drops);
80474+ atomic_inc_unchecked(&sk->sk_drops);
80475 kfree_skb(skb);
80476 return -1;
80477 }
80478@@ -691,7 +695,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
80479 if (likely(skb1 == NULL))
80480 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
80481 if (!skb1) {
80482- atomic_inc(&sk->sk_drops);
80483+ atomic_inc_unchecked(&sk->sk_drops);
80484 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
80485 IS_UDPLITE(sk));
80486 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
80487@@ -862,6 +866,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
80488 goto discard;
80489
80490 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
80491+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80492+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
80493+#endif
80494 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
80495
80496 kfree_skb(skb);
80497@@ -1473,7 +1480,7 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
80498 0,
80499 sock_i_ino(sp),
80500 atomic_read(&sp->sk_refcnt), sp,
80501- atomic_read(&sp->sk_drops));
80502+ atomic_read_unchecked(&sp->sk_drops));
80503 }
80504
80505 int udp6_seq_show(struct seq_file *seq, void *v)
80506diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
80507index 496ce2c..f79fac8 100644
80508--- a/net/irda/ircomm/ircomm_tty.c
80509+++ b/net/irda/ircomm/ircomm_tty.c
80510@@ -311,12 +311,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
80511 add_wait_queue(&port->open_wait, &wait);
80512
80513 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
80514- __FILE__, __LINE__, tty->driver->name, port->count);
80515+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
80516
80517 spin_lock_irqsave(&port->lock, flags);
80518 if (!tty_hung_up_p(filp)) {
80519 extra_count = 1;
80520- port->count--;
80521+ atomic_dec(&port->count);
80522 }
80523 spin_unlock_irqrestore(&port->lock, flags);
80524 port->blocked_open++;
80525@@ -352,7 +352,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
80526 }
80527
80528 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
80529- __FILE__, __LINE__, tty->driver->name, port->count);
80530+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
80531
80532 schedule();
80533 }
80534@@ -363,13 +363,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
80535 if (extra_count) {
80536 /* ++ is not atomic, so this should be protected - Jean II */
80537 spin_lock_irqsave(&port->lock, flags);
80538- port->count++;
80539+ atomic_inc(&port->count);
80540 spin_unlock_irqrestore(&port->lock, flags);
80541 }
80542 port->blocked_open--;
80543
80544 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
80545- __FILE__, __LINE__, tty->driver->name, port->count);
80546+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
80547
80548 if (!retval)
80549 port->flags |= ASYNC_NORMAL_ACTIVE;
80550@@ -443,12 +443,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
80551
80552 /* ++ is not atomic, so this should be protected - Jean II */
80553 spin_lock_irqsave(&self->port.lock, flags);
80554- self->port.count++;
80555+ atomic_inc(&self->port.count);
80556 spin_unlock_irqrestore(&self->port.lock, flags);
80557 tty_port_tty_set(&self->port, tty);
80558
80559 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
80560- self->line, self->port.count);
80561+ self->line, atomic_read(&self->port.count));
80562
80563 /* Not really used by us, but lets do it anyway */
80564 tty->low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
80565@@ -985,7 +985,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
80566 tty_kref_put(port->tty);
80567 }
80568 port->tty = NULL;
80569- port->count = 0;
80570+ atomic_set(&port->count, 0);
80571 spin_unlock_irqrestore(&port->lock, flags);
80572
80573 wake_up_interruptible(&port->open_wait);
80574@@ -1342,7 +1342,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
80575 seq_putc(m, '\n');
80576
80577 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
80578- seq_printf(m, "Open count: %d\n", self->port.count);
80579+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
80580 seq_printf(m, "Max data size: %d\n", self->max_data_size);
80581 seq_printf(m, "Max header size: %d\n", self->max_header_size);
80582
80583diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
80584index cd6f7a9..e63fe89 100644
80585--- a/net/iucv/af_iucv.c
80586+++ b/net/iucv/af_iucv.c
80587@@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
80588
80589 write_lock_bh(&iucv_sk_list.lock);
80590
80591- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
80592+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
80593 while (__iucv_get_sock_by_name(name)) {
80594 sprintf(name, "%08x",
80595- atomic_inc_return(&iucv_sk_list.autobind_name));
80596+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
80597 }
80598
80599 write_unlock_bh(&iucv_sk_list.lock);
80600diff --git a/net/key/af_key.c b/net/key/af_key.c
80601index 08897a3..0b812ab 100644
80602--- a/net/key/af_key.c
80603+++ b/net/key/af_key.c
80604@@ -3019,10 +3019,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
80605 static u32 get_acqseq(void)
80606 {
80607 u32 res;
80608- static atomic_t acqseq;
80609+ static atomic_unchecked_t acqseq;
80610
80611 do {
80612- res = atomic_inc_return(&acqseq);
80613+ res = atomic_inc_return_unchecked(&acqseq);
80614 } while (!res);
80615 return res;
80616 }
80617diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
80618index 494da7f..6ce2ffd 100644
80619--- a/net/mac80211/cfg.c
80620+++ b/net/mac80211/cfg.c
80621@@ -2604,7 +2604,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
80622 else
80623 local->probe_req_reg--;
80624
80625- if (!local->open_count)
80626+ if (!local_read(&local->open_count))
80627 break;
80628
80629 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
80630diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
80631index 493e2e8..be76574 100644
80632--- a/net/mac80211/ieee80211_i.h
80633+++ b/net/mac80211/ieee80211_i.h
80634@@ -28,6 +28,7 @@
80635 #include <net/ieee80211_radiotap.h>
80636 #include <net/cfg80211.h>
80637 #include <net/mac80211.h>
80638+#include <asm/local.h>
80639 #include "key.h"
80640 #include "sta_info.h"
80641 #include "debug.h"
80642@@ -852,7 +853,7 @@ struct ieee80211_local {
80643 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
80644 spinlock_t queue_stop_reason_lock;
80645
80646- int open_count;
80647+ local_t open_count;
80648 int monitors, cooked_mntrs;
80649 /* number of interfaces with corresponding FIF_ flags */
80650 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
80651diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
80652index 0f5af91..4dba9e7 100644
80653--- a/net/mac80211/iface.c
80654+++ b/net/mac80211/iface.c
80655@@ -465,7 +465,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
80656 break;
80657 }
80658
80659- if (local->open_count == 0) {
80660+ if (local_read(&local->open_count) == 0) {
80661 res = drv_start(local);
80662 if (res)
80663 goto err_del_bss;
80664@@ -508,7 +508,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
80665 break;
80666 }
80667
80668- if (local->monitors == 0 && local->open_count == 0) {
80669+ if (local->monitors == 0 && local_read(&local->open_count) == 0) {
80670 res = ieee80211_add_virtual_monitor(local);
80671 if (res)
80672 goto err_stop;
80673@@ -616,7 +616,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
80674 mutex_unlock(&local->mtx);
80675
80676 if (coming_up)
80677- local->open_count++;
80678+ local_inc(&local->open_count);
80679
80680 if (hw_reconf_flags)
80681 ieee80211_hw_config(local, hw_reconf_flags);
80682@@ -630,7 +630,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
80683 err_del_interface:
80684 drv_remove_interface(local, sdata);
80685 err_stop:
80686- if (!local->open_count)
80687+ if (!local_read(&local->open_count))
80688 drv_stop(local);
80689 err_del_bss:
80690 sdata->bss = NULL;
80691@@ -762,7 +762,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
80692 }
80693
80694 if (going_down)
80695- local->open_count--;
80696+ local_dec(&local->open_count);
80697
80698 switch (sdata->vif.type) {
80699 case NL80211_IFTYPE_AP_VLAN:
80700@@ -818,7 +818,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
80701
80702 ieee80211_recalc_ps(local, -1);
80703
80704- if (local->open_count == 0) {
80705+ if (local_read(&local->open_count) == 0) {
80706 if (local->ops->napi_poll)
80707 napi_disable(&local->napi);
80708 ieee80211_clear_tx_pending(local);
80709@@ -850,7 +850,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
80710 }
80711 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
80712
80713- if (local->monitors == local->open_count && local->monitors > 0)
80714+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
80715 ieee80211_add_virtual_monitor(local);
80716 }
80717
80718diff --git a/net/mac80211/main.c b/net/mac80211/main.c
80719index f57f597..e0a7c03 100644
80720--- a/net/mac80211/main.c
80721+++ b/net/mac80211/main.c
80722@@ -164,7 +164,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
80723 local->hw.conf.power_level = power;
80724 }
80725
80726- if (changed && local->open_count) {
80727+ if (changed && local_read(&local->open_count)) {
80728 ret = drv_config(local, changed);
80729 /*
80730 * Goal:
80731diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
80732index 5c572e7..ecf75ce 100644
80733--- a/net/mac80211/pm.c
80734+++ b/net/mac80211/pm.c
80735@@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
80736 struct ieee80211_sub_if_data *sdata;
80737 struct sta_info *sta;
80738
80739- if (!local->open_count)
80740+ if (!local_read(&local->open_count))
80741 goto suspend;
80742
80743 ieee80211_scan_cancel(local);
80744@@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
80745 cancel_work_sync(&local->dynamic_ps_enable_work);
80746 del_timer_sync(&local->dynamic_ps_timer);
80747
80748- local->wowlan = wowlan && local->open_count;
80749+ local->wowlan = wowlan && local_read(&local->open_count);
80750 if (local->wowlan) {
80751 int err = drv_suspend(local, wowlan);
80752 if (err < 0) {
80753@@ -143,7 +143,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
80754 drv_remove_interface(local, sdata);
80755
80756 /* stop hardware - this must stop RX */
80757- if (local->open_count)
80758+ if (local_read(&local->open_count))
80759 ieee80211_stop_device(local);
80760
80761 suspend:
80762diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
80763index 3313c11..bec9f17 100644
80764--- a/net/mac80211/rate.c
80765+++ b/net/mac80211/rate.c
80766@@ -494,7 +494,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
80767
80768 ASSERT_RTNL();
80769
80770- if (local->open_count)
80771+ if (local_read(&local->open_count))
80772 return -EBUSY;
80773
80774 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
80775diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
80776index c97a065..ff61928 100644
80777--- a/net/mac80211/rc80211_pid_debugfs.c
80778+++ b/net/mac80211/rc80211_pid_debugfs.c
80779@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
80780
80781 spin_unlock_irqrestore(&events->lock, status);
80782
80783- if (copy_to_user(buf, pb, p))
80784+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
80785 return -EFAULT;
80786
80787 return p;
80788diff --git a/net/mac80211/util.c b/net/mac80211/util.c
80789index 0151ae3..26709d3 100644
80790--- a/net/mac80211/util.c
80791+++ b/net/mac80211/util.c
80792@@ -1332,7 +1332,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
80793 }
80794 #endif
80795 /* everything else happens only if HW was up & running */
80796- if (!local->open_count)
80797+ if (!local_read(&local->open_count))
80798 goto wake_up;
80799
80800 /*
80801diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
80802index 49e96df..63a51c3 100644
80803--- a/net/netfilter/Kconfig
80804+++ b/net/netfilter/Kconfig
80805@@ -936,6 +936,16 @@ config NETFILTER_XT_MATCH_ESP
80806
80807 To compile it as a module, choose M here. If unsure, say N.
80808
80809+config NETFILTER_XT_MATCH_GRADM
80810+ tristate '"gradm" match support'
80811+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
80812+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
80813+ ---help---
80814+ The gradm match allows to match on grsecurity RBAC being enabled.
80815+ It is useful when iptables rules are applied early on bootup to
80816+ prevent connections to the machine (except from a trusted host)
80817+ while the RBAC system is disabled.
80818+
80819 config NETFILTER_XT_MATCH_HASHLIMIT
80820 tristate '"hashlimit" match support'
80821 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
80822diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
80823index 3259697..54d5393 100644
80824--- a/net/netfilter/Makefile
80825+++ b/net/netfilter/Makefile
80826@@ -109,6 +109,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
80827 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
80828 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
80829 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
80830+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
80831 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
80832 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
80833 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
80834diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
80835index 1548df9..98ad9b4 100644
80836--- a/net/netfilter/ipvs/ip_vs_conn.c
80837+++ b/net/netfilter/ipvs/ip_vs_conn.c
80838@@ -557,7 +557,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
80839 /* Increase the refcnt counter of the dest */
80840 atomic_inc(&dest->refcnt);
80841
80842- conn_flags = atomic_read(&dest->conn_flags);
80843+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
80844 if (cp->protocol != IPPROTO_UDP)
80845 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
80846 flags = cp->flags;
80847@@ -902,7 +902,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
80848 atomic_set(&cp->refcnt, 1);
80849
80850 atomic_set(&cp->n_control, 0);
80851- atomic_set(&cp->in_pkts, 0);
80852+ atomic_set_unchecked(&cp->in_pkts, 0);
80853
80854 atomic_inc(&ipvs->conn_count);
80855 if (flags & IP_VS_CONN_F_NO_CPORT)
80856@@ -1183,7 +1183,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
80857
80858 /* Don't drop the entry if its number of incoming packets is not
80859 located in [0, 8] */
80860- i = atomic_read(&cp->in_pkts);
80861+ i = atomic_read_unchecked(&cp->in_pkts);
80862 if (i > 8 || i < 0) return 0;
80863
80864 if (!todrop_rate[i]) return 0;
80865diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
80866index 58918e2..4d177a9 100644
80867--- a/net/netfilter/ipvs/ip_vs_core.c
80868+++ b/net/netfilter/ipvs/ip_vs_core.c
80869@@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
80870 ret = cp->packet_xmit(skb, cp, pd->pp);
80871 /* do not touch skb anymore */
80872
80873- atomic_inc(&cp->in_pkts);
80874+ atomic_inc_unchecked(&cp->in_pkts);
80875 ip_vs_conn_put(cp);
80876 return ret;
80877 }
80878@@ -1681,7 +1681,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
80879 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
80880 pkts = sysctl_sync_threshold(ipvs);
80881 else
80882- pkts = atomic_add_return(1, &cp->in_pkts);
80883+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
80884
80885 if (ipvs->sync_state & IP_VS_STATE_MASTER)
80886 ip_vs_sync_conn(net, cp, pkts);
80887diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
80888index c4ee437..a774a74 100644
80889--- a/net/netfilter/ipvs/ip_vs_ctl.c
80890+++ b/net/netfilter/ipvs/ip_vs_ctl.c
80891@@ -787,7 +787,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
80892 ip_vs_rs_hash(ipvs, dest);
80893 write_unlock_bh(&ipvs->rs_lock);
80894 }
80895- atomic_set(&dest->conn_flags, conn_flags);
80896+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
80897
80898 /* bind the service */
80899 if (!dest->svc) {
80900@@ -2081,7 +2081,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
80901 " %-7s %-6d %-10d %-10d\n",
80902 &dest->addr.in6,
80903 ntohs(dest->port),
80904- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
80905+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
80906 atomic_read(&dest->weight),
80907 atomic_read(&dest->activeconns),
80908 atomic_read(&dest->inactconns));
80909@@ -2092,7 +2092,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
80910 "%-7s %-6d %-10d %-10d\n",
80911 ntohl(dest->addr.ip),
80912 ntohs(dest->port),
80913- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
80914+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
80915 atomic_read(&dest->weight),
80916 atomic_read(&dest->activeconns),
80917 atomic_read(&dest->inactconns));
80918@@ -2562,7 +2562,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
80919
80920 entry.addr = dest->addr.ip;
80921 entry.port = dest->port;
80922- entry.conn_flags = atomic_read(&dest->conn_flags);
80923+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
80924 entry.weight = atomic_read(&dest->weight);
80925 entry.u_threshold = dest->u_threshold;
80926 entry.l_threshold = dest->l_threshold;
80927@@ -3098,7 +3098,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
80928 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
80929 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
80930 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
80931- (atomic_read(&dest->conn_flags) &
80932+ (atomic_read_unchecked(&dest->conn_flags) &
80933 IP_VS_CONN_F_FWD_MASK)) ||
80934 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
80935 atomic_read(&dest->weight)) ||
80936diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
80937index effa10c..9058928 100644
80938--- a/net/netfilter/ipvs/ip_vs_sync.c
80939+++ b/net/netfilter/ipvs/ip_vs_sync.c
80940@@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
80941 cp = cp->control;
80942 if (cp) {
80943 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
80944- pkts = atomic_add_return(1, &cp->in_pkts);
80945+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
80946 else
80947 pkts = sysctl_sync_threshold(ipvs);
80948 ip_vs_sync_conn(net, cp->control, pkts);
80949@@ -758,7 +758,7 @@ control:
80950 if (!cp)
80951 return;
80952 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
80953- pkts = atomic_add_return(1, &cp->in_pkts);
80954+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
80955 else
80956 pkts = sysctl_sync_threshold(ipvs);
80957 goto sloop;
80958@@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
80959
80960 if (opt)
80961 memcpy(&cp->in_seq, opt, sizeof(*opt));
80962- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
80963+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
80964 cp->state = state;
80965 cp->old_state = cp->state;
80966 /*
80967diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
80968index cc4c809..50f8fe5 100644
80969--- a/net/netfilter/ipvs/ip_vs_xmit.c
80970+++ b/net/netfilter/ipvs/ip_vs_xmit.c
80971@@ -1202,7 +1202,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
80972 else
80973 rc = NF_ACCEPT;
80974 /* do not touch skb anymore */
80975- atomic_inc(&cp->in_pkts);
80976+ atomic_inc_unchecked(&cp->in_pkts);
80977 goto out;
80978 }
80979
80980@@ -1323,7 +1323,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
80981 else
80982 rc = NF_ACCEPT;
80983 /* do not touch skb anymore */
80984- atomic_inc(&cp->in_pkts);
80985+ atomic_inc_unchecked(&cp->in_pkts);
80986 goto out;
80987 }
80988
80989diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
80990index ec02168..f0caab6 100644
80991--- a/net/netfilter/nf_conntrack_core.c
80992+++ b/net/netfilter/nf_conntrack_core.c
80993@@ -1533,6 +1533,10 @@ err_extend:
80994 #define UNCONFIRMED_NULLS_VAL ((1<<30)+0)
80995 #define DYING_NULLS_VAL ((1<<30)+1)
80996
80997+#ifdef CONFIG_GRKERNSEC_HIDESYM
80998+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
80999+#endif
81000+
81001 static int nf_conntrack_init_net(struct net *net)
81002 {
81003 int ret;
81004@@ -1546,7 +1550,11 @@ static int nf_conntrack_init_net(struct net *net)
81005 goto err_stat;
81006 }
81007
81008+#ifdef CONFIG_GRKERNSEC_HIDESYM
81009+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
81010+#else
81011 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
81012+#endif
81013 if (!net->ct.slabname) {
81014 ret = -ENOMEM;
81015 goto err_slabname;
81016diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
81017index 92fd8ec..3f6ea4b 100644
81018--- a/net/netfilter/nfnetlink_log.c
81019+++ b/net/netfilter/nfnetlink_log.c
81020@@ -72,7 +72,7 @@ struct nfulnl_instance {
81021 };
81022
81023 static DEFINE_SPINLOCK(instances_lock);
81024-static atomic_t global_seq;
81025+static atomic_unchecked_t global_seq;
81026
81027 #define INSTANCE_BUCKETS 16
81028 static struct hlist_head instance_table[INSTANCE_BUCKETS];
81029@@ -537,7 +537,7 @@ __build_packet_message(struct nfulnl_instance *inst,
81030 /* global sequence number */
81031 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
81032 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
81033- htonl(atomic_inc_return(&global_seq))))
81034+ htonl(atomic_inc_return_unchecked(&global_seq))))
81035 goto nla_put_failure;
81036
81037 if (data_len) {
81038diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
81039new file mode 100644
81040index 0000000..c566332
81041--- /dev/null
81042+++ b/net/netfilter/xt_gradm.c
81043@@ -0,0 +1,51 @@
81044+/*
81045+ * gradm match for netfilter
81046