]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.9.1-3.7.1-201301041854.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.7.1-201301041854.patch
CommitLineData
920a3f04
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 fbf84a4..339f6de 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@@ -1050,6 +1110,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@@ -1210,6 +1271,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@@ -1347,17 +1410,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@@ -1367,11 +1434,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..65de923 100644
583--- a/arch/alpha/kernel/osf_sys.c
584+++ b/arch/alpha/kernel/osf_sys.c
585@@ -1304,7 +1304,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
586 /* At this point: (!vma || addr < vma->vm_end). */
587 if (limit - len < addr)
588 return -ENOMEM;
589- if (!vma || addr + len <= vma->vm_start)
590+ if (check_heap_stack_gap(vma, addr, len))
591 return addr;
592 addr = vma->vm_end;
593 vma = vma->vm_next;
594@@ -1340,6 +1340,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
595 merely specific addresses, but regions of memory -- perhaps
596 this feature should be incorporated into all ports? */
597
598+#ifdef CONFIG_PAX_RANDMMAP
599+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
600+#endif
601+
602 if (addr) {
603 addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
604 if (addr != (unsigned long) -ENOMEM)
605@@ -1347,8 +1351,8 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
606 }
607
608 /* Next, try allocating at TASK_UNMAPPED_BASE. */
609- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
610- len, limit);
611+ addr = arch_get_unmapped_area_1 (PAGE_ALIGN(current->mm->mmap_base), len, limit);
612+
613 if (addr != (unsigned long) -ENOMEM)
614 return addr;
615
616diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
617index 0c4132d..88f0d53 100644
618--- a/arch/alpha/mm/fault.c
619+++ b/arch/alpha/mm/fault.c
620@@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
621 __reload_thread(pcb);
622 }
623
624+#ifdef CONFIG_PAX_PAGEEXEC
625+/*
626+ * PaX: decide what to do with offenders (regs->pc = fault address)
627+ *
628+ * returns 1 when task should be killed
629+ * 2 when patched PLT trampoline was detected
630+ * 3 when unpatched PLT trampoline was detected
631+ */
632+static int pax_handle_fetch_fault(struct pt_regs *regs)
633+{
634+
635+#ifdef CONFIG_PAX_EMUPLT
636+ int err;
637+
638+ do { /* PaX: patched PLT emulation #1 */
639+ unsigned int ldah, ldq, jmp;
640+
641+ err = get_user(ldah, (unsigned int *)regs->pc);
642+ err |= get_user(ldq, (unsigned int *)(regs->pc+4));
643+ err |= get_user(jmp, (unsigned int *)(regs->pc+8));
644+
645+ if (err)
646+ break;
647+
648+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
649+ (ldq & 0xFFFF0000U) == 0xA77B0000U &&
650+ jmp == 0x6BFB0000U)
651+ {
652+ unsigned long r27, addr;
653+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
654+ unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
655+
656+ addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
657+ err = get_user(r27, (unsigned long *)addr);
658+ if (err)
659+ break;
660+
661+ regs->r27 = r27;
662+ regs->pc = r27;
663+ return 2;
664+ }
665+ } while (0);
666+
667+ do { /* PaX: patched PLT emulation #2 */
668+ unsigned int ldah, lda, br;
669+
670+ err = get_user(ldah, (unsigned int *)regs->pc);
671+ err |= get_user(lda, (unsigned int *)(regs->pc+4));
672+ err |= get_user(br, (unsigned int *)(regs->pc+8));
673+
674+ if (err)
675+ break;
676+
677+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
678+ (lda & 0xFFFF0000U) == 0xA77B0000U &&
679+ (br & 0xFFE00000U) == 0xC3E00000U)
680+ {
681+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
682+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
683+ unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
684+
685+ regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
686+ regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
687+ return 2;
688+ }
689+ } while (0);
690+
691+ do { /* PaX: unpatched PLT emulation */
692+ unsigned int br;
693+
694+ err = get_user(br, (unsigned int *)regs->pc);
695+
696+ if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
697+ unsigned int br2, ldq, nop, jmp;
698+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
699+
700+ addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
701+ err = get_user(br2, (unsigned int *)addr);
702+ err |= get_user(ldq, (unsigned int *)(addr+4));
703+ err |= get_user(nop, (unsigned int *)(addr+8));
704+ err |= get_user(jmp, (unsigned int *)(addr+12));
705+ err |= get_user(resolver, (unsigned long *)(addr+16));
706+
707+ if (err)
708+ break;
709+
710+ if (br2 == 0xC3600000U &&
711+ ldq == 0xA77B000CU &&
712+ nop == 0x47FF041FU &&
713+ jmp == 0x6B7B0000U)
714+ {
715+ regs->r28 = regs->pc+4;
716+ regs->r27 = addr+16;
717+ regs->pc = resolver;
718+ return 3;
719+ }
720+ }
721+ } while (0);
722+#endif
723+
724+ return 1;
725+}
726+
727+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
728+{
729+ unsigned long i;
730+
731+ printk(KERN_ERR "PAX: bytes at PC: ");
732+ for (i = 0; i < 5; i++) {
733+ unsigned int c;
734+ if (get_user(c, (unsigned int *)pc+i))
735+ printk(KERN_CONT "???????? ");
736+ else
737+ printk(KERN_CONT "%08x ", c);
738+ }
739+ printk("\n");
740+}
741+#endif
742
743 /*
744 * This routine handles page faults. It determines the address,
745@@ -133,8 +251,29 @@ retry:
746 good_area:
747 si_code = SEGV_ACCERR;
748 if (cause < 0) {
749- if (!(vma->vm_flags & VM_EXEC))
750+ if (!(vma->vm_flags & VM_EXEC)) {
751+
752+#ifdef CONFIG_PAX_PAGEEXEC
753+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
754+ goto bad_area;
755+
756+ up_read(&mm->mmap_sem);
757+ switch (pax_handle_fetch_fault(regs)) {
758+
759+#ifdef CONFIG_PAX_EMUPLT
760+ case 2:
761+ case 3:
762+ return;
763+#endif
764+
765+ }
766+ pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
767+ do_group_exit(SIGKILL);
768+#else
769 goto bad_area;
770+#endif
771+
772+ }
773 } else if (!cause) {
774 /* Allow reads even for write-only mappings */
775 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
776diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
777index c79f61f..9ac0642 100644
778--- a/arch/arm/include/asm/atomic.h
779+++ b/arch/arm/include/asm/atomic.h
780@@ -17,17 +17,35 @@
781 #include <asm/barrier.h>
782 #include <asm/cmpxchg.h>
783
784+#ifdef CONFIG_GENERIC_ATOMIC64
785+#include <asm-generic/atomic64.h>
786+#endif
787+
788 #define ATOMIC_INIT(i) { (i) }
789
790 #ifdef __KERNEL__
791
792+#define _ASM_EXTABLE(from, to) \
793+" .pushsection __ex_table,\"a\"\n"\
794+" .align 3\n" \
795+" .long " #from ", " #to"\n" \
796+" .popsection"
797+
798 /*
799 * On ARM, ordinary assignment (str instruction) doesn't clear the local
800 * strex/ldrex monitor on some implementations. The reason we can use it for
801 * atomic_set() is the clrex or dummy strex done on every exception return.
802 */
803 #define atomic_read(v) (*(volatile int *)&(v)->counter)
804+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
805+{
806+ return v->counter;
807+}
808 #define atomic_set(v,i) (((v)->counter) = (i))
809+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
810+{
811+ v->counter = i;
812+}
813
814 #if __LINUX_ARM_ARCH__ >= 6
815
816@@ -42,6 +60,35 @@ static inline void atomic_add(int i, atomic_t *v)
817 int result;
818
819 __asm__ __volatile__("@ atomic_add\n"
820+"1: ldrex %1, [%3]\n"
821+" adds %0, %1, %4\n"
822+
823+#ifdef CONFIG_PAX_REFCOUNT
824+" bvc 3f\n"
825+"2: bkpt 0xf103\n"
826+"3:\n"
827+#endif
828+
829+" strex %1, %0, [%3]\n"
830+" teq %1, #0\n"
831+" bne 1b"
832+
833+#ifdef CONFIG_PAX_REFCOUNT
834+"\n4:\n"
835+ _ASM_EXTABLE(2b, 4b)
836+#endif
837+
838+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
839+ : "r" (&v->counter), "Ir" (i)
840+ : "cc");
841+}
842+
843+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
844+{
845+ unsigned long tmp;
846+ int result;
847+
848+ __asm__ __volatile__("@ atomic_add_unchecked\n"
849 "1: ldrex %0, [%3]\n"
850 " add %0, %0, %4\n"
851 " strex %1, %0, [%3]\n"
852@@ -60,6 +107,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
853 smp_mb();
854
855 __asm__ __volatile__("@ atomic_add_return\n"
856+"1: ldrex %1, [%3]\n"
857+" adds %0, %1, %4\n"
858+
859+#ifdef CONFIG_PAX_REFCOUNT
860+" bvc 3f\n"
861+" mov %0, %1\n"
862+"2: bkpt 0xf103\n"
863+"3:\n"
864+#endif
865+
866+" strex %1, %0, [%3]\n"
867+" teq %1, #0\n"
868+" bne 1b"
869+
870+#ifdef CONFIG_PAX_REFCOUNT
871+"\n4:\n"
872+ _ASM_EXTABLE(2b, 4b)
873+#endif
874+
875+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
876+ : "r" (&v->counter), "Ir" (i)
877+ : "cc");
878+
879+ smp_mb();
880+
881+ return result;
882+}
883+
884+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
885+{
886+ unsigned long tmp;
887+ int result;
888+
889+ smp_mb();
890+
891+ __asm__ __volatile__("@ atomic_add_return_unchecked\n"
892 "1: ldrex %0, [%3]\n"
893 " add %0, %0, %4\n"
894 " strex %1, %0, [%3]\n"
895@@ -80,6 +163,35 @@ static inline void atomic_sub(int i, atomic_t *v)
896 int result;
897
898 __asm__ __volatile__("@ atomic_sub\n"
899+"1: ldrex %1, [%3]\n"
900+" subs %0, %1, %4\n"
901+
902+#ifdef CONFIG_PAX_REFCOUNT
903+" bvc 3f\n"
904+"2: bkpt 0xf103\n"
905+"3:\n"
906+#endif
907+
908+" strex %1, %0, [%3]\n"
909+" teq %1, #0\n"
910+" bne 1b"
911+
912+#ifdef CONFIG_PAX_REFCOUNT
913+"\n4:\n"
914+ _ASM_EXTABLE(2b, 4b)
915+#endif
916+
917+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
918+ : "r" (&v->counter), "Ir" (i)
919+ : "cc");
920+}
921+
922+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
923+{
924+ unsigned long tmp;
925+ int result;
926+
927+ __asm__ __volatile__("@ atomic_sub_unchecked\n"
928 "1: ldrex %0, [%3]\n"
929 " sub %0, %0, %4\n"
930 " strex %1, %0, [%3]\n"
931@@ -98,11 +210,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
932 smp_mb();
933
934 __asm__ __volatile__("@ atomic_sub_return\n"
935-"1: ldrex %0, [%3]\n"
936-" sub %0, %0, %4\n"
937+"1: ldrex %1, [%3]\n"
938+" subs %0, %1, %4\n"
939+
940+#ifdef CONFIG_PAX_REFCOUNT
941+" bvc 3f\n"
942+" mov %0, %1\n"
943+"2: bkpt 0xf103\n"
944+"3:\n"
945+#endif
946+
947 " strex %1, %0, [%3]\n"
948 " teq %1, #0\n"
949 " bne 1b"
950+
951+#ifdef CONFIG_PAX_REFCOUNT
952+"\n4:\n"
953+ _ASM_EXTABLE(2b, 4b)
954+#endif
955+
956 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
957 : "r" (&v->counter), "Ir" (i)
958 : "cc");
959@@ -134,6 +260,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
960 return oldval;
961 }
962
963+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
964+{
965+ unsigned long oldval, res;
966+
967+ smp_mb();
968+
969+ do {
970+ __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
971+ "ldrex %1, [%3]\n"
972+ "mov %0, #0\n"
973+ "teq %1, %4\n"
974+ "strexeq %0, %5, [%3]\n"
975+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
976+ : "r" (&ptr->counter), "Ir" (old), "r" (new)
977+ : "cc");
978+ } while (res);
979+
980+ smp_mb();
981+
982+ return oldval;
983+}
984+
985 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
986 {
987 unsigned long tmp, tmp2;
988@@ -167,7 +315,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
989
990 return val;
991 }
992+
993+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
994+{
995+ return atomic_add_return(i, v);
996+}
997+
998 #define atomic_add(i, v) (void) atomic_add_return(i, v)
999+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1000+{
1001+ (void) atomic_add_return(i, v);
1002+}
1003
1004 static inline int atomic_sub_return(int i, atomic_t *v)
1005 {
1006@@ -182,6 +340,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1007 return val;
1008 }
1009 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1010+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1011+{
1012+ (void) atomic_sub_return(i, v);
1013+}
1014
1015 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1016 {
1017@@ -197,6 +359,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1018 return ret;
1019 }
1020
1021+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1022+{
1023+ return atomic_cmpxchg(v, old, new);
1024+}
1025+
1026 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1027 {
1028 unsigned long flags;
1029@@ -209,6 +376,10 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1030 #endif /* __LINUX_ARM_ARCH__ */
1031
1032 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1033+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1034+{
1035+ return xchg(&v->counter, new);
1036+}
1037
1038 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1039 {
1040@@ -221,11 +392,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1041 }
1042
1043 #define atomic_inc(v) atomic_add(1, v)
1044+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1045+{
1046+ atomic_add_unchecked(1, v);
1047+}
1048 #define atomic_dec(v) atomic_sub(1, v)
1049+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1050+{
1051+ atomic_sub_unchecked(1, v);
1052+}
1053
1054 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1055+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1056+{
1057+ return atomic_add_return_unchecked(1, v) == 0;
1058+}
1059 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1060 #define atomic_inc_return(v) (atomic_add_return(1, v))
1061+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1062+{
1063+ return atomic_add_return_unchecked(1, v);
1064+}
1065 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1066 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1067
1068@@ -241,6 +428,14 @@ typedef struct {
1069 u64 __aligned(8) counter;
1070 } atomic64_t;
1071
1072+#ifdef CONFIG_PAX_REFCOUNT
1073+typedef struct {
1074+ u64 __aligned(8) counter;
1075+} atomic64_unchecked_t;
1076+#else
1077+typedef atomic64_t atomic64_unchecked_t;
1078+#endif
1079+
1080 #define ATOMIC64_INIT(i) { (i) }
1081
1082 static inline u64 atomic64_read(const atomic64_t *v)
1083@@ -256,6 +451,19 @@ static inline u64 atomic64_read(const atomic64_t *v)
1084 return result;
1085 }
1086
1087+static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
1088+{
1089+ u64 result;
1090+
1091+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1092+" ldrexd %0, %H0, [%1]"
1093+ : "=&r" (result)
1094+ : "r" (&v->counter), "Qo" (v->counter)
1095+ );
1096+
1097+ return result;
1098+}
1099+
1100 static inline void atomic64_set(atomic64_t *v, u64 i)
1101 {
1102 u64 tmp;
1103@@ -270,6 +478,20 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1104 : "cc");
1105 }
1106
1107+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1108+{
1109+ u64 tmp;
1110+
1111+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1112+"1: ldrexd %0, %H0, [%2]\n"
1113+" strexd %0, %3, %H3, [%2]\n"
1114+" teq %0, #0\n"
1115+" bne 1b"
1116+ : "=&r" (tmp), "=Qo" (v->counter)
1117+ : "r" (&v->counter), "r" (i)
1118+ : "cc");
1119+}
1120+
1121 static inline void atomic64_add(u64 i, atomic64_t *v)
1122 {
1123 u64 result;
1124@@ -278,6 +500,36 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1125 __asm__ __volatile__("@ atomic64_add\n"
1126 "1: ldrexd %0, %H0, [%3]\n"
1127 " adds %0, %0, %4\n"
1128+" adcs %H0, %H0, %H4\n"
1129+
1130+#ifdef CONFIG_PAX_REFCOUNT
1131+" bvc 3f\n"
1132+"2: bkpt 0xf103\n"
1133+"3:\n"
1134+#endif
1135+
1136+" strexd %1, %0, %H0, [%3]\n"
1137+" teq %1, #0\n"
1138+" bne 1b"
1139+
1140+#ifdef CONFIG_PAX_REFCOUNT
1141+"\n4:\n"
1142+ _ASM_EXTABLE(2b, 4b)
1143+#endif
1144+
1145+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1146+ : "r" (&v->counter), "r" (i)
1147+ : "cc");
1148+}
1149+
1150+static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
1151+{
1152+ u64 result;
1153+ unsigned long tmp;
1154+
1155+ __asm__ __volatile__("@ atomic64_add_unchecked\n"
1156+"1: ldrexd %0, %H0, [%3]\n"
1157+" adds %0, %0, %4\n"
1158 " adc %H0, %H0, %H4\n"
1159 " strexd %1, %0, %H0, [%3]\n"
1160 " teq %1, #0\n"
1161@@ -289,12 +541,49 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1162
1163 static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
1164 {
1165- u64 result;
1166- unsigned long tmp;
1167+ u64 result, tmp;
1168
1169 smp_mb();
1170
1171 __asm__ __volatile__("@ atomic64_add_return\n"
1172+"1: ldrexd %1, %H1, [%3]\n"
1173+" adds %0, %1, %4\n"
1174+" adcs %H0, %H1, %H4\n"
1175+
1176+#ifdef CONFIG_PAX_REFCOUNT
1177+" bvc 3f\n"
1178+" mov %0, %1\n"
1179+" mov %H0, %H1\n"
1180+"2: bkpt 0xf103\n"
1181+"3:\n"
1182+#endif
1183+
1184+" strexd %1, %0, %H0, [%3]\n"
1185+" teq %1, #0\n"
1186+" bne 1b"
1187+
1188+#ifdef CONFIG_PAX_REFCOUNT
1189+"\n4:\n"
1190+ _ASM_EXTABLE(2b, 4b)
1191+#endif
1192+
1193+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1194+ : "r" (&v->counter), "r" (i)
1195+ : "cc");
1196+
1197+ smp_mb();
1198+
1199+ return result;
1200+}
1201+
1202+static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
1203+{
1204+ u64 result;
1205+ unsigned long tmp;
1206+
1207+ smp_mb();
1208+
1209+ __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1210 "1: ldrexd %0, %H0, [%3]\n"
1211 " adds %0, %0, %4\n"
1212 " adc %H0, %H0, %H4\n"
1213@@ -318,6 +607,36 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1214 __asm__ __volatile__("@ atomic64_sub\n"
1215 "1: ldrexd %0, %H0, [%3]\n"
1216 " subs %0, %0, %4\n"
1217+" sbcs %H0, %H0, %H4\n"
1218+
1219+#ifdef CONFIG_PAX_REFCOUNT
1220+" bvc 3f\n"
1221+"2: bkpt 0xf103\n"
1222+"3:\n"
1223+#endif
1224+
1225+" strexd %1, %0, %H0, [%3]\n"
1226+" teq %1, #0\n"
1227+" bne 1b"
1228+
1229+#ifdef CONFIG_PAX_REFCOUNT
1230+"\n4:\n"
1231+ _ASM_EXTABLE(2b, 4b)
1232+#endif
1233+
1234+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1235+ : "r" (&v->counter), "r" (i)
1236+ : "cc");
1237+}
1238+
1239+static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
1240+{
1241+ u64 result;
1242+ unsigned long tmp;
1243+
1244+ __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1245+"1: ldrexd %0, %H0, [%3]\n"
1246+" subs %0, %0, %4\n"
1247 " sbc %H0, %H0, %H4\n"
1248 " strexd %1, %0, %H0, [%3]\n"
1249 " teq %1, #0\n"
1250@@ -329,18 +648,32 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1251
1252 static inline u64 atomic64_sub_return(u64 i, atomic64_t *v)
1253 {
1254- u64 result;
1255- unsigned long tmp;
1256+ u64 result, tmp;
1257
1258 smp_mb();
1259
1260 __asm__ __volatile__("@ atomic64_sub_return\n"
1261-"1: ldrexd %0, %H0, [%3]\n"
1262-" subs %0, %0, %4\n"
1263-" sbc %H0, %H0, %H4\n"
1264+"1: ldrexd %1, %H1, [%3]\n"
1265+" subs %0, %1, %4\n"
1266+" sbcs %H0, %H1, %H4\n"
1267+
1268+#ifdef CONFIG_PAX_REFCOUNT
1269+" bvc 3f\n"
1270+" mov %0, %1\n"
1271+" mov %H0, %H1\n"
1272+"2: bkpt 0xf103\n"
1273+"3:\n"
1274+#endif
1275+
1276 " strexd %1, %0, %H0, [%3]\n"
1277 " teq %1, #0\n"
1278 " bne 1b"
1279+
1280+#ifdef CONFIG_PAX_REFCOUNT
1281+"\n4:\n"
1282+ _ASM_EXTABLE(2b, 4b)
1283+#endif
1284+
1285 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1286 : "r" (&v->counter), "r" (i)
1287 : "cc");
1288@@ -374,6 +707,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1289 return oldval;
1290 }
1291
1292+static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1293+{
1294+ u64 oldval;
1295+ unsigned long res;
1296+
1297+ smp_mb();
1298+
1299+ do {
1300+ __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1301+ "ldrexd %1, %H1, [%3]\n"
1302+ "mov %0, #0\n"
1303+ "teq %1, %4\n"
1304+ "teqeq %H1, %H4\n"
1305+ "strexdeq %0, %5, %H5, [%3]"
1306+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1307+ : "r" (&ptr->counter), "r" (old), "r" (new)
1308+ : "cc");
1309+ } while (res);
1310+
1311+ smp_mb();
1312+
1313+ return oldval;
1314+}
1315+
1316 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1317 {
1318 u64 result;
1319@@ -397,21 +754,34 @@ static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1320
1321 static inline u64 atomic64_dec_if_positive(atomic64_t *v)
1322 {
1323- u64 result;
1324- unsigned long tmp;
1325+ u64 result, tmp;
1326
1327 smp_mb();
1328
1329 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1330-"1: ldrexd %0, %H0, [%3]\n"
1331-" subs %0, %0, #1\n"
1332-" sbc %H0, %H0, #0\n"
1333+"1: ldrexd %1, %H1, [%3]\n"
1334+" subs %0, %1, #1\n"
1335+" sbcs %H0, %H1, #0\n"
1336+
1337+#ifdef CONFIG_PAX_REFCOUNT
1338+" bvc 3f\n"
1339+" mov %0, %1\n"
1340+" mov %H0, %H1\n"
1341+"2: bkpt 0xf103\n"
1342+"3:\n"
1343+#endif
1344+
1345 " teq %H0, #0\n"
1346-" bmi 2f\n"
1347+" bmi 4f\n"
1348 " strexd %1, %0, %H0, [%3]\n"
1349 " teq %1, #0\n"
1350 " bne 1b\n"
1351-"2:"
1352+"4:\n"
1353+
1354+#ifdef CONFIG_PAX_REFCOUNT
1355+ _ASM_EXTABLE(2b, 4b)
1356+#endif
1357+
1358 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1359 : "r" (&v->counter)
1360 : "cc");
1361@@ -434,13 +804,25 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1362 " teq %0, %5\n"
1363 " teqeq %H0, %H5\n"
1364 " moveq %1, #0\n"
1365-" beq 2f\n"
1366+" beq 4f\n"
1367 " adds %0, %0, %6\n"
1368-" adc %H0, %H0, %H6\n"
1369+" adcs %H0, %H0, %H6\n"
1370+
1371+#ifdef CONFIG_PAX_REFCOUNT
1372+" bvc 3f\n"
1373+"2: bkpt 0xf103\n"
1374+"3:\n"
1375+#endif
1376+
1377 " strexd %2, %0, %H0, [%4]\n"
1378 " teq %2, #0\n"
1379 " bne 1b\n"
1380-"2:"
1381+"4:\n"
1382+
1383+#ifdef CONFIG_PAX_REFCOUNT
1384+ _ASM_EXTABLE(2b, 4b)
1385+#endif
1386+
1387 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1388 : "r" (&v->counter), "r" (u), "r" (a)
1389 : "cc");
1390@@ -453,10 +835,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1391
1392 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1393 #define atomic64_inc(v) atomic64_add(1LL, (v))
1394+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1395 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1396+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1397 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1398 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1399 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1400+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1401 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1402 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1403 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1404diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1405index 75fe66b..ba3dee4 100644
1406--- a/arch/arm/include/asm/cache.h
1407+++ b/arch/arm/include/asm/cache.h
1408@@ -4,8 +4,10 @@
1409 #ifndef __ASMARM_CACHE_H
1410 #define __ASMARM_CACHE_H
1411
1412+#include <linux/const.h>
1413+
1414 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1415-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1416+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1417
1418 /*
1419 * Memory returned by kmalloc() may be used for DMA, so we must make
1420@@ -24,5 +26,6 @@
1421 #endif
1422
1423 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1424+#define __read_only __attribute__ ((__section__(".data..read_only")))
1425
1426 #endif
1427diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1428index e1489c5..d418304 100644
1429--- a/arch/arm/include/asm/cacheflush.h
1430+++ b/arch/arm/include/asm/cacheflush.h
1431@@ -116,7 +116,7 @@ struct cpu_cache_fns {
1432 void (*dma_unmap_area)(const void *, size_t, int);
1433
1434 void (*dma_flush_range)(const void *, const void *);
1435-};
1436+} __no_const;
1437
1438 /*
1439 * Select the calling method
1440diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1441index 7eb18c1..e38b6d2 100644
1442--- a/arch/arm/include/asm/cmpxchg.h
1443+++ b/arch/arm/include/asm/cmpxchg.h
1444@@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1445
1446 #define xchg(ptr,x) \
1447 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1448+#define xchg_unchecked(ptr,x) \
1449+ ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1450
1451 #include <asm-generic/cmpxchg-local.h>
1452
1453diff --git a/arch/arm/include/asm/delay.h b/arch/arm/include/asm/delay.h
1454index ab98fdd..6b19938 100644
1455--- a/arch/arm/include/asm/delay.h
1456+++ b/arch/arm/include/asm/delay.h
1457@@ -24,9 +24,9 @@ extern struct arm_delay_ops {
1458 void (*delay)(unsigned long);
1459 void (*const_udelay)(unsigned long);
1460 void (*udelay)(unsigned long);
1461-} arm_delay_ops;
1462+} *arm_delay_ops;
1463
1464-#define __delay(n) arm_delay_ops.delay(n)
1465+#define __delay(n) arm_delay_ops->delay(n)
1466
1467 /*
1468 * This function intentionally does not exist; if you see references to
1469@@ -47,8 +47,8 @@ extern void __bad_udelay(void);
1470 * first constant multiplications gets optimized away if the delay is
1471 * a constant)
1472 */
1473-#define __udelay(n) arm_delay_ops.udelay(n)
1474-#define __const_udelay(n) arm_delay_ops.const_udelay(n)
1475+#define __udelay(n) arm_delay_ops->udelay(n)
1476+#define __const_udelay(n) arm_delay_ops->const_udelay(n)
1477
1478 #define udelay(n) \
1479 (__builtin_constant_p(n) ? \
1480diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1481index 38050b1..9d90e8b 100644
1482--- a/arch/arm/include/asm/elf.h
1483+++ b/arch/arm/include/asm/elf.h
1484@@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1485 the loader. We need to make sure that it is out of the way of the program
1486 that it will "exec", and that there is sufficient room for the brk. */
1487
1488-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1489+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1490+
1491+#ifdef CONFIG_PAX_ASLR
1492+#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1493+
1494+#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1495+#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1496+#endif
1497
1498 /* When the program starts, a1 contains a pointer to a function to be
1499 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1500@@ -126,8 +133,4 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1501 extern void elf_set_personality(const struct elf32_hdr *);
1502 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1503
1504-struct mm_struct;
1505-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1506-#define arch_randomize_brk arch_randomize_brk
1507-
1508 #endif
1509diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1510index 83eb2f7..ed77159 100644
1511--- a/arch/arm/include/asm/kmap_types.h
1512+++ b/arch/arm/include/asm/kmap_types.h
1513@@ -4,6 +4,6 @@
1514 /*
1515 * This is the "bare minimum". AIO seems to require this.
1516 */
1517-#define KM_TYPE_NR 16
1518+#define KM_TYPE_NR 17
1519
1520 #endif
1521diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1522index 195ac2f..2272f0d 100644
1523--- a/arch/arm/include/asm/mach/map.h
1524+++ b/arch/arm/include/asm/mach/map.h
1525@@ -34,6 +34,9 @@ struct map_desc {
1526 #define MT_MEMORY_ITCM 13
1527 #define MT_MEMORY_SO 14
1528 #define MT_MEMORY_DMA_READY 15
1529+#define MT_MEMORY_R 16
1530+#define MT_MEMORY_RW 17
1531+#define MT_MEMORY_RX 18
1532
1533 #ifdef CONFIG_MMU
1534 extern void iotable_init(struct map_desc *, int);
1535diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1536index 53426c6..c7baff3 100644
1537--- a/arch/arm/include/asm/outercache.h
1538+++ b/arch/arm/include/asm/outercache.h
1539@@ -35,7 +35,7 @@ struct outer_cache_fns {
1540 #endif
1541 void (*set_debug)(unsigned long);
1542 void (*resume)(void);
1543-};
1544+} __no_const;
1545
1546 #ifdef CONFIG_OUTER_CACHE
1547
1548diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1549index 812a494..71fc0b6 100644
1550--- a/arch/arm/include/asm/page.h
1551+++ b/arch/arm/include/asm/page.h
1552@@ -114,7 +114,7 @@ struct cpu_user_fns {
1553 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1554 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1555 unsigned long vaddr, struct vm_area_struct *vma);
1556-};
1557+} __no_const;
1558
1559 #ifdef MULTI_USER
1560 extern struct cpu_user_fns cpu_user;
1561diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1562index 943504f..1ad2de8 100644
1563--- a/arch/arm/include/asm/pgalloc.h
1564+++ b/arch/arm/include/asm/pgalloc.h
1565@@ -22,7 +22,7 @@
1566
1567 #ifdef CONFIG_MMU
1568
1569-#define _PAGE_USER_TABLE (PMD_TYPE_TABLE | PMD_BIT4 | PMD_DOMAIN(DOMAIN_USER))
1570+#define _PAGE_USER_TABLE (PMD_TYPE_TABLE | PMD_PXNTABLE | PMD_BIT4 | PMD_DOMAIN(DOMAIN_USER))
1571 #define _PAGE_KERNEL_TABLE (PMD_TYPE_TABLE | PMD_BIT4 | PMD_DOMAIN(DOMAIN_KERNEL))
1572
1573 #ifdef CONFIG_ARM_LPAE
1574@@ -43,6 +43,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1575 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1576 }
1577
1578+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1579+{
1580+ pud_populate(mm, pud, pmd);
1581+}
1582+
1583 #else /* !CONFIG_ARM_LPAE */
1584
1585 /*
1586@@ -51,6 +56,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1587 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1588 #define pmd_free(mm, pmd) do { } while (0)
1589 #define pud_populate(mm,pmd,pte) BUG()
1590+#define pud_populate_kernel(mm,pmd,pte) BUG()
1591
1592 #endif /* CONFIG_ARM_LPAE */
1593
1594@@ -126,6 +132,16 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1595 __free_page(pte);
1596 }
1597
1598+static inline void __pmd_update(pmd_t *pmdp, pmdval_t prot)
1599+{
1600+ pmdval_t pmdval = pmd_val(*pmdp) | prot;
1601+ pmdp[0] = __pmd(pmdval);
1602+#ifndef CONFIG_ARM_LPAE
1603+ pmdp[1] = __pmd(pmdval + 256 * sizeof(pte_t));
1604+#endif
1605+ flush_pmd_entry(pmdp);
1606+}
1607+
1608 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1609 pmdval_t prot)
1610 {
1611diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1612index 5cfba15..d437dc2 100644
1613--- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1614+++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1615@@ -20,12 +20,15 @@
1616 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1617 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1618 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1619+#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* PXN */
1620 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1621 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1622 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1623+
1624 /*
1625 * - section
1626 */
1627+#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0)
1628 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1629 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1630 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1631@@ -37,6 +40,7 @@
1632 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1633 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1634 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1635+#define PMD_SECT_AP_RDONLY (_AT(pmdval_t, 0))
1636
1637 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1638 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1639diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
1640index d795282..d82ff13 100644
1641--- a/arch/arm/include/asm/pgtable-3level-hwdef.h
1642+++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
1643@@ -32,6 +32,7 @@
1644 #define PMD_TYPE_SECT (_AT(pmdval_t, 1) << 0)
1645 #define PMD_BIT4 (_AT(pmdval_t, 0))
1646 #define PMD_DOMAIN(x) (_AT(pmdval_t, 0))
1647+#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 59) /* PXNTable */
1648
1649 /*
1650 * - section
1651@@ -41,9 +42,11 @@
1652 #define PMD_SECT_S (_AT(pmdval_t, 3) << 8)
1653 #define PMD_SECT_AF (_AT(pmdval_t, 1) << 10)
1654 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 11)
1655+#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 53)
1656 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 54)
1657 #define PMD_SECT_AP_WRITE (_AT(pmdval_t, 0))
1658 #define PMD_SECT_AP_READ (_AT(pmdval_t, 0))
1659+#define PMD_SECT_AP_RDONLY (_AT(pmdval_t, 1) << 7)
1660 #define PMD_SECT_TEX(x) (_AT(pmdval_t, 0))
1661
1662 /*
1663@@ -66,6 +69,7 @@
1664 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1665 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
1666 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
1667+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1668 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
1669
1670 /*
1671diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
1672index b249035..4ab204b 100644
1673--- a/arch/arm/include/asm/pgtable-3level.h
1674+++ b/arch/arm/include/asm/pgtable-3level.h
1675@@ -73,6 +73,7 @@
1676 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
1677 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1678 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
1679+#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1680 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
1681 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
1682 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
1683@@ -80,6 +81,7 @@
1684 /*
1685 * To be used in assembly code with the upper page attributes.
1686 */
1687+#define L_PTE_PXN_HIGH (1 << (53 - 32))
1688 #define L_PTE_XN_HIGH (1 << (54 - 32))
1689 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
1690
1691diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
1692index 08c1231..6a2d6b0 100644
1693--- a/arch/arm/include/asm/pgtable.h
1694+++ b/arch/arm/include/asm/pgtable.h
1695@@ -30,6 +30,9 @@
1696 #include <asm/pgtable-2level.h>
1697 #endif
1698
1699+#define ktla_ktva(addr) (addr)
1700+#define ktva_ktla(addr) (addr)
1701+
1702 /*
1703 * Just any arbitrary offset to the start of the vmalloc VM area: the
1704 * current 8MB value just means that there will be a 8MB "hole" after the
1705@@ -53,6 +56,17 @@ extern void __pgd_error(const char *file, int line, pgd_t);
1706 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
1707 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
1708
1709+#define __HAVE_ARCH_PAX_OPEN_KERNEL
1710+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
1711+
1712+#ifdef CONFIG_PAX_KERNEXEC
1713+static inline unsigned long pax_open_kernel(void) { return 0; /* TODO */ }
1714+static inline unsigned long pax_close_kernel(void) { return 0; /* TODO */ }
1715+#else
1716+static inline unsigned long pax_open_kernel(void) { return 0; }
1717+static inline unsigned long pax_close_kernel(void) { return 0; }
1718+#endif
1719+
1720 /*
1721 * This is the lowest virtual address we can permit any user space
1722 * mapping to be mapped at. This is particularly important for
1723@@ -73,23 +87,23 @@ extern pgprot_t pgprot_kernel;
1724
1725 #define _MOD_PROT(p, b) __pgprot(pgprot_val(p) | (b))
1726
1727-#define PAGE_NONE _MOD_PROT(pgprot_user, L_PTE_XN | L_PTE_RDONLY)
1728-#define PAGE_SHARED _MOD_PROT(pgprot_user, L_PTE_USER | L_PTE_XN)
1729-#define PAGE_SHARED_EXEC _MOD_PROT(pgprot_user, L_PTE_USER)
1730-#define PAGE_COPY _MOD_PROT(pgprot_user, L_PTE_USER | L_PTE_RDONLY | L_PTE_XN)
1731-#define PAGE_COPY_EXEC _MOD_PROT(pgprot_user, L_PTE_USER | L_PTE_RDONLY)
1732-#define PAGE_READONLY _MOD_PROT(pgprot_user, L_PTE_USER | L_PTE_RDONLY | L_PTE_XN)
1733-#define PAGE_READONLY_EXEC _MOD_PROT(pgprot_user, L_PTE_USER | L_PTE_RDONLY)
1734+#define PAGE_NONE _MOD_PROT(pgprot_user, L_PTE_XN | L_PTE_PXN | L_PTE_RDONLY)
1735+#define PAGE_SHARED _MOD_PROT(pgprot_user, L_PTE_USER | L_PTE_XN | L_PTE_PXN)
1736+#define PAGE_SHARED_EXEC _MOD_PROT(pgprot_user, L_PTE_USER | L_PTE_PXN)
1737+#define PAGE_COPY _MOD_PROT(pgprot_user, L_PTE_USER | L_PTE_RDONLY | L_PTE_XN | L_PTE_PXN)
1738+#define PAGE_COPY_EXEC _MOD_PROT(pgprot_user, L_PTE_USER | L_PTE_RDONLY | L_PTE_PXN)
1739+#define PAGE_READONLY _MOD_PROT(pgprot_user, L_PTE_USER | L_PTE_RDONLY | L_PTE_XN | L_PTE_PXN)
1740+#define PAGE_READONLY_EXEC _MOD_PROT(pgprot_user, L_PTE_USER | L_PTE_RDONLY | L_PTE_PXN)
1741 #define PAGE_KERNEL _MOD_PROT(pgprot_kernel, L_PTE_XN)
1742 #define PAGE_KERNEL_EXEC pgprot_kernel
1743
1744-#define __PAGE_NONE __pgprot(_L_PTE_DEFAULT | L_PTE_RDONLY | L_PTE_XN)
1745-#define __PAGE_SHARED __pgprot(_L_PTE_DEFAULT | L_PTE_USER | L_PTE_XN)
1746-#define __PAGE_SHARED_EXEC __pgprot(_L_PTE_DEFAULT | L_PTE_USER)
1747-#define __PAGE_COPY __pgprot(_L_PTE_DEFAULT | L_PTE_USER | L_PTE_RDONLY | L_PTE_XN)
1748-#define __PAGE_COPY_EXEC __pgprot(_L_PTE_DEFAULT | L_PTE_USER | L_PTE_RDONLY)
1749-#define __PAGE_READONLY __pgprot(_L_PTE_DEFAULT | L_PTE_USER | L_PTE_RDONLY | L_PTE_XN)
1750-#define __PAGE_READONLY_EXEC __pgprot(_L_PTE_DEFAULT | L_PTE_USER | L_PTE_RDONLY)
1751+#define __PAGE_NONE __pgprot(_L_PTE_DEFAULT | L_PTE_RDONLY | L_PTE_XN | L_PTE_PXN)
1752+#define __PAGE_SHARED __pgprot(_L_PTE_DEFAULT | L_PTE_USER | L_PTE_XN | L_PTE_PXN)
1753+#define __PAGE_SHARED_EXEC __pgprot(_L_PTE_DEFAULT | L_PTE_USER | L_PTE_PXN)
1754+#define __PAGE_COPY __pgprot(_L_PTE_DEFAULT | L_PTE_USER | L_PTE_RDONLY | L_PTE_XN | L_PTE_PXN)
1755+#define __PAGE_COPY_EXEC __pgprot(_L_PTE_DEFAULT | L_PTE_USER | L_PTE_RDONLY | L_PTE_PXN)
1756+#define __PAGE_READONLY __pgprot(_L_PTE_DEFAULT | L_PTE_USER | L_PTE_RDONLY | L_PTE_XN | L_PTE_PXN)
1757+#define __PAGE_READONLY_EXEC __pgprot(_L_PTE_DEFAULT | L_PTE_USER | L_PTE_RDONLY | L_PTE_PXN)
1758
1759 #define __pgprot_modify(prot,mask,bits) \
1760 __pgprot((pgprot_val(prot) & ~(mask)) | (bits))
1761@@ -242,7 +256,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
1762
1763 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
1764 {
1765- const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER;
1766+ const pteval_t mask = L_PTE_XN | L_PTE_PXN | L_PTE_RDONLY | L_PTE_USER;
1767 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
1768 return pte;
1769 }
1770diff --git a/arch/arm/include/asm/proc-fns.h b/arch/arm/include/asm/proc-fns.h
1771index f3628fb..a0672dd 100644
1772--- a/arch/arm/include/asm/proc-fns.h
1773+++ b/arch/arm/include/asm/proc-fns.h
1774@@ -75,7 +75,7 @@ extern struct processor {
1775 unsigned int suspend_size;
1776 void (*do_suspend)(void *);
1777 void (*do_resume)(void *);
1778-} processor;
1779+} __do_const processor;
1780
1781 #ifndef MULTI_CPU
1782 extern void cpu_proc_init(void);
1783diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
1784index 2e3be16..4dc90fc 100644
1785--- a/arch/arm/include/asm/smp.h
1786+++ b/arch/arm/include/asm/smp.h
1787@@ -106,7 +106,7 @@ struct smp_operations {
1788 int (*cpu_disable)(unsigned int cpu);
1789 #endif
1790 #endif
1791-};
1792+} __no_const;
1793
1794 /*
1795 * set platform specific SMP operations
1796diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
1797index 8477b4c..801a6a9 100644
1798--- a/arch/arm/include/asm/thread_info.h
1799+++ b/arch/arm/include/asm/thread_info.h
1800@@ -151,6 +151,12 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1801 #define TIF_SYSCALL_TRACE 8
1802 #define TIF_SYSCALL_AUDIT 9
1803 #define TIF_SYSCALL_TRACEPOINT 10
1804+
1805+/* within 8 bits of TIF_SYSCALL_TRACE
1806+ to meet flexible second operand requirements
1807+*/
1808+#define TIF_GRSEC_SETXID 11
1809+
1810 #define TIF_USING_IWMMXT 17
1811 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
1812 #define TIF_RESTORE_SIGMASK 20
1813@@ -165,9 +171,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1814 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
1815 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
1816 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
1817+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
1818
1819 /* Checks for any syscall work in entry-common.S */
1820-#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
1821+#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | \
1822+ _TIF_GRSEC_SETXID)
1823
1824 /*
1825 * Change these and you break ASM code in entry-common.S
1826diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
1827index 7e1f760..1af891c 100644
1828--- a/arch/arm/include/asm/uaccess.h
1829+++ b/arch/arm/include/asm/uaccess.h
1830@@ -22,6 +22,8 @@
1831 #define VERIFY_READ 0
1832 #define VERIFY_WRITE 1
1833
1834+extern void check_object_size(const void *ptr, unsigned long n, bool to);
1835+
1836 /*
1837 * The exception table consists of pairs of addresses: the first is the
1838 * address of an instruction that is allowed to fault, and the second is
1839@@ -418,8 +420,23 @@ do { \
1840
1841
1842 #ifdef CONFIG_MMU
1843-extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
1844-extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
1845+extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
1846+extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
1847+
1848+static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
1849+{
1850+ if (!__builtin_constant_p(n))
1851+ check_object_size(to, n, false);
1852+ return ___copy_from_user(to, from, n);
1853+}
1854+
1855+static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
1856+{
1857+ if (!__builtin_constant_p(n))
1858+ check_object_size(from, n, true);
1859+ return ___copy_to_user(to, from, n);
1860+}
1861+
1862 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
1863 extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
1864 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
1865@@ -431,6 +448,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
1866
1867 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
1868 {
1869+ if ((long)n < 0)
1870+ return n;
1871+
1872 if (access_ok(VERIFY_READ, from, n))
1873 n = __copy_from_user(to, from, n);
1874 else /* security hole - plug it */
1875@@ -440,6 +460,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
1876
1877 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
1878 {
1879+ if ((long)n < 0)
1880+ return n;
1881+
1882 if (access_ok(VERIFY_WRITE, to, n))
1883 n = __copy_to_user(to, from, n);
1884 return n;
1885diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
1886index 60d3b73..9168db0 100644
1887--- a/arch/arm/kernel/armksyms.c
1888+++ b/arch/arm/kernel/armksyms.c
1889@@ -89,8 +89,8 @@ EXPORT_SYMBOL(__memzero);
1890 #ifdef CONFIG_MMU
1891 EXPORT_SYMBOL(copy_page);
1892
1893-EXPORT_SYMBOL(__copy_from_user);
1894-EXPORT_SYMBOL(__copy_to_user);
1895+EXPORT_SYMBOL(___copy_from_user);
1896+EXPORT_SYMBOL(___copy_to_user);
1897 EXPORT_SYMBOL(__clear_user);
1898
1899 EXPORT_SYMBOL(__get_user_1);
1900diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
1901index 4eee351..e247728 100644
1902--- a/arch/arm/kernel/head.S
1903+++ b/arch/arm/kernel/head.S
1904@@ -52,7 +52,9 @@
1905 .equ swapper_pg_dir, KERNEL_RAM_VADDR - PG_DIR_SIZE
1906
1907 .macro pgtbl, rd, phys
1908- add \rd, \phys, #TEXT_OFFSET - PG_DIR_SIZE
1909+ mov \rd, #TEXT_OFFSET
1910+ sub \rd, #PG_DIR_SIZE
1911+ add \rd, \rd, \phys
1912 .endm
1913
1914 /*
1915diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
1916index 1e9be5d..b9a75e1 100644
1917--- a/arch/arm/kernel/module.c
1918+++ b/arch/arm/kernel/module.c
1919@@ -37,12 +37,35 @@
1920 #endif
1921
1922 #ifdef CONFIG_MMU
1923-void *module_alloc(unsigned long size)
1924+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
1925 {
1926 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
1927- GFP_KERNEL, PAGE_KERNEL_EXEC, -1,
1928+ GFP_KERNEL, prot, -1,
1929 __builtin_return_address(0));
1930 }
1931+
1932+void *module_alloc(unsigned long size)
1933+{
1934+
1935+#ifdef CONFIG_PAX_KERNEXEC
1936+ return __module_alloc(size, PAGE_KERNEL);
1937+#else
1938+ return __module_alloc(size, PAGE_KERNEL_EXEC);
1939+#endif
1940+
1941+}
1942+
1943+#ifdef CONFIG_PAX_KERNEXEC
1944+void module_free_exec(struct module *mod, void *module_region)
1945+{
1946+ module_free(mod, module_region);
1947+}
1948+
1949+void *module_alloc_exec(unsigned long size)
1950+{
1951+ return __module_alloc(size, PAGE_KERNEL_EXEC);
1952+}
1953+#endif
1954 #endif
1955
1956 int
1957diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
1958index 90084a6..bf4bcfb 100644
1959--- a/arch/arm/kernel/process.c
1960+++ b/arch/arm/kernel/process.c
1961@@ -28,7 +28,6 @@
1962 #include <linux/tick.h>
1963 #include <linux/utsname.h>
1964 #include <linux/uaccess.h>
1965-#include <linux/random.h>
1966 #include <linux/hw_breakpoint.h>
1967 #include <linux/cpuidle.h>
1968 #include <linux/leds.h>
1969@@ -256,9 +255,10 @@ void machine_power_off(void)
1970 machine_shutdown();
1971 if (pm_power_off)
1972 pm_power_off();
1973+ BUG();
1974 }
1975
1976-void machine_restart(char *cmd)
1977+__noreturn void machine_restart(char *cmd)
1978 {
1979 machine_shutdown();
1980
1981@@ -451,12 +451,6 @@ unsigned long get_wchan(struct task_struct *p)
1982 return 0;
1983 }
1984
1985-unsigned long arch_randomize_brk(struct mm_struct *mm)
1986-{
1987- unsigned long range_end = mm->brk + 0x02000000;
1988- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
1989-}
1990-
1991 #ifdef CONFIG_MMU
1992 /*
1993 * The vectors page is always readable from user space for the
1994diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
1995index 739db3a..7f4a272 100644
1996--- a/arch/arm/kernel/ptrace.c
1997+++ b/arch/arm/kernel/ptrace.c
1998@@ -916,6 +916,10 @@ enum ptrace_syscall_dir {
1999 PTRACE_SYSCALL_EXIT,
2000 };
2001
2002+#ifdef CONFIG_GRKERNSEC_SETXID
2003+extern void gr_delayed_cred_worker(void);
2004+#endif
2005+
2006 static int ptrace_syscall_trace(struct pt_regs *regs, int scno,
2007 enum ptrace_syscall_dir dir)
2008 {
2009@@ -923,6 +927,11 @@ static int ptrace_syscall_trace(struct pt_regs *regs, int scno,
2010
2011 current_thread_info()->syscall = scno;
2012
2013+#ifdef CONFIG_GRKERNSEC_SETXID
2014+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2015+ gr_delayed_cred_worker();
2016+#endif
2017+
2018 if (!test_thread_flag(TIF_SYSCALL_TRACE))
2019 return scno;
2020
2021diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
2022index da1d1aa..0a606e7 100644
2023--- a/arch/arm/kernel/setup.c
2024+++ b/arch/arm/kernel/setup.c
2025@@ -99,19 +99,19 @@ EXPORT_SYMBOL(elf_hwcap);
2026
2027
2028 #ifdef MULTI_CPU
2029-struct processor processor __read_mostly;
2030+struct processor processor;
2031 #endif
2032 #ifdef MULTI_TLB
2033-struct cpu_tlb_fns cpu_tlb __read_mostly;
2034+struct cpu_tlb_fns cpu_tlb __read_only;
2035 #endif
2036 #ifdef MULTI_USER
2037-struct cpu_user_fns cpu_user __read_mostly;
2038+struct cpu_user_fns cpu_user __read_only;
2039 #endif
2040 #ifdef MULTI_CACHE
2041-struct cpu_cache_fns cpu_cache __read_mostly;
2042+struct cpu_cache_fns cpu_cache __read_only;
2043 #endif
2044 #ifdef CONFIG_OUTER_CACHE
2045-struct outer_cache_fns outer_cache __read_mostly;
2046+struct outer_cache_fns outer_cache __read_only;
2047 EXPORT_SYMBOL(outer_cache);
2048 #endif
2049
2050diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
2051index fbc8b26..000ded0 100644
2052--- a/arch/arm/kernel/smp.c
2053+++ b/arch/arm/kernel/smp.c
2054@@ -70,7 +70,7 @@ enum ipi_msg_type {
2055
2056 static DECLARE_COMPLETION(cpu_running);
2057
2058-static struct smp_operations smp_ops;
2059+static struct smp_operations smp_ops __read_only;
2060
2061 void __init smp_set_ops(struct smp_operations *ops)
2062 {
2063diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
2064index b0179b8..b54c6c1 100644
2065--- a/arch/arm/kernel/traps.c
2066+++ b/arch/arm/kernel/traps.c
2067@@ -266,6 +266,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
2068 static int die_owner = -1;
2069 static unsigned int die_nest_count;
2070
2071+extern void gr_handle_kernel_exploit(void);
2072+
2073 static unsigned long oops_begin(void)
2074 {
2075 int cpu;
2076@@ -308,6 +310,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
2077 panic("Fatal exception in interrupt");
2078 if (panic_on_oops)
2079 panic("Fatal exception");
2080+
2081+ gr_handle_kernel_exploit();
2082+
2083 if (signr)
2084 do_exit(signr);
2085 }
2086diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
2087index 36ff15b..75d9e9d 100644
2088--- a/arch/arm/kernel/vmlinux.lds.S
2089+++ b/arch/arm/kernel/vmlinux.lds.S
2090@@ -8,7 +8,11 @@
2091 #include <asm/thread_info.h>
2092 #include <asm/memory.h>
2093 #include <asm/page.h>
2094-
2095+
2096+#ifdef CONFIG_PAX_KERNEXEC
2097+#include <asm/pgtable.h>
2098+#endif
2099+
2100 #define PROC_INFO \
2101 . = ALIGN(4); \
2102 VMLINUX_SYMBOL(__proc_info_begin) = .; \
2103@@ -90,6 +94,11 @@ SECTIONS
2104 _text = .;
2105 HEAD_TEXT
2106 }
2107+
2108+#ifdef CONFIG_PAX_KERNEXEC
2109+ . = ALIGN(1<<SECTION_SHIFT);
2110+#endif
2111+
2112 .text : { /* Real text segment */
2113 _stext = .; /* Text and read-only data */
2114 __exception_text_start = .;
2115@@ -133,6 +142,10 @@ SECTIONS
2116
2117 _etext = .; /* End of text and rodata section */
2118
2119+#ifdef CONFIG_PAX_KERNEXEC
2120+ . = ALIGN(1<<SECTION_SHIFT);
2121+#endif
2122+
2123 #ifndef CONFIG_XIP_KERNEL
2124 . = ALIGN(PAGE_SIZE);
2125 __init_begin = .;
2126@@ -192,6 +205,11 @@ SECTIONS
2127 . = PAGE_OFFSET + TEXT_OFFSET;
2128 #else
2129 __init_end = .;
2130+
2131+#ifdef CONFIG_PAX_KERNEXEC
2132+ . = ALIGN(1<<SECTION_SHIFT);
2133+#endif
2134+
2135 . = ALIGN(THREAD_SIZE);
2136 __data_loc = .;
2137 #endif
2138diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
2139index 66a477a..bee61d3 100644
2140--- a/arch/arm/lib/copy_from_user.S
2141+++ b/arch/arm/lib/copy_from_user.S
2142@@ -16,7 +16,7 @@
2143 /*
2144 * Prototype:
2145 *
2146- * size_t __copy_from_user(void *to, const void *from, size_t n)
2147+ * size_t ___copy_from_user(void *to, const void *from, size_t n)
2148 *
2149 * Purpose:
2150 *
2151@@ -84,11 +84,11 @@
2152
2153 .text
2154
2155-ENTRY(__copy_from_user)
2156+ENTRY(___copy_from_user)
2157
2158 #include "copy_template.S"
2159
2160-ENDPROC(__copy_from_user)
2161+ENDPROC(___copy_from_user)
2162
2163 .pushsection .fixup,"ax"
2164 .align 0
2165diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
2166index 6ee2f67..d1cce76 100644
2167--- a/arch/arm/lib/copy_page.S
2168+++ b/arch/arm/lib/copy_page.S
2169@@ -10,6 +10,7 @@
2170 * ASM optimised string functions
2171 */
2172 #include <linux/linkage.h>
2173+#include <linux/const.h>
2174 #include <asm/assembler.h>
2175 #include <asm/asm-offsets.h>
2176 #include <asm/cache.h>
2177diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
2178index d066df6..df28194 100644
2179--- a/arch/arm/lib/copy_to_user.S
2180+++ b/arch/arm/lib/copy_to_user.S
2181@@ -16,7 +16,7 @@
2182 /*
2183 * Prototype:
2184 *
2185- * size_t __copy_to_user(void *to, const void *from, size_t n)
2186+ * size_t ___copy_to_user(void *to, const void *from, size_t n)
2187 *
2188 * Purpose:
2189 *
2190@@ -88,11 +88,11 @@
2191 .text
2192
2193 ENTRY(__copy_to_user_std)
2194-WEAK(__copy_to_user)
2195+WEAK(___copy_to_user)
2196
2197 #include "copy_template.S"
2198
2199-ENDPROC(__copy_to_user)
2200+ENDPROC(___copy_to_user)
2201 ENDPROC(__copy_to_user_std)
2202
2203 .pushsection .fixup,"ax"
2204diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
2205index 0dc5385..45833ef 100644
2206--- a/arch/arm/lib/delay.c
2207+++ b/arch/arm/lib/delay.c
2208@@ -28,12 +28,14 @@
2209 /*
2210 * Default to the loop-based delay implementation.
2211 */
2212-struct arm_delay_ops arm_delay_ops = {
2213+static struct arm_delay_ops arm_loop_delay_ops = {
2214 .delay = __loop_delay,
2215 .const_udelay = __loop_const_udelay,
2216 .udelay = __loop_udelay,
2217 };
2218
2219+struct arm_delay_ops *arm_delay_ops __read_only = &arm_loop_delay_ops;
2220+
2221 static const struct delay_timer *delay_timer;
2222 static bool delay_calibrated;
2223
2224@@ -67,6 +69,12 @@ static void __timer_udelay(unsigned long usecs)
2225 __timer_const_udelay(usecs * UDELAY_MULT);
2226 }
2227
2228+static struct arm_delay_ops arm_timer_delay_ops = {
2229+ .delay = __timer_delay,
2230+ .const_udelay = __timer_const_udelay,
2231+ .udelay = __timer_udelay,
2232+};
2233+
2234 void __init register_current_timer_delay(const struct delay_timer *timer)
2235 {
2236 if (!delay_calibrated) {
2237@@ -74,9 +82,7 @@ void __init register_current_timer_delay(const struct delay_timer *timer)
2238 delay_timer = timer;
2239 lpj_fine = timer->freq / HZ;
2240 loops_per_jiffy = lpj_fine;
2241- arm_delay_ops.delay = __timer_delay;
2242- arm_delay_ops.const_udelay = __timer_const_udelay;
2243- arm_delay_ops.udelay = __timer_udelay;
2244+ arm_delay_ops = &arm_timer_delay_ops;
2245 delay_calibrated = true;
2246 } else {
2247 pr_info("Ignoring duplicate/late registration of read_current_timer delay\n");
2248diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
2249index 025f742..8432b08 100644
2250--- a/arch/arm/lib/uaccess_with_memcpy.c
2251+++ b/arch/arm/lib/uaccess_with_memcpy.c
2252@@ -104,7 +104,7 @@ out:
2253 }
2254
2255 unsigned long
2256-__copy_to_user(void __user *to, const void *from, unsigned long n)
2257+___copy_to_user(void __user *to, const void *from, unsigned long n)
2258 {
2259 /*
2260 * This test is stubbed out of the main function above to keep
2261diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
2262index 2c6c218..f491e87 100644
2263--- a/arch/arm/mach-kirkwood/common.c
2264+++ b/arch/arm/mach-kirkwood/common.c
2265@@ -150,7 +150,7 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
2266 clk_gate_ops.disable(hw);
2267 }
2268
2269-static struct clk_ops clk_gate_fn_ops;
2270+static clk_ops_no_const clk_gate_fn_ops;
2271
2272 static struct clk __init *clk_register_gate_fn(struct device *dev,
2273 const char *name,
2274diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
2275index d95f727..12f10dd 100644
2276--- a/arch/arm/mach-omap2/board-n8x0.c
2277+++ b/arch/arm/mach-omap2/board-n8x0.c
2278@@ -589,7 +589,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
2279 }
2280 #endif
2281
2282-static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
2283+static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
2284 .late_init = n8x0_menelaus_late_init,
2285 };
2286
2287diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
2288index 87cc6d0..fd4f248 100644
2289--- a/arch/arm/mach-omap2/omap_hwmod.c
2290+++ b/arch/arm/mach-omap2/omap_hwmod.c
2291@@ -189,10 +189,10 @@ struct omap_hwmod_soc_ops {
2292 int (*is_hardreset_asserted)(struct omap_hwmod *oh,
2293 struct omap_hwmod_rst_info *ohri);
2294 int (*init_clkdm)(struct omap_hwmod *oh);
2295-};
2296+} __no_const;
2297
2298 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
2299-static struct omap_hwmod_soc_ops soc_ops;
2300+static struct omap_hwmod_soc_ops soc_ops __read_only;
2301
2302 /* omap_hwmod_list contains all registered struct omap_hwmods */
2303 static LIST_HEAD(omap_hwmod_list);
2304diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
2305index 5dbf13f..9be36fd 100644
2306--- a/arch/arm/mm/fault.c
2307+++ b/arch/arm/mm/fault.c
2308@@ -25,6 +25,7 @@
2309 #include <asm/system_misc.h>
2310 #include <asm/system_info.h>
2311 #include <asm/tlbflush.h>
2312+#include <asm/sections.h>
2313
2314 #include "fault.h"
2315
2316@@ -138,6 +139,19 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
2317 if (fixup_exception(regs))
2318 return;
2319
2320+#ifdef CONFIG_PAX_KERNEXEC
2321+ if (fsr & FSR_WRITE) {
2322+ if (((unsigned long)_stext <= addr && addr < init_mm.end_code) || (MODULES_VADDR <= addr && addr < MODULES_END)) {
2323+ if (current->signal->curr_ip)
2324+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
2325+ &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
2326+ else
2327+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
2328+ current->comm, task_pid_nr(current), current_uid(), current_euid());
2329+ }
2330+ }
2331+#endif
2332+
2333 /*
2334 * No handler, we'll have to terminate things with extreme prejudice.
2335 */
2336@@ -174,6 +188,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
2337 }
2338 #endif
2339
2340+#ifdef CONFIG_PAX_PAGEEXEC
2341+ if (fsr & FSR_LNX_PF) {
2342+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
2343+ do_group_exit(SIGKILL);
2344+ }
2345+#endif
2346+
2347 tsk->thread.address = addr;
2348 tsk->thread.error_code = fsr;
2349 tsk->thread.trap_no = 14;
2350@@ -398,6 +419,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
2351 }
2352 #endif /* CONFIG_MMU */
2353
2354+#ifdef CONFIG_PAX_PAGEEXEC
2355+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2356+{
2357+ long i;
2358+
2359+ printk(KERN_ERR "PAX: bytes at PC: ");
2360+ for (i = 0; i < 20; i++) {
2361+ unsigned char c;
2362+ if (get_user(c, (__force unsigned char __user *)pc+i))
2363+ printk(KERN_CONT "?? ");
2364+ else
2365+ printk(KERN_CONT "%02x ", c);
2366+ }
2367+ printk("\n");
2368+
2369+ printk(KERN_ERR "PAX: bytes at SP-4: ");
2370+ for (i = -1; i < 20; i++) {
2371+ unsigned long c;
2372+ if (get_user(c, (__force unsigned long __user *)sp+i))
2373+ printk(KERN_CONT "???????? ");
2374+ else
2375+ printk(KERN_CONT "%08lx ", c);
2376+ }
2377+ printk("\n");
2378+}
2379+#endif
2380+
2381 /*
2382 * First Level Translation Fault Handler
2383 *
2384@@ -575,12 +623,41 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
2385 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
2386 struct siginfo info;
2387
2388+#ifdef CONFIG_PAX_KERNEXEC
2389+ if (!user_mode(regs) && is_xn_fault(ifsr)) {
2390+ if (current->signal->curr_ip)
2391+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n",
2392+ &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid(),
2393+ addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
2394+ else
2395+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n",
2396+ current->comm, task_pid_nr(current), current_uid(), current_euid(),
2397+ addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
2398+ goto die;
2399+ }
2400+#endif
2401+
2402+#ifdef CONFIG_PAX_REFCOUNT
2403+ if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
2404+ unsigned int bkpt;
2405+
2406+ if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
2407+ current->thread.error_code = ifsr;
2408+ current->thread.trap_no = 0;
2409+ pax_report_refcount_overflow(regs);
2410+ fixup_exception(regs);
2411+ return;
2412+ }
2413+ }
2414+#endif
2415+
2416 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
2417 return;
2418
2419 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
2420 inf->name, ifsr, addr);
2421
2422+die:
2423 info.si_signo = inf->sig;
2424 info.si_errno = 0;
2425 info.si_code = inf->code;
2426diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
2427index cf08bdf..f1a0383 100644
2428--- a/arch/arm/mm/fault.h
2429+++ b/arch/arm/mm/fault.h
2430@@ -3,6 +3,7 @@
2431
2432 /*
2433 * Fault status register encodings. We steal bit 31 for our own purposes.
2434+ * Set when the FSR value is from an instruction fault.
2435 */
2436 #define FSR_LNX_PF (1 << 31)
2437 #define FSR_WRITE (1 << 11)
2438@@ -22,6 +23,12 @@ static inline int fsr_fs(unsigned int fsr)
2439 }
2440 #endif
2441
2442+/* valid for LPAE and !LPAE */
2443+static inline int is_xn_fault(unsigned int fsr)
2444+{
2445+ return ((fsr_fs(fsr) & 0x3c) == 0xc);
2446+}
2447+
2448 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
2449 unsigned long search_exception_table(unsigned long addr);
2450
2451diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
2452index ad722f1..46b670e 100644
2453--- a/arch/arm/mm/init.c
2454+++ b/arch/arm/mm/init.c
2455@@ -734,9 +734,43 @@ void __init mem_init(void)
2456
2457 void free_initmem(void)
2458 {
2459+
2460+#ifdef CONFIG_PAX_KERNEXEC
2461+ unsigned long addr;
2462+ pgd_t *pgd;
2463+ pud_t *pud;
2464+ pmd_t *pmd;
2465+#endif
2466+
2467 #ifdef CONFIG_HAVE_TCM
2468 extern char __tcm_start, __tcm_end;
2469+#endif
2470
2471+#ifdef CONFIG_PAX_KERNEXEC
2472+ /* make pages tables, etc before .text NX */
2473+ for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += PMD_SIZE) {
2474+ pgd = pgd_offset_k(addr);
2475+ pud = pud_offset(pgd, addr);
2476+ pmd = pmd_offset(pud, addr);
2477+ __pmd_update(pmd, PMD_SECT_XN);
2478+ }
2479+ /* make init NX */
2480+ for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += PMD_SIZE) {
2481+ pgd = pgd_offset_k(addr);
2482+ pud = pud_offset(pgd, addr);
2483+ pmd = pmd_offset(pud, addr);
2484+ __pmd_update(pmd, PMD_SECT_XN);
2485+ }
2486+ /* make kernel code/rodata read-only */
2487+ for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += PMD_SIZE) {
2488+ pgd = pgd_offset_k(addr);
2489+ pud = pud_offset(pgd, addr);
2490+ pmd = pmd_offset(pud, addr);
2491+ __pmd_update(pmd, PMD_SECT_AP_RDONLY);
2492+ }
2493+#endif
2494+
2495+#ifdef CONFIG_HAVE_TCM
2496 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
2497 totalram_pages += free_area(__phys_to_pfn(__pa(&__tcm_start)),
2498 __phys_to_pfn(__pa(&__tcm_end)),
2499diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
2500index ce8cb19..3ec539d 100644
2501--- a/arch/arm/mm/mmap.c
2502+++ b/arch/arm/mm/mmap.c
2503@@ -93,6 +93,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
2504 if (len > TASK_SIZE)
2505 return -ENOMEM;
2506
2507+#ifdef CONFIG_PAX_RANDMMAP
2508+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
2509+#endif
2510+
2511 if (addr) {
2512 if (do_align)
2513 addr = COLOUR_ALIGN(addr, pgoff);
2514@@ -100,15 +104,14 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
2515 addr = PAGE_ALIGN(addr);
2516
2517 vma = find_vma(mm, addr);
2518- if (TASK_SIZE - len >= addr &&
2519- (!vma || addr + len <= vma->vm_start))
2520+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
2521 return addr;
2522 }
2523 if (len > mm->cached_hole_size) {
2524- start_addr = addr = mm->free_area_cache;
2525+ start_addr = addr = mm->free_area_cache;
2526 } else {
2527- start_addr = addr = mm->mmap_base;
2528- mm->cached_hole_size = 0;
2529+ start_addr = addr = mm->mmap_base;
2530+ mm->cached_hole_size = 0;
2531 }
2532
2533 full_search:
2534@@ -124,14 +127,14 @@ full_search:
2535 * Start a new search - just in case we missed
2536 * some holes.
2537 */
2538- if (start_addr != TASK_UNMAPPED_BASE) {
2539- start_addr = addr = TASK_UNMAPPED_BASE;
2540+ if (start_addr != mm->mmap_base) {
2541+ start_addr = addr = mm->mmap_base;
2542 mm->cached_hole_size = 0;
2543 goto full_search;
2544 }
2545 return -ENOMEM;
2546 }
2547- if (!vma || addr + len <= vma->vm_start) {
2548+ if (check_heap_stack_gap(vma, addr, len)) {
2549 /*
2550 * Remember the place where we stopped the search:
2551 */
2552@@ -266,10 +269,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
2553
2554 if (mmap_is_legacy()) {
2555 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
2556+
2557+#ifdef CONFIG_PAX_RANDMMAP
2558+ if (mm->pax_flags & MF_PAX_RANDMMAP)
2559+ mm->mmap_base += mm->delta_mmap;
2560+#endif
2561+
2562 mm->get_unmapped_area = arch_get_unmapped_area;
2563 mm->unmap_area = arch_unmap_area;
2564 } else {
2565 mm->mmap_base = mmap_base(random_factor);
2566+
2567+#ifdef CONFIG_PAX_RANDMMAP
2568+ if (mm->pax_flags & MF_PAX_RANDMMAP)
2569+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
2570+#endif
2571+
2572 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
2573 mm->unmap_area = arch_unmap_area_topdown;
2574 }
2575diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
2576index 941dfb9..af59618 100644
2577--- a/arch/arm/mm/mmu.c
2578+++ b/arch/arm/mm/mmu.c
2579@@ -227,16 +227,16 @@ static struct mem_type mem_types[] = {
2580 [MT_UNCACHED] = {
2581 .prot_pte = PROT_PTE_DEVICE,
2582 .prot_l1 = PMD_TYPE_TABLE,
2583- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
2584+ .prot_sect = PROT_SECT_DEVICE | PMD_SECT_XN,
2585 .domain = DOMAIN_IO,
2586 },
2587 [MT_CACHECLEAN] = {
2588- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
2589+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_AP_RDONLY,
2590 .domain = DOMAIN_KERNEL,
2591 },
2592 #ifndef CONFIG_ARM_LPAE
2593 [MT_MINICLEAN] = {
2594- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
2595+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE | PMD_SECT_AP_RDONLY,
2596 .domain = DOMAIN_KERNEL,
2597 },
2598 #endif
2599@@ -258,8 +258,26 @@ static struct mem_type mem_types[] = {
2600 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
2601 .domain = DOMAIN_KERNEL,
2602 },
2603+ [MT_MEMORY_R] = {
2604+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_RDONLY | L_PTE_XN,
2605+ .prot_l1 = PMD_TYPE_TABLE,
2606+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_RDONLY | PMD_SECT_XN,
2607+ .domain = DOMAIN_KERNEL,
2608+ },
2609+ [MT_MEMORY_RW] = {
2610+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY | L_PTE_XN,
2611+ .prot_l1 = PMD_TYPE_TABLE,
2612+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_SECT_XN,
2613+ .domain = DOMAIN_KERNEL,
2614+ },
2615+ [MT_MEMORY_RX] = {
2616+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_RDONLY,
2617+ .prot_l1 = PMD_TYPE_TABLE,
2618+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_RDONLY,
2619+ .domain = DOMAIN_KERNEL,
2620+ },
2621 [MT_ROM] = {
2622- .prot_sect = PMD_TYPE_SECT,
2623+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_RDONLY,
2624 .domain = DOMAIN_KERNEL,
2625 },
2626 [MT_MEMORY_NONCACHED] = {
2627@@ -273,7 +291,7 @@ static struct mem_type mem_types[] = {
2628 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
2629 L_PTE_XN,
2630 .prot_l1 = PMD_TYPE_TABLE,
2631- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
2632+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_AP_RDONLY,
2633 .domain = DOMAIN_KERNEL,
2634 },
2635 [MT_MEMORY_ITCM] = {
2636@@ -432,6 +450,8 @@ static void __init build_mem_type_table(void)
2637 * from SVC mode and no access from userspace.
2638 */
2639 mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
2640+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
2641+ mem_types[MT_MEMORY_R].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
2642 mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
2643 mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
2644 #endif
2645@@ -450,6 +470,12 @@ static void __init build_mem_type_table(void)
2646 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
2647 mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
2648 mem_types[MT_MEMORY].prot_pte |= L_PTE_SHARED;
2649+ mem_types[MT_MEMORY_R].prot_sect |= PMD_SECT_S;
2650+ mem_types[MT_MEMORY_R].prot_pte |= L_PTE_SHARED;
2651+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
2652+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
2653+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
2654+ mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
2655 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
2656 mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_S;
2657 mem_types[MT_MEMORY_NONCACHED].prot_pte |= L_PTE_SHARED;
2658@@ -503,6 +529,12 @@ static void __init build_mem_type_table(void)
2659 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
2660 mem_types[MT_MEMORY].prot_sect |= ecc_mask | cp->pmd;
2661 mem_types[MT_MEMORY].prot_pte |= kern_pgprot;
2662+ mem_types[MT_MEMORY_R].prot_sect |= ecc_mask | cp->pmd;
2663+ mem_types[MT_MEMORY_R].prot_pte |= kern_pgprot;
2664+ mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
2665+ mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
2666+ mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
2667+ mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
2668 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
2669 mem_types[MT_MEMORY_NONCACHED].prot_sect |= ecc_mask;
2670 mem_types[MT_ROM].prot_sect |= cp->pmd;
2671@@ -1198,8 +1230,37 @@ static void __init map_lowmem(void)
2672 map.pfn = __phys_to_pfn(start);
2673 map.virtual = __phys_to_virt(start);
2674 map.length = end - start;
2675- map.type = MT_MEMORY;
2676
2677+ if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
2678+ struct map_desc kernel;
2679+ struct map_desc initmap;
2680+
2681+ /* when freeing initmem we will make this RW */
2682+ initmap.pfn = __phys_to_pfn(__pa(__init_begin));
2683+ initmap.virtual = (unsigned long)__init_begin;
2684+ initmap.length = _sdata - __init_begin;
2685+ initmap.type = MT_MEMORY;
2686+ create_mapping(&initmap);
2687+
2688+ /* when freeing initmem we will make this RX */
2689+ kernel.pfn = __phys_to_pfn(__pa(_stext));
2690+ kernel.virtual = (unsigned long)_stext;
2691+ kernel.length = __init_begin - _stext;
2692+ kernel.type = MT_MEMORY;
2693+ create_mapping(&kernel);
2694+
2695+ if (map.virtual < (unsigned long)_stext) {
2696+ map.length = (unsigned long)_stext - map.virtual;
2697+ map.type = MT_MEMORY;
2698+ create_mapping(&map);
2699+ }
2700+
2701+ map.pfn = __phys_to_pfn(__pa(_sdata));
2702+ map.virtual = (unsigned long)_sdata;
2703+ map.length = end - __pa(_sdata);
2704+ }
2705+
2706+ map.type = MT_MEMORY_RW;
2707 create_mapping(&map);
2708 }
2709 }
2710diff --git a/arch/arm/plat-orion/include/plat/addr-map.h b/arch/arm/plat-orion/include/plat/addr-map.h
2711index ec63e4a..62aa5f1d 100644
2712--- a/arch/arm/plat-orion/include/plat/addr-map.h
2713+++ b/arch/arm/plat-orion/include/plat/addr-map.h
2714@@ -26,7 +26,7 @@ struct orion_addr_map_cfg {
2715 value in bridge_virt_base */
2716 void __iomem *(*win_cfg_base) (const struct orion_addr_map_cfg *cfg,
2717 const int win);
2718-};
2719+} __no_const;
2720
2721 /*
2722 * Information needed to setup one address mapping.
2723diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
2724index f5144cd..71f6d1f 100644
2725--- a/arch/arm/plat-samsung/include/plat/dma-ops.h
2726+++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
2727@@ -47,7 +47,7 @@ struct samsung_dma_ops {
2728 int (*started)(unsigned ch);
2729 int (*flush)(unsigned ch);
2730 int (*stop)(unsigned ch);
2731-};
2732+} __no_const;
2733
2734 extern void *samsung_dmadev_get_ops(void);
2735 extern void *s3c_dma_get_ops(void);
2736diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
2737index c3a58a1..78fbf54 100644
2738--- a/arch/avr32/include/asm/cache.h
2739+++ b/arch/avr32/include/asm/cache.h
2740@@ -1,8 +1,10 @@
2741 #ifndef __ASM_AVR32_CACHE_H
2742 #define __ASM_AVR32_CACHE_H
2743
2744+#include <linux/const.h>
2745+
2746 #define L1_CACHE_SHIFT 5
2747-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2748+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2749
2750 /*
2751 * Memory returned by kmalloc() may be used for DMA, so we must make
2752diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
2753index e2c3287..6c4f98c 100644
2754--- a/arch/avr32/include/asm/elf.h
2755+++ b/arch/avr32/include/asm/elf.h
2756@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
2757 the loader. We need to make sure that it is out of the way of the program
2758 that it will "exec", and that there is sufficient room for the brk. */
2759
2760-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
2761+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2762
2763+#ifdef CONFIG_PAX_ASLR
2764+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
2765+
2766+#define PAX_DELTA_MMAP_LEN 15
2767+#define PAX_DELTA_STACK_LEN 15
2768+#endif
2769
2770 /* This yields a mask that user programs can use to figure out what
2771 instruction set this CPU supports. This could be done in user space,
2772diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
2773index 479330b..53717a8 100644
2774--- a/arch/avr32/include/asm/kmap_types.h
2775+++ b/arch/avr32/include/asm/kmap_types.h
2776@@ -2,9 +2,9 @@
2777 #define __ASM_AVR32_KMAP_TYPES_H
2778
2779 #ifdef CONFIG_DEBUG_HIGHMEM
2780-# define KM_TYPE_NR 29
2781+# define KM_TYPE_NR 30
2782 #else
2783-# define KM_TYPE_NR 14
2784+# define KM_TYPE_NR 15
2785 #endif
2786
2787 #endif /* __ASM_AVR32_KMAP_TYPES_H */
2788diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
2789index b2f2d2d..d1c85cb 100644
2790--- a/arch/avr32/mm/fault.c
2791+++ b/arch/avr32/mm/fault.c
2792@@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
2793
2794 int exception_trace = 1;
2795
2796+#ifdef CONFIG_PAX_PAGEEXEC
2797+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2798+{
2799+ unsigned long i;
2800+
2801+ printk(KERN_ERR "PAX: bytes at PC: ");
2802+ for (i = 0; i < 20; i++) {
2803+ unsigned char c;
2804+ if (get_user(c, (unsigned char *)pc+i))
2805+ printk(KERN_CONT "???????? ");
2806+ else
2807+ printk(KERN_CONT "%02x ", c);
2808+ }
2809+ printk("\n");
2810+}
2811+#endif
2812+
2813 /*
2814 * This routine handles page faults. It determines the address and the
2815 * problem, and then passes it off to one of the appropriate routines.
2816@@ -174,6 +191,16 @@ bad_area:
2817 up_read(&mm->mmap_sem);
2818
2819 if (user_mode(regs)) {
2820+
2821+#ifdef CONFIG_PAX_PAGEEXEC
2822+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
2823+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
2824+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
2825+ do_group_exit(SIGKILL);
2826+ }
2827+ }
2828+#endif
2829+
2830 if (exception_trace && printk_ratelimit())
2831 printk("%s%s[%d]: segfault at %08lx pc %08lx "
2832 "sp %08lx ecr %lu\n",
2833diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
2834index 568885a..f8008df 100644
2835--- a/arch/blackfin/include/asm/cache.h
2836+++ b/arch/blackfin/include/asm/cache.h
2837@@ -7,6 +7,7 @@
2838 #ifndef __ARCH_BLACKFIN_CACHE_H
2839 #define __ARCH_BLACKFIN_CACHE_H
2840
2841+#include <linux/const.h>
2842 #include <linux/linkage.h> /* for asmlinkage */
2843
2844 /*
2845@@ -14,7 +15,7 @@
2846 * Blackfin loads 32 bytes for cache
2847 */
2848 #define L1_CACHE_SHIFT 5
2849-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2850+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2851 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2852
2853 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2854diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
2855index aea2718..3639a60 100644
2856--- a/arch/cris/include/arch-v10/arch/cache.h
2857+++ b/arch/cris/include/arch-v10/arch/cache.h
2858@@ -1,8 +1,9 @@
2859 #ifndef _ASM_ARCH_CACHE_H
2860 #define _ASM_ARCH_CACHE_H
2861
2862+#include <linux/const.h>
2863 /* Etrax 100LX have 32-byte cache-lines. */
2864-#define L1_CACHE_BYTES 32
2865 #define L1_CACHE_SHIFT 5
2866+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2867
2868 #endif /* _ASM_ARCH_CACHE_H */
2869diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
2870index 7caf25d..ee65ac5 100644
2871--- a/arch/cris/include/arch-v32/arch/cache.h
2872+++ b/arch/cris/include/arch-v32/arch/cache.h
2873@@ -1,11 +1,12 @@
2874 #ifndef _ASM_CRIS_ARCH_CACHE_H
2875 #define _ASM_CRIS_ARCH_CACHE_H
2876
2877+#include <linux/const.h>
2878 #include <arch/hwregs/dma.h>
2879
2880 /* A cache-line is 32 bytes. */
2881-#define L1_CACHE_BYTES 32
2882 #define L1_CACHE_SHIFT 5
2883+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2884
2885 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
2886
2887diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
2888index b86329d..6709906 100644
2889--- a/arch/frv/include/asm/atomic.h
2890+++ b/arch/frv/include/asm/atomic.h
2891@@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
2892 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
2893 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
2894
2895+#define atomic64_read_unchecked(v) atomic64_read(v)
2896+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2897+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2898+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2899+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2900+#define atomic64_inc_unchecked(v) atomic64_inc(v)
2901+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2902+#define atomic64_dec_unchecked(v) atomic64_dec(v)
2903+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2904+
2905 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
2906 {
2907 int c, old;
2908diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
2909index 2797163..c2a401d 100644
2910--- a/arch/frv/include/asm/cache.h
2911+++ b/arch/frv/include/asm/cache.h
2912@@ -12,10 +12,11 @@
2913 #ifndef __ASM_CACHE_H
2914 #define __ASM_CACHE_H
2915
2916+#include <linux/const.h>
2917
2918 /* bytes per L1 cache line */
2919 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
2920-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2921+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2922
2923 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2924 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2925diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
2926index 43901f2..0d8b865 100644
2927--- a/arch/frv/include/asm/kmap_types.h
2928+++ b/arch/frv/include/asm/kmap_types.h
2929@@ -2,6 +2,6 @@
2930 #ifndef _ASM_KMAP_TYPES_H
2931 #define _ASM_KMAP_TYPES_H
2932
2933-#define KM_TYPE_NR 17
2934+#define KM_TYPE_NR 18
2935
2936 #endif
2937diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
2938index 385fd30..6c3d97e 100644
2939--- a/arch/frv/mm/elf-fdpic.c
2940+++ b/arch/frv/mm/elf-fdpic.c
2941@@ -73,8 +73,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2942 if (addr) {
2943 addr = PAGE_ALIGN(addr);
2944 vma = find_vma(current->mm, addr);
2945- if (TASK_SIZE - len >= addr &&
2946- (!vma || addr + len <= vma->vm_start))
2947+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
2948 goto success;
2949 }
2950
2951@@ -89,7 +88,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2952 for (; vma; vma = vma->vm_next) {
2953 if (addr > limit)
2954 break;
2955- if (addr + len <= vma->vm_start)
2956+ if (check_heap_stack_gap(vma, addr, len))
2957 goto success;
2958 addr = vma->vm_end;
2959 }
2960@@ -104,7 +103,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2961 for (; vma; vma = vma->vm_next) {
2962 if (addr > limit)
2963 break;
2964- if (addr + len <= vma->vm_start)
2965+ if (check_heap_stack_gap(vma, addr, len))
2966 goto success;
2967 addr = vma->vm_end;
2968 }
2969diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
2970index f4ca594..adc72fd6 100644
2971--- a/arch/hexagon/include/asm/cache.h
2972+++ b/arch/hexagon/include/asm/cache.h
2973@@ -21,9 +21,11 @@
2974 #ifndef __ASM_CACHE_H
2975 #define __ASM_CACHE_H
2976
2977+#include <linux/const.h>
2978+
2979 /* Bytes per L1 cache line */
2980-#define L1_CACHE_SHIFT (5)
2981-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2982+#define L1_CACHE_SHIFT 5
2983+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2984
2985 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
2986 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
2987diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
2988index 6e6fe18..a6ae668 100644
2989--- a/arch/ia64/include/asm/atomic.h
2990+++ b/arch/ia64/include/asm/atomic.h
2991@@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
2992 #define atomic64_inc(v) atomic64_add(1, (v))
2993 #define atomic64_dec(v) atomic64_sub(1, (v))
2994
2995+#define atomic64_read_unchecked(v) atomic64_read(v)
2996+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2997+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2998+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2999+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3000+#define atomic64_inc_unchecked(v) atomic64_inc(v)
3001+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3002+#define atomic64_dec_unchecked(v) atomic64_dec(v)
3003+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3004+
3005 /* Atomic operations are already serializing */
3006 #define smp_mb__before_atomic_dec() barrier()
3007 #define smp_mb__after_atomic_dec() barrier()
3008diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
3009index 988254a..e1ee885 100644
3010--- a/arch/ia64/include/asm/cache.h
3011+++ b/arch/ia64/include/asm/cache.h
3012@@ -1,6 +1,7 @@
3013 #ifndef _ASM_IA64_CACHE_H
3014 #define _ASM_IA64_CACHE_H
3015
3016+#include <linux/const.h>
3017
3018 /*
3019 * Copyright (C) 1998-2000 Hewlett-Packard Co
3020@@ -9,7 +10,7 @@
3021
3022 /* Bytes per L1 (data) cache line. */
3023 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
3024-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3025+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3026
3027 #ifdef CONFIG_SMP
3028 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
3029diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
3030index b5298eb..67c6e62 100644
3031--- a/arch/ia64/include/asm/elf.h
3032+++ b/arch/ia64/include/asm/elf.h
3033@@ -42,6 +42,13 @@
3034 */
3035 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
3036
3037+#ifdef CONFIG_PAX_ASLR
3038+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
3039+
3040+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
3041+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
3042+#endif
3043+
3044 #define PT_IA_64_UNWIND 0x70000001
3045
3046 /* IA-64 relocations: */
3047diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
3048index 96a8d92..617a1cf 100644
3049--- a/arch/ia64/include/asm/pgalloc.h
3050+++ b/arch/ia64/include/asm/pgalloc.h
3051@@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
3052 pgd_val(*pgd_entry) = __pa(pud);
3053 }
3054
3055+static inline void
3056+pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
3057+{
3058+ pgd_populate(mm, pgd_entry, pud);
3059+}
3060+
3061 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
3062 {
3063 return quicklist_alloc(0, GFP_KERNEL, NULL);
3064@@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
3065 pud_val(*pud_entry) = __pa(pmd);
3066 }
3067
3068+static inline void
3069+pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
3070+{
3071+ pud_populate(mm, pud_entry, pmd);
3072+}
3073+
3074 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
3075 {
3076 return quicklist_alloc(0, GFP_KERNEL, NULL);
3077diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
3078index 815810c..d60bd4c 100644
3079--- a/arch/ia64/include/asm/pgtable.h
3080+++ b/arch/ia64/include/asm/pgtable.h
3081@@ -12,7 +12,7 @@
3082 * David Mosberger-Tang <davidm@hpl.hp.com>
3083 */
3084
3085-
3086+#include <linux/const.h>
3087 #include <asm/mman.h>
3088 #include <asm/page.h>
3089 #include <asm/processor.h>
3090@@ -142,6 +142,17 @@
3091 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
3092 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
3093 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
3094+
3095+#ifdef CONFIG_PAX_PAGEEXEC
3096+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
3097+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
3098+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
3099+#else
3100+# define PAGE_SHARED_NOEXEC PAGE_SHARED
3101+# define PAGE_READONLY_NOEXEC PAGE_READONLY
3102+# define PAGE_COPY_NOEXEC PAGE_COPY
3103+#endif
3104+
3105 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
3106 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
3107 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
3108diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
3109index 54ff557..70c88b7 100644
3110--- a/arch/ia64/include/asm/spinlock.h
3111+++ b/arch/ia64/include/asm/spinlock.h
3112@@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
3113 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
3114
3115 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
3116- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
3117+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
3118 }
3119
3120 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
3121diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
3122index 449c8c0..50cdf87 100644
3123--- a/arch/ia64/include/asm/uaccess.h
3124+++ b/arch/ia64/include/asm/uaccess.h
3125@@ -42,6 +42,8 @@
3126 #include <asm/pgtable.h>
3127 #include <asm/io.h>
3128
3129+extern void check_object_size(const void *ptr, unsigned long n, bool to);
3130+
3131 /*
3132 * For historical reasons, the following macros are grossly misnamed:
3133 */
3134@@ -240,12 +242,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
3135 static inline unsigned long
3136 __copy_to_user (void __user *to, const void *from, unsigned long count)
3137 {
3138+ if (count > INT_MAX)
3139+ return count;
3140+
3141+ if (!__builtin_constant_p(count))
3142+ check_object_size(from, count, true);
3143+
3144 return __copy_user(to, (__force void __user *) from, count);
3145 }
3146
3147 static inline unsigned long
3148 __copy_from_user (void *to, const void __user *from, unsigned long count)
3149 {
3150+ if (count > INT_MAX)
3151+ return count;
3152+
3153+ if (!__builtin_constant_p(count))
3154+ check_object_size(to, count, false);
3155+
3156 return __copy_user((__force void __user *) to, from, count);
3157 }
3158
3159@@ -255,10 +269,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
3160 ({ \
3161 void __user *__cu_to = (to); \
3162 const void *__cu_from = (from); \
3163- long __cu_len = (n); \
3164+ unsigned long __cu_len = (n); \
3165 \
3166- if (__access_ok(__cu_to, __cu_len, get_fs())) \
3167+ if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
3168+ if (!__builtin_constant_p(n)) \
3169+ check_object_size(__cu_from, __cu_len, true); \
3170 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
3171+ } \
3172 __cu_len; \
3173 })
3174
3175@@ -266,11 +283,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
3176 ({ \
3177 void *__cu_to = (to); \
3178 const void __user *__cu_from = (from); \
3179- long __cu_len = (n); \
3180+ unsigned long __cu_len = (n); \
3181 \
3182 __chk_user_ptr(__cu_from); \
3183- if (__access_ok(__cu_from, __cu_len, get_fs())) \
3184+ if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
3185+ if (!__builtin_constant_p(n)) \
3186+ check_object_size(__cu_to, __cu_len, false); \
3187 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
3188+ } \
3189 __cu_len; \
3190 })
3191
3192diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
3193index 24603be..948052d 100644
3194--- a/arch/ia64/kernel/module.c
3195+++ b/arch/ia64/kernel/module.c
3196@@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
3197 void
3198 module_free (struct module *mod, void *module_region)
3199 {
3200- if (mod && mod->arch.init_unw_table &&
3201- module_region == mod->module_init) {
3202+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
3203 unw_remove_unwind_table(mod->arch.init_unw_table);
3204 mod->arch.init_unw_table = NULL;
3205 }
3206@@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
3207 }
3208
3209 static inline int
3210+in_init_rx (const struct module *mod, uint64_t addr)
3211+{
3212+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
3213+}
3214+
3215+static inline int
3216+in_init_rw (const struct module *mod, uint64_t addr)
3217+{
3218+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
3219+}
3220+
3221+static inline int
3222 in_init (const struct module *mod, uint64_t addr)
3223 {
3224- return addr - (uint64_t) mod->module_init < mod->init_size;
3225+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
3226+}
3227+
3228+static inline int
3229+in_core_rx (const struct module *mod, uint64_t addr)
3230+{
3231+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
3232+}
3233+
3234+static inline int
3235+in_core_rw (const struct module *mod, uint64_t addr)
3236+{
3237+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
3238 }
3239
3240 static inline int
3241 in_core (const struct module *mod, uint64_t addr)
3242 {
3243- return addr - (uint64_t) mod->module_core < mod->core_size;
3244+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
3245 }
3246
3247 static inline int
3248@@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
3249 break;
3250
3251 case RV_BDREL:
3252- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
3253+ if (in_init_rx(mod, val))
3254+ val -= (uint64_t) mod->module_init_rx;
3255+ else if (in_init_rw(mod, val))
3256+ val -= (uint64_t) mod->module_init_rw;
3257+ else if (in_core_rx(mod, val))
3258+ val -= (uint64_t) mod->module_core_rx;
3259+ else if (in_core_rw(mod, val))
3260+ val -= (uint64_t) mod->module_core_rw;
3261 break;
3262
3263 case RV_LTV:
3264@@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
3265 * addresses have been selected...
3266 */
3267 uint64_t gp;
3268- if (mod->core_size > MAX_LTOFF)
3269+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
3270 /*
3271 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
3272 * at the end of the module.
3273 */
3274- gp = mod->core_size - MAX_LTOFF / 2;
3275+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
3276 else
3277- gp = mod->core_size / 2;
3278- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
3279+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
3280+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
3281 mod->arch.gp = gp;
3282 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
3283 }
3284diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
3285index d9439ef..b9a4303 100644
3286--- a/arch/ia64/kernel/sys_ia64.c
3287+++ b/arch/ia64/kernel/sys_ia64.c
3288@@ -43,6 +43,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
3289 if (REGION_NUMBER(addr) == RGN_HPAGE)
3290 addr = 0;
3291 #endif
3292+
3293+#ifdef CONFIG_PAX_RANDMMAP
3294+ if (mm->pax_flags & MF_PAX_RANDMMAP)
3295+ addr = mm->free_area_cache;
3296+ else
3297+#endif
3298+
3299 if (!addr)
3300 addr = mm->free_area_cache;
3301
3302@@ -61,14 +68,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
3303 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
3304 /* At this point: (!vma || addr < vma->vm_end). */
3305 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
3306- if (start_addr != TASK_UNMAPPED_BASE) {
3307+ if (start_addr != mm->mmap_base) {
3308 /* Start a new search --- just in case we missed some holes. */
3309- addr = TASK_UNMAPPED_BASE;
3310+ addr = mm->mmap_base;
3311 goto full_search;
3312 }
3313 return -ENOMEM;
3314 }
3315- if (!vma || addr + len <= vma->vm_start) {
3316+ if (check_heap_stack_gap(vma, addr, len)) {
3317 /* Remember the address where we stopped this search: */
3318 mm->free_area_cache = addr + len;
3319 return addr;
3320diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
3321index 0ccb28f..8992469 100644
3322--- a/arch/ia64/kernel/vmlinux.lds.S
3323+++ b/arch/ia64/kernel/vmlinux.lds.S
3324@@ -198,7 +198,7 @@ SECTIONS {
3325 /* Per-cpu data: */
3326 . = ALIGN(PERCPU_PAGE_SIZE);
3327 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
3328- __phys_per_cpu_start = __per_cpu_load;
3329+ __phys_per_cpu_start = per_cpu_load;
3330 /*
3331 * ensure percpu data fits
3332 * into percpu page size
3333diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
3334index 6cf0341..d352594 100644
3335--- a/arch/ia64/mm/fault.c
3336+++ b/arch/ia64/mm/fault.c
3337@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
3338 return pte_present(pte);
3339 }
3340
3341+#ifdef CONFIG_PAX_PAGEEXEC
3342+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3343+{
3344+ unsigned long i;
3345+
3346+ printk(KERN_ERR "PAX: bytes at PC: ");
3347+ for (i = 0; i < 8; i++) {
3348+ unsigned int c;
3349+ if (get_user(c, (unsigned int *)pc+i))
3350+ printk(KERN_CONT "???????? ");
3351+ else
3352+ printk(KERN_CONT "%08x ", c);
3353+ }
3354+ printk("\n");
3355+}
3356+#endif
3357+
3358 # define VM_READ_BIT 0
3359 # define VM_WRITE_BIT 1
3360 # define VM_EXEC_BIT 2
3361@@ -149,8 +166,21 @@ retry:
3362 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
3363 goto bad_area;
3364
3365- if ((vma->vm_flags & mask) != mask)
3366+ if ((vma->vm_flags & mask) != mask) {
3367+
3368+#ifdef CONFIG_PAX_PAGEEXEC
3369+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
3370+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
3371+ goto bad_area;
3372+
3373+ up_read(&mm->mmap_sem);
3374+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
3375+ do_group_exit(SIGKILL);
3376+ }
3377+#endif
3378+
3379 goto bad_area;
3380+ }
3381
3382 /*
3383 * If for any reason at all we couldn't handle the fault, make
3384diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
3385index 5ca674b..e0e1b70 100644
3386--- a/arch/ia64/mm/hugetlbpage.c
3387+++ b/arch/ia64/mm/hugetlbpage.c
3388@@ -171,7 +171,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
3389 /* At this point: (!vmm || addr < vmm->vm_end). */
3390 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
3391 return -ENOMEM;
3392- if (!vmm || (addr + len) <= vmm->vm_start)
3393+ if (check_heap_stack_gap(vmm, addr, len))
3394 return addr;
3395 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
3396 }
3397diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
3398index 082e383..fb7be80 100644
3399--- a/arch/ia64/mm/init.c
3400+++ b/arch/ia64/mm/init.c
3401@@ -120,6 +120,19 @@ ia64_init_addr_space (void)
3402 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
3403 vma->vm_end = vma->vm_start + PAGE_SIZE;
3404 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
3405+
3406+#ifdef CONFIG_PAX_PAGEEXEC
3407+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
3408+ vma->vm_flags &= ~VM_EXEC;
3409+
3410+#ifdef CONFIG_PAX_MPROTECT
3411+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
3412+ vma->vm_flags &= ~VM_MAYEXEC;
3413+#endif
3414+
3415+ }
3416+#endif
3417+
3418 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
3419 down_write(&current->mm->mmap_sem);
3420 if (insert_vm_struct(current->mm, vma)) {
3421diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
3422index 40b3ee9..8c2c112 100644
3423--- a/arch/m32r/include/asm/cache.h
3424+++ b/arch/m32r/include/asm/cache.h
3425@@ -1,8 +1,10 @@
3426 #ifndef _ASM_M32R_CACHE_H
3427 #define _ASM_M32R_CACHE_H
3428
3429+#include <linux/const.h>
3430+
3431 /* L1 cache line size */
3432 #define L1_CACHE_SHIFT 4
3433-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3434+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3435
3436 #endif /* _ASM_M32R_CACHE_H */
3437diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
3438index 82abd15..d95ae5d 100644
3439--- a/arch/m32r/lib/usercopy.c
3440+++ b/arch/m32r/lib/usercopy.c
3441@@ -14,6 +14,9 @@
3442 unsigned long
3443 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
3444 {
3445+ if ((long)n < 0)
3446+ return n;
3447+
3448 prefetch(from);
3449 if (access_ok(VERIFY_WRITE, to, n))
3450 __copy_user(to,from,n);
3451@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
3452 unsigned long
3453 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
3454 {
3455+ if ((long)n < 0)
3456+ return n;
3457+
3458 prefetchw(to);
3459 if (access_ok(VERIFY_READ, from, n))
3460 __copy_user_zeroing(to,from,n);
3461diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
3462index 0395c51..5f26031 100644
3463--- a/arch/m68k/include/asm/cache.h
3464+++ b/arch/m68k/include/asm/cache.h
3465@@ -4,9 +4,11 @@
3466 #ifndef __ARCH_M68K_CACHE_H
3467 #define __ARCH_M68K_CACHE_H
3468
3469+#include <linux/const.h>
3470+
3471 /* bytes per L1 cache line */
3472 #define L1_CACHE_SHIFT 4
3473-#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
3474+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3475
3476 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
3477
3478diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
3479index 4efe96a..60e8699 100644
3480--- a/arch/microblaze/include/asm/cache.h
3481+++ b/arch/microblaze/include/asm/cache.h
3482@@ -13,11 +13,12 @@
3483 #ifndef _ASM_MICROBLAZE_CACHE_H
3484 #define _ASM_MICROBLAZE_CACHE_H
3485
3486+#include <linux/const.h>
3487 #include <asm/registers.h>
3488
3489 #define L1_CACHE_SHIFT 5
3490 /* word-granular cache in microblaze */
3491-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3492+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3493
3494 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3495
3496diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
3497index 01cc6ba..bcb7a5d 100644
3498--- a/arch/mips/include/asm/atomic.h
3499+++ b/arch/mips/include/asm/atomic.h
3500@@ -21,6 +21,10 @@
3501 #include <asm/cmpxchg.h>
3502 #include <asm/war.h>
3503
3504+#ifdef CONFIG_GENERIC_ATOMIC64
3505+#include <asm-generic/atomic64.h>
3506+#endif
3507+
3508 #define ATOMIC_INIT(i) { (i) }
3509
3510 /*
3511@@ -759,6 +763,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
3512 */
3513 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
3514
3515+#define atomic64_read_unchecked(v) atomic64_read(v)
3516+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3517+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3518+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3519+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3520+#define atomic64_inc_unchecked(v) atomic64_inc(v)
3521+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3522+#define atomic64_dec_unchecked(v) atomic64_dec(v)
3523+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3524+
3525 #endif /* CONFIG_64BIT */
3526
3527 /*
3528diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
3529index b4db69f..8f3b093 100644
3530--- a/arch/mips/include/asm/cache.h
3531+++ b/arch/mips/include/asm/cache.h
3532@@ -9,10 +9,11 @@
3533 #ifndef _ASM_CACHE_H
3534 #define _ASM_CACHE_H
3535
3536+#include <linux/const.h>
3537 #include <kmalloc.h>
3538
3539 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
3540-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3541+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3542
3543 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
3544 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3545diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
3546index 455c0ac..ad65fbe 100644
3547--- a/arch/mips/include/asm/elf.h
3548+++ b/arch/mips/include/asm/elf.h
3549@@ -372,13 +372,16 @@ extern const char *__elf_platform;
3550 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
3551 #endif
3552
3553+#ifdef CONFIG_PAX_ASLR
3554+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
3555+
3556+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3557+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3558+#endif
3559+
3560 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
3561 struct linux_binprm;
3562 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
3563 int uses_interp);
3564
3565-struct mm_struct;
3566-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
3567-#define arch_randomize_brk arch_randomize_brk
3568-
3569 #endif /* _ASM_ELF_H */
3570diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
3571index c1f6afa..38cc6e9 100644
3572--- a/arch/mips/include/asm/exec.h
3573+++ b/arch/mips/include/asm/exec.h
3574@@ -12,6 +12,6 @@
3575 #ifndef _ASM_EXEC_H
3576 #define _ASM_EXEC_H
3577
3578-extern unsigned long arch_align_stack(unsigned long sp);
3579+#define arch_align_stack(x) ((x) & ~0xfUL)
3580
3581 #endif /* _ASM_EXEC_H */
3582diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
3583index da9bd7d..91aa7ab 100644
3584--- a/arch/mips/include/asm/page.h
3585+++ b/arch/mips/include/asm/page.h
3586@@ -98,7 +98,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
3587 #ifdef CONFIG_CPU_MIPS32
3588 typedef struct { unsigned long pte_low, pte_high; } pte_t;
3589 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
3590- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
3591+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
3592 #else
3593 typedef struct { unsigned long long pte; } pte_t;
3594 #define pte_val(x) ((x).pte)
3595diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
3596index 881d18b..cea38bc 100644
3597--- a/arch/mips/include/asm/pgalloc.h
3598+++ b/arch/mips/include/asm/pgalloc.h
3599@@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3600 {
3601 set_pud(pud, __pud((unsigned long)pmd));
3602 }
3603+
3604+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3605+{
3606+ pud_populate(mm, pud, pmd);
3607+}
3608 #endif
3609
3610 /*
3611diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
3612index 18806a5..141ffcf 100644
3613--- a/arch/mips/include/asm/thread_info.h
3614+++ b/arch/mips/include/asm/thread_info.h
3615@@ -110,6 +110,8 @@ register struct thread_info *__current_thread_info __asm__("$28");
3616 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
3617 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
3618 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
3619+/* li takes a 32bit immediate */
3620+#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
3621 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
3622
3623 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
3624@@ -125,15 +127,18 @@ register struct thread_info *__current_thread_info __asm__("$28");
3625 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
3626 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
3627 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
3628+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
3629+
3630+#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
3631
3632 /* work to do in syscall_trace_leave() */
3633-#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
3634+#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
3635
3636 /* work to do on interrupt/exception return */
3637 #define _TIF_WORK_MASK \
3638 (_TIF_SIGPENDING | _TIF_NEED_RESCHED | _TIF_NOTIFY_RESUME)
3639 /* work to do on any return to u-space */
3640-#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT)
3641+#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT | _TIF_GRSEC_SETXID)
3642
3643 #endif /* __KERNEL__ */
3644
3645diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
3646index 9fdd8bc..4bd7f1a 100644
3647--- a/arch/mips/kernel/binfmt_elfn32.c
3648+++ b/arch/mips/kernel/binfmt_elfn32.c
3649@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
3650 #undef ELF_ET_DYN_BASE
3651 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
3652
3653+#ifdef CONFIG_PAX_ASLR
3654+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
3655+
3656+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3657+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3658+#endif
3659+
3660 #include <asm/processor.h>
3661 #include <linux/module.h>
3662 #include <linux/elfcore.h>
3663diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
3664index ff44823..97f8906 100644
3665--- a/arch/mips/kernel/binfmt_elfo32.c
3666+++ b/arch/mips/kernel/binfmt_elfo32.c
3667@@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
3668 #undef ELF_ET_DYN_BASE
3669 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
3670
3671+#ifdef CONFIG_PAX_ASLR
3672+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
3673+
3674+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3675+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3676+#endif
3677+
3678 #include <asm/processor.h>
3679
3680 /*
3681diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
3682index e9a5fd7..378809a 100644
3683--- a/arch/mips/kernel/process.c
3684+++ b/arch/mips/kernel/process.c
3685@@ -480,15 +480,3 @@ unsigned long get_wchan(struct task_struct *task)
3686 out:
3687 return pc;
3688 }
3689-
3690-/*
3691- * Don't forget that the stack pointer must be aligned on a 8 bytes
3692- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
3693- */
3694-unsigned long arch_align_stack(unsigned long sp)
3695-{
3696- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
3697- sp -= get_random_int() & ~PAGE_MASK;
3698-
3699- return sp & ALMASK;
3700-}
3701diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
3702index 4812c6d..2069554 100644
3703--- a/arch/mips/kernel/ptrace.c
3704+++ b/arch/mips/kernel/ptrace.c
3705@@ -528,6 +528,10 @@ static inline int audit_arch(void)
3706 return arch;
3707 }
3708
3709+#ifdef CONFIG_GRKERNSEC_SETXID
3710+extern void gr_delayed_cred_worker(void);
3711+#endif
3712+
3713 /*
3714 * Notification of system call entry/exit
3715 * - triggered by current->work.syscall_trace
3716@@ -537,6 +541,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
3717 /* do the secure computing check first */
3718 secure_computing_strict(regs->regs[2]);
3719
3720+#ifdef CONFIG_GRKERNSEC_SETXID
3721+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
3722+ gr_delayed_cred_worker();
3723+#endif
3724+
3725 if (!(current->ptrace & PT_PTRACED))
3726 goto out;
3727
3728diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
3729index 374f66e..1c882a0 100644
3730--- a/arch/mips/kernel/scall32-o32.S
3731+++ b/arch/mips/kernel/scall32-o32.S
3732@@ -52,7 +52,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3733
3734 stack_done:
3735 lw t0, TI_FLAGS($28) # syscall tracing enabled?
3736- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3737+ li t1, _TIF_SYSCALL_WORK
3738 and t0, t1
3739 bnez t0, syscall_trace_entry # -> yes
3740
3741diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
3742index 169de6a..f594a89 100644
3743--- a/arch/mips/kernel/scall64-64.S
3744+++ b/arch/mips/kernel/scall64-64.S
3745@@ -54,7 +54,7 @@ NESTED(handle_sys64, PT_SIZE, sp)
3746
3747 sd a3, PT_R26(sp) # save a3 for syscall restarting
3748
3749- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3750+ li t1, _TIF_SYSCALL_WORK
3751 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3752 and t0, t1, t0
3753 bnez t0, syscall_trace_entry
3754diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
3755index 86ec03f..1235baf 100644
3756--- a/arch/mips/kernel/scall64-n32.S
3757+++ b/arch/mips/kernel/scall64-n32.S
3758@@ -53,7 +53,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
3759
3760 sd a3, PT_R26(sp) # save a3 for syscall restarting
3761
3762- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3763+ li t1, _TIF_SYSCALL_WORK
3764 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3765 and t0, t1, t0
3766 bnez t0, n32_syscall_trace_entry
3767diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
3768index 53c2d72..3734584 100644
3769--- a/arch/mips/kernel/scall64-o32.S
3770+++ b/arch/mips/kernel/scall64-o32.S
3771@@ -81,7 +81,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3772 PTR 4b, bad_stack
3773 .previous
3774
3775- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3776+ li t1, _TIF_SYSCALL_WORK
3777 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3778 and t0, t1, t0
3779 bnez t0, trace_a_syscall
3780diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
3781index ddcec1e..c7f983e 100644
3782--- a/arch/mips/mm/fault.c
3783+++ b/arch/mips/mm/fault.c
3784@@ -27,6 +27,23 @@
3785 #include <asm/highmem.h> /* For VMALLOC_END */
3786 #include <linux/kdebug.h>
3787
3788+#ifdef CONFIG_PAX_PAGEEXEC
3789+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3790+{
3791+ unsigned long i;
3792+
3793+ printk(KERN_ERR "PAX: bytes at PC: ");
3794+ for (i = 0; i < 5; i++) {
3795+ unsigned int c;
3796+ if (get_user(c, (unsigned int *)pc+i))
3797+ printk(KERN_CONT "???????? ");
3798+ else
3799+ printk(KERN_CONT "%08x ", c);
3800+ }
3801+ printk("\n");
3802+}
3803+#endif
3804+
3805 /*
3806 * This routine handles page faults. It determines the address,
3807 * and the problem, and then passes it off to one of the appropriate
3808diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
3809index 302d779..7d35bf8 100644
3810--- a/arch/mips/mm/mmap.c
3811+++ b/arch/mips/mm/mmap.c
3812@@ -95,6 +95,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3813 do_color_align = 1;
3814
3815 /* requesting a specific address */
3816+
3817+#ifdef CONFIG_PAX_RANDMMAP
3818+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
3819+#endif
3820+
3821 if (addr) {
3822 if (do_color_align)
3823 addr = COLOUR_ALIGN(addr, pgoff);
3824@@ -102,8 +107,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3825 addr = PAGE_ALIGN(addr);
3826
3827 vma = find_vma(mm, addr);
3828- if (TASK_SIZE - len >= addr &&
3829- (!vma || addr + len <= vma->vm_start))
3830+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len))
3831 return addr;
3832 }
3833
3834@@ -118,7 +122,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3835 /* At this point: (!vma || addr < vma->vm_end). */
3836 if (TASK_SIZE - len < addr)
3837 return -ENOMEM;
3838- if (!vma || addr + len <= vma->vm_start)
3839+ if (check_heap_stack_gap(vmm, addr, len))
3840 return addr;
3841 addr = vma->vm_end;
3842 if (do_color_align)
3843@@ -145,7 +149,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3844 /* make sure it can fit in the remaining address space */
3845 if (likely(addr > len)) {
3846 vma = find_vma(mm, addr - len);
3847- if (!vma || addr <= vma->vm_start) {
3848+ if (check_heap_stack_gap(vmm, addr - len, len))
3849 /* cache the address as a hint for next time */
3850 return mm->free_area_cache = addr - len;
3851 }
3852@@ -165,7 +169,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3853 * return with success:
3854 */
3855 vma = find_vma(mm, addr);
3856- if (likely(!vma || addr + len <= vma->vm_start)) {
3857+ if (check_heap_stack_gap(vmm, addr, len)) {
3858 /* cache the address as a hint for next time */
3859 return mm->free_area_cache = addr;
3860 }
3861@@ -242,30 +246,3 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3862 mm->unmap_area = arch_unmap_area_topdown;
3863 }
3864 }
3865-
3866-static inline unsigned long brk_rnd(void)
3867-{
3868- unsigned long rnd = get_random_int();
3869-
3870- rnd = rnd << PAGE_SHIFT;
3871- /* 8MB for 32bit, 256MB for 64bit */
3872- if (TASK_IS_32BIT_ADDR)
3873- rnd = rnd & 0x7ffffful;
3874- else
3875- rnd = rnd & 0xffffffful;
3876-
3877- return rnd;
3878-}
3879-
3880-unsigned long arch_randomize_brk(struct mm_struct *mm)
3881-{
3882- unsigned long base = mm->brk;
3883- unsigned long ret;
3884-
3885- ret = PAGE_ALIGN(base + brk_rnd());
3886-
3887- if (ret < mm->brk)
3888- return mm->brk;
3889-
3890- return ret;
3891-}
3892diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
3893index 967d144..db12197 100644
3894--- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
3895+++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
3896@@ -11,12 +11,14 @@
3897 #ifndef _ASM_PROC_CACHE_H
3898 #define _ASM_PROC_CACHE_H
3899
3900+#include <linux/const.h>
3901+
3902 /* L1 cache */
3903
3904 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
3905 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
3906-#define L1_CACHE_BYTES 16 /* bytes per entry */
3907 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
3908+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
3909 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
3910
3911 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
3912diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3913index bcb5df2..84fabd2 100644
3914--- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3915+++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3916@@ -16,13 +16,15 @@
3917 #ifndef _ASM_PROC_CACHE_H
3918 #define _ASM_PROC_CACHE_H
3919
3920+#include <linux/const.h>
3921+
3922 /*
3923 * L1 cache
3924 */
3925 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
3926 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
3927-#define L1_CACHE_BYTES 32 /* bytes per entry */
3928 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
3929+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
3930 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
3931
3932 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
3933diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
3934index 4ce7a01..449202a 100644
3935--- a/arch/openrisc/include/asm/cache.h
3936+++ b/arch/openrisc/include/asm/cache.h
3937@@ -19,11 +19,13 @@
3938 #ifndef __ASM_OPENRISC_CACHE_H
3939 #define __ASM_OPENRISC_CACHE_H
3940
3941+#include <linux/const.h>
3942+
3943 /* FIXME: How can we replace these with values from the CPU...
3944 * they shouldn't be hard-coded!
3945 */
3946
3947-#define L1_CACHE_BYTES 16
3948 #define L1_CACHE_SHIFT 4
3949+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3950
3951 #endif /* __ASM_OPENRISC_CACHE_H */
3952diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
3953index af9cf30..2aae9b2 100644
3954--- a/arch/parisc/include/asm/atomic.h
3955+++ b/arch/parisc/include/asm/atomic.h
3956@@ -229,6 +229,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
3957
3958 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
3959
3960+#define atomic64_read_unchecked(v) atomic64_read(v)
3961+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3962+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3963+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3964+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3965+#define atomic64_inc_unchecked(v) atomic64_inc(v)
3966+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3967+#define atomic64_dec_unchecked(v) atomic64_dec(v)
3968+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3969+
3970 #endif /* !CONFIG_64BIT */
3971
3972
3973diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
3974index 47f11c7..3420df2 100644
3975--- a/arch/parisc/include/asm/cache.h
3976+++ b/arch/parisc/include/asm/cache.h
3977@@ -5,6 +5,7 @@
3978 #ifndef __ARCH_PARISC_CACHE_H
3979 #define __ARCH_PARISC_CACHE_H
3980
3981+#include <linux/const.h>
3982
3983 /*
3984 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
3985@@ -15,13 +16,13 @@
3986 * just ruin performance.
3987 */
3988 #ifdef CONFIG_PA20
3989-#define L1_CACHE_BYTES 64
3990 #define L1_CACHE_SHIFT 6
3991 #else
3992-#define L1_CACHE_BYTES 32
3993 #define L1_CACHE_SHIFT 5
3994 #endif
3995
3996+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3997+
3998 #ifndef __ASSEMBLY__
3999
4000 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4001diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
4002index 19f6cb1..6c78cf2 100644
4003--- a/arch/parisc/include/asm/elf.h
4004+++ b/arch/parisc/include/asm/elf.h
4005@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
4006
4007 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
4008
4009+#ifdef CONFIG_PAX_ASLR
4010+#define PAX_ELF_ET_DYN_BASE 0x10000UL
4011+
4012+#define PAX_DELTA_MMAP_LEN 16
4013+#define PAX_DELTA_STACK_LEN 16
4014+#endif
4015+
4016 /* This yields a mask that user programs can use to figure out what
4017 instruction set this CPU supports. This could be done in user space,
4018 but it's not easy, and we've already done it here. */
4019diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
4020index fc987a1..6e068ef 100644
4021--- a/arch/parisc/include/asm/pgalloc.h
4022+++ b/arch/parisc/include/asm/pgalloc.h
4023@@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
4024 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
4025 }
4026
4027+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
4028+{
4029+ pgd_populate(mm, pgd, pmd);
4030+}
4031+
4032 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
4033 {
4034 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
4035@@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
4036 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
4037 #define pmd_free(mm, x) do { } while (0)
4038 #define pgd_populate(mm, pmd, pte) BUG()
4039+#define pgd_populate_kernel(mm, pmd, pte) BUG()
4040
4041 #endif
4042
4043diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
4044index ee99f23..802b0a1 100644
4045--- a/arch/parisc/include/asm/pgtable.h
4046+++ b/arch/parisc/include/asm/pgtable.h
4047@@ -212,6 +212,17 @@ struct vm_area_struct;
4048 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
4049 #define PAGE_COPY PAGE_EXECREAD
4050 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
4051+
4052+#ifdef CONFIG_PAX_PAGEEXEC
4053+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
4054+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
4055+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
4056+#else
4057+# define PAGE_SHARED_NOEXEC PAGE_SHARED
4058+# define PAGE_COPY_NOEXEC PAGE_COPY
4059+# define PAGE_READONLY_NOEXEC PAGE_READONLY
4060+#endif
4061+
4062 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
4063 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
4064 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
4065diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
4066index 4ba2c93..f5e3974 100644
4067--- a/arch/parisc/include/asm/uaccess.h
4068+++ b/arch/parisc/include/asm/uaccess.h
4069@@ -251,10 +251,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
4070 const void __user *from,
4071 unsigned long n)
4072 {
4073- int sz = __compiletime_object_size(to);
4074+ size_t sz = __compiletime_object_size(to);
4075 int ret = -EFAULT;
4076
4077- if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
4078+ if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
4079 ret = __copy_from_user(to, from, n);
4080 else
4081 copy_from_user_overflow();
4082diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
4083index 5e34ccf..672bc9c 100644
4084--- a/arch/parisc/kernel/module.c
4085+++ b/arch/parisc/kernel/module.c
4086@@ -98,16 +98,38 @@
4087
4088 /* three functions to determine where in the module core
4089 * or init pieces the location is */
4090+static inline int in_init_rx(struct module *me, void *loc)
4091+{
4092+ return (loc >= me->module_init_rx &&
4093+ loc < (me->module_init_rx + me->init_size_rx));
4094+}
4095+
4096+static inline int in_init_rw(struct module *me, void *loc)
4097+{
4098+ return (loc >= me->module_init_rw &&
4099+ loc < (me->module_init_rw + me->init_size_rw));
4100+}
4101+
4102 static inline int in_init(struct module *me, void *loc)
4103 {
4104- return (loc >= me->module_init &&
4105- loc <= (me->module_init + me->init_size));
4106+ return in_init_rx(me, loc) || in_init_rw(me, loc);
4107+}
4108+
4109+static inline int in_core_rx(struct module *me, void *loc)
4110+{
4111+ return (loc >= me->module_core_rx &&
4112+ loc < (me->module_core_rx + me->core_size_rx));
4113+}
4114+
4115+static inline int in_core_rw(struct module *me, void *loc)
4116+{
4117+ return (loc >= me->module_core_rw &&
4118+ loc < (me->module_core_rw + me->core_size_rw));
4119 }
4120
4121 static inline int in_core(struct module *me, void *loc)
4122 {
4123- return (loc >= me->module_core &&
4124- loc <= (me->module_core + me->core_size));
4125+ return in_core_rx(me, loc) || in_core_rw(me, loc);
4126 }
4127
4128 static inline int in_local(struct module *me, void *loc)
4129@@ -373,13 +395,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
4130 }
4131
4132 /* align things a bit */
4133- me->core_size = ALIGN(me->core_size, 16);
4134- me->arch.got_offset = me->core_size;
4135- me->core_size += gots * sizeof(struct got_entry);
4136+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
4137+ me->arch.got_offset = me->core_size_rw;
4138+ me->core_size_rw += gots * sizeof(struct got_entry);
4139
4140- me->core_size = ALIGN(me->core_size, 16);
4141- me->arch.fdesc_offset = me->core_size;
4142- me->core_size += fdescs * sizeof(Elf_Fdesc);
4143+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
4144+ me->arch.fdesc_offset = me->core_size_rw;
4145+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
4146
4147 me->arch.got_max = gots;
4148 me->arch.fdesc_max = fdescs;
4149@@ -397,7 +419,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
4150
4151 BUG_ON(value == 0);
4152
4153- got = me->module_core + me->arch.got_offset;
4154+ got = me->module_core_rw + me->arch.got_offset;
4155 for (i = 0; got[i].addr; i++)
4156 if (got[i].addr == value)
4157 goto out;
4158@@ -415,7 +437,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
4159 #ifdef CONFIG_64BIT
4160 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
4161 {
4162- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
4163+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
4164
4165 if (!value) {
4166 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
4167@@ -433,7 +455,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
4168
4169 /* Create new one */
4170 fdesc->addr = value;
4171- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
4172+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
4173 return (Elf_Addr)fdesc;
4174 }
4175 #endif /* CONFIG_64BIT */
4176@@ -845,7 +867,7 @@ register_unwind_table(struct module *me,
4177
4178 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
4179 end = table + sechdrs[me->arch.unwind_section].sh_size;
4180- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
4181+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
4182
4183 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
4184 me->arch.unwind_section, table, end, gp);
4185diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
4186index f76c108..8117482 100644
4187--- a/arch/parisc/kernel/sys_parisc.c
4188+++ b/arch/parisc/kernel/sys_parisc.c
4189@@ -43,7 +43,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
4190 /* At this point: (!vma || addr < vma->vm_end). */
4191 if (TASK_SIZE - len < addr)
4192 return -ENOMEM;
4193- if (!vma || addr + len <= vma->vm_start)
4194+ if (check_heap_stack_gap(vma, addr, len))
4195 return addr;
4196 addr = vma->vm_end;
4197 }
4198@@ -81,7 +81,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
4199 /* At this point: (!vma || addr < vma->vm_end). */
4200 if (TASK_SIZE - len < addr)
4201 return -ENOMEM;
4202- if (!vma || addr + len <= vma->vm_start)
4203+ if (check_heap_stack_gap(vma, addr, len))
4204 return addr;
4205 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
4206 if (addr < vma->vm_end) /* handle wraparound */
4207@@ -100,7 +100,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
4208 if (flags & MAP_FIXED)
4209 return addr;
4210 if (!addr)
4211- addr = TASK_UNMAPPED_BASE;
4212+ addr = current->mm->mmap_base;
4213
4214 if (filp) {
4215 addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
4216diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
4217index 45ba99f..8e22c33 100644
4218--- a/arch/parisc/kernel/traps.c
4219+++ b/arch/parisc/kernel/traps.c
4220@@ -732,9 +732,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
4221
4222 down_read(&current->mm->mmap_sem);
4223 vma = find_vma(current->mm,regs->iaoq[0]);
4224- if (vma && (regs->iaoq[0] >= vma->vm_start)
4225- && (vma->vm_flags & VM_EXEC)) {
4226-
4227+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
4228 fault_address = regs->iaoq[0];
4229 fault_space = regs->iasq[0];
4230
4231diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
4232index 18162ce..94de376 100644
4233--- a/arch/parisc/mm/fault.c
4234+++ b/arch/parisc/mm/fault.c
4235@@ -15,6 +15,7 @@
4236 #include <linux/sched.h>
4237 #include <linux/interrupt.h>
4238 #include <linux/module.h>
4239+#include <linux/unistd.h>
4240
4241 #include <asm/uaccess.h>
4242 #include <asm/traps.h>
4243@@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
4244 static unsigned long
4245 parisc_acctyp(unsigned long code, unsigned int inst)
4246 {
4247- if (code == 6 || code == 16)
4248+ if (code == 6 || code == 7 || code == 16)
4249 return VM_EXEC;
4250
4251 switch (inst & 0xf0000000) {
4252@@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
4253 }
4254 #endif
4255
4256+#ifdef CONFIG_PAX_PAGEEXEC
4257+/*
4258+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
4259+ *
4260+ * returns 1 when task should be killed
4261+ * 2 when rt_sigreturn trampoline was detected
4262+ * 3 when unpatched PLT trampoline was detected
4263+ */
4264+static int pax_handle_fetch_fault(struct pt_regs *regs)
4265+{
4266+
4267+#ifdef CONFIG_PAX_EMUPLT
4268+ int err;
4269+
4270+ do { /* PaX: unpatched PLT emulation */
4271+ unsigned int bl, depwi;
4272+
4273+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
4274+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
4275+
4276+ if (err)
4277+ break;
4278+
4279+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
4280+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
4281+
4282+ err = get_user(ldw, (unsigned int *)addr);
4283+ err |= get_user(bv, (unsigned int *)(addr+4));
4284+ err |= get_user(ldw2, (unsigned int *)(addr+8));
4285+
4286+ if (err)
4287+ break;
4288+
4289+ if (ldw == 0x0E801096U &&
4290+ bv == 0xEAC0C000U &&
4291+ ldw2 == 0x0E881095U)
4292+ {
4293+ unsigned int resolver, map;
4294+
4295+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
4296+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
4297+ if (err)
4298+ break;
4299+
4300+ regs->gr[20] = instruction_pointer(regs)+8;
4301+ regs->gr[21] = map;
4302+ regs->gr[22] = resolver;
4303+ regs->iaoq[0] = resolver | 3UL;
4304+ regs->iaoq[1] = regs->iaoq[0] + 4;
4305+ return 3;
4306+ }
4307+ }
4308+ } while (0);
4309+#endif
4310+
4311+#ifdef CONFIG_PAX_EMUTRAMP
4312+
4313+#ifndef CONFIG_PAX_EMUSIGRT
4314+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
4315+ return 1;
4316+#endif
4317+
4318+ do { /* PaX: rt_sigreturn emulation */
4319+ unsigned int ldi1, ldi2, bel, nop;
4320+
4321+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
4322+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
4323+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
4324+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
4325+
4326+ if (err)
4327+ break;
4328+
4329+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
4330+ ldi2 == 0x3414015AU &&
4331+ bel == 0xE4008200U &&
4332+ nop == 0x08000240U)
4333+ {
4334+ regs->gr[25] = (ldi1 & 2) >> 1;
4335+ regs->gr[20] = __NR_rt_sigreturn;
4336+ regs->gr[31] = regs->iaoq[1] + 16;
4337+ regs->sr[0] = regs->iasq[1];
4338+ regs->iaoq[0] = 0x100UL;
4339+ regs->iaoq[1] = regs->iaoq[0] + 4;
4340+ regs->iasq[0] = regs->sr[2];
4341+ regs->iasq[1] = regs->sr[2];
4342+ return 2;
4343+ }
4344+ } while (0);
4345+#endif
4346+
4347+ return 1;
4348+}
4349+
4350+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4351+{
4352+ unsigned long i;
4353+
4354+ printk(KERN_ERR "PAX: bytes at PC: ");
4355+ for (i = 0; i < 5; i++) {
4356+ unsigned int c;
4357+ if (get_user(c, (unsigned int *)pc+i))
4358+ printk(KERN_CONT "???????? ");
4359+ else
4360+ printk(KERN_CONT "%08x ", c);
4361+ }
4362+ printk("\n");
4363+}
4364+#endif
4365+
4366 int fixup_exception(struct pt_regs *regs)
4367 {
4368 const struct exception_table_entry *fix;
4369@@ -192,8 +303,33 @@ good_area:
4370
4371 acc_type = parisc_acctyp(code,regs->iir);
4372
4373- if ((vma->vm_flags & acc_type) != acc_type)
4374+ if ((vma->vm_flags & acc_type) != acc_type) {
4375+
4376+#ifdef CONFIG_PAX_PAGEEXEC
4377+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
4378+ (address & ~3UL) == instruction_pointer(regs))
4379+ {
4380+ up_read(&mm->mmap_sem);
4381+ switch (pax_handle_fetch_fault(regs)) {
4382+
4383+#ifdef CONFIG_PAX_EMUPLT
4384+ case 3:
4385+ return;
4386+#endif
4387+
4388+#ifdef CONFIG_PAX_EMUTRAMP
4389+ case 2:
4390+ return;
4391+#endif
4392+
4393+ }
4394+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
4395+ do_group_exit(SIGKILL);
4396+ }
4397+#endif
4398+
4399 goto bad_area;
4400+ }
4401
4402 /*
4403 * If for any reason at all we couldn't handle the fault, make
4404diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
4405index e3b1d41..8e81edf 100644
4406--- a/arch/powerpc/include/asm/atomic.h
4407+++ b/arch/powerpc/include/asm/atomic.h
4408@@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
4409 return t1;
4410 }
4411
4412+#define atomic64_read_unchecked(v) atomic64_read(v)
4413+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4414+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4415+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4416+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4417+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4418+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4419+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4420+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4421+
4422 #endif /* __powerpc64__ */
4423
4424 #endif /* __KERNEL__ */
4425diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
4426index 9e495c9..b6878e5 100644
4427--- a/arch/powerpc/include/asm/cache.h
4428+++ b/arch/powerpc/include/asm/cache.h
4429@@ -3,6 +3,7 @@
4430
4431 #ifdef __KERNEL__
4432
4433+#include <linux/const.h>
4434
4435 /* bytes per L1 cache line */
4436 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
4437@@ -22,7 +23,7 @@
4438 #define L1_CACHE_SHIFT 7
4439 #endif
4440
4441-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4442+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4443
4444 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4445
4446diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
4447index 6abf0a1..459d0f1 100644
4448--- a/arch/powerpc/include/asm/elf.h
4449+++ b/arch/powerpc/include/asm/elf.h
4450@@ -28,8 +28,19 @@
4451 the loader. We need to make sure that it is out of the way of the program
4452 that it will "exec", and that there is sufficient room for the brk. */
4453
4454-extern unsigned long randomize_et_dyn(unsigned long base);
4455-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
4456+#define ELF_ET_DYN_BASE (0x20000000)
4457+
4458+#ifdef CONFIG_PAX_ASLR
4459+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
4460+
4461+#ifdef __powerpc64__
4462+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
4463+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
4464+#else
4465+#define PAX_DELTA_MMAP_LEN 15
4466+#define PAX_DELTA_STACK_LEN 15
4467+#endif
4468+#endif
4469
4470 /*
4471 * Our registers are always unsigned longs, whether we're a 32 bit
4472@@ -124,10 +135,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
4473 (0x7ff >> (PAGE_SHIFT - 12)) : \
4474 (0x3ffff >> (PAGE_SHIFT - 12)))
4475
4476-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
4477-#define arch_randomize_brk arch_randomize_brk
4478-
4479-
4480 #ifdef CONFIG_SPU_BASE
4481 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
4482 #define NT_SPU 1
4483diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
4484index 8196e9c..d83a9f3 100644
4485--- a/arch/powerpc/include/asm/exec.h
4486+++ b/arch/powerpc/include/asm/exec.h
4487@@ -4,6 +4,6 @@
4488 #ifndef _ASM_POWERPC_EXEC_H
4489 #define _ASM_POWERPC_EXEC_H
4490
4491-extern unsigned long arch_align_stack(unsigned long sp);
4492+#define arch_align_stack(x) ((x) & ~0xfUL)
4493
4494 #endif /* _ASM_POWERPC_EXEC_H */
4495diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
4496index 5acabbd..7ea14fa 100644
4497--- a/arch/powerpc/include/asm/kmap_types.h
4498+++ b/arch/powerpc/include/asm/kmap_types.h
4499@@ -10,7 +10,7 @@
4500 * 2 of the License, or (at your option) any later version.
4501 */
4502
4503-#define KM_TYPE_NR 16
4504+#define KM_TYPE_NR 17
4505
4506 #endif /* __KERNEL__ */
4507 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
4508diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
4509index 8565c25..2865190 100644
4510--- a/arch/powerpc/include/asm/mman.h
4511+++ b/arch/powerpc/include/asm/mman.h
4512@@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
4513 }
4514 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
4515
4516-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
4517+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
4518 {
4519 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
4520 }
4521diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
4522index f072e97..b436dee 100644
4523--- a/arch/powerpc/include/asm/page.h
4524+++ b/arch/powerpc/include/asm/page.h
4525@@ -220,8 +220,9 @@ extern long long virt_phys_offset;
4526 * and needs to be executable. This means the whole heap ends
4527 * up being executable.
4528 */
4529-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
4530- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
4531+#define VM_DATA_DEFAULT_FLAGS32 \
4532+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
4533+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
4534
4535 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
4536 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
4537@@ -249,6 +250,9 @@ extern long long virt_phys_offset;
4538 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
4539 #endif
4540
4541+#define ktla_ktva(addr) (addr)
4542+#define ktva_ktla(addr) (addr)
4543+
4544 /*
4545 * Use the top bit of the higher-level page table entries to indicate whether
4546 * the entries we point to contain hugepages. This works because we know that
4547diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
4548index cd915d6..c10cee8 100644
4549--- a/arch/powerpc/include/asm/page_64.h
4550+++ b/arch/powerpc/include/asm/page_64.h
4551@@ -154,15 +154,18 @@ do { \
4552 * stack by default, so in the absence of a PT_GNU_STACK program header
4553 * we turn execute permission off.
4554 */
4555-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
4556- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
4557+#define VM_STACK_DEFAULT_FLAGS32 \
4558+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
4559+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
4560
4561 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
4562 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
4563
4564+#ifndef CONFIG_PAX_PAGEEXEC
4565 #define VM_STACK_DEFAULT_FLAGS \
4566 (is_32bit_task() ? \
4567 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
4568+#endif
4569
4570 #include <asm-generic/getorder.h>
4571
4572diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
4573index 292725c..f87ae14 100644
4574--- a/arch/powerpc/include/asm/pgalloc-64.h
4575+++ b/arch/powerpc/include/asm/pgalloc-64.h
4576@@ -50,6 +50,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
4577 #ifndef CONFIG_PPC_64K_PAGES
4578
4579 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
4580+#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
4581
4582 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
4583 {
4584@@ -67,6 +68,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
4585 pud_set(pud, (unsigned long)pmd);
4586 }
4587
4588+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
4589+{
4590+ pud_populate(mm, pud, pmd);
4591+}
4592+
4593 #define pmd_populate(mm, pmd, pte_page) \
4594 pmd_populate_kernel(mm, pmd, page_address(pte_page))
4595 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
4596@@ -76,6 +82,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
4597 #else /* CONFIG_PPC_64K_PAGES */
4598
4599 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
4600+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
4601
4602 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
4603 pte_t *pte)
4604diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
4605index a9cbd3b..3b67efa 100644
4606--- a/arch/powerpc/include/asm/pgtable.h
4607+++ b/arch/powerpc/include/asm/pgtable.h
4608@@ -2,6 +2,7 @@
4609 #define _ASM_POWERPC_PGTABLE_H
4610 #ifdef __KERNEL__
4611
4612+#include <linux/const.h>
4613 #ifndef __ASSEMBLY__
4614 #include <asm/processor.h> /* For TASK_SIZE */
4615 #include <asm/mmu.h>
4616diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
4617index 4aad413..85d86bf 100644
4618--- a/arch/powerpc/include/asm/pte-hash32.h
4619+++ b/arch/powerpc/include/asm/pte-hash32.h
4620@@ -21,6 +21,7 @@
4621 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
4622 #define _PAGE_USER 0x004 /* usermode access allowed */
4623 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
4624+#define _PAGE_EXEC _PAGE_GUARDED
4625 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
4626 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
4627 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
4628diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
4629index d24c141..b60696e 100644
4630--- a/arch/powerpc/include/asm/reg.h
4631+++ b/arch/powerpc/include/asm/reg.h
4632@@ -215,6 +215,7 @@
4633 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
4634 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
4635 #define DSISR_NOHPTE 0x40000000 /* no translation found */
4636+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
4637 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
4638 #define DSISR_ISSTORE 0x02000000 /* access was a store */
4639 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
4640diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
4641index 406b7b9..af63426 100644
4642--- a/arch/powerpc/include/asm/thread_info.h
4643+++ b/arch/powerpc/include/asm/thread_info.h
4644@@ -97,7 +97,6 @@ static inline struct thread_info *current_thread_info(void)
4645 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
4646 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
4647 #define TIF_SINGLESTEP 8 /* singlestepping active */
4648-#define TIF_MEMDIE 9 /* is terminating due to OOM killer */
4649 #define TIF_SECCOMP 10 /* secure computing */
4650 #define TIF_RESTOREALL 11 /* Restore all regs (implies NOERROR) */
4651 #define TIF_NOERROR 12 /* Force successful syscall return */
4652@@ -106,6 +105,9 @@ static inline struct thread_info *current_thread_info(void)
4653 #define TIF_SYSCALL_TRACEPOINT 15 /* syscall tracepoint instrumentation */
4654 #define TIF_EMULATE_STACK_STORE 16 /* Is an instruction emulation
4655 for stack store? */
4656+#define TIF_MEMDIE 17 /* is terminating due to OOM killer */
4657+/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
4658+#define TIF_GRSEC_SETXID 9 /* update credentials on syscall entry/exit */
4659
4660 /* as above, but as bit values */
4661 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
4662@@ -124,8 +126,10 @@ static inline struct thread_info *current_thread_info(void)
4663 #define _TIF_UPROBE (1<<TIF_UPROBE)
4664 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
4665 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
4666+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
4667 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
4668- _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT)
4669+ _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
4670+ _TIF_GRSEC_SETXID)
4671
4672 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
4673 _TIF_NOTIFY_RESUME | _TIF_UPROBE)
4674diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
4675index 4db4959..335e00c 100644
4676--- a/arch/powerpc/include/asm/uaccess.h
4677+++ b/arch/powerpc/include/asm/uaccess.h
4678@@ -13,6 +13,8 @@
4679 #define VERIFY_READ 0
4680 #define VERIFY_WRITE 1
4681
4682+extern void check_object_size(const void *ptr, unsigned long n, bool to);
4683+
4684 /*
4685 * The fs value determines whether argument validity checking should be
4686 * performed or not. If get_fs() == USER_DS, checking is performed, with
4687@@ -318,52 +320,6 @@ do { \
4688 extern unsigned long __copy_tofrom_user(void __user *to,
4689 const void __user *from, unsigned long size);
4690
4691-#ifndef __powerpc64__
4692-
4693-static inline unsigned long copy_from_user(void *to,
4694- const void __user *from, unsigned long n)
4695-{
4696- unsigned long over;
4697-
4698- if (access_ok(VERIFY_READ, from, n))
4699- return __copy_tofrom_user((__force void __user *)to, from, n);
4700- if ((unsigned long)from < TASK_SIZE) {
4701- over = (unsigned long)from + n - TASK_SIZE;
4702- return __copy_tofrom_user((__force void __user *)to, from,
4703- n - over) + over;
4704- }
4705- return n;
4706-}
4707-
4708-static inline unsigned long copy_to_user(void __user *to,
4709- const void *from, unsigned long n)
4710-{
4711- unsigned long over;
4712-
4713- if (access_ok(VERIFY_WRITE, to, n))
4714- return __copy_tofrom_user(to, (__force void __user *)from, n);
4715- if ((unsigned long)to < TASK_SIZE) {
4716- over = (unsigned long)to + n - TASK_SIZE;
4717- return __copy_tofrom_user(to, (__force void __user *)from,
4718- n - over) + over;
4719- }
4720- return n;
4721-}
4722-
4723-#else /* __powerpc64__ */
4724-
4725-#define __copy_in_user(to, from, size) \
4726- __copy_tofrom_user((to), (from), (size))
4727-
4728-extern unsigned long copy_from_user(void *to, const void __user *from,
4729- unsigned long n);
4730-extern unsigned long copy_to_user(void __user *to, const void *from,
4731- unsigned long n);
4732-extern unsigned long copy_in_user(void __user *to, const void __user *from,
4733- unsigned long n);
4734-
4735-#endif /* __powerpc64__ */
4736-
4737 static inline unsigned long __copy_from_user_inatomic(void *to,
4738 const void __user *from, unsigned long n)
4739 {
4740@@ -387,6 +343,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
4741 if (ret == 0)
4742 return 0;
4743 }
4744+
4745+ if (!__builtin_constant_p(n))
4746+ check_object_size(to, n, false);
4747+
4748 return __copy_tofrom_user((__force void __user *)to, from, n);
4749 }
4750
4751@@ -413,6 +373,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
4752 if (ret == 0)
4753 return 0;
4754 }
4755+
4756+ if (!__builtin_constant_p(n))
4757+ check_object_size(from, n, true);
4758+
4759 return __copy_tofrom_user(to, (__force const void __user *)from, n);
4760 }
4761
4762@@ -430,6 +394,92 @@ static inline unsigned long __copy_to_user(void __user *to,
4763 return __copy_to_user_inatomic(to, from, size);
4764 }
4765
4766+#ifndef __powerpc64__
4767+
4768+static inline unsigned long __must_check copy_from_user(void *to,
4769+ const void __user *from, unsigned long n)
4770+{
4771+ unsigned long over;
4772+
4773+ if ((long)n < 0)
4774+ return n;
4775+
4776+ if (access_ok(VERIFY_READ, from, n)) {
4777+ if (!__builtin_constant_p(n))
4778+ check_object_size(to, n, false);
4779+ return __copy_tofrom_user((__force void __user *)to, from, n);
4780+ }
4781+ if ((unsigned long)from < TASK_SIZE) {
4782+ over = (unsigned long)from + n - TASK_SIZE;
4783+ if (!__builtin_constant_p(n - over))
4784+ check_object_size(to, n - over, false);
4785+ return __copy_tofrom_user((__force void __user *)to, from,
4786+ n - over) + over;
4787+ }
4788+ return n;
4789+}
4790+
4791+static inline unsigned long __must_check copy_to_user(void __user *to,
4792+ const void *from, unsigned long n)
4793+{
4794+ unsigned long over;
4795+
4796+ if ((long)n < 0)
4797+ return n;
4798+
4799+ if (access_ok(VERIFY_WRITE, to, n)) {
4800+ if (!__builtin_constant_p(n))
4801+ check_object_size(from, n, true);
4802+ return __copy_tofrom_user(to, (__force void __user *)from, n);
4803+ }
4804+ if ((unsigned long)to < TASK_SIZE) {
4805+ over = (unsigned long)to + n - TASK_SIZE;
4806+ if (!__builtin_constant_p(n))
4807+ check_object_size(from, n - over, true);
4808+ return __copy_tofrom_user(to, (__force void __user *)from,
4809+ n - over) + over;
4810+ }
4811+ return n;
4812+}
4813+
4814+#else /* __powerpc64__ */
4815+
4816+#define __copy_in_user(to, from, size) \
4817+ __copy_tofrom_user((to), (from), (size))
4818+
4819+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
4820+{
4821+ if ((long)n < 0 || n > INT_MAX)
4822+ return n;
4823+
4824+ if (!__builtin_constant_p(n))
4825+ check_object_size(to, n, false);
4826+
4827+ if (likely(access_ok(VERIFY_READ, from, n)))
4828+ n = __copy_from_user(to, from, n);
4829+ else
4830+ memset(to, 0, n);
4831+ return n;
4832+}
4833+
4834+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
4835+{
4836+ if ((long)n < 0 || n > INT_MAX)
4837+ return n;
4838+
4839+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
4840+ if (!__builtin_constant_p(n))
4841+ check_object_size(from, n, true);
4842+ n = __copy_to_user(to, from, n);
4843+ }
4844+ return n;
4845+}
4846+
4847+extern unsigned long copy_in_user(void __user *to, const void __user *from,
4848+ unsigned long n);
4849+
4850+#endif /* __powerpc64__ */
4851+
4852 extern unsigned long __clear_user(void __user *addr, unsigned long size);
4853
4854 static inline unsigned long clear_user(void __user *addr, unsigned long size)
4855diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
4856index 4684e33..acc4d19e 100644
4857--- a/arch/powerpc/kernel/exceptions-64e.S
4858+++ b/arch/powerpc/kernel/exceptions-64e.S
4859@@ -715,6 +715,7 @@ storage_fault_common:
4860 std r14,_DAR(r1)
4861 std r15,_DSISR(r1)
4862 addi r3,r1,STACK_FRAME_OVERHEAD
4863+ bl .save_nvgprs
4864 mr r4,r14
4865 mr r5,r15
4866 ld r14,PACA_EXGEN+EX_R14(r13)
4867@@ -723,8 +724,7 @@ storage_fault_common:
4868 cmpdi r3,0
4869 bne- 1f
4870 b .ret_from_except_lite
4871-1: bl .save_nvgprs
4872- mr r5,r3
4873+1: mr r5,r3
4874 addi r3,r1,STACK_FRAME_OVERHEAD
4875 ld r4,_DAR(r1)
4876 bl .bad_page_fault
4877diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
4878index 10b658a..e542888 100644
4879--- a/arch/powerpc/kernel/exceptions-64s.S
4880+++ b/arch/powerpc/kernel/exceptions-64s.S
4881@@ -1013,10 +1013,10 @@ handle_page_fault:
4882 11: ld r4,_DAR(r1)
4883 ld r5,_DSISR(r1)
4884 addi r3,r1,STACK_FRAME_OVERHEAD
4885+ bl .save_nvgprs
4886 bl .do_page_fault
4887 cmpdi r3,0
4888 beq+ 12f
4889- bl .save_nvgprs
4890 mr r5,r3
4891 addi r3,r1,STACK_FRAME_OVERHEAD
4892 lwz r4,_DAR(r1)
4893diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
4894index 2e3200c..72095ce 100644
4895--- a/arch/powerpc/kernel/module_32.c
4896+++ b/arch/powerpc/kernel/module_32.c
4897@@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
4898 me->arch.core_plt_section = i;
4899 }
4900 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
4901- printk("Module doesn't contain .plt or .init.plt sections.\n");
4902+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
4903 return -ENOEXEC;
4904 }
4905
4906@@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
4907
4908 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
4909 /* Init, or core PLT? */
4910- if (location >= mod->module_core
4911- && location < mod->module_core + mod->core_size)
4912+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
4913+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
4914 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
4915- else
4916+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
4917+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
4918 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
4919+ else {
4920+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
4921+ return ~0UL;
4922+ }
4923
4924 /* Find this entry, or if that fails, the next avail. entry */
4925 while (entry->jump[0]) {
4926diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
4927index ba48233..16ac31d 100644
4928--- a/arch/powerpc/kernel/process.c
4929+++ b/arch/powerpc/kernel/process.c
4930@@ -680,8 +680,8 @@ void show_regs(struct pt_regs * regs)
4931 * Lookup NIP late so we have the best change of getting the
4932 * above info out without failing
4933 */
4934- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
4935- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
4936+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
4937+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
4938 #endif
4939 show_stack(current, (unsigned long *) regs->gpr[1]);
4940 if (!user_mode(regs))
4941@@ -1175,10 +1175,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
4942 newsp = stack[0];
4943 ip = stack[STACK_FRAME_LR_SAVE];
4944 if (!firstframe || ip != lr) {
4945- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
4946+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
4947 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
4948 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
4949- printk(" (%pS)",
4950+ printk(" (%pA)",
4951 (void *)current->ret_stack[curr_frame].ret);
4952 curr_frame--;
4953 }
4954@@ -1198,7 +1198,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
4955 struct pt_regs *regs = (struct pt_regs *)
4956 (sp + STACK_FRAME_OVERHEAD);
4957 lr = regs->link;
4958- printk("--- Exception: %lx at %pS\n LR = %pS\n",
4959+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
4960 regs->trap, (void *)regs->nip, (void *)lr);
4961 firstframe = 1;
4962 }
4963@@ -1240,58 +1240,3 @@ void __ppc64_runlatch_off(void)
4964 mtspr(SPRN_CTRLT, ctrl);
4965 }
4966 #endif /* CONFIG_PPC64 */
4967-
4968-unsigned long arch_align_stack(unsigned long sp)
4969-{
4970- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4971- sp -= get_random_int() & ~PAGE_MASK;
4972- return sp & ~0xf;
4973-}
4974-
4975-static inline unsigned long brk_rnd(void)
4976-{
4977- unsigned long rnd = 0;
4978-
4979- /* 8MB for 32bit, 1GB for 64bit */
4980- if (is_32bit_task())
4981- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
4982- else
4983- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
4984-
4985- return rnd << PAGE_SHIFT;
4986-}
4987-
4988-unsigned long arch_randomize_brk(struct mm_struct *mm)
4989-{
4990- unsigned long base = mm->brk;
4991- unsigned long ret;
4992-
4993-#ifdef CONFIG_PPC_STD_MMU_64
4994- /*
4995- * If we are using 1TB segments and we are allowed to randomise
4996- * the heap, we can put it above 1TB so it is backed by a 1TB
4997- * segment. Otherwise the heap will be in the bottom 1TB
4998- * which always uses 256MB segments and this may result in a
4999- * performance penalty.
5000- */
5001- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
5002- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
5003-#endif
5004-
5005- ret = PAGE_ALIGN(base + brk_rnd());
5006-
5007- if (ret < mm->brk)
5008- return mm->brk;
5009-
5010- return ret;
5011-}
5012-
5013-unsigned long randomize_et_dyn(unsigned long base)
5014-{
5015- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
5016-
5017- if (ret < base)
5018- return base;
5019-
5020- return ret;
5021-}
5022diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
5023index 79d8e56..38ffcbb 100644
5024--- a/arch/powerpc/kernel/ptrace.c
5025+++ b/arch/powerpc/kernel/ptrace.c
5026@@ -1663,6 +1663,10 @@ long arch_ptrace(struct task_struct *child, long request,
5027 return ret;
5028 }
5029
5030+#ifdef CONFIG_GRKERNSEC_SETXID
5031+extern void gr_delayed_cred_worker(void);
5032+#endif
5033+
5034 /*
5035 * We must return the syscall number to actually look up in the table.
5036 * This can be -1L to skip running any syscall at all.
5037@@ -1673,6 +1677,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
5038
5039 secure_computing_strict(regs->gpr[0]);
5040
5041+#ifdef CONFIG_GRKERNSEC_SETXID
5042+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5043+ gr_delayed_cred_worker();
5044+#endif
5045+
5046 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
5047 tracehook_report_syscall_entry(regs))
5048 /*
5049@@ -1707,6 +1716,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
5050 {
5051 int step;
5052
5053+#ifdef CONFIG_GRKERNSEC_SETXID
5054+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5055+ gr_delayed_cred_worker();
5056+#endif
5057+
5058 audit_syscall_exit(regs);
5059
5060 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
5061diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
5062index 804e323..79181c1 100644
5063--- a/arch/powerpc/kernel/signal_32.c
5064+++ b/arch/powerpc/kernel/signal_32.c
5065@@ -851,7 +851,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
5066 /* Save user registers on the stack */
5067 frame = &rt_sf->uc.uc_mcontext;
5068 addr = frame;
5069- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
5070+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
5071 if (save_user_regs(regs, frame, 0, 1))
5072 goto badframe;
5073 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
5074diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
5075index d183f87..1867f1a 100644
5076--- a/arch/powerpc/kernel/signal_64.c
5077+++ b/arch/powerpc/kernel/signal_64.c
5078@@ -430,7 +430,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
5079 current->thread.fpscr.val = 0;
5080
5081 /* Set up to return from userspace. */
5082- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
5083+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
5084 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
5085 } else {
5086 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
5087diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
5088index 3251840..3f7c77a 100644
5089--- a/arch/powerpc/kernel/traps.c
5090+++ b/arch/powerpc/kernel/traps.c
5091@@ -133,6 +133,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
5092 return flags;
5093 }
5094
5095+extern void gr_handle_kernel_exploit(void);
5096+
5097 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
5098 int signr)
5099 {
5100@@ -182,6 +184,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
5101 panic("Fatal exception in interrupt");
5102 if (panic_on_oops)
5103 panic("Fatal exception");
5104+
5105+ gr_handle_kernel_exploit();
5106+
5107 do_exit(signr);
5108 }
5109
5110diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
5111index 1b2076f..835e4be 100644
5112--- a/arch/powerpc/kernel/vdso.c
5113+++ b/arch/powerpc/kernel/vdso.c
5114@@ -34,6 +34,7 @@
5115 #include <asm/firmware.h>
5116 #include <asm/vdso.h>
5117 #include <asm/vdso_datapage.h>
5118+#include <asm/mman.h>
5119
5120 #include "setup.h"
5121
5122@@ -218,7 +219,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
5123 vdso_base = VDSO32_MBASE;
5124 #endif
5125
5126- current->mm->context.vdso_base = 0;
5127+ current->mm->context.vdso_base = ~0UL;
5128
5129 /* vDSO has a problem and was disabled, just don't "enable" it for the
5130 * process
5131@@ -238,7 +239,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
5132 vdso_base = get_unmapped_area(NULL, vdso_base,
5133 (vdso_pages << PAGE_SHIFT) +
5134 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
5135- 0, 0);
5136+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
5137 if (IS_ERR_VALUE(vdso_base)) {
5138 rc = vdso_base;
5139 goto fail_mmapsem;
5140diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
5141index 5eea6f3..5d10396 100644
5142--- a/arch/powerpc/lib/usercopy_64.c
5143+++ b/arch/powerpc/lib/usercopy_64.c
5144@@ -9,22 +9,6 @@
5145 #include <linux/module.h>
5146 #include <asm/uaccess.h>
5147
5148-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
5149-{
5150- if (likely(access_ok(VERIFY_READ, from, n)))
5151- n = __copy_from_user(to, from, n);
5152- else
5153- memset(to, 0, n);
5154- return n;
5155-}
5156-
5157-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
5158-{
5159- if (likely(access_ok(VERIFY_WRITE, to, n)))
5160- n = __copy_to_user(to, from, n);
5161- return n;
5162-}
5163-
5164 unsigned long copy_in_user(void __user *to, const void __user *from,
5165 unsigned long n)
5166 {
5167@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
5168 return n;
5169 }
5170
5171-EXPORT_SYMBOL(copy_from_user);
5172-EXPORT_SYMBOL(copy_to_user);
5173 EXPORT_SYMBOL(copy_in_user);
5174
5175diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
5176index 0a6b283..7674925 100644
5177--- a/arch/powerpc/mm/fault.c
5178+++ b/arch/powerpc/mm/fault.c
5179@@ -32,6 +32,10 @@
5180 #include <linux/perf_event.h>
5181 #include <linux/magic.h>
5182 #include <linux/ratelimit.h>
5183+#include <linux/slab.h>
5184+#include <linux/pagemap.h>
5185+#include <linux/compiler.h>
5186+#include <linux/unistd.h>
5187
5188 #include <asm/firmware.h>
5189 #include <asm/page.h>
5190@@ -68,6 +72,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
5191 }
5192 #endif
5193
5194+#ifdef CONFIG_PAX_PAGEEXEC
5195+/*
5196+ * PaX: decide what to do with offenders (regs->nip = fault address)
5197+ *
5198+ * returns 1 when task should be killed
5199+ */
5200+static int pax_handle_fetch_fault(struct pt_regs *regs)
5201+{
5202+ return 1;
5203+}
5204+
5205+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5206+{
5207+ unsigned long i;
5208+
5209+ printk(KERN_ERR "PAX: bytes at PC: ");
5210+ for (i = 0; i < 5; i++) {
5211+ unsigned int c;
5212+ if (get_user(c, (unsigned int __user *)pc+i))
5213+ printk(KERN_CONT "???????? ");
5214+ else
5215+ printk(KERN_CONT "%08x ", c);
5216+ }
5217+ printk("\n");
5218+}
5219+#endif
5220+
5221 /*
5222 * Check whether the instruction at regs->nip is a store using
5223 * an update addressing form which will update r1.
5224@@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
5225 * indicate errors in DSISR but can validly be set in SRR1.
5226 */
5227 if (trap == 0x400)
5228- error_code &= 0x48200000;
5229+ error_code &= 0x58200000;
5230 else
5231 is_write = error_code & DSISR_ISSTORE;
5232 #else
5233@@ -367,7 +398,7 @@ good_area:
5234 * "undefined". Of those that can be set, this is the only
5235 * one which seems bad.
5236 */
5237- if (error_code & 0x10000000)
5238+ if (error_code & DSISR_GUARDED)
5239 /* Guarded storage error. */
5240 goto bad_area;
5241 #endif /* CONFIG_8xx */
5242@@ -382,7 +413,7 @@ good_area:
5243 * processors use the same I/D cache coherency mechanism
5244 * as embedded.
5245 */
5246- if (error_code & DSISR_PROTFAULT)
5247+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
5248 goto bad_area;
5249 #endif /* CONFIG_PPC_STD_MMU */
5250
5251@@ -465,6 +496,23 @@ bad_area:
5252 bad_area_nosemaphore:
5253 /* User mode accesses cause a SIGSEGV */
5254 if (user_mode(regs)) {
5255+
5256+#ifdef CONFIG_PAX_PAGEEXEC
5257+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
5258+#ifdef CONFIG_PPC_STD_MMU
5259+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
5260+#else
5261+ if (is_exec && regs->nip == address) {
5262+#endif
5263+ switch (pax_handle_fetch_fault(regs)) {
5264+ }
5265+
5266+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
5267+ do_group_exit(SIGKILL);
5268+ }
5269+ }
5270+#endif
5271+
5272 _exception(SIGSEGV, regs, code, address);
5273 return 0;
5274 }
5275diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
5276index 67a42ed..1c7210c 100644
5277--- a/arch/powerpc/mm/mmap_64.c
5278+++ b/arch/powerpc/mm/mmap_64.c
5279@@ -91,10 +91,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5280 */
5281 if (mmap_is_legacy()) {
5282 mm->mmap_base = TASK_UNMAPPED_BASE;
5283+
5284+#ifdef CONFIG_PAX_RANDMMAP
5285+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5286+ mm->mmap_base += mm->delta_mmap;
5287+#endif
5288+
5289 mm->get_unmapped_area = arch_get_unmapped_area;
5290 mm->unmap_area = arch_unmap_area;
5291 } else {
5292 mm->mmap_base = mmap_base();
5293+
5294+#ifdef CONFIG_PAX_RANDMMAP
5295+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5296+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5297+#endif
5298+
5299 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5300 mm->unmap_area = arch_unmap_area_topdown;
5301 }
5302diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
5303index 5829d2a..b64ed2e 100644
5304--- a/arch/powerpc/mm/slice.c
5305+++ b/arch/powerpc/mm/slice.c
5306@@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
5307 if ((mm->task_size - len) < addr)
5308 return 0;
5309 vma = find_vma(mm, addr);
5310- return (!vma || (addr + len) <= vma->vm_start);
5311+ return check_heap_stack_gap(vma, addr, len);
5312 }
5313
5314 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
5315@@ -272,7 +272,7 @@ full_search:
5316 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
5317 continue;
5318 }
5319- if (!vma || addr + len <= vma->vm_start) {
5320+ if (check_heap_stack_gap(vma, addr, len)) {
5321 /*
5322 * Remember the place where we stopped the search:
5323 */
5324@@ -329,10 +329,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
5325 }
5326 }
5327
5328- addr = mm->mmap_base;
5329- while (addr > len) {
5330+ if (mm->mmap_base < len)
5331+ addr = -ENOMEM;
5332+ else
5333+ addr = mm->mmap_base - len;
5334+
5335+ while (!IS_ERR_VALUE(addr)) {
5336 /* Go down by chunk size */
5337- addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
5338+ addr = _ALIGN_DOWN(addr, 1ul << pshift);
5339
5340 /* Check for hit with different page size */
5341 mask = slice_range_to_mask(addr, len);
5342@@ -352,7 +356,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
5343 * return with success:
5344 */
5345 vma = find_vma(mm, addr);
5346- if (!vma || (addr + len) <= vma->vm_start) {
5347+ if (check_heap_stack_gap(vma, addr, len)) {
5348 /* remember the address as a hint for next time */
5349 if (use_cache)
5350 mm->free_area_cache = addr;
5351@@ -364,7 +368,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
5352 mm->cached_hole_size = vma->vm_start - addr;
5353
5354 /* try just below the current vma->vm_start */
5355- addr = vma->vm_start;
5356+ addr = skip_heap_stack_gap(vma, len);
5357 }
5358
5359 /*
5360@@ -442,6 +446,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
5361 if (fixed && addr > (mm->task_size - len))
5362 return -EINVAL;
5363
5364+#ifdef CONFIG_PAX_RANDMMAP
5365+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
5366+ addr = 0;
5367+#endif
5368+
5369 /* If hint, make sure it matches our alignment restrictions */
5370 if (!fixed && addr) {
5371 addr = _ALIGN_UP(addr, 1ul << pshift);
5372diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
5373index c797832..ce575c8 100644
5374--- a/arch/s390/include/asm/atomic.h
5375+++ b/arch/s390/include/asm/atomic.h
5376@@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
5377 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
5378 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5379
5380+#define atomic64_read_unchecked(v) atomic64_read(v)
5381+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5382+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5383+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5384+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5385+#define atomic64_inc_unchecked(v) atomic64_inc(v)
5386+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5387+#define atomic64_dec_unchecked(v) atomic64_dec(v)
5388+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5389+
5390 #define smp_mb__before_atomic_dec() smp_mb()
5391 #define smp_mb__after_atomic_dec() smp_mb()
5392 #define smp_mb__before_atomic_inc() smp_mb()
5393diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
5394index 4d7ccac..d03d0ad 100644
5395--- a/arch/s390/include/asm/cache.h
5396+++ b/arch/s390/include/asm/cache.h
5397@@ -9,8 +9,10 @@
5398 #ifndef __ARCH_S390_CACHE_H
5399 #define __ARCH_S390_CACHE_H
5400
5401-#define L1_CACHE_BYTES 256
5402+#include <linux/const.h>
5403+
5404 #define L1_CACHE_SHIFT 8
5405+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5406 #define NET_SKB_PAD 32
5407
5408 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
5409diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
5410index 178ff96..8c93bd1 100644
5411--- a/arch/s390/include/asm/elf.h
5412+++ b/arch/s390/include/asm/elf.h
5413@@ -160,8 +160,14 @@ extern unsigned int vdso_enabled;
5414 the loader. We need to make sure that it is out of the way of the program
5415 that it will "exec", and that there is sufficient room for the brk. */
5416
5417-extern unsigned long randomize_et_dyn(unsigned long base);
5418-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
5419+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
5420+
5421+#ifdef CONFIG_PAX_ASLR
5422+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
5423+
5424+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
5425+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
5426+#endif
5427
5428 /* This yields a mask that user programs can use to figure out what
5429 instruction set this CPU supports. */
5430@@ -210,9 +216,6 @@ struct linux_binprm;
5431 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
5432 int arch_setup_additional_pages(struct linux_binprm *, int);
5433
5434-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
5435-#define arch_randomize_brk arch_randomize_brk
5436-
5437 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
5438
5439 #endif
5440diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
5441index c4a93d6..4d2a9b4 100644
5442--- a/arch/s390/include/asm/exec.h
5443+++ b/arch/s390/include/asm/exec.h
5444@@ -7,6 +7,6 @@
5445 #ifndef __ASM_EXEC_H
5446 #define __ASM_EXEC_H
5447
5448-extern unsigned long arch_align_stack(unsigned long sp);
5449+#define arch_align_stack(x) ((x) & ~0xfUL)
5450
5451 #endif /* __ASM_EXEC_H */
5452diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
5453index 34268df..ea97318 100644
5454--- a/arch/s390/include/asm/uaccess.h
5455+++ b/arch/s390/include/asm/uaccess.h
5456@@ -252,6 +252,10 @@ static inline unsigned long __must_check
5457 copy_to_user(void __user *to, const void *from, unsigned long n)
5458 {
5459 might_fault();
5460+
5461+ if ((long)n < 0)
5462+ return n;
5463+
5464 if (access_ok(VERIFY_WRITE, to, n))
5465 n = __copy_to_user(to, from, n);
5466 return n;
5467@@ -277,6 +281,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
5468 static inline unsigned long __must_check
5469 __copy_from_user(void *to, const void __user *from, unsigned long n)
5470 {
5471+ if ((long)n < 0)
5472+ return n;
5473+
5474 if (__builtin_constant_p(n) && (n <= 256))
5475 return uaccess.copy_from_user_small(n, from, to);
5476 else
5477@@ -308,10 +315,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
5478 static inline unsigned long __must_check
5479 copy_from_user(void *to, const void __user *from, unsigned long n)
5480 {
5481- unsigned int sz = __compiletime_object_size(to);
5482+ size_t sz = __compiletime_object_size(to);
5483
5484 might_fault();
5485- if (unlikely(sz != -1 && sz < n)) {
5486+
5487+ if ((long)n < 0)
5488+ return n;
5489+
5490+ if (unlikely(sz != (size_t)-1 && sz < n)) {
5491 copy_from_user_overflow();
5492 return n;
5493 }
5494diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
5495index 4610dea..cf0af21 100644
5496--- a/arch/s390/kernel/module.c
5497+++ b/arch/s390/kernel/module.c
5498@@ -171,11 +171,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
5499
5500 /* Increase core size by size of got & plt and set start
5501 offsets for got and plt. */
5502- me->core_size = ALIGN(me->core_size, 4);
5503- me->arch.got_offset = me->core_size;
5504- me->core_size += me->arch.got_size;
5505- me->arch.plt_offset = me->core_size;
5506- me->core_size += me->arch.plt_size;
5507+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
5508+ me->arch.got_offset = me->core_size_rw;
5509+ me->core_size_rw += me->arch.got_size;
5510+ me->arch.plt_offset = me->core_size_rx;
5511+ me->core_size_rx += me->arch.plt_size;
5512 return 0;
5513 }
5514
5515@@ -252,7 +252,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
5516 if (info->got_initialized == 0) {
5517 Elf_Addr *gotent;
5518
5519- gotent = me->module_core + me->arch.got_offset +
5520+ gotent = me->module_core_rw + me->arch.got_offset +
5521 info->got_offset;
5522 *gotent = val;
5523 info->got_initialized = 1;
5524@@ -276,7 +276,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
5525 else if (r_type == R_390_GOTENT ||
5526 r_type == R_390_GOTPLTENT)
5527 *(unsigned int *) loc =
5528- (val + (Elf_Addr) me->module_core - loc) >> 1;
5529+ (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
5530 else if (r_type == R_390_GOT64 ||
5531 r_type == R_390_GOTPLT64)
5532 *(unsigned long *) loc = val;
5533@@ -290,7 +290,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
5534 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
5535 if (info->plt_initialized == 0) {
5536 unsigned int *ip;
5537- ip = me->module_core + me->arch.plt_offset +
5538+ ip = me->module_core_rx + me->arch.plt_offset +
5539 info->plt_offset;
5540 #ifndef CONFIG_64BIT
5541 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
5542@@ -315,7 +315,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
5543 val - loc + 0xffffUL < 0x1ffffeUL) ||
5544 (r_type == R_390_PLT32DBL &&
5545 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
5546- val = (Elf_Addr) me->module_core +
5547+ val = (Elf_Addr) me->module_core_rx +
5548 me->arch.plt_offset +
5549 info->plt_offset;
5550 val += rela->r_addend - loc;
5551@@ -337,7 +337,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
5552 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
5553 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
5554 val = val + rela->r_addend -
5555- ((Elf_Addr) me->module_core + me->arch.got_offset);
5556+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
5557 if (r_type == R_390_GOTOFF16)
5558 *(unsigned short *) loc = val;
5559 else if (r_type == R_390_GOTOFF32)
5560@@ -347,7 +347,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
5561 break;
5562 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
5563 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
5564- val = (Elf_Addr) me->module_core + me->arch.got_offset +
5565+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
5566 rela->r_addend - loc;
5567 if (r_type == R_390_GOTPC)
5568 *(unsigned int *) loc = val;
5569diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
5570index cd31ad4..201c5a3 100644
5571--- a/arch/s390/kernel/process.c
5572+++ b/arch/s390/kernel/process.c
5573@@ -283,39 +283,3 @@ unsigned long get_wchan(struct task_struct *p)
5574 }
5575 return 0;
5576 }
5577-
5578-unsigned long arch_align_stack(unsigned long sp)
5579-{
5580- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
5581- sp -= get_random_int() & ~PAGE_MASK;
5582- return sp & ~0xf;
5583-}
5584-
5585-static inline unsigned long brk_rnd(void)
5586-{
5587- /* 8MB for 32bit, 1GB for 64bit */
5588- if (is_32bit_task())
5589- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
5590- else
5591- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
5592-}
5593-
5594-unsigned long arch_randomize_brk(struct mm_struct *mm)
5595-{
5596- unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
5597-
5598- if (ret < mm->brk)
5599- return mm->brk;
5600- return ret;
5601-}
5602-
5603-unsigned long randomize_et_dyn(unsigned long base)
5604-{
5605- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
5606-
5607- if (!(current->flags & PF_RANDOMIZE))
5608- return base;
5609- if (ret < base)
5610- return base;
5611- return ret;
5612-}
5613diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
5614index c59a5ef..3fae59c 100644
5615--- a/arch/s390/mm/mmap.c
5616+++ b/arch/s390/mm/mmap.c
5617@@ -90,10 +90,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5618 */
5619 if (mmap_is_legacy()) {
5620 mm->mmap_base = TASK_UNMAPPED_BASE;
5621+
5622+#ifdef CONFIG_PAX_RANDMMAP
5623+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5624+ mm->mmap_base += mm->delta_mmap;
5625+#endif
5626+
5627 mm->get_unmapped_area = arch_get_unmapped_area;
5628 mm->unmap_area = arch_unmap_area;
5629 } else {
5630 mm->mmap_base = mmap_base();
5631+
5632+#ifdef CONFIG_PAX_RANDMMAP
5633+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5634+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5635+#endif
5636+
5637 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5638 mm->unmap_area = arch_unmap_area_topdown;
5639 }
5640@@ -172,10 +184,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5641 */
5642 if (mmap_is_legacy()) {
5643 mm->mmap_base = TASK_UNMAPPED_BASE;
5644+
5645+#ifdef CONFIG_PAX_RANDMMAP
5646+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5647+ mm->mmap_base += mm->delta_mmap;
5648+#endif
5649+
5650 mm->get_unmapped_area = s390_get_unmapped_area;
5651 mm->unmap_area = arch_unmap_area;
5652 } else {
5653 mm->mmap_base = mmap_base();
5654+
5655+#ifdef CONFIG_PAX_RANDMMAP
5656+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5657+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5658+#endif
5659+
5660 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
5661 mm->unmap_area = arch_unmap_area_topdown;
5662 }
5663diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
5664index ae3d59f..f65f075 100644
5665--- a/arch/score/include/asm/cache.h
5666+++ b/arch/score/include/asm/cache.h
5667@@ -1,7 +1,9 @@
5668 #ifndef _ASM_SCORE_CACHE_H
5669 #define _ASM_SCORE_CACHE_H
5670
5671+#include <linux/const.h>
5672+
5673 #define L1_CACHE_SHIFT 4
5674-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5675+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5676
5677 #endif /* _ASM_SCORE_CACHE_H */
5678diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
5679index f9f3cd5..58ff438 100644
5680--- a/arch/score/include/asm/exec.h
5681+++ b/arch/score/include/asm/exec.h
5682@@ -1,6 +1,6 @@
5683 #ifndef _ASM_SCORE_EXEC_H
5684 #define _ASM_SCORE_EXEC_H
5685
5686-extern unsigned long arch_align_stack(unsigned long sp);
5687+#define arch_align_stack(x) (x)
5688
5689 #endif /* _ASM_SCORE_EXEC_H */
5690diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
5691index 637970c..0b6556b 100644
5692--- a/arch/score/kernel/process.c
5693+++ b/arch/score/kernel/process.c
5694@@ -161,8 +161,3 @@ unsigned long get_wchan(struct task_struct *task)
5695
5696 return task_pt_regs(task)->cp0_epc;
5697 }
5698-
5699-unsigned long arch_align_stack(unsigned long sp)
5700-{
5701- return sp;
5702-}
5703diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
5704index ef9e555..331bd29 100644
5705--- a/arch/sh/include/asm/cache.h
5706+++ b/arch/sh/include/asm/cache.h
5707@@ -9,10 +9,11 @@
5708 #define __ASM_SH_CACHE_H
5709 #ifdef __KERNEL__
5710
5711+#include <linux/const.h>
5712 #include <linux/init.h>
5713 #include <cpu/cache.h>
5714
5715-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5716+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5717
5718 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
5719
5720diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
5721index afeb710..d1d1289 100644
5722--- a/arch/sh/mm/mmap.c
5723+++ b/arch/sh/mm/mmap.c
5724@@ -74,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
5725 addr = PAGE_ALIGN(addr);
5726
5727 vma = find_vma(mm, addr);
5728- if (TASK_SIZE - len >= addr &&
5729- (!vma || addr + len <= vma->vm_start))
5730+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
5731 return addr;
5732 }
5733
5734@@ -106,7 +105,7 @@ full_search:
5735 }
5736 return -ENOMEM;
5737 }
5738- if (likely(!vma || addr + len <= vma->vm_start)) {
5739+ if (likely(check_heap_stack_gap(vma, addr, len))) {
5740 /*
5741 * Remember the place where we stopped the search:
5742 */
5743@@ -157,8 +156,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5744 addr = PAGE_ALIGN(addr);
5745
5746 vma = find_vma(mm, addr);
5747- if (TASK_SIZE - len >= addr &&
5748- (!vma || addr + len <= vma->vm_start))
5749+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
5750 return addr;
5751 }
5752
5753@@ -179,7 +177,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5754 /* make sure it can fit in the remaining address space */
5755 if (likely(addr > len)) {
5756 vma = find_vma(mm, addr-len);
5757- if (!vma || addr <= vma->vm_start) {
5758+ if (check_heap_stack_gap(vma, addr - len, len)) {
5759 /* remember the address as a hint for next time */
5760 return (mm->free_area_cache = addr-len);
5761 }
5762@@ -188,18 +186,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5763 if (unlikely(mm->mmap_base < len))
5764 goto bottomup;
5765
5766- addr = mm->mmap_base-len;
5767- if (do_colour_align)
5768- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5769+ addr = mm->mmap_base - len;
5770
5771 do {
5772+ if (do_colour_align)
5773+ addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5774 /*
5775 * Lookup failure means no vma is above this address,
5776 * else if new region fits below vma->vm_start,
5777 * return with success:
5778 */
5779 vma = find_vma(mm, addr);
5780- if (likely(!vma || addr+len <= vma->vm_start)) {
5781+ if (likely(check_heap_stack_gap(vma, addr, len))) {
5782 /* remember the address as a hint for next time */
5783 return (mm->free_area_cache = addr);
5784 }
5785@@ -209,10 +207,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5786 mm->cached_hole_size = vma->vm_start - addr;
5787
5788 /* try just below the current vma->vm_start */
5789- addr = vma->vm_start-len;
5790- if (do_colour_align)
5791- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5792- } while (likely(len < vma->vm_start));
5793+ addr = skip_heap_stack_gap(vma, len);
5794+ } while (!IS_ERR_VALUE(addr));
5795
5796 bottomup:
5797 /*
5798diff --git a/arch/sparc/crypto/aes_asm.S b/arch/sparc/crypto/aes_asm.S
5799index 23f6cbb..1cda8aa 100644
5800--- a/arch/sparc/crypto/aes_asm.S
5801+++ b/arch/sparc/crypto/aes_asm.S
5802@@ -1024,7 +1024,11 @@ ENTRY(aes_sparc64_ecb_encrypt_256)
5803 add %o2, 0x20, %o2
5804 brlz,pt %o3, 11f
5805 nop
5806-10: ldx [%o1 + 0x00], %g3
5807+10: ldd [%o0 + 0xd0], %f56
5808+ ldd [%o0 + 0xd8], %f58
5809+ ldd [%o0 + 0xe0], %f60
5810+ ldd [%o0 + 0xe8], %f62
5811+ ldx [%o1 + 0x00], %g3
5812 ldx [%o1 + 0x08], %g7
5813 xor %g1, %g3, %g3
5814 xor %g2, %g7, %g7
5815@@ -1128,9 +1132,9 @@ ENTRY(aes_sparc64_ecb_decrypt_256)
5816 /* %o0=&key[key_len], %o1=input, %o2=output, %o3=len */
5817 ldx [%o0 - 0x10], %g1
5818 subcc %o3, 0x10, %o3
5819+ ldx [%o0 - 0x08], %g2
5820 be 10f
5821- ldx [%o0 - 0x08], %g2
5822- sub %o0, 0xf0, %o0
5823+ sub %o0, 0xf0, %o0
5824 1: ldx [%o1 + 0x00], %g3
5825 ldx [%o1 + 0x08], %g7
5826 ldx [%o1 + 0x10], %o4
5827@@ -1154,7 +1158,11 @@ ENTRY(aes_sparc64_ecb_decrypt_256)
5828 add %o2, 0x20, %o2
5829 brlz,pt %o3, 11f
5830 nop
5831-10: ldx [%o1 + 0x00], %g3
5832+10: ldd [%o0 + 0x18], %f56
5833+ ldd [%o0 + 0x10], %f58
5834+ ldd [%o0 + 0x08], %f60
5835+ ldd [%o0 + 0x00], %f62
5836+ ldx [%o1 + 0x00], %g3
5837 ldx [%o1 + 0x08], %g7
5838 xor %g1, %g3, %g3
5839 xor %g2, %g7, %g7
5840@@ -1511,11 +1519,11 @@ ENTRY(aes_sparc64_ctr_crypt_256)
5841 add %o2, 0x20, %o2
5842 brlz,pt %o3, 11f
5843 nop
5844- ldd [%o0 + 0xd0], %f56
5845+10: ldd [%o0 + 0xd0], %f56
5846 ldd [%o0 + 0xd8], %f58
5847 ldd [%o0 + 0xe0], %f60
5848 ldd [%o0 + 0xe8], %f62
5849-10: xor %g1, %g3, %o5
5850+ xor %g1, %g3, %o5
5851 MOVXTOD_O5_F0
5852 xor %g2, %g7, %o5
5853 MOVXTOD_O5_F2
5854diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
5855index be56a24..443328f 100644
5856--- a/arch/sparc/include/asm/atomic_64.h
5857+++ b/arch/sparc/include/asm/atomic_64.h
5858@@ -14,18 +14,40 @@
5859 #define ATOMIC64_INIT(i) { (i) }
5860
5861 #define atomic_read(v) (*(volatile int *)&(v)->counter)
5862+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5863+{
5864+ return v->counter;
5865+}
5866 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
5867+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
5868+{
5869+ return v->counter;
5870+}
5871
5872 #define atomic_set(v, i) (((v)->counter) = i)
5873+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5874+{
5875+ v->counter = i;
5876+}
5877 #define atomic64_set(v, i) (((v)->counter) = i)
5878+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
5879+{
5880+ v->counter = i;
5881+}
5882
5883 extern void atomic_add(int, atomic_t *);
5884+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
5885 extern void atomic64_add(long, atomic64_t *);
5886+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
5887 extern void atomic_sub(int, atomic_t *);
5888+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
5889 extern void atomic64_sub(long, atomic64_t *);
5890+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
5891
5892 extern int atomic_add_ret(int, atomic_t *);
5893+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
5894 extern long atomic64_add_ret(long, atomic64_t *);
5895+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
5896 extern int atomic_sub_ret(int, atomic_t *);
5897 extern long atomic64_sub_ret(long, atomic64_t *);
5898
5899@@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5900 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
5901
5902 #define atomic_inc_return(v) atomic_add_ret(1, v)
5903+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5904+{
5905+ return atomic_add_ret_unchecked(1, v);
5906+}
5907 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
5908+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
5909+{
5910+ return atomic64_add_ret_unchecked(1, v);
5911+}
5912
5913 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
5914 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
5915
5916 #define atomic_add_return(i, v) atomic_add_ret(i, v)
5917+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5918+{
5919+ return atomic_add_ret_unchecked(i, v);
5920+}
5921 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
5922+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
5923+{
5924+ return atomic64_add_ret_unchecked(i, v);
5925+}
5926
5927 /*
5928 * atomic_inc_and_test - increment and test
5929@@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5930 * other cases.
5931 */
5932 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5933+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5934+{
5935+ return atomic_inc_return_unchecked(v) == 0;
5936+}
5937 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
5938
5939 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
5940@@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5941 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
5942
5943 #define atomic_inc(v) atomic_add(1, v)
5944+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
5945+{
5946+ atomic_add_unchecked(1, v);
5947+}
5948 #define atomic64_inc(v) atomic64_add(1, v)
5949+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
5950+{
5951+ atomic64_add_unchecked(1, v);
5952+}
5953
5954 #define atomic_dec(v) atomic_sub(1, v)
5955+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
5956+{
5957+ atomic_sub_unchecked(1, v);
5958+}
5959 #define atomic64_dec(v) atomic64_sub(1, v)
5960+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
5961+{
5962+ atomic64_sub_unchecked(1, v);
5963+}
5964
5965 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
5966 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
5967
5968 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5969+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
5970+{
5971+ return cmpxchg(&v->counter, old, new);
5972+}
5973 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
5974+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5975+{
5976+ return xchg(&v->counter, new);
5977+}
5978
5979 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
5980 {
5981- int c, old;
5982+ int c, old, new;
5983 c = atomic_read(v);
5984 for (;;) {
5985- if (unlikely(c == (u)))
5986+ if (unlikely(c == u))
5987 break;
5988- old = atomic_cmpxchg((v), c, c + (a));
5989+
5990+ asm volatile("addcc %2, %0, %0\n"
5991+
5992+#ifdef CONFIG_PAX_REFCOUNT
5993+ "tvs %%icc, 6\n"
5994+#endif
5995+
5996+ : "=r" (new)
5997+ : "0" (c), "ir" (a)
5998+ : "cc");
5999+
6000+ old = atomic_cmpxchg(v, c, new);
6001 if (likely(old == c))
6002 break;
6003 c = old;
6004@@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
6005 #define atomic64_cmpxchg(v, o, n) \
6006 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
6007 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
6008+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
6009+{
6010+ return xchg(&v->counter, new);
6011+}
6012
6013 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
6014 {
6015- long c, old;
6016+ long c, old, new;
6017 c = atomic64_read(v);
6018 for (;;) {
6019- if (unlikely(c == (u)))
6020+ if (unlikely(c == u))
6021 break;
6022- old = atomic64_cmpxchg((v), c, c + (a));
6023+
6024+ asm volatile("addcc %2, %0, %0\n"
6025+
6026+#ifdef CONFIG_PAX_REFCOUNT
6027+ "tvs %%xcc, 6\n"
6028+#endif
6029+
6030+ : "=r" (new)
6031+ : "0" (c), "ir" (a)
6032+ : "cc");
6033+
6034+ old = atomic64_cmpxchg(v, c, new);
6035 if (likely(old == c))
6036 break;
6037 c = old;
6038 }
6039- return c != (u);
6040+ return c != u;
6041 }
6042
6043 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
6044diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
6045index 5bb6991..5c2132e 100644
6046--- a/arch/sparc/include/asm/cache.h
6047+++ b/arch/sparc/include/asm/cache.h
6048@@ -7,10 +7,12 @@
6049 #ifndef _SPARC_CACHE_H
6050 #define _SPARC_CACHE_H
6051
6052+#include <linux/const.h>
6053+
6054 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
6055
6056 #define L1_CACHE_SHIFT 5
6057-#define L1_CACHE_BYTES 32
6058+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6059
6060 #ifdef CONFIG_SPARC32
6061 #define SMP_CACHE_BYTES_SHIFT 5
6062diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
6063index ac74a2c..a9e58af 100644
6064--- a/arch/sparc/include/asm/elf_32.h
6065+++ b/arch/sparc/include/asm/elf_32.h
6066@@ -114,6 +114,13 @@ typedef struct {
6067
6068 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
6069
6070+#ifdef CONFIG_PAX_ASLR
6071+#define PAX_ELF_ET_DYN_BASE 0x10000UL
6072+
6073+#define PAX_DELTA_MMAP_LEN 16
6074+#define PAX_DELTA_STACK_LEN 16
6075+#endif
6076+
6077 /* This yields a mask that user programs can use to figure out what
6078 instruction set this cpu supports. This can NOT be done in userspace
6079 on Sparc. */
6080diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
6081index 370ca1e..d4f4a98 100644
6082--- a/arch/sparc/include/asm/elf_64.h
6083+++ b/arch/sparc/include/asm/elf_64.h
6084@@ -189,6 +189,13 @@ typedef struct {
6085 #define ELF_ET_DYN_BASE 0x0000010000000000UL
6086 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
6087
6088+#ifdef CONFIG_PAX_ASLR
6089+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
6090+
6091+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
6092+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
6093+#endif
6094+
6095 extern unsigned long sparc64_elf_hwcap;
6096 #define ELF_HWCAP sparc64_elf_hwcap
6097
6098diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
6099index 9b1c36d..209298b 100644
6100--- a/arch/sparc/include/asm/pgalloc_32.h
6101+++ b/arch/sparc/include/asm/pgalloc_32.h
6102@@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
6103 }
6104
6105 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
6106+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
6107
6108 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
6109 unsigned long address)
6110diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
6111index bcfe063..b333142 100644
6112--- a/arch/sparc/include/asm/pgalloc_64.h
6113+++ b/arch/sparc/include/asm/pgalloc_64.h
6114@@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
6115 }
6116
6117 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
6118+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
6119
6120 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
6121 {
6122diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
6123index 6fc1348..390c50a 100644
6124--- a/arch/sparc/include/asm/pgtable_32.h
6125+++ b/arch/sparc/include/asm/pgtable_32.h
6126@@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
6127 #define PAGE_SHARED SRMMU_PAGE_SHARED
6128 #define PAGE_COPY SRMMU_PAGE_COPY
6129 #define PAGE_READONLY SRMMU_PAGE_RDONLY
6130+#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
6131+#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
6132+#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
6133 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
6134
6135 /* Top-level page directory - dummy used by init-mm.
6136@@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
6137
6138 /* xwr */
6139 #define __P000 PAGE_NONE
6140-#define __P001 PAGE_READONLY
6141-#define __P010 PAGE_COPY
6142-#define __P011 PAGE_COPY
6143+#define __P001 PAGE_READONLY_NOEXEC
6144+#define __P010 PAGE_COPY_NOEXEC
6145+#define __P011 PAGE_COPY_NOEXEC
6146 #define __P100 PAGE_READONLY
6147 #define __P101 PAGE_READONLY
6148 #define __P110 PAGE_COPY
6149 #define __P111 PAGE_COPY
6150
6151 #define __S000 PAGE_NONE
6152-#define __S001 PAGE_READONLY
6153-#define __S010 PAGE_SHARED
6154-#define __S011 PAGE_SHARED
6155+#define __S001 PAGE_READONLY_NOEXEC
6156+#define __S010 PAGE_SHARED_NOEXEC
6157+#define __S011 PAGE_SHARED_NOEXEC
6158 #define __S100 PAGE_READONLY
6159 #define __S101 PAGE_READONLY
6160 #define __S110 PAGE_SHARED
6161diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
6162index 79da178..c2eede8 100644
6163--- a/arch/sparc/include/asm/pgtsrmmu.h
6164+++ b/arch/sparc/include/asm/pgtsrmmu.h
6165@@ -115,6 +115,11 @@
6166 SRMMU_EXEC | SRMMU_REF)
6167 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
6168 SRMMU_EXEC | SRMMU_REF)
6169+
6170+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
6171+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
6172+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
6173+
6174 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
6175 SRMMU_DIRTY | SRMMU_REF)
6176
6177diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
6178index 9689176..63c18ea 100644
6179--- a/arch/sparc/include/asm/spinlock_64.h
6180+++ b/arch/sparc/include/asm/spinlock_64.h
6181@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
6182
6183 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
6184
6185-static void inline arch_read_lock(arch_rwlock_t *lock)
6186+static inline void arch_read_lock(arch_rwlock_t *lock)
6187 {
6188 unsigned long tmp1, tmp2;
6189
6190 __asm__ __volatile__ (
6191 "1: ldsw [%2], %0\n"
6192 " brlz,pn %0, 2f\n"
6193-"4: add %0, 1, %1\n"
6194+"4: addcc %0, 1, %1\n"
6195+
6196+#ifdef CONFIG_PAX_REFCOUNT
6197+" tvs %%icc, 6\n"
6198+#endif
6199+
6200 " cas [%2], %0, %1\n"
6201 " cmp %0, %1\n"
6202 " bne,pn %%icc, 1b\n"
6203@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
6204 " .previous"
6205 : "=&r" (tmp1), "=&r" (tmp2)
6206 : "r" (lock)
6207- : "memory");
6208+ : "memory", "cc");
6209 }
6210
6211-static int inline arch_read_trylock(arch_rwlock_t *lock)
6212+static inline int arch_read_trylock(arch_rwlock_t *lock)
6213 {
6214 int tmp1, tmp2;
6215
6216@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
6217 "1: ldsw [%2], %0\n"
6218 " brlz,a,pn %0, 2f\n"
6219 " mov 0, %0\n"
6220-" add %0, 1, %1\n"
6221+" addcc %0, 1, %1\n"
6222+
6223+#ifdef CONFIG_PAX_REFCOUNT
6224+" tvs %%icc, 6\n"
6225+#endif
6226+
6227 " cas [%2], %0, %1\n"
6228 " cmp %0, %1\n"
6229 " bne,pn %%icc, 1b\n"
6230@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
6231 return tmp1;
6232 }
6233
6234-static void inline arch_read_unlock(arch_rwlock_t *lock)
6235+static inline void arch_read_unlock(arch_rwlock_t *lock)
6236 {
6237 unsigned long tmp1, tmp2;
6238
6239 __asm__ __volatile__(
6240 "1: lduw [%2], %0\n"
6241-" sub %0, 1, %1\n"
6242+" subcc %0, 1, %1\n"
6243+
6244+#ifdef CONFIG_PAX_REFCOUNT
6245+" tvs %%icc, 6\n"
6246+#endif
6247+
6248 " cas [%2], %0, %1\n"
6249 " cmp %0, %1\n"
6250 " bne,pn %%xcc, 1b\n"
6251@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
6252 : "memory");
6253 }
6254
6255-static void inline arch_write_lock(arch_rwlock_t *lock)
6256+static inline void arch_write_lock(arch_rwlock_t *lock)
6257 {
6258 unsigned long mask, tmp1, tmp2;
6259
6260@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
6261 : "memory");
6262 }
6263
6264-static void inline arch_write_unlock(arch_rwlock_t *lock)
6265+static inline void arch_write_unlock(arch_rwlock_t *lock)
6266 {
6267 __asm__ __volatile__(
6268 " stw %%g0, [%0]"
6269@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
6270 : "memory");
6271 }
6272
6273-static int inline arch_write_trylock(arch_rwlock_t *lock)
6274+static inline int arch_write_trylock(arch_rwlock_t *lock)
6275 {
6276 unsigned long mask, tmp1, tmp2, result;
6277
6278diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
6279index 25849ae..924c54b 100644
6280--- a/arch/sparc/include/asm/thread_info_32.h
6281+++ b/arch/sparc/include/asm/thread_info_32.h
6282@@ -49,6 +49,8 @@ struct thread_info {
6283 unsigned long w_saved;
6284
6285 struct restart_block restart_block;
6286+
6287+ unsigned long lowest_stack;
6288 };
6289
6290 /*
6291diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
6292index a3fe4dc..cae132a 100644
6293--- a/arch/sparc/include/asm/thread_info_64.h
6294+++ b/arch/sparc/include/asm/thread_info_64.h
6295@@ -63,6 +63,8 @@ struct thread_info {
6296 struct pt_regs *kern_una_regs;
6297 unsigned int kern_una_insn;
6298
6299+ unsigned long lowest_stack;
6300+
6301 unsigned long fpregs[0] __attribute__ ((aligned(64)));
6302 };
6303
6304@@ -193,10 +195,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
6305 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
6306 /* flag bit 6 is available */
6307 #define TIF_32BIT 7 /* 32-bit binary */
6308-/* flag bit 8 is available */
6309+#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
6310 #define TIF_SECCOMP 9 /* secure computing */
6311 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
6312 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
6313+
6314 /* NOTE: Thread flags >= 12 should be ones we have no interest
6315 * in using in assembly, else we can't use the mask as
6316 * an immediate value in instructions such as andcc.
6317@@ -215,12 +218,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
6318 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
6319 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6320 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
6321+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6322
6323 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
6324 _TIF_DO_NOTIFY_RESUME_MASK | \
6325 _TIF_NEED_RESCHED)
6326 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
6327
6328+#define _TIF_WORK_SYSCALL \
6329+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
6330+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6331+
6332+
6333 /*
6334 * Thread-synchronous status.
6335 *
6336diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
6337index 0167d26..9acd8ed 100644
6338--- a/arch/sparc/include/asm/uaccess.h
6339+++ b/arch/sparc/include/asm/uaccess.h
6340@@ -1,5 +1,13 @@
6341 #ifndef ___ASM_SPARC_UACCESS_H
6342 #define ___ASM_SPARC_UACCESS_H
6343+
6344+#ifdef __KERNEL__
6345+#ifndef __ASSEMBLY__
6346+#include <linux/types.h>
6347+extern void check_object_size(const void *ptr, unsigned long n, bool to);
6348+#endif
6349+#endif
6350+
6351 #if defined(__sparc__) && defined(__arch64__)
6352 #include <asm/uaccess_64.h>
6353 #else
6354diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
6355index 53a28dd..50c38c3 100644
6356--- a/arch/sparc/include/asm/uaccess_32.h
6357+++ b/arch/sparc/include/asm/uaccess_32.h
6358@@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
6359
6360 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
6361 {
6362- if (n && __access_ok((unsigned long) to, n))
6363+ if ((long)n < 0)
6364+ return n;
6365+
6366+ if (n && __access_ok((unsigned long) to, n)) {
6367+ if (!__builtin_constant_p(n))
6368+ check_object_size(from, n, true);
6369 return __copy_user(to, (__force void __user *) from, n);
6370- else
6371+ } else
6372 return n;
6373 }
6374
6375 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
6376 {
6377+ if ((long)n < 0)
6378+ return n;
6379+
6380+ if (!__builtin_constant_p(n))
6381+ check_object_size(from, n, true);
6382+
6383 return __copy_user(to, (__force void __user *) from, n);
6384 }
6385
6386 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
6387 {
6388- if (n && __access_ok((unsigned long) from, n))
6389+ if ((long)n < 0)
6390+ return n;
6391+
6392+ if (n && __access_ok((unsigned long) from, n)) {
6393+ if (!__builtin_constant_p(n))
6394+ check_object_size(to, n, false);
6395 return __copy_user((__force void __user *) to, from, n);
6396- else
6397+ } else
6398 return n;
6399 }
6400
6401 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
6402 {
6403+ if ((long)n < 0)
6404+ return n;
6405+
6406 return __copy_user((__force void __user *) to, from, n);
6407 }
6408
6409diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
6410index 73083e1..2bc62a6 100644
6411--- a/arch/sparc/include/asm/uaccess_64.h
6412+++ b/arch/sparc/include/asm/uaccess_64.h
6413@@ -10,6 +10,7 @@
6414 #include <linux/compiler.h>
6415 #include <linux/string.h>
6416 #include <linux/thread_info.h>
6417+#include <linux/kernel.h>
6418 #include <asm/asi.h>
6419 #include <asm/spitfire.h>
6420 #include <asm-generic/uaccess-unaligned.h>
6421@@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
6422 static inline unsigned long __must_check
6423 copy_from_user(void *to, const void __user *from, unsigned long size)
6424 {
6425- unsigned long ret = ___copy_from_user(to, from, size);
6426+ unsigned long ret;
6427
6428+ if ((long)size < 0 || size > INT_MAX)
6429+ return size;
6430+
6431+ if (!__builtin_constant_p(size))
6432+ check_object_size(to, size, false);
6433+
6434+ ret = ___copy_from_user(to, from, size);
6435 if (unlikely(ret))
6436 ret = copy_from_user_fixup(to, from, size);
6437
6438@@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
6439 static inline unsigned long __must_check
6440 copy_to_user(void __user *to, const void *from, unsigned long size)
6441 {
6442- unsigned long ret = ___copy_to_user(to, from, size);
6443+ unsigned long ret;
6444
6445+ if ((long)size < 0 || size > INT_MAX)
6446+ return size;
6447+
6448+ if (!__builtin_constant_p(size))
6449+ check_object_size(from, size, true);
6450+
6451+ ret = ___copy_to_user(to, from, size);
6452 if (unlikely(ret))
6453 ret = copy_to_user_fixup(to, from, size);
6454 return ret;
6455diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
6456index 6cf591b..b49e65a 100644
6457--- a/arch/sparc/kernel/Makefile
6458+++ b/arch/sparc/kernel/Makefile
6459@@ -3,7 +3,7 @@
6460 #
6461
6462 asflags-y := -ansi
6463-ccflags-y := -Werror
6464+#ccflags-y := -Werror
6465
6466 extra-y := head_$(BITS).o
6467
6468diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
6469index 487bffb..955a925 100644
6470--- a/arch/sparc/kernel/process_32.c
6471+++ b/arch/sparc/kernel/process_32.c
6472@@ -126,14 +126,14 @@ void show_regs(struct pt_regs *r)
6473
6474 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
6475 r->psr, r->pc, r->npc, r->y, print_tainted());
6476- printk("PC: <%pS>\n", (void *) r->pc);
6477+ printk("PC: <%pA>\n", (void *) r->pc);
6478 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
6479 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
6480 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
6481 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
6482 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
6483 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
6484- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
6485+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
6486
6487 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
6488 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
6489@@ -168,7 +168,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
6490 rw = (struct reg_window32 *) fp;
6491 pc = rw->ins[7];
6492 printk("[%08lx : ", pc);
6493- printk("%pS ] ", (void *) pc);
6494+ printk("%pA ] ", (void *) pc);
6495 fp = rw->ins[6];
6496 } while (++count < 16);
6497 printk("\n");
6498diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
6499index c6e0c29..052832b 100644
6500--- a/arch/sparc/kernel/process_64.c
6501+++ b/arch/sparc/kernel/process_64.c
6502@@ -181,14 +181,14 @@ static void show_regwindow(struct pt_regs *regs)
6503 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
6504 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
6505 if (regs->tstate & TSTATE_PRIV)
6506- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
6507+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
6508 }
6509
6510 void show_regs(struct pt_regs *regs)
6511 {
6512 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
6513 regs->tpc, regs->tnpc, regs->y, print_tainted());
6514- printk("TPC: <%pS>\n", (void *) regs->tpc);
6515+ printk("TPC: <%pA>\n", (void *) regs->tpc);
6516 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
6517 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
6518 regs->u_regs[3]);
6519@@ -201,7 +201,7 @@ void show_regs(struct pt_regs *regs)
6520 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
6521 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
6522 regs->u_regs[15]);
6523- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
6524+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
6525 show_regwindow(regs);
6526 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
6527 }
6528@@ -290,7 +290,7 @@ void arch_trigger_all_cpu_backtrace(void)
6529 ((tp && tp->task) ? tp->task->pid : -1));
6530
6531 if (gp->tstate & TSTATE_PRIV) {
6532- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
6533+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
6534 (void *) gp->tpc,
6535 (void *) gp->o7,
6536 (void *) gp->i7,
6537diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
6538index 7ff45e4..a58f271 100644
6539--- a/arch/sparc/kernel/ptrace_64.c
6540+++ b/arch/sparc/kernel/ptrace_64.c
6541@@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
6542 return ret;
6543 }
6544
6545+#ifdef CONFIG_GRKERNSEC_SETXID
6546+extern void gr_delayed_cred_worker(void);
6547+#endif
6548+
6549 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
6550 {
6551 int ret = 0;
6552@@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
6553 /* do the secure computing check first */
6554 secure_computing_strict(regs->u_regs[UREG_G1]);
6555
6556+#ifdef CONFIG_GRKERNSEC_SETXID
6557+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6558+ gr_delayed_cred_worker();
6559+#endif
6560+
6561 if (test_thread_flag(TIF_SYSCALL_TRACE))
6562 ret = tracehook_report_syscall_entry(regs);
6563
6564@@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
6565
6566 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
6567 {
6568+#ifdef CONFIG_GRKERNSEC_SETXID
6569+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6570+ gr_delayed_cred_worker();
6571+#endif
6572+
6573 audit_syscall_exit(regs);
6574
6575 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
6576diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
6577index 0c9b31b..7cb7aee 100644
6578--- a/arch/sparc/kernel/sys_sparc_32.c
6579+++ b/arch/sparc/kernel/sys_sparc_32.c
6580@@ -54,7 +54,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
6581 if (len > TASK_SIZE - PAGE_SIZE)
6582 return -ENOMEM;
6583 if (!addr)
6584- addr = TASK_UNMAPPED_BASE;
6585+ addr = current->mm->mmap_base;
6586
6587 if (flags & MAP_SHARED)
6588 addr = COLOUR_ALIGN(addr);
6589@@ -65,7 +65,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
6590 /* At this point: (!vmm || addr < vmm->vm_end). */
6591 if (TASK_SIZE - PAGE_SIZE - len < addr)
6592 return -ENOMEM;
6593- if (!vmm || addr + len <= vmm->vm_start)
6594+ if (check_heap_stack_gap(vmm, addr, len))
6595 return addr;
6596 addr = vmm->vm_end;
6597 if (flags & MAP_SHARED)
6598diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
6599index 878ef3d..8742f10 100644
6600--- a/arch/sparc/kernel/sys_sparc_64.c
6601+++ b/arch/sparc/kernel/sys_sparc_64.c
6602@@ -107,7 +107,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
6603 /* We do not accept a shared mapping if it would violate
6604 * cache aliasing constraints.
6605 */
6606- if ((flags & MAP_SHARED) &&
6607+ if ((filp || (flags & MAP_SHARED)) &&
6608 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
6609 return -EINVAL;
6610 return addr;
6611@@ -122,6 +122,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
6612 if (filp || (flags & MAP_SHARED))
6613 do_color_align = 1;
6614
6615+#ifdef CONFIG_PAX_RANDMMAP
6616+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
6617+#endif
6618+
6619 if (addr) {
6620 if (do_color_align)
6621 addr = COLOUR_ALIGN(addr, pgoff);
6622@@ -129,15 +133,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
6623 addr = PAGE_ALIGN(addr);
6624
6625 vma = find_vma(mm, addr);
6626- if (task_size - len >= addr &&
6627- (!vma || addr + len <= vma->vm_start))
6628+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
6629 return addr;
6630 }
6631
6632 if (len > mm->cached_hole_size) {
6633- start_addr = addr = mm->free_area_cache;
6634+ start_addr = addr = mm->free_area_cache;
6635 } else {
6636- start_addr = addr = TASK_UNMAPPED_BASE;
6637+ start_addr = addr = mm->mmap_base;
6638 mm->cached_hole_size = 0;
6639 }
6640
6641@@ -157,14 +160,14 @@ full_search:
6642 vma = find_vma(mm, VA_EXCLUDE_END);
6643 }
6644 if (unlikely(task_size < addr)) {
6645- if (start_addr != TASK_UNMAPPED_BASE) {
6646- start_addr = addr = TASK_UNMAPPED_BASE;
6647+ if (start_addr != mm->mmap_base) {
6648+ start_addr = addr = mm->mmap_base;
6649 mm->cached_hole_size = 0;
6650 goto full_search;
6651 }
6652 return -ENOMEM;
6653 }
6654- if (likely(!vma || addr + len <= vma->vm_start)) {
6655+ if (likely(check_heap_stack_gap(vma, addr, len))) {
6656 /*
6657 * Remember the place where we stopped the search:
6658 */
6659@@ -198,7 +201,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6660 /* We do not accept a shared mapping if it would violate
6661 * cache aliasing constraints.
6662 */
6663- if ((flags & MAP_SHARED) &&
6664+ if ((filp || (flags & MAP_SHARED)) &&
6665 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
6666 return -EINVAL;
6667 return addr;
6668@@ -219,8 +222,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6669 addr = PAGE_ALIGN(addr);
6670
6671 vma = find_vma(mm, addr);
6672- if (task_size - len >= addr &&
6673- (!vma || addr + len <= vma->vm_start))
6674+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
6675 return addr;
6676 }
6677
6678@@ -241,7 +243,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6679 /* make sure it can fit in the remaining address space */
6680 if (likely(addr > len)) {
6681 vma = find_vma(mm, addr-len);
6682- if (!vma || addr <= vma->vm_start) {
6683+ if (check_heap_stack_gap(vma, addr - len, len)) {
6684 /* remember the address as a hint for next time */
6685 return (mm->free_area_cache = addr-len);
6686 }
6687@@ -250,18 +252,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6688 if (unlikely(mm->mmap_base < len))
6689 goto bottomup;
6690
6691- addr = mm->mmap_base-len;
6692- if (do_color_align)
6693- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
6694+ addr = mm->mmap_base - len;
6695
6696 do {
6697+ if (do_color_align)
6698+ addr = COLOUR_ALIGN_DOWN(addr, pgoff);
6699 /*
6700 * Lookup failure means no vma is above this address,
6701 * else if new region fits below vma->vm_start,
6702 * return with success:
6703 */
6704 vma = find_vma(mm, addr);
6705- if (likely(!vma || addr+len <= vma->vm_start)) {
6706+ if (likely(check_heap_stack_gap(vma, addr, len))) {
6707 /* remember the address as a hint for next time */
6708 return (mm->free_area_cache = addr);
6709 }
6710@@ -271,10 +273,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6711 mm->cached_hole_size = vma->vm_start - addr;
6712
6713 /* try just below the current vma->vm_start */
6714- addr = vma->vm_start-len;
6715- if (do_color_align)
6716- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
6717- } while (likely(len < vma->vm_start));
6718+ addr = skip_heap_stack_gap(vma, len);
6719+ } while (!IS_ERR_VALUE(addr));
6720
6721 bottomup:
6722 /*
6723@@ -373,6 +373,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6724 gap == RLIM_INFINITY ||
6725 sysctl_legacy_va_layout) {
6726 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
6727+
6728+#ifdef CONFIG_PAX_RANDMMAP
6729+ if (mm->pax_flags & MF_PAX_RANDMMAP)
6730+ mm->mmap_base += mm->delta_mmap;
6731+#endif
6732+
6733 mm->get_unmapped_area = arch_get_unmapped_area;
6734 mm->unmap_area = arch_unmap_area;
6735 } else {
6736@@ -385,6 +391,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6737 gap = (task_size / 6 * 5);
6738
6739 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
6740+
6741+#ifdef CONFIG_PAX_RANDMMAP
6742+ if (mm->pax_flags & MF_PAX_RANDMMAP)
6743+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
6744+#endif
6745+
6746 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
6747 mm->unmap_area = arch_unmap_area_topdown;
6748 }
6749diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
6750index bf23477..b7425a6 100644
6751--- a/arch/sparc/kernel/syscalls.S
6752+++ b/arch/sparc/kernel/syscalls.S
6753@@ -62,7 +62,7 @@ sys32_rt_sigreturn:
6754 #endif
6755 .align 32
6756 1: ldx [%g6 + TI_FLAGS], %l5
6757- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6758+ andcc %l5, _TIF_WORK_SYSCALL, %g0
6759 be,pt %icc, rtrap
6760 nop
6761 call syscall_trace_leave
6762@@ -189,7 +189,7 @@ linux_sparc_syscall32:
6763
6764 srl %i5, 0, %o5 ! IEU1
6765 srl %i2, 0, %o2 ! IEU0 Group
6766- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6767+ andcc %l0, _TIF_WORK_SYSCALL, %g0
6768 bne,pn %icc, linux_syscall_trace32 ! CTI
6769 mov %i0, %l5 ! IEU1
6770 call %l7 ! CTI Group brk forced
6771@@ -212,7 +212,7 @@ linux_sparc_syscall:
6772
6773 mov %i3, %o3 ! IEU1
6774 mov %i4, %o4 ! IEU0 Group
6775- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6776+ andcc %l0, _TIF_WORK_SYSCALL, %g0
6777 bne,pn %icc, linux_syscall_trace ! CTI Group
6778 mov %i0, %l5 ! IEU0
6779 2: call %l7 ! CTI Group brk forced
6780@@ -228,7 +228,7 @@ ret_sys_call:
6781
6782 cmp %o0, -ERESTART_RESTARTBLOCK
6783 bgeu,pn %xcc, 1f
6784- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6785+ andcc %l0, _TIF_WORK_SYSCALL, %g0
6786 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
6787
6788 2:
6789diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
6790index a5785ea..405c5f7 100644
6791--- a/arch/sparc/kernel/traps_32.c
6792+++ b/arch/sparc/kernel/traps_32.c
6793@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
6794 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
6795 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
6796
6797+extern void gr_handle_kernel_exploit(void);
6798+
6799 void die_if_kernel(char *str, struct pt_regs *regs)
6800 {
6801 static int die_counter;
6802@@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6803 count++ < 30 &&
6804 (((unsigned long) rw) >= PAGE_OFFSET) &&
6805 !(((unsigned long) rw) & 0x7)) {
6806- printk("Caller[%08lx]: %pS\n", rw->ins[7],
6807+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
6808 (void *) rw->ins[7]);
6809 rw = (struct reg_window32 *)rw->ins[6];
6810 }
6811 }
6812 printk("Instruction DUMP:");
6813 instruction_dump ((unsigned long *) regs->pc);
6814- if(regs->psr & PSR_PS)
6815+ if(regs->psr & PSR_PS) {
6816+ gr_handle_kernel_exploit();
6817 do_exit(SIGKILL);
6818+ }
6819 do_exit(SIGSEGV);
6820 }
6821
6822diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
6823index b66a779..8e8d66c 100644
6824--- a/arch/sparc/kernel/traps_64.c
6825+++ b/arch/sparc/kernel/traps_64.c
6826@@ -76,7 +76,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
6827 i + 1,
6828 p->trapstack[i].tstate, p->trapstack[i].tpc,
6829 p->trapstack[i].tnpc, p->trapstack[i].tt);
6830- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
6831+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
6832 }
6833 }
6834
6835@@ -96,6 +96,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
6836
6837 lvl -= 0x100;
6838 if (regs->tstate & TSTATE_PRIV) {
6839+
6840+#ifdef CONFIG_PAX_REFCOUNT
6841+ if (lvl == 6)
6842+ pax_report_refcount_overflow(regs);
6843+#endif
6844+
6845 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
6846 die_if_kernel(buffer, regs);
6847 }
6848@@ -114,11 +120,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
6849 void bad_trap_tl1(struct pt_regs *regs, long lvl)
6850 {
6851 char buffer[32];
6852-
6853+
6854 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
6855 0, lvl, SIGTRAP) == NOTIFY_STOP)
6856 return;
6857
6858+#ifdef CONFIG_PAX_REFCOUNT
6859+ if (lvl == 6)
6860+ pax_report_refcount_overflow(regs);
6861+#endif
6862+
6863 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
6864
6865 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
6866@@ -1142,7 +1153,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
6867 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
6868 printk("%s" "ERROR(%d): ",
6869 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
6870- printk("TPC<%pS>\n", (void *) regs->tpc);
6871+ printk("TPC<%pA>\n", (void *) regs->tpc);
6872 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
6873 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
6874 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
6875@@ -1749,7 +1760,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6876 smp_processor_id(),
6877 (type & 0x1) ? 'I' : 'D',
6878 regs->tpc);
6879- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
6880+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
6881 panic("Irrecoverable Cheetah+ parity error.");
6882 }
6883
6884@@ -1757,7 +1768,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6885 smp_processor_id(),
6886 (type & 0x1) ? 'I' : 'D',
6887 regs->tpc);
6888- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
6889+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
6890 }
6891
6892 struct sun4v_error_entry {
6893@@ -2104,9 +2115,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
6894
6895 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
6896 regs->tpc, tl);
6897- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
6898+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
6899 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6900- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
6901+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
6902 (void *) regs->u_regs[UREG_I7]);
6903 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
6904 "pte[%lx] error[%lx]\n",
6905@@ -2128,9 +2139,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
6906
6907 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
6908 regs->tpc, tl);
6909- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
6910+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
6911 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6912- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
6913+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
6914 (void *) regs->u_regs[UREG_I7]);
6915 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
6916 "pte[%lx] error[%lx]\n",
6917@@ -2336,13 +2347,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
6918 fp = (unsigned long)sf->fp + STACK_BIAS;
6919 }
6920
6921- printk(" [%016lx] %pS\n", pc, (void *) pc);
6922+ printk(" [%016lx] %pA\n", pc, (void *) pc);
6923 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
6924 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
6925 int index = tsk->curr_ret_stack;
6926 if (tsk->ret_stack && index >= graph) {
6927 pc = tsk->ret_stack[index - graph].ret;
6928- printk(" [%016lx] %pS\n", pc, (void *) pc);
6929+ printk(" [%016lx] %pA\n", pc, (void *) pc);
6930 graph++;
6931 }
6932 }
6933@@ -2367,6 +2378,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
6934 return (struct reg_window *) (fp + STACK_BIAS);
6935 }
6936
6937+extern void gr_handle_kernel_exploit(void);
6938+
6939 void die_if_kernel(char *str, struct pt_regs *regs)
6940 {
6941 static int die_counter;
6942@@ -2395,7 +2408,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6943 while (rw &&
6944 count++ < 30 &&
6945 kstack_valid(tp, (unsigned long) rw)) {
6946- printk("Caller[%016lx]: %pS\n", rw->ins[7],
6947+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
6948 (void *) rw->ins[7]);
6949
6950 rw = kernel_stack_up(rw);
6951@@ -2408,8 +2421,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6952 }
6953 user_instruction_dump ((unsigned int __user *) regs->tpc);
6954 }
6955- if (regs->tstate & TSTATE_PRIV)
6956+ if (regs->tstate & TSTATE_PRIV) {
6957+ gr_handle_kernel_exploit();
6958 do_exit(SIGKILL);
6959+ }
6960 do_exit(SIGSEGV);
6961 }
6962 EXPORT_SYMBOL(die_if_kernel);
6963diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
6964index 8201c25e..072a2a7 100644
6965--- a/arch/sparc/kernel/unaligned_64.c
6966+++ b/arch/sparc/kernel/unaligned_64.c
6967@@ -286,7 +286,7 @@ static void log_unaligned(struct pt_regs *regs)
6968 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
6969
6970 if (__ratelimit(&ratelimit)) {
6971- printk("Kernel unaligned access at TPC[%lx] %pS\n",
6972+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
6973 regs->tpc, (void *) regs->tpc);
6974 }
6975 }
6976diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
6977index 8410065f2..4fd4ca22 100644
6978--- a/arch/sparc/lib/Makefile
6979+++ b/arch/sparc/lib/Makefile
6980@@ -2,7 +2,7 @@
6981 #
6982
6983 asflags-y := -ansi -DST_DIV0=0x02
6984-ccflags-y := -Werror
6985+#ccflags-y := -Werror
6986
6987 lib-$(CONFIG_SPARC32) += ashrdi3.o
6988 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
6989diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
6990index 85c233d..68500e0 100644
6991--- a/arch/sparc/lib/atomic_64.S
6992+++ b/arch/sparc/lib/atomic_64.S
6993@@ -17,7 +17,12 @@
6994 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
6995 BACKOFF_SETUP(%o2)
6996 1: lduw [%o1], %g1
6997- add %g1, %o0, %g7
6998+ addcc %g1, %o0, %g7
6999+
7000+#ifdef CONFIG_PAX_REFCOUNT
7001+ tvs %icc, 6
7002+#endif
7003+
7004 cas [%o1], %g1, %g7
7005 cmp %g1, %g7
7006 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
7007@@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
7008 2: BACKOFF_SPIN(%o2, %o3, 1b)
7009 ENDPROC(atomic_add)
7010
7011+ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
7012+ BACKOFF_SETUP(%o2)
7013+1: lduw [%o1], %g1
7014+ add %g1, %o0, %g7
7015+ cas [%o1], %g1, %g7
7016+ cmp %g1, %g7
7017+ bne,pn %icc, 2f
7018+ nop
7019+ retl
7020+ nop
7021+2: BACKOFF_SPIN(%o2, %o3, 1b)
7022+ENDPROC(atomic_add_unchecked)
7023+
7024 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
7025 BACKOFF_SETUP(%o2)
7026 1: lduw [%o1], %g1
7027- sub %g1, %o0, %g7
7028+ subcc %g1, %o0, %g7
7029+
7030+#ifdef CONFIG_PAX_REFCOUNT
7031+ tvs %icc, 6
7032+#endif
7033+
7034 cas [%o1], %g1, %g7
7035 cmp %g1, %g7
7036 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
7037@@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
7038 2: BACKOFF_SPIN(%o2, %o3, 1b)
7039 ENDPROC(atomic_sub)
7040
7041+ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
7042+ BACKOFF_SETUP(%o2)
7043+1: lduw [%o1], %g1
7044+ sub %g1, %o0, %g7
7045+ cas [%o1], %g1, %g7
7046+ cmp %g1, %g7
7047+ bne,pn %icc, 2f
7048+ nop
7049+ retl
7050+ nop
7051+2: BACKOFF_SPIN(%o2, %o3, 1b)
7052+ENDPROC(atomic_sub_unchecked)
7053+
7054 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
7055 BACKOFF_SETUP(%o2)
7056 1: lduw [%o1], %g1
7057- add %g1, %o0, %g7
7058+ addcc %g1, %o0, %g7
7059+
7060+#ifdef CONFIG_PAX_REFCOUNT
7061+ tvs %icc, 6
7062+#endif
7063+
7064 cas [%o1], %g1, %g7
7065 cmp %g1, %g7
7066 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
7067@@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
7068 2: BACKOFF_SPIN(%o2, %o3, 1b)
7069 ENDPROC(atomic_add_ret)
7070
7071+ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
7072+ BACKOFF_SETUP(%o2)
7073+1: lduw [%o1], %g1
7074+ addcc %g1, %o0, %g7
7075+ cas [%o1], %g1, %g7
7076+ cmp %g1, %g7
7077+ bne,pn %icc, 2f
7078+ add %g7, %o0, %g7
7079+ sra %g7, 0, %o0
7080+ retl
7081+ nop
7082+2: BACKOFF_SPIN(%o2, %o3, 1b)
7083+ENDPROC(atomic_add_ret_unchecked)
7084+
7085 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
7086 BACKOFF_SETUP(%o2)
7087 1: lduw [%o1], %g1
7088- sub %g1, %o0, %g7
7089+ subcc %g1, %o0, %g7
7090+
7091+#ifdef CONFIG_PAX_REFCOUNT
7092+ tvs %icc, 6
7093+#endif
7094+
7095 cas [%o1], %g1, %g7
7096 cmp %g1, %g7
7097 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
7098@@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
7099 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
7100 BACKOFF_SETUP(%o2)
7101 1: ldx [%o1], %g1
7102- add %g1, %o0, %g7
7103+ addcc %g1, %o0, %g7
7104+
7105+#ifdef CONFIG_PAX_REFCOUNT
7106+ tvs %xcc, 6
7107+#endif
7108+
7109 casx [%o1], %g1, %g7
7110 cmp %g1, %g7
7111 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
7112@@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
7113 2: BACKOFF_SPIN(%o2, %o3, 1b)
7114 ENDPROC(atomic64_add)
7115
7116+ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
7117+ BACKOFF_SETUP(%o2)
7118+1: ldx [%o1], %g1
7119+ addcc %g1, %o0, %g7
7120+ casx [%o1], %g1, %g7
7121+ cmp %g1, %g7
7122+ bne,pn %xcc, 2f
7123+ nop
7124+ retl
7125+ nop
7126+2: BACKOFF_SPIN(%o2, %o3, 1b)
7127+ENDPROC(atomic64_add_unchecked)
7128+
7129 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
7130 BACKOFF_SETUP(%o2)
7131 1: ldx [%o1], %g1
7132- sub %g1, %o0, %g7
7133+ subcc %g1, %o0, %g7
7134+
7135+#ifdef CONFIG_PAX_REFCOUNT
7136+ tvs %xcc, 6
7137+#endif
7138+
7139 casx [%o1], %g1, %g7
7140 cmp %g1, %g7
7141 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
7142@@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
7143 2: BACKOFF_SPIN(%o2, %o3, 1b)
7144 ENDPROC(atomic64_sub)
7145
7146+ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
7147+ BACKOFF_SETUP(%o2)
7148+1: ldx [%o1], %g1
7149+ subcc %g1, %o0, %g7
7150+ casx [%o1], %g1, %g7
7151+ cmp %g1, %g7
7152+ bne,pn %xcc, 2f
7153+ nop
7154+ retl
7155+ nop
7156+2: BACKOFF_SPIN(%o2, %o3, 1b)
7157+ENDPROC(atomic64_sub_unchecked)
7158+
7159 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
7160 BACKOFF_SETUP(%o2)
7161 1: ldx [%o1], %g1
7162- add %g1, %o0, %g7
7163+ addcc %g1, %o0, %g7
7164+
7165+#ifdef CONFIG_PAX_REFCOUNT
7166+ tvs %xcc, 6
7167+#endif
7168+
7169 casx [%o1], %g1, %g7
7170 cmp %g1, %g7
7171 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
7172@@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
7173 2: BACKOFF_SPIN(%o2, %o3, 1b)
7174 ENDPROC(atomic64_add_ret)
7175
7176+ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
7177+ BACKOFF_SETUP(%o2)
7178+1: ldx [%o1], %g1
7179+ addcc %g1, %o0, %g7
7180+ casx [%o1], %g1, %g7
7181+ cmp %g1, %g7
7182+ bne,pn %xcc, 2f
7183+ add %g7, %o0, %g7
7184+ mov %g7, %o0
7185+ retl
7186+ nop
7187+2: BACKOFF_SPIN(%o2, %o3, 1b)
7188+ENDPROC(atomic64_add_ret_unchecked)
7189+
7190 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
7191 BACKOFF_SETUP(%o2)
7192 1: ldx [%o1], %g1
7193- sub %g1, %o0, %g7
7194+ subcc %g1, %o0, %g7
7195+
7196+#ifdef CONFIG_PAX_REFCOUNT
7197+ tvs %xcc, 6
7198+#endif
7199+
7200 casx [%o1], %g1, %g7
7201 cmp %g1, %g7
7202 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
7203diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
7204index 0c4e35e..745d3e4 100644
7205--- a/arch/sparc/lib/ksyms.c
7206+++ b/arch/sparc/lib/ksyms.c
7207@@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
7208
7209 /* Atomic counter implementation. */
7210 EXPORT_SYMBOL(atomic_add);
7211+EXPORT_SYMBOL(atomic_add_unchecked);
7212 EXPORT_SYMBOL(atomic_add_ret);
7213+EXPORT_SYMBOL(atomic_add_ret_unchecked);
7214 EXPORT_SYMBOL(atomic_sub);
7215+EXPORT_SYMBOL(atomic_sub_unchecked);
7216 EXPORT_SYMBOL(atomic_sub_ret);
7217 EXPORT_SYMBOL(atomic64_add);
7218+EXPORT_SYMBOL(atomic64_add_unchecked);
7219 EXPORT_SYMBOL(atomic64_add_ret);
7220+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
7221 EXPORT_SYMBOL(atomic64_sub);
7222+EXPORT_SYMBOL(atomic64_sub_unchecked);
7223 EXPORT_SYMBOL(atomic64_sub_ret);
7224 EXPORT_SYMBOL(atomic64_dec_if_positive);
7225
7226diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
7227index 30c3ecc..736f015 100644
7228--- a/arch/sparc/mm/Makefile
7229+++ b/arch/sparc/mm/Makefile
7230@@ -2,7 +2,7 @@
7231 #
7232
7233 asflags-y := -ansi
7234-ccflags-y := -Werror
7235+#ccflags-y := -Werror
7236
7237 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
7238 obj-y += fault_$(BITS).o
7239diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
7240index e98bfda..ea8d221 100644
7241--- a/arch/sparc/mm/fault_32.c
7242+++ b/arch/sparc/mm/fault_32.c
7243@@ -21,6 +21,9 @@
7244 #include <linux/perf_event.h>
7245 #include <linux/interrupt.h>
7246 #include <linux/kdebug.h>
7247+#include <linux/slab.h>
7248+#include <linux/pagemap.h>
7249+#include <linux/compiler.h>
7250
7251 #include <asm/page.h>
7252 #include <asm/pgtable.h>
7253@@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
7254 return safe_compute_effective_address(regs, insn);
7255 }
7256
7257+#ifdef CONFIG_PAX_PAGEEXEC
7258+#ifdef CONFIG_PAX_DLRESOLVE
7259+static void pax_emuplt_close(struct vm_area_struct *vma)
7260+{
7261+ vma->vm_mm->call_dl_resolve = 0UL;
7262+}
7263+
7264+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
7265+{
7266+ unsigned int *kaddr;
7267+
7268+ vmf->page = alloc_page(GFP_HIGHUSER);
7269+ if (!vmf->page)
7270+ return VM_FAULT_OOM;
7271+
7272+ kaddr = kmap(vmf->page);
7273+ memset(kaddr, 0, PAGE_SIZE);
7274+ kaddr[0] = 0x9DE3BFA8U; /* save */
7275+ flush_dcache_page(vmf->page);
7276+ kunmap(vmf->page);
7277+ return VM_FAULT_MAJOR;
7278+}
7279+
7280+static const struct vm_operations_struct pax_vm_ops = {
7281+ .close = pax_emuplt_close,
7282+ .fault = pax_emuplt_fault
7283+};
7284+
7285+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
7286+{
7287+ int ret;
7288+
7289+ INIT_LIST_HEAD(&vma->anon_vma_chain);
7290+ vma->vm_mm = current->mm;
7291+ vma->vm_start = addr;
7292+ vma->vm_end = addr + PAGE_SIZE;
7293+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
7294+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
7295+ vma->vm_ops = &pax_vm_ops;
7296+
7297+ ret = insert_vm_struct(current->mm, vma);
7298+ if (ret)
7299+ return ret;
7300+
7301+ ++current->mm->total_vm;
7302+ return 0;
7303+}
7304+#endif
7305+
7306+/*
7307+ * PaX: decide what to do with offenders (regs->pc = fault address)
7308+ *
7309+ * returns 1 when task should be killed
7310+ * 2 when patched PLT trampoline was detected
7311+ * 3 when unpatched PLT trampoline was detected
7312+ */
7313+static int pax_handle_fetch_fault(struct pt_regs *regs)
7314+{
7315+
7316+#ifdef CONFIG_PAX_EMUPLT
7317+ int err;
7318+
7319+ do { /* PaX: patched PLT emulation #1 */
7320+ unsigned int sethi1, sethi2, jmpl;
7321+
7322+ err = get_user(sethi1, (unsigned int *)regs->pc);
7323+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
7324+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
7325+
7326+ if (err)
7327+ break;
7328+
7329+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
7330+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
7331+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
7332+ {
7333+ unsigned int addr;
7334+
7335+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
7336+ addr = regs->u_regs[UREG_G1];
7337+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
7338+ regs->pc = addr;
7339+ regs->npc = addr+4;
7340+ return 2;
7341+ }
7342+ } while (0);
7343+
7344+ do { /* PaX: patched PLT emulation #2 */
7345+ unsigned int ba;
7346+
7347+ err = get_user(ba, (unsigned int *)regs->pc);
7348+
7349+ if (err)
7350+ break;
7351+
7352+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
7353+ unsigned int addr;
7354+
7355+ if ((ba & 0xFFC00000U) == 0x30800000U)
7356+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
7357+ else
7358+ addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
7359+ regs->pc = addr;
7360+ regs->npc = addr+4;
7361+ return 2;
7362+ }
7363+ } while (0);
7364+
7365+ do { /* PaX: patched PLT emulation #3 */
7366+ unsigned int sethi, bajmpl, nop;
7367+
7368+ err = get_user(sethi, (unsigned int *)regs->pc);
7369+ err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
7370+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
7371+
7372+ if (err)
7373+ break;
7374+
7375+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7376+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
7377+ nop == 0x01000000U)
7378+ {
7379+ unsigned int addr;
7380+
7381+ addr = (sethi & 0x003FFFFFU) << 10;
7382+ regs->u_regs[UREG_G1] = addr;
7383+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
7384+ addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
7385+ else
7386+ addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
7387+ regs->pc = addr;
7388+ regs->npc = addr+4;
7389+ return 2;
7390+ }
7391+ } while (0);
7392+
7393+ do { /* PaX: unpatched PLT emulation step 1 */
7394+ unsigned int sethi, ba, nop;
7395+
7396+ err = get_user(sethi, (unsigned int *)regs->pc);
7397+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
7398+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
7399+
7400+ if (err)
7401+ break;
7402+
7403+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7404+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
7405+ nop == 0x01000000U)
7406+ {
7407+ unsigned int addr, save, call;
7408+
7409+ if ((ba & 0xFFC00000U) == 0x30800000U)
7410+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
7411+ else
7412+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
7413+
7414+ err = get_user(save, (unsigned int *)addr);
7415+ err |= get_user(call, (unsigned int *)(addr+4));
7416+ err |= get_user(nop, (unsigned int *)(addr+8));
7417+ if (err)
7418+ break;
7419+
7420+#ifdef CONFIG_PAX_DLRESOLVE
7421+ if (save == 0x9DE3BFA8U &&
7422+ (call & 0xC0000000U) == 0x40000000U &&
7423+ nop == 0x01000000U)
7424+ {
7425+ struct vm_area_struct *vma;
7426+ unsigned long call_dl_resolve;
7427+
7428+ down_read(&current->mm->mmap_sem);
7429+ call_dl_resolve = current->mm->call_dl_resolve;
7430+ up_read(&current->mm->mmap_sem);
7431+ if (likely(call_dl_resolve))
7432+ goto emulate;
7433+
7434+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
7435+
7436+ down_write(&current->mm->mmap_sem);
7437+ if (current->mm->call_dl_resolve) {
7438+ call_dl_resolve = current->mm->call_dl_resolve;
7439+ up_write(&current->mm->mmap_sem);
7440+ if (vma)
7441+ kmem_cache_free(vm_area_cachep, vma);
7442+ goto emulate;
7443+ }
7444+
7445+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
7446+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
7447+ up_write(&current->mm->mmap_sem);
7448+ if (vma)
7449+ kmem_cache_free(vm_area_cachep, vma);
7450+ return 1;
7451+ }
7452+
7453+ if (pax_insert_vma(vma, call_dl_resolve)) {
7454+ up_write(&current->mm->mmap_sem);
7455+ kmem_cache_free(vm_area_cachep, vma);
7456+ return 1;
7457+ }
7458+
7459+ current->mm->call_dl_resolve = call_dl_resolve;
7460+ up_write(&current->mm->mmap_sem);
7461+
7462+emulate:
7463+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7464+ regs->pc = call_dl_resolve;
7465+ regs->npc = addr+4;
7466+ return 3;
7467+ }
7468+#endif
7469+
7470+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
7471+ if ((save & 0xFFC00000U) == 0x05000000U &&
7472+ (call & 0xFFFFE000U) == 0x85C0A000U &&
7473+ nop == 0x01000000U)
7474+ {
7475+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7476+ regs->u_regs[UREG_G2] = addr + 4;
7477+ addr = (save & 0x003FFFFFU) << 10;
7478+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
7479+ regs->pc = addr;
7480+ regs->npc = addr+4;
7481+ return 3;
7482+ }
7483+ }
7484+ } while (0);
7485+
7486+ do { /* PaX: unpatched PLT emulation step 2 */
7487+ unsigned int save, call, nop;
7488+
7489+ err = get_user(save, (unsigned int *)(regs->pc-4));
7490+ err |= get_user(call, (unsigned int *)regs->pc);
7491+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
7492+ if (err)
7493+ break;
7494+
7495+ if (save == 0x9DE3BFA8U &&
7496+ (call & 0xC0000000U) == 0x40000000U &&
7497+ nop == 0x01000000U)
7498+ {
7499+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
7500+
7501+ regs->u_regs[UREG_RETPC] = regs->pc;
7502+ regs->pc = dl_resolve;
7503+ regs->npc = dl_resolve+4;
7504+ return 3;
7505+ }
7506+ } while (0);
7507+#endif
7508+
7509+ return 1;
7510+}
7511+
7512+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7513+{
7514+ unsigned long i;
7515+
7516+ printk(KERN_ERR "PAX: bytes at PC: ");
7517+ for (i = 0; i < 8; i++) {
7518+ unsigned int c;
7519+ if (get_user(c, (unsigned int *)pc+i))
7520+ printk(KERN_CONT "???????? ");
7521+ else
7522+ printk(KERN_CONT "%08x ", c);
7523+ }
7524+ printk("\n");
7525+}
7526+#endif
7527+
7528 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
7529 int text_fault)
7530 {
7531@@ -230,6 +504,24 @@ good_area:
7532 if (!(vma->vm_flags & VM_WRITE))
7533 goto bad_area;
7534 } else {
7535+
7536+#ifdef CONFIG_PAX_PAGEEXEC
7537+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
7538+ up_read(&mm->mmap_sem);
7539+ switch (pax_handle_fetch_fault(regs)) {
7540+
7541+#ifdef CONFIG_PAX_EMUPLT
7542+ case 2:
7543+ case 3:
7544+ return;
7545+#endif
7546+
7547+ }
7548+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
7549+ do_group_exit(SIGKILL);
7550+ }
7551+#endif
7552+
7553 /* Allow reads even for write-only mappings */
7554 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
7555 goto bad_area;
7556diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
7557index 097aee7..5ca6697 100644
7558--- a/arch/sparc/mm/fault_64.c
7559+++ b/arch/sparc/mm/fault_64.c
7560@@ -21,6 +21,9 @@
7561 #include <linux/kprobes.h>
7562 #include <linux/kdebug.h>
7563 #include <linux/percpu.h>
7564+#include <linux/slab.h>
7565+#include <linux/pagemap.h>
7566+#include <linux/compiler.h>
7567
7568 #include <asm/page.h>
7569 #include <asm/pgtable.h>
7570@@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
7571 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
7572 regs->tpc);
7573 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
7574- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
7575+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
7576 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
7577 dump_stack();
7578 unhandled_fault(regs->tpc, current, regs);
7579@@ -270,6 +273,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
7580 show_regs(regs);
7581 }
7582
7583+#ifdef CONFIG_PAX_PAGEEXEC
7584+#ifdef CONFIG_PAX_DLRESOLVE
7585+static void pax_emuplt_close(struct vm_area_struct *vma)
7586+{
7587+ vma->vm_mm->call_dl_resolve = 0UL;
7588+}
7589+
7590+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
7591+{
7592+ unsigned int *kaddr;
7593+
7594+ vmf->page = alloc_page(GFP_HIGHUSER);
7595+ if (!vmf->page)
7596+ return VM_FAULT_OOM;
7597+
7598+ kaddr = kmap(vmf->page);
7599+ memset(kaddr, 0, PAGE_SIZE);
7600+ kaddr[0] = 0x9DE3BFA8U; /* save */
7601+ flush_dcache_page(vmf->page);
7602+ kunmap(vmf->page);
7603+ return VM_FAULT_MAJOR;
7604+}
7605+
7606+static const struct vm_operations_struct pax_vm_ops = {
7607+ .close = pax_emuplt_close,
7608+ .fault = pax_emuplt_fault
7609+};
7610+
7611+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
7612+{
7613+ int ret;
7614+
7615+ INIT_LIST_HEAD(&vma->anon_vma_chain);
7616+ vma->vm_mm = current->mm;
7617+ vma->vm_start = addr;
7618+ vma->vm_end = addr + PAGE_SIZE;
7619+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
7620+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
7621+ vma->vm_ops = &pax_vm_ops;
7622+
7623+ ret = insert_vm_struct(current->mm, vma);
7624+ if (ret)
7625+ return ret;
7626+
7627+ ++current->mm->total_vm;
7628+ return 0;
7629+}
7630+#endif
7631+
7632+/*
7633+ * PaX: decide what to do with offenders (regs->tpc = fault address)
7634+ *
7635+ * returns 1 when task should be killed
7636+ * 2 when patched PLT trampoline was detected
7637+ * 3 when unpatched PLT trampoline was detected
7638+ */
7639+static int pax_handle_fetch_fault(struct pt_regs *regs)
7640+{
7641+
7642+#ifdef CONFIG_PAX_EMUPLT
7643+ int err;
7644+
7645+ do { /* PaX: patched PLT emulation #1 */
7646+ unsigned int sethi1, sethi2, jmpl;
7647+
7648+ err = get_user(sethi1, (unsigned int *)regs->tpc);
7649+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
7650+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
7651+
7652+ if (err)
7653+ break;
7654+
7655+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
7656+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
7657+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
7658+ {
7659+ unsigned long addr;
7660+
7661+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
7662+ addr = regs->u_regs[UREG_G1];
7663+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
7664+
7665+ if (test_thread_flag(TIF_32BIT))
7666+ addr &= 0xFFFFFFFFUL;
7667+
7668+ regs->tpc = addr;
7669+ regs->tnpc = addr+4;
7670+ return 2;
7671+ }
7672+ } while (0);
7673+
7674+ do { /* PaX: patched PLT emulation #2 */
7675+ unsigned int ba;
7676+
7677+ err = get_user(ba, (unsigned int *)regs->tpc);
7678+
7679+ if (err)
7680+ break;
7681+
7682+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
7683+ unsigned long addr;
7684+
7685+ if ((ba & 0xFFC00000U) == 0x30800000U)
7686+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
7687+ else
7688+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7689+
7690+ if (test_thread_flag(TIF_32BIT))
7691+ addr &= 0xFFFFFFFFUL;
7692+
7693+ regs->tpc = addr;
7694+ regs->tnpc = addr+4;
7695+ return 2;
7696+ }
7697+ } while (0);
7698+
7699+ do { /* PaX: patched PLT emulation #3 */
7700+ unsigned int sethi, bajmpl, nop;
7701+
7702+ err = get_user(sethi, (unsigned int *)regs->tpc);
7703+ err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
7704+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7705+
7706+ if (err)
7707+ break;
7708+
7709+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7710+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
7711+ nop == 0x01000000U)
7712+ {
7713+ unsigned long addr;
7714+
7715+ addr = (sethi & 0x003FFFFFU) << 10;
7716+ regs->u_regs[UREG_G1] = addr;
7717+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
7718+ addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
7719+ else
7720+ addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7721+
7722+ if (test_thread_flag(TIF_32BIT))
7723+ addr &= 0xFFFFFFFFUL;
7724+
7725+ regs->tpc = addr;
7726+ regs->tnpc = addr+4;
7727+ return 2;
7728+ }
7729+ } while (0);
7730+
7731+ do { /* PaX: patched PLT emulation #4 */
7732+ unsigned int sethi, mov1, call, mov2;
7733+
7734+ err = get_user(sethi, (unsigned int *)regs->tpc);
7735+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
7736+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
7737+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
7738+
7739+ if (err)
7740+ break;
7741+
7742+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7743+ mov1 == 0x8210000FU &&
7744+ (call & 0xC0000000U) == 0x40000000U &&
7745+ mov2 == 0x9E100001U)
7746+ {
7747+ unsigned long addr;
7748+
7749+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
7750+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
7751+
7752+ if (test_thread_flag(TIF_32BIT))
7753+ addr &= 0xFFFFFFFFUL;
7754+
7755+ regs->tpc = addr;
7756+ regs->tnpc = addr+4;
7757+ return 2;
7758+ }
7759+ } while (0);
7760+
7761+ do { /* PaX: patched PLT emulation #5 */
7762+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
7763+
7764+ err = get_user(sethi, (unsigned int *)regs->tpc);
7765+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
7766+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
7767+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
7768+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
7769+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
7770+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
7771+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
7772+
7773+ if (err)
7774+ break;
7775+
7776+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7777+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
7778+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7779+ (or1 & 0xFFFFE000U) == 0x82106000U &&
7780+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
7781+ sllx == 0x83287020U &&
7782+ jmpl == 0x81C04005U &&
7783+ nop == 0x01000000U)
7784+ {
7785+ unsigned long addr;
7786+
7787+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7788+ regs->u_regs[UREG_G1] <<= 32;
7789+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7790+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7791+ regs->tpc = addr;
7792+ regs->tnpc = addr+4;
7793+ return 2;
7794+ }
7795+ } while (0);
7796+
7797+ do { /* PaX: patched PLT emulation #6 */
7798+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
7799+
7800+ err = get_user(sethi, (unsigned int *)regs->tpc);
7801+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
7802+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
7803+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
7804+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
7805+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
7806+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
7807+
7808+ if (err)
7809+ break;
7810+
7811+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7812+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
7813+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7814+ sllx == 0x83287020U &&
7815+ (or & 0xFFFFE000U) == 0x8A116000U &&
7816+ jmpl == 0x81C04005U &&
7817+ nop == 0x01000000U)
7818+ {
7819+ unsigned long addr;
7820+
7821+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
7822+ regs->u_regs[UREG_G1] <<= 32;
7823+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
7824+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7825+ regs->tpc = addr;
7826+ regs->tnpc = addr+4;
7827+ return 2;
7828+ }
7829+ } while (0);
7830+
7831+ do { /* PaX: unpatched PLT emulation step 1 */
7832+ unsigned int sethi, ba, nop;
7833+
7834+ err = get_user(sethi, (unsigned int *)regs->tpc);
7835+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7836+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7837+
7838+ if (err)
7839+ break;
7840+
7841+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7842+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
7843+ nop == 0x01000000U)
7844+ {
7845+ unsigned long addr;
7846+ unsigned int save, call;
7847+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
7848+
7849+ if ((ba & 0xFFC00000U) == 0x30800000U)
7850+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
7851+ else
7852+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7853+
7854+ if (test_thread_flag(TIF_32BIT))
7855+ addr &= 0xFFFFFFFFUL;
7856+
7857+ err = get_user(save, (unsigned int *)addr);
7858+ err |= get_user(call, (unsigned int *)(addr+4));
7859+ err |= get_user(nop, (unsigned int *)(addr+8));
7860+ if (err)
7861+ break;
7862+
7863+#ifdef CONFIG_PAX_DLRESOLVE
7864+ if (save == 0x9DE3BFA8U &&
7865+ (call & 0xC0000000U) == 0x40000000U &&
7866+ nop == 0x01000000U)
7867+ {
7868+ struct vm_area_struct *vma;
7869+ unsigned long call_dl_resolve;
7870+
7871+ down_read(&current->mm->mmap_sem);
7872+ call_dl_resolve = current->mm->call_dl_resolve;
7873+ up_read(&current->mm->mmap_sem);
7874+ if (likely(call_dl_resolve))
7875+ goto emulate;
7876+
7877+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
7878+
7879+ down_write(&current->mm->mmap_sem);
7880+ if (current->mm->call_dl_resolve) {
7881+ call_dl_resolve = current->mm->call_dl_resolve;
7882+ up_write(&current->mm->mmap_sem);
7883+ if (vma)
7884+ kmem_cache_free(vm_area_cachep, vma);
7885+ goto emulate;
7886+ }
7887+
7888+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
7889+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
7890+ up_write(&current->mm->mmap_sem);
7891+ if (vma)
7892+ kmem_cache_free(vm_area_cachep, vma);
7893+ return 1;
7894+ }
7895+
7896+ if (pax_insert_vma(vma, call_dl_resolve)) {
7897+ up_write(&current->mm->mmap_sem);
7898+ kmem_cache_free(vm_area_cachep, vma);
7899+ return 1;
7900+ }
7901+
7902+ current->mm->call_dl_resolve = call_dl_resolve;
7903+ up_write(&current->mm->mmap_sem);
7904+
7905+emulate:
7906+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7907+ regs->tpc = call_dl_resolve;
7908+ regs->tnpc = addr+4;
7909+ return 3;
7910+ }
7911+#endif
7912+
7913+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
7914+ if ((save & 0xFFC00000U) == 0x05000000U &&
7915+ (call & 0xFFFFE000U) == 0x85C0A000U &&
7916+ nop == 0x01000000U)
7917+ {
7918+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7919+ regs->u_regs[UREG_G2] = addr + 4;
7920+ addr = (save & 0x003FFFFFU) << 10;
7921+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
7922+
7923+ if (test_thread_flag(TIF_32BIT))
7924+ addr &= 0xFFFFFFFFUL;
7925+
7926+ regs->tpc = addr;
7927+ regs->tnpc = addr+4;
7928+ return 3;
7929+ }
7930+
7931+ /* PaX: 64-bit PLT stub */
7932+ err = get_user(sethi1, (unsigned int *)addr);
7933+ err |= get_user(sethi2, (unsigned int *)(addr+4));
7934+ err |= get_user(or1, (unsigned int *)(addr+8));
7935+ err |= get_user(or2, (unsigned int *)(addr+12));
7936+ err |= get_user(sllx, (unsigned int *)(addr+16));
7937+ err |= get_user(add, (unsigned int *)(addr+20));
7938+ err |= get_user(jmpl, (unsigned int *)(addr+24));
7939+ err |= get_user(nop, (unsigned int *)(addr+28));
7940+ if (err)
7941+ break;
7942+
7943+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
7944+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7945+ (or1 & 0xFFFFE000U) == 0x88112000U &&
7946+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
7947+ sllx == 0x89293020U &&
7948+ add == 0x8A010005U &&
7949+ jmpl == 0x89C14000U &&
7950+ nop == 0x01000000U)
7951+ {
7952+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7953+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7954+ regs->u_regs[UREG_G4] <<= 32;
7955+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7956+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
7957+ regs->u_regs[UREG_G4] = addr + 24;
7958+ addr = regs->u_regs[UREG_G5];
7959+ regs->tpc = addr;
7960+ regs->tnpc = addr+4;
7961+ return 3;
7962+ }
7963+ }
7964+ } while (0);
7965+
7966+#ifdef CONFIG_PAX_DLRESOLVE
7967+ do { /* PaX: unpatched PLT emulation step 2 */
7968+ unsigned int save, call, nop;
7969+
7970+ err = get_user(save, (unsigned int *)(regs->tpc-4));
7971+ err |= get_user(call, (unsigned int *)regs->tpc);
7972+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
7973+ if (err)
7974+ break;
7975+
7976+ if (save == 0x9DE3BFA8U &&
7977+ (call & 0xC0000000U) == 0x40000000U &&
7978+ nop == 0x01000000U)
7979+ {
7980+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
7981+
7982+ if (test_thread_flag(TIF_32BIT))
7983+ dl_resolve &= 0xFFFFFFFFUL;
7984+
7985+ regs->u_regs[UREG_RETPC] = regs->tpc;
7986+ regs->tpc = dl_resolve;
7987+ regs->tnpc = dl_resolve+4;
7988+ return 3;
7989+ }
7990+ } while (0);
7991+#endif
7992+
7993+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
7994+ unsigned int sethi, ba, nop;
7995+
7996+ err = get_user(sethi, (unsigned int *)regs->tpc);
7997+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7998+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7999+
8000+ if (err)
8001+ break;
8002+
8003+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
8004+ (ba & 0xFFF00000U) == 0x30600000U &&
8005+ nop == 0x01000000U)
8006+ {
8007+ unsigned long addr;
8008+
8009+ addr = (sethi & 0x003FFFFFU) << 10;
8010+ regs->u_regs[UREG_G1] = addr;
8011+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
8012+
8013+ if (test_thread_flag(TIF_32BIT))
8014+ addr &= 0xFFFFFFFFUL;
8015+
8016+ regs->tpc = addr;
8017+ regs->tnpc = addr+4;
8018+ return 2;
8019+ }
8020+ } while (0);
8021+
8022+#endif
8023+
8024+ return 1;
8025+}
8026+
8027+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
8028+{
8029+ unsigned long i;
8030+
8031+ printk(KERN_ERR "PAX: bytes at PC: ");
8032+ for (i = 0; i < 8; i++) {
8033+ unsigned int c;
8034+ if (get_user(c, (unsigned int *)pc+i))
8035+ printk(KERN_CONT "???????? ");
8036+ else
8037+ printk(KERN_CONT "%08x ", c);
8038+ }
8039+ printk("\n");
8040+}
8041+#endif
8042+
8043 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
8044 {
8045 struct mm_struct *mm = current->mm;
8046@@ -341,6 +804,29 @@ retry:
8047 if (!vma)
8048 goto bad_area;
8049
8050+#ifdef CONFIG_PAX_PAGEEXEC
8051+ /* PaX: detect ITLB misses on non-exec pages */
8052+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
8053+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
8054+ {
8055+ if (address != regs->tpc)
8056+ goto good_area;
8057+
8058+ up_read(&mm->mmap_sem);
8059+ switch (pax_handle_fetch_fault(regs)) {
8060+
8061+#ifdef CONFIG_PAX_EMUPLT
8062+ case 2:
8063+ case 3:
8064+ return;
8065+#endif
8066+
8067+ }
8068+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
8069+ do_group_exit(SIGKILL);
8070+ }
8071+#endif
8072+
8073 /* Pure DTLB misses do not tell us whether the fault causing
8074 * load/store/atomic was a write or not, it only says that there
8075 * was no match. So in such a case we (carefully) read the
8076diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
8077index f76f83d..0f28457 100644
8078--- a/arch/sparc/mm/hugetlbpage.c
8079+++ b/arch/sparc/mm/hugetlbpage.c
8080@@ -67,7 +67,7 @@ full_search:
8081 }
8082 return -ENOMEM;
8083 }
8084- if (likely(!vma || addr + len <= vma->vm_start)) {
8085+ if (likely(check_heap_stack_gap(vma, addr, len))) {
8086 /*
8087 * Remember the place where we stopped the search:
8088 */
8089@@ -106,7 +106,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8090 /* make sure it can fit in the remaining address space */
8091 if (likely(addr > len)) {
8092 vma = find_vma(mm, addr-len);
8093- if (!vma || addr <= vma->vm_start) {
8094+ if (check_heap_stack_gap(vma, addr - len, len)) {
8095 /* remember the address as a hint for next time */
8096 return (mm->free_area_cache = addr-len);
8097 }
8098@@ -115,16 +115,17 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8099 if (unlikely(mm->mmap_base < len))
8100 goto bottomup;
8101
8102- addr = (mm->mmap_base-len) & HPAGE_MASK;
8103+ addr = mm->mmap_base - len;
8104
8105 do {
8106+ addr &= HPAGE_MASK;
8107 /*
8108 * Lookup failure means no vma is above this address,
8109 * else if new region fits below vma->vm_start,
8110 * return with success:
8111 */
8112 vma = find_vma(mm, addr);
8113- if (likely(!vma || addr+len <= vma->vm_start)) {
8114+ if (likely(check_heap_stack_gap(vma, addr, len))) {
8115 /* remember the address as a hint for next time */
8116 return (mm->free_area_cache = addr);
8117 }
8118@@ -134,8 +135,8 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8119 mm->cached_hole_size = vma->vm_start - addr;
8120
8121 /* try just below the current vma->vm_start */
8122- addr = (vma->vm_start-len) & HPAGE_MASK;
8123- } while (likely(len < vma->vm_start));
8124+ addr = skip_heap_stack_gap(vma, len);
8125+ } while (!IS_ERR_VALUE(addr));
8126
8127 bottomup:
8128 /*
8129@@ -181,8 +182,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
8130 if (addr) {
8131 addr = ALIGN(addr, HPAGE_SIZE);
8132 vma = find_vma(mm, addr);
8133- if (task_size - len >= addr &&
8134- (!vma || addr + len <= vma->vm_start))
8135+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
8136 return addr;
8137 }
8138 if (mm->get_unmapped_area == arch_get_unmapped_area)
8139diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
8140index f4500c6..889656c 100644
8141--- a/arch/tile/include/asm/atomic_64.h
8142+++ b/arch/tile/include/asm/atomic_64.h
8143@@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
8144
8145 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
8146
8147+#define atomic64_read_unchecked(v) atomic64_read(v)
8148+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
8149+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
8150+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
8151+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
8152+#define atomic64_inc_unchecked(v) atomic64_inc(v)
8153+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
8154+#define atomic64_dec_unchecked(v) atomic64_dec(v)
8155+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
8156+
8157 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
8158 #define smp_mb__before_atomic_dec() smp_mb()
8159 #define smp_mb__after_atomic_dec() smp_mb()
8160diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
8161index a9a5299..0fce79e 100644
8162--- a/arch/tile/include/asm/cache.h
8163+++ b/arch/tile/include/asm/cache.h
8164@@ -15,11 +15,12 @@
8165 #ifndef _ASM_TILE_CACHE_H
8166 #define _ASM_TILE_CACHE_H
8167
8168+#include <linux/const.h>
8169 #include <arch/chip.h>
8170
8171 /* bytes per L1 data cache line */
8172 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
8173-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8174+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8175
8176 /* bytes per L2 cache line */
8177 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
8178diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
8179index 9ab078a..d6635c2 100644
8180--- a/arch/tile/include/asm/uaccess.h
8181+++ b/arch/tile/include/asm/uaccess.h
8182@@ -403,9 +403,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
8183 const void __user *from,
8184 unsigned long n)
8185 {
8186- int sz = __compiletime_object_size(to);
8187+ size_t sz = __compiletime_object_size(to);
8188
8189- if (likely(sz == -1 || sz >= n))
8190+ if (likely(sz == (size_t)-1 || sz >= n))
8191 n = _copy_from_user(to, from, n);
8192 else
8193 copy_from_user_overflow();
8194diff --git a/arch/um/Makefile b/arch/um/Makefile
8195index 133f7de..1d6f2f1 100644
8196--- a/arch/um/Makefile
8197+++ b/arch/um/Makefile
8198@@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
8199 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
8200 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
8201
8202+ifdef CONSTIFY_PLUGIN
8203+USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
8204+endif
8205+
8206 #This will adjust *FLAGS accordingly to the platform.
8207 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
8208
8209diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
8210index 19e1bdd..3665b77 100644
8211--- a/arch/um/include/asm/cache.h
8212+++ b/arch/um/include/asm/cache.h
8213@@ -1,6 +1,7 @@
8214 #ifndef __UM_CACHE_H
8215 #define __UM_CACHE_H
8216
8217+#include <linux/const.h>
8218
8219 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
8220 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
8221@@ -12,6 +13,6 @@
8222 # define L1_CACHE_SHIFT 5
8223 #endif
8224
8225-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8226+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8227
8228 #endif
8229diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
8230index 2e0a6b1..a64d0f5 100644
8231--- a/arch/um/include/asm/kmap_types.h
8232+++ b/arch/um/include/asm/kmap_types.h
8233@@ -8,6 +8,6 @@
8234
8235 /* No more #include "asm/arch/kmap_types.h" ! */
8236
8237-#define KM_TYPE_NR 14
8238+#define KM_TYPE_NR 15
8239
8240 #endif
8241diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
8242index 5ff53d9..5850cdf 100644
8243--- a/arch/um/include/asm/page.h
8244+++ b/arch/um/include/asm/page.h
8245@@ -14,6 +14,9 @@
8246 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
8247 #define PAGE_MASK (~(PAGE_SIZE-1))
8248
8249+#define ktla_ktva(addr) (addr)
8250+#define ktva_ktla(addr) (addr)
8251+
8252 #ifndef __ASSEMBLY__
8253
8254 struct page;
8255diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
8256index 0032f92..cd151e0 100644
8257--- a/arch/um/include/asm/pgtable-3level.h
8258+++ b/arch/um/include/asm/pgtable-3level.h
8259@@ -58,6 +58,7 @@
8260 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
8261 #define pud_populate(mm, pud, pmd) \
8262 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
8263+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
8264
8265 #ifdef CONFIG_64BIT
8266 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
8267diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
8268index b6d699c..df7ac1d 100644
8269--- a/arch/um/kernel/process.c
8270+++ b/arch/um/kernel/process.c
8271@@ -387,22 +387,6 @@ int singlestepping(void * t)
8272 return 2;
8273 }
8274
8275-/*
8276- * Only x86 and x86_64 have an arch_align_stack().
8277- * All other arches have "#define arch_align_stack(x) (x)"
8278- * in their asm/system.h
8279- * As this is included in UML from asm-um/system-generic.h,
8280- * we can use it to behave as the subarch does.
8281- */
8282-#ifndef arch_align_stack
8283-unsigned long arch_align_stack(unsigned long sp)
8284-{
8285- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8286- sp -= get_random_int() % 8192;
8287- return sp & ~0xf;
8288-}
8289-#endif
8290-
8291 unsigned long get_wchan(struct task_struct *p)
8292 {
8293 unsigned long stack_page, sp, ip;
8294diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
8295index ad8f795..2c7eec6 100644
8296--- a/arch/unicore32/include/asm/cache.h
8297+++ b/arch/unicore32/include/asm/cache.h
8298@@ -12,8 +12,10 @@
8299 #ifndef __UNICORE_CACHE_H__
8300 #define __UNICORE_CACHE_H__
8301
8302-#define L1_CACHE_SHIFT (5)
8303-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8304+#include <linux/const.h>
8305+
8306+#define L1_CACHE_SHIFT 5
8307+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8308
8309 /*
8310 * Memory returned by kmalloc() may be used for DMA, so we must make
8311diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
8312index 46c3bff..c2286e7 100644
8313--- a/arch/x86/Kconfig
8314+++ b/arch/x86/Kconfig
8315@@ -241,7 +241,7 @@ config X86_HT
8316
8317 config X86_32_LAZY_GS
8318 def_bool y
8319- depends on X86_32 && !CC_STACKPROTECTOR
8320+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
8321
8322 config ARCH_HWEIGHT_CFLAGS
8323 string
8324@@ -1056,7 +1056,7 @@ choice
8325
8326 config NOHIGHMEM
8327 bool "off"
8328- depends on !X86_NUMAQ
8329+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
8330 ---help---
8331 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
8332 However, the address space of 32-bit x86 processors is only 4
8333@@ -1093,7 +1093,7 @@ config NOHIGHMEM
8334
8335 config HIGHMEM4G
8336 bool "4GB"
8337- depends on !X86_NUMAQ
8338+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
8339 ---help---
8340 Select this if you have a 32-bit processor and between 1 and 4
8341 gigabytes of physical RAM.
8342@@ -1147,7 +1147,7 @@ config PAGE_OFFSET
8343 hex
8344 default 0xB0000000 if VMSPLIT_3G_OPT
8345 default 0x80000000 if VMSPLIT_2G
8346- default 0x78000000 if VMSPLIT_2G_OPT
8347+ default 0x70000000 if VMSPLIT_2G_OPT
8348 default 0x40000000 if VMSPLIT_1G
8349 default 0xC0000000
8350 depends on X86_32
8351@@ -1548,6 +1548,7 @@ config SECCOMP
8352
8353 config CC_STACKPROTECTOR
8354 bool "Enable -fstack-protector buffer overflow detection"
8355+ depends on X86_64 || !PAX_MEMORY_UDEREF
8356 ---help---
8357 This option turns on the -fstack-protector GCC feature. This
8358 feature puts, at the beginning of functions, a canary value on
8359@@ -1605,6 +1606,7 @@ config KEXEC_JUMP
8360 config PHYSICAL_START
8361 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
8362 default "0x1000000"
8363+ range 0x400000 0x40000000
8364 ---help---
8365 This gives the physical address where the kernel is loaded.
8366
8367@@ -1668,6 +1670,7 @@ config X86_NEED_RELOCS
8368 config PHYSICAL_ALIGN
8369 hex "Alignment value to which kernel should be aligned" if X86_32
8370 default "0x1000000"
8371+ range 0x400000 0x1000000 if PAX_KERNEXEC
8372 range 0x2000 0x1000000
8373 ---help---
8374 This value puts the alignment restrictions on physical address
8375@@ -1699,9 +1702,10 @@ config HOTPLUG_CPU
8376 Say N if you want to disable CPU hotplug.
8377
8378 config COMPAT_VDSO
8379- def_bool y
8380+ def_bool n
8381 prompt "Compat VDSO support"
8382 depends on X86_32 || IA32_EMULATION
8383+ depends on !PAX_NOEXEC && !PAX_MEMORY_UDEREF
8384 ---help---
8385 Map the 32-bit VDSO to the predictable old-style address too.
8386
8387diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
8388index f3b86d0..17fd30f 100644
8389--- a/arch/x86/Kconfig.cpu
8390+++ b/arch/x86/Kconfig.cpu
8391@@ -335,7 +335,7 @@ config X86_PPRO_FENCE
8392
8393 config X86_F00F_BUG
8394 def_bool y
8395- depends on M586MMX || M586TSC || M586 || M486 || M386
8396+ depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
8397
8398 config X86_INVD_BUG
8399 def_bool y
8400@@ -359,7 +359,7 @@ config X86_POPAD_OK
8401
8402 config X86_ALIGNMENT_16
8403 def_bool y
8404- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
8405+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
8406
8407 config X86_INTEL_USERCOPY
8408 def_bool y
8409@@ -405,7 +405,7 @@ config X86_CMPXCHG64
8410 # generates cmov.
8411 config X86_CMOV
8412 def_bool y
8413- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
8414+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
8415
8416 config X86_MINIMUM_CPU_FAMILY
8417 int
8418diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
8419index b322f12..652d0d9 100644
8420--- a/arch/x86/Kconfig.debug
8421+++ b/arch/x86/Kconfig.debug
8422@@ -84,7 +84,7 @@ config X86_PTDUMP
8423 config DEBUG_RODATA
8424 bool "Write protect kernel read-only data structures"
8425 default y
8426- depends on DEBUG_KERNEL
8427+ depends on DEBUG_KERNEL && BROKEN
8428 ---help---
8429 Mark the kernel read-only data as write-protected in the pagetables,
8430 in order to catch accidental (and incorrect) writes to such const
8431@@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
8432
8433 config DEBUG_SET_MODULE_RONX
8434 bool "Set loadable kernel module data as NX and text as RO"
8435- depends on MODULES
8436+ depends on MODULES && BROKEN
8437 ---help---
8438 This option helps catch unintended modifications to loadable
8439 kernel module's text and read-only data. It also prevents execution
8440@@ -294,7 +294,7 @@ config OPTIMIZE_INLINING
8441
8442 config DEBUG_STRICT_USER_COPY_CHECKS
8443 bool "Strict copy size checks"
8444- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
8445+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
8446 ---help---
8447 Enabling this option turns a certain set of sanity checks for user
8448 copy operations into compile time failures.
8449diff --git a/arch/x86/Makefile b/arch/x86/Makefile
8450index 05afcca..b6ecb51 100644
8451--- a/arch/x86/Makefile
8452+++ b/arch/x86/Makefile
8453@@ -50,6 +50,7 @@ else
8454 UTS_MACHINE := x86_64
8455 CHECKFLAGS += -D__x86_64__ -m64
8456
8457+ biarch := $(call cc-option,-m64)
8458 KBUILD_AFLAGS += -m64
8459 KBUILD_CFLAGS += -m64
8460
8461@@ -229,3 +230,12 @@ define archhelp
8462 echo ' FDARGS="..." arguments for the booted kernel'
8463 echo ' FDINITRD=file initrd for the booted kernel'
8464 endef
8465+
8466+define OLD_LD
8467+
8468+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
8469+*** Please upgrade your binutils to 2.18 or newer
8470+endef
8471+
8472+archprepare:
8473+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
8474diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
8475index ccce0ed..fd9da25 100644
8476--- a/arch/x86/boot/Makefile
8477+++ b/arch/x86/boot/Makefile
8478@@ -65,6 +65,9 @@ KBUILD_CFLAGS := $(USERINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
8479 $(call cc-option, -fno-stack-protector) \
8480 $(call cc-option, -mpreferred-stack-boundary=2)
8481 KBUILD_CFLAGS += $(call cc-option, -m32)
8482+ifdef CONSTIFY_PLUGIN
8483+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
8484+endif
8485 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
8486 GCOV_PROFILE := n
8487
8488diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
8489index 878e4b9..20537ab 100644
8490--- a/arch/x86/boot/bitops.h
8491+++ b/arch/x86/boot/bitops.h
8492@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
8493 u8 v;
8494 const u32 *p = (const u32 *)addr;
8495
8496- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
8497+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
8498 return v;
8499 }
8500
8501@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
8502
8503 static inline void set_bit(int nr, void *addr)
8504 {
8505- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
8506+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
8507 }
8508
8509 #endif /* BOOT_BITOPS_H */
8510diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
8511index 18997e5..83d9c67 100644
8512--- a/arch/x86/boot/boot.h
8513+++ b/arch/x86/boot/boot.h
8514@@ -85,7 +85,7 @@ static inline void io_delay(void)
8515 static inline u16 ds(void)
8516 {
8517 u16 seg;
8518- asm("movw %%ds,%0" : "=rm" (seg));
8519+ asm volatile("movw %%ds,%0" : "=rm" (seg));
8520 return seg;
8521 }
8522
8523@@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
8524 static inline int memcmp(const void *s1, const void *s2, size_t len)
8525 {
8526 u8 diff;
8527- asm("repe; cmpsb; setnz %0"
8528+ asm volatile("repe; cmpsb; setnz %0"
8529 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
8530 return diff;
8531 }
8532diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
8533index 8a84501..b2d165f 100644
8534--- a/arch/x86/boot/compressed/Makefile
8535+++ b/arch/x86/boot/compressed/Makefile
8536@@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
8537 KBUILD_CFLAGS += $(cflags-y)
8538 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
8539 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
8540+ifdef CONSTIFY_PLUGIN
8541+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
8542+endif
8543
8544 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
8545 GCOV_PROFILE := n
8546diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
8547index e87b0ca..2bce457 100644
8548--- a/arch/x86/boot/compressed/eboot.c
8549+++ b/arch/x86/boot/compressed/eboot.c
8550@@ -144,7 +144,6 @@ again:
8551 *addr = max_addr;
8552 }
8553
8554-free_pool:
8555 efi_call_phys1(sys_table->boottime->free_pool, map);
8556
8557 fail:
8558@@ -208,7 +207,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
8559 if (i == map_size / desc_size)
8560 status = EFI_NOT_FOUND;
8561
8562-free_pool:
8563 efi_call_phys1(sys_table->boottime->free_pool, map);
8564 fail:
8565 return status;
8566diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
8567index aa4aaf1..6656f2f 100644
8568--- a/arch/x86/boot/compressed/head_32.S
8569+++ b/arch/x86/boot/compressed/head_32.S
8570@@ -116,7 +116,7 @@ preferred_addr:
8571 notl %eax
8572 andl %eax, %ebx
8573 #else
8574- movl $LOAD_PHYSICAL_ADDR, %ebx
8575+ movl $____LOAD_PHYSICAL_ADDR, %ebx
8576 #endif
8577
8578 /* Target address to relocate to for decompression */
8579@@ -202,7 +202,7 @@ relocated:
8580 * and where it was actually loaded.
8581 */
8582 movl %ebp, %ebx
8583- subl $LOAD_PHYSICAL_ADDR, %ebx
8584+ subl $____LOAD_PHYSICAL_ADDR, %ebx
8585 jz 2f /* Nothing to be done if loaded at compiled addr. */
8586 /*
8587 * Process relocations.
8588@@ -210,8 +210,7 @@ relocated:
8589
8590 1: subl $4, %edi
8591 movl (%edi), %ecx
8592- testl %ecx, %ecx
8593- jz 2f
8594+ jecxz 2f
8595 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
8596 jmp 1b
8597 2:
8598diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
8599index 2c4b171..e1fa5b1 100644
8600--- a/arch/x86/boot/compressed/head_64.S
8601+++ b/arch/x86/boot/compressed/head_64.S
8602@@ -91,7 +91,7 @@ ENTRY(startup_32)
8603 notl %eax
8604 andl %eax, %ebx
8605 #else
8606- movl $LOAD_PHYSICAL_ADDR, %ebx
8607+ movl $____LOAD_PHYSICAL_ADDR, %ebx
8608 #endif
8609
8610 /* Target address to relocate to for decompression */
8611@@ -273,7 +273,7 @@ preferred_addr:
8612 notq %rax
8613 andq %rax, %rbp
8614 #else
8615- movq $LOAD_PHYSICAL_ADDR, %rbp
8616+ movq $____LOAD_PHYSICAL_ADDR, %rbp
8617 #endif
8618
8619 /* Target address to relocate to for decompression */
8620diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
8621index 88f7ff6..ed695dd 100644
8622--- a/arch/x86/boot/compressed/misc.c
8623+++ b/arch/x86/boot/compressed/misc.c
8624@@ -303,7 +303,7 @@ static void parse_elf(void *output)
8625 case PT_LOAD:
8626 #ifdef CONFIG_RELOCATABLE
8627 dest = output;
8628- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
8629+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
8630 #else
8631 dest = (void *)(phdr->p_paddr);
8632 #endif
8633@@ -352,7 +352,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
8634 error("Destination address too large");
8635 #endif
8636 #ifndef CONFIG_RELOCATABLE
8637- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
8638+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
8639 error("Wrong destination address");
8640 #endif
8641
8642diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
8643index 4d3ff03..e4972ff 100644
8644--- a/arch/x86/boot/cpucheck.c
8645+++ b/arch/x86/boot/cpucheck.c
8646@@ -74,7 +74,7 @@ static int has_fpu(void)
8647 u16 fcw = -1, fsw = -1;
8648 u32 cr0;
8649
8650- asm("movl %%cr0,%0" : "=r" (cr0));
8651+ asm volatile("movl %%cr0,%0" : "=r" (cr0));
8652 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
8653 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
8654 asm volatile("movl %0,%%cr0" : : "r" (cr0));
8655@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
8656 {
8657 u32 f0, f1;
8658
8659- asm("pushfl ; "
8660+ asm volatile("pushfl ; "
8661 "pushfl ; "
8662 "popl %0 ; "
8663 "movl %0,%1 ; "
8664@@ -115,7 +115,7 @@ static void get_flags(void)
8665 set_bit(X86_FEATURE_FPU, cpu.flags);
8666
8667 if (has_eflag(X86_EFLAGS_ID)) {
8668- asm("cpuid"
8669+ asm volatile("cpuid"
8670 : "=a" (max_intel_level),
8671 "=b" (cpu_vendor[0]),
8672 "=d" (cpu_vendor[1]),
8673@@ -124,7 +124,7 @@ static void get_flags(void)
8674
8675 if (max_intel_level >= 0x00000001 &&
8676 max_intel_level <= 0x0000ffff) {
8677- asm("cpuid"
8678+ asm volatile("cpuid"
8679 : "=a" (tfms),
8680 "=c" (cpu.flags[4]),
8681 "=d" (cpu.flags[0])
8682@@ -136,7 +136,7 @@ static void get_flags(void)
8683 cpu.model += ((tfms >> 16) & 0xf) << 4;
8684 }
8685
8686- asm("cpuid"
8687+ asm volatile("cpuid"
8688 : "=a" (max_amd_level)
8689 : "a" (0x80000000)
8690 : "ebx", "ecx", "edx");
8691@@ -144,7 +144,7 @@ static void get_flags(void)
8692 if (max_amd_level >= 0x80000001 &&
8693 max_amd_level <= 0x8000ffff) {
8694 u32 eax = 0x80000001;
8695- asm("cpuid"
8696+ asm volatile("cpuid"
8697 : "+a" (eax),
8698 "=c" (cpu.flags[6]),
8699 "=d" (cpu.flags[1])
8700@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
8701 u32 ecx = MSR_K7_HWCR;
8702 u32 eax, edx;
8703
8704- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8705+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8706 eax &= ~(1 << 15);
8707- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8708+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8709
8710 get_flags(); /* Make sure it really did something */
8711 err = check_flags();
8712@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
8713 u32 ecx = MSR_VIA_FCR;
8714 u32 eax, edx;
8715
8716- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8717+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8718 eax |= (1<<1)|(1<<7);
8719- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8720+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8721
8722 set_bit(X86_FEATURE_CX8, cpu.flags);
8723 err = check_flags();
8724@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
8725 u32 eax, edx;
8726 u32 level = 1;
8727
8728- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8729- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
8730- asm("cpuid"
8731+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8732+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
8733+ asm volatile("cpuid"
8734 : "+a" (level), "=d" (cpu.flags[0])
8735 : : "ecx", "ebx");
8736- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8737+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8738
8739 err = check_flags();
8740 }
8741diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
8742index 8c132a6..13e5c96 100644
8743--- a/arch/x86/boot/header.S
8744+++ b/arch/x86/boot/header.S
8745@@ -387,10 +387,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
8746 # single linked list of
8747 # struct setup_data
8748
8749-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
8750+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
8751
8752 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
8753+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
8754+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
8755+#else
8756 #define VO_INIT_SIZE (VO__end - VO__text)
8757+#endif
8758 #if ZO_INIT_SIZE > VO_INIT_SIZE
8759 #define INIT_SIZE ZO_INIT_SIZE
8760 #else
8761diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
8762index db75d07..8e6d0af 100644
8763--- a/arch/x86/boot/memory.c
8764+++ b/arch/x86/boot/memory.c
8765@@ -19,7 +19,7 @@
8766
8767 static int detect_memory_e820(void)
8768 {
8769- int count = 0;
8770+ unsigned int count = 0;
8771 struct biosregs ireg, oreg;
8772 struct e820entry *desc = boot_params.e820_map;
8773 static struct e820entry buf; /* static so it is zeroed */
8774diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
8775index 11e8c6e..fdbb1ed 100644
8776--- a/arch/x86/boot/video-vesa.c
8777+++ b/arch/x86/boot/video-vesa.c
8778@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
8779
8780 boot_params.screen_info.vesapm_seg = oreg.es;
8781 boot_params.screen_info.vesapm_off = oreg.di;
8782+ boot_params.screen_info.vesapm_size = oreg.cx;
8783 }
8784
8785 /*
8786diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
8787index 43eda28..5ab5fdb 100644
8788--- a/arch/x86/boot/video.c
8789+++ b/arch/x86/boot/video.c
8790@@ -96,7 +96,7 @@ static void store_mode_params(void)
8791 static unsigned int get_entry(void)
8792 {
8793 char entry_buf[4];
8794- int i, len = 0;
8795+ unsigned int i, len = 0;
8796 int key;
8797 unsigned int v;
8798
8799diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
8800index 5b577d5..3c1fed4 100644
8801--- a/arch/x86/crypto/aes-x86_64-asm_64.S
8802+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
8803@@ -8,6 +8,8 @@
8804 * including this sentence is retained in full.
8805 */
8806
8807+#include <asm/alternative-asm.h>
8808+
8809 .extern crypto_ft_tab
8810 .extern crypto_it_tab
8811 .extern crypto_fl_tab
8812@@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
8813 je B192; \
8814 leaq 32(r9),r9;
8815
8816+#define ret pax_force_retaddr 0, 1; ret
8817+
8818 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
8819 movq r1,r2; \
8820 movq r3,r4; \
8821diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
8822index 3470624..201259d 100644
8823--- a/arch/x86/crypto/aesni-intel_asm.S
8824+++ b/arch/x86/crypto/aesni-intel_asm.S
8825@@ -31,6 +31,7 @@
8826
8827 #include <linux/linkage.h>
8828 #include <asm/inst.h>
8829+#include <asm/alternative-asm.h>
8830
8831 #ifdef __x86_64__
8832 .data
8833@@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
8834 pop %r14
8835 pop %r13
8836 pop %r12
8837+ pax_force_retaddr 0, 1
8838 ret
8839+ENDPROC(aesni_gcm_dec)
8840
8841
8842 /*****************************************************************************
8843@@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
8844 pop %r14
8845 pop %r13
8846 pop %r12
8847+ pax_force_retaddr 0, 1
8848 ret
8849+ENDPROC(aesni_gcm_enc)
8850
8851 #endif
8852
8853@@ -1714,6 +1719,7 @@ _key_expansion_256a:
8854 pxor %xmm1, %xmm0
8855 movaps %xmm0, (TKEYP)
8856 add $0x10, TKEYP
8857+ pax_force_retaddr_bts
8858 ret
8859
8860 .align 4
8861@@ -1738,6 +1744,7 @@ _key_expansion_192a:
8862 shufps $0b01001110, %xmm2, %xmm1
8863 movaps %xmm1, 0x10(TKEYP)
8864 add $0x20, TKEYP
8865+ pax_force_retaddr_bts
8866 ret
8867
8868 .align 4
8869@@ -1757,6 +1764,7 @@ _key_expansion_192b:
8870
8871 movaps %xmm0, (TKEYP)
8872 add $0x10, TKEYP
8873+ pax_force_retaddr_bts
8874 ret
8875
8876 .align 4
8877@@ -1769,6 +1777,7 @@ _key_expansion_256b:
8878 pxor %xmm1, %xmm2
8879 movaps %xmm2, (TKEYP)
8880 add $0x10, TKEYP
8881+ pax_force_retaddr_bts
8882 ret
8883
8884 /*
8885@@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
8886 #ifndef __x86_64__
8887 popl KEYP
8888 #endif
8889+ pax_force_retaddr 0, 1
8890 ret
8891+ENDPROC(aesni_set_key)
8892
8893 /*
8894 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
8895@@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
8896 popl KLEN
8897 popl KEYP
8898 #endif
8899+ pax_force_retaddr 0, 1
8900 ret
8901+ENDPROC(aesni_enc)
8902
8903 /*
8904 * _aesni_enc1: internal ABI
8905@@ -1959,6 +1972,7 @@ _aesni_enc1:
8906 AESENC KEY STATE
8907 movaps 0x70(TKEYP), KEY
8908 AESENCLAST KEY STATE
8909+ pax_force_retaddr_bts
8910 ret
8911
8912 /*
8913@@ -2067,6 +2081,7 @@ _aesni_enc4:
8914 AESENCLAST KEY STATE2
8915 AESENCLAST KEY STATE3
8916 AESENCLAST KEY STATE4
8917+ pax_force_retaddr_bts
8918 ret
8919
8920 /*
8921@@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
8922 popl KLEN
8923 popl KEYP
8924 #endif
8925+ pax_force_retaddr 0, 1
8926 ret
8927+ENDPROC(aesni_dec)
8928
8929 /*
8930 * _aesni_dec1: internal ABI
8931@@ -2146,6 +2163,7 @@ _aesni_dec1:
8932 AESDEC KEY STATE
8933 movaps 0x70(TKEYP), KEY
8934 AESDECLAST KEY STATE
8935+ pax_force_retaddr_bts
8936 ret
8937
8938 /*
8939@@ -2254,6 +2272,7 @@ _aesni_dec4:
8940 AESDECLAST KEY STATE2
8941 AESDECLAST KEY STATE3
8942 AESDECLAST KEY STATE4
8943+ pax_force_retaddr_bts
8944 ret
8945
8946 /*
8947@@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
8948 popl KEYP
8949 popl LEN
8950 #endif
8951+ pax_force_retaddr 0, 1
8952 ret
8953+ENDPROC(aesni_ecb_enc)
8954
8955 /*
8956 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8957@@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
8958 popl KEYP
8959 popl LEN
8960 #endif
8961+ pax_force_retaddr 0, 1
8962 ret
8963+ENDPROC(aesni_ecb_dec)
8964
8965 /*
8966 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8967@@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
8968 popl LEN
8969 popl IVP
8970 #endif
8971+ pax_force_retaddr 0, 1
8972 ret
8973+ENDPROC(aesni_cbc_enc)
8974
8975 /*
8976 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8977@@ -2500,7 +2525,9 @@ ENTRY(aesni_cbc_dec)
8978 popl LEN
8979 popl IVP
8980 #endif
8981+ pax_force_retaddr 0, 1
8982 ret
8983+ENDPROC(aesni_cbc_dec)
8984
8985 #ifdef __x86_64__
8986 .align 16
8987@@ -2526,6 +2553,7 @@ _aesni_inc_init:
8988 mov $1, TCTR_LOW
8989 MOVQ_R64_XMM TCTR_LOW INC
8990 MOVQ_R64_XMM CTR TCTR_LOW
8991+ pax_force_retaddr_bts
8992 ret
8993
8994 /*
8995@@ -2554,6 +2582,7 @@ _aesni_inc:
8996 .Linc_low:
8997 movaps CTR, IV
8998 PSHUFB_XMM BSWAP_MASK IV
8999+ pax_force_retaddr_bts
9000 ret
9001
9002 /*
9003@@ -2614,5 +2643,7 @@ ENTRY(aesni_ctr_enc)
9004 .Lctr_enc_ret:
9005 movups IV, (IVP)
9006 .Lctr_enc_just_ret:
9007+ pax_force_retaddr 0, 1
9008 ret
9009+ENDPROC(aesni_ctr_enc)
9010 #endif
9011diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
9012index 391d245..67f35c2 100644
9013--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
9014+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
9015@@ -20,6 +20,8 @@
9016 *
9017 */
9018
9019+#include <asm/alternative-asm.h>
9020+
9021 .file "blowfish-x86_64-asm.S"
9022 .text
9023
9024@@ -151,9 +153,11 @@ __blowfish_enc_blk:
9025 jnz __enc_xor;
9026
9027 write_block();
9028+ pax_force_retaddr 0, 1
9029 ret;
9030 __enc_xor:
9031 xor_block();
9032+ pax_force_retaddr 0, 1
9033 ret;
9034
9035 .align 8
9036@@ -188,6 +192,7 @@ blowfish_dec_blk:
9037
9038 movq %r11, %rbp;
9039
9040+ pax_force_retaddr 0, 1
9041 ret;
9042
9043 /**********************************************************************
9044@@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
9045
9046 popq %rbx;
9047 popq %rbp;
9048+ pax_force_retaddr 0, 1
9049 ret;
9050
9051 __enc_xor4:
9052@@ -349,6 +355,7 @@ __enc_xor4:
9053
9054 popq %rbx;
9055 popq %rbp;
9056+ pax_force_retaddr 0, 1
9057 ret;
9058
9059 .align 8
9060@@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
9061 popq %rbx;
9062 popq %rbp;
9063
9064+ pax_force_retaddr 0, 1
9065 ret;
9066
9067diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
9068index 0b33743..7a56206 100644
9069--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
9070+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
9071@@ -20,6 +20,8 @@
9072 *
9073 */
9074
9075+#include <asm/alternative-asm.h>
9076+
9077 .file "camellia-x86_64-asm_64.S"
9078 .text
9079
9080@@ -229,12 +231,14 @@ __enc_done:
9081 enc_outunpack(mov, RT1);
9082
9083 movq RRBP, %rbp;
9084+ pax_force_retaddr 0, 1
9085 ret;
9086
9087 __enc_xor:
9088 enc_outunpack(xor, RT1);
9089
9090 movq RRBP, %rbp;
9091+ pax_force_retaddr 0, 1
9092 ret;
9093
9094 .global camellia_dec_blk;
9095@@ -275,6 +279,7 @@ __dec_rounds16:
9096 dec_outunpack();
9097
9098 movq RRBP, %rbp;
9099+ pax_force_retaddr 0, 1
9100 ret;
9101
9102 /**********************************************************************
9103@@ -468,6 +473,7 @@ __enc2_done:
9104
9105 movq RRBP, %rbp;
9106 popq %rbx;
9107+ pax_force_retaddr 0, 1
9108 ret;
9109
9110 __enc2_xor:
9111@@ -475,6 +481,7 @@ __enc2_xor:
9112
9113 movq RRBP, %rbp;
9114 popq %rbx;
9115+ pax_force_retaddr 0, 1
9116 ret;
9117
9118 .global camellia_dec_blk_2way;
9119@@ -517,4 +524,5 @@ __dec2_rounds16:
9120
9121 movq RRBP, %rbp;
9122 movq RXOR, %rbx;
9123+ pax_force_retaddr 0, 1
9124 ret;
9125diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
9126index a41a3aa..bdf5753 100644
9127--- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
9128+++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
9129@@ -23,6 +23,8 @@
9130 *
9131 */
9132
9133+#include <asm/alternative-asm.h>
9134+
9135 .file "cast5-avx-x86_64-asm_64.S"
9136
9137 .extern cast5_s1
9138@@ -293,6 +295,7 @@ __skip_enc:
9139 leaq 3*(2*4*4)(%r11), %rax;
9140 outunpack_blocks(%rax, RR4, RL4, RTMP, RX, RKM);
9141
9142+ pax_force_retaddr 0, 1
9143 ret;
9144
9145 __enc_xor16:
9146@@ -303,6 +306,7 @@ __enc_xor16:
9147 leaq 3*(2*4*4)(%r11), %rax;
9148 outunpack_xor_blocks(%rax, RR4, RL4, RTMP, RX, RKM);
9149
9150+ pax_force_retaddr 0, 1
9151 ret;
9152
9153 .align 16
9154@@ -369,6 +373,7 @@ __dec_tail:
9155 leaq 3*(2*4*4)(%r11), %rax;
9156 outunpack_blocks(%rax, RR4, RL4, RTMP, RX, RKM);
9157
9158+ pax_force_retaddr 0, 1
9159 ret;
9160
9161 __skip_dec:
9162diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
9163index 218d283..819e6da 100644
9164--- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
9165+++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
9166@@ -23,6 +23,8 @@
9167 *
9168 */
9169
9170+#include <asm/alternative-asm.h>
9171+
9172 .file "cast6-avx-x86_64-asm_64.S"
9173
9174 .extern cast6_s1
9175@@ -324,12 +326,14 @@ __cast6_enc_blk_8way:
9176 outunpack_blocks(%r11, RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
9177 outunpack_blocks(%rax, RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
9178
9179+ pax_force_retaddr 0, 1
9180 ret;
9181
9182 __enc_xor8:
9183 outunpack_xor_blocks(%r11, RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
9184 outunpack_xor_blocks(%rax, RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
9185
9186+ pax_force_retaddr 0, 1
9187 ret;
9188
9189 .align 16
9190@@ -380,4 +384,5 @@ cast6_dec_blk_8way:
9191 outunpack_blocks(%r11, RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
9192 outunpack_blocks(%rax, RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
9193
9194+ pax_force_retaddr 0, 1
9195 ret;
9196diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
9197index 6214a9b..1f4fc9a 100644
9198--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
9199+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
9200@@ -1,3 +1,5 @@
9201+#include <asm/alternative-asm.h>
9202+
9203 # enter ECRYPT_encrypt_bytes
9204 .text
9205 .p2align 5
9206@@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
9207 add %r11,%rsp
9208 mov %rdi,%rax
9209 mov %rsi,%rdx
9210+ pax_force_retaddr 0, 1
9211 ret
9212 # bytesatleast65:
9213 ._bytesatleast65:
9214@@ -891,6 +894,7 @@ ECRYPT_keysetup:
9215 add %r11,%rsp
9216 mov %rdi,%rax
9217 mov %rsi,%rdx
9218+ pax_force_retaddr
9219 ret
9220 # enter ECRYPT_ivsetup
9221 .text
9222@@ -917,4 +921,5 @@ ECRYPT_ivsetup:
9223 add %r11,%rsp
9224 mov %rdi,%rax
9225 mov %rsi,%rdx
9226+ pax_force_retaddr
9227 ret
9228diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
9229index 504106b..4e50951 100644
9230--- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
9231+++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
9232@@ -24,6 +24,8 @@
9233 *
9234 */
9235
9236+#include <asm/alternative-asm.h>
9237+
9238 .file "serpent-avx-x86_64-asm_64.S"
9239 .text
9240
9241@@ -638,12 +640,14 @@ __serpent_enc_blk_8way_avx:
9242 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
9243 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
9244
9245+ pax_force_retaddr
9246 ret;
9247
9248 __enc_xor8:
9249 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
9250 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
9251
9252+ pax_force_retaddr
9253 ret;
9254
9255 .align 8
9256@@ -701,4 +705,5 @@ serpent_dec_blk_8way_avx:
9257 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
9258 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
9259
9260+ pax_force_retaddr
9261 ret;
9262diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
9263index 3ee1ff0..cbc568b 100644
9264--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
9265+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
9266@@ -24,6 +24,8 @@
9267 *
9268 */
9269
9270+#include <asm/alternative-asm.h>
9271+
9272 .file "serpent-sse2-x86_64-asm_64.S"
9273 .text
9274
9275@@ -692,12 +694,14 @@ __serpent_enc_blk_8way:
9276 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
9277 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
9278
9279+ pax_force_retaddr
9280 ret;
9281
9282 __enc_xor8:
9283 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
9284 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
9285
9286+ pax_force_retaddr
9287 ret;
9288
9289 .align 8
9290@@ -755,4 +759,5 @@ serpent_dec_blk_8way:
9291 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
9292 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
9293
9294+ pax_force_retaddr
9295 ret;
9296diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
9297index 49d6987..df66bd4 100644
9298--- a/arch/x86/crypto/sha1_ssse3_asm.S
9299+++ b/arch/x86/crypto/sha1_ssse3_asm.S
9300@@ -28,6 +28,8 @@
9301 * (at your option) any later version.
9302 */
9303
9304+#include <asm/alternative-asm.h>
9305+
9306 #define CTX %rdi // arg1
9307 #define BUF %rsi // arg2
9308 #define CNT %rdx // arg3
9309@@ -104,6 +106,7 @@
9310 pop %r12
9311 pop %rbp
9312 pop %rbx
9313+ pax_force_retaddr 0, 1
9314 ret
9315
9316 .size \name, .-\name
9317diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
9318index 1585abb..4a9af16 100644
9319--- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
9320+++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
9321@@ -23,6 +23,8 @@
9322 *
9323 */
9324
9325+#include <asm/alternative-asm.h>
9326+
9327 .file "twofish-avx-x86_64-asm_64.S"
9328 .text
9329
9330@@ -303,12 +305,14 @@ __twofish_enc_blk_8way:
9331 outunpack_blocks(%r11, RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
9332 outunpack_blocks(%rax, RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
9333
9334+ pax_force_retaddr
9335 ret;
9336
9337 __enc_xor8:
9338 outunpack_xor_blocks(%r11, RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
9339 outunpack_xor_blocks(%rax, RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
9340
9341+ pax_force_retaddr
9342 ret;
9343
9344 .align 8
9345@@ -354,4 +358,5 @@ twofish_dec_blk_8way:
9346 outunpack_blocks(%r11, RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
9347 outunpack_blocks(%rax, RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
9348
9349+ pax_force_retaddr
9350 ret;
9351diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
9352index 5b012a2..36d5364 100644
9353--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
9354+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
9355@@ -20,6 +20,8 @@
9356 *
9357 */
9358
9359+#include <asm/alternative-asm.h>
9360+
9361 .file "twofish-x86_64-asm-3way.S"
9362 .text
9363
9364@@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
9365 popq %r13;
9366 popq %r14;
9367 popq %r15;
9368+ pax_force_retaddr 0, 1
9369 ret;
9370
9371 __enc_xor3:
9372@@ -271,6 +274,7 @@ __enc_xor3:
9373 popq %r13;
9374 popq %r14;
9375 popq %r15;
9376+ pax_force_retaddr 0, 1
9377 ret;
9378
9379 .global twofish_dec_blk_3way
9380@@ -312,5 +316,6 @@ twofish_dec_blk_3way:
9381 popq %r13;
9382 popq %r14;
9383 popq %r15;
9384+ pax_force_retaddr 0, 1
9385 ret;
9386
9387diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
9388index 7bcf3fc..f53832f 100644
9389--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
9390+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
9391@@ -21,6 +21,7 @@
9392 .text
9393
9394 #include <asm/asm-offsets.h>
9395+#include <asm/alternative-asm.h>
9396
9397 #define a_offset 0
9398 #define b_offset 4
9399@@ -268,6 +269,7 @@ twofish_enc_blk:
9400
9401 popq R1
9402 movq $1,%rax
9403+ pax_force_retaddr 0, 1
9404 ret
9405
9406 twofish_dec_blk:
9407@@ -319,4 +321,5 @@ twofish_dec_blk:
9408
9409 popq R1
9410 movq $1,%rax
9411+ pax_force_retaddr 0, 1
9412 ret
9413diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
9414index 07b3a68..bd2a388 100644
9415--- a/arch/x86/ia32/ia32_aout.c
9416+++ b/arch/x86/ia32/ia32_aout.c
9417@@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
9418 unsigned long dump_start, dump_size;
9419 struct user32 dump;
9420
9421+ memset(&dump, 0, sizeof(dump));
9422+
9423 fs = get_fs();
9424 set_fs(KERNEL_DS);
9425 has_dumped = 1;
9426diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
9427index efc6a95..95abfe2 100644
9428--- a/arch/x86/ia32/ia32_signal.c
9429+++ b/arch/x86/ia32/ia32_signal.c
9430@@ -163,8 +163,8 @@ asmlinkage long sys32_sigaltstack(const stack_ia32_t __user *uss_ptr,
9431 }
9432 seg = get_fs();
9433 set_fs(KERNEL_DS);
9434- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
9435- (stack_t __force __user *) &uoss, regs->sp);
9436+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
9437+ (stack_t __force_user *) &uoss, regs->sp);
9438 set_fs(seg);
9439 if (ret >= 0 && uoss_ptr) {
9440 if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(stack_ia32_t)))
9441@@ -396,7 +396,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
9442 sp -= frame_size;
9443 /* Align the stack pointer according to the i386 ABI,
9444 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
9445- sp = ((sp + 4) & -16ul) - 4;
9446+ sp = ((sp - 12) & -16ul) - 4;
9447 return (void __user *) sp;
9448 }
9449
9450@@ -454,7 +454,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
9451 * These are actually not used anymore, but left because some
9452 * gdb versions depend on them as a marker.
9453 */
9454- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
9455+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
9456 } put_user_catch(err);
9457
9458 if (err)
9459@@ -496,7 +496,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
9460 0xb8,
9461 __NR_ia32_rt_sigreturn,
9462 0x80cd,
9463- 0,
9464+ 0
9465 };
9466
9467 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
9468@@ -522,16 +522,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
9469
9470 if (ka->sa.sa_flags & SA_RESTORER)
9471 restorer = ka->sa.sa_restorer;
9472+ else if (current->mm->context.vdso)
9473+ /* Return stub is in 32bit vsyscall page */
9474+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
9475 else
9476- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
9477- rt_sigreturn);
9478+ restorer = &frame->retcode;
9479 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
9480
9481 /*
9482 * Not actually used anymore, but left because some gdb
9483 * versions need it.
9484 */
9485- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
9486+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
9487 } put_user_catch(err);
9488
9489 err |= copy_siginfo_to_user32(&frame->info, info);
9490diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
9491index 076745f..ae8f6cb 100644
9492--- a/arch/x86/ia32/ia32entry.S
9493+++ b/arch/x86/ia32/ia32entry.S
9494@@ -15,8 +15,10 @@
9495 #include <asm/irqflags.h>
9496 #include <asm/asm.h>
9497 #include <asm/smap.h>
9498+#include <asm/pgtable.h>
9499 #include <linux/linkage.h>
9500 #include <linux/err.h>
9501+#include <asm/alternative-asm.h>
9502
9503 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
9504 #include <linux/elf-em.h>
9505@@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
9506 ENDPROC(native_irq_enable_sysexit)
9507 #endif
9508
9509+ .macro pax_enter_kernel_user
9510+ pax_set_fptr_mask
9511+#ifdef CONFIG_PAX_MEMORY_UDEREF
9512+ call pax_enter_kernel_user
9513+#endif
9514+ .endm
9515+
9516+ .macro pax_exit_kernel_user
9517+#ifdef CONFIG_PAX_MEMORY_UDEREF
9518+ call pax_exit_kernel_user
9519+#endif
9520+#ifdef CONFIG_PAX_RANDKSTACK
9521+ pushq %rax
9522+ pushq %r11
9523+ call pax_randomize_kstack
9524+ popq %r11
9525+ popq %rax
9526+#endif
9527+ .endm
9528+
9529+.macro pax_erase_kstack
9530+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
9531+ call pax_erase_kstack
9532+#endif
9533+.endm
9534+
9535 /*
9536 * 32bit SYSENTER instruction entry.
9537 *
9538@@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
9539 CFI_REGISTER rsp,rbp
9540 SWAPGS_UNSAFE_STACK
9541 movq PER_CPU_VAR(kernel_stack), %rsp
9542- addq $(KERNEL_STACK_OFFSET),%rsp
9543- /*
9544- * No need to follow this irqs on/off section: the syscall
9545- * disabled irqs, here we enable it straight after entry:
9546- */
9547- ENABLE_INTERRUPTS(CLBR_NONE)
9548 movl %ebp,%ebp /* zero extension */
9549 pushq_cfi $__USER32_DS
9550 /*CFI_REL_OFFSET ss,0*/
9551@@ -135,24 +157,44 @@ ENTRY(ia32_sysenter_target)
9552 CFI_REL_OFFSET rsp,0
9553 pushfq_cfi
9554 /*CFI_REL_OFFSET rflags,0*/
9555- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
9556- CFI_REGISTER rip,r10
9557+ orl $X86_EFLAGS_IF,(%rsp)
9558+ GET_THREAD_INFO(%r11)
9559+ movl TI_sysenter_return(%r11), %r11d
9560+ CFI_REGISTER rip,r11
9561 pushq_cfi $__USER32_CS
9562 /*CFI_REL_OFFSET cs,0*/
9563 movl %eax, %eax
9564- pushq_cfi %r10
9565+ pushq_cfi %r11
9566 CFI_REL_OFFSET rip,0
9567 pushq_cfi %rax
9568 cld
9569 SAVE_ARGS 0,1,0
9570+ pax_enter_kernel_user
9571+
9572+#ifdef CONFIG_PAX_RANDKSTACK
9573+ pax_erase_kstack
9574+#endif
9575+
9576+ /*
9577+ * No need to follow this irqs on/off section: the syscall
9578+ * disabled irqs, here we enable it straight after entry:
9579+ */
9580+ ENABLE_INTERRUPTS(CLBR_NONE)
9581 /* no need to do an access_ok check here because rbp has been
9582 32bit zero extended */
9583+
9584+#ifdef CONFIG_PAX_MEMORY_UDEREF
9585+ mov $PAX_USER_SHADOW_BASE,%r11
9586+ add %r11,%rbp
9587+#endif
9588+
9589 ASM_STAC
9590 1: movl (%rbp),%ebp
9591 _ASM_EXTABLE(1b,ia32_badarg)
9592 ASM_CLAC
9593- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9594- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9595+ GET_THREAD_INFO(%r11)
9596+ orl $TS_COMPAT,TI_status(%r11)
9597+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
9598 CFI_REMEMBER_STATE
9599 jnz sysenter_tracesys
9600 cmpq $(IA32_NR_syscalls-1),%rax
9601@@ -162,12 +204,15 @@ sysenter_do_call:
9602 sysenter_dispatch:
9603 call *ia32_sys_call_table(,%rax,8)
9604 movq %rax,RAX-ARGOFFSET(%rsp)
9605+ GET_THREAD_INFO(%r11)
9606 DISABLE_INTERRUPTS(CLBR_NONE)
9607 TRACE_IRQS_OFF
9608- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9609+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
9610 jnz sysexit_audit
9611 sysexit_from_sys_call:
9612- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9613+ pax_exit_kernel_user
9614+ pax_erase_kstack
9615+ andl $~TS_COMPAT,TI_status(%r11)
9616 /* clear IF, that popfq doesn't enable interrupts early */
9617 andl $~0x200,EFLAGS-R11(%rsp)
9618 movl RIP-R11(%rsp),%edx /* User %eip */
9619@@ -193,6 +238,9 @@ sysexit_from_sys_call:
9620 movl %eax,%esi /* 2nd arg: syscall number */
9621 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
9622 call __audit_syscall_entry
9623+
9624+ pax_erase_kstack
9625+
9626 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
9627 cmpq $(IA32_NR_syscalls-1),%rax
9628 ja ia32_badsys
9629@@ -204,7 +252,7 @@ sysexit_from_sys_call:
9630 .endm
9631
9632 .macro auditsys_exit exit
9633- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9634+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
9635 jnz ia32_ret_from_sys_call
9636 TRACE_IRQS_ON
9637 sti
9638@@ -215,11 +263,12 @@ sysexit_from_sys_call:
9639 1: setbe %al /* 1 if error, 0 if not */
9640 movzbl %al,%edi /* zero-extend that into %edi */
9641 call __audit_syscall_exit
9642+ GET_THREAD_INFO(%r11)
9643 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
9644 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
9645 cli
9646 TRACE_IRQS_OFF
9647- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9648+ testl %edi,TI_flags(%r11)
9649 jz \exit
9650 CLEAR_RREGS -ARGOFFSET
9651 jmp int_with_check
9652@@ -237,7 +286,7 @@ sysexit_audit:
9653
9654 sysenter_tracesys:
9655 #ifdef CONFIG_AUDITSYSCALL
9656- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9657+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
9658 jz sysenter_auditsys
9659 #endif
9660 SAVE_REST
9661@@ -249,6 +298,9 @@ sysenter_tracesys:
9662 RESTORE_REST
9663 cmpq $(IA32_NR_syscalls-1),%rax
9664 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
9665+
9666+ pax_erase_kstack
9667+
9668 jmp sysenter_do_call
9669 CFI_ENDPROC
9670 ENDPROC(ia32_sysenter_target)
9671@@ -276,19 +328,25 @@ ENDPROC(ia32_sysenter_target)
9672 ENTRY(ia32_cstar_target)
9673 CFI_STARTPROC32 simple
9674 CFI_SIGNAL_FRAME
9675- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
9676+ CFI_DEF_CFA rsp,0
9677 CFI_REGISTER rip,rcx
9678 /*CFI_REGISTER rflags,r11*/
9679 SWAPGS_UNSAFE_STACK
9680 movl %esp,%r8d
9681 CFI_REGISTER rsp,r8
9682 movq PER_CPU_VAR(kernel_stack),%rsp
9683+ SAVE_ARGS 8*6,0,0
9684+ pax_enter_kernel_user
9685+
9686+#ifdef CONFIG_PAX_RANDKSTACK
9687+ pax_erase_kstack
9688+#endif
9689+
9690 /*
9691 * No need to follow this irqs on/off section: the syscall
9692 * disabled irqs and here we enable it straight after entry:
9693 */
9694 ENABLE_INTERRUPTS(CLBR_NONE)
9695- SAVE_ARGS 8,0,0
9696 movl %eax,%eax /* zero extension */
9697 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
9698 movq %rcx,RIP-ARGOFFSET(%rsp)
9699@@ -304,12 +362,19 @@ ENTRY(ia32_cstar_target)
9700 /* no need to do an access_ok check here because r8 has been
9701 32bit zero extended */
9702 /* hardware stack frame is complete now */
9703+
9704+#ifdef CONFIG_PAX_MEMORY_UDEREF
9705+ mov $PAX_USER_SHADOW_BASE,%r11
9706+ add %r11,%r8
9707+#endif
9708+
9709 ASM_STAC
9710 1: movl (%r8),%r9d
9711 _ASM_EXTABLE(1b,ia32_badarg)
9712 ASM_CLAC
9713- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9714- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9715+ GET_THREAD_INFO(%r11)
9716+ orl $TS_COMPAT,TI_status(%r11)
9717+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
9718 CFI_REMEMBER_STATE
9719 jnz cstar_tracesys
9720 cmpq $IA32_NR_syscalls-1,%rax
9721@@ -319,12 +384,15 @@ cstar_do_call:
9722 cstar_dispatch:
9723 call *ia32_sys_call_table(,%rax,8)
9724 movq %rax,RAX-ARGOFFSET(%rsp)
9725+ GET_THREAD_INFO(%r11)
9726 DISABLE_INTERRUPTS(CLBR_NONE)
9727 TRACE_IRQS_OFF
9728- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9729+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
9730 jnz sysretl_audit
9731 sysretl_from_sys_call:
9732- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9733+ pax_exit_kernel_user
9734+ pax_erase_kstack
9735+ andl $~TS_COMPAT,TI_status(%r11)
9736 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
9737 movl RIP-ARGOFFSET(%rsp),%ecx
9738 CFI_REGISTER rip,rcx
9739@@ -352,7 +420,7 @@ sysretl_audit:
9740
9741 cstar_tracesys:
9742 #ifdef CONFIG_AUDITSYSCALL
9743- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9744+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
9745 jz cstar_auditsys
9746 #endif
9747 xchgl %r9d,%ebp
9748@@ -366,6 +434,9 @@ cstar_tracesys:
9749 xchgl %ebp,%r9d
9750 cmpq $(IA32_NR_syscalls-1),%rax
9751 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
9752+
9753+ pax_erase_kstack
9754+
9755 jmp cstar_do_call
9756 END(ia32_cstar_target)
9757
9758@@ -407,19 +478,26 @@ ENTRY(ia32_syscall)
9759 CFI_REL_OFFSET rip,RIP-RIP
9760 PARAVIRT_ADJUST_EXCEPTION_FRAME
9761 SWAPGS
9762- /*
9763- * No need to follow this irqs on/off section: the syscall
9764- * disabled irqs and here we enable it straight after entry:
9765- */
9766- ENABLE_INTERRUPTS(CLBR_NONE)
9767 movl %eax,%eax
9768 pushq_cfi %rax
9769 cld
9770 /* note the registers are not zero extended to the sf.
9771 this could be a problem. */
9772 SAVE_ARGS 0,1,0
9773- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9774- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9775+ pax_enter_kernel_user
9776+
9777+#ifdef CONFIG_PAX_RANDKSTACK
9778+ pax_erase_kstack
9779+#endif
9780+
9781+ /*
9782+ * No need to follow this irqs on/off section: the syscall
9783+ * disabled irqs and here we enable it straight after entry:
9784+ */
9785+ ENABLE_INTERRUPTS(CLBR_NONE)
9786+ GET_THREAD_INFO(%r11)
9787+ orl $TS_COMPAT,TI_status(%r11)
9788+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
9789 jnz ia32_tracesys
9790 cmpq $(IA32_NR_syscalls-1),%rax
9791 ja ia32_badsys
9792@@ -442,6 +520,9 @@ ia32_tracesys:
9793 RESTORE_REST
9794 cmpq $(IA32_NR_syscalls-1),%rax
9795 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
9796+
9797+ pax_erase_kstack
9798+
9799 jmp ia32_do_call
9800 END(ia32_syscall)
9801
9802diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
9803index 86d68d1..f9960fe 100644
9804--- a/arch/x86/ia32/sys_ia32.c
9805+++ b/arch/x86/ia32/sys_ia32.c
9806@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
9807 */
9808 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
9809 {
9810- typeof(ubuf->st_uid) uid = 0;
9811- typeof(ubuf->st_gid) gid = 0;
9812+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
9813+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
9814 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
9815 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
9816 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
9817@@ -303,7 +303,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
9818 mm_segment_t old_fs = get_fs();
9819
9820 set_fs(KERNEL_DS);
9821- ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
9822+ ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
9823 set_fs(old_fs);
9824 if (put_compat_timespec(&t, interval))
9825 return -EFAULT;
9826@@ -319,7 +319,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
9827 mm_segment_t old_fs = get_fs();
9828
9829 set_fs(KERNEL_DS);
9830- ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
9831+ ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
9832 set_fs(old_fs);
9833 if (!ret) {
9834 switch (_NSIG_WORDS) {
9835@@ -344,7 +344,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
9836 if (copy_siginfo_from_user32(&info, uinfo))
9837 return -EFAULT;
9838 set_fs(KERNEL_DS);
9839- ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
9840+ ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
9841 set_fs(old_fs);
9842 return ret;
9843 }
9844@@ -376,7 +376,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
9845 return -EFAULT;
9846
9847 set_fs(KERNEL_DS);
9848- ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
9849+ ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
9850 count);
9851 set_fs(old_fs);
9852
9853diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
9854index 372231c..a5aa1a1 100644
9855--- a/arch/x86/include/asm/alternative-asm.h
9856+++ b/arch/x86/include/asm/alternative-asm.h
9857@@ -18,6 +18,45 @@
9858 .endm
9859 #endif
9860
9861+#ifdef KERNEXEC_PLUGIN
9862+ .macro pax_force_retaddr_bts rip=0
9863+ btsq $63,\rip(%rsp)
9864+ .endm
9865+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
9866+ .macro pax_force_retaddr rip=0, reload=0
9867+ btsq $63,\rip(%rsp)
9868+ .endm
9869+ .macro pax_force_fptr ptr
9870+ btsq $63,\ptr
9871+ .endm
9872+ .macro pax_set_fptr_mask
9873+ .endm
9874+#endif
9875+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
9876+ .macro pax_force_retaddr rip=0, reload=0
9877+ .if \reload
9878+ pax_set_fptr_mask
9879+ .endif
9880+ orq %r10,\rip(%rsp)
9881+ .endm
9882+ .macro pax_force_fptr ptr
9883+ orq %r10,\ptr
9884+ .endm
9885+ .macro pax_set_fptr_mask
9886+ movabs $0x8000000000000000,%r10
9887+ .endm
9888+#endif
9889+#else
9890+ .macro pax_force_retaddr rip=0, reload=0
9891+ .endm
9892+ .macro pax_force_fptr ptr
9893+ .endm
9894+ .macro pax_force_retaddr_bts rip=0
9895+ .endm
9896+ .macro pax_set_fptr_mask
9897+ .endm
9898+#endif
9899+
9900 .macro altinstruction_entry orig alt feature orig_len alt_len
9901 .long \orig - .
9902 .long \alt - .
9903diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
9904index 58ed6d9..f1cbe58 100644
9905--- a/arch/x86/include/asm/alternative.h
9906+++ b/arch/x86/include/asm/alternative.h
9907@@ -105,7 +105,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
9908 ".pushsection .discard,\"aw\",@progbits\n" \
9909 DISCARD_ENTRY(1) \
9910 ".popsection\n" \
9911- ".pushsection .altinstr_replacement, \"ax\"\n" \
9912+ ".pushsection .altinstr_replacement, \"a\"\n" \
9913 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
9914 ".popsection"
9915
9916@@ -119,7 +119,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
9917 DISCARD_ENTRY(1) \
9918 DISCARD_ENTRY(2) \
9919 ".popsection\n" \
9920- ".pushsection .altinstr_replacement, \"ax\"\n" \
9921+ ".pushsection .altinstr_replacement, \"a\"\n" \
9922 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
9923 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
9924 ".popsection"
9925diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
9926index 3388034..ba52312 100644
9927--- a/arch/x86/include/asm/apic.h
9928+++ b/arch/x86/include/asm/apic.h
9929@@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
9930
9931 #ifdef CONFIG_X86_LOCAL_APIC
9932
9933-extern unsigned int apic_verbosity;
9934+extern int apic_verbosity;
9935 extern int local_apic_timer_c2_ok;
9936
9937 extern int disable_apic;
9938@@ -391,7 +391,7 @@ struct apic {
9939 */
9940 int (*x86_32_numa_cpu_node)(int cpu);
9941 #endif
9942-};
9943+} __do_const;
9944
9945 /*
9946 * Pointer to the local APIC driver in use on this system (there's
9947diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
9948index 20370c6..a2eb9b0 100644
9949--- a/arch/x86/include/asm/apm.h
9950+++ b/arch/x86/include/asm/apm.h
9951@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
9952 __asm__ __volatile__(APM_DO_ZERO_SEGS
9953 "pushl %%edi\n\t"
9954 "pushl %%ebp\n\t"
9955- "lcall *%%cs:apm_bios_entry\n\t"
9956+ "lcall *%%ss:apm_bios_entry\n\t"
9957 "setc %%al\n\t"
9958 "popl %%ebp\n\t"
9959 "popl %%edi\n\t"
9960@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
9961 __asm__ __volatile__(APM_DO_ZERO_SEGS
9962 "pushl %%edi\n\t"
9963 "pushl %%ebp\n\t"
9964- "lcall *%%cs:apm_bios_entry\n\t"
9965+ "lcall *%%ss:apm_bios_entry\n\t"
9966 "setc %%bl\n\t"
9967 "popl %%ebp\n\t"
9968 "popl %%edi\n\t"
9969diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
9970index b6c3b82..b4c077a 100644
9971--- a/arch/x86/include/asm/atomic.h
9972+++ b/arch/x86/include/asm/atomic.h
9973@@ -22,7 +22,18 @@
9974 */
9975 static inline int atomic_read(const atomic_t *v)
9976 {
9977- return (*(volatile int *)&(v)->counter);
9978+ return (*(volatile const int *)&(v)->counter);
9979+}
9980+
9981+/**
9982+ * atomic_read_unchecked - read atomic variable
9983+ * @v: pointer of type atomic_unchecked_t
9984+ *
9985+ * Atomically reads the value of @v.
9986+ */
9987+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9988+{
9989+ return (*(volatile const int *)&(v)->counter);
9990 }
9991
9992 /**
9993@@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
9994 }
9995
9996 /**
9997+ * atomic_set_unchecked - set atomic variable
9998+ * @v: pointer of type atomic_unchecked_t
9999+ * @i: required value
10000+ *
10001+ * Atomically sets the value of @v to @i.
10002+ */
10003+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
10004+{
10005+ v->counter = i;
10006+}
10007+
10008+/**
10009 * atomic_add - add integer to atomic variable
10010 * @i: integer value to add
10011 * @v: pointer of type atomic_t
10012@@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
10013 */
10014 static inline void atomic_add(int i, atomic_t *v)
10015 {
10016- asm volatile(LOCK_PREFIX "addl %1,%0"
10017+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
10018+
10019+#ifdef CONFIG_PAX_REFCOUNT
10020+ "jno 0f\n"
10021+ LOCK_PREFIX "subl %1,%0\n"
10022+ "int $4\n0:\n"
10023+ _ASM_EXTABLE(0b, 0b)
10024+#endif
10025+
10026+ : "+m" (v->counter)
10027+ : "ir" (i));
10028+}
10029+
10030+/**
10031+ * atomic_add_unchecked - add integer to atomic variable
10032+ * @i: integer value to add
10033+ * @v: pointer of type atomic_unchecked_t
10034+ *
10035+ * Atomically adds @i to @v.
10036+ */
10037+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
10038+{
10039+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
10040 : "+m" (v->counter)
10041 : "ir" (i));
10042 }
10043@@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
10044 */
10045 static inline void atomic_sub(int i, atomic_t *v)
10046 {
10047- asm volatile(LOCK_PREFIX "subl %1,%0"
10048+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
10049+
10050+#ifdef CONFIG_PAX_REFCOUNT
10051+ "jno 0f\n"
10052+ LOCK_PREFIX "addl %1,%0\n"
10053+ "int $4\n0:\n"
10054+ _ASM_EXTABLE(0b, 0b)
10055+#endif
10056+
10057+ : "+m" (v->counter)
10058+ : "ir" (i));
10059+}
10060+
10061+/**
10062+ * atomic_sub_unchecked - subtract integer from atomic variable
10063+ * @i: integer value to subtract
10064+ * @v: pointer of type atomic_unchecked_t
10065+ *
10066+ * Atomically subtracts @i from @v.
10067+ */
10068+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
10069+{
10070+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
10071 : "+m" (v->counter)
10072 : "ir" (i));
10073 }
10074@@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
10075 {
10076 unsigned char c;
10077
10078- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
10079+ asm volatile(LOCK_PREFIX "subl %2,%0\n"
10080+
10081+#ifdef CONFIG_PAX_REFCOUNT
10082+ "jno 0f\n"
10083+ LOCK_PREFIX "addl %2,%0\n"
10084+ "int $4\n0:\n"
10085+ _ASM_EXTABLE(0b, 0b)
10086+#endif
10087+
10088+ "sete %1\n"
10089 : "+m" (v->counter), "=qm" (c)
10090 : "ir" (i) : "memory");
10091 return c;
10092@@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
10093 */
10094 static inline void atomic_inc(atomic_t *v)
10095 {
10096- asm volatile(LOCK_PREFIX "incl %0"
10097+ asm volatile(LOCK_PREFIX "incl %0\n"
10098+
10099+#ifdef CONFIG_PAX_REFCOUNT
10100+ "jno 0f\n"
10101+ LOCK_PREFIX "decl %0\n"
10102+ "int $4\n0:\n"
10103+ _ASM_EXTABLE(0b, 0b)
10104+#endif
10105+
10106+ : "+m" (v->counter));
10107+}
10108+
10109+/**
10110+ * atomic_inc_unchecked - increment atomic variable
10111+ * @v: pointer of type atomic_unchecked_t
10112+ *
10113+ * Atomically increments @v by 1.
10114+ */
10115+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
10116+{
10117+ asm volatile(LOCK_PREFIX "incl %0\n"
10118 : "+m" (v->counter));
10119 }
10120
10121@@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
10122 */
10123 static inline void atomic_dec(atomic_t *v)
10124 {
10125- asm volatile(LOCK_PREFIX "decl %0"
10126+ asm volatile(LOCK_PREFIX "decl %0\n"
10127+
10128+#ifdef CONFIG_PAX_REFCOUNT
10129+ "jno 0f\n"
10130+ LOCK_PREFIX "incl %0\n"
10131+ "int $4\n0:\n"
10132+ _ASM_EXTABLE(0b, 0b)
10133+#endif
10134+
10135+ : "+m" (v->counter));
10136+}
10137+
10138+/**
10139+ * atomic_dec_unchecked - decrement atomic variable
10140+ * @v: pointer of type atomic_unchecked_t
10141+ *
10142+ * Atomically decrements @v by 1.
10143+ */
10144+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
10145+{
10146+ asm volatile(LOCK_PREFIX "decl %0\n"
10147 : "+m" (v->counter));
10148 }
10149
10150@@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
10151 {
10152 unsigned char c;
10153
10154- asm volatile(LOCK_PREFIX "decl %0; sete %1"
10155+ asm volatile(LOCK_PREFIX "decl %0\n"
10156+
10157+#ifdef CONFIG_PAX_REFCOUNT
10158+ "jno 0f\n"
10159+ LOCK_PREFIX "incl %0\n"
10160+ "int $4\n0:\n"
10161+ _ASM_EXTABLE(0b, 0b)
10162+#endif
10163+
10164+ "sete %1\n"
10165 : "+m" (v->counter), "=qm" (c)
10166 : : "memory");
10167 return c != 0;
10168@@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
10169 {
10170 unsigned char c;
10171
10172- asm volatile(LOCK_PREFIX "incl %0; sete %1"
10173+ asm volatile(LOCK_PREFIX "incl %0\n"
10174+
10175+#ifdef CONFIG_PAX_REFCOUNT
10176+ "jno 0f\n"
10177+ LOCK_PREFIX "decl %0\n"
10178+ "int $4\n0:\n"
10179+ _ASM_EXTABLE(0b, 0b)
10180+#endif
10181+
10182+ "sete %1\n"
10183+ : "+m" (v->counter), "=qm" (c)
10184+ : : "memory");
10185+ return c != 0;
10186+}
10187+
10188+/**
10189+ * atomic_inc_and_test_unchecked - increment and test
10190+ * @v: pointer of type atomic_unchecked_t
10191+ *
10192+ * Atomically increments @v by 1
10193+ * and returns true if the result is zero, or false for all
10194+ * other cases.
10195+ */
10196+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
10197+{
10198+ unsigned char c;
10199+
10200+ asm volatile(LOCK_PREFIX "incl %0\n"
10201+ "sete %1\n"
10202 : "+m" (v->counter), "=qm" (c)
10203 : : "memory");
10204 return c != 0;
10205@@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
10206 {
10207 unsigned char c;
10208
10209- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
10210+ asm volatile(LOCK_PREFIX "addl %2,%0\n"
10211+
10212+#ifdef CONFIG_PAX_REFCOUNT
10213+ "jno 0f\n"
10214+ LOCK_PREFIX "subl %2,%0\n"
10215+ "int $4\n0:\n"
10216+ _ASM_EXTABLE(0b, 0b)
10217+#endif
10218+
10219+ "sets %1\n"
10220 : "+m" (v->counter), "=qm" (c)
10221 : "ir" (i) : "memory");
10222 return c;
10223@@ -179,7 +341,7 @@ static inline int atomic_add_return(int i, atomic_t *v)
10224 goto no_xadd;
10225 #endif
10226 /* Modern 486+ processor */
10227- return i + xadd(&v->counter, i);
10228+ return i + xadd_check_overflow(&v->counter, i);
10229
10230 #ifdef CONFIG_M386
10231 no_xadd: /* Legacy 386 processor */
10232@@ -192,6 +354,34 @@ no_xadd: /* Legacy 386 processor */
10233 }
10234
10235 /**
10236+ * atomic_add_return_unchecked - add integer and return
10237+ * @i: integer value to add
10238+ * @v: pointer of type atomic_unchecked_t
10239+ *
10240+ * Atomically adds @i to @v and returns @i + @v
10241+ */
10242+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
10243+{
10244+#ifdef CONFIG_M386
10245+ int __i;
10246+ unsigned long flags;
10247+ if (unlikely(boot_cpu_data.x86 <= 3))
10248+ goto no_xadd;
10249+#endif
10250+ /* Modern 486+ processor */
10251+ return i + xadd(&v->counter, i);
10252+
10253+#ifdef CONFIG_M386
10254+no_xadd: /* Legacy 386 processor */
10255+ raw_local_irq_save(flags);
10256+ __i = atomic_read_unchecked(v);
10257+ atomic_set_unchecked(v, i + __i);
10258+ raw_local_irq_restore(flags);
10259+ return i + __i;
10260+#endif
10261+}
10262+
10263+/**
10264 * atomic_sub_return - subtract integer and return
10265 * @v: pointer of type atomic_t
10266 * @i: integer value to subtract
10267@@ -204,6 +394,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
10268 }
10269
10270 #define atomic_inc_return(v) (atomic_add_return(1, v))
10271+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
10272+{
10273+ return atomic_add_return_unchecked(1, v);
10274+}
10275 #define atomic_dec_return(v) (atomic_sub_return(1, v))
10276
10277 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
10278@@ -211,11 +405,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
10279 return cmpxchg(&v->counter, old, new);
10280 }
10281
10282+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
10283+{
10284+ return cmpxchg(&v->counter, old, new);
10285+}
10286+
10287 static inline int atomic_xchg(atomic_t *v, int new)
10288 {
10289 return xchg(&v->counter, new);
10290 }
10291
10292+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
10293+{
10294+ return xchg(&v->counter, new);
10295+}
10296+
10297 /**
10298 * __atomic_add_unless - add unless the number is already a given value
10299 * @v: pointer of type atomic_t
10300@@ -227,12 +431,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
10301 */
10302 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
10303 {
10304- int c, old;
10305+ int c, old, new;
10306 c = atomic_read(v);
10307 for (;;) {
10308- if (unlikely(c == (u)))
10309+ if (unlikely(c == u))
10310 break;
10311- old = atomic_cmpxchg((v), c, c + (a));
10312+
10313+ asm volatile("addl %2,%0\n"
10314+
10315+#ifdef CONFIG_PAX_REFCOUNT
10316+ "jno 0f\n"
10317+ "subl %2,%0\n"
10318+ "int $4\n0:\n"
10319+ _ASM_EXTABLE(0b, 0b)
10320+#endif
10321+
10322+ : "=r" (new)
10323+ : "0" (c), "ir" (a));
10324+
10325+ old = atomic_cmpxchg(v, c, new);
10326 if (likely(old == c))
10327 break;
10328 c = old;
10329@@ -241,6 +458,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
10330 }
10331
10332 /**
10333+ * atomic_inc_not_zero_hint - increment if not null
10334+ * @v: pointer of type atomic_t
10335+ * @hint: probable value of the atomic before the increment
10336+ *
10337+ * This version of atomic_inc_not_zero() gives a hint of probable
10338+ * value of the atomic. This helps processor to not read the memory
10339+ * before doing the atomic read/modify/write cycle, lowering
10340+ * number of bus transactions on some arches.
10341+ *
10342+ * Returns: 0 if increment was not done, 1 otherwise.
10343+ */
10344+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
10345+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
10346+{
10347+ int val, c = hint, new;
10348+
10349+ /* sanity test, should be removed by compiler if hint is a constant */
10350+ if (!hint)
10351+ return __atomic_add_unless(v, 1, 0);
10352+
10353+ do {
10354+ asm volatile("incl %0\n"
10355+
10356+#ifdef CONFIG_PAX_REFCOUNT
10357+ "jno 0f\n"
10358+ "decl %0\n"
10359+ "int $4\n0:\n"
10360+ _ASM_EXTABLE(0b, 0b)
10361+#endif
10362+
10363+ : "=r" (new)
10364+ : "0" (c));
10365+
10366+ val = atomic_cmpxchg(v, c, new);
10367+ if (val == c)
10368+ return 1;
10369+ c = val;
10370+ } while (c);
10371+
10372+ return 0;
10373+}
10374+
10375+/**
10376 * atomic_inc_short - increment of a short integer
10377 * @v: pointer to type int
10378 *
10379@@ -269,14 +529,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
10380 #endif
10381
10382 /* These are x86-specific, used by some header files */
10383-#define atomic_clear_mask(mask, addr) \
10384- asm volatile(LOCK_PREFIX "andl %0,%1" \
10385- : : "r" (~(mask)), "m" (*(addr)) : "memory")
10386+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
10387+{
10388+ asm volatile(LOCK_PREFIX "andl %1,%0"
10389+ : "+m" (v->counter)
10390+ : "r" (~(mask))
10391+ : "memory");
10392+}
10393
10394-#define atomic_set_mask(mask, addr) \
10395- asm volatile(LOCK_PREFIX "orl %0,%1" \
10396- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
10397- : "memory")
10398+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
10399+{
10400+ asm volatile(LOCK_PREFIX "andl %1,%0"
10401+ : "+m" (v->counter)
10402+ : "r" (~(mask))
10403+ : "memory");
10404+}
10405+
10406+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
10407+{
10408+ asm volatile(LOCK_PREFIX "orl %1,%0"
10409+ : "+m" (v->counter)
10410+ : "r" (mask)
10411+ : "memory");
10412+}
10413+
10414+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
10415+{
10416+ asm volatile(LOCK_PREFIX "orl %1,%0"
10417+ : "+m" (v->counter)
10418+ : "r" (mask)
10419+ : "memory");
10420+}
10421
10422 /* Atomic operations are already serializing on x86 */
10423 #define smp_mb__before_atomic_dec() barrier()
10424diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
10425index b154de7..aadebd8 100644
10426--- a/arch/x86/include/asm/atomic64_32.h
10427+++ b/arch/x86/include/asm/atomic64_32.h
10428@@ -12,6 +12,14 @@ typedef struct {
10429 u64 __aligned(8) counter;
10430 } atomic64_t;
10431
10432+#ifdef CONFIG_PAX_REFCOUNT
10433+typedef struct {
10434+ u64 __aligned(8) counter;
10435+} atomic64_unchecked_t;
10436+#else
10437+typedef atomic64_t atomic64_unchecked_t;
10438+#endif
10439+
10440 #define ATOMIC64_INIT(val) { (val) }
10441
10442 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
10443@@ -37,21 +45,31 @@ typedef struct {
10444 ATOMIC64_DECL_ONE(sym##_386)
10445
10446 ATOMIC64_DECL_ONE(add_386);
10447+ATOMIC64_DECL_ONE(add_unchecked_386);
10448 ATOMIC64_DECL_ONE(sub_386);
10449+ATOMIC64_DECL_ONE(sub_unchecked_386);
10450 ATOMIC64_DECL_ONE(inc_386);
10451+ATOMIC64_DECL_ONE(inc_unchecked_386);
10452 ATOMIC64_DECL_ONE(dec_386);
10453+ATOMIC64_DECL_ONE(dec_unchecked_386);
10454 #endif
10455
10456 #define alternative_atomic64(f, out, in...) \
10457 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
10458
10459 ATOMIC64_DECL(read);
10460+ATOMIC64_DECL(read_unchecked);
10461 ATOMIC64_DECL(set);
10462+ATOMIC64_DECL(set_unchecked);
10463 ATOMIC64_DECL(xchg);
10464 ATOMIC64_DECL(add_return);
10465+ATOMIC64_DECL(add_return_unchecked);
10466 ATOMIC64_DECL(sub_return);
10467+ATOMIC64_DECL(sub_return_unchecked);
10468 ATOMIC64_DECL(inc_return);
10469+ATOMIC64_DECL(inc_return_unchecked);
10470 ATOMIC64_DECL(dec_return);
10471+ATOMIC64_DECL(dec_return_unchecked);
10472 ATOMIC64_DECL(dec_if_positive);
10473 ATOMIC64_DECL(inc_not_zero);
10474 ATOMIC64_DECL(add_unless);
10475@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
10476 }
10477
10478 /**
10479+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
10480+ * @p: pointer to type atomic64_unchecked_t
10481+ * @o: expected value
10482+ * @n: new value
10483+ *
10484+ * Atomically sets @v to @n if it was equal to @o and returns
10485+ * the old value.
10486+ */
10487+
10488+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
10489+{
10490+ return cmpxchg64(&v->counter, o, n);
10491+}
10492+
10493+/**
10494 * atomic64_xchg - xchg atomic64 variable
10495 * @v: pointer to type atomic64_t
10496 * @n: value to assign
10497@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
10498 }
10499
10500 /**
10501+ * atomic64_set_unchecked - set atomic64 variable
10502+ * @v: pointer to type atomic64_unchecked_t
10503+ * @n: value to assign
10504+ *
10505+ * Atomically sets the value of @v to @n.
10506+ */
10507+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
10508+{
10509+ unsigned high = (unsigned)(i >> 32);
10510+ unsigned low = (unsigned)i;
10511+ alternative_atomic64(set, /* no output */,
10512+ "S" (v), "b" (low), "c" (high)
10513+ : "eax", "edx", "memory");
10514+}
10515+
10516+/**
10517 * atomic64_read - read atomic64 variable
10518 * @v: pointer to type atomic64_t
10519 *
10520@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
10521 }
10522
10523 /**
10524+ * atomic64_read_unchecked - read atomic64 variable
10525+ * @v: pointer to type atomic64_unchecked_t
10526+ *
10527+ * Atomically reads the value of @v and returns it.
10528+ */
10529+static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
10530+{
10531+ long long r;
10532+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
10533+ return r;
10534+ }
10535+
10536+/**
10537 * atomic64_add_return - add and return
10538 * @i: integer value to add
10539 * @v: pointer to type atomic64_t
10540@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
10541 return i;
10542 }
10543
10544+/**
10545+ * atomic64_add_return_unchecked - add and return
10546+ * @i: integer value to add
10547+ * @v: pointer to type atomic64_unchecked_t
10548+ *
10549+ * Atomically adds @i to @v and returns @i + *@v
10550+ */
10551+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
10552+{
10553+ alternative_atomic64(add_return_unchecked,
10554+ ASM_OUTPUT2("+A" (i), "+c" (v)),
10555+ ASM_NO_INPUT_CLOBBER("memory"));
10556+ return i;
10557+}
10558+
10559 /*
10560 * Other variants with different arithmetic operators:
10561 */
10562@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
10563 return a;
10564 }
10565
10566+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
10567+{
10568+ long long a;
10569+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
10570+ "S" (v) : "memory", "ecx");
10571+ return a;
10572+}
10573+
10574 static inline long long atomic64_dec_return(atomic64_t *v)
10575 {
10576 long long a;
10577@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
10578 }
10579
10580 /**
10581+ * atomic64_add_unchecked - add integer to atomic64 variable
10582+ * @i: integer value to add
10583+ * @v: pointer to type atomic64_unchecked_t
10584+ *
10585+ * Atomically adds @i to @v.
10586+ */
10587+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
10588+{
10589+ __alternative_atomic64(add_unchecked, add_return_unchecked,
10590+ ASM_OUTPUT2("+A" (i), "+c" (v)),
10591+ ASM_NO_INPUT_CLOBBER("memory"));
10592+ return i;
10593+}
10594+
10595+/**
10596 * atomic64_sub - subtract the atomic64 variable
10597 * @i: integer value to subtract
10598 * @v: pointer to type atomic64_t
10599diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
10600index 0e1cbfc..5623683 100644
10601--- a/arch/x86/include/asm/atomic64_64.h
10602+++ b/arch/x86/include/asm/atomic64_64.h
10603@@ -18,7 +18,19 @@
10604 */
10605 static inline long atomic64_read(const atomic64_t *v)
10606 {
10607- return (*(volatile long *)&(v)->counter);
10608+ return (*(volatile const long *)&(v)->counter);
10609+}
10610+
10611+/**
10612+ * atomic64_read_unchecked - read atomic64 variable
10613+ * @v: pointer of type atomic64_unchecked_t
10614+ *
10615+ * Atomically reads the value of @v.
10616+ * Doesn't imply a read memory barrier.
10617+ */
10618+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
10619+{
10620+ return (*(volatile const long *)&(v)->counter);
10621 }
10622
10623 /**
10624@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
10625 }
10626
10627 /**
10628+ * atomic64_set_unchecked - set atomic64 variable
10629+ * @v: pointer to type atomic64_unchecked_t
10630+ * @i: required value
10631+ *
10632+ * Atomically sets the value of @v to @i.
10633+ */
10634+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
10635+{
10636+ v->counter = i;
10637+}
10638+
10639+/**
10640 * atomic64_add - add integer to atomic64 variable
10641 * @i: integer value to add
10642 * @v: pointer to type atomic64_t
10643@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
10644 */
10645 static inline void atomic64_add(long i, atomic64_t *v)
10646 {
10647+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
10648+
10649+#ifdef CONFIG_PAX_REFCOUNT
10650+ "jno 0f\n"
10651+ LOCK_PREFIX "subq %1,%0\n"
10652+ "int $4\n0:\n"
10653+ _ASM_EXTABLE(0b, 0b)
10654+#endif
10655+
10656+ : "=m" (v->counter)
10657+ : "er" (i), "m" (v->counter));
10658+}
10659+
10660+/**
10661+ * atomic64_add_unchecked - add integer to atomic64 variable
10662+ * @i: integer value to add
10663+ * @v: pointer to type atomic64_unchecked_t
10664+ *
10665+ * Atomically adds @i to @v.
10666+ */
10667+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
10668+{
10669 asm volatile(LOCK_PREFIX "addq %1,%0"
10670 : "=m" (v->counter)
10671 : "er" (i), "m" (v->counter));
10672@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
10673 */
10674 static inline void atomic64_sub(long i, atomic64_t *v)
10675 {
10676- asm volatile(LOCK_PREFIX "subq %1,%0"
10677+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
10678+
10679+#ifdef CONFIG_PAX_REFCOUNT
10680+ "jno 0f\n"
10681+ LOCK_PREFIX "addq %1,%0\n"
10682+ "int $4\n0:\n"
10683+ _ASM_EXTABLE(0b, 0b)
10684+#endif
10685+
10686+ : "=m" (v->counter)
10687+ : "er" (i), "m" (v->counter));
10688+}
10689+
10690+/**
10691+ * atomic64_sub_unchecked - subtract the atomic64 variable
10692+ * @i: integer value to subtract
10693+ * @v: pointer to type atomic64_unchecked_t
10694+ *
10695+ * Atomically subtracts @i from @v.
10696+ */
10697+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
10698+{
10699+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
10700 : "=m" (v->counter)
10701 : "er" (i), "m" (v->counter));
10702 }
10703@@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
10704 {
10705 unsigned char c;
10706
10707- asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
10708+ asm volatile(LOCK_PREFIX "subq %2,%0\n"
10709+
10710+#ifdef CONFIG_PAX_REFCOUNT
10711+ "jno 0f\n"
10712+ LOCK_PREFIX "addq %2,%0\n"
10713+ "int $4\n0:\n"
10714+ _ASM_EXTABLE(0b, 0b)
10715+#endif
10716+
10717+ "sete %1\n"
10718 : "=m" (v->counter), "=qm" (c)
10719 : "er" (i), "m" (v->counter) : "memory");
10720 return c;
10721@@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
10722 */
10723 static inline void atomic64_inc(atomic64_t *v)
10724 {
10725+ asm volatile(LOCK_PREFIX "incq %0\n"
10726+
10727+#ifdef CONFIG_PAX_REFCOUNT
10728+ "jno 0f\n"
10729+ LOCK_PREFIX "decq %0\n"
10730+ "int $4\n0:\n"
10731+ _ASM_EXTABLE(0b, 0b)
10732+#endif
10733+
10734+ : "=m" (v->counter)
10735+ : "m" (v->counter));
10736+}
10737+
10738+/**
10739+ * atomic64_inc_unchecked - increment atomic64 variable
10740+ * @v: pointer to type atomic64_unchecked_t
10741+ *
10742+ * Atomically increments @v by 1.
10743+ */
10744+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
10745+{
10746 asm volatile(LOCK_PREFIX "incq %0"
10747 : "=m" (v->counter)
10748 : "m" (v->counter));
10749@@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
10750 */
10751 static inline void atomic64_dec(atomic64_t *v)
10752 {
10753- asm volatile(LOCK_PREFIX "decq %0"
10754+ asm volatile(LOCK_PREFIX "decq %0\n"
10755+
10756+#ifdef CONFIG_PAX_REFCOUNT
10757+ "jno 0f\n"
10758+ LOCK_PREFIX "incq %0\n"
10759+ "int $4\n0:\n"
10760+ _ASM_EXTABLE(0b, 0b)
10761+#endif
10762+
10763+ : "=m" (v->counter)
10764+ : "m" (v->counter));
10765+}
10766+
10767+/**
10768+ * atomic64_dec_unchecked - decrement atomic64 variable
10769+ * @v: pointer to type atomic64_t
10770+ *
10771+ * Atomically decrements @v by 1.
10772+ */
10773+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
10774+{
10775+ asm volatile(LOCK_PREFIX "decq %0\n"
10776 : "=m" (v->counter)
10777 : "m" (v->counter));
10778 }
10779@@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
10780 {
10781 unsigned char c;
10782
10783- asm volatile(LOCK_PREFIX "decq %0; sete %1"
10784+ asm volatile(LOCK_PREFIX "decq %0\n"
10785+
10786+#ifdef CONFIG_PAX_REFCOUNT
10787+ "jno 0f\n"
10788+ LOCK_PREFIX "incq %0\n"
10789+ "int $4\n0:\n"
10790+ _ASM_EXTABLE(0b, 0b)
10791+#endif
10792+
10793+ "sete %1\n"
10794 : "=m" (v->counter), "=qm" (c)
10795 : "m" (v->counter) : "memory");
10796 return c != 0;
10797@@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
10798 {
10799 unsigned char c;
10800
10801- asm volatile(LOCK_PREFIX "incq %0; sete %1"
10802+ asm volatile(LOCK_PREFIX "incq %0\n"
10803+
10804+#ifdef CONFIG_PAX_REFCOUNT
10805+ "jno 0f\n"
10806+ LOCK_PREFIX "decq %0\n"
10807+ "int $4\n0:\n"
10808+ _ASM_EXTABLE(0b, 0b)
10809+#endif
10810+
10811+ "sete %1\n"
10812 : "=m" (v->counter), "=qm" (c)
10813 : "m" (v->counter) : "memory");
10814 return c != 0;
10815@@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
10816 {
10817 unsigned char c;
10818
10819- asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
10820+ asm volatile(LOCK_PREFIX "addq %2,%0\n"
10821+
10822+#ifdef CONFIG_PAX_REFCOUNT
10823+ "jno 0f\n"
10824+ LOCK_PREFIX "subq %2,%0\n"
10825+ "int $4\n0:\n"
10826+ _ASM_EXTABLE(0b, 0b)
10827+#endif
10828+
10829+ "sets %1\n"
10830 : "=m" (v->counter), "=qm" (c)
10831 : "er" (i), "m" (v->counter) : "memory");
10832 return c;
10833@@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
10834 */
10835 static inline long atomic64_add_return(long i, atomic64_t *v)
10836 {
10837+ return i + xadd_check_overflow(&v->counter, i);
10838+}
10839+
10840+/**
10841+ * atomic64_add_return_unchecked - add and return
10842+ * @i: integer value to add
10843+ * @v: pointer to type atomic64_unchecked_t
10844+ *
10845+ * Atomically adds @i to @v and returns @i + @v
10846+ */
10847+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
10848+{
10849 return i + xadd(&v->counter, i);
10850 }
10851
10852@@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
10853 }
10854
10855 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
10856+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
10857+{
10858+ return atomic64_add_return_unchecked(1, v);
10859+}
10860 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
10861
10862 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
10863@@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
10864 return cmpxchg(&v->counter, old, new);
10865 }
10866
10867+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
10868+{
10869+ return cmpxchg(&v->counter, old, new);
10870+}
10871+
10872 static inline long atomic64_xchg(atomic64_t *v, long new)
10873 {
10874 return xchg(&v->counter, new);
10875@@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
10876 */
10877 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
10878 {
10879- long c, old;
10880+ long c, old, new;
10881 c = atomic64_read(v);
10882 for (;;) {
10883- if (unlikely(c == (u)))
10884+ if (unlikely(c == u))
10885 break;
10886- old = atomic64_cmpxchg((v), c, c + (a));
10887+
10888+ asm volatile("add %2,%0\n"
10889+
10890+#ifdef CONFIG_PAX_REFCOUNT
10891+ "jno 0f\n"
10892+ "sub %2,%0\n"
10893+ "int $4\n0:\n"
10894+ _ASM_EXTABLE(0b, 0b)
10895+#endif
10896+
10897+ : "=r" (new)
10898+ : "0" (c), "ir" (a));
10899+
10900+ old = atomic64_cmpxchg(v, c, new);
10901 if (likely(old == c))
10902 break;
10903 c = old;
10904 }
10905- return c != (u);
10906+ return c != u;
10907 }
10908
10909 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
10910diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
10911index 6dfd019..0c6699f 100644
10912--- a/arch/x86/include/asm/bitops.h
10913+++ b/arch/x86/include/asm/bitops.h
10914@@ -40,7 +40,7 @@
10915 * a mask operation on a byte.
10916 */
10917 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
10918-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
10919+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
10920 #define CONST_MASK(nr) (1 << ((nr) & 7))
10921
10922 /**
10923diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
10924index b13fe63..0dab13a 100644
10925--- a/arch/x86/include/asm/boot.h
10926+++ b/arch/x86/include/asm/boot.h
10927@@ -11,10 +11,15 @@
10928 #include <asm/pgtable_types.h>
10929
10930 /* Physical address where kernel should be loaded. */
10931-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10932+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10933 + (CONFIG_PHYSICAL_ALIGN - 1)) \
10934 & ~(CONFIG_PHYSICAL_ALIGN - 1))
10935
10936+#ifndef __ASSEMBLY__
10937+extern unsigned char __LOAD_PHYSICAL_ADDR[];
10938+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
10939+#endif
10940+
10941 /* Minimum kernel alignment, as a power of two */
10942 #ifdef CONFIG_X86_64
10943 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
10944diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
10945index 48f99f1..d78ebf9 100644
10946--- a/arch/x86/include/asm/cache.h
10947+++ b/arch/x86/include/asm/cache.h
10948@@ -5,12 +5,13 @@
10949
10950 /* L1 cache line size */
10951 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
10952-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10953+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10954
10955 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
10956+#define __read_only __attribute__((__section__(".data..read_only")))
10957
10958 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
10959-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
10960+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
10961
10962 #ifdef CONFIG_X86_VSMP
10963 #ifdef CONFIG_SMP
10964diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
10965index 9863ee3..4a1f8e1 100644
10966--- a/arch/x86/include/asm/cacheflush.h
10967+++ b/arch/x86/include/asm/cacheflush.h
10968@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
10969 unsigned long pg_flags = pg->flags & _PGMT_MASK;
10970
10971 if (pg_flags == _PGMT_DEFAULT)
10972- return -1;
10973+ return ~0UL;
10974 else if (pg_flags == _PGMT_WC)
10975 return _PAGE_CACHE_WC;
10976 else if (pg_flags == _PGMT_UC_MINUS)
10977diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
10978index 46fc474..b02b0f9 100644
10979--- a/arch/x86/include/asm/checksum_32.h
10980+++ b/arch/x86/include/asm/checksum_32.h
10981@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
10982 int len, __wsum sum,
10983 int *src_err_ptr, int *dst_err_ptr);
10984
10985+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
10986+ int len, __wsum sum,
10987+ int *src_err_ptr, int *dst_err_ptr);
10988+
10989+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
10990+ int len, __wsum sum,
10991+ int *src_err_ptr, int *dst_err_ptr);
10992+
10993 /*
10994 * Note: when you get a NULL pointer exception here this means someone
10995 * passed in an incorrect kernel address to one of these functions.
10996@@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
10997 int *err_ptr)
10998 {
10999 might_sleep();
11000- return csum_partial_copy_generic((__force void *)src, dst,
11001+ return csum_partial_copy_generic_from_user((__force void *)src, dst,
11002 len, sum, err_ptr, NULL);
11003 }
11004
11005@@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
11006 {
11007 might_sleep();
11008 if (access_ok(VERIFY_WRITE, dst, len))
11009- return csum_partial_copy_generic(src, (__force void *)dst,
11010+ return csum_partial_copy_generic_to_user(src, (__force void *)dst,
11011 len, sum, NULL, err_ptr);
11012
11013 if (len)
11014diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
11015index 8d871ea..c1a0dc9 100644
11016--- a/arch/x86/include/asm/cmpxchg.h
11017+++ b/arch/x86/include/asm/cmpxchg.h
11018@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
11019 __compiletime_error("Bad argument size for cmpxchg");
11020 extern void __xadd_wrong_size(void)
11021 __compiletime_error("Bad argument size for xadd");
11022+extern void __xadd_check_overflow_wrong_size(void)
11023+ __compiletime_error("Bad argument size for xadd_check_overflow");
11024 extern void __add_wrong_size(void)
11025 __compiletime_error("Bad argument size for add");
11026+extern void __add_check_overflow_wrong_size(void)
11027+ __compiletime_error("Bad argument size for add_check_overflow");
11028
11029 /*
11030 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
11031@@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
11032 __ret; \
11033 })
11034
11035+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
11036+ ({ \
11037+ __typeof__ (*(ptr)) __ret = (arg); \
11038+ switch (sizeof(*(ptr))) { \
11039+ case __X86_CASE_L: \
11040+ asm volatile (lock #op "l %0, %1\n" \
11041+ "jno 0f\n" \
11042+ "mov %0,%1\n" \
11043+ "int $4\n0:\n" \
11044+ _ASM_EXTABLE(0b, 0b) \
11045+ : "+r" (__ret), "+m" (*(ptr)) \
11046+ : : "memory", "cc"); \
11047+ break; \
11048+ case __X86_CASE_Q: \
11049+ asm volatile (lock #op "q %q0, %1\n" \
11050+ "jno 0f\n" \
11051+ "mov %0,%1\n" \
11052+ "int $4\n0:\n" \
11053+ _ASM_EXTABLE(0b, 0b) \
11054+ : "+r" (__ret), "+m" (*(ptr)) \
11055+ : : "memory", "cc"); \
11056+ break; \
11057+ default: \
11058+ __ ## op ## _check_overflow_wrong_size(); \
11059+ } \
11060+ __ret; \
11061+ })
11062+
11063 /*
11064 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
11065 * Since this is generally used to protect other memory information, we
11066@@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
11067 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
11068 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
11069
11070+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
11071+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
11072+
11073 #define __add(ptr, inc, lock) \
11074 ({ \
11075 __typeof__ (*(ptr)) __ret = (inc); \
11076diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
11077index 8c297aa..7a90f03 100644
11078--- a/arch/x86/include/asm/cpufeature.h
11079+++ b/arch/x86/include/asm/cpufeature.h
11080@@ -205,7 +205,7 @@
11081 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
11082 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
11083 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
11084-#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
11085+#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
11086 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
11087 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
11088 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
11089@@ -379,7 +379,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
11090 ".section .discard,\"aw\",@progbits\n"
11091 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
11092 ".previous\n"
11093- ".section .altinstr_replacement,\"ax\"\n"
11094+ ".section .altinstr_replacement,\"a\"\n"
11095 "3: movb $1,%0\n"
11096 "4:\n"
11097 ".previous\n"
11098diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
11099index 8bf1c06..f723dfd 100644
11100--- a/arch/x86/include/asm/desc.h
11101+++ b/arch/x86/include/asm/desc.h
11102@@ -4,6 +4,7 @@
11103 #include <asm/desc_defs.h>
11104 #include <asm/ldt.h>
11105 #include <asm/mmu.h>
11106+#include <asm/pgtable.h>
11107
11108 #include <linux/smp.h>
11109 #include <linux/percpu.h>
11110@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
11111
11112 desc->type = (info->read_exec_only ^ 1) << 1;
11113 desc->type |= info->contents << 2;
11114+ desc->type |= info->seg_not_present ^ 1;
11115
11116 desc->s = 1;
11117 desc->dpl = 0x3;
11118@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
11119 }
11120
11121 extern struct desc_ptr idt_descr;
11122-extern gate_desc idt_table[];
11123 extern struct desc_ptr nmi_idt_descr;
11124-extern gate_desc nmi_idt_table[];
11125-
11126-struct gdt_page {
11127- struct desc_struct gdt[GDT_ENTRIES];
11128-} __attribute__((aligned(PAGE_SIZE)));
11129-
11130-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
11131+extern gate_desc idt_table[256];
11132+extern gate_desc nmi_idt_table[256];
11133
11134+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
11135 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
11136 {
11137- return per_cpu(gdt_page, cpu).gdt;
11138+ return cpu_gdt_table[cpu];
11139 }
11140
11141 #ifdef CONFIG_X86_64
11142@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
11143 unsigned long base, unsigned dpl, unsigned flags,
11144 unsigned short seg)
11145 {
11146- gate->a = (seg << 16) | (base & 0xffff);
11147- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
11148+ gate->gate.offset_low = base;
11149+ gate->gate.seg = seg;
11150+ gate->gate.reserved = 0;
11151+ gate->gate.type = type;
11152+ gate->gate.s = 0;
11153+ gate->gate.dpl = dpl;
11154+ gate->gate.p = 1;
11155+ gate->gate.offset_high = base >> 16;
11156 }
11157
11158 #endif
11159@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
11160
11161 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
11162 {
11163+ pax_open_kernel();
11164 memcpy(&idt[entry], gate, sizeof(*gate));
11165+ pax_close_kernel();
11166 }
11167
11168 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
11169 {
11170+ pax_open_kernel();
11171 memcpy(&ldt[entry], desc, 8);
11172+ pax_close_kernel();
11173 }
11174
11175 static inline void
11176@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
11177 default: size = sizeof(*gdt); break;
11178 }
11179
11180+ pax_open_kernel();
11181 memcpy(&gdt[entry], desc, size);
11182+ pax_close_kernel();
11183 }
11184
11185 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
11186@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
11187
11188 static inline void native_load_tr_desc(void)
11189 {
11190+ pax_open_kernel();
11191 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
11192+ pax_close_kernel();
11193 }
11194
11195 static inline void native_load_gdt(const struct desc_ptr *dtr)
11196@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
11197 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
11198 unsigned int i;
11199
11200+ pax_open_kernel();
11201 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
11202 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
11203+ pax_close_kernel();
11204 }
11205
11206 #define _LDT_empty(info) \
11207@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
11208 }
11209
11210 #ifdef CONFIG_X86_64
11211-static inline void set_nmi_gate(int gate, void *addr)
11212+static inline void set_nmi_gate(int gate, const void *addr)
11213 {
11214 gate_desc s;
11215
11216@@ -320,7 +333,7 @@ static inline void set_nmi_gate(int gate, void *addr)
11217 }
11218 #endif
11219
11220-static inline void _set_gate(int gate, unsigned type, void *addr,
11221+static inline void _set_gate(int gate, unsigned type, const void *addr,
11222 unsigned dpl, unsigned ist, unsigned seg)
11223 {
11224 gate_desc s;
11225@@ -339,7 +352,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
11226 * Pentium F0 0F bugfix can have resulted in the mapped
11227 * IDT being write-protected.
11228 */
11229-static inline void set_intr_gate(unsigned int n, void *addr)
11230+static inline void set_intr_gate(unsigned int n, const void *addr)
11231 {
11232 BUG_ON((unsigned)n > 0xFF);
11233 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
11234@@ -369,19 +382,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
11235 /*
11236 * This routine sets up an interrupt gate at directory privilege level 3.
11237 */
11238-static inline void set_system_intr_gate(unsigned int n, void *addr)
11239+static inline void set_system_intr_gate(unsigned int n, const void *addr)
11240 {
11241 BUG_ON((unsigned)n > 0xFF);
11242 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
11243 }
11244
11245-static inline void set_system_trap_gate(unsigned int n, void *addr)
11246+static inline void set_system_trap_gate(unsigned int n, const void *addr)
11247 {
11248 BUG_ON((unsigned)n > 0xFF);
11249 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
11250 }
11251
11252-static inline void set_trap_gate(unsigned int n, void *addr)
11253+static inline void set_trap_gate(unsigned int n, const void *addr)
11254 {
11255 BUG_ON((unsigned)n > 0xFF);
11256 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
11257@@ -390,19 +403,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
11258 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
11259 {
11260 BUG_ON((unsigned)n > 0xFF);
11261- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
11262+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
11263 }
11264
11265-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
11266+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
11267 {
11268 BUG_ON((unsigned)n > 0xFF);
11269 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
11270 }
11271
11272-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
11273+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
11274 {
11275 BUG_ON((unsigned)n > 0xFF);
11276 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
11277 }
11278
11279+#ifdef CONFIG_X86_32
11280+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
11281+{
11282+ struct desc_struct d;
11283+
11284+ if (likely(limit))
11285+ limit = (limit - 1UL) >> PAGE_SHIFT;
11286+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
11287+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
11288+}
11289+#endif
11290+
11291 #endif /* _ASM_X86_DESC_H */
11292diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
11293index 278441f..b95a174 100644
11294--- a/arch/x86/include/asm/desc_defs.h
11295+++ b/arch/x86/include/asm/desc_defs.h
11296@@ -31,6 +31,12 @@ struct desc_struct {
11297 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
11298 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
11299 };
11300+ struct {
11301+ u16 offset_low;
11302+ u16 seg;
11303+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
11304+ unsigned offset_high: 16;
11305+ } gate;
11306 };
11307 } __attribute__((packed));
11308
11309diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
11310index 3778256..c5d4fce 100644
11311--- a/arch/x86/include/asm/e820.h
11312+++ b/arch/x86/include/asm/e820.h
11313@@ -69,7 +69,7 @@ struct e820map {
11314 #define ISA_START_ADDRESS 0xa0000
11315 #define ISA_END_ADDRESS 0x100000
11316
11317-#define BIOS_BEGIN 0x000a0000
11318+#define BIOS_BEGIN 0x000c0000
11319 #define BIOS_END 0x00100000
11320
11321 #define BIOS_ROM_BASE 0xffe00000
11322diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
11323index 5939f44..f8845f6 100644
11324--- a/arch/x86/include/asm/elf.h
11325+++ b/arch/x86/include/asm/elf.h
11326@@ -243,7 +243,25 @@ extern int force_personality32;
11327 the loader. We need to make sure that it is out of the way of the program
11328 that it will "exec", and that there is sufficient room for the brk. */
11329
11330+#ifdef CONFIG_PAX_SEGMEXEC
11331+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
11332+#else
11333 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
11334+#endif
11335+
11336+#ifdef CONFIG_PAX_ASLR
11337+#ifdef CONFIG_X86_32
11338+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
11339+
11340+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
11341+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
11342+#else
11343+#define PAX_ELF_ET_DYN_BASE 0x400000UL
11344+
11345+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
11346+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
11347+#endif
11348+#endif
11349
11350 /* This yields a mask that user programs can use to figure out what
11351 instruction set this CPU supports. This could be done in user space,
11352@@ -296,16 +314,12 @@ do { \
11353
11354 #define ARCH_DLINFO \
11355 do { \
11356- if (vdso_enabled) \
11357- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
11358- (unsigned long)current->mm->context.vdso); \
11359+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
11360 } while (0)
11361
11362 #define ARCH_DLINFO_X32 \
11363 do { \
11364- if (vdso_enabled) \
11365- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
11366- (unsigned long)current->mm->context.vdso); \
11367+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
11368 } while (0)
11369
11370 #define AT_SYSINFO 32
11371@@ -320,7 +334,7 @@ else \
11372
11373 #endif /* !CONFIG_X86_32 */
11374
11375-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
11376+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
11377
11378 #define VDSO_ENTRY \
11379 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
11380@@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
11381 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
11382 #define compat_arch_setup_additional_pages syscall32_setup_pages
11383
11384-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
11385-#define arch_randomize_brk arch_randomize_brk
11386-
11387 /*
11388 * True on X86_32 or when emulating IA32 on X86_64
11389 */
11390diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
11391index 75ce3f4..882e801 100644
11392--- a/arch/x86/include/asm/emergency-restart.h
11393+++ b/arch/x86/include/asm/emergency-restart.h
11394@@ -13,6 +13,6 @@ enum reboot_type {
11395
11396 extern enum reboot_type reboot_type;
11397
11398-extern void machine_emergency_restart(void);
11399+extern void machine_emergency_restart(void) __noreturn;
11400
11401 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
11402diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
11403index 41ab26e..a88c9e6 100644
11404--- a/arch/x86/include/asm/fpu-internal.h
11405+++ b/arch/x86/include/asm/fpu-internal.h
11406@@ -126,7 +126,9 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
11407 ({ \
11408 int err; \
11409 asm volatile(ASM_STAC "\n" \
11410- "1:" #insn "\n\t" \
11411+ "1:" \
11412+ __copyuser_seg \
11413+ #insn "\n\t" \
11414 "2: " ASM_CLAC "\n" \
11415 ".section .fixup,\"ax\"\n" \
11416 "3: movl $-1,%[err]\n" \
11417@@ -299,7 +301,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
11418 "emms\n\t" /* clear stack tags */
11419 "fildl %P[addr]", /* set F?P to defined value */
11420 X86_FEATURE_FXSAVE_LEAK,
11421- [addr] "m" (tsk->thread.fpu.has_fpu));
11422+ [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
11423
11424 return fpu_restore_checking(&tsk->thread.fpu);
11425 }
11426diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
11427index f373046..02653e2 100644
11428--- a/arch/x86/include/asm/futex.h
11429+++ b/arch/x86/include/asm/futex.h
11430@@ -12,6 +12,7 @@
11431 #include <asm/smap.h>
11432
11433 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
11434+ typecheck(u32 __user *, uaddr); \
11435 asm volatile("\t" ASM_STAC "\n" \
11436 "1:\t" insn "\n" \
11437 "2:\t" ASM_CLAC "\n" \
11438@@ -20,15 +21,16 @@
11439 "\tjmp\t2b\n" \
11440 "\t.previous\n" \
11441 _ASM_EXTABLE(1b, 3b) \
11442- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
11443+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
11444 : "i" (-EFAULT), "0" (oparg), "1" (0))
11445
11446 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
11447+ typecheck(u32 __user *, uaddr); \
11448 asm volatile("\t" ASM_STAC "\n" \
11449 "1:\tmovl %2, %0\n" \
11450 "\tmovl\t%0, %3\n" \
11451 "\t" insn "\n" \
11452- "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
11453+ "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
11454 "\tjnz\t1b\n" \
11455 "3:\t" ASM_CLAC "\n" \
11456 "\t.section .fixup,\"ax\"\n" \
11457@@ -38,7 +40,7 @@
11458 _ASM_EXTABLE(1b, 4b) \
11459 _ASM_EXTABLE(2b, 4b) \
11460 : "=&a" (oldval), "=&r" (ret), \
11461- "+m" (*uaddr), "=&r" (tem) \
11462+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
11463 : "r" (oparg), "i" (-EFAULT), "1" (0))
11464
11465 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
11466@@ -65,10 +67,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
11467
11468 switch (op) {
11469 case FUTEX_OP_SET:
11470- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
11471+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
11472 break;
11473 case FUTEX_OP_ADD:
11474- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
11475+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
11476 uaddr, oparg);
11477 break;
11478 case FUTEX_OP_OR:
11479@@ -128,14 +130,14 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
11480 return -EFAULT;
11481
11482 asm volatile("\t" ASM_STAC "\n"
11483- "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
11484+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
11485 "2:\t" ASM_CLAC "\n"
11486 "\t.section .fixup, \"ax\"\n"
11487 "3:\tmov %3, %0\n"
11488 "\tjmp 2b\n"
11489 "\t.previous\n"
11490 _ASM_EXTABLE(1b, 3b)
11491- : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
11492+ : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
11493 : "i" (-EFAULT), "r" (newval), "1" (oldval)
11494 : "memory"
11495 );
11496diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
11497index eb92a6e..b98b2f4 100644
11498--- a/arch/x86/include/asm/hw_irq.h
11499+++ b/arch/x86/include/asm/hw_irq.h
11500@@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
11501 extern void enable_IO_APIC(void);
11502
11503 /* Statistics */
11504-extern atomic_t irq_err_count;
11505-extern atomic_t irq_mis_count;
11506+extern atomic_unchecked_t irq_err_count;
11507+extern atomic_unchecked_t irq_mis_count;
11508
11509 /* EISA */
11510 extern void eisa_set_level_irq(unsigned int irq);
11511diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
11512index d8e8eef..15b1179 100644
11513--- a/arch/x86/include/asm/io.h
11514+++ b/arch/x86/include/asm/io.h
11515@@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
11516 return ioremap_nocache(offset, size);
11517 }
11518
11519-extern void iounmap(volatile void __iomem *addr);
11520+extern void iounmap(const volatile void __iomem *addr);
11521
11522 extern void set_iounmap_nonlazy(void);
11523
11524@@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
11525
11526 #include <linux/vmalloc.h>
11527
11528+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
11529+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
11530+{
11531+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
11532+}
11533+
11534+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
11535+{
11536+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
11537+}
11538+
11539 /*
11540 * Convert a virtual cached pointer to an uncached pointer
11541 */
11542diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
11543index bba3cf8..06bc8da 100644
11544--- a/arch/x86/include/asm/irqflags.h
11545+++ b/arch/x86/include/asm/irqflags.h
11546@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
11547 sti; \
11548 sysexit
11549
11550+#define GET_CR0_INTO_RDI mov %cr0, %rdi
11551+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
11552+#define GET_CR3_INTO_RDI mov %cr3, %rdi
11553+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
11554+
11555 #else
11556 #define INTERRUPT_RETURN iret
11557 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
11558diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
11559index d3ddd17..c9fb0cc 100644
11560--- a/arch/x86/include/asm/kprobes.h
11561+++ b/arch/x86/include/asm/kprobes.h
11562@@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
11563 #define RELATIVEJUMP_SIZE 5
11564 #define RELATIVECALL_OPCODE 0xe8
11565 #define RELATIVE_ADDR_SIZE 4
11566-#define MAX_STACK_SIZE 64
11567-#define MIN_STACK_SIZE(ADDR) \
11568- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
11569- THREAD_SIZE - (unsigned long)(ADDR))) \
11570- ? (MAX_STACK_SIZE) \
11571- : (((unsigned long)current_thread_info()) + \
11572- THREAD_SIZE - (unsigned long)(ADDR)))
11573+#define MAX_STACK_SIZE 64UL
11574+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
11575
11576 #define flush_insn_slot(p) do { } while (0)
11577
11578diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
11579index b2e11f4..f293e2e 100644
11580--- a/arch/x86/include/asm/kvm_host.h
11581+++ b/arch/x86/include/asm/kvm_host.h
11582@@ -707,7 +707,7 @@ struct kvm_x86_ops {
11583 int (*check_intercept)(struct kvm_vcpu *vcpu,
11584 struct x86_instruction_info *info,
11585 enum x86_intercept_stage stage);
11586-};
11587+} __do_const;
11588
11589 struct kvm_arch_async_pf {
11590 u32 token;
11591diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
11592index c8bed0d..85c03fd 100644
11593--- a/arch/x86/include/asm/local.h
11594+++ b/arch/x86/include/asm/local.h
11595@@ -10,33 +10,97 @@ typedef struct {
11596 atomic_long_t a;
11597 } local_t;
11598
11599+typedef struct {
11600+ atomic_long_unchecked_t a;
11601+} local_unchecked_t;
11602+
11603 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
11604
11605 #define local_read(l) atomic_long_read(&(l)->a)
11606+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
11607 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
11608+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
11609
11610 static inline void local_inc(local_t *l)
11611 {
11612- asm volatile(_ASM_INC "%0"
11613+ asm volatile(_ASM_INC "%0\n"
11614+
11615+#ifdef CONFIG_PAX_REFCOUNT
11616+ "jno 0f\n"
11617+ _ASM_DEC "%0\n"
11618+ "int $4\n0:\n"
11619+ _ASM_EXTABLE(0b, 0b)
11620+#endif
11621+
11622+ : "+m" (l->a.counter));
11623+}
11624+
11625+static inline void local_inc_unchecked(local_unchecked_t *l)
11626+{
11627+ asm volatile(_ASM_INC "%0\n"
11628 : "+m" (l->a.counter));
11629 }
11630
11631 static inline void local_dec(local_t *l)
11632 {
11633- asm volatile(_ASM_DEC "%0"
11634+ asm volatile(_ASM_DEC "%0\n"
11635+
11636+#ifdef CONFIG_PAX_REFCOUNT
11637+ "jno 0f\n"
11638+ _ASM_INC "%0\n"
11639+ "int $4\n0:\n"
11640+ _ASM_EXTABLE(0b, 0b)
11641+#endif
11642+
11643+ : "+m" (l->a.counter));
11644+}
11645+
11646+static inline void local_dec_unchecked(local_unchecked_t *l)
11647+{
11648+ asm volatile(_ASM_DEC "%0\n"
11649 : "+m" (l->a.counter));
11650 }
11651
11652 static inline void local_add(long i, local_t *l)
11653 {
11654- asm volatile(_ASM_ADD "%1,%0"
11655+ asm volatile(_ASM_ADD "%1,%0\n"
11656+
11657+#ifdef CONFIG_PAX_REFCOUNT
11658+ "jno 0f\n"
11659+ _ASM_SUB "%1,%0\n"
11660+ "int $4\n0:\n"
11661+ _ASM_EXTABLE(0b, 0b)
11662+#endif
11663+
11664+ : "+m" (l->a.counter)
11665+ : "ir" (i));
11666+}
11667+
11668+static inline void local_add_unchecked(long i, local_unchecked_t *l)
11669+{
11670+ asm volatile(_ASM_ADD "%1,%0\n"
11671 : "+m" (l->a.counter)
11672 : "ir" (i));
11673 }
11674
11675 static inline void local_sub(long i, local_t *l)
11676 {
11677- asm volatile(_ASM_SUB "%1,%0"
11678+ asm volatile(_ASM_SUB "%1,%0\n"
11679+
11680+#ifdef CONFIG_PAX_REFCOUNT
11681+ "jno 0f\n"
11682+ _ASM_ADD "%1,%0\n"
11683+ "int $4\n0:\n"
11684+ _ASM_EXTABLE(0b, 0b)
11685+#endif
11686+
11687+ : "+m" (l->a.counter)
11688+ : "ir" (i));
11689+}
11690+
11691+static inline void local_sub_unchecked(long i, local_unchecked_t *l)
11692+{
11693+ asm volatile(_ASM_SUB "%1,%0\n"
11694 : "+m" (l->a.counter)
11695 : "ir" (i));
11696 }
11697@@ -54,7 +118,16 @@ static inline int local_sub_and_test(long i, local_t *l)
11698 {
11699 unsigned char c;
11700
11701- asm volatile(_ASM_SUB "%2,%0; sete %1"
11702+ asm volatile(_ASM_SUB "%2,%0\n"
11703+
11704+#ifdef CONFIG_PAX_REFCOUNT
11705+ "jno 0f\n"
11706+ _ASM_ADD "%2,%0\n"
11707+ "int $4\n0:\n"
11708+ _ASM_EXTABLE(0b, 0b)
11709+#endif
11710+
11711+ "sete %1\n"
11712 : "+m" (l->a.counter), "=qm" (c)
11713 : "ir" (i) : "memory");
11714 return c;
11715@@ -72,7 +145,16 @@ static inline int local_dec_and_test(local_t *l)
11716 {
11717 unsigned char c;
11718
11719- asm volatile(_ASM_DEC "%0; sete %1"
11720+ asm volatile(_ASM_DEC "%0\n"
11721+
11722+#ifdef CONFIG_PAX_REFCOUNT
11723+ "jno 0f\n"
11724+ _ASM_INC "%0\n"
11725+ "int $4\n0:\n"
11726+ _ASM_EXTABLE(0b, 0b)
11727+#endif
11728+
11729+ "sete %1\n"
11730 : "+m" (l->a.counter), "=qm" (c)
11731 : : "memory");
11732 return c != 0;
11733@@ -90,7 +172,16 @@ static inline int local_inc_and_test(local_t *l)
11734 {
11735 unsigned char c;
11736
11737- asm volatile(_ASM_INC "%0; sete %1"
11738+ asm volatile(_ASM_INC "%0\n"
11739+
11740+#ifdef CONFIG_PAX_REFCOUNT
11741+ "jno 0f\n"
11742+ _ASM_DEC "%0\n"
11743+ "int $4\n0:\n"
11744+ _ASM_EXTABLE(0b, 0b)
11745+#endif
11746+
11747+ "sete %1\n"
11748 : "+m" (l->a.counter), "=qm" (c)
11749 : : "memory");
11750 return c != 0;
11751@@ -109,7 +200,16 @@ static inline int local_add_negative(long i, local_t *l)
11752 {
11753 unsigned char c;
11754
11755- asm volatile(_ASM_ADD "%2,%0; sets %1"
11756+ asm volatile(_ASM_ADD "%2,%0\n"
11757+
11758+#ifdef CONFIG_PAX_REFCOUNT
11759+ "jno 0f\n"
11760+ _ASM_SUB "%2,%0\n"
11761+ "int $4\n0:\n"
11762+ _ASM_EXTABLE(0b, 0b)
11763+#endif
11764+
11765+ "sets %1\n"
11766 : "+m" (l->a.counter), "=qm" (c)
11767 : "ir" (i) : "memory");
11768 return c;
11769@@ -132,7 +232,15 @@ static inline long local_add_return(long i, local_t *l)
11770 #endif
11771 /* Modern 486+ processor */
11772 __i = i;
11773- asm volatile(_ASM_XADD "%0, %1;"
11774+ asm volatile(_ASM_XADD "%0, %1\n"
11775+
11776+#ifdef CONFIG_PAX_REFCOUNT
11777+ "jno 0f\n"
11778+ _ASM_MOV "%0,%1\n"
11779+ "int $4\n0:\n"
11780+ _ASM_EXTABLE(0b, 0b)
11781+#endif
11782+
11783 : "+r" (i), "+m" (l->a.counter)
11784 : : "memory");
11785 return i + __i;
11786@@ -147,6 +255,38 @@ no_xadd: /* Legacy 386 processor */
11787 #endif
11788 }
11789
11790+/**
11791+ * local_add_return_unchecked - add and return
11792+ * @i: integer value to add
11793+ * @l: pointer to type local_unchecked_t
11794+ *
11795+ * Atomically adds @i to @l and returns @i + @l
11796+ */
11797+static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
11798+{
11799+ long __i;
11800+#ifdef CONFIG_M386
11801+ unsigned long flags;
11802+ if (unlikely(boot_cpu_data.x86 <= 3))
11803+ goto no_xadd;
11804+#endif
11805+ /* Modern 486+ processor */
11806+ __i = i;
11807+ asm volatile(_ASM_XADD "%0, %1\n"
11808+ : "+r" (i), "+m" (l->a.counter)
11809+ : : "memory");
11810+ return i + __i;
11811+
11812+#ifdef CONFIG_M386
11813+no_xadd: /* Legacy 386 processor */
11814+ local_irq_save(flags);
11815+ __i = local_read_unchecked(l);
11816+ local_set_unchecked(l, i + __i);
11817+ local_irq_restore(flags);
11818+ return i + __i;
11819+#endif
11820+}
11821+
11822 static inline long local_sub_return(long i, local_t *l)
11823 {
11824 return local_add_return(-i, l);
11825@@ -157,6 +297,8 @@ static inline long local_sub_return(long i, local_t *l)
11826
11827 #define local_cmpxchg(l, o, n) \
11828 (cmpxchg_local(&((l)->a.counter), (o), (n)))
11829+#define local_cmpxchg_unchecked(l, o, n) \
11830+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
11831 /* Always has a lock prefix */
11832 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
11833
11834diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
11835index 593e51d..fa69c9a 100644
11836--- a/arch/x86/include/asm/mman.h
11837+++ b/arch/x86/include/asm/mman.h
11838@@ -5,4 +5,14 @@
11839
11840 #include <asm-generic/mman.h>
11841
11842+#ifdef __KERNEL__
11843+#ifndef __ASSEMBLY__
11844+#ifdef CONFIG_X86_32
11845+#define arch_mmap_check i386_mmap_check
11846+int i386_mmap_check(unsigned long addr, unsigned long len,
11847+ unsigned long flags);
11848+#endif
11849+#endif
11850+#endif
11851+
11852 #endif /* _ASM_X86_MMAN_H */
11853diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
11854index 5f55e69..e20bfb1 100644
11855--- a/arch/x86/include/asm/mmu.h
11856+++ b/arch/x86/include/asm/mmu.h
11857@@ -9,7 +9,7 @@
11858 * we put the segment information here.
11859 */
11860 typedef struct {
11861- void *ldt;
11862+ struct desc_struct *ldt;
11863 int size;
11864
11865 #ifdef CONFIG_X86_64
11866@@ -18,7 +18,19 @@ typedef struct {
11867 #endif
11868
11869 struct mutex lock;
11870- void *vdso;
11871+ unsigned long vdso;
11872+
11873+#ifdef CONFIG_X86_32
11874+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
11875+ unsigned long user_cs_base;
11876+ unsigned long user_cs_limit;
11877+
11878+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
11879+ cpumask_t cpu_user_cs_mask;
11880+#endif
11881+
11882+#endif
11883+#endif
11884 } mm_context_t;
11885
11886 #ifdef CONFIG_SMP
11887diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
11888index cdbf367..adb37ac 100644
11889--- a/arch/x86/include/asm/mmu_context.h
11890+++ b/arch/x86/include/asm/mmu_context.h
11891@@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
11892
11893 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
11894 {
11895+
11896+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11897+ unsigned int i;
11898+ pgd_t *pgd;
11899+
11900+ pax_open_kernel();
11901+ pgd = get_cpu_pgd(smp_processor_id());
11902+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
11903+ set_pgd_batched(pgd+i, native_make_pgd(0));
11904+ pax_close_kernel();
11905+#endif
11906+
11907 #ifdef CONFIG_SMP
11908 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
11909 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
11910@@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
11911 struct task_struct *tsk)
11912 {
11913 unsigned cpu = smp_processor_id();
11914+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11915+ int tlbstate = TLBSTATE_OK;
11916+#endif
11917
11918 if (likely(prev != next)) {
11919 #ifdef CONFIG_SMP
11920+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11921+ tlbstate = this_cpu_read(cpu_tlbstate.state);
11922+#endif
11923 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
11924 this_cpu_write(cpu_tlbstate.active_mm, next);
11925 #endif
11926 cpumask_set_cpu(cpu, mm_cpumask(next));
11927
11928 /* Re-load page tables */
11929+#ifdef CONFIG_PAX_PER_CPU_PGD
11930+ pax_open_kernel();
11931+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
11932+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
11933+ pax_close_kernel();
11934+ load_cr3(get_cpu_pgd(cpu));
11935+#else
11936 load_cr3(next->pgd);
11937+#endif
11938
11939 /* stop flush ipis for the previous mm */
11940 cpumask_clear_cpu(cpu, mm_cpumask(prev));
11941@@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
11942 */
11943 if (unlikely(prev->context.ldt != next->context.ldt))
11944 load_LDT_nolock(&next->context);
11945- }
11946+
11947+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
11948+ if (!(__supported_pte_mask & _PAGE_NX)) {
11949+ smp_mb__before_clear_bit();
11950+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
11951+ smp_mb__after_clear_bit();
11952+ cpu_set(cpu, next->context.cpu_user_cs_mask);
11953+ }
11954+#endif
11955+
11956+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11957+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
11958+ prev->context.user_cs_limit != next->context.user_cs_limit))
11959+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11960 #ifdef CONFIG_SMP
11961+ else if (unlikely(tlbstate != TLBSTATE_OK))
11962+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11963+#endif
11964+#endif
11965+
11966+ }
11967 else {
11968+
11969+#ifdef CONFIG_PAX_PER_CPU_PGD
11970+ pax_open_kernel();
11971+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
11972+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
11973+ pax_close_kernel();
11974+ load_cr3(get_cpu_pgd(cpu));
11975+#endif
11976+
11977+#ifdef CONFIG_SMP
11978 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
11979 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
11980
11981@@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
11982 * tlb flush IPI delivery. We must reload CR3
11983 * to make sure to use no freed page tables.
11984 */
11985+
11986+#ifndef CONFIG_PAX_PER_CPU_PGD
11987 load_cr3(next->pgd);
11988+#endif
11989+
11990 load_LDT_nolock(&next->context);
11991+
11992+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
11993+ if (!(__supported_pte_mask & _PAGE_NX))
11994+ cpu_set(cpu, next->context.cpu_user_cs_mask);
11995+#endif
11996+
11997+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11998+#ifdef CONFIG_PAX_PAGEEXEC
11999+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
12000+#endif
12001+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
12002+#endif
12003+
12004 }
12005+#endif
12006 }
12007-#endif
12008 }
12009
12010 #define activate_mm(prev, next) \
12011diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
12012index 9eae775..c914fea 100644
12013--- a/arch/x86/include/asm/module.h
12014+++ b/arch/x86/include/asm/module.h
12015@@ -5,6 +5,7 @@
12016
12017 #ifdef CONFIG_X86_64
12018 /* X86_64 does not define MODULE_PROC_FAMILY */
12019+#define MODULE_PROC_FAMILY ""
12020 #elif defined CONFIG_M386
12021 #define MODULE_PROC_FAMILY "386 "
12022 #elif defined CONFIG_M486
12023@@ -59,8 +60,20 @@
12024 #error unknown processor family
12025 #endif
12026
12027-#ifdef CONFIG_X86_32
12028-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
12029+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
12030+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
12031+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
12032+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
12033+#else
12034+#define MODULE_PAX_KERNEXEC ""
12035 #endif
12036
12037+#ifdef CONFIG_PAX_MEMORY_UDEREF
12038+#define MODULE_PAX_UDEREF "UDEREF "
12039+#else
12040+#define MODULE_PAX_UDEREF ""
12041+#endif
12042+
12043+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
12044+
12045 #endif /* _ASM_X86_MODULE_H */
12046diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
12047index 320f7bb..e89f8f8 100644
12048--- a/arch/x86/include/asm/page_64_types.h
12049+++ b/arch/x86/include/asm/page_64_types.h
12050@@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
12051
12052 /* duplicated to the one in bootmem.h */
12053 extern unsigned long max_pfn;
12054-extern unsigned long phys_base;
12055+extern const unsigned long phys_base;
12056
12057 extern unsigned long __phys_addr(unsigned long);
12058 #define __phys_reloc_hide(x) (x)
12059diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
12060index a0facf3..c017b15 100644
12061--- a/arch/x86/include/asm/paravirt.h
12062+++ b/arch/x86/include/asm/paravirt.h
12063@@ -632,6 +632,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
12064 val);
12065 }
12066
12067+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
12068+{
12069+ pgdval_t val = native_pgd_val(pgd);
12070+
12071+ if (sizeof(pgdval_t) > sizeof(long))
12072+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
12073+ val, (u64)val >> 32);
12074+ else
12075+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
12076+ val);
12077+}
12078+
12079 static inline void pgd_clear(pgd_t *pgdp)
12080 {
12081 set_pgd(pgdp, __pgd(0));
12082@@ -713,6 +725,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
12083 pv_mmu_ops.set_fixmap(idx, phys, flags);
12084 }
12085
12086+#ifdef CONFIG_PAX_KERNEXEC
12087+static inline unsigned long pax_open_kernel(void)
12088+{
12089+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
12090+}
12091+
12092+static inline unsigned long pax_close_kernel(void)
12093+{
12094+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
12095+}
12096+#else
12097+static inline unsigned long pax_open_kernel(void) { return 0; }
12098+static inline unsigned long pax_close_kernel(void) { return 0; }
12099+#endif
12100+
12101 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
12102
12103 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
12104@@ -929,7 +956,7 @@ extern void default_banner(void);
12105
12106 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
12107 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
12108-#define PARA_INDIRECT(addr) *%cs:addr
12109+#define PARA_INDIRECT(addr) *%ss:addr
12110 #endif
12111
12112 #define INTERRUPT_RETURN \
12113@@ -1004,6 +1031,21 @@ extern void default_banner(void);
12114 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
12115 CLBR_NONE, \
12116 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
12117+
12118+#define GET_CR0_INTO_RDI \
12119+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
12120+ mov %rax,%rdi
12121+
12122+#define SET_RDI_INTO_CR0 \
12123+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
12124+
12125+#define GET_CR3_INTO_RDI \
12126+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
12127+ mov %rax,%rdi
12128+
12129+#define SET_RDI_INTO_CR3 \
12130+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
12131+
12132 #endif /* CONFIG_X86_32 */
12133
12134 #endif /* __ASSEMBLY__ */
12135diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
12136index 142236e..6a6b4a6 100644
12137--- a/arch/x86/include/asm/paravirt_types.h
12138+++ b/arch/x86/include/asm/paravirt_types.h
12139@@ -84,20 +84,20 @@ struct pv_init_ops {
12140 */
12141 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
12142 unsigned long addr, unsigned len);
12143-};
12144+} __no_const;
12145
12146
12147 struct pv_lazy_ops {
12148 /* Set deferred update mode, used for batching operations. */
12149 void (*enter)(void);
12150 void (*leave)(void);
12151-};
12152+} __no_const;
12153
12154 struct pv_time_ops {
12155 unsigned long long (*sched_clock)(void);
12156 unsigned long long (*steal_clock)(int cpu);
12157 unsigned long (*get_tsc_khz)(void);
12158-};
12159+} __no_const;
12160
12161 struct pv_cpu_ops {
12162 /* hooks for various privileged instructions */
12163@@ -191,7 +191,7 @@ struct pv_cpu_ops {
12164
12165 void (*start_context_switch)(struct task_struct *prev);
12166 void (*end_context_switch)(struct task_struct *next);
12167-};
12168+} __no_const;
12169
12170 struct pv_irq_ops {
12171 /*
12172@@ -222,7 +222,7 @@ struct pv_apic_ops {
12173 unsigned long start_eip,
12174 unsigned long start_esp);
12175 #endif
12176-};
12177+} __no_const;
12178
12179 struct pv_mmu_ops {
12180 unsigned long (*read_cr2)(void);
12181@@ -312,6 +312,7 @@ struct pv_mmu_ops {
12182 struct paravirt_callee_save make_pud;
12183
12184 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
12185+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
12186 #endif /* PAGETABLE_LEVELS == 4 */
12187 #endif /* PAGETABLE_LEVELS >= 3 */
12188
12189@@ -323,6 +324,12 @@ struct pv_mmu_ops {
12190 an mfn. We can tell which is which from the index. */
12191 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
12192 phys_addr_t phys, pgprot_t flags);
12193+
12194+#ifdef CONFIG_PAX_KERNEXEC
12195+ unsigned long (*pax_open_kernel)(void);
12196+ unsigned long (*pax_close_kernel)(void);
12197+#endif
12198+
12199 };
12200
12201 struct arch_spinlock;
12202@@ -333,7 +340,7 @@ struct pv_lock_ops {
12203 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
12204 int (*spin_trylock)(struct arch_spinlock *lock);
12205 void (*spin_unlock)(struct arch_spinlock *lock);
12206-};
12207+} __no_const;
12208
12209 /* This contains all the paravirt structures: we get a convenient
12210 * number for each function using the offset which we use to indicate
12211diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
12212index b4389a4..7024269 100644
12213--- a/arch/x86/include/asm/pgalloc.h
12214+++ b/arch/x86/include/asm/pgalloc.h
12215@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
12216 pmd_t *pmd, pte_t *pte)
12217 {
12218 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
12219+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
12220+}
12221+
12222+static inline void pmd_populate_user(struct mm_struct *mm,
12223+ pmd_t *pmd, pte_t *pte)
12224+{
12225+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
12226 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
12227 }
12228
12229@@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
12230
12231 #ifdef CONFIG_X86_PAE
12232 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
12233+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
12234+{
12235+ pud_populate(mm, pudp, pmd);
12236+}
12237 #else /* !CONFIG_X86_PAE */
12238 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
12239 {
12240 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
12241 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
12242 }
12243+
12244+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
12245+{
12246+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
12247+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
12248+}
12249 #endif /* CONFIG_X86_PAE */
12250
12251 #if PAGETABLE_LEVELS > 3
12252@@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
12253 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
12254 }
12255
12256+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
12257+{
12258+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
12259+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
12260+}
12261+
12262 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
12263 {
12264 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
12265diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
12266index f2b489c..4f7e2e5 100644
12267--- a/arch/x86/include/asm/pgtable-2level.h
12268+++ b/arch/x86/include/asm/pgtable-2level.h
12269@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
12270
12271 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
12272 {
12273+ pax_open_kernel();
12274 *pmdp = pmd;
12275+ pax_close_kernel();
12276 }
12277
12278 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
12279diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
12280index 4cc9f2b..5fd9226 100644
12281--- a/arch/x86/include/asm/pgtable-3level.h
12282+++ b/arch/x86/include/asm/pgtable-3level.h
12283@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
12284
12285 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
12286 {
12287+ pax_open_kernel();
12288 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
12289+ pax_close_kernel();
12290 }
12291
12292 static inline void native_set_pud(pud_t *pudp, pud_t pud)
12293 {
12294+ pax_open_kernel();
12295 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
12296+ pax_close_kernel();
12297 }
12298
12299 /*
12300diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
12301index a1f780d..5f38ced4 100644
12302--- a/arch/x86/include/asm/pgtable.h
12303+++ b/arch/x86/include/asm/pgtable.h
12304@@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
12305
12306 #ifndef __PAGETABLE_PUD_FOLDED
12307 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
12308+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
12309 #define pgd_clear(pgd) native_pgd_clear(pgd)
12310 #endif
12311
12312@@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
12313
12314 #define arch_end_context_switch(prev) do {} while(0)
12315
12316+#define pax_open_kernel() native_pax_open_kernel()
12317+#define pax_close_kernel() native_pax_close_kernel()
12318 #endif /* CONFIG_PARAVIRT */
12319
12320+#define __HAVE_ARCH_PAX_OPEN_KERNEL
12321+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
12322+
12323+#ifdef CONFIG_PAX_KERNEXEC
12324+static inline unsigned long native_pax_open_kernel(void)
12325+{
12326+ unsigned long cr0;
12327+
12328+ preempt_disable();
12329+ barrier();
12330+ cr0 = read_cr0() ^ X86_CR0_WP;
12331+ BUG_ON(unlikely(cr0 & X86_CR0_WP));
12332+ write_cr0(cr0);
12333+ return cr0 ^ X86_CR0_WP;
12334+}
12335+
12336+static inline unsigned long native_pax_close_kernel(void)
12337+{
12338+ unsigned long cr0;
12339+
12340+ cr0 = read_cr0() ^ X86_CR0_WP;
12341+ BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
12342+ write_cr0(cr0);
12343+ barrier();
12344+ preempt_enable_no_resched();
12345+ return cr0 ^ X86_CR0_WP;
12346+}
12347+#else
12348+static inline unsigned long native_pax_open_kernel(void) { return 0; }
12349+static inline unsigned long native_pax_close_kernel(void) { return 0; }
12350+#endif
12351+
12352 /*
12353 * The following only work if pte_present() is true.
12354 * Undefined behaviour if not..
12355 */
12356+static inline int pte_user(pte_t pte)
12357+{
12358+ return pte_val(pte) & _PAGE_USER;
12359+}
12360+
12361 static inline int pte_dirty(pte_t pte)
12362 {
12363 return pte_flags(pte) & _PAGE_DIRTY;
12364@@ -195,9 +235,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
12365 return pte_clear_flags(pte, _PAGE_RW);
12366 }
12367
12368+static inline pte_t pte_mkread(pte_t pte)
12369+{
12370+ return __pte(pte_val(pte) | _PAGE_USER);
12371+}
12372+
12373 static inline pte_t pte_mkexec(pte_t pte)
12374 {
12375- return pte_clear_flags(pte, _PAGE_NX);
12376+#ifdef CONFIG_X86_PAE
12377+ if (__supported_pte_mask & _PAGE_NX)
12378+ return pte_clear_flags(pte, _PAGE_NX);
12379+ else
12380+#endif
12381+ return pte_set_flags(pte, _PAGE_USER);
12382+}
12383+
12384+static inline pte_t pte_exprotect(pte_t pte)
12385+{
12386+#ifdef CONFIG_X86_PAE
12387+ if (__supported_pte_mask & _PAGE_NX)
12388+ return pte_set_flags(pte, _PAGE_NX);
12389+ else
12390+#endif
12391+ return pte_clear_flags(pte, _PAGE_USER);
12392 }
12393
12394 static inline pte_t pte_mkdirty(pte_t pte)
12395@@ -389,6 +449,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
12396 #endif
12397
12398 #ifndef __ASSEMBLY__
12399+
12400+#ifdef CONFIG_PAX_PER_CPU_PGD
12401+extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
12402+static inline pgd_t *get_cpu_pgd(unsigned int cpu)
12403+{
12404+ return cpu_pgd[cpu];
12405+}
12406+#endif
12407+
12408 #include <linux/mm_types.h>
12409
12410 static inline int pte_none(pte_t pte)
12411@@ -565,7 +634,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
12412
12413 static inline int pgd_bad(pgd_t pgd)
12414 {
12415- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
12416+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
12417 }
12418
12419 static inline int pgd_none(pgd_t pgd)
12420@@ -588,7 +657,12 @@ static inline int pgd_none(pgd_t pgd)
12421 * pgd_offset() returns a (pgd_t *)
12422 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
12423 */
12424-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
12425+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
12426+
12427+#ifdef CONFIG_PAX_PER_CPU_PGD
12428+#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
12429+#endif
12430+
12431 /*
12432 * a shortcut which implies the use of the kernel's pgd, instead
12433 * of a process's
12434@@ -599,6 +673,20 @@ static inline int pgd_none(pgd_t pgd)
12435 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
12436 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
12437
12438+#ifdef CONFIG_X86_32
12439+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
12440+#else
12441+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
12442+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
12443+
12444+#ifdef CONFIG_PAX_MEMORY_UDEREF
12445+#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
12446+#else
12447+#define PAX_USER_SHADOW_BASE (_AC(0,UL))
12448+#endif
12449+
12450+#endif
12451+
12452 #ifndef __ASSEMBLY__
12453
12454 extern int direct_gbpages;
12455@@ -763,11 +851,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
12456 * dst and src can be on the same page, but the range must not overlap,
12457 * and must not cross a page boundary.
12458 */
12459-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
12460+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
12461 {
12462- memcpy(dst, src, count * sizeof(pgd_t));
12463+ pax_open_kernel();
12464+ while (count--)
12465+ *dst++ = *src++;
12466+ pax_close_kernel();
12467 }
12468
12469+#ifdef CONFIG_PAX_PER_CPU_PGD
12470+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
12471+#endif
12472+
12473+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12474+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
12475+#else
12476+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
12477+#endif
12478
12479 #include <asm-generic/pgtable.h>
12480 #endif /* __ASSEMBLY__ */
12481diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
12482index 8faa215..a8a17ea 100644
12483--- a/arch/x86/include/asm/pgtable_32.h
12484+++ b/arch/x86/include/asm/pgtable_32.h
12485@@ -25,9 +25,6 @@
12486 struct mm_struct;
12487 struct vm_area_struct;
12488
12489-extern pgd_t swapper_pg_dir[1024];
12490-extern pgd_t initial_page_table[1024];
12491-
12492 static inline void pgtable_cache_init(void) { }
12493 static inline void check_pgt_cache(void) { }
12494 void paging_init(void);
12495@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
12496 # include <asm/pgtable-2level.h>
12497 #endif
12498
12499+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
12500+extern pgd_t initial_page_table[PTRS_PER_PGD];
12501+#ifdef CONFIG_X86_PAE
12502+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
12503+#endif
12504+
12505 #if defined(CONFIG_HIGHPTE)
12506 #define pte_offset_map(dir, address) \
12507 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
12508@@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
12509 /* Clear a kernel PTE and flush it from the TLB */
12510 #define kpte_clear_flush(ptep, vaddr) \
12511 do { \
12512+ pax_open_kernel(); \
12513 pte_clear(&init_mm, (vaddr), (ptep)); \
12514+ pax_close_kernel(); \
12515 __flush_tlb_one((vaddr)); \
12516 } while (0)
12517
12518@@ -75,6 +80,9 @@ do { \
12519
12520 #endif /* !__ASSEMBLY__ */
12521
12522+#define HAVE_ARCH_UNMAPPED_AREA
12523+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
12524+
12525 /*
12526 * kern_addr_valid() is (1) for FLATMEM and (0) for
12527 * SPARSEMEM and DISCONTIGMEM
12528diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
12529index ed5903b..c7fe163 100644
12530--- a/arch/x86/include/asm/pgtable_32_types.h
12531+++ b/arch/x86/include/asm/pgtable_32_types.h
12532@@ -8,7 +8,7 @@
12533 */
12534 #ifdef CONFIG_X86_PAE
12535 # include <asm/pgtable-3level_types.h>
12536-# define PMD_SIZE (1UL << PMD_SHIFT)
12537+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
12538 # define PMD_MASK (~(PMD_SIZE - 1))
12539 #else
12540 # include <asm/pgtable-2level_types.h>
12541@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
12542 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
12543 #endif
12544
12545+#ifdef CONFIG_PAX_KERNEXEC
12546+#ifndef __ASSEMBLY__
12547+extern unsigned char MODULES_EXEC_VADDR[];
12548+extern unsigned char MODULES_EXEC_END[];
12549+#endif
12550+#include <asm/boot.h>
12551+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
12552+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
12553+#else
12554+#define ktla_ktva(addr) (addr)
12555+#define ktva_ktla(addr) (addr)
12556+#endif
12557+
12558 #define MODULES_VADDR VMALLOC_START
12559 #define MODULES_END VMALLOC_END
12560 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
12561diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
12562index 47356f9..deb94a2 100644
12563--- a/arch/x86/include/asm/pgtable_64.h
12564+++ b/arch/x86/include/asm/pgtable_64.h
12565@@ -16,10 +16,14 @@
12566
12567 extern pud_t level3_kernel_pgt[512];
12568 extern pud_t level3_ident_pgt[512];
12569+extern pud_t level3_vmalloc_start_pgt[512];
12570+extern pud_t level3_vmalloc_end_pgt[512];
12571+extern pud_t level3_vmemmap_pgt[512];
12572+extern pud_t level2_vmemmap_pgt[512];
12573 extern pmd_t level2_kernel_pgt[512];
12574 extern pmd_t level2_fixmap_pgt[512];
12575-extern pmd_t level2_ident_pgt[512];
12576-extern pgd_t init_level4_pgt[];
12577+extern pmd_t level2_ident_pgt[512*2];
12578+extern pgd_t init_level4_pgt[512];
12579
12580 #define swapper_pg_dir init_level4_pgt
12581
12582@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
12583
12584 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
12585 {
12586+ pax_open_kernel();
12587 *pmdp = pmd;
12588+ pax_close_kernel();
12589 }
12590
12591 static inline void native_pmd_clear(pmd_t *pmd)
12592@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
12593
12594 static inline void native_set_pud(pud_t *pudp, pud_t pud)
12595 {
12596+ pax_open_kernel();
12597 *pudp = pud;
12598+ pax_close_kernel();
12599 }
12600
12601 static inline void native_pud_clear(pud_t *pud)
12602@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
12603
12604 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
12605 {
12606+ pax_open_kernel();
12607+ *pgdp = pgd;
12608+ pax_close_kernel();
12609+}
12610+
12611+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
12612+{
12613 *pgdp = pgd;
12614 }
12615
12616diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
12617index 766ea16..5b96cb3 100644
12618--- a/arch/x86/include/asm/pgtable_64_types.h
12619+++ b/arch/x86/include/asm/pgtable_64_types.h
12620@@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
12621 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
12622 #define MODULES_END _AC(0xffffffffff000000, UL)
12623 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
12624+#define MODULES_EXEC_VADDR MODULES_VADDR
12625+#define MODULES_EXEC_END MODULES_END
12626+
12627+#define ktla_ktva(addr) (addr)
12628+#define ktva_ktla(addr) (addr)
12629
12630 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
12631diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
12632index ec8a1fc..7ccb593 100644
12633--- a/arch/x86/include/asm/pgtable_types.h
12634+++ b/arch/x86/include/asm/pgtable_types.h
12635@@ -16,13 +16,12 @@
12636 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
12637 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
12638 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
12639-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
12640+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
12641 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
12642 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
12643 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
12644-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
12645-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
12646-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
12647+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
12648+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
12649 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
12650
12651 /* If _PAGE_BIT_PRESENT is clear, we use these: */
12652@@ -40,7 +39,6 @@
12653 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
12654 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
12655 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
12656-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
12657 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
12658 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
12659 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
12660@@ -57,8 +55,10 @@
12661
12662 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
12663 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
12664-#else
12665+#elif defined(CONFIG_KMEMCHECK)
12666 #define _PAGE_NX (_AT(pteval_t, 0))
12667+#else
12668+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
12669 #endif
12670
12671 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
12672@@ -96,6 +96,9 @@
12673 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
12674 _PAGE_ACCESSED)
12675
12676+#define PAGE_READONLY_NOEXEC PAGE_READONLY
12677+#define PAGE_SHARED_NOEXEC PAGE_SHARED
12678+
12679 #define __PAGE_KERNEL_EXEC \
12680 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
12681 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
12682@@ -106,7 +109,7 @@
12683 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
12684 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
12685 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
12686-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
12687+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
12688 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
12689 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
12690 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
12691@@ -168,8 +171,8 @@
12692 * bits are combined, this will alow user to access the high address mapped
12693 * VDSO in the presence of CONFIG_COMPAT_VDSO
12694 */
12695-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
12696-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
12697+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
12698+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
12699 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
12700 #endif
12701
12702@@ -207,7 +210,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
12703 {
12704 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
12705 }
12706+#endif
12707
12708+#if PAGETABLE_LEVELS == 3
12709+#include <asm-generic/pgtable-nopud.h>
12710+#endif
12711+
12712+#if PAGETABLE_LEVELS == 2
12713+#include <asm-generic/pgtable-nopmd.h>
12714+#endif
12715+
12716+#ifndef __ASSEMBLY__
12717 #if PAGETABLE_LEVELS > 3
12718 typedef struct { pudval_t pud; } pud_t;
12719
12720@@ -221,8 +234,6 @@ static inline pudval_t native_pud_val(pud_t pud)
12721 return pud.pud;
12722 }
12723 #else
12724-#include <asm-generic/pgtable-nopud.h>
12725-
12726 static inline pudval_t native_pud_val(pud_t pud)
12727 {
12728 return native_pgd_val(pud.pgd);
12729@@ -242,8 +253,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
12730 return pmd.pmd;
12731 }
12732 #else
12733-#include <asm-generic/pgtable-nopmd.h>
12734-
12735 static inline pmdval_t native_pmd_val(pmd_t pmd)
12736 {
12737 return native_pgd_val(pmd.pud.pgd);
12738@@ -283,7 +292,6 @@ typedef struct page *pgtable_t;
12739
12740 extern pteval_t __supported_pte_mask;
12741 extern void set_nx(void);
12742-extern int nx_enabled;
12743
12744 #define pgprot_writecombine pgprot_writecombine
12745 extern pgprot_t pgprot_writecombine(pgprot_t prot);
12746diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
12747index ad1fc85..0b15fe1 100644
12748--- a/arch/x86/include/asm/processor.h
12749+++ b/arch/x86/include/asm/processor.h
12750@@ -289,7 +289,7 @@ struct tss_struct {
12751
12752 } ____cacheline_aligned;
12753
12754-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
12755+extern struct tss_struct init_tss[NR_CPUS];
12756
12757 /*
12758 * Save the original ist values for checking stack pointers during debugging
12759@@ -818,11 +818,18 @@ static inline void spin_lock_prefetch(const void *x)
12760 */
12761 #define TASK_SIZE PAGE_OFFSET
12762 #define TASK_SIZE_MAX TASK_SIZE
12763+
12764+#ifdef CONFIG_PAX_SEGMEXEC
12765+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
12766+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
12767+#else
12768 #define STACK_TOP TASK_SIZE
12769-#define STACK_TOP_MAX STACK_TOP
12770+#endif
12771+
12772+#define STACK_TOP_MAX TASK_SIZE
12773
12774 #define INIT_THREAD { \
12775- .sp0 = sizeof(init_stack) + (long)&init_stack, \
12776+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
12777 .vm86_info = NULL, \
12778 .sysenter_cs = __KERNEL_CS, \
12779 .io_bitmap_ptr = NULL, \
12780@@ -836,7 +843,7 @@ static inline void spin_lock_prefetch(const void *x)
12781 */
12782 #define INIT_TSS { \
12783 .x86_tss = { \
12784- .sp0 = sizeof(init_stack) + (long)&init_stack, \
12785+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
12786 .ss0 = __KERNEL_DS, \
12787 .ss1 = __KERNEL_CS, \
12788 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
12789@@ -847,11 +854,7 @@ static inline void spin_lock_prefetch(const void *x)
12790 extern unsigned long thread_saved_pc(struct task_struct *tsk);
12791
12792 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
12793-#define KSTK_TOP(info) \
12794-({ \
12795- unsigned long *__ptr = (unsigned long *)(info); \
12796- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
12797-})
12798+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
12799
12800 /*
12801 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
12802@@ -866,7 +869,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
12803 #define task_pt_regs(task) \
12804 ({ \
12805 struct pt_regs *__regs__; \
12806- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
12807+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
12808 __regs__ - 1; \
12809 })
12810
12811@@ -876,13 +879,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
12812 /*
12813 * User space process size. 47bits minus one guard page.
12814 */
12815-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
12816+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
12817
12818 /* This decides where the kernel will search for a free chunk of vm
12819 * space during mmap's.
12820 */
12821 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
12822- 0xc0000000 : 0xFFFFe000)
12823+ 0xc0000000 : 0xFFFFf000)
12824
12825 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
12826 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
12827@@ -893,11 +896,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
12828 #define STACK_TOP_MAX TASK_SIZE_MAX
12829
12830 #define INIT_THREAD { \
12831- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
12832+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
12833 }
12834
12835 #define INIT_TSS { \
12836- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
12837+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
12838 }
12839
12840 /*
12841@@ -925,6 +928,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
12842 */
12843 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
12844
12845+#ifdef CONFIG_PAX_SEGMEXEC
12846+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
12847+#endif
12848+
12849 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
12850
12851 /* Get/set a process' ability to use the timestamp counter instruction */
12852@@ -985,12 +992,12 @@ extern bool cpu_has_amd_erratum(const int *);
12853 #define cpu_has_amd_erratum(x) (false)
12854 #endif /* CONFIG_CPU_SUP_AMD */
12855
12856-extern unsigned long arch_align_stack(unsigned long sp);
12857+#define arch_align_stack(x) ((x) & ~0xfUL)
12858 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
12859
12860 void default_idle(void);
12861 bool set_pm_idle_to_default(void);
12862
12863-void stop_this_cpu(void *dummy);
12864+void stop_this_cpu(void *dummy) __noreturn;
12865
12866 #endif /* _ASM_X86_PROCESSOR_H */
12867diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
12868index 19f16eb..b50624b 100644
12869--- a/arch/x86/include/asm/ptrace.h
12870+++ b/arch/x86/include/asm/ptrace.h
12871@@ -155,28 +155,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
12872 }
12873
12874 /*
12875- * user_mode_vm(regs) determines whether a register set came from user mode.
12876+ * user_mode(regs) determines whether a register set came from user mode.
12877 * This is true if V8086 mode was enabled OR if the register set was from
12878 * protected mode with RPL-3 CS value. This tricky test checks that with
12879 * one comparison. Many places in the kernel can bypass this full check
12880- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
12881+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
12882+ * be used.
12883 */
12884-static inline int user_mode(struct pt_regs *regs)
12885+static inline int user_mode_novm(struct pt_regs *regs)
12886 {
12887 #ifdef CONFIG_X86_32
12888 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
12889 #else
12890- return !!(regs->cs & 3);
12891+ return !!(regs->cs & SEGMENT_RPL_MASK);
12892 #endif
12893 }
12894
12895-static inline int user_mode_vm(struct pt_regs *regs)
12896+static inline int user_mode(struct pt_regs *regs)
12897 {
12898 #ifdef CONFIG_X86_32
12899 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
12900 USER_RPL;
12901 #else
12902- return user_mode(regs);
12903+ return user_mode_novm(regs);
12904 #endif
12905 }
12906
12907@@ -192,15 +193,16 @@ static inline int v8086_mode(struct pt_regs *regs)
12908 #ifdef CONFIG_X86_64
12909 static inline bool user_64bit_mode(struct pt_regs *regs)
12910 {
12911+ unsigned long cs = regs->cs & 0xffff;
12912 #ifndef CONFIG_PARAVIRT
12913 /*
12914 * On non-paravirt systems, this is the only long mode CPL 3
12915 * selector. We do not allow long mode selectors in the LDT.
12916 */
12917- return regs->cs == __USER_CS;
12918+ return cs == __USER_CS;
12919 #else
12920 /* Headers are too twisted for this to go in paravirt.h. */
12921- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
12922+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
12923 #endif
12924 }
12925 #endif
12926diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
12927index fe1ec5b..dc5c3fe 100644
12928--- a/arch/x86/include/asm/realmode.h
12929+++ b/arch/x86/include/asm/realmode.h
12930@@ -22,16 +22,14 @@ struct real_mode_header {
12931 #endif
12932 /* APM/BIOS reboot */
12933 u32 machine_real_restart_asm;
12934-#ifdef CONFIG_X86_64
12935 u32 machine_real_restart_seg;
12936-#endif
12937 };
12938
12939 /* This must match data at trampoline_32/64.S */
12940 struct trampoline_header {
12941 #ifdef CONFIG_X86_32
12942 u32 start;
12943- u16 gdt_pad;
12944+ u16 boot_cs;
12945 u16 gdt_limit;
12946 u32 gdt_base;
12947 #else
12948diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
12949index a82c4f1..ac45053 100644
12950--- a/arch/x86/include/asm/reboot.h
12951+++ b/arch/x86/include/asm/reboot.h
12952@@ -6,13 +6,13 @@
12953 struct pt_regs;
12954
12955 struct machine_ops {
12956- void (*restart)(char *cmd);
12957- void (*halt)(void);
12958- void (*power_off)(void);
12959+ void (* __noreturn restart)(char *cmd);
12960+ void (* __noreturn halt)(void);
12961+ void (* __noreturn power_off)(void);
12962 void (*shutdown)(void);
12963 void (*crash_shutdown)(struct pt_regs *);
12964- void (*emergency_restart)(void);
12965-};
12966+ void (* __noreturn emergency_restart)(void);
12967+} __no_const;
12968
12969 extern struct machine_ops machine_ops;
12970
12971diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
12972index 2dbe4a7..ce1db00 100644
12973--- a/arch/x86/include/asm/rwsem.h
12974+++ b/arch/x86/include/asm/rwsem.h
12975@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
12976 {
12977 asm volatile("# beginning down_read\n\t"
12978 LOCK_PREFIX _ASM_INC "(%1)\n\t"
12979+
12980+#ifdef CONFIG_PAX_REFCOUNT
12981+ "jno 0f\n"
12982+ LOCK_PREFIX _ASM_DEC "(%1)\n"
12983+ "int $4\n0:\n"
12984+ _ASM_EXTABLE(0b, 0b)
12985+#endif
12986+
12987 /* adds 0x00000001 */
12988 " jns 1f\n"
12989 " call call_rwsem_down_read_failed\n"
12990@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
12991 "1:\n\t"
12992 " mov %1,%2\n\t"
12993 " add %3,%2\n\t"
12994+
12995+#ifdef CONFIG_PAX_REFCOUNT
12996+ "jno 0f\n"
12997+ "sub %3,%2\n"
12998+ "int $4\n0:\n"
12999+ _ASM_EXTABLE(0b, 0b)
13000+#endif
13001+
13002 " jle 2f\n\t"
13003 LOCK_PREFIX " cmpxchg %2,%0\n\t"
13004 " jnz 1b\n\t"
13005@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
13006 long tmp;
13007 asm volatile("# beginning down_write\n\t"
13008 LOCK_PREFIX " xadd %1,(%2)\n\t"
13009+
13010+#ifdef CONFIG_PAX_REFCOUNT
13011+ "jno 0f\n"
13012+ "mov %1,(%2)\n"
13013+ "int $4\n0:\n"
13014+ _ASM_EXTABLE(0b, 0b)
13015+#endif
13016+
13017 /* adds 0xffff0001, returns the old value */
13018 " test %1,%1\n\t"
13019 /* was the count 0 before? */
13020@@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
13021 long tmp;
13022 asm volatile("# beginning __up_read\n\t"
13023 LOCK_PREFIX " xadd %1,(%2)\n\t"
13024+
13025+#ifdef CONFIG_PAX_REFCOUNT
13026+ "jno 0f\n"
13027+ "mov %1,(%2)\n"
13028+ "int $4\n0:\n"
13029+ _ASM_EXTABLE(0b, 0b)
13030+#endif
13031+
13032 /* subtracts 1, returns the old value */
13033 " jns 1f\n\t"
13034 " call call_rwsem_wake\n" /* expects old value in %edx */
13035@@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
13036 long tmp;
13037 asm volatile("# beginning __up_write\n\t"
13038 LOCK_PREFIX " xadd %1,(%2)\n\t"
13039+
13040+#ifdef CONFIG_PAX_REFCOUNT
13041+ "jno 0f\n"
13042+ "mov %1,(%2)\n"
13043+ "int $4\n0:\n"
13044+ _ASM_EXTABLE(0b, 0b)
13045+#endif
13046+
13047 /* subtracts 0xffff0001, returns the old value */
13048 " jns 1f\n\t"
13049 " call call_rwsem_wake\n" /* expects old value in %edx */
13050@@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
13051 {
13052 asm volatile("# beginning __downgrade_write\n\t"
13053 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
13054+
13055+#ifdef CONFIG_PAX_REFCOUNT
13056+ "jno 0f\n"
13057+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
13058+ "int $4\n0:\n"
13059+ _ASM_EXTABLE(0b, 0b)
13060+#endif
13061+
13062 /*
13063 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
13064 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
13065@@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
13066 */
13067 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
13068 {
13069- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
13070+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
13071+
13072+#ifdef CONFIG_PAX_REFCOUNT
13073+ "jno 0f\n"
13074+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
13075+ "int $4\n0:\n"
13076+ _ASM_EXTABLE(0b, 0b)
13077+#endif
13078+
13079 : "+m" (sem->count)
13080 : "er" (delta));
13081 }
13082@@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
13083 */
13084 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
13085 {
13086- return delta + xadd(&sem->count, delta);
13087+ return delta + xadd_check_overflow(&sem->count, delta);
13088 }
13089
13090 #endif /* __KERNEL__ */
13091diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
13092index c48a950..c6d7468 100644
13093--- a/arch/x86/include/asm/segment.h
13094+++ b/arch/x86/include/asm/segment.h
13095@@ -64,10 +64,15 @@
13096 * 26 - ESPFIX small SS
13097 * 27 - per-cpu [ offset to per-cpu data area ]
13098 * 28 - stack_canary-20 [ for stack protector ]
13099- * 29 - unused
13100- * 30 - unused
13101+ * 29 - PCI BIOS CS
13102+ * 30 - PCI BIOS DS
13103 * 31 - TSS for double fault handler
13104 */
13105+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
13106+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
13107+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
13108+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
13109+
13110 #define GDT_ENTRY_TLS_MIN 6
13111 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
13112
13113@@ -79,6 +84,8 @@
13114
13115 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
13116
13117+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
13118+
13119 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
13120
13121 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
13122@@ -104,6 +111,12 @@
13123 #define __KERNEL_STACK_CANARY 0
13124 #endif
13125
13126+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
13127+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
13128+
13129+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
13130+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
13131+
13132 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
13133
13134 /*
13135@@ -141,7 +154,7 @@
13136 */
13137
13138 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
13139-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
13140+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
13141
13142
13143 #else
13144@@ -165,6 +178,8 @@
13145 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
13146 #define __USER32_DS __USER_DS
13147
13148+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
13149+
13150 #define GDT_ENTRY_TSS 8 /* needs two entries */
13151 #define GDT_ENTRY_LDT 10 /* needs two entries */
13152 #define GDT_ENTRY_TLS_MIN 12
13153@@ -185,6 +200,7 @@
13154 #endif
13155
13156 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
13157+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
13158 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
13159 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
13160 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
13161@@ -265,7 +281,7 @@ static inline unsigned long get_limit(unsigned long segment)
13162 {
13163 unsigned long __limit;
13164 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
13165- return __limit + 1;
13166+ return __limit;
13167 }
13168
13169 #endif /* !__ASSEMBLY__ */
13170diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
13171index 4f19a15..9e14f27 100644
13172--- a/arch/x86/include/asm/smp.h
13173+++ b/arch/x86/include/asm/smp.h
13174@@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
13175 /* cpus sharing the last level cache: */
13176 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
13177 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
13178-DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
13179+DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
13180
13181 static inline struct cpumask *cpu_sibling_mask(int cpu)
13182 {
13183@@ -79,7 +79,7 @@ struct smp_ops {
13184
13185 void (*send_call_func_ipi)(const struct cpumask *mask);
13186 void (*send_call_func_single_ipi)(int cpu);
13187-};
13188+} __no_const;
13189
13190 /* Globals due to paravirt */
13191 extern void set_cpu_sibling_map(int cpu);
13192@@ -190,14 +190,8 @@ extern unsigned disabled_cpus __cpuinitdata;
13193 extern int safe_smp_processor_id(void);
13194
13195 #elif defined(CONFIG_X86_64_SMP)
13196-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
13197-
13198-#define stack_smp_processor_id() \
13199-({ \
13200- struct thread_info *ti; \
13201- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
13202- ti->cpu; \
13203-})
13204+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
13205+#define stack_smp_processor_id() raw_smp_processor_id()
13206 #define safe_smp_processor_id() smp_processor_id()
13207
13208 #endif
13209diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
13210index 33692ea..350a534 100644
13211--- a/arch/x86/include/asm/spinlock.h
13212+++ b/arch/x86/include/asm/spinlock.h
13213@@ -172,6 +172,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
13214 static inline void arch_read_lock(arch_rwlock_t *rw)
13215 {
13216 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
13217+
13218+#ifdef CONFIG_PAX_REFCOUNT
13219+ "jno 0f\n"
13220+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
13221+ "int $4\n0:\n"
13222+ _ASM_EXTABLE(0b, 0b)
13223+#endif
13224+
13225 "jns 1f\n"
13226 "call __read_lock_failed\n\t"
13227 "1:\n"
13228@@ -181,6 +189,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
13229 static inline void arch_write_lock(arch_rwlock_t *rw)
13230 {
13231 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
13232+
13233+#ifdef CONFIG_PAX_REFCOUNT
13234+ "jno 0f\n"
13235+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
13236+ "int $4\n0:\n"
13237+ _ASM_EXTABLE(0b, 0b)
13238+#endif
13239+
13240 "jz 1f\n"
13241 "call __write_lock_failed\n\t"
13242 "1:\n"
13243@@ -210,13 +226,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
13244
13245 static inline void arch_read_unlock(arch_rwlock_t *rw)
13246 {
13247- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
13248+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
13249+
13250+#ifdef CONFIG_PAX_REFCOUNT
13251+ "jno 0f\n"
13252+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
13253+ "int $4\n0:\n"
13254+ _ASM_EXTABLE(0b, 0b)
13255+#endif
13256+
13257 :"+m" (rw->lock) : : "memory");
13258 }
13259
13260 static inline void arch_write_unlock(arch_rwlock_t *rw)
13261 {
13262- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
13263+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
13264+
13265+#ifdef CONFIG_PAX_REFCOUNT
13266+ "jno 0f\n"
13267+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
13268+ "int $4\n0:\n"
13269+ _ASM_EXTABLE(0b, 0b)
13270+#endif
13271+
13272 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
13273 }
13274
13275diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
13276index 6a99859..03cb807 100644
13277--- a/arch/x86/include/asm/stackprotector.h
13278+++ b/arch/x86/include/asm/stackprotector.h
13279@@ -47,7 +47,7 @@
13280 * head_32 for boot CPU and setup_per_cpu_areas() for others.
13281 */
13282 #define GDT_STACK_CANARY_INIT \
13283- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
13284+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
13285
13286 /*
13287 * Initialize the stackprotector canary value.
13288@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
13289
13290 static inline void load_stack_canary_segment(void)
13291 {
13292-#ifdef CONFIG_X86_32
13293+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
13294 asm volatile ("mov %0, %%gs" : : "r" (0));
13295 #endif
13296 }
13297diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
13298index 70bbe39..4ae2bd4 100644
13299--- a/arch/x86/include/asm/stacktrace.h
13300+++ b/arch/x86/include/asm/stacktrace.h
13301@@ -11,28 +11,20 @@
13302
13303 extern int kstack_depth_to_print;
13304
13305-struct thread_info;
13306+struct task_struct;
13307 struct stacktrace_ops;
13308
13309-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
13310- unsigned long *stack,
13311- unsigned long bp,
13312- const struct stacktrace_ops *ops,
13313- void *data,
13314- unsigned long *end,
13315- int *graph);
13316+typedef unsigned long walk_stack_t(struct task_struct *task,
13317+ void *stack_start,
13318+ unsigned long *stack,
13319+ unsigned long bp,
13320+ const struct stacktrace_ops *ops,
13321+ void *data,
13322+ unsigned long *end,
13323+ int *graph);
13324
13325-extern unsigned long
13326-print_context_stack(struct thread_info *tinfo,
13327- unsigned long *stack, unsigned long bp,
13328- const struct stacktrace_ops *ops, void *data,
13329- unsigned long *end, int *graph);
13330-
13331-extern unsigned long
13332-print_context_stack_bp(struct thread_info *tinfo,
13333- unsigned long *stack, unsigned long bp,
13334- const struct stacktrace_ops *ops, void *data,
13335- unsigned long *end, int *graph);
13336+extern walk_stack_t print_context_stack;
13337+extern walk_stack_t print_context_stack_bp;
13338
13339 /* Generic stack tracer with callbacks */
13340
13341@@ -40,7 +32,7 @@ struct stacktrace_ops {
13342 void (*address)(void *data, unsigned long address, int reliable);
13343 /* On negative return stop dumping */
13344 int (*stack)(void *data, char *name);
13345- walk_stack_t walk_stack;
13346+ walk_stack_t *walk_stack;
13347 };
13348
13349 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
13350diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
13351index 4ec45b3..a4f0a8a 100644
13352--- a/arch/x86/include/asm/switch_to.h
13353+++ b/arch/x86/include/asm/switch_to.h
13354@@ -108,7 +108,7 @@ do { \
13355 "call __switch_to\n\t" \
13356 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
13357 __switch_canary \
13358- "movq %P[thread_info](%%rsi),%%r8\n\t" \
13359+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
13360 "movq %%rax,%%rdi\n\t" \
13361 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
13362 "jnz ret_from_fork\n\t" \
13363@@ -119,7 +119,7 @@ do { \
13364 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
13365 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
13366 [_tif_fork] "i" (_TIF_FORK), \
13367- [thread_info] "i" (offsetof(struct task_struct, stack)), \
13368+ [thread_info] "m" (current_tinfo), \
13369 [current_task] "m" (current_task) \
13370 __switch_canary_iparam \
13371 : "memory", "cc" __EXTRA_CLOBBER)
13372diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
13373index 2d946e6..e453ec4 100644
13374--- a/arch/x86/include/asm/thread_info.h
13375+++ b/arch/x86/include/asm/thread_info.h
13376@@ -10,6 +10,7 @@
13377 #include <linux/compiler.h>
13378 #include <asm/page.h>
13379 #include <asm/types.h>
13380+#include <asm/percpu.h>
13381
13382 /*
13383 * low level task data that entry.S needs immediate access to
13384@@ -24,7 +25,6 @@ struct exec_domain;
13385 #include <linux/atomic.h>
13386
13387 struct thread_info {
13388- struct task_struct *task; /* main task structure */
13389 struct exec_domain *exec_domain; /* execution domain */
13390 __u32 flags; /* low level flags */
13391 __u32 status; /* thread synchronous flags */
13392@@ -34,19 +34,13 @@ struct thread_info {
13393 mm_segment_t addr_limit;
13394 struct restart_block restart_block;
13395 void __user *sysenter_return;
13396-#ifdef CONFIG_X86_32
13397- unsigned long previous_esp; /* ESP of the previous stack in
13398- case of nested (IRQ) stacks
13399- */
13400- __u8 supervisor_stack[0];
13401-#endif
13402+ unsigned long lowest_stack;
13403 unsigned int sig_on_uaccess_error:1;
13404 unsigned int uaccess_err:1; /* uaccess failed */
13405 };
13406
13407-#define INIT_THREAD_INFO(tsk) \
13408+#define INIT_THREAD_INFO \
13409 { \
13410- .task = &tsk, \
13411 .exec_domain = &default_exec_domain, \
13412 .flags = 0, \
13413 .cpu = 0, \
13414@@ -57,7 +51,7 @@ struct thread_info {
13415 }, \
13416 }
13417
13418-#define init_thread_info (init_thread_union.thread_info)
13419+#define init_thread_info (init_thread_union.stack)
13420 #define init_stack (init_thread_union.stack)
13421
13422 #else /* !__ASSEMBLY__ */
13423@@ -98,6 +92,7 @@ struct thread_info {
13424 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
13425 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
13426 #define TIF_X32 30 /* 32-bit native x86-64 binary */
13427+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
13428
13429 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
13430 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
13431@@ -122,17 +117,18 @@ struct thread_info {
13432 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
13433 #define _TIF_ADDR32 (1 << TIF_ADDR32)
13434 #define _TIF_X32 (1 << TIF_X32)
13435+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
13436
13437 /* work to do in syscall_trace_enter() */
13438 #define _TIF_WORK_SYSCALL_ENTRY \
13439 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
13440 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
13441- _TIF_NOHZ)
13442+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
13443
13444 /* work to do in syscall_trace_leave() */
13445 #define _TIF_WORK_SYSCALL_EXIT \
13446 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
13447- _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
13448+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
13449
13450 /* work to do on interrupt/exception return */
13451 #define _TIF_WORK_MASK \
13452@@ -143,7 +139,7 @@ struct thread_info {
13453 /* work to do on any return to user space */
13454 #define _TIF_ALLWORK_MASK \
13455 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
13456- _TIF_NOHZ)
13457+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
13458
13459 /* Only used for 64 bit */
13460 #define _TIF_DO_NOTIFY_MASK \
13461@@ -159,45 +155,40 @@ struct thread_info {
13462
13463 #define PREEMPT_ACTIVE 0x10000000
13464
13465-#ifdef CONFIG_X86_32
13466-
13467-#define STACK_WARN (THREAD_SIZE/8)
13468-/*
13469- * macros/functions for gaining access to the thread information structure
13470- *
13471- * preempt_count needs to be 1 initially, until the scheduler is functional.
13472- */
13473-#ifndef __ASSEMBLY__
13474-
13475-
13476-/* how to get the current stack pointer from C */
13477-register unsigned long current_stack_pointer asm("esp") __used;
13478-
13479-/* how to get the thread information struct from C */
13480-static inline struct thread_info *current_thread_info(void)
13481-{
13482- return (struct thread_info *)
13483- (current_stack_pointer & ~(THREAD_SIZE - 1));
13484-}
13485-
13486-#else /* !__ASSEMBLY__ */
13487-
13488+#ifdef __ASSEMBLY__
13489 /* how to get the thread information struct from ASM */
13490 #define GET_THREAD_INFO(reg) \
13491- movl $-THREAD_SIZE, reg; \
13492- andl %esp, reg
13493+ mov PER_CPU_VAR(current_tinfo), reg
13494
13495 /* use this one if reg already contains %esp */
13496-#define GET_THREAD_INFO_WITH_ESP(reg) \
13497- andl $-THREAD_SIZE, reg
13498+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
13499+#else
13500+/* how to get the thread information struct from C */
13501+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
13502+
13503+static __always_inline struct thread_info *current_thread_info(void)
13504+{
13505+ return this_cpu_read_stable(current_tinfo);
13506+}
13507+#endif
13508+
13509+#ifdef CONFIG_X86_32
13510+
13511+#define STACK_WARN (THREAD_SIZE/8)
13512+/*
13513+ * macros/functions for gaining access to the thread information structure
13514+ *
13515+ * preempt_count needs to be 1 initially, until the scheduler is functional.
13516+ */
13517+#ifndef __ASSEMBLY__
13518+
13519+/* how to get the current stack pointer from C */
13520+register unsigned long current_stack_pointer asm("esp") __used;
13521
13522 #endif
13523
13524 #else /* X86_32 */
13525
13526-#include <asm/percpu.h>
13527-#define KERNEL_STACK_OFFSET (5*8)
13528-
13529 /*
13530 * macros/functions for gaining access to the thread information structure
13531 * preempt_count needs to be 1 initially, until the scheduler is functional.
13532@@ -205,27 +196,8 @@ static inline struct thread_info *current_thread_info(void)
13533 #ifndef __ASSEMBLY__
13534 DECLARE_PER_CPU(unsigned long, kernel_stack);
13535
13536-static inline struct thread_info *current_thread_info(void)
13537-{
13538- struct thread_info *ti;
13539- ti = (void *)(this_cpu_read_stable(kernel_stack) +
13540- KERNEL_STACK_OFFSET - THREAD_SIZE);
13541- return ti;
13542-}
13543-
13544-#else /* !__ASSEMBLY__ */
13545-
13546-/* how to get the thread information struct from ASM */
13547-#define GET_THREAD_INFO(reg) \
13548- movq PER_CPU_VAR(kernel_stack),reg ; \
13549- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
13550-
13551-/*
13552- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
13553- * a certain register (to be used in assembler memory operands).
13554- */
13555-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
13556-
13557+/* how to get the current stack pointer from C */
13558+register unsigned long current_stack_pointer asm("rsp") __used;
13559 #endif
13560
13561 #endif /* !X86_32 */
13562@@ -286,5 +258,12 @@ static inline bool is_ia32_task(void)
13563 extern void arch_task_cache_init(void);
13564 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
13565 extern void arch_release_task_struct(struct task_struct *tsk);
13566+
13567+#define __HAVE_THREAD_FUNCTIONS
13568+#define task_thread_info(task) (&(task)->tinfo)
13569+#define task_stack_page(task) ((task)->stack)
13570+#define setup_thread_stack(p, org) do {} while (0)
13571+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
13572+
13573 #endif
13574 #endif /* _ASM_X86_THREAD_INFO_H */
13575diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
13576index 7ccf8d1..7cdca12 100644
13577--- a/arch/x86/include/asm/uaccess.h
13578+++ b/arch/x86/include/asm/uaccess.h
13579@@ -7,6 +7,7 @@
13580 #include <linux/compiler.h>
13581 #include <linux/thread_info.h>
13582 #include <linux/string.h>
13583+#include <linux/sched.h>
13584 #include <asm/asm.h>
13585 #include <asm/page.h>
13586 #include <asm/smap.h>
13587@@ -14,6 +15,8 @@
13588 #define VERIFY_READ 0
13589 #define VERIFY_WRITE 1
13590
13591+extern void check_object_size(const void *ptr, unsigned long n, bool to);
13592+
13593 /*
13594 * The fs value determines whether argument validity checking should be
13595 * performed or not. If get_fs() == USER_DS, checking is performed, with
13596@@ -29,7 +32,12 @@
13597
13598 #define get_ds() (KERNEL_DS)
13599 #define get_fs() (current_thread_info()->addr_limit)
13600+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
13601+void __set_fs(mm_segment_t x);
13602+void set_fs(mm_segment_t x);
13603+#else
13604 #define set_fs(x) (current_thread_info()->addr_limit = (x))
13605+#endif
13606
13607 #define segment_eq(a, b) ((a).seg == (b).seg)
13608
13609@@ -77,8 +85,33 @@
13610 * checks that the pointer is in the user space range - after calling
13611 * this function, memory access functions may still return -EFAULT.
13612 */
13613-#define access_ok(type, addr, size) \
13614- (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
13615+#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
13616+#define access_ok(type, addr, size) \
13617+({ \
13618+ long __size = size; \
13619+ unsigned long __addr = (unsigned long)addr; \
13620+ unsigned long __addr_ao = __addr & PAGE_MASK; \
13621+ unsigned long __end_ao = __addr + __size - 1; \
13622+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
13623+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
13624+ while(__addr_ao <= __end_ao) { \
13625+ char __c_ao; \
13626+ __addr_ao += PAGE_SIZE; \
13627+ if (__size > PAGE_SIZE) \
13628+ cond_resched(); \
13629+ if (__get_user(__c_ao, (char __user *)__addr)) \
13630+ break; \
13631+ if (type != VERIFY_WRITE) { \
13632+ __addr = __addr_ao; \
13633+ continue; \
13634+ } \
13635+ if (__put_user(__c_ao, (char __user *)__addr)) \
13636+ break; \
13637+ __addr = __addr_ao; \
13638+ } \
13639+ } \
13640+ __ret_ao; \
13641+})
13642
13643 /*
13644 * The exception table consists of pairs of addresses relative to the
13645@@ -189,13 +222,21 @@ extern int __get_user_bad(void);
13646 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
13647 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
13648
13649-
13650+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
13651+#define __copyuser_seg "gs;"
13652+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
13653+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
13654+#else
13655+#define __copyuser_seg
13656+#define __COPYUSER_SET_ES
13657+#define __COPYUSER_RESTORE_ES
13658+#endif
13659
13660 #ifdef CONFIG_X86_32
13661 #define __put_user_asm_u64(x, addr, err, errret) \
13662 asm volatile(ASM_STAC "\n" \
13663- "1: movl %%eax,0(%2)\n" \
13664- "2: movl %%edx,4(%2)\n" \
13665+ "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
13666+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
13667 "3: " ASM_CLAC "\n" \
13668 ".section .fixup,\"ax\"\n" \
13669 "4: movl %3,%0\n" \
13670@@ -208,8 +249,8 @@ extern int __get_user_bad(void);
13671
13672 #define __put_user_asm_ex_u64(x, addr) \
13673 asm volatile(ASM_STAC "\n" \
13674- "1: movl %%eax,0(%1)\n" \
13675- "2: movl %%edx,4(%1)\n" \
13676+ "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
13677+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
13678 "3: " ASM_CLAC "\n" \
13679 _ASM_EXTABLE_EX(1b, 2b) \
13680 _ASM_EXTABLE_EX(2b, 3b) \
13681@@ -261,7 +302,7 @@ extern void __put_user_8(void);
13682 __typeof__(*(ptr)) __pu_val; \
13683 __chk_user_ptr(ptr); \
13684 might_fault(); \
13685- __pu_val = x; \
13686+ __pu_val = (x); \
13687 switch (sizeof(*(ptr))) { \
13688 case 1: \
13689 __put_user_x(1, __pu_val, ptr, __ret_pu); \
13690@@ -383,7 +424,7 @@ do { \
13691
13692 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
13693 asm volatile(ASM_STAC "\n" \
13694- "1: mov"itype" %2,%"rtype"1\n" \
13695+ "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
13696 "2: " ASM_CLAC "\n" \
13697 ".section .fixup,\"ax\"\n" \
13698 "3: mov %3,%0\n" \
13699@@ -391,7 +432,7 @@ do { \
13700 " jmp 2b\n" \
13701 ".previous\n" \
13702 _ASM_EXTABLE(1b, 3b) \
13703- : "=r" (err), ltype(x) \
13704+ : "=r" (err), ltype (x) \
13705 : "m" (__m(addr)), "i" (errret), "0" (err))
13706
13707 #define __get_user_size_ex(x, ptr, size) \
13708@@ -416,7 +457,7 @@ do { \
13709 } while (0)
13710
13711 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
13712- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
13713+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
13714 "2:\n" \
13715 _ASM_EXTABLE_EX(1b, 2b) \
13716 : ltype(x) : "m" (__m(addr)))
13717@@ -433,13 +474,24 @@ do { \
13718 int __gu_err; \
13719 unsigned long __gu_val; \
13720 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
13721- (x) = (__force __typeof__(*(ptr)))__gu_val; \
13722+ (x) = (__typeof__(*(ptr)))__gu_val; \
13723 __gu_err; \
13724 })
13725
13726 /* FIXME: this hack is definitely wrong -AK */
13727 struct __large_struct { unsigned long buf[100]; };
13728-#define __m(x) (*(struct __large_struct __user *)(x))
13729+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13730+#define ____m(x) \
13731+({ \
13732+ unsigned long ____x = (unsigned long)(x); \
13733+ if (____x < PAX_USER_SHADOW_BASE) \
13734+ ____x += PAX_USER_SHADOW_BASE; \
13735+ (void __user *)____x; \
13736+})
13737+#else
13738+#define ____m(x) (x)
13739+#endif
13740+#define __m(x) (*(struct __large_struct __user *)____m(x))
13741
13742 /*
13743 * Tell gcc we read from memory instead of writing: this is because
13744@@ -448,7 +500,7 @@ struct __large_struct { unsigned long buf[100]; };
13745 */
13746 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
13747 asm volatile(ASM_STAC "\n" \
13748- "1: mov"itype" %"rtype"1,%2\n" \
13749+ "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
13750 "2: " ASM_CLAC "\n" \
13751 ".section .fixup,\"ax\"\n" \
13752 "3: mov %3,%0\n" \
13753@@ -456,10 +508,10 @@ struct __large_struct { unsigned long buf[100]; };
13754 ".previous\n" \
13755 _ASM_EXTABLE(1b, 3b) \
13756 : "=r"(err) \
13757- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
13758+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
13759
13760 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
13761- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
13762+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
13763 "2:\n" \
13764 _ASM_EXTABLE_EX(1b, 2b) \
13765 : : ltype(x), "m" (__m(addr)))
13766@@ -498,8 +550,12 @@ struct __large_struct { unsigned long buf[100]; };
13767 * On error, the variable @x is set to zero.
13768 */
13769
13770+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13771+#define __get_user(x, ptr) get_user((x), (ptr))
13772+#else
13773 #define __get_user(x, ptr) \
13774 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
13775+#endif
13776
13777 /**
13778 * __put_user: - Write a simple value into user space, with less checking.
13779@@ -521,8 +577,12 @@ struct __large_struct { unsigned long buf[100]; };
13780 * Returns zero on success, or -EFAULT on error.
13781 */
13782
13783+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13784+#define __put_user(x, ptr) put_user((x), (ptr))
13785+#else
13786 #define __put_user(x, ptr) \
13787 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
13788+#endif
13789
13790 #define __get_user_unaligned __get_user
13791 #define __put_user_unaligned __put_user
13792@@ -540,7 +600,7 @@ struct __large_struct { unsigned long buf[100]; };
13793 #define get_user_ex(x, ptr) do { \
13794 unsigned long __gue_val; \
13795 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
13796- (x) = (__force __typeof__(*(ptr)))__gue_val; \
13797+ (x) = (__typeof__(*(ptr)))__gue_val; \
13798 } while (0)
13799
13800 #ifdef CONFIG_X86_WP_WORKS_OK
13801@@ -574,8 +634,8 @@ strncpy_from_user(char *dst, const char __user *src, long count);
13802 extern __must_check long strlen_user(const char __user *str);
13803 extern __must_check long strnlen_user(const char __user *str, long n);
13804
13805-unsigned long __must_check clear_user(void __user *mem, unsigned long len);
13806-unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
13807+unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13808+unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13809
13810 /*
13811 * movsl can be slow when source and dest are not both 8-byte aligned
13812diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
13813index 7f760a9..00f93c0 100644
13814--- a/arch/x86/include/asm/uaccess_32.h
13815+++ b/arch/x86/include/asm/uaccess_32.h
13816@@ -11,15 +11,15 @@
13817 #include <asm/page.h>
13818
13819 unsigned long __must_check __copy_to_user_ll
13820- (void __user *to, const void *from, unsigned long n);
13821+ (void __user *to, const void *from, unsigned long n) __size_overflow(3);
13822 unsigned long __must_check __copy_from_user_ll
13823- (void *to, const void __user *from, unsigned long n);
13824+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
13825 unsigned long __must_check __copy_from_user_ll_nozero
13826- (void *to, const void __user *from, unsigned long n);
13827+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
13828 unsigned long __must_check __copy_from_user_ll_nocache
13829- (void *to, const void __user *from, unsigned long n);
13830+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
13831 unsigned long __must_check __copy_from_user_ll_nocache_nozero
13832- (void *to, const void __user *from, unsigned long n);
13833+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
13834
13835 /**
13836 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
13837@@ -43,6 +43,9 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
13838 static __always_inline unsigned long __must_check
13839 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
13840 {
13841+ if ((long)n < 0)
13842+ return n;
13843+
13844 if (__builtin_constant_p(n)) {
13845 unsigned long ret;
13846
13847@@ -61,6 +64,8 @@ __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
13848 return ret;
13849 }
13850 }
13851+ if (!__builtin_constant_p(n))
13852+ check_object_size(from, n, true);
13853 return __copy_to_user_ll(to, from, n);
13854 }
13855
13856@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
13857 __copy_to_user(void __user *to, const void *from, unsigned long n)
13858 {
13859 might_fault();
13860+
13861 return __copy_to_user_inatomic(to, from, n);
13862 }
13863
13864 static __always_inline unsigned long
13865 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
13866 {
13867+ if ((long)n < 0)
13868+ return n;
13869+
13870 /* Avoid zeroing the tail if the copy fails..
13871 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
13872 * but as the zeroing behaviour is only significant when n is not
13873@@ -137,6 +146,10 @@ static __always_inline unsigned long
13874 __copy_from_user(void *to, const void __user *from, unsigned long n)
13875 {
13876 might_fault();
13877+
13878+ if ((long)n < 0)
13879+ return n;
13880+
13881 if (__builtin_constant_p(n)) {
13882 unsigned long ret;
13883
13884@@ -152,6 +165,8 @@ __copy_from_user(void *to, const void __user *from, unsigned long n)
13885 return ret;
13886 }
13887 }
13888+ if (!__builtin_constant_p(n))
13889+ check_object_size(to, n, false);
13890 return __copy_from_user_ll(to, from, n);
13891 }
13892
13893@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
13894 const void __user *from, unsigned long n)
13895 {
13896 might_fault();
13897+
13898+ if ((long)n < 0)
13899+ return n;
13900+
13901 if (__builtin_constant_p(n)) {
13902 unsigned long ret;
13903
13904@@ -181,15 +200,19 @@ static __always_inline unsigned long
13905 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
13906 unsigned long n)
13907 {
13908- return __copy_from_user_ll_nocache_nozero(to, from, n);
13909+ if ((long)n < 0)
13910+ return n;
13911+
13912+ return __copy_from_user_ll_nocache_nozero(to, from, n);
13913 }
13914
13915-unsigned long __must_check copy_to_user(void __user *to,
13916- const void *from, unsigned long n);
13917-unsigned long __must_check _copy_from_user(void *to,
13918- const void __user *from,
13919- unsigned long n);
13920-
13921+extern void copy_to_user_overflow(void)
13922+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13923+ __compiletime_error("copy_to_user() buffer size is not provably correct")
13924+#else
13925+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
13926+#endif
13927+;
13928
13929 extern void copy_from_user_overflow(void)
13930 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13931@@ -199,17 +222,61 @@ extern void copy_from_user_overflow(void)
13932 #endif
13933 ;
13934
13935-static inline unsigned long __must_check copy_from_user(void *to,
13936- const void __user *from,
13937- unsigned long n)
13938+/**
13939+ * copy_to_user: - Copy a block of data into user space.
13940+ * @to: Destination address, in user space.
13941+ * @from: Source address, in kernel space.
13942+ * @n: Number of bytes to copy.
13943+ *
13944+ * Context: User context only. This function may sleep.
13945+ *
13946+ * Copy data from kernel space to user space.
13947+ *
13948+ * Returns number of bytes that could not be copied.
13949+ * On success, this will be zero.
13950+ */
13951+static inline unsigned long __must_check
13952+copy_to_user(void __user *to, const void *from, unsigned long n)
13953 {
13954- int sz = __compiletime_object_size(to);
13955+ size_t sz = __compiletime_object_size(from);
13956
13957- if (likely(sz == -1 || sz >= n))
13958- n = _copy_from_user(to, from, n);
13959- else
13960+ if (unlikely(sz != (size_t)-1 && sz < n))
13961+ copy_to_user_overflow();
13962+ else if (access_ok(VERIFY_WRITE, to, n))
13963+ n = __copy_to_user(to, from, n);
13964+ return n;
13965+}
13966+
13967+/**
13968+ * copy_from_user: - Copy a block of data from user space.
13969+ * @to: Destination address, in kernel space.
13970+ * @from: Source address, in user space.
13971+ * @n: Number of bytes to copy.
13972+ *
13973+ * Context: User context only. This function may sleep.
13974+ *
13975+ * Copy data from user space to kernel space.
13976+ *
13977+ * Returns number of bytes that could not be copied.
13978+ * On success, this will be zero.
13979+ *
13980+ * If some data could not be copied, this function will pad the copied
13981+ * data to the requested size using zero bytes.
13982+ */
13983+static inline unsigned long __must_check
13984+copy_from_user(void *to, const void __user *from, unsigned long n)
13985+{
13986+ size_t sz = __compiletime_object_size(to);
13987+
13988+ if (unlikely(sz != (size_t)-1 && sz < n))
13989 copy_from_user_overflow();
13990-
13991+ else if (access_ok(VERIFY_READ, from, n))
13992+ n = __copy_from_user(to, from, n);
13993+ else if ((long)n > 0) {
13994+ if (!__builtin_constant_p(n))
13995+ check_object_size(to, n, false);
13996+ memset(to, 0, n);
13997+ }
13998 return n;
13999 }
14000
14001diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
14002index 142810c..4389299 100644
14003--- a/arch/x86/include/asm/uaccess_64.h
14004+++ b/arch/x86/include/asm/uaccess_64.h
14005@@ -10,6 +10,9 @@
14006 #include <asm/alternative.h>
14007 #include <asm/cpufeature.h>
14008 #include <asm/page.h>
14009+#include <asm/pgtable.h>
14010+
14011+#define set_fs(x) (current_thread_info()->addr_limit = (x))
14012
14013 /*
14014 * Copy To/From Userspace
14015@@ -17,13 +20,13 @@
14016
14017 /* Handles exceptions in both to and from, but doesn't do access_ok */
14018 __must_check unsigned long
14019-copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
14020+copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
14021 __must_check unsigned long
14022-copy_user_generic_string(void *to, const void *from, unsigned len);
14023+copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
14024 __must_check unsigned long
14025-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
14026+copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
14027
14028-static __always_inline __must_check unsigned long
14029+static __always_inline __must_check __size_overflow(3) unsigned long
14030 copy_user_generic(void *to, const void *from, unsigned len)
14031 {
14032 unsigned ret;
14033@@ -41,142 +44,205 @@ copy_user_generic(void *to, const void *from, unsigned len)
14034 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
14035 "=d" (len)),
14036 "1" (to), "2" (from), "3" (len)
14037- : "memory", "rcx", "r8", "r9", "r10", "r11");
14038+ : "memory", "rcx", "r8", "r9", "r11");
14039 return ret;
14040 }
14041
14042+static __always_inline __must_check unsigned long
14043+__copy_to_user(void __user *to, const void *from, unsigned long len) __size_overflow(3);
14044+static __always_inline __must_check unsigned long
14045+__copy_from_user(void *to, const void __user *from, unsigned long len) __size_overflow(3);
14046 __must_check unsigned long
14047-_copy_to_user(void __user *to, const void *from, unsigned len);
14048-__must_check unsigned long
14049-_copy_from_user(void *to, const void __user *from, unsigned len);
14050-__must_check unsigned long
14051-copy_in_user(void __user *to, const void __user *from, unsigned len);
14052+copy_in_user(void __user *to, const void __user *from, unsigned long len) __size_overflow(3);
14053+
14054+extern void copy_to_user_overflow(void)
14055+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
14056+ __compiletime_error("copy_to_user() buffer size is not provably correct")
14057+#else
14058+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
14059+#endif
14060+;
14061+
14062+extern void copy_from_user_overflow(void)
14063+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
14064+ __compiletime_error("copy_from_user() buffer size is not provably correct")
14065+#else
14066+ __compiletime_warning("copy_from_user() buffer size is not provably correct")
14067+#endif
14068+;
14069
14070 static inline unsigned long __must_check copy_from_user(void *to,
14071 const void __user *from,
14072 unsigned long n)
14073 {
14074- int sz = __compiletime_object_size(to);
14075-
14076 might_fault();
14077- if (likely(sz == -1 || sz >= n))
14078- n = _copy_from_user(to, from, n);
14079-#ifdef CONFIG_DEBUG_VM
14080- else
14081- WARN(1, "Buffer overflow detected!\n");
14082-#endif
14083+
14084+ if (access_ok(VERIFY_READ, from, n))
14085+ n = __copy_from_user(to, from, n);
14086+ else if (n < INT_MAX) {
14087+ if (!__builtin_constant_p(n))
14088+ check_object_size(to, n, false);
14089+ memset(to, 0, n);
14090+ }
14091 return n;
14092 }
14093
14094 static __always_inline __must_check
14095-int copy_to_user(void __user *dst, const void *src, unsigned size)
14096+int copy_to_user(void __user *dst, const void *src, unsigned long size)
14097 {
14098 might_fault();
14099
14100- return _copy_to_user(dst, src, size);
14101+ if (access_ok(VERIFY_WRITE, dst, size))
14102+ size = __copy_to_user(dst, src, size);
14103+ return size;
14104 }
14105
14106 static __always_inline __must_check
14107-int __copy_from_user(void *dst, const void __user *src, unsigned size)
14108+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
14109 {
14110- int ret = 0;
14111+ size_t sz = __compiletime_object_size(dst);
14112+ unsigned ret = 0;
14113
14114 might_fault();
14115- if (!__builtin_constant_p(size))
14116- return copy_user_generic(dst, (__force void *)src, size);
14117+
14118+ if (size > INT_MAX)
14119+ return size;
14120+
14121+#ifdef CONFIG_PAX_MEMORY_UDEREF
14122+ if (!__access_ok(VERIFY_READ, src, size))
14123+ return size;
14124+#endif
14125+
14126+ if (unlikely(sz != (size_t)-1 && sz < size)) {
14127+ copy_from_user_overflow();
14128+ return size;
14129+ }
14130+
14131+ if (!__builtin_constant_p(size)) {
14132+ check_object_size(dst, size, false);
14133+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
14134+ }
14135 switch (size) {
14136- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
14137+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
14138 ret, "b", "b", "=q", 1);
14139 return ret;
14140- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
14141+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
14142 ret, "w", "w", "=r", 2);
14143 return ret;
14144- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
14145+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
14146 ret, "l", "k", "=r", 4);
14147 return ret;
14148- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
14149+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
14150 ret, "q", "", "=r", 8);
14151 return ret;
14152 case 10:
14153- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
14154+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
14155 ret, "q", "", "=r", 10);
14156 if (unlikely(ret))
14157 return ret;
14158 __get_user_asm(*(u16 *)(8 + (char *)dst),
14159- (u16 __user *)(8 + (char __user *)src),
14160+ (const u16 __user *)(8 + (const char __user *)src),
14161 ret, "w", "w", "=r", 2);
14162 return ret;
14163 case 16:
14164- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
14165+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
14166 ret, "q", "", "=r", 16);
14167 if (unlikely(ret))
14168 return ret;
14169 __get_user_asm(*(u64 *)(8 + (char *)dst),
14170- (u64 __user *)(8 + (char __user *)src),
14171+ (const u64 __user *)(8 + (const char __user *)src),
14172 ret, "q", "", "=r", 8);
14173 return ret;
14174 default:
14175- return copy_user_generic(dst, (__force void *)src, size);
14176+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
14177 }
14178 }
14179
14180 static __always_inline __must_check
14181-int __copy_to_user(void __user *dst, const void *src, unsigned size)
14182+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
14183 {
14184- int ret = 0;
14185+ size_t sz = __compiletime_object_size(src);
14186+ unsigned ret = 0;
14187
14188 might_fault();
14189- if (!__builtin_constant_p(size))
14190- return copy_user_generic((__force void *)dst, src, size);
14191+
14192+ if (size > INT_MAX)
14193+ return size;
14194+
14195+#ifdef CONFIG_PAX_MEMORY_UDEREF
14196+ if (!__access_ok(VERIFY_WRITE, dst, size))
14197+ return size;
14198+#endif
14199+
14200+ if (unlikely(sz != (size_t)-1 && sz < size)) {
14201+ copy_to_user_overflow();
14202+ return size;
14203+ }
14204+
14205+ if (!__builtin_constant_p(size)) {
14206+ check_object_size(src, size, true);
14207+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
14208+ }
14209 switch (size) {
14210- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
14211+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
14212 ret, "b", "b", "iq", 1);
14213 return ret;
14214- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
14215+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
14216 ret, "w", "w", "ir", 2);
14217 return ret;
14218- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
14219+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
14220 ret, "l", "k", "ir", 4);
14221 return ret;
14222- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
14223+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
14224 ret, "q", "", "er", 8);
14225 return ret;
14226 case 10:
14227- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
14228+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
14229 ret, "q", "", "er", 10);
14230 if (unlikely(ret))
14231 return ret;
14232 asm("":::"memory");
14233- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
14234+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
14235 ret, "w", "w", "ir", 2);
14236 return ret;
14237 case 16:
14238- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
14239+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
14240 ret, "q", "", "er", 16);
14241 if (unlikely(ret))
14242 return ret;
14243 asm("":::"memory");
14244- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
14245+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
14246 ret, "q", "", "er", 8);
14247 return ret;
14248 default:
14249- return copy_user_generic((__force void *)dst, src, size);
14250+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
14251 }
14252 }
14253
14254 static __always_inline __must_check
14255-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
14256+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
14257 {
14258- int ret = 0;
14259+ unsigned ret = 0;
14260
14261 might_fault();
14262+
14263+ if (size > INT_MAX)
14264+ return size;
14265+
14266+#ifdef CONFIG_PAX_MEMORY_UDEREF
14267+ if (!__access_ok(VERIFY_READ, src, size))
14268+ return size;
14269+ if (!__access_ok(VERIFY_WRITE, dst, size))
14270+ return size;
14271+#endif
14272+
14273 if (!__builtin_constant_p(size))
14274- return copy_user_generic((__force void *)dst,
14275- (__force void *)src, size);
14276+ return copy_user_generic((__force_kernel void *)____m(dst),
14277+ (__force_kernel const void *)____m(src), size);
14278 switch (size) {
14279 case 1: {
14280 u8 tmp;
14281- __get_user_asm(tmp, (u8 __user *)src,
14282+ __get_user_asm(tmp, (const u8 __user *)src,
14283 ret, "b", "b", "=q", 1);
14284 if (likely(!ret))
14285 __put_user_asm(tmp, (u8 __user *)dst,
14286@@ -185,7 +251,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
14287 }
14288 case 2: {
14289 u16 tmp;
14290- __get_user_asm(tmp, (u16 __user *)src,
14291+ __get_user_asm(tmp, (const u16 __user *)src,
14292 ret, "w", "w", "=r", 2);
14293 if (likely(!ret))
14294 __put_user_asm(tmp, (u16 __user *)dst,
14295@@ -195,7 +261,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
14296
14297 case 4: {
14298 u32 tmp;
14299- __get_user_asm(tmp, (u32 __user *)src,
14300+ __get_user_asm(tmp, (const u32 __user *)src,
14301 ret, "l", "k", "=r", 4);
14302 if (likely(!ret))
14303 __put_user_asm(tmp, (u32 __user *)dst,
14304@@ -204,7 +270,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
14305 }
14306 case 8: {
14307 u64 tmp;
14308- __get_user_asm(tmp, (u64 __user *)src,
14309+ __get_user_asm(tmp, (const u64 __user *)src,
14310 ret, "q", "", "=r", 8);
14311 if (likely(!ret))
14312 __put_user_asm(tmp, (u64 __user *)dst,
14313@@ -212,41 +278,72 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
14314 return ret;
14315 }
14316 default:
14317- return copy_user_generic((__force void *)dst,
14318- (__force void *)src, size);
14319+ return copy_user_generic((__force_kernel void *)____m(dst),
14320+ (__force_kernel const void *)____m(src), size);
14321 }
14322 }
14323
14324 static __must_check __always_inline int
14325-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
14326+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
14327 {
14328- return copy_user_generic(dst, (__force const void *)src, size);
14329+ if (size > INT_MAX)
14330+ return size;
14331+
14332+#ifdef CONFIG_PAX_MEMORY_UDEREF
14333+ if (!__access_ok(VERIFY_READ, src, size))
14334+ return size;
14335+#endif
14336+
14337+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
14338 }
14339
14340-static __must_check __always_inline int
14341-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
14342+static __must_check __always_inline unsigned long
14343+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
14344 {
14345- return copy_user_generic((__force void *)dst, src, size);
14346+ if (size > INT_MAX)
14347+ return size;
14348+
14349+#ifdef CONFIG_PAX_MEMORY_UDEREF
14350+ if (!__access_ok(VERIFY_WRITE, dst, size))
14351+ return size;
14352+#endif
14353+
14354+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
14355 }
14356
14357-extern long __copy_user_nocache(void *dst, const void __user *src,
14358- unsigned size, int zerorest);
14359+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
14360+ unsigned long size, int zerorest) __size_overflow(3);
14361
14362-static inline int
14363-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
14364+static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
14365 {
14366 might_sleep();
14367+
14368+ if (size > INT_MAX)
14369+ return size;
14370+
14371+#ifdef CONFIG_PAX_MEMORY_UDEREF
14372+ if (!__access_ok(VERIFY_READ, src, size))
14373+ return size;
14374+#endif
14375+
14376 return __copy_user_nocache(dst, src, size, 1);
14377 }
14378
14379-static inline int
14380-__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
14381- unsigned size)
14382+static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
14383+ unsigned long size)
14384 {
14385+ if (size > INT_MAX)
14386+ return size;
14387+
14388+#ifdef CONFIG_PAX_MEMORY_UDEREF
14389+ if (!__access_ok(VERIFY_READ, src, size))
14390+ return size;
14391+#endif
14392+
14393 return __copy_user_nocache(dst, src, size, 0);
14394 }
14395
14396-unsigned long
14397-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
14398+extern unsigned long
14399+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
14400
14401 #endif /* _ASM_X86_UACCESS_64_H */
14402diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
14403index 5b238981..77fdd78 100644
14404--- a/arch/x86/include/asm/word-at-a-time.h
14405+++ b/arch/x86/include/asm/word-at-a-time.h
14406@@ -11,7 +11,7 @@
14407 * and shift, for example.
14408 */
14409 struct word_at_a_time {
14410- const unsigned long one_bits, high_bits;
14411+ unsigned long one_bits, high_bits;
14412 };
14413
14414 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
14415diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
14416index 5769349..d49a4dd 100644
14417--- a/arch/x86/include/asm/x86_init.h
14418+++ b/arch/x86/include/asm/x86_init.h
14419@@ -29,7 +29,7 @@ struct x86_init_mpparse {
14420 void (*mpc_oem_bus_info)(struct mpc_bus *m, char *name);
14421 void (*find_smp_config)(void);
14422 void (*get_smp_config)(unsigned int early);
14423-};
14424+} __no_const;
14425
14426 /**
14427 * struct x86_init_resources - platform specific resource related ops
14428@@ -43,7 +43,7 @@ struct x86_init_resources {
14429 void (*probe_roms)(void);
14430 void (*reserve_resources)(void);
14431 char *(*memory_setup)(void);
14432-};
14433+} __no_const;
14434
14435 /**
14436 * struct x86_init_irqs - platform specific interrupt setup
14437@@ -56,7 +56,7 @@ struct x86_init_irqs {
14438 void (*pre_vector_init)(void);
14439 void (*intr_init)(void);
14440 void (*trap_init)(void);
14441-};
14442+} __no_const;
14443
14444 /**
14445 * struct x86_init_oem - oem platform specific customizing functions
14446@@ -66,7 +66,7 @@ struct x86_init_irqs {
14447 struct x86_init_oem {
14448 void (*arch_setup)(void);
14449 void (*banner)(void);
14450-};
14451+} __no_const;
14452
14453 /**
14454 * struct x86_init_mapping - platform specific initial kernel pagetable setup
14455@@ -77,7 +77,7 @@ struct x86_init_oem {
14456 */
14457 struct x86_init_mapping {
14458 void (*pagetable_reserve)(u64 start, u64 end);
14459-};
14460+} __no_const;
14461
14462 /**
14463 * struct x86_init_paging - platform specific paging functions
14464@@ -88,7 +88,7 @@ struct x86_init_mapping {
14465 */
14466 struct x86_init_paging {
14467 void (*pagetable_init)(void);
14468-};
14469+} __no_const;
14470
14471 /**
14472 * struct x86_init_timers - platform specific timer setup
14473@@ -103,7 +103,7 @@ struct x86_init_timers {
14474 void (*tsc_pre_init)(void);
14475 void (*timer_init)(void);
14476 void (*wallclock_init)(void);
14477-};
14478+} __no_const;
14479
14480 /**
14481 * struct x86_init_iommu - platform specific iommu setup
14482@@ -111,7 +111,7 @@ struct x86_init_timers {
14483 */
14484 struct x86_init_iommu {
14485 int (*iommu_init)(void);
14486-};
14487+} __no_const;
14488
14489 /**
14490 * struct x86_init_pci - platform specific pci init functions
14491@@ -125,7 +125,7 @@ struct x86_init_pci {
14492 int (*init)(void);
14493 void (*init_irq)(void);
14494 void (*fixup_irqs)(void);
14495-};
14496+} __no_const;
14497
14498 /**
14499 * struct x86_init_ops - functions for platform specific setup
14500@@ -141,7 +141,7 @@ struct x86_init_ops {
14501 struct x86_init_timers timers;
14502 struct x86_init_iommu iommu;
14503 struct x86_init_pci pci;
14504-};
14505+} __no_const;
14506
14507 /**
14508 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
14509@@ -152,7 +152,7 @@ struct x86_cpuinit_ops {
14510 void (*setup_percpu_clockev)(void);
14511 void (*early_percpu_clock_init)(void);
14512 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
14513-};
14514+} __no_const;
14515
14516 /**
14517 * struct x86_platform_ops - platform specific runtime functions
14518@@ -178,7 +178,7 @@ struct x86_platform_ops {
14519 void (*save_sched_clock_state)(void);
14520 void (*restore_sched_clock_state)(void);
14521 void (*apic_post_init)(void);
14522-};
14523+} __no_const;
14524
14525 struct pci_dev;
14526
14527@@ -187,14 +187,14 @@ struct x86_msi_ops {
14528 void (*teardown_msi_irq)(unsigned int irq);
14529 void (*teardown_msi_irqs)(struct pci_dev *dev);
14530 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
14531-};
14532+} __no_const;
14533
14534 struct x86_io_apic_ops {
14535 void (*init) (void);
14536 unsigned int (*read) (unsigned int apic, unsigned int reg);
14537 void (*write) (unsigned int apic, unsigned int reg, unsigned int value);
14538 void (*modify)(unsigned int apic, unsigned int reg, unsigned int value);
14539-};
14540+} __no_const;
14541
14542 extern struct x86_init_ops x86_init;
14543 extern struct x86_cpuinit_ops x86_cpuinit;
14544diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
14545index 0415cda..b43d877 100644
14546--- a/arch/x86/include/asm/xsave.h
14547+++ b/arch/x86/include/asm/xsave.h
14548@@ -71,7 +71,9 @@ static inline int xsave_user(struct xsave_struct __user *buf)
14549 return -EFAULT;
14550
14551 __asm__ __volatile__(ASM_STAC "\n"
14552- "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
14553+ "1:"
14554+ __copyuser_seg
14555+ ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
14556 "2: " ASM_CLAC "\n"
14557 ".section .fixup,\"ax\"\n"
14558 "3: movl $-1,%[err]\n"
14559@@ -87,12 +89,14 @@ static inline int xsave_user(struct xsave_struct __user *buf)
14560 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
14561 {
14562 int err;
14563- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
14564+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
14565 u32 lmask = mask;
14566 u32 hmask = mask >> 32;
14567
14568 __asm__ __volatile__(ASM_STAC "\n"
14569- "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
14570+ "1:"
14571+ __copyuser_seg
14572+ ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
14573 "2: " ASM_CLAC "\n"
14574 ".section .fixup,\"ax\"\n"
14575 "3: movl $-1,%[err]\n"
14576diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
14577index 91ce48f..a48ea05 100644
14578--- a/arch/x86/kernel/Makefile
14579+++ b/arch/x86/kernel/Makefile
14580@@ -23,7 +23,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
14581 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
14582 obj-$(CONFIG_IRQ_WORK) += irq_work.o
14583 obj-y += probe_roms.o
14584-obj-$(CONFIG_X86_32) += i386_ksyms_32.o
14585+obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
14586 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
14587 obj-y += syscall_$(BITS).o
14588 obj-$(CONFIG_X86_64) += vsyscall_64.o
14589diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
14590index 11676cf..a8cf3ec 100644
14591--- a/arch/x86/kernel/acpi/sleep.c
14592+++ b/arch/x86/kernel/acpi/sleep.c
14593@@ -74,8 +74,12 @@ int acpi_suspend_lowlevel(void)
14594 #else /* CONFIG_64BIT */
14595 #ifdef CONFIG_SMP
14596 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
14597+
14598+ pax_open_kernel();
14599 early_gdt_descr.address =
14600 (unsigned long)get_cpu_gdt_table(smp_processor_id());
14601+ pax_close_kernel();
14602+
14603 initial_gs = per_cpu_offset(smp_processor_id());
14604 #endif
14605 initial_code = (unsigned long)wakeup_long64;
14606diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
14607index 13ab720..95d5442 100644
14608--- a/arch/x86/kernel/acpi/wakeup_32.S
14609+++ b/arch/x86/kernel/acpi/wakeup_32.S
14610@@ -30,13 +30,11 @@ wakeup_pmode_return:
14611 # and restore the stack ... but you need gdt for this to work
14612 movl saved_context_esp, %esp
14613
14614- movl %cs:saved_magic, %eax
14615- cmpl $0x12345678, %eax
14616+ cmpl $0x12345678, saved_magic
14617 jne bogus_magic
14618
14619 # jump to place where we left off
14620- movl saved_eip, %eax
14621- jmp *%eax
14622+ jmp *(saved_eip)
14623
14624 bogus_magic:
14625 jmp bogus_magic
14626diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
14627index ef5ccca..bd83949 100644
14628--- a/arch/x86/kernel/alternative.c
14629+++ b/arch/x86/kernel/alternative.c
14630@@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
14631 */
14632 for (a = start; a < end; a++) {
14633 instr = (u8 *)&a->instr_offset + a->instr_offset;
14634+
14635+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
14636+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
14637+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
14638+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
14639+#endif
14640+
14641 replacement = (u8 *)&a->repl_offset + a->repl_offset;
14642 BUG_ON(a->replacementlen > a->instrlen);
14643 BUG_ON(a->instrlen > sizeof(insnbuf));
14644@@ -299,10 +306,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
14645 for (poff = start; poff < end; poff++) {
14646 u8 *ptr = (u8 *)poff + *poff;
14647
14648+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
14649+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
14650+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
14651+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
14652+#endif
14653+
14654 if (!*poff || ptr < text || ptr >= text_end)
14655 continue;
14656 /* turn DS segment override prefix into lock prefix */
14657- if (*ptr == 0x3e)
14658+ if (*ktla_ktva(ptr) == 0x3e)
14659 text_poke(ptr, ((unsigned char []){0xf0}), 1);
14660 }
14661 mutex_unlock(&text_mutex);
14662@@ -317,10 +330,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
14663 for (poff = start; poff < end; poff++) {
14664 u8 *ptr = (u8 *)poff + *poff;
14665
14666+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
14667+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
14668+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
14669+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
14670+#endif
14671+
14672 if (!*poff || ptr < text || ptr >= text_end)
14673 continue;
14674 /* turn lock prefix into DS segment override prefix */
14675- if (*ptr == 0xf0)
14676+ if (*ktla_ktva(ptr) == 0xf0)
14677 text_poke(ptr, ((unsigned char []){0x3E}), 1);
14678 }
14679 mutex_unlock(&text_mutex);
14680@@ -468,7 +487,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
14681
14682 BUG_ON(p->len > MAX_PATCH_LEN);
14683 /* prep the buffer with the original instructions */
14684- memcpy(insnbuf, p->instr, p->len);
14685+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
14686 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
14687 (unsigned long)p->instr, p->len);
14688
14689@@ -515,7 +534,7 @@ void __init alternative_instructions(void)
14690 if (!uniproc_patched || num_possible_cpus() == 1)
14691 free_init_pages("SMP alternatives",
14692 (unsigned long)__smp_locks,
14693- (unsigned long)__smp_locks_end);
14694+ PAGE_ALIGN((unsigned long)__smp_locks_end));
14695 #endif
14696
14697 apply_paravirt(__parainstructions, __parainstructions_end);
14698@@ -535,13 +554,17 @@ void __init alternative_instructions(void)
14699 * instructions. And on the local CPU you need to be protected again NMI or MCE
14700 * handlers seeing an inconsistent instruction while you patch.
14701 */
14702-void *__init_or_module text_poke_early(void *addr, const void *opcode,
14703+void *__kprobes text_poke_early(void *addr, const void *opcode,
14704 size_t len)
14705 {
14706 unsigned long flags;
14707 local_irq_save(flags);
14708- memcpy(addr, opcode, len);
14709+
14710+ pax_open_kernel();
14711+ memcpy(ktla_ktva(addr), opcode, len);
14712 sync_core();
14713+ pax_close_kernel();
14714+
14715 local_irq_restore(flags);
14716 /* Could also do a CLFLUSH here to speed up CPU recovery; but
14717 that causes hangs on some VIA CPUs. */
14718@@ -563,36 +586,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
14719 */
14720 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
14721 {
14722- unsigned long flags;
14723- char *vaddr;
14724+ unsigned char *vaddr = ktla_ktva(addr);
14725 struct page *pages[2];
14726- int i;
14727+ size_t i;
14728
14729 if (!core_kernel_text((unsigned long)addr)) {
14730- pages[0] = vmalloc_to_page(addr);
14731- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
14732+ pages[0] = vmalloc_to_page(vaddr);
14733+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
14734 } else {
14735- pages[0] = virt_to_page(addr);
14736+ pages[0] = virt_to_page(vaddr);
14737 WARN_ON(!PageReserved(pages[0]));
14738- pages[1] = virt_to_page(addr + PAGE_SIZE);
14739+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
14740 }
14741 BUG_ON(!pages[0]);
14742- local_irq_save(flags);
14743- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
14744- if (pages[1])
14745- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
14746- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
14747- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
14748- clear_fixmap(FIX_TEXT_POKE0);
14749- if (pages[1])
14750- clear_fixmap(FIX_TEXT_POKE1);
14751- local_flush_tlb();
14752- sync_core();
14753- /* Could also do a CLFLUSH here to speed up CPU recovery; but
14754- that causes hangs on some VIA CPUs. */
14755+ text_poke_early(addr, opcode, len);
14756 for (i = 0; i < len; i++)
14757- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
14758- local_irq_restore(flags);
14759+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
14760 return addr;
14761 }
14762
14763diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
14764index b17416e..be6e5dc 100644
14765--- a/arch/x86/kernel/apic/apic.c
14766+++ b/arch/x86/kernel/apic/apic.c
14767@@ -185,7 +185,7 @@ int first_system_vector = 0xfe;
14768 /*
14769 * Debug level, exported for io_apic.c
14770 */
14771-unsigned int apic_verbosity;
14772+int apic_verbosity;
14773
14774 int pic_mode;
14775
14776@@ -1923,7 +1923,7 @@ void smp_error_interrupt(struct pt_regs *regs)
14777 apic_write(APIC_ESR, 0);
14778 v1 = apic_read(APIC_ESR);
14779 ack_APIC_irq();
14780- atomic_inc(&irq_err_count);
14781+ atomic_inc_unchecked(&irq_err_count);
14782
14783 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
14784 smp_processor_id(), v0 , v1);
14785@@ -2155,7 +2155,9 @@ void __init apic_set_eoi_write(void (*eoi_write)(u32 reg, u32 v))
14786 for (drv = __apicdrivers; drv < __apicdrivers_end; drv++) {
14787 /* Should happen once for each apic */
14788 WARN_ON((*drv)->eoi_write == eoi_write);
14789- (*drv)->eoi_write = eoi_write;
14790+ pax_open_kernel();
14791+ *(void **)&(*drv)->eoi_write = eoi_write;
14792+ pax_close_kernel();
14793 }
14794 }
14795
14796diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
14797index 1817fa9..7bff097 100644
14798--- a/arch/x86/kernel/apic/io_apic.c
14799+++ b/arch/x86/kernel/apic/io_apic.c
14800@@ -1084,7 +1084,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
14801 }
14802 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
14803
14804-void lock_vector_lock(void)
14805+void lock_vector_lock(void) __acquires(vector_lock)
14806 {
14807 /* Used to the online set of cpus does not change
14808 * during assign_irq_vector.
14809@@ -1092,7 +1092,7 @@ void lock_vector_lock(void)
14810 raw_spin_lock(&vector_lock);
14811 }
14812
14813-void unlock_vector_lock(void)
14814+void unlock_vector_lock(void) __releases(vector_lock)
14815 {
14816 raw_spin_unlock(&vector_lock);
14817 }
14818@@ -2411,7 +2411,7 @@ static void ack_apic_edge(struct irq_data *data)
14819 ack_APIC_irq();
14820 }
14821
14822-atomic_t irq_mis_count;
14823+atomic_unchecked_t irq_mis_count;
14824
14825 #ifdef CONFIG_GENERIC_PENDING_IRQ
14826 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
14827@@ -2552,7 +2552,7 @@ static void ack_apic_level(struct irq_data *data)
14828 * at the cpu.
14829 */
14830 if (!(v & (1 << (i & 0x1f)))) {
14831- atomic_inc(&irq_mis_count);
14832+ atomic_inc_unchecked(&irq_mis_count);
14833
14834 eoi_ioapic_irq(irq, cfg);
14835 }
14836diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
14837index d65464e..1035d31 100644
14838--- a/arch/x86/kernel/apm_32.c
14839+++ b/arch/x86/kernel/apm_32.c
14840@@ -412,7 +412,7 @@ static DEFINE_MUTEX(apm_mutex);
14841 * This is for buggy BIOS's that refer to (real mode) segment 0x40
14842 * even though they are called in protected mode.
14843 */
14844-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
14845+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
14846 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
14847
14848 static const char driver_version[] = "1.16ac"; /* no spaces */
14849@@ -590,7 +590,10 @@ static long __apm_bios_call(void *_call)
14850 BUG_ON(cpu != 0);
14851 gdt = get_cpu_gdt_table(cpu);
14852 save_desc_40 = gdt[0x40 / 8];
14853+
14854+ pax_open_kernel();
14855 gdt[0x40 / 8] = bad_bios_desc;
14856+ pax_close_kernel();
14857
14858 apm_irq_save(flags);
14859 APM_DO_SAVE_SEGS;
14860@@ -599,7 +602,11 @@ static long __apm_bios_call(void *_call)
14861 &call->esi);
14862 APM_DO_RESTORE_SEGS;
14863 apm_irq_restore(flags);
14864+
14865+ pax_open_kernel();
14866 gdt[0x40 / 8] = save_desc_40;
14867+ pax_close_kernel();
14868+
14869 put_cpu();
14870
14871 return call->eax & 0xff;
14872@@ -666,7 +673,10 @@ static long __apm_bios_call_simple(void *_call)
14873 BUG_ON(cpu != 0);
14874 gdt = get_cpu_gdt_table(cpu);
14875 save_desc_40 = gdt[0x40 / 8];
14876+
14877+ pax_open_kernel();
14878 gdt[0x40 / 8] = bad_bios_desc;
14879+ pax_close_kernel();
14880
14881 apm_irq_save(flags);
14882 APM_DO_SAVE_SEGS;
14883@@ -674,7 +684,11 @@ static long __apm_bios_call_simple(void *_call)
14884 &call->eax);
14885 APM_DO_RESTORE_SEGS;
14886 apm_irq_restore(flags);
14887+
14888+ pax_open_kernel();
14889 gdt[0x40 / 8] = save_desc_40;
14890+ pax_close_kernel();
14891+
14892 put_cpu();
14893 return error;
14894 }
14895@@ -2345,12 +2359,15 @@ static int __init apm_init(void)
14896 * code to that CPU.
14897 */
14898 gdt = get_cpu_gdt_table(0);
14899+
14900+ pax_open_kernel();
14901 set_desc_base(&gdt[APM_CS >> 3],
14902 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
14903 set_desc_base(&gdt[APM_CS_16 >> 3],
14904 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
14905 set_desc_base(&gdt[APM_DS >> 3],
14906 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
14907+ pax_close_kernel();
14908
14909 proc_create("apm", 0, NULL, &apm_file_ops);
14910
14911diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
14912index 2861082..6d4718e 100644
14913--- a/arch/x86/kernel/asm-offsets.c
14914+++ b/arch/x86/kernel/asm-offsets.c
14915@@ -33,6 +33,8 @@ void common(void) {
14916 OFFSET(TI_status, thread_info, status);
14917 OFFSET(TI_addr_limit, thread_info, addr_limit);
14918 OFFSET(TI_preempt_count, thread_info, preempt_count);
14919+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
14920+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
14921
14922 BLANK();
14923 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
14924@@ -53,8 +55,26 @@ void common(void) {
14925 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
14926 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
14927 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
14928+
14929+#ifdef CONFIG_PAX_KERNEXEC
14930+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
14931 #endif
14932
14933+#ifdef CONFIG_PAX_MEMORY_UDEREF
14934+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
14935+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
14936+#ifdef CONFIG_X86_64
14937+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
14938+#endif
14939+#endif
14940+
14941+#endif
14942+
14943+ BLANK();
14944+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
14945+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
14946+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
14947+
14948 #ifdef CONFIG_XEN
14949 BLANK();
14950 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
14951diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
14952index 1b4754f..fbb4227 100644
14953--- a/arch/x86/kernel/asm-offsets_64.c
14954+++ b/arch/x86/kernel/asm-offsets_64.c
14955@@ -76,6 +76,7 @@ int main(void)
14956 BLANK();
14957 #undef ENTRY
14958
14959+ DEFINE(TSS_size, sizeof(struct tss_struct));
14960 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
14961 BLANK();
14962
14963diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
14964index a0e067d..9c7db16 100644
14965--- a/arch/x86/kernel/cpu/Makefile
14966+++ b/arch/x86/kernel/cpu/Makefile
14967@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
14968 CFLAGS_REMOVE_perf_event.o = -pg
14969 endif
14970
14971-# Make sure load_percpu_segment has no stackprotector
14972-nostackp := $(call cc-option, -fno-stack-protector)
14973-CFLAGS_common.o := $(nostackp)
14974-
14975 obj-y := intel_cacheinfo.o scattered.o topology.o
14976 obj-y += proc.o capflags.o powerflags.o common.o
14977 obj-y += vmware.o hypervisor.o mshyperv.o
14978diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
14979index 1b7d165..b9e2627 100644
14980--- a/arch/x86/kernel/cpu/amd.c
14981+++ b/arch/x86/kernel/cpu/amd.c
14982@@ -738,7 +738,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
14983 unsigned int size)
14984 {
14985 /* AMD errata T13 (order #21922) */
14986- if ((c->x86 == 6)) {
14987+ if (c->x86 == 6) {
14988 /* Duron Rev A0 */
14989 if (c->x86_model == 3 && c->x86_mask == 0)
14990 size = 64;
14991diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
14992index 7505f7b..d59dac0 100644
14993--- a/arch/x86/kernel/cpu/common.c
14994+++ b/arch/x86/kernel/cpu/common.c
14995@@ -86,60 +86,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
14996
14997 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
14998
14999-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
15000-#ifdef CONFIG_X86_64
15001- /*
15002- * We need valid kernel segments for data and code in long mode too
15003- * IRET will check the segment types kkeil 2000/10/28
15004- * Also sysret mandates a special GDT layout
15005- *
15006- * TLS descriptors are currently at a different place compared to i386.
15007- * Hopefully nobody expects them at a fixed place (Wine?)
15008- */
15009- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
15010- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
15011- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
15012- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
15013- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
15014- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
15015-#else
15016- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
15017- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
15018- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
15019- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
15020- /*
15021- * Segments used for calling PnP BIOS have byte granularity.
15022- * They code segments and data segments have fixed 64k limits,
15023- * the transfer segment sizes are set at run time.
15024- */
15025- /* 32-bit code */
15026- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
15027- /* 16-bit code */
15028- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
15029- /* 16-bit data */
15030- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
15031- /* 16-bit data */
15032- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
15033- /* 16-bit data */
15034- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
15035- /*
15036- * The APM segments have byte granularity and their bases
15037- * are set at run time. All have 64k limits.
15038- */
15039- /* 32-bit code */
15040- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
15041- /* 16-bit code */
15042- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
15043- /* data */
15044- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
15045-
15046- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
15047- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
15048- GDT_STACK_CANARY_INIT
15049-#endif
15050-} };
15051-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
15052-
15053 static int __init x86_xsave_setup(char *s)
15054 {
15055 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
15056@@ -389,7 +335,7 @@ void switch_to_new_gdt(int cpu)
15057 {
15058 struct desc_ptr gdt_descr;
15059
15060- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
15061+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
15062 gdt_descr.size = GDT_SIZE - 1;
15063 load_gdt(&gdt_descr);
15064 /* Reload the per-cpu base */
15065@@ -885,6 +831,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
15066 /* Filter out anything that depends on CPUID levels we don't have */
15067 filter_cpuid_features(c, true);
15068
15069+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
15070+ setup_clear_cpu_cap(X86_FEATURE_SEP);
15071+#endif
15072+
15073 /* If the model name is still unset, do table lookup. */
15074 if (!c->x86_model_id[0]) {
15075 const char *p;
15076@@ -1068,10 +1018,12 @@ static __init int setup_disablecpuid(char *arg)
15077 }
15078 __setup("clearcpuid=", setup_disablecpuid);
15079
15080+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
15081+EXPORT_PER_CPU_SYMBOL(current_tinfo);
15082+
15083 #ifdef CONFIG_X86_64
15084 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
15085-struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
15086- (unsigned long) nmi_idt_table };
15087+struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
15088
15089 DEFINE_PER_CPU_FIRST(union irq_stack_union,
15090 irq_stack_union) __aligned(PAGE_SIZE);
15091@@ -1085,7 +1037,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
15092 EXPORT_PER_CPU_SYMBOL(current_task);
15093
15094 DEFINE_PER_CPU(unsigned long, kernel_stack) =
15095- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
15096+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
15097 EXPORT_PER_CPU_SYMBOL(kernel_stack);
15098
15099 DEFINE_PER_CPU(char *, irq_stack_ptr) =
15100@@ -1178,7 +1130,7 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
15101 {
15102 memset(regs, 0, sizeof(struct pt_regs));
15103 regs->fs = __KERNEL_PERCPU;
15104- regs->gs = __KERNEL_STACK_CANARY;
15105+ savesegment(gs, regs->gs);
15106
15107 return regs;
15108 }
15109@@ -1233,7 +1185,7 @@ void __cpuinit cpu_init(void)
15110 int i;
15111
15112 cpu = stack_smp_processor_id();
15113- t = &per_cpu(init_tss, cpu);
15114+ t = init_tss + cpu;
15115 oist = &per_cpu(orig_ist, cpu);
15116
15117 #ifdef CONFIG_NUMA
15118@@ -1259,7 +1211,7 @@ void __cpuinit cpu_init(void)
15119 switch_to_new_gdt(cpu);
15120 loadsegment(fs, 0);
15121
15122- load_idt((const struct desc_ptr *)&idt_descr);
15123+ load_idt(&idt_descr);
15124
15125 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
15126 syscall_init();
15127@@ -1268,7 +1220,6 @@ void __cpuinit cpu_init(void)
15128 wrmsrl(MSR_KERNEL_GS_BASE, 0);
15129 barrier();
15130
15131- x86_configure_nx();
15132 if (cpu != 0)
15133 enable_x2apic();
15134
15135@@ -1321,7 +1272,7 @@ void __cpuinit cpu_init(void)
15136 {
15137 int cpu = smp_processor_id();
15138 struct task_struct *curr = current;
15139- struct tss_struct *t = &per_cpu(init_tss, cpu);
15140+ struct tss_struct *t = init_tss + cpu;
15141 struct thread_struct *thread = &curr->thread;
15142
15143 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
15144diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
15145index 198e019..867575e 100644
15146--- a/arch/x86/kernel/cpu/intel.c
15147+++ b/arch/x86/kernel/cpu/intel.c
15148@@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
15149 * Update the IDT descriptor and reload the IDT so that
15150 * it uses the read-only mapped virtual address.
15151 */
15152- idt_descr.address = fix_to_virt(FIX_F00F_IDT);
15153+ idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
15154 load_idt(&idt_descr);
15155 }
15156 #endif
15157diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
15158index 93c5451..3887433 100644
15159--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
15160+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
15161@@ -983,6 +983,22 @@ static struct attribute *default_attrs[] = {
15162 };
15163
15164 #ifdef CONFIG_AMD_NB
15165+static struct attribute *default_attrs_amd_nb[] = {
15166+ &type.attr,
15167+ &level.attr,
15168+ &coherency_line_size.attr,
15169+ &physical_line_partition.attr,
15170+ &ways_of_associativity.attr,
15171+ &number_of_sets.attr,
15172+ &size.attr,
15173+ &shared_cpu_map.attr,
15174+ &shared_cpu_list.attr,
15175+ NULL,
15176+ NULL,
15177+ NULL,
15178+ NULL
15179+};
15180+
15181 static struct attribute ** __cpuinit amd_l3_attrs(void)
15182 {
15183 static struct attribute **attrs;
15184@@ -993,18 +1009,7 @@ static struct attribute ** __cpuinit amd_l3_attrs(void)
15185
15186 n = ARRAY_SIZE(default_attrs);
15187
15188- if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
15189- n += 2;
15190-
15191- if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
15192- n += 1;
15193-
15194- attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
15195- if (attrs == NULL)
15196- return attrs = default_attrs;
15197-
15198- for (n = 0; default_attrs[n]; n++)
15199- attrs[n] = default_attrs[n];
15200+ attrs = default_attrs_amd_nb;
15201
15202 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
15203 attrs[n++] = &cache_disable_0.attr;
15204@@ -1055,6 +1060,13 @@ static struct kobj_type ktype_cache = {
15205 .default_attrs = default_attrs,
15206 };
15207
15208+#ifdef CONFIG_AMD_NB
15209+static struct kobj_type ktype_cache_amd_nb = {
15210+ .sysfs_ops = &sysfs_ops,
15211+ .default_attrs = default_attrs_amd_nb,
15212+};
15213+#endif
15214+
15215 static struct kobj_type ktype_percpu_entry = {
15216 .sysfs_ops = &sysfs_ops,
15217 };
15218@@ -1120,20 +1132,26 @@ static int __cpuinit cache_add_dev(struct device *dev)
15219 return retval;
15220 }
15221
15222+#ifdef CONFIG_AMD_NB
15223+ amd_l3_attrs();
15224+#endif
15225+
15226 for (i = 0; i < num_cache_leaves; i++) {
15227+ struct kobj_type *ktype;
15228+
15229 this_object = INDEX_KOBJECT_PTR(cpu, i);
15230 this_object->cpu = cpu;
15231 this_object->index = i;
15232
15233 this_leaf = CPUID4_INFO_IDX(cpu, i);
15234
15235- ktype_cache.default_attrs = default_attrs;
15236+ ktype = &ktype_cache;
15237 #ifdef CONFIG_AMD_NB
15238 if (this_leaf->base.nb)
15239- ktype_cache.default_attrs = amd_l3_attrs();
15240+ ktype = &ktype_cache_amd_nb;
15241 #endif
15242 retval = kobject_init_and_add(&(this_object->kobj),
15243- &ktype_cache,
15244+ ktype,
15245 per_cpu(ici_cache_kobject, cpu),
15246 "index%1lu", i);
15247 if (unlikely(retval)) {
15248diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
15249index 46cbf86..55c7292 100644
15250--- a/arch/x86/kernel/cpu/mcheck/mce.c
15251+++ b/arch/x86/kernel/cpu/mcheck/mce.c
15252@@ -45,6 +45,7 @@
15253 #include <asm/processor.h>
15254 #include <asm/mce.h>
15255 #include <asm/msr.h>
15256+#include <asm/local.h>
15257
15258 #include "mce-internal.h"
15259
15260@@ -254,7 +255,7 @@ static void print_mce(struct mce *m)
15261 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
15262 m->cs, m->ip);
15263
15264- if (m->cs == __KERNEL_CS)
15265+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
15266 print_symbol("{%s}", m->ip);
15267 pr_cont("\n");
15268 }
15269@@ -287,10 +288,10 @@ static void print_mce(struct mce *m)
15270
15271 #define PANIC_TIMEOUT 5 /* 5 seconds */
15272
15273-static atomic_t mce_paniced;
15274+static atomic_unchecked_t mce_paniced;
15275
15276 static int fake_panic;
15277-static atomic_t mce_fake_paniced;
15278+static atomic_unchecked_t mce_fake_paniced;
15279
15280 /* Panic in progress. Enable interrupts and wait for final IPI */
15281 static void wait_for_panic(void)
15282@@ -314,7 +315,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
15283 /*
15284 * Make sure only one CPU runs in machine check panic
15285 */
15286- if (atomic_inc_return(&mce_paniced) > 1)
15287+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
15288 wait_for_panic();
15289 barrier();
15290
15291@@ -322,7 +323,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
15292 console_verbose();
15293 } else {
15294 /* Don't log too much for fake panic */
15295- if (atomic_inc_return(&mce_fake_paniced) > 1)
15296+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
15297 return;
15298 }
15299 /* First print corrected ones that are still unlogged */
15300@@ -694,7 +695,7 @@ static int mce_timed_out(u64 *t)
15301 * might have been modified by someone else.
15302 */
15303 rmb();
15304- if (atomic_read(&mce_paniced))
15305+ if (atomic_read_unchecked(&mce_paniced))
15306 wait_for_panic();
15307 if (!monarch_timeout)
15308 goto out;
15309@@ -1659,7 +1660,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
15310 }
15311
15312 /* Call the installed machine check handler for this CPU setup. */
15313-void (*machine_check_vector)(struct pt_regs *, long error_code) =
15314+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
15315 unexpected_machine_check;
15316
15317 /*
15318@@ -1682,7 +1683,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
15319 return;
15320 }
15321
15322+ pax_open_kernel();
15323 machine_check_vector = do_machine_check;
15324+ pax_close_kernel();
15325
15326 __mcheck_cpu_init_generic();
15327 __mcheck_cpu_init_vendor(c);
15328@@ -1696,7 +1699,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
15329 */
15330
15331 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
15332-static int mce_chrdev_open_count; /* #times opened */
15333+static local_t mce_chrdev_open_count; /* #times opened */
15334 static int mce_chrdev_open_exclu; /* already open exclusive? */
15335
15336 static int mce_chrdev_open(struct inode *inode, struct file *file)
15337@@ -1704,7 +1707,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
15338 spin_lock(&mce_chrdev_state_lock);
15339
15340 if (mce_chrdev_open_exclu ||
15341- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
15342+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
15343 spin_unlock(&mce_chrdev_state_lock);
15344
15345 return -EBUSY;
15346@@ -1712,7 +1715,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
15347
15348 if (file->f_flags & O_EXCL)
15349 mce_chrdev_open_exclu = 1;
15350- mce_chrdev_open_count++;
15351+ local_inc(&mce_chrdev_open_count);
15352
15353 spin_unlock(&mce_chrdev_state_lock);
15354
15355@@ -1723,7 +1726,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
15356 {
15357 spin_lock(&mce_chrdev_state_lock);
15358
15359- mce_chrdev_open_count--;
15360+ local_dec(&mce_chrdev_open_count);
15361 mce_chrdev_open_exclu = 0;
15362
15363 spin_unlock(&mce_chrdev_state_lock);
15364@@ -2367,7 +2370,7 @@ mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
15365 return NOTIFY_OK;
15366 }
15367
15368-static struct notifier_block mce_cpu_notifier __cpuinitdata = {
15369+static struct notifier_block mce_cpu_notifier __cpuinitconst = {
15370 .notifier_call = mce_cpu_callback,
15371 };
15372
15373@@ -2445,7 +2448,7 @@ struct dentry *mce_get_debugfs_dir(void)
15374 static void mce_reset(void)
15375 {
15376 cpu_missing = 0;
15377- atomic_set(&mce_fake_paniced, 0);
15378+ atomic_set_unchecked(&mce_fake_paniced, 0);
15379 atomic_set(&mce_executing, 0);
15380 atomic_set(&mce_callin, 0);
15381 atomic_set(&global_nwo, 0);
15382diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
15383index 2d5454c..51987eb 100644
15384--- a/arch/x86/kernel/cpu/mcheck/p5.c
15385+++ b/arch/x86/kernel/cpu/mcheck/p5.c
15386@@ -11,6 +11,7 @@
15387 #include <asm/processor.h>
15388 #include <asm/mce.h>
15389 #include <asm/msr.h>
15390+#include <asm/pgtable.h>
15391
15392 /* By default disabled */
15393 int mce_p5_enabled __read_mostly;
15394@@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
15395 if (!cpu_has(c, X86_FEATURE_MCE))
15396 return;
15397
15398+ pax_open_kernel();
15399 machine_check_vector = pentium_machine_check;
15400+ pax_close_kernel();
15401 /* Make sure the vector pointer is visible before we enable MCEs: */
15402 wmb();
15403
15404diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
15405index 2d7998f..17c9de1 100644
15406--- a/arch/x86/kernel/cpu/mcheck/winchip.c
15407+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
15408@@ -10,6 +10,7 @@
15409 #include <asm/processor.h>
15410 #include <asm/mce.h>
15411 #include <asm/msr.h>
15412+#include <asm/pgtable.h>
15413
15414 /* Machine check handler for WinChip C6: */
15415 static void winchip_machine_check(struct pt_regs *regs, long error_code)
15416@@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
15417 {
15418 u32 lo, hi;
15419
15420+ pax_open_kernel();
15421 machine_check_vector = winchip_machine_check;
15422+ pax_close_kernel();
15423 /* Make sure the vector pointer is visible before we enable MCEs: */
15424 wmb();
15425
15426diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
15427index 6b96110..0da73eb 100644
15428--- a/arch/x86/kernel/cpu/mtrr/main.c
15429+++ b/arch/x86/kernel/cpu/mtrr/main.c
15430@@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
15431 u64 size_or_mask, size_and_mask;
15432 static bool mtrr_aps_delayed_init;
15433
15434-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
15435+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
15436
15437 const struct mtrr_ops *mtrr_if;
15438
15439diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
15440index df5e41f..816c719 100644
15441--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
15442+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
15443@@ -25,7 +25,7 @@ struct mtrr_ops {
15444 int (*validate_add_page)(unsigned long base, unsigned long size,
15445 unsigned int type);
15446 int (*have_wrcomb)(void);
15447-};
15448+} __do_const;
15449
15450 extern int generic_get_free_region(unsigned long base, unsigned long size,
15451 int replace_reg);
15452diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
15453index 4a3374e..1ca3ecb 100644
15454--- a/arch/x86/kernel/cpu/perf_event.c
15455+++ b/arch/x86/kernel/cpu/perf_event.c
15456@@ -1765,7 +1765,7 @@ static unsigned long get_segment_base(unsigned int segment)
15457 if (idx > GDT_ENTRIES)
15458 return 0;
15459
15460- desc = __this_cpu_ptr(&gdt_page.gdt[0]);
15461+ desc = get_cpu_gdt_table(smp_processor_id());
15462 }
15463
15464 return get_desc_base(desc + idx);
15465@@ -1855,7 +1855,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
15466 break;
15467
15468 perf_callchain_store(entry, frame.return_address);
15469- fp = frame.next_frame;
15470+ fp = (const void __force_user *)frame.next_frame;
15471 }
15472 }
15473
15474diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
15475index 324bb52..1a93d85 100644
15476--- a/arch/x86/kernel/cpu/perf_event_intel.c
15477+++ b/arch/x86/kernel/cpu/perf_event_intel.c
15478@@ -1949,10 +1949,10 @@ __init int intel_pmu_init(void)
15479 * v2 and above have a perf capabilities MSR
15480 */
15481 if (version > 1) {
15482- u64 capabilities;
15483+ u64 capabilities = x86_pmu.intel_cap.capabilities;
15484
15485- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
15486- x86_pmu.intel_cap.capabilities = capabilities;
15487+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
15488+ x86_pmu.intel_cap.capabilities = capabilities;
15489 }
15490
15491 intel_ds_init();
15492diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
15493index 13ad899..f642b9a 100644
15494--- a/arch/x86/kernel/crash.c
15495+++ b/arch/x86/kernel/crash.c
15496@@ -36,10 +36,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
15497 {
15498 #ifdef CONFIG_X86_32
15499 struct pt_regs fixed_regs;
15500-#endif
15501
15502-#ifdef CONFIG_X86_32
15503- if (!user_mode_vm(regs)) {
15504+ if (!user_mode(regs)) {
15505 crash_fixup_ss_esp(&fixed_regs, regs);
15506 regs = &fixed_regs;
15507 }
15508diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
15509index 37250fe..bf2ec74 100644
15510--- a/arch/x86/kernel/doublefault_32.c
15511+++ b/arch/x86/kernel/doublefault_32.c
15512@@ -11,7 +11,7 @@
15513
15514 #define DOUBLEFAULT_STACKSIZE (1024)
15515 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
15516-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
15517+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
15518
15519 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
15520
15521@@ -21,7 +21,7 @@ static void doublefault_fn(void)
15522 unsigned long gdt, tss;
15523
15524 store_gdt(&gdt_desc);
15525- gdt = gdt_desc.address;
15526+ gdt = (unsigned long)gdt_desc.address;
15527
15528 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
15529
15530@@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
15531 /* 0x2 bit is always set */
15532 .flags = X86_EFLAGS_SF | 0x2,
15533 .sp = STACK_START,
15534- .es = __USER_DS,
15535+ .es = __KERNEL_DS,
15536 .cs = __KERNEL_CS,
15537 .ss = __KERNEL_DS,
15538- .ds = __USER_DS,
15539+ .ds = __KERNEL_DS,
15540 .fs = __KERNEL_PERCPU,
15541
15542 .__cr3 = __pa_nodebug(swapper_pg_dir),
15543diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
15544index ae42418b..787c16b 100644
15545--- a/arch/x86/kernel/dumpstack.c
15546+++ b/arch/x86/kernel/dumpstack.c
15547@@ -2,6 +2,9 @@
15548 * Copyright (C) 1991, 1992 Linus Torvalds
15549 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
15550 */
15551+#ifdef CONFIG_GRKERNSEC_HIDESYM
15552+#define __INCLUDED_BY_HIDESYM 1
15553+#endif
15554 #include <linux/kallsyms.h>
15555 #include <linux/kprobes.h>
15556 #include <linux/uaccess.h>
15557@@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
15558 static void
15559 print_ftrace_graph_addr(unsigned long addr, void *data,
15560 const struct stacktrace_ops *ops,
15561- struct thread_info *tinfo, int *graph)
15562+ struct task_struct *task, int *graph)
15563 {
15564- struct task_struct *task;
15565 unsigned long ret_addr;
15566 int index;
15567
15568 if (addr != (unsigned long)return_to_handler)
15569 return;
15570
15571- task = tinfo->task;
15572 index = task->curr_ret_stack;
15573
15574 if (!task->ret_stack || index < *graph)
15575@@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
15576 static inline void
15577 print_ftrace_graph_addr(unsigned long addr, void *data,
15578 const struct stacktrace_ops *ops,
15579- struct thread_info *tinfo, int *graph)
15580+ struct task_struct *task, int *graph)
15581 { }
15582 #endif
15583
15584@@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
15585 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
15586 */
15587
15588-static inline int valid_stack_ptr(struct thread_info *tinfo,
15589- void *p, unsigned int size, void *end)
15590+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
15591 {
15592- void *t = tinfo;
15593 if (end) {
15594 if (p < end && p >= (end-THREAD_SIZE))
15595 return 1;
15596@@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
15597 }
15598
15599 unsigned long
15600-print_context_stack(struct thread_info *tinfo,
15601+print_context_stack(struct task_struct *task, void *stack_start,
15602 unsigned long *stack, unsigned long bp,
15603 const struct stacktrace_ops *ops, void *data,
15604 unsigned long *end, int *graph)
15605 {
15606 struct stack_frame *frame = (struct stack_frame *)bp;
15607
15608- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
15609+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
15610 unsigned long addr;
15611
15612 addr = *stack;
15613@@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
15614 } else {
15615 ops->address(data, addr, 0);
15616 }
15617- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
15618+ print_ftrace_graph_addr(addr, data, ops, task, graph);
15619 }
15620 stack++;
15621 }
15622@@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
15623 EXPORT_SYMBOL_GPL(print_context_stack);
15624
15625 unsigned long
15626-print_context_stack_bp(struct thread_info *tinfo,
15627+print_context_stack_bp(struct task_struct *task, void *stack_start,
15628 unsigned long *stack, unsigned long bp,
15629 const struct stacktrace_ops *ops, void *data,
15630 unsigned long *end, int *graph)
15631@@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
15632 struct stack_frame *frame = (struct stack_frame *)bp;
15633 unsigned long *ret_addr = &frame->return_address;
15634
15635- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
15636+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
15637 unsigned long addr = *ret_addr;
15638
15639 if (!__kernel_text_address(addr))
15640@@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
15641 ops->address(data, addr, 1);
15642 frame = frame->next_frame;
15643 ret_addr = &frame->return_address;
15644- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
15645+ print_ftrace_graph_addr(addr, data, ops, task, graph);
15646 }
15647
15648 return (unsigned long)frame;
15649@@ -189,7 +188,7 @@ void dump_stack(void)
15650
15651 bp = stack_frame(current, NULL);
15652 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
15653- current->pid, current->comm, print_tainted(),
15654+ task_pid_nr(current), current->comm, print_tainted(),
15655 init_utsname()->release,
15656 (int)strcspn(init_utsname()->version, " "),
15657 init_utsname()->version);
15658@@ -225,6 +224,8 @@ unsigned __kprobes long oops_begin(void)
15659 }
15660 EXPORT_SYMBOL_GPL(oops_begin);
15661
15662+extern void gr_handle_kernel_exploit(void);
15663+
15664 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
15665 {
15666 if (regs && kexec_should_crash(current))
15667@@ -246,7 +247,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
15668 panic("Fatal exception in interrupt");
15669 if (panic_on_oops)
15670 panic("Fatal exception");
15671- do_exit(signr);
15672+
15673+ gr_handle_kernel_exploit();
15674+
15675+ do_group_exit(signr);
15676 }
15677
15678 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
15679@@ -274,7 +278,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
15680 print_modules();
15681 show_regs(regs);
15682 #ifdef CONFIG_X86_32
15683- if (user_mode_vm(regs)) {
15684+ if (user_mode(regs)) {
15685 sp = regs->sp;
15686 ss = regs->ss & 0xffff;
15687 } else {
15688@@ -302,7 +306,7 @@ void die(const char *str, struct pt_regs *regs, long err)
15689 unsigned long flags = oops_begin();
15690 int sig = SIGSEGV;
15691
15692- if (!user_mode_vm(regs))
15693+ if (!user_mode(regs))
15694 report_bug(regs->ip, regs);
15695
15696 if (__die(str, regs, err))
15697diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
15698index 1038a41..db2c12b 100644
15699--- a/arch/x86/kernel/dumpstack_32.c
15700+++ b/arch/x86/kernel/dumpstack_32.c
15701@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
15702 bp = stack_frame(task, regs);
15703
15704 for (;;) {
15705- struct thread_info *context;
15706+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
15707
15708- context = (struct thread_info *)
15709- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
15710- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
15711+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
15712
15713- stack = (unsigned long *)context->previous_esp;
15714- if (!stack)
15715+ if (stack_start == task_stack_page(task))
15716 break;
15717+ stack = *(unsigned long **)stack_start;
15718 if (ops->stack(data, "IRQ") < 0)
15719 break;
15720 touch_nmi_watchdog();
15721@@ -86,7 +84,7 @@ void show_regs(struct pt_regs *regs)
15722 {
15723 int i;
15724
15725- __show_regs(regs, !user_mode_vm(regs));
15726+ __show_regs(regs, !user_mode(regs));
15727
15728 pr_emerg("Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
15729 TASK_COMM_LEN, current->comm, task_pid_nr(current),
15730@@ -95,21 +93,22 @@ void show_regs(struct pt_regs *regs)
15731 * When in-kernel, we also print out the stack and code at the
15732 * time of the fault..
15733 */
15734- if (!user_mode_vm(regs)) {
15735+ if (!user_mode(regs)) {
15736 unsigned int code_prologue = code_bytes * 43 / 64;
15737 unsigned int code_len = code_bytes;
15738 unsigned char c;
15739 u8 *ip;
15740+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
15741
15742 pr_emerg("Stack:\n");
15743 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
15744
15745 pr_emerg("Code:");
15746
15747- ip = (u8 *)regs->ip - code_prologue;
15748+ ip = (u8 *)regs->ip - code_prologue + cs_base;
15749 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
15750 /* try starting at IP */
15751- ip = (u8 *)regs->ip;
15752+ ip = (u8 *)regs->ip + cs_base;
15753 code_len = code_len - code_prologue + 1;
15754 }
15755 for (i = 0; i < code_len; i++, ip++) {
15756@@ -118,7 +117,7 @@ void show_regs(struct pt_regs *regs)
15757 pr_cont(" Bad EIP value.");
15758 break;
15759 }
15760- if (ip == (u8 *)regs->ip)
15761+ if (ip == (u8 *)regs->ip + cs_base)
15762 pr_cont(" <%02x>", c);
15763 else
15764 pr_cont(" %02x", c);
15765@@ -131,6 +130,7 @@ int is_valid_bugaddr(unsigned long ip)
15766 {
15767 unsigned short ud2;
15768
15769+ ip = ktla_ktva(ip);
15770 if (ip < PAGE_OFFSET)
15771 return 0;
15772 if (probe_kernel_address((unsigned short *)ip, ud2))
15773@@ -138,3 +138,15 @@ int is_valid_bugaddr(unsigned long ip)
15774
15775 return ud2 == 0x0b0f;
15776 }
15777+
15778+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15779+void pax_check_alloca(unsigned long size)
15780+{
15781+ unsigned long sp = (unsigned long)&sp, stack_left;
15782+
15783+ /* all kernel stacks are of the same size */
15784+ stack_left = sp & (THREAD_SIZE - 1);
15785+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
15786+}
15787+EXPORT_SYMBOL(pax_check_alloca);
15788+#endif
15789diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
15790index b653675..51cc8c0 100644
15791--- a/arch/x86/kernel/dumpstack_64.c
15792+++ b/arch/x86/kernel/dumpstack_64.c
15793@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
15794 unsigned long *irq_stack_end =
15795 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
15796 unsigned used = 0;
15797- struct thread_info *tinfo;
15798 int graph = 0;
15799 unsigned long dummy;
15800+ void *stack_start;
15801
15802 if (!task)
15803 task = current;
15804@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
15805 * current stack address. If the stacks consist of nested
15806 * exceptions
15807 */
15808- tinfo = task_thread_info(task);
15809 for (;;) {
15810 char *id;
15811 unsigned long *estack_end;
15812+
15813 estack_end = in_exception_stack(cpu, (unsigned long)stack,
15814 &used, &id);
15815
15816@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
15817 if (ops->stack(data, id) < 0)
15818 break;
15819
15820- bp = ops->walk_stack(tinfo, stack, bp, ops,
15821+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
15822 data, estack_end, &graph);
15823 ops->stack(data, "<EOE>");
15824 /*
15825@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
15826 * second-to-last pointer (index -2 to end) in the
15827 * exception stack:
15828 */
15829+ if ((u16)estack_end[-1] != __KERNEL_DS)
15830+ goto out;
15831 stack = (unsigned long *) estack_end[-2];
15832 continue;
15833 }
15834@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
15835 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
15836 if (ops->stack(data, "IRQ") < 0)
15837 break;
15838- bp = ops->walk_stack(tinfo, stack, bp,
15839+ bp = ops->walk_stack(task, irq_stack, stack, bp,
15840 ops, data, irq_stack_end, &graph);
15841 /*
15842 * We link to the next stack (which would be
15843@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
15844 /*
15845 * This handles the process stack:
15846 */
15847- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
15848+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
15849+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
15850+out:
15851 put_cpu();
15852 }
15853 EXPORT_SYMBOL(dump_trace);
15854@@ -249,7 +253,7 @@ void show_regs(struct pt_regs *regs)
15855 {
15856 int i;
15857 unsigned long sp;
15858- const int cpu = smp_processor_id();
15859+ const int cpu = raw_smp_processor_id();
15860 struct task_struct *cur = current;
15861
15862 sp = regs->sp;
15863@@ -304,3 +308,50 @@ int is_valid_bugaddr(unsigned long ip)
15864
15865 return ud2 == 0x0b0f;
15866 }
15867+
15868+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15869+void pax_check_alloca(unsigned long size)
15870+{
15871+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
15872+ unsigned cpu, used;
15873+ char *id;
15874+
15875+ /* check the process stack first */
15876+ stack_start = (unsigned long)task_stack_page(current);
15877+ stack_end = stack_start + THREAD_SIZE;
15878+ if (likely(stack_start <= sp && sp < stack_end)) {
15879+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
15880+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
15881+ return;
15882+ }
15883+
15884+ cpu = get_cpu();
15885+
15886+ /* check the irq stacks */
15887+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
15888+ stack_start = stack_end - IRQ_STACK_SIZE;
15889+ if (stack_start <= sp && sp < stack_end) {
15890+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
15891+ put_cpu();
15892+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
15893+ return;
15894+ }
15895+
15896+ /* check the exception stacks */
15897+ used = 0;
15898+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
15899+ stack_start = stack_end - EXCEPTION_STKSZ;
15900+ if (stack_end && stack_start <= sp && sp < stack_end) {
15901+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
15902+ put_cpu();
15903+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
15904+ return;
15905+ }
15906+
15907+ put_cpu();
15908+
15909+ /* unknown stack */
15910+ BUG();
15911+}
15912+EXPORT_SYMBOL(pax_check_alloca);
15913+#endif
15914diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
15915index 9b9f18b..9fcaa04 100644
15916--- a/arch/x86/kernel/early_printk.c
15917+++ b/arch/x86/kernel/early_printk.c
15918@@ -7,6 +7,7 @@
15919 #include <linux/pci_regs.h>
15920 #include <linux/pci_ids.h>
15921 #include <linux/errno.h>
15922+#include <linux/sched.h>
15923 #include <asm/io.h>
15924 #include <asm/processor.h>
15925 #include <asm/fcntl.h>
15926diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
15927index 88b725a..3efabf6 100644
15928--- a/arch/x86/kernel/entry_32.S
15929+++ b/arch/x86/kernel/entry_32.S
15930@@ -177,13 +177,153 @@
15931 /*CFI_REL_OFFSET gs, PT_GS*/
15932 .endm
15933 .macro SET_KERNEL_GS reg
15934+
15935+#ifdef CONFIG_CC_STACKPROTECTOR
15936 movl $(__KERNEL_STACK_CANARY), \reg
15937+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
15938+ movl $(__USER_DS), \reg
15939+#else
15940+ xorl \reg, \reg
15941+#endif
15942+
15943 movl \reg, %gs
15944 .endm
15945
15946 #endif /* CONFIG_X86_32_LAZY_GS */
15947
15948-.macro SAVE_ALL
15949+.macro pax_enter_kernel
15950+#ifdef CONFIG_PAX_KERNEXEC
15951+ call pax_enter_kernel
15952+#endif
15953+.endm
15954+
15955+.macro pax_exit_kernel
15956+#ifdef CONFIG_PAX_KERNEXEC
15957+ call pax_exit_kernel
15958+#endif
15959+.endm
15960+
15961+#ifdef CONFIG_PAX_KERNEXEC
15962+ENTRY(pax_enter_kernel)
15963+#ifdef CONFIG_PARAVIRT
15964+ pushl %eax
15965+ pushl %ecx
15966+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
15967+ mov %eax, %esi
15968+#else
15969+ mov %cr0, %esi
15970+#endif
15971+ bts $16, %esi
15972+ jnc 1f
15973+ mov %cs, %esi
15974+ cmp $__KERNEL_CS, %esi
15975+ jz 3f
15976+ ljmp $__KERNEL_CS, $3f
15977+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
15978+2:
15979+#ifdef CONFIG_PARAVIRT
15980+ mov %esi, %eax
15981+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
15982+#else
15983+ mov %esi, %cr0
15984+#endif
15985+3:
15986+#ifdef CONFIG_PARAVIRT
15987+ popl %ecx
15988+ popl %eax
15989+#endif
15990+ ret
15991+ENDPROC(pax_enter_kernel)
15992+
15993+ENTRY(pax_exit_kernel)
15994+#ifdef CONFIG_PARAVIRT
15995+ pushl %eax
15996+ pushl %ecx
15997+#endif
15998+ mov %cs, %esi
15999+ cmp $__KERNEXEC_KERNEL_CS, %esi
16000+ jnz 2f
16001+#ifdef CONFIG_PARAVIRT
16002+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
16003+ mov %eax, %esi
16004+#else
16005+ mov %cr0, %esi
16006+#endif
16007+ btr $16, %esi
16008+ ljmp $__KERNEL_CS, $1f
16009+1:
16010+#ifdef CONFIG_PARAVIRT
16011+ mov %esi, %eax
16012+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
16013+#else
16014+ mov %esi, %cr0
16015+#endif
16016+2:
16017+#ifdef CONFIG_PARAVIRT
16018+ popl %ecx
16019+ popl %eax
16020+#endif
16021+ ret
16022+ENDPROC(pax_exit_kernel)
16023+#endif
16024+
16025+.macro pax_erase_kstack
16026+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16027+ call pax_erase_kstack
16028+#endif
16029+.endm
16030+
16031+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16032+/*
16033+ * ebp: thread_info
16034+ */
16035+ENTRY(pax_erase_kstack)
16036+ pushl %edi
16037+ pushl %ecx
16038+ pushl %eax
16039+
16040+ mov TI_lowest_stack(%ebp), %edi
16041+ mov $-0xBEEF, %eax
16042+ std
16043+
16044+1: mov %edi, %ecx
16045+ and $THREAD_SIZE_asm - 1, %ecx
16046+ shr $2, %ecx
16047+ repne scasl
16048+ jecxz 2f
16049+
16050+ cmp $2*16, %ecx
16051+ jc 2f
16052+
16053+ mov $2*16, %ecx
16054+ repe scasl
16055+ jecxz 2f
16056+ jne 1b
16057+
16058+2: cld
16059+ mov %esp, %ecx
16060+ sub %edi, %ecx
16061+
16062+ cmp $THREAD_SIZE_asm, %ecx
16063+ jb 3f
16064+ ud2
16065+3:
16066+
16067+ shr $2, %ecx
16068+ rep stosl
16069+
16070+ mov TI_task_thread_sp0(%ebp), %edi
16071+ sub $128, %edi
16072+ mov %edi, TI_lowest_stack(%ebp)
16073+
16074+ popl %eax
16075+ popl %ecx
16076+ popl %edi
16077+ ret
16078+ENDPROC(pax_erase_kstack)
16079+#endif
16080+
16081+.macro __SAVE_ALL _DS
16082 cld
16083 PUSH_GS
16084 pushl_cfi %fs
16085@@ -206,7 +346,7 @@
16086 CFI_REL_OFFSET ecx, 0
16087 pushl_cfi %ebx
16088 CFI_REL_OFFSET ebx, 0
16089- movl $(__USER_DS), %edx
16090+ movl $\_DS, %edx
16091 movl %edx, %ds
16092 movl %edx, %es
16093 movl $(__KERNEL_PERCPU), %edx
16094@@ -214,6 +354,15 @@
16095 SET_KERNEL_GS %edx
16096 .endm
16097
16098+.macro SAVE_ALL
16099+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
16100+ __SAVE_ALL __KERNEL_DS
16101+ pax_enter_kernel
16102+#else
16103+ __SAVE_ALL __USER_DS
16104+#endif
16105+.endm
16106+
16107 .macro RESTORE_INT_REGS
16108 popl_cfi %ebx
16109 CFI_RESTORE ebx
16110@@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
16111 popfl_cfi
16112 jmp syscall_exit
16113 CFI_ENDPROC
16114-END(ret_from_fork)
16115+ENDPROC(ret_from_fork)
16116
16117 ENTRY(ret_from_kernel_thread)
16118 CFI_STARTPROC
16119@@ -344,7 +493,15 @@ ret_from_intr:
16120 andl $SEGMENT_RPL_MASK, %eax
16121 #endif
16122 cmpl $USER_RPL, %eax
16123+
16124+#ifdef CONFIG_PAX_KERNEXEC
16125+ jae resume_userspace
16126+
16127+ pax_exit_kernel
16128+ jmp resume_kernel
16129+#else
16130 jb resume_kernel # not returning to v8086 or userspace
16131+#endif
16132
16133 ENTRY(resume_userspace)
16134 LOCKDEP_SYS_EXIT
16135@@ -356,8 +513,8 @@ ENTRY(resume_userspace)
16136 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
16137 # int/exception return?
16138 jne work_pending
16139- jmp restore_all
16140-END(ret_from_exception)
16141+ jmp restore_all_pax
16142+ENDPROC(ret_from_exception)
16143
16144 #ifdef CONFIG_PREEMPT
16145 ENTRY(resume_kernel)
16146@@ -372,7 +529,7 @@ need_resched:
16147 jz restore_all
16148 call preempt_schedule_irq
16149 jmp need_resched
16150-END(resume_kernel)
16151+ENDPROC(resume_kernel)
16152 #endif
16153 CFI_ENDPROC
16154 /*
16155@@ -406,30 +563,45 @@ sysenter_past_esp:
16156 /*CFI_REL_OFFSET cs, 0*/
16157 /*
16158 * Push current_thread_info()->sysenter_return to the stack.
16159- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
16160- * pushed above; +8 corresponds to copy_thread's esp0 setting.
16161 */
16162- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
16163+ pushl_cfi $0
16164 CFI_REL_OFFSET eip, 0
16165
16166 pushl_cfi %eax
16167 SAVE_ALL
16168+ GET_THREAD_INFO(%ebp)
16169+ movl TI_sysenter_return(%ebp),%ebp
16170+ movl %ebp,PT_EIP(%esp)
16171 ENABLE_INTERRUPTS(CLBR_NONE)
16172
16173 /*
16174 * Load the potential sixth argument from user stack.
16175 * Careful about security.
16176 */
16177+ movl PT_OLDESP(%esp),%ebp
16178+
16179+#ifdef CONFIG_PAX_MEMORY_UDEREF
16180+ mov PT_OLDSS(%esp),%ds
16181+1: movl %ds:(%ebp),%ebp
16182+ push %ss
16183+ pop %ds
16184+#else
16185 cmpl $__PAGE_OFFSET-3,%ebp
16186 jae syscall_fault
16187 ASM_STAC
16188 1: movl (%ebp),%ebp
16189 ASM_CLAC
16190+#endif
16191+
16192 movl %ebp,PT_EBP(%esp)
16193 _ASM_EXTABLE(1b,syscall_fault)
16194
16195 GET_THREAD_INFO(%ebp)
16196
16197+#ifdef CONFIG_PAX_RANDKSTACK
16198+ pax_erase_kstack
16199+#endif
16200+
16201 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
16202 jnz sysenter_audit
16203 sysenter_do_call:
16204@@ -444,12 +616,24 @@ sysenter_do_call:
16205 testl $_TIF_ALLWORK_MASK, %ecx
16206 jne sysexit_audit
16207 sysenter_exit:
16208+
16209+#ifdef CONFIG_PAX_RANDKSTACK
16210+ pushl_cfi %eax
16211+ movl %esp, %eax
16212+ call pax_randomize_kstack
16213+ popl_cfi %eax
16214+#endif
16215+
16216+ pax_erase_kstack
16217+
16218 /* if something modifies registers it must also disable sysexit */
16219 movl PT_EIP(%esp), %edx
16220 movl PT_OLDESP(%esp), %ecx
16221 xorl %ebp,%ebp
16222 TRACE_IRQS_ON
16223 1: mov PT_FS(%esp), %fs
16224+2: mov PT_DS(%esp), %ds
16225+3: mov PT_ES(%esp), %es
16226 PTGS_TO_GS
16227 ENABLE_INTERRUPTS_SYSEXIT
16228
16229@@ -466,6 +650,9 @@ sysenter_audit:
16230 movl %eax,%edx /* 2nd arg: syscall number */
16231 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
16232 call __audit_syscall_entry
16233+
16234+ pax_erase_kstack
16235+
16236 pushl_cfi %ebx
16237 movl PT_EAX(%esp),%eax /* reload syscall number */
16238 jmp sysenter_do_call
16239@@ -491,10 +678,16 @@ sysexit_audit:
16240
16241 CFI_ENDPROC
16242 .pushsection .fixup,"ax"
16243-2: movl $0,PT_FS(%esp)
16244+4: movl $0,PT_FS(%esp)
16245+ jmp 1b
16246+5: movl $0,PT_DS(%esp)
16247+ jmp 1b
16248+6: movl $0,PT_ES(%esp)
16249 jmp 1b
16250 .popsection
16251- _ASM_EXTABLE(1b,2b)
16252+ _ASM_EXTABLE(1b,4b)
16253+ _ASM_EXTABLE(2b,5b)
16254+ _ASM_EXTABLE(3b,6b)
16255 PTGS_TO_GS_EX
16256 ENDPROC(ia32_sysenter_target)
16257
16258@@ -509,6 +702,11 @@ ENTRY(system_call)
16259 pushl_cfi %eax # save orig_eax
16260 SAVE_ALL
16261 GET_THREAD_INFO(%ebp)
16262+
16263+#ifdef CONFIG_PAX_RANDKSTACK
16264+ pax_erase_kstack
16265+#endif
16266+
16267 # system call tracing in operation / emulation
16268 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
16269 jnz syscall_trace_entry
16270@@ -527,6 +725,15 @@ syscall_exit:
16271 testl $_TIF_ALLWORK_MASK, %ecx # current->work
16272 jne syscall_exit_work
16273
16274+restore_all_pax:
16275+
16276+#ifdef CONFIG_PAX_RANDKSTACK
16277+ movl %esp, %eax
16278+ call pax_randomize_kstack
16279+#endif
16280+
16281+ pax_erase_kstack
16282+
16283 restore_all:
16284 TRACE_IRQS_IRET
16285 restore_all_notrace:
16286@@ -583,14 +790,34 @@ ldt_ss:
16287 * compensating for the offset by changing to the ESPFIX segment with
16288 * a base address that matches for the difference.
16289 */
16290-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
16291+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
16292 mov %esp, %edx /* load kernel esp */
16293 mov PT_OLDESP(%esp), %eax /* load userspace esp */
16294 mov %dx, %ax /* eax: new kernel esp */
16295 sub %eax, %edx /* offset (low word is 0) */
16296+#ifdef CONFIG_SMP
16297+ movl PER_CPU_VAR(cpu_number), %ebx
16298+ shll $PAGE_SHIFT_asm, %ebx
16299+ addl $cpu_gdt_table, %ebx
16300+#else
16301+ movl $cpu_gdt_table, %ebx
16302+#endif
16303 shr $16, %edx
16304- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
16305- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
16306+
16307+#ifdef CONFIG_PAX_KERNEXEC
16308+ mov %cr0, %esi
16309+ btr $16, %esi
16310+ mov %esi, %cr0
16311+#endif
16312+
16313+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
16314+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
16315+
16316+#ifdef CONFIG_PAX_KERNEXEC
16317+ bts $16, %esi
16318+ mov %esi, %cr0
16319+#endif
16320+
16321 pushl_cfi $__ESPFIX_SS
16322 pushl_cfi %eax /* new kernel esp */
16323 /* Disable interrupts, but do not irqtrace this section: we
16324@@ -619,20 +846,18 @@ work_resched:
16325 movl TI_flags(%ebp), %ecx
16326 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
16327 # than syscall tracing?
16328- jz restore_all
16329+ jz restore_all_pax
16330 testb $_TIF_NEED_RESCHED, %cl
16331 jnz work_resched
16332
16333 work_notifysig: # deal with pending signals and
16334 # notify-resume requests
16335+ movl %esp, %eax
16336 #ifdef CONFIG_VM86
16337 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
16338- movl %esp, %eax
16339 jne work_notifysig_v86 # returning to kernel-space or
16340 # vm86-space
16341 1:
16342-#else
16343- movl %esp, %eax
16344 #endif
16345 TRACE_IRQS_ON
16346 ENABLE_INTERRUPTS(CLBR_NONE)
16347@@ -653,7 +878,7 @@ work_notifysig_v86:
16348 movl %eax, %esp
16349 jmp 1b
16350 #endif
16351-END(work_pending)
16352+ENDPROC(work_pending)
16353
16354 # perform syscall exit tracing
16355 ALIGN
16356@@ -661,11 +886,14 @@ syscall_trace_entry:
16357 movl $-ENOSYS,PT_EAX(%esp)
16358 movl %esp, %eax
16359 call syscall_trace_enter
16360+
16361+ pax_erase_kstack
16362+
16363 /* What it returned is what we'll actually use. */
16364 cmpl $(NR_syscalls), %eax
16365 jnae syscall_call
16366 jmp syscall_exit
16367-END(syscall_trace_entry)
16368+ENDPROC(syscall_trace_entry)
16369
16370 # perform syscall exit tracing
16371 ALIGN
16372@@ -678,21 +906,25 @@ syscall_exit_work:
16373 movl %esp, %eax
16374 call syscall_trace_leave
16375 jmp resume_userspace
16376-END(syscall_exit_work)
16377+ENDPROC(syscall_exit_work)
16378 CFI_ENDPROC
16379
16380 RING0_INT_FRAME # can't unwind into user space anyway
16381 syscall_fault:
16382+#ifdef CONFIG_PAX_MEMORY_UDEREF
16383+ push %ss
16384+ pop %ds
16385+#endif
16386 ASM_CLAC
16387 GET_THREAD_INFO(%ebp)
16388 movl $-EFAULT,PT_EAX(%esp)
16389 jmp resume_userspace
16390-END(syscall_fault)
16391+ENDPROC(syscall_fault)
16392
16393 syscall_badsys:
16394 movl $-ENOSYS,PT_EAX(%esp)
16395 jmp resume_userspace
16396-END(syscall_badsys)
16397+ENDPROC(syscall_badsys)
16398 CFI_ENDPROC
16399 /*
16400 * End of kprobes section
16401@@ -763,6 +995,36 @@ ENTRY(ptregs_clone)
16402 CFI_ENDPROC
16403 ENDPROC(ptregs_clone)
16404
16405+ ALIGN;
16406+ENTRY(kernel_execve)
16407+ CFI_STARTPROC
16408+ pushl_cfi %ebp
16409+ sub $PT_OLDSS+4,%esp
16410+ pushl_cfi %edi
16411+ pushl_cfi %ecx
16412+ pushl_cfi %eax
16413+ lea 3*4(%esp),%edi
16414+ mov $PT_OLDSS/4+1,%ecx
16415+ xorl %eax,%eax
16416+ rep stosl
16417+ popl_cfi %eax
16418+ popl_cfi %ecx
16419+ popl_cfi %edi
16420+ movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
16421+ pushl_cfi %esp
16422+ call sys_execve
16423+ add $4,%esp
16424+ CFI_ADJUST_CFA_OFFSET -4
16425+ GET_THREAD_INFO(%ebp)
16426+ test %eax,%eax
16427+ jz syscall_exit
16428+ add $PT_OLDSS+4,%esp
16429+ CFI_ADJUST_CFA_OFFSET -PT_OLDSS-4
16430+ popl_cfi %ebp
16431+ ret
16432+ CFI_ENDPROC
16433+ENDPROC(kernel_execve)
16434+
16435 .macro FIXUP_ESPFIX_STACK
16436 /*
16437 * Switch back for ESPFIX stack to the normal zerobased stack
16438@@ -772,8 +1034,15 @@ ENDPROC(ptregs_clone)
16439 * normal stack and adjusts ESP with the matching offset.
16440 */
16441 /* fixup the stack */
16442- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
16443- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
16444+#ifdef CONFIG_SMP
16445+ movl PER_CPU_VAR(cpu_number), %ebx
16446+ shll $PAGE_SHIFT_asm, %ebx
16447+ addl $cpu_gdt_table, %ebx
16448+#else
16449+ movl $cpu_gdt_table, %ebx
16450+#endif
16451+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
16452+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
16453 shl $16, %eax
16454 addl %esp, %eax /* the adjusted stack pointer */
16455 pushl_cfi $__KERNEL_DS
16456@@ -826,7 +1095,7 @@ vector=vector+1
16457 .endr
16458 2: jmp common_interrupt
16459 .endr
16460-END(irq_entries_start)
16461+ENDPROC(irq_entries_start)
16462
16463 .previous
16464 END(interrupt)
16465@@ -877,7 +1146,7 @@ ENTRY(coprocessor_error)
16466 pushl_cfi $do_coprocessor_error
16467 jmp error_code
16468 CFI_ENDPROC
16469-END(coprocessor_error)
16470+ENDPROC(coprocessor_error)
16471
16472 ENTRY(simd_coprocessor_error)
16473 RING0_INT_FRAME
16474@@ -899,7 +1168,7 @@ ENTRY(simd_coprocessor_error)
16475 #endif
16476 jmp error_code
16477 CFI_ENDPROC
16478-END(simd_coprocessor_error)
16479+ENDPROC(simd_coprocessor_error)
16480
16481 ENTRY(device_not_available)
16482 RING0_INT_FRAME
16483@@ -908,18 +1177,18 @@ ENTRY(device_not_available)
16484 pushl_cfi $do_device_not_available
16485 jmp error_code
16486 CFI_ENDPROC
16487-END(device_not_available)
16488+ENDPROC(device_not_available)
16489
16490 #ifdef CONFIG_PARAVIRT
16491 ENTRY(native_iret)
16492 iret
16493 _ASM_EXTABLE(native_iret, iret_exc)
16494-END(native_iret)
16495+ENDPROC(native_iret)
16496
16497 ENTRY(native_irq_enable_sysexit)
16498 sti
16499 sysexit
16500-END(native_irq_enable_sysexit)
16501+ENDPROC(native_irq_enable_sysexit)
16502 #endif
16503
16504 ENTRY(overflow)
16505@@ -929,7 +1198,7 @@ ENTRY(overflow)
16506 pushl_cfi $do_overflow
16507 jmp error_code
16508 CFI_ENDPROC
16509-END(overflow)
16510+ENDPROC(overflow)
16511
16512 ENTRY(bounds)
16513 RING0_INT_FRAME
16514@@ -938,7 +1207,7 @@ ENTRY(bounds)
16515 pushl_cfi $do_bounds
16516 jmp error_code
16517 CFI_ENDPROC
16518-END(bounds)
16519+ENDPROC(bounds)
16520
16521 ENTRY(invalid_op)
16522 RING0_INT_FRAME
16523@@ -947,7 +1216,7 @@ ENTRY(invalid_op)
16524 pushl_cfi $do_invalid_op
16525 jmp error_code
16526 CFI_ENDPROC
16527-END(invalid_op)
16528+ENDPROC(invalid_op)
16529
16530 ENTRY(coprocessor_segment_overrun)
16531 RING0_INT_FRAME
16532@@ -956,7 +1225,7 @@ ENTRY(coprocessor_segment_overrun)
16533 pushl_cfi $do_coprocessor_segment_overrun
16534 jmp error_code
16535 CFI_ENDPROC
16536-END(coprocessor_segment_overrun)
16537+ENDPROC(coprocessor_segment_overrun)
16538
16539 ENTRY(invalid_TSS)
16540 RING0_EC_FRAME
16541@@ -964,7 +1233,7 @@ ENTRY(invalid_TSS)
16542 pushl_cfi $do_invalid_TSS
16543 jmp error_code
16544 CFI_ENDPROC
16545-END(invalid_TSS)
16546+ENDPROC(invalid_TSS)
16547
16548 ENTRY(segment_not_present)
16549 RING0_EC_FRAME
16550@@ -972,7 +1241,7 @@ ENTRY(segment_not_present)
16551 pushl_cfi $do_segment_not_present
16552 jmp error_code
16553 CFI_ENDPROC
16554-END(segment_not_present)
16555+ENDPROC(segment_not_present)
16556
16557 ENTRY(stack_segment)
16558 RING0_EC_FRAME
16559@@ -980,7 +1249,7 @@ ENTRY(stack_segment)
16560 pushl_cfi $do_stack_segment
16561 jmp error_code
16562 CFI_ENDPROC
16563-END(stack_segment)
16564+ENDPROC(stack_segment)
16565
16566 ENTRY(alignment_check)
16567 RING0_EC_FRAME
16568@@ -988,7 +1257,7 @@ ENTRY(alignment_check)
16569 pushl_cfi $do_alignment_check
16570 jmp error_code
16571 CFI_ENDPROC
16572-END(alignment_check)
16573+ENDPROC(alignment_check)
16574
16575 ENTRY(divide_error)
16576 RING0_INT_FRAME
16577@@ -997,7 +1266,7 @@ ENTRY(divide_error)
16578 pushl_cfi $do_divide_error
16579 jmp error_code
16580 CFI_ENDPROC
16581-END(divide_error)
16582+ENDPROC(divide_error)
16583
16584 #ifdef CONFIG_X86_MCE
16585 ENTRY(machine_check)
16586@@ -1007,7 +1276,7 @@ ENTRY(machine_check)
16587 pushl_cfi machine_check_vector
16588 jmp error_code
16589 CFI_ENDPROC
16590-END(machine_check)
16591+ENDPROC(machine_check)
16592 #endif
16593
16594 ENTRY(spurious_interrupt_bug)
16595@@ -1017,7 +1286,7 @@ ENTRY(spurious_interrupt_bug)
16596 pushl_cfi $do_spurious_interrupt_bug
16597 jmp error_code
16598 CFI_ENDPROC
16599-END(spurious_interrupt_bug)
16600+ENDPROC(spurious_interrupt_bug)
16601 /*
16602 * End of kprobes section
16603 */
16604@@ -1121,7 +1390,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
16605
16606 ENTRY(mcount)
16607 ret
16608-END(mcount)
16609+ENDPROC(mcount)
16610
16611 ENTRY(ftrace_caller)
16612 cmpl $0, function_trace_stop
16613@@ -1154,7 +1423,7 @@ ftrace_graph_call:
16614 .globl ftrace_stub
16615 ftrace_stub:
16616 ret
16617-END(ftrace_caller)
16618+ENDPROC(ftrace_caller)
16619
16620 ENTRY(ftrace_regs_caller)
16621 pushf /* push flags before compare (in cs location) */
16622@@ -1255,7 +1524,7 @@ trace:
16623 popl %ecx
16624 popl %eax
16625 jmp ftrace_stub
16626-END(mcount)
16627+ENDPROC(mcount)
16628 #endif /* CONFIG_DYNAMIC_FTRACE */
16629 #endif /* CONFIG_FUNCTION_TRACER */
16630
16631@@ -1273,7 +1542,7 @@ ENTRY(ftrace_graph_caller)
16632 popl %ecx
16633 popl %eax
16634 ret
16635-END(ftrace_graph_caller)
16636+ENDPROC(ftrace_graph_caller)
16637
16638 .globl return_to_handler
16639 return_to_handler:
16640@@ -1329,15 +1598,18 @@ error_code:
16641 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
16642 REG_TO_PTGS %ecx
16643 SET_KERNEL_GS %ecx
16644- movl $(__USER_DS), %ecx
16645+ movl $(__KERNEL_DS), %ecx
16646 movl %ecx, %ds
16647 movl %ecx, %es
16648+
16649+ pax_enter_kernel
16650+
16651 TRACE_IRQS_OFF
16652 movl %esp,%eax # pt_regs pointer
16653 call *%edi
16654 jmp ret_from_exception
16655 CFI_ENDPROC
16656-END(page_fault)
16657+ENDPROC(page_fault)
16658
16659 /*
16660 * Debug traps and NMI can happen at the one SYSENTER instruction
16661@@ -1380,7 +1652,7 @@ debug_stack_correct:
16662 call do_debug
16663 jmp ret_from_exception
16664 CFI_ENDPROC
16665-END(debug)
16666+ENDPROC(debug)
16667
16668 /*
16669 * NMI is doubly nasty. It can happen _while_ we're handling
16670@@ -1418,6 +1690,9 @@ nmi_stack_correct:
16671 xorl %edx,%edx # zero error code
16672 movl %esp,%eax # pt_regs pointer
16673 call do_nmi
16674+
16675+ pax_exit_kernel
16676+
16677 jmp restore_all_notrace
16678 CFI_ENDPROC
16679
16680@@ -1454,12 +1729,15 @@ nmi_espfix_stack:
16681 FIXUP_ESPFIX_STACK # %eax == %esp
16682 xorl %edx,%edx # zero error code
16683 call do_nmi
16684+
16685+ pax_exit_kernel
16686+
16687 RESTORE_REGS
16688 lss 12+4(%esp), %esp # back to espfix stack
16689 CFI_ADJUST_CFA_OFFSET -24
16690 jmp irq_return
16691 CFI_ENDPROC
16692-END(nmi)
16693+ENDPROC(nmi)
16694
16695 ENTRY(int3)
16696 RING0_INT_FRAME
16697@@ -1472,14 +1750,14 @@ ENTRY(int3)
16698 call do_int3
16699 jmp ret_from_exception
16700 CFI_ENDPROC
16701-END(int3)
16702+ENDPROC(int3)
16703
16704 ENTRY(general_protection)
16705 RING0_EC_FRAME
16706 pushl_cfi $do_general_protection
16707 jmp error_code
16708 CFI_ENDPROC
16709-END(general_protection)
16710+ENDPROC(general_protection)
16711
16712 #ifdef CONFIG_KVM_GUEST
16713 ENTRY(async_page_fault)
16714@@ -1488,7 +1766,7 @@ ENTRY(async_page_fault)
16715 pushl_cfi $do_async_page_fault
16716 jmp error_code
16717 CFI_ENDPROC
16718-END(async_page_fault)
16719+ENDPROC(async_page_fault)
16720 #endif
16721
16722 /*
16723diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
16724index 1328fe4..cb03298 100644
16725--- a/arch/x86/kernel/entry_64.S
16726+++ b/arch/x86/kernel/entry_64.S
16727@@ -59,6 +59,8 @@
16728 #include <asm/rcu.h>
16729 #include <asm/smap.h>
16730 #include <linux/err.h>
16731+#include <asm/pgtable.h>
16732+#include <asm/alternative-asm.h>
16733
16734 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
16735 #include <linux/elf-em.h>
16736@@ -80,8 +82,9 @@
16737 #ifdef CONFIG_DYNAMIC_FTRACE
16738
16739 ENTRY(function_hook)
16740+ pax_force_retaddr
16741 retq
16742-END(function_hook)
16743+ENDPROC(function_hook)
16744
16745 /* skip is set if stack has been adjusted */
16746 .macro ftrace_caller_setup skip=0
16747@@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
16748 #endif
16749
16750 GLOBAL(ftrace_stub)
16751+ pax_force_retaddr
16752 retq
16753-END(ftrace_caller)
16754+ENDPROC(ftrace_caller)
16755
16756 ENTRY(ftrace_regs_caller)
16757 /* Save the current flags before compare (in SS location)*/
16758@@ -191,7 +195,7 @@ ftrace_restore_flags:
16759 popfq
16760 jmp ftrace_stub
16761
16762-END(ftrace_regs_caller)
16763+ENDPROC(ftrace_regs_caller)
16764
16765
16766 #else /* ! CONFIG_DYNAMIC_FTRACE */
16767@@ -212,6 +216,7 @@ ENTRY(function_hook)
16768 #endif
16769
16770 GLOBAL(ftrace_stub)
16771+ pax_force_retaddr
16772 retq
16773
16774 trace:
16775@@ -225,12 +230,13 @@ trace:
16776 #endif
16777 subq $MCOUNT_INSN_SIZE, %rdi
16778
16779+ pax_force_fptr ftrace_trace_function
16780 call *ftrace_trace_function
16781
16782 MCOUNT_RESTORE_FRAME
16783
16784 jmp ftrace_stub
16785-END(function_hook)
16786+ENDPROC(function_hook)
16787 #endif /* CONFIG_DYNAMIC_FTRACE */
16788 #endif /* CONFIG_FUNCTION_TRACER */
16789
16790@@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
16791
16792 MCOUNT_RESTORE_FRAME
16793
16794+ pax_force_retaddr
16795 retq
16796-END(ftrace_graph_caller)
16797+ENDPROC(ftrace_graph_caller)
16798
16799 GLOBAL(return_to_handler)
16800 subq $24, %rsp
16801@@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
16802 movq 8(%rsp), %rdx
16803 movq (%rsp), %rax
16804 addq $24, %rsp
16805+ pax_force_fptr %rdi
16806 jmp *%rdi
16807+ENDPROC(return_to_handler)
16808 #endif
16809
16810
16811@@ -284,6 +293,273 @@ ENTRY(native_usergs_sysret64)
16812 ENDPROC(native_usergs_sysret64)
16813 #endif /* CONFIG_PARAVIRT */
16814
16815+ .macro ljmpq sel, off
16816+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
16817+ .byte 0x48; ljmp *1234f(%rip)
16818+ .pushsection .rodata
16819+ .align 16
16820+ 1234: .quad \off; .word \sel
16821+ .popsection
16822+#else
16823+ pushq $\sel
16824+ pushq $\off
16825+ lretq
16826+#endif
16827+ .endm
16828+
16829+ .macro pax_enter_kernel
16830+ pax_set_fptr_mask
16831+#ifdef CONFIG_PAX_KERNEXEC
16832+ call pax_enter_kernel
16833+#endif
16834+ .endm
16835+
16836+ .macro pax_exit_kernel
16837+#ifdef CONFIG_PAX_KERNEXEC
16838+ call pax_exit_kernel
16839+#endif
16840+ .endm
16841+
16842+#ifdef CONFIG_PAX_KERNEXEC
16843+ENTRY(pax_enter_kernel)
16844+ pushq %rdi
16845+
16846+#ifdef CONFIG_PARAVIRT
16847+ PV_SAVE_REGS(CLBR_RDI)
16848+#endif
16849+
16850+ GET_CR0_INTO_RDI
16851+ bts $16,%rdi
16852+ jnc 3f
16853+ mov %cs,%edi
16854+ cmp $__KERNEL_CS,%edi
16855+ jnz 2f
16856+1:
16857+
16858+#ifdef CONFIG_PARAVIRT
16859+ PV_RESTORE_REGS(CLBR_RDI)
16860+#endif
16861+
16862+ popq %rdi
16863+ pax_force_retaddr
16864+ retq
16865+
16866+2: ljmpq __KERNEL_CS,1f
16867+3: ljmpq __KERNEXEC_KERNEL_CS,4f
16868+4: SET_RDI_INTO_CR0
16869+ jmp 1b
16870+ENDPROC(pax_enter_kernel)
16871+
16872+ENTRY(pax_exit_kernel)
16873+ pushq %rdi
16874+
16875+#ifdef CONFIG_PARAVIRT
16876+ PV_SAVE_REGS(CLBR_RDI)
16877+#endif
16878+
16879+ mov %cs,%rdi
16880+ cmp $__KERNEXEC_KERNEL_CS,%edi
16881+ jz 2f
16882+1:
16883+
16884+#ifdef CONFIG_PARAVIRT
16885+ PV_RESTORE_REGS(CLBR_RDI);
16886+#endif
16887+
16888+ popq %rdi
16889+ pax_force_retaddr
16890+ retq
16891+
16892+2: GET_CR0_INTO_RDI
16893+ btr $16,%rdi
16894+ ljmpq __KERNEL_CS,3f
16895+3: SET_RDI_INTO_CR0
16896+ jmp 1b
16897+ENDPROC(pax_exit_kernel)
16898+#endif
16899+
16900+ .macro pax_enter_kernel_user
16901+ pax_set_fptr_mask
16902+#ifdef CONFIG_PAX_MEMORY_UDEREF
16903+ call pax_enter_kernel_user
16904+#endif
16905+ .endm
16906+
16907+ .macro pax_exit_kernel_user
16908+#ifdef CONFIG_PAX_MEMORY_UDEREF
16909+ call pax_exit_kernel_user
16910+#endif
16911+#ifdef CONFIG_PAX_RANDKSTACK
16912+ pushq %rax
16913+ call pax_randomize_kstack
16914+ popq %rax
16915+#endif
16916+ .endm
16917+
16918+#ifdef CONFIG_PAX_MEMORY_UDEREF
16919+ENTRY(pax_enter_kernel_user)
16920+ pushq %rdi
16921+ pushq %rbx
16922+
16923+#ifdef CONFIG_PARAVIRT
16924+ PV_SAVE_REGS(CLBR_RDI)
16925+#endif
16926+
16927+ GET_CR3_INTO_RDI
16928+ mov %rdi,%rbx
16929+ add $__START_KERNEL_map,%rbx
16930+ sub phys_base(%rip),%rbx
16931+
16932+#ifdef CONFIG_PARAVIRT
16933+ pushq %rdi
16934+ cmpl $0, pv_info+PARAVIRT_enabled
16935+ jz 1f
16936+ i = 0
16937+ .rept USER_PGD_PTRS
16938+ mov i*8(%rbx),%rsi
16939+ mov $0,%sil
16940+ lea i*8(%rbx),%rdi
16941+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
16942+ i = i + 1
16943+ .endr
16944+ jmp 2f
16945+1:
16946+#endif
16947+
16948+ i = 0
16949+ .rept USER_PGD_PTRS
16950+ movb $0,i*8(%rbx)
16951+ i = i + 1
16952+ .endr
16953+
16954+#ifdef CONFIG_PARAVIRT
16955+2: popq %rdi
16956+#endif
16957+ SET_RDI_INTO_CR3
16958+
16959+#ifdef CONFIG_PAX_KERNEXEC
16960+ GET_CR0_INTO_RDI
16961+ bts $16,%rdi
16962+ SET_RDI_INTO_CR0
16963+#endif
16964+
16965+#ifdef CONFIG_PARAVIRT
16966+ PV_RESTORE_REGS(CLBR_RDI)
16967+#endif
16968+
16969+ popq %rbx
16970+ popq %rdi
16971+ pax_force_retaddr
16972+ retq
16973+ENDPROC(pax_enter_kernel_user)
16974+
16975+ENTRY(pax_exit_kernel_user)
16976+ push %rdi
16977+
16978+#ifdef CONFIG_PARAVIRT
16979+ pushq %rbx
16980+ PV_SAVE_REGS(CLBR_RDI)
16981+#endif
16982+
16983+#ifdef CONFIG_PAX_KERNEXEC
16984+ GET_CR0_INTO_RDI
16985+ btr $16,%rdi
16986+ SET_RDI_INTO_CR0
16987+#endif
16988+
16989+ GET_CR3_INTO_RDI
16990+ add $__START_KERNEL_map,%rdi
16991+ sub phys_base(%rip),%rdi
16992+
16993+#ifdef CONFIG_PARAVIRT
16994+ cmpl $0, pv_info+PARAVIRT_enabled
16995+ jz 1f
16996+ mov %rdi,%rbx
16997+ i = 0
16998+ .rept USER_PGD_PTRS
16999+ mov i*8(%rbx),%rsi
17000+ mov $0x67,%sil
17001+ lea i*8(%rbx),%rdi
17002+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
17003+ i = i + 1
17004+ .endr
17005+ jmp 2f
17006+1:
17007+#endif
17008+
17009+ i = 0
17010+ .rept USER_PGD_PTRS
17011+ movb $0x67,i*8(%rdi)
17012+ i = i + 1
17013+ .endr
17014+
17015+#ifdef CONFIG_PARAVIRT
17016+2: PV_RESTORE_REGS(CLBR_RDI)
17017+ popq %rbx
17018+#endif
17019+
17020+ popq %rdi
17021+ pax_force_retaddr
17022+ retq
17023+ENDPROC(pax_exit_kernel_user)
17024+#endif
17025+
17026+.macro pax_erase_kstack
17027+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
17028+ call pax_erase_kstack
17029+#endif
17030+.endm
17031+
17032+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
17033+ENTRY(pax_erase_kstack)
17034+ pushq %rdi
17035+ pushq %rcx
17036+ pushq %rax
17037+ pushq %r11
17038+
17039+ GET_THREAD_INFO(%r11)
17040+ mov TI_lowest_stack(%r11), %rdi
17041+ mov $-0xBEEF, %rax
17042+ std
17043+
17044+1: mov %edi, %ecx
17045+ and $THREAD_SIZE_asm - 1, %ecx
17046+ shr $3, %ecx
17047+ repne scasq
17048+ jecxz 2f
17049+
17050+ cmp $2*8, %ecx
17051+ jc 2f
17052+
17053+ mov $2*8, %ecx
17054+ repe scasq
17055+ jecxz 2f
17056+ jne 1b
17057+
17058+2: cld
17059+ mov %esp, %ecx
17060+ sub %edi, %ecx
17061+
17062+ cmp $THREAD_SIZE_asm, %rcx
17063+ jb 3f
17064+ ud2
17065+3:
17066+
17067+ shr $3, %ecx
17068+ rep stosq
17069+
17070+ mov TI_task_thread_sp0(%r11), %rdi
17071+ sub $256, %rdi
17072+ mov %rdi, TI_lowest_stack(%r11)
17073+
17074+ popq %r11
17075+ popq %rax
17076+ popq %rcx
17077+ popq %rdi
17078+ pax_force_retaddr
17079+ ret
17080+ENDPROC(pax_erase_kstack)
17081+#endif
17082
17083 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
17084 #ifdef CONFIG_TRACE_IRQFLAGS
17085@@ -375,8 +651,8 @@ ENDPROC(native_usergs_sysret64)
17086 .endm
17087
17088 .macro UNFAKE_STACK_FRAME
17089- addq $8*6, %rsp
17090- CFI_ADJUST_CFA_OFFSET -(6*8)
17091+ addq $8*6 + ARG_SKIP, %rsp
17092+ CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
17093 .endm
17094
17095 /*
17096@@ -463,7 +739,7 @@ ENDPROC(native_usergs_sysret64)
17097 movq %rsp, %rsi
17098
17099 leaq -RBP(%rsp),%rdi /* arg1 for handler */
17100- testl $3, CS-RBP(%rsi)
17101+ testb $3, CS-RBP(%rsi)
17102 je 1f
17103 SWAPGS
17104 /*
17105@@ -498,9 +774,10 @@ ENTRY(save_rest)
17106 movq_cfi r15, R15+16
17107 movq %r11, 8(%rsp) /* return address */
17108 FIXUP_TOP_OF_STACK %r11, 16
17109+ pax_force_retaddr
17110 ret
17111 CFI_ENDPROC
17112-END(save_rest)
17113+ENDPROC(save_rest)
17114
17115 /* save complete stack frame */
17116 .pushsection .kprobes.text, "ax"
17117@@ -529,9 +806,10 @@ ENTRY(save_paranoid)
17118 js 1f /* negative -> in kernel */
17119 SWAPGS
17120 xorl %ebx,%ebx
17121-1: ret
17122+1: pax_force_retaddr_bts
17123+ ret
17124 CFI_ENDPROC
17125-END(save_paranoid)
17126+ENDPROC(save_paranoid)
17127 .popsection
17128
17129 /*
17130@@ -553,7 +831,7 @@ ENTRY(ret_from_fork)
17131
17132 RESTORE_REST
17133
17134- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
17135+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
17136 jz 1f
17137
17138 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
17139@@ -571,7 +849,7 @@ ENTRY(ret_from_fork)
17140 RESTORE_REST
17141 jmp int_ret_from_sys_call
17142 CFI_ENDPROC
17143-END(ret_from_fork)
17144+ENDPROC(ret_from_fork)
17145
17146 /*
17147 * System call entry. Up to 6 arguments in registers are supported.
17148@@ -608,7 +886,7 @@ END(ret_from_fork)
17149 ENTRY(system_call)
17150 CFI_STARTPROC simple
17151 CFI_SIGNAL_FRAME
17152- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
17153+ CFI_DEF_CFA rsp,0
17154 CFI_REGISTER rip,rcx
17155 /*CFI_REGISTER rflags,r11*/
17156 SWAPGS_UNSAFE_STACK
17157@@ -621,16 +899,23 @@ GLOBAL(system_call_after_swapgs)
17158
17159 movq %rsp,PER_CPU_VAR(old_rsp)
17160 movq PER_CPU_VAR(kernel_stack),%rsp
17161+ SAVE_ARGS 8*6,0
17162+ pax_enter_kernel_user
17163+
17164+#ifdef CONFIG_PAX_RANDKSTACK
17165+ pax_erase_kstack
17166+#endif
17167+
17168 /*
17169 * No need to follow this irqs off/on section - it's straight
17170 * and short:
17171 */
17172 ENABLE_INTERRUPTS(CLBR_NONE)
17173- SAVE_ARGS 8,0
17174 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
17175 movq %rcx,RIP-ARGOFFSET(%rsp)
17176 CFI_REL_OFFSET rip,RIP-ARGOFFSET
17177- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
17178+ GET_THREAD_INFO(%rcx)
17179+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
17180 jnz tracesys
17181 system_call_fastpath:
17182 #if __SYSCALL_MASK == ~0
17183@@ -640,7 +925,7 @@ system_call_fastpath:
17184 cmpl $__NR_syscall_max,%eax
17185 #endif
17186 ja badsys
17187- movq %r10,%rcx
17188+ movq R10-ARGOFFSET(%rsp),%rcx
17189 call *sys_call_table(,%rax,8) # XXX: rip relative
17190 movq %rax,RAX-ARGOFFSET(%rsp)
17191 /*
17192@@ -654,10 +939,13 @@ sysret_check:
17193 LOCKDEP_SYS_EXIT
17194 DISABLE_INTERRUPTS(CLBR_NONE)
17195 TRACE_IRQS_OFF
17196- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
17197+ GET_THREAD_INFO(%rcx)
17198+ movl TI_flags(%rcx),%edx
17199 andl %edi,%edx
17200 jnz sysret_careful
17201 CFI_REMEMBER_STATE
17202+ pax_exit_kernel_user
17203+ pax_erase_kstack
17204 /*
17205 * sysretq will re-enable interrupts:
17206 */
17207@@ -709,14 +997,18 @@ badsys:
17208 * jump back to the normal fast path.
17209 */
17210 auditsys:
17211- movq %r10,%r9 /* 6th arg: 4th syscall arg */
17212+ movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
17213 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
17214 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
17215 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
17216 movq %rax,%rsi /* 2nd arg: syscall number */
17217 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
17218 call __audit_syscall_entry
17219+
17220+ pax_erase_kstack
17221+
17222 LOAD_ARGS 0 /* reload call-clobbered registers */
17223+ pax_set_fptr_mask
17224 jmp system_call_fastpath
17225
17226 /*
17227@@ -737,7 +1029,7 @@ sysret_audit:
17228 /* Do syscall tracing */
17229 tracesys:
17230 #ifdef CONFIG_AUDITSYSCALL
17231- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
17232+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
17233 jz auditsys
17234 #endif
17235 SAVE_REST
17236@@ -745,12 +1037,16 @@ tracesys:
17237 FIXUP_TOP_OF_STACK %rdi
17238 movq %rsp,%rdi
17239 call syscall_trace_enter
17240+
17241+ pax_erase_kstack
17242+
17243 /*
17244 * Reload arg registers from stack in case ptrace changed them.
17245 * We don't reload %rax because syscall_trace_enter() returned
17246 * the value it wants us to use in the table lookup.
17247 */
17248 LOAD_ARGS ARGOFFSET, 1
17249+ pax_set_fptr_mask
17250 RESTORE_REST
17251 #if __SYSCALL_MASK == ~0
17252 cmpq $__NR_syscall_max,%rax
17253@@ -759,7 +1055,7 @@ tracesys:
17254 cmpl $__NR_syscall_max,%eax
17255 #endif
17256 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
17257- movq %r10,%rcx /* fixup for C */
17258+ movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
17259 call *sys_call_table(,%rax,8)
17260 movq %rax,RAX-ARGOFFSET(%rsp)
17261 /* Use IRET because user could have changed frame */
17262@@ -780,7 +1076,9 @@ GLOBAL(int_with_check)
17263 andl %edi,%edx
17264 jnz int_careful
17265 andl $~TS_COMPAT,TI_status(%rcx)
17266- jmp retint_swapgs
17267+ pax_exit_kernel_user
17268+ pax_erase_kstack
17269+ jmp retint_swapgs_pax
17270
17271 /* Either reschedule or signal or syscall exit tracking needed. */
17272 /* First do a reschedule test. */
17273@@ -826,7 +1124,7 @@ int_restore_rest:
17274 TRACE_IRQS_OFF
17275 jmp int_with_check
17276 CFI_ENDPROC
17277-END(system_call)
17278+ENDPROC(system_call)
17279
17280 /*
17281 * Certain special system calls that need to save a complete full stack frame.
17282@@ -842,7 +1140,7 @@ ENTRY(\label)
17283 call \func
17284 jmp ptregscall_common
17285 CFI_ENDPROC
17286-END(\label)
17287+ENDPROC(\label)
17288 .endm
17289
17290 PTREGSCALL stub_clone, sys_clone, %r8
17291@@ -860,9 +1158,10 @@ ENTRY(ptregscall_common)
17292 movq_cfi_restore R12+8, r12
17293 movq_cfi_restore RBP+8, rbp
17294 movq_cfi_restore RBX+8, rbx
17295+ pax_force_retaddr
17296 ret $REST_SKIP /* pop extended registers */
17297 CFI_ENDPROC
17298-END(ptregscall_common)
17299+ENDPROC(ptregscall_common)
17300
17301 ENTRY(stub_execve)
17302 CFI_STARTPROC
17303@@ -876,7 +1175,7 @@ ENTRY(stub_execve)
17304 RESTORE_REST
17305 jmp int_ret_from_sys_call
17306 CFI_ENDPROC
17307-END(stub_execve)
17308+ENDPROC(stub_execve)
17309
17310 /*
17311 * sigreturn is special because it needs to restore all registers on return.
17312@@ -894,7 +1193,7 @@ ENTRY(stub_rt_sigreturn)
17313 RESTORE_REST
17314 jmp int_ret_from_sys_call
17315 CFI_ENDPROC
17316-END(stub_rt_sigreturn)
17317+ENDPROC(stub_rt_sigreturn)
17318
17319 #ifdef CONFIG_X86_X32_ABI
17320 PTREGSCALL stub_x32_sigaltstack, sys32_sigaltstack, %rdx
17321@@ -962,7 +1261,7 @@ vector=vector+1
17322 2: jmp common_interrupt
17323 .endr
17324 CFI_ENDPROC
17325-END(irq_entries_start)
17326+ENDPROC(irq_entries_start)
17327
17328 .previous
17329 END(interrupt)
17330@@ -982,6 +1281,16 @@ END(interrupt)
17331 subq $ORIG_RAX-RBP, %rsp
17332 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
17333 SAVE_ARGS_IRQ
17334+#ifdef CONFIG_PAX_MEMORY_UDEREF
17335+ testb $3, CS(%rdi)
17336+ jnz 1f
17337+ pax_enter_kernel
17338+ jmp 2f
17339+1: pax_enter_kernel_user
17340+2:
17341+#else
17342+ pax_enter_kernel
17343+#endif
17344 call \func
17345 .endm
17346
17347@@ -1014,7 +1323,7 @@ ret_from_intr:
17348
17349 exit_intr:
17350 GET_THREAD_INFO(%rcx)
17351- testl $3,CS-ARGOFFSET(%rsp)
17352+ testb $3,CS-ARGOFFSET(%rsp)
17353 je retint_kernel
17354
17355 /* Interrupt came from user space */
17356@@ -1036,12 +1345,16 @@ retint_swapgs: /* return to user-space */
17357 * The iretq could re-enable interrupts:
17358 */
17359 DISABLE_INTERRUPTS(CLBR_ANY)
17360+ pax_exit_kernel_user
17361+retint_swapgs_pax:
17362 TRACE_IRQS_IRETQ
17363 SWAPGS
17364 jmp restore_args
17365
17366 retint_restore_args: /* return to kernel space */
17367 DISABLE_INTERRUPTS(CLBR_ANY)
17368+ pax_exit_kernel
17369+ pax_force_retaddr (RIP-ARGOFFSET)
17370 /*
17371 * The iretq could re-enable interrupts:
17372 */
17373@@ -1124,7 +1437,7 @@ ENTRY(retint_kernel)
17374 #endif
17375
17376 CFI_ENDPROC
17377-END(common_interrupt)
17378+ENDPROC(common_interrupt)
17379 /*
17380 * End of kprobes section
17381 */
17382@@ -1142,7 +1455,7 @@ ENTRY(\sym)
17383 interrupt \do_sym
17384 jmp ret_from_intr
17385 CFI_ENDPROC
17386-END(\sym)
17387+ENDPROC(\sym)
17388 .endm
17389
17390 #ifdef CONFIG_SMP
17391@@ -1198,12 +1511,22 @@ ENTRY(\sym)
17392 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
17393 call error_entry
17394 DEFAULT_FRAME 0
17395+#ifdef CONFIG_PAX_MEMORY_UDEREF
17396+ testb $3, CS(%rsp)
17397+ jnz 1f
17398+ pax_enter_kernel
17399+ jmp 2f
17400+1: pax_enter_kernel_user
17401+2:
17402+#else
17403+ pax_enter_kernel
17404+#endif
17405 movq %rsp,%rdi /* pt_regs pointer */
17406 xorl %esi,%esi /* no error code */
17407 call \do_sym
17408 jmp error_exit /* %ebx: no swapgs flag */
17409 CFI_ENDPROC
17410-END(\sym)
17411+ENDPROC(\sym)
17412 .endm
17413
17414 .macro paranoidzeroentry sym do_sym
17415@@ -1216,15 +1539,25 @@ ENTRY(\sym)
17416 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
17417 call save_paranoid
17418 TRACE_IRQS_OFF
17419+#ifdef CONFIG_PAX_MEMORY_UDEREF
17420+ testb $3, CS(%rsp)
17421+ jnz 1f
17422+ pax_enter_kernel
17423+ jmp 2f
17424+1: pax_enter_kernel_user
17425+2:
17426+#else
17427+ pax_enter_kernel
17428+#endif
17429 movq %rsp,%rdi /* pt_regs pointer */
17430 xorl %esi,%esi /* no error code */
17431 call \do_sym
17432 jmp paranoid_exit /* %ebx: no swapgs flag */
17433 CFI_ENDPROC
17434-END(\sym)
17435+ENDPROC(\sym)
17436 .endm
17437
17438-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
17439+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
17440 .macro paranoidzeroentry_ist sym do_sym ist
17441 ENTRY(\sym)
17442 INTR_FRAME
17443@@ -1235,14 +1568,30 @@ ENTRY(\sym)
17444 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
17445 call save_paranoid
17446 TRACE_IRQS_OFF_DEBUG
17447+#ifdef CONFIG_PAX_MEMORY_UDEREF
17448+ testb $3, CS(%rsp)
17449+ jnz 1f
17450+ pax_enter_kernel
17451+ jmp 2f
17452+1: pax_enter_kernel_user
17453+2:
17454+#else
17455+ pax_enter_kernel
17456+#endif
17457 movq %rsp,%rdi /* pt_regs pointer */
17458 xorl %esi,%esi /* no error code */
17459+#ifdef CONFIG_SMP
17460+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
17461+ lea init_tss(%r12), %r12
17462+#else
17463+ lea init_tss(%rip), %r12
17464+#endif
17465 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
17466 call \do_sym
17467 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
17468 jmp paranoid_exit /* %ebx: no swapgs flag */
17469 CFI_ENDPROC
17470-END(\sym)
17471+ENDPROC(\sym)
17472 .endm
17473
17474 .macro errorentry sym do_sym
17475@@ -1254,13 +1603,23 @@ ENTRY(\sym)
17476 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
17477 call error_entry
17478 DEFAULT_FRAME 0
17479+#ifdef CONFIG_PAX_MEMORY_UDEREF
17480+ testb $3, CS(%rsp)
17481+ jnz 1f
17482+ pax_enter_kernel
17483+ jmp 2f
17484+1: pax_enter_kernel_user
17485+2:
17486+#else
17487+ pax_enter_kernel
17488+#endif
17489 movq %rsp,%rdi /* pt_regs pointer */
17490 movq ORIG_RAX(%rsp),%rsi /* get error code */
17491 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
17492 call \do_sym
17493 jmp error_exit /* %ebx: no swapgs flag */
17494 CFI_ENDPROC
17495-END(\sym)
17496+ENDPROC(\sym)
17497 .endm
17498
17499 /* error code is on the stack already */
17500@@ -1274,13 +1633,23 @@ ENTRY(\sym)
17501 call save_paranoid
17502 DEFAULT_FRAME 0
17503 TRACE_IRQS_OFF
17504+#ifdef CONFIG_PAX_MEMORY_UDEREF
17505+ testb $3, CS(%rsp)
17506+ jnz 1f
17507+ pax_enter_kernel
17508+ jmp 2f
17509+1: pax_enter_kernel_user
17510+2:
17511+#else
17512+ pax_enter_kernel
17513+#endif
17514 movq %rsp,%rdi /* pt_regs pointer */
17515 movq ORIG_RAX(%rsp),%rsi /* get error code */
17516 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
17517 call \do_sym
17518 jmp paranoid_exit /* %ebx: no swapgs flag */
17519 CFI_ENDPROC
17520-END(\sym)
17521+ENDPROC(\sym)
17522 .endm
17523
17524 zeroentry divide_error do_divide_error
17525@@ -1310,9 +1679,10 @@ gs_change:
17526 2: mfence /* workaround */
17527 SWAPGS
17528 popfq_cfi
17529+ pax_force_retaddr
17530 ret
17531 CFI_ENDPROC
17532-END(native_load_gs_index)
17533+ENDPROC(native_load_gs_index)
17534
17535 _ASM_EXTABLE(gs_change,bad_gs)
17536 .section .fixup,"ax"
17537@@ -1340,9 +1710,10 @@ ENTRY(call_softirq)
17538 CFI_DEF_CFA_REGISTER rsp
17539 CFI_ADJUST_CFA_OFFSET -8
17540 decl PER_CPU_VAR(irq_count)
17541+ pax_force_retaddr
17542 ret
17543 CFI_ENDPROC
17544-END(call_softirq)
17545+ENDPROC(call_softirq)
17546
17547 #ifdef CONFIG_XEN
17548 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
17549@@ -1380,7 +1751,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
17550 decl PER_CPU_VAR(irq_count)
17551 jmp error_exit
17552 CFI_ENDPROC
17553-END(xen_do_hypervisor_callback)
17554+ENDPROC(xen_do_hypervisor_callback)
17555
17556 /*
17557 * Hypervisor uses this for application faults while it executes.
17558@@ -1439,7 +1810,7 @@ ENTRY(xen_failsafe_callback)
17559 SAVE_ALL
17560 jmp error_exit
17561 CFI_ENDPROC
17562-END(xen_failsafe_callback)
17563+ENDPROC(xen_failsafe_callback)
17564
17565 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
17566 xen_hvm_callback_vector xen_evtchn_do_upcall
17567@@ -1488,16 +1859,31 @@ ENTRY(paranoid_exit)
17568 TRACE_IRQS_OFF_DEBUG
17569 testl %ebx,%ebx /* swapgs needed? */
17570 jnz paranoid_restore
17571- testl $3,CS(%rsp)
17572+ testb $3,CS(%rsp)
17573 jnz paranoid_userspace
17574+#ifdef CONFIG_PAX_MEMORY_UDEREF
17575+ pax_exit_kernel
17576+ TRACE_IRQS_IRETQ 0
17577+ SWAPGS_UNSAFE_STACK
17578+ RESTORE_ALL 8
17579+ pax_force_retaddr_bts
17580+ jmp irq_return
17581+#endif
17582 paranoid_swapgs:
17583+#ifdef CONFIG_PAX_MEMORY_UDEREF
17584+ pax_exit_kernel_user
17585+#else
17586+ pax_exit_kernel
17587+#endif
17588 TRACE_IRQS_IRETQ 0
17589 SWAPGS_UNSAFE_STACK
17590 RESTORE_ALL 8
17591 jmp irq_return
17592 paranoid_restore:
17593+ pax_exit_kernel
17594 TRACE_IRQS_IRETQ_DEBUG 0
17595 RESTORE_ALL 8
17596+ pax_force_retaddr_bts
17597 jmp irq_return
17598 paranoid_userspace:
17599 GET_THREAD_INFO(%rcx)
17600@@ -1526,7 +1912,7 @@ paranoid_schedule:
17601 TRACE_IRQS_OFF
17602 jmp paranoid_userspace
17603 CFI_ENDPROC
17604-END(paranoid_exit)
17605+ENDPROC(paranoid_exit)
17606
17607 /*
17608 * Exception entry point. This expects an error code/orig_rax on the stack.
17609@@ -1553,12 +1939,13 @@ ENTRY(error_entry)
17610 movq_cfi r14, R14+8
17611 movq_cfi r15, R15+8
17612 xorl %ebx,%ebx
17613- testl $3,CS+8(%rsp)
17614+ testb $3,CS+8(%rsp)
17615 je error_kernelspace
17616 error_swapgs:
17617 SWAPGS
17618 error_sti:
17619 TRACE_IRQS_OFF
17620+ pax_force_retaddr_bts
17621 ret
17622
17623 /*
17624@@ -1585,7 +1972,7 @@ bstep_iret:
17625 movq %rcx,RIP+8(%rsp)
17626 jmp error_swapgs
17627 CFI_ENDPROC
17628-END(error_entry)
17629+ENDPROC(error_entry)
17630
17631
17632 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
17633@@ -1605,7 +1992,7 @@ ENTRY(error_exit)
17634 jnz retint_careful
17635 jmp retint_swapgs
17636 CFI_ENDPROC
17637-END(error_exit)
17638+ENDPROC(error_exit)
17639
17640 /*
17641 * Test if a given stack is an NMI stack or not.
17642@@ -1663,9 +2050,11 @@ ENTRY(nmi)
17643 * If %cs was not the kernel segment, then the NMI triggered in user
17644 * space, which means it is definitely not nested.
17645 */
17646+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
17647+ je 1f
17648 cmpl $__KERNEL_CS, 16(%rsp)
17649 jne first_nmi
17650-
17651+1:
17652 /*
17653 * Check the special variable on the stack to see if NMIs are
17654 * executing.
17655@@ -1824,6 +2213,17 @@ end_repeat_nmi:
17656 */
17657 movq %cr2, %r12
17658
17659+#ifdef CONFIG_PAX_MEMORY_UDEREF
17660+ testb $3, CS(%rsp)
17661+ jnz 1f
17662+ pax_enter_kernel
17663+ jmp 2f
17664+1: pax_enter_kernel_user
17665+2:
17666+#else
17667+ pax_enter_kernel
17668+#endif
17669+
17670 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
17671 movq %rsp,%rdi
17672 movq $-1,%rsi
17673@@ -1839,21 +2239,32 @@ end_repeat_nmi:
17674 testl %ebx,%ebx /* swapgs needed? */
17675 jnz nmi_restore
17676 nmi_swapgs:
17677+#ifdef CONFIG_PAX_MEMORY_UDEREF
17678+ pax_exit_kernel_user
17679+#else
17680+ pax_exit_kernel
17681+#endif
17682 SWAPGS_UNSAFE_STACK
17683+ RESTORE_ALL 8
17684+ /* Clear the NMI executing stack variable */
17685+ movq $0, 10*8(%rsp)
17686+ jmp irq_return
17687 nmi_restore:
17688+ pax_exit_kernel
17689 RESTORE_ALL 8
17690+ pax_force_retaddr_bts
17691 /* Clear the NMI executing stack variable */
17692 movq $0, 10*8(%rsp)
17693 jmp irq_return
17694 CFI_ENDPROC
17695-END(nmi)
17696+ENDPROC(nmi)
17697
17698 ENTRY(ignore_sysret)
17699 CFI_STARTPROC
17700 mov $-ENOSYS,%eax
17701 sysret
17702 CFI_ENDPROC
17703-END(ignore_sysret)
17704+ENDPROC(ignore_sysret)
17705
17706 /*
17707 * End of kprobes section
17708diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
17709index 1d41402..af9a46a 100644
17710--- a/arch/x86/kernel/ftrace.c
17711+++ b/arch/x86/kernel/ftrace.c
17712@@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
17713 {
17714 unsigned char replaced[MCOUNT_INSN_SIZE];
17715
17716+ ip = ktla_ktva(ip);
17717+
17718 /*
17719 * Note: Due to modules and __init, code can
17720 * disappear and change, we need to protect against faulting
17721@@ -227,7 +229,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
17722 unsigned char old[MCOUNT_INSN_SIZE], *new;
17723 int ret;
17724
17725- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
17726+ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
17727 new = ftrace_call_replace(ip, (unsigned long)func);
17728
17729 /* See comment above by declaration of modifying_ftrace_code */
17730@@ -238,7 +240,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
17731 /* Also update the regs callback function */
17732 if (!ret) {
17733 ip = (unsigned long)(&ftrace_regs_call);
17734- memcpy(old, &ftrace_regs_call, MCOUNT_INSN_SIZE);
17735+ memcpy(old, ktla_ktva((void *)&ftrace_regs_call), MCOUNT_INSN_SIZE);
17736 new = ftrace_call_replace(ip, (unsigned long)func);
17737 ret = ftrace_modify_code(ip, old, new);
17738 }
17739@@ -279,7 +281,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
17740 * kernel identity mapping to modify code.
17741 */
17742 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
17743- ip = (unsigned long)__va(__pa(ip));
17744+ ip = (unsigned long)__va(__pa(ktla_ktva(ip)));
17745
17746 return probe_kernel_write((void *)ip, val, size);
17747 }
17748@@ -289,7 +291,7 @@ static int add_break(unsigned long ip, const char *old)
17749 unsigned char replaced[MCOUNT_INSN_SIZE];
17750 unsigned char brk = BREAKPOINT_INSTRUCTION;
17751
17752- if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
17753+ if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
17754 return -EFAULT;
17755
17756 /* Make sure it is what we expect it to be */
17757@@ -637,7 +639,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
17758 return ret;
17759
17760 fail_update:
17761- probe_kernel_write((void *)ip, &old_code[0], 1);
17762+ probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
17763 goto out;
17764 }
17765
17766@@ -670,6 +672,8 @@ static int ftrace_mod_jmp(unsigned long ip,
17767 {
17768 unsigned char code[MCOUNT_INSN_SIZE];
17769
17770+ ip = ktla_ktva(ip);
17771+
17772 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
17773 return -EFAULT;
17774
17775diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
17776index c18f59d..9c0c9f6 100644
17777--- a/arch/x86/kernel/head32.c
17778+++ b/arch/x86/kernel/head32.c
17779@@ -18,6 +18,7 @@
17780 #include <asm/io_apic.h>
17781 #include <asm/bios_ebda.h>
17782 #include <asm/tlbflush.h>
17783+#include <asm/boot.h>
17784
17785 static void __init i386_default_early_setup(void)
17786 {
17787@@ -30,8 +31,7 @@ static void __init i386_default_early_setup(void)
17788
17789 void __init i386_start_kernel(void)
17790 {
17791- memblock_reserve(__pa_symbol(&_text),
17792- __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
17793+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
17794
17795 #ifdef CONFIG_BLK_DEV_INITRD
17796 /* Reserve INITRD */
17797diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
17798index 4dac2f6..bc6a335 100644
17799--- a/arch/x86/kernel/head_32.S
17800+++ b/arch/x86/kernel/head_32.S
17801@@ -26,6 +26,12 @@
17802 /* Physical address */
17803 #define pa(X) ((X) - __PAGE_OFFSET)
17804
17805+#ifdef CONFIG_PAX_KERNEXEC
17806+#define ta(X) (X)
17807+#else
17808+#define ta(X) ((X) - __PAGE_OFFSET)
17809+#endif
17810+
17811 /*
17812 * References to members of the new_cpu_data structure.
17813 */
17814@@ -55,11 +61,7 @@
17815 * and small than max_low_pfn, otherwise will waste some page table entries
17816 */
17817
17818-#if PTRS_PER_PMD > 1
17819-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
17820-#else
17821-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
17822-#endif
17823+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
17824
17825 /* Number of possible pages in the lowmem region */
17826 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
17827@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
17828 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
17829
17830 /*
17831+ * Real beginning of normal "text" segment
17832+ */
17833+ENTRY(stext)
17834+ENTRY(_stext)
17835+
17836+/*
17837 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
17838 * %esi points to the real-mode code as a 32-bit pointer.
17839 * CS and DS must be 4 GB flat segments, but we don't depend on
17840@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
17841 * can.
17842 */
17843 __HEAD
17844+
17845+#ifdef CONFIG_PAX_KERNEXEC
17846+ jmp startup_32
17847+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
17848+.fill PAGE_SIZE-5,1,0xcc
17849+#endif
17850+
17851 ENTRY(startup_32)
17852 movl pa(stack_start),%ecx
17853
17854@@ -106,6 +121,59 @@ ENTRY(startup_32)
17855 2:
17856 leal -__PAGE_OFFSET(%ecx),%esp
17857
17858+#ifdef CONFIG_SMP
17859+ movl $pa(cpu_gdt_table),%edi
17860+ movl $__per_cpu_load,%eax
17861+ movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
17862+ rorl $16,%eax
17863+ movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
17864+ movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
17865+ movl $__per_cpu_end - 1,%eax
17866+ subl $__per_cpu_start,%eax
17867+ movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
17868+#endif
17869+
17870+#ifdef CONFIG_PAX_MEMORY_UDEREF
17871+ movl $NR_CPUS,%ecx
17872+ movl $pa(cpu_gdt_table),%edi
17873+1:
17874+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
17875+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
17876+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
17877+ addl $PAGE_SIZE_asm,%edi
17878+ loop 1b
17879+#endif
17880+
17881+#ifdef CONFIG_PAX_KERNEXEC
17882+ movl $pa(boot_gdt),%edi
17883+ movl $__LOAD_PHYSICAL_ADDR,%eax
17884+ movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
17885+ rorl $16,%eax
17886+ movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
17887+ movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
17888+ rorl $16,%eax
17889+
17890+ ljmp $(__BOOT_CS),$1f
17891+1:
17892+
17893+ movl $NR_CPUS,%ecx
17894+ movl $pa(cpu_gdt_table),%edi
17895+ addl $__PAGE_OFFSET,%eax
17896+1:
17897+ movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
17898+ movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
17899+ movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
17900+ movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
17901+ rorl $16,%eax
17902+ movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
17903+ movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
17904+ movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
17905+ movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
17906+ rorl $16,%eax
17907+ addl $PAGE_SIZE_asm,%edi
17908+ loop 1b
17909+#endif
17910+
17911 /*
17912 * Clear BSS first so that there are no surprises...
17913 */
17914@@ -196,8 +264,11 @@ ENTRY(startup_32)
17915 movl %eax, pa(max_pfn_mapped)
17916
17917 /* Do early initialization of the fixmap area */
17918- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
17919- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
17920+#ifdef CONFIG_COMPAT_VDSO
17921+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
17922+#else
17923+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
17924+#endif
17925 #else /* Not PAE */
17926
17927 page_pde_offset = (__PAGE_OFFSET >> 20);
17928@@ -227,8 +298,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
17929 movl %eax, pa(max_pfn_mapped)
17930
17931 /* Do early initialization of the fixmap area */
17932- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
17933- movl %eax,pa(initial_page_table+0xffc)
17934+#ifdef CONFIG_COMPAT_VDSO
17935+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
17936+#else
17937+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
17938+#endif
17939 #endif
17940
17941 #ifdef CONFIG_PARAVIRT
17942@@ -242,9 +316,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
17943 cmpl $num_subarch_entries, %eax
17944 jae bad_subarch
17945
17946- movl pa(subarch_entries)(,%eax,4), %eax
17947- subl $__PAGE_OFFSET, %eax
17948- jmp *%eax
17949+ jmp *pa(subarch_entries)(,%eax,4)
17950
17951 bad_subarch:
17952 WEAK(lguest_entry)
17953@@ -256,10 +328,10 @@ WEAK(xen_entry)
17954 __INITDATA
17955
17956 subarch_entries:
17957- .long default_entry /* normal x86/PC */
17958- .long lguest_entry /* lguest hypervisor */
17959- .long xen_entry /* Xen hypervisor */
17960- .long default_entry /* Moorestown MID */
17961+ .long ta(default_entry) /* normal x86/PC */
17962+ .long ta(lguest_entry) /* lguest hypervisor */
17963+ .long ta(xen_entry) /* Xen hypervisor */
17964+ .long ta(default_entry) /* Moorestown MID */
17965 num_subarch_entries = (. - subarch_entries) / 4
17966 .previous
17967 #else
17968@@ -316,6 +388,7 @@ default_entry:
17969 movl pa(mmu_cr4_features),%eax
17970 movl %eax,%cr4
17971
17972+#ifdef CONFIG_X86_PAE
17973 testb $X86_CR4_PAE, %al # check if PAE is enabled
17974 jz 6f
17975
17976@@ -344,6 +417,9 @@ default_entry:
17977 /* Make changes effective */
17978 wrmsr
17979
17980+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
17981+#endif
17982+
17983 6:
17984
17985 /*
17986@@ -442,14 +518,20 @@ is386: movl $2,%ecx # set MP
17987 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
17988 movl %eax,%ss # after changing gdt.
17989
17990- movl $(__USER_DS),%eax # DS/ES contains default USER segment
17991+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
17992 movl %eax,%ds
17993 movl %eax,%es
17994
17995 movl $(__KERNEL_PERCPU), %eax
17996 movl %eax,%fs # set this cpu's percpu
17997
17998+#ifdef CONFIG_CC_STACKPROTECTOR
17999 movl $(__KERNEL_STACK_CANARY),%eax
18000+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
18001+ movl $(__USER_DS),%eax
18002+#else
18003+ xorl %eax,%eax
18004+#endif
18005 movl %eax,%gs
18006
18007 xorl %eax,%eax # Clear LDT
18008@@ -526,8 +608,11 @@ setup_once:
18009 * relocation. Manually set base address in stack canary
18010 * segment descriptor.
18011 */
18012- movl $gdt_page,%eax
18013+ movl $cpu_gdt_table,%eax
18014 movl $stack_canary,%ecx
18015+#ifdef CONFIG_SMP
18016+ addl $__per_cpu_load,%ecx
18017+#endif
18018 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
18019 shrl $16, %ecx
18020 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
18021@@ -558,7 +643,7 @@ ENDPROC(early_idt_handlers)
18022 /* This is global to keep gas from relaxing the jumps */
18023 ENTRY(early_idt_handler)
18024 cld
18025- cmpl $2,%ss:early_recursion_flag
18026+ cmpl $1,%ss:early_recursion_flag
18027 je hlt_loop
18028 incl %ss:early_recursion_flag
18029
18030@@ -596,8 +681,8 @@ ENTRY(early_idt_handler)
18031 pushl (20+6*4)(%esp) /* trapno */
18032 pushl $fault_msg
18033 call printk
18034-#endif
18035 call dump_stack
18036+#endif
18037 hlt_loop:
18038 hlt
18039 jmp hlt_loop
18040@@ -616,8 +701,11 @@ ENDPROC(early_idt_handler)
18041 /* This is the default interrupt "handler" :-) */
18042 ALIGN
18043 ignore_int:
18044- cld
18045 #ifdef CONFIG_PRINTK
18046+ cmpl $2,%ss:early_recursion_flag
18047+ je hlt_loop
18048+ incl %ss:early_recursion_flag
18049+ cld
18050 pushl %eax
18051 pushl %ecx
18052 pushl %edx
18053@@ -626,9 +714,6 @@ ignore_int:
18054 movl $(__KERNEL_DS),%eax
18055 movl %eax,%ds
18056 movl %eax,%es
18057- cmpl $2,early_recursion_flag
18058- je hlt_loop
18059- incl early_recursion_flag
18060 pushl 16(%esp)
18061 pushl 24(%esp)
18062 pushl 32(%esp)
18063@@ -662,29 +747,43 @@ ENTRY(setup_once_ref)
18064 /*
18065 * BSS section
18066 */
18067-__PAGE_ALIGNED_BSS
18068- .align PAGE_SIZE
18069 #ifdef CONFIG_X86_PAE
18070+.section .initial_pg_pmd,"a",@progbits
18071 initial_pg_pmd:
18072 .fill 1024*KPMDS,4,0
18073 #else
18074+.section .initial_page_table,"a",@progbits
18075 ENTRY(initial_page_table)
18076 .fill 1024,4,0
18077 #endif
18078+.section .initial_pg_fixmap,"a",@progbits
18079 initial_pg_fixmap:
18080 .fill 1024,4,0
18081+.section .empty_zero_page,"a",@progbits
18082 ENTRY(empty_zero_page)
18083 .fill 4096,1,0
18084+.section .swapper_pg_dir,"a",@progbits
18085 ENTRY(swapper_pg_dir)
18086+#ifdef CONFIG_X86_PAE
18087+ .fill 4,8,0
18088+#else
18089 .fill 1024,4,0
18090+#endif
18091+
18092+/*
18093+ * The IDT has to be page-aligned to simplify the Pentium
18094+ * F0 0F bug workaround.. We have a special link segment
18095+ * for this.
18096+ */
18097+.section .idt,"a",@progbits
18098+ENTRY(idt_table)
18099+ .fill 256,8,0
18100
18101 /*
18102 * This starts the data section.
18103 */
18104 #ifdef CONFIG_X86_PAE
18105-__PAGE_ALIGNED_DATA
18106- /* Page-aligned for the benefit of paravirt? */
18107- .align PAGE_SIZE
18108+.section .initial_page_table,"a",@progbits
18109 ENTRY(initial_page_table)
18110 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
18111 # if KPMDS == 3
18112@@ -703,12 +802,20 @@ ENTRY(initial_page_table)
18113 # error "Kernel PMDs should be 1, 2 or 3"
18114 # endif
18115 .align PAGE_SIZE /* needs to be page-sized too */
18116+
18117+#ifdef CONFIG_PAX_PER_CPU_PGD
18118+ENTRY(cpu_pgd)
18119+ .rept NR_CPUS
18120+ .fill 4,8,0
18121+ .endr
18122+#endif
18123+
18124 #endif
18125
18126 .data
18127 .balign 4
18128 ENTRY(stack_start)
18129- .long init_thread_union+THREAD_SIZE
18130+ .long init_thread_union+THREAD_SIZE-8
18131
18132 __INITRODATA
18133 int_msg:
18134@@ -736,7 +843,7 @@ fault_msg:
18135 * segment size, and 32-bit linear address value:
18136 */
18137
18138- .data
18139+.section .rodata,"a",@progbits
18140 .globl boot_gdt_descr
18141 .globl idt_descr
18142
18143@@ -745,7 +852,7 @@ fault_msg:
18144 .word 0 # 32 bit align gdt_desc.address
18145 boot_gdt_descr:
18146 .word __BOOT_DS+7
18147- .long boot_gdt - __PAGE_OFFSET
18148+ .long pa(boot_gdt)
18149
18150 .word 0 # 32-bit align idt_desc.address
18151 idt_descr:
18152@@ -756,7 +863,7 @@ idt_descr:
18153 .word 0 # 32 bit align gdt_desc.address
18154 ENTRY(early_gdt_descr)
18155 .word GDT_ENTRIES*8-1
18156- .long gdt_page /* Overwritten for secondary CPUs */
18157+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
18158
18159 /*
18160 * The boot_gdt must mirror the equivalent in setup.S and is
18161@@ -765,5 +872,65 @@ ENTRY(early_gdt_descr)
18162 .align L1_CACHE_BYTES
18163 ENTRY(boot_gdt)
18164 .fill GDT_ENTRY_BOOT_CS,8,0
18165- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
18166- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
18167+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
18168+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
18169+
18170+ .align PAGE_SIZE_asm
18171+ENTRY(cpu_gdt_table)
18172+ .rept NR_CPUS
18173+ .quad 0x0000000000000000 /* NULL descriptor */
18174+ .quad 0x0000000000000000 /* 0x0b reserved */
18175+ .quad 0x0000000000000000 /* 0x13 reserved */
18176+ .quad 0x0000000000000000 /* 0x1b reserved */
18177+
18178+#ifdef CONFIG_PAX_KERNEXEC
18179+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
18180+#else
18181+ .quad 0x0000000000000000 /* 0x20 unused */
18182+#endif
18183+
18184+ .quad 0x0000000000000000 /* 0x28 unused */
18185+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
18186+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
18187+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
18188+ .quad 0x0000000000000000 /* 0x4b reserved */
18189+ .quad 0x0000000000000000 /* 0x53 reserved */
18190+ .quad 0x0000000000000000 /* 0x5b reserved */
18191+
18192+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
18193+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
18194+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
18195+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
18196+
18197+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
18198+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
18199+
18200+ /*
18201+ * Segments used for calling PnP BIOS have byte granularity.
18202+ * The code segments and data segments have fixed 64k limits,
18203+ * the transfer segment sizes are set at run time.
18204+ */
18205+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
18206+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
18207+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
18208+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
18209+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
18210+
18211+ /*
18212+ * The APM segments have byte granularity and their bases
18213+ * are set at run time. All have 64k limits.
18214+ */
18215+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
18216+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
18217+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
18218+
18219+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
18220+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
18221+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
18222+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
18223+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
18224+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
18225+
18226+ /* Be sure this is zeroed to avoid false validations in Xen */
18227+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
18228+ .endr
18229diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
18230index 94bf9cc..400455a 100644
18231--- a/arch/x86/kernel/head_64.S
18232+++ b/arch/x86/kernel/head_64.S
18233@@ -20,6 +20,8 @@
18234 #include <asm/processor-flags.h>
18235 #include <asm/percpu.h>
18236 #include <asm/nops.h>
18237+#include <asm/cpufeature.h>
18238+#include <asm/alternative-asm.h>
18239
18240 #ifdef CONFIG_PARAVIRT
18241 #include <asm/asm-offsets.h>
18242@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
18243 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
18244 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
18245 L3_START_KERNEL = pud_index(__START_KERNEL_map)
18246+L4_VMALLOC_START = pgd_index(VMALLOC_START)
18247+L3_VMALLOC_START = pud_index(VMALLOC_START)
18248+L4_VMALLOC_END = pgd_index(VMALLOC_END)
18249+L3_VMALLOC_END = pud_index(VMALLOC_END)
18250+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
18251+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
18252
18253 .text
18254 __HEAD
18255@@ -88,35 +96,23 @@ startup_64:
18256 */
18257 addq %rbp, init_level4_pgt + 0(%rip)
18258 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
18259+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
18260+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
18261+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
18262 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
18263
18264 addq %rbp, level3_ident_pgt + 0(%rip)
18265+#ifndef CONFIG_XEN
18266+ addq %rbp, level3_ident_pgt + 8(%rip)
18267+#endif
18268
18269- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
18270- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
18271+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
18272+
18273+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
18274+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
18275
18276 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
18277-
18278- /* Add an Identity mapping if I am above 1G */
18279- leaq _text(%rip), %rdi
18280- andq $PMD_PAGE_MASK, %rdi
18281-
18282- movq %rdi, %rax
18283- shrq $PUD_SHIFT, %rax
18284- andq $(PTRS_PER_PUD - 1), %rax
18285- jz ident_complete
18286-
18287- leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
18288- leaq level3_ident_pgt(%rip), %rbx
18289- movq %rdx, 0(%rbx, %rax, 8)
18290-
18291- movq %rdi, %rax
18292- shrq $PMD_SHIFT, %rax
18293- andq $(PTRS_PER_PMD - 1), %rax
18294- leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
18295- leaq level2_spare_pgt(%rip), %rbx
18296- movq %rdx, 0(%rbx, %rax, 8)
18297-ident_complete:
18298+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
18299
18300 /*
18301 * Fixup the kernel text+data virtual addresses. Note that
18302@@ -159,8 +155,8 @@ ENTRY(secondary_startup_64)
18303 * after the boot processor executes this code.
18304 */
18305
18306- /* Enable PAE mode and PGE */
18307- movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
18308+ /* Enable PAE mode and PSE/PGE */
18309+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
18310 movq %rax, %cr4
18311
18312 /* Setup early boot stage 4 level pagetables. */
18313@@ -182,9 +178,17 @@ ENTRY(secondary_startup_64)
18314 movl $MSR_EFER, %ecx
18315 rdmsr
18316 btsl $_EFER_SCE, %eax /* Enable System Call */
18317- btl $20,%edi /* No Execute supported? */
18318+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
18319 jnc 1f
18320 btsl $_EFER_NX, %eax
18321+ leaq init_level4_pgt(%rip), %rdi
18322+#ifndef CONFIG_EFI
18323+ btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
18324+#endif
18325+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
18326+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
18327+ btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
18328+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
18329 1: wrmsr /* Make changes effective */
18330
18331 /* Setup cr0 */
18332@@ -246,6 +250,7 @@ ENTRY(secondary_startup_64)
18333 * jump. In addition we need to ensure %cs is set so we make this
18334 * a far return.
18335 */
18336+ pax_set_fptr_mask
18337 movq initial_code(%rip),%rax
18338 pushq $0 # fake return address to stop unwinder
18339 pushq $__KERNEL_CS # set correct cs
18340@@ -268,7 +273,7 @@ ENTRY(secondary_startup_64)
18341 bad_address:
18342 jmp bad_address
18343
18344- .section ".init.text","ax"
18345+ __INIT
18346 .globl early_idt_handlers
18347 early_idt_handlers:
18348 # 104(%rsp) %rflags
18349@@ -347,11 +352,15 @@ ENTRY(early_idt_handler)
18350 addq $16,%rsp # drop vector number and error code
18351 decl early_recursion_flag(%rip)
18352 INTERRUPT_RETURN
18353+ .previous
18354
18355+ __INITDATA
18356 .balign 4
18357 early_recursion_flag:
18358 .long 0
18359+ .previous
18360
18361+ .section .rodata,"a",@progbits
18362 #ifdef CONFIG_EARLY_PRINTK
18363 early_idt_msg:
18364 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
18365@@ -360,6 +369,7 @@ early_idt_ripmsg:
18366 #endif /* CONFIG_EARLY_PRINTK */
18367 .previous
18368
18369+ .section .rodata,"a",@progbits
18370 #define NEXT_PAGE(name) \
18371 .balign PAGE_SIZE; \
18372 ENTRY(name)
18373@@ -372,7 +382,6 @@ ENTRY(name)
18374 i = i + 1 ; \
18375 .endr
18376
18377- .data
18378 /*
18379 * This default setting generates an ident mapping at address 0x100000
18380 * and a mapping for the kernel that precisely maps virtual address
18381@@ -383,13 +392,41 @@ NEXT_PAGE(init_level4_pgt)
18382 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
18383 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
18384 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
18385+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
18386+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
18387+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
18388+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
18389+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
18390+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
18391 .org init_level4_pgt + L4_START_KERNEL*8, 0
18392 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
18393 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
18394
18395+#ifdef CONFIG_PAX_PER_CPU_PGD
18396+NEXT_PAGE(cpu_pgd)
18397+ .rept NR_CPUS
18398+ .fill 512,8,0
18399+ .endr
18400+#endif
18401+
18402 NEXT_PAGE(level3_ident_pgt)
18403 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
18404+#ifdef CONFIG_XEN
18405 .fill 511,8,0
18406+#else
18407+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
18408+ .fill 510,8,0
18409+#endif
18410+
18411+NEXT_PAGE(level3_vmalloc_start_pgt)
18412+ .fill 512,8,0
18413+
18414+NEXT_PAGE(level3_vmalloc_end_pgt)
18415+ .fill 512,8,0
18416+
18417+NEXT_PAGE(level3_vmemmap_pgt)
18418+ .fill L3_VMEMMAP_START,8,0
18419+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
18420
18421 NEXT_PAGE(level3_kernel_pgt)
18422 .fill L3_START_KERNEL,8,0
18423@@ -397,20 +434,23 @@ NEXT_PAGE(level3_kernel_pgt)
18424 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
18425 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
18426
18427+NEXT_PAGE(level2_vmemmap_pgt)
18428+ .fill 512,8,0
18429+
18430 NEXT_PAGE(level2_fixmap_pgt)
18431- .fill 506,8,0
18432- .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
18433- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
18434- .fill 5,8,0
18435+ .fill 507,8,0
18436+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
18437+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
18438+ .fill 4,8,0
18439
18440-NEXT_PAGE(level1_fixmap_pgt)
18441+NEXT_PAGE(level1_vsyscall_pgt)
18442 .fill 512,8,0
18443
18444-NEXT_PAGE(level2_ident_pgt)
18445- /* Since I easily can, map the first 1G.
18446+ /* Since I easily can, map the first 2G.
18447 * Don't set NX because code runs from these pages.
18448 */
18449- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
18450+NEXT_PAGE(level2_ident_pgt)
18451+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
18452
18453 NEXT_PAGE(level2_kernel_pgt)
18454 /*
18455@@ -423,37 +463,59 @@ NEXT_PAGE(level2_kernel_pgt)
18456 * If you want to increase this then increase MODULES_VADDR
18457 * too.)
18458 */
18459- PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
18460- KERNEL_IMAGE_SIZE/PMD_SIZE)
18461-
18462-NEXT_PAGE(level2_spare_pgt)
18463- .fill 512, 8, 0
18464+ PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
18465
18466 #undef PMDS
18467 #undef NEXT_PAGE
18468
18469- .data
18470+ .align PAGE_SIZE
18471+ENTRY(cpu_gdt_table)
18472+ .rept NR_CPUS
18473+ .quad 0x0000000000000000 /* NULL descriptor */
18474+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
18475+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
18476+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
18477+ .quad 0x00cffb000000ffff /* __USER32_CS */
18478+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
18479+ .quad 0x00affb000000ffff /* __USER_CS */
18480+
18481+#ifdef CONFIG_PAX_KERNEXEC
18482+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
18483+#else
18484+ .quad 0x0 /* unused */
18485+#endif
18486+
18487+ .quad 0,0 /* TSS */
18488+ .quad 0,0 /* LDT */
18489+ .quad 0,0,0 /* three TLS descriptors */
18490+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
18491+ /* asm/segment.h:GDT_ENTRIES must match this */
18492+
18493+ /* zero the remaining page */
18494+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
18495+ .endr
18496+
18497 .align 16
18498 .globl early_gdt_descr
18499 early_gdt_descr:
18500 .word GDT_ENTRIES*8-1
18501 early_gdt_descr_base:
18502- .quad INIT_PER_CPU_VAR(gdt_page)
18503+ .quad cpu_gdt_table
18504
18505 ENTRY(phys_base)
18506 /* This must match the first entry in level2_kernel_pgt */
18507 .quad 0x0000000000000000
18508
18509 #include "../../x86/xen/xen-head.S"
18510-
18511- .section .bss, "aw", @nobits
18512+
18513+ .section .rodata,"a",@progbits
18514 .align L1_CACHE_BYTES
18515 ENTRY(idt_table)
18516- .skip IDT_ENTRIES * 16
18517+ .fill 512,8,0
18518
18519 .align L1_CACHE_BYTES
18520 ENTRY(nmi_idt_table)
18521- .skip IDT_ENTRIES * 16
18522+ .fill 512,8,0
18523
18524 __PAGE_ALIGNED_BSS
18525 .align PAGE_SIZE
18526diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
18527index 9c3bd4a..e1d9b35 100644
18528--- a/arch/x86/kernel/i386_ksyms_32.c
18529+++ b/arch/x86/kernel/i386_ksyms_32.c
18530@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
18531 EXPORT_SYMBOL(cmpxchg8b_emu);
18532 #endif
18533
18534+EXPORT_SYMBOL_GPL(cpu_gdt_table);
18535+
18536 /* Networking helper routines. */
18537 EXPORT_SYMBOL(csum_partial_copy_generic);
18538+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
18539+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
18540
18541 EXPORT_SYMBOL(__get_user_1);
18542 EXPORT_SYMBOL(__get_user_2);
18543@@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
18544
18545 EXPORT_SYMBOL(csum_partial);
18546 EXPORT_SYMBOL(empty_zero_page);
18547+
18548+#ifdef CONFIG_PAX_KERNEXEC
18549+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
18550+#endif
18551diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
18552index 675a050..95febfd 100644
18553--- a/arch/x86/kernel/i387.c
18554+++ b/arch/x86/kernel/i387.c
18555@@ -55,7 +55,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
18556 static inline bool interrupted_user_mode(void)
18557 {
18558 struct pt_regs *regs = get_irq_regs();
18559- return regs && user_mode_vm(regs);
18560+ return regs && user_mode(regs);
18561 }
18562
18563 /*
18564diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
18565index 9a5c460..dc4374d 100644
18566--- a/arch/x86/kernel/i8259.c
18567+++ b/arch/x86/kernel/i8259.c
18568@@ -209,7 +209,7 @@ spurious_8259A_irq:
18569 "spurious 8259A interrupt: IRQ%d.\n", irq);
18570 spurious_irq_mask |= irqmask;
18571 }
18572- atomic_inc(&irq_err_count);
18573+ atomic_inc_unchecked(&irq_err_count);
18574 /*
18575 * Theoretically we do not have to handle this IRQ,
18576 * but in Linux this does not cause problems and is
18577diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
18578index 8c96897..be66bfa 100644
18579--- a/arch/x86/kernel/ioport.c
18580+++ b/arch/x86/kernel/ioport.c
18581@@ -6,6 +6,7 @@
18582 #include <linux/sched.h>
18583 #include <linux/kernel.h>
18584 #include <linux/capability.h>
18585+#include <linux/security.h>
18586 #include <linux/errno.h>
18587 #include <linux/types.h>
18588 #include <linux/ioport.h>
18589@@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
18590
18591 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
18592 return -EINVAL;
18593+#ifdef CONFIG_GRKERNSEC_IO
18594+ if (turn_on && grsec_disable_privio) {
18595+ gr_handle_ioperm();
18596+ return -EPERM;
18597+ }
18598+#endif
18599 if (turn_on && !capable(CAP_SYS_RAWIO))
18600 return -EPERM;
18601
18602@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
18603 * because the ->io_bitmap_max value must match the bitmap
18604 * contents:
18605 */
18606- tss = &per_cpu(init_tss, get_cpu());
18607+ tss = init_tss + get_cpu();
18608
18609 if (turn_on)
18610 bitmap_clear(t->io_bitmap_ptr, from, num);
18611@@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
18612 return -EINVAL;
18613 /* Trying to gain more privileges? */
18614 if (level > old) {
18615+#ifdef CONFIG_GRKERNSEC_IO
18616+ if (grsec_disable_privio) {
18617+ gr_handle_iopl();
18618+ return -EPERM;
18619+ }
18620+#endif
18621 if (!capable(CAP_SYS_RAWIO))
18622 return -EPERM;
18623 }
18624diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
18625index e4595f1..ee3bfb8 100644
18626--- a/arch/x86/kernel/irq.c
18627+++ b/arch/x86/kernel/irq.c
18628@@ -18,7 +18,7 @@
18629 #include <asm/mce.h>
18630 #include <asm/hw_irq.h>
18631
18632-atomic_t irq_err_count;
18633+atomic_unchecked_t irq_err_count;
18634
18635 /* Function pointer for generic interrupt vector handling */
18636 void (*x86_platform_ipi_callback)(void) = NULL;
18637@@ -122,9 +122,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
18638 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
18639 seq_printf(p, " Machine check polls\n");
18640 #endif
18641- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
18642+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
18643 #if defined(CONFIG_X86_IO_APIC)
18644- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
18645+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
18646 #endif
18647 return 0;
18648 }
18649@@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
18650
18651 u64 arch_irq_stat(void)
18652 {
18653- u64 sum = atomic_read(&irq_err_count);
18654+ u64 sum = atomic_read_unchecked(&irq_err_count);
18655
18656 #ifdef CONFIG_X86_IO_APIC
18657- sum += atomic_read(&irq_mis_count);
18658+ sum += atomic_read_unchecked(&irq_mis_count);
18659 #endif
18660 return sum;
18661 }
18662diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
18663index 344faf8..355f60d 100644
18664--- a/arch/x86/kernel/irq_32.c
18665+++ b/arch/x86/kernel/irq_32.c
18666@@ -39,7 +39,7 @@ static int check_stack_overflow(void)
18667 __asm__ __volatile__("andl %%esp,%0" :
18668 "=r" (sp) : "0" (THREAD_SIZE - 1));
18669
18670- return sp < (sizeof(struct thread_info) + STACK_WARN);
18671+ return sp < STACK_WARN;
18672 }
18673
18674 static void print_stack_overflow(void)
18675@@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
18676 * per-CPU IRQ handling contexts (thread information and stack)
18677 */
18678 union irq_ctx {
18679- struct thread_info tinfo;
18680- u32 stack[THREAD_SIZE/sizeof(u32)];
18681+ unsigned long previous_esp;
18682+ u32 stack[THREAD_SIZE/sizeof(u32)];
18683 } __attribute__((aligned(THREAD_SIZE)));
18684
18685 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
18686@@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
18687 static inline int
18688 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
18689 {
18690- union irq_ctx *curctx, *irqctx;
18691+ union irq_ctx *irqctx;
18692 u32 *isp, arg1, arg2;
18693
18694- curctx = (union irq_ctx *) current_thread_info();
18695 irqctx = __this_cpu_read(hardirq_ctx);
18696
18697 /*
18698@@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
18699 * handler) we can't do that and just have to keep using the
18700 * current stack (which is the irq stack already after all)
18701 */
18702- if (unlikely(curctx == irqctx))
18703+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
18704 return 0;
18705
18706 /* build the stack frame on the IRQ stack */
18707- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
18708- irqctx->tinfo.task = curctx->tinfo.task;
18709- irqctx->tinfo.previous_esp = current_stack_pointer;
18710+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
18711+ irqctx->previous_esp = current_stack_pointer;
18712
18713- /* Copy the preempt_count so that the [soft]irq checks work. */
18714- irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
18715+#ifdef CONFIG_PAX_MEMORY_UDEREF
18716+ __set_fs(MAKE_MM_SEG(0));
18717+#endif
18718
18719 if (unlikely(overflow))
18720 call_on_stack(print_stack_overflow, isp);
18721@@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
18722 : "0" (irq), "1" (desc), "2" (isp),
18723 "D" (desc->handle_irq)
18724 : "memory", "cc", "ecx");
18725+
18726+#ifdef CONFIG_PAX_MEMORY_UDEREF
18727+ __set_fs(current_thread_info()->addr_limit);
18728+#endif
18729+
18730 return 1;
18731 }
18732
18733@@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
18734 */
18735 void __cpuinit irq_ctx_init(int cpu)
18736 {
18737- union irq_ctx *irqctx;
18738-
18739 if (per_cpu(hardirq_ctx, cpu))
18740 return;
18741
18742- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
18743- THREADINFO_GFP,
18744- THREAD_SIZE_ORDER));
18745- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
18746- irqctx->tinfo.cpu = cpu;
18747- irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
18748- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
18749-
18750- per_cpu(hardirq_ctx, cpu) = irqctx;
18751-
18752- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
18753- THREADINFO_GFP,
18754- THREAD_SIZE_ORDER));
18755- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
18756- irqctx->tinfo.cpu = cpu;
18757- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
18758-
18759- per_cpu(softirq_ctx, cpu) = irqctx;
18760+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
18761+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
18762+
18763+ printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
18764+ cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
18765
18766 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
18767 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
18768@@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
18769 asmlinkage void do_softirq(void)
18770 {
18771 unsigned long flags;
18772- struct thread_info *curctx;
18773 union irq_ctx *irqctx;
18774 u32 *isp;
18775
18776@@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
18777 local_irq_save(flags);
18778
18779 if (local_softirq_pending()) {
18780- curctx = current_thread_info();
18781 irqctx = __this_cpu_read(softirq_ctx);
18782- irqctx->tinfo.task = curctx->task;
18783- irqctx->tinfo.previous_esp = current_stack_pointer;
18784+ irqctx->previous_esp = current_stack_pointer;
18785
18786 /* build the stack frame on the softirq stack */
18787- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
18788+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
18789+
18790+#ifdef CONFIG_PAX_MEMORY_UDEREF
18791+ __set_fs(MAKE_MM_SEG(0));
18792+#endif
18793
18794 call_on_stack(__do_softirq, isp);
18795+
18796+#ifdef CONFIG_PAX_MEMORY_UDEREF
18797+ __set_fs(current_thread_info()->addr_limit);
18798+#endif
18799+
18800 /*
18801 * Shouldn't happen, we returned above if in_interrupt():
18802 */
18803@@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
18804 if (unlikely(!desc))
18805 return false;
18806
18807- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
18808+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
18809 if (unlikely(overflow))
18810 print_stack_overflow();
18811 desc->handle_irq(irq, desc);
18812diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
18813index d04d3ec..ea4b374 100644
18814--- a/arch/x86/kernel/irq_64.c
18815+++ b/arch/x86/kernel/irq_64.c
18816@@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
18817 u64 estack_top, estack_bottom;
18818 u64 curbase = (u64)task_stack_page(current);
18819
18820- if (user_mode_vm(regs))
18821+ if (user_mode(regs))
18822 return;
18823
18824 if (regs->sp >= curbase + sizeof(struct thread_info) +
18825diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
18826index dc1404b..bbc43e7 100644
18827--- a/arch/x86/kernel/kdebugfs.c
18828+++ b/arch/x86/kernel/kdebugfs.c
18829@@ -27,7 +27,7 @@ struct setup_data_node {
18830 u32 len;
18831 };
18832
18833-static ssize_t setup_data_read(struct file *file, char __user *user_buf,
18834+static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
18835 size_t count, loff_t *ppos)
18836 {
18837 struct setup_data_node *node = file->private_data;
18838diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
18839index 836f832..a8bda67 100644
18840--- a/arch/x86/kernel/kgdb.c
18841+++ b/arch/x86/kernel/kgdb.c
18842@@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
18843 #ifdef CONFIG_X86_32
18844 switch (regno) {
18845 case GDB_SS:
18846- if (!user_mode_vm(regs))
18847+ if (!user_mode(regs))
18848 *(unsigned long *)mem = __KERNEL_DS;
18849 break;
18850 case GDB_SP:
18851- if (!user_mode_vm(regs))
18852+ if (!user_mode(regs))
18853 *(unsigned long *)mem = kernel_stack_pointer(regs);
18854 break;
18855 case GDB_GS:
18856@@ -229,7 +229,10 @@ static void kgdb_correct_hw_break(void)
18857 bp->attr.bp_addr = breakinfo[breakno].addr;
18858 bp->attr.bp_len = breakinfo[breakno].len;
18859 bp->attr.bp_type = breakinfo[breakno].type;
18860- info->address = breakinfo[breakno].addr;
18861+ if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
18862+ info->address = ktla_ktva(breakinfo[breakno].addr);
18863+ else
18864+ info->address = breakinfo[breakno].addr;
18865 info->len = breakinfo[breakno].len;
18866 info->type = breakinfo[breakno].type;
18867 val = arch_install_hw_breakpoint(bp);
18868@@ -476,12 +479,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
18869 case 'k':
18870 /* clear the trace bit */
18871 linux_regs->flags &= ~X86_EFLAGS_TF;
18872- atomic_set(&kgdb_cpu_doing_single_step, -1);
18873+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
18874
18875 /* set the trace bit if we're stepping */
18876 if (remcomInBuffer[0] == 's') {
18877 linux_regs->flags |= X86_EFLAGS_TF;
18878- atomic_set(&kgdb_cpu_doing_single_step,
18879+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
18880 raw_smp_processor_id());
18881 }
18882
18883@@ -546,7 +549,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
18884
18885 switch (cmd) {
18886 case DIE_DEBUG:
18887- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
18888+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
18889 if (user_mode(regs))
18890 return single_step_cont(regs, args);
18891 break;
18892@@ -751,11 +754,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
18893 #endif /* CONFIG_DEBUG_RODATA */
18894
18895 bpt->type = BP_BREAKPOINT;
18896- err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
18897+ err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
18898 BREAK_INSTR_SIZE);
18899 if (err)
18900 return err;
18901- err = probe_kernel_write((char *)bpt->bpt_addr,
18902+ err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
18903 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
18904 #ifdef CONFIG_DEBUG_RODATA
18905 if (!err)
18906@@ -768,7 +771,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
18907 return -EBUSY;
18908 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
18909 BREAK_INSTR_SIZE);
18910- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
18911+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
18912 if (err)
18913 return err;
18914 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
18915@@ -793,13 +796,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
18916 if (mutex_is_locked(&text_mutex))
18917 goto knl_write;
18918 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
18919- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
18920+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
18921 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
18922 goto knl_write;
18923 return err;
18924 knl_write:
18925 #endif /* CONFIG_DEBUG_RODATA */
18926- return probe_kernel_write((char *)bpt->bpt_addr,
18927+ return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
18928 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
18929 }
18930
18931diff --git a/arch/x86/kernel/kprobes-opt.c b/arch/x86/kernel/kprobes-opt.c
18932index c5e410e..ed5a7f0 100644
18933--- a/arch/x86/kernel/kprobes-opt.c
18934+++ b/arch/x86/kernel/kprobes-opt.c
18935@@ -338,7 +338,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
18936 * Verify if the address gap is in 2GB range, because this uses
18937 * a relative jump.
18938 */
18939- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
18940+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
18941 if (abs(rel) > 0x7fffffff)
18942 return -ERANGE;
18943
18944@@ -353,16 +353,16 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
18945 op->optinsn.size = ret;
18946
18947 /* Copy arch-dep-instance from template */
18948- memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
18949+ memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
18950
18951 /* Set probe information */
18952 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
18953
18954 /* Set probe function call */
18955- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
18956+ synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
18957
18958 /* Set returning jmp instruction at the tail of out-of-line buffer */
18959- synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
18960+ synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
18961 (u8 *)op->kp.addr + op->optinsn.size);
18962
18963 flush_icache_range((unsigned long) buf,
18964@@ -385,7 +385,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
18965 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
18966
18967 /* Backup instructions which will be replaced by jump address */
18968- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
18969+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
18970 RELATIVE_ADDR_SIZE);
18971
18972 insn_buf[0] = RELATIVEJUMP_OPCODE;
18973@@ -483,7 +483,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
18974 /* This kprobe is really able to run optimized path. */
18975 op = container_of(p, struct optimized_kprobe, kp);
18976 /* Detour through copied instructions */
18977- regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
18978+ regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
18979 if (!reenter)
18980 reset_current_kprobe();
18981 preempt_enable_no_resched();
18982diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
18983index 57916c0..9e0b9d0 100644
18984--- a/arch/x86/kernel/kprobes.c
18985+++ b/arch/x86/kernel/kprobes.c
18986@@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
18987 s32 raddr;
18988 } __attribute__((packed)) *insn;
18989
18990- insn = (struct __arch_relative_insn *)from;
18991+ insn = (struct __arch_relative_insn *)ktla_ktva(from);
18992+
18993+ pax_open_kernel();
18994 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
18995 insn->op = op;
18996+ pax_close_kernel();
18997 }
18998
18999 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
19000@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
19001 kprobe_opcode_t opcode;
19002 kprobe_opcode_t *orig_opcodes = opcodes;
19003
19004- if (search_exception_tables((unsigned long)opcodes))
19005+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
19006 return 0; /* Page fault may occur on this address. */
19007
19008 retry:
19009@@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
19010 * for the first byte, we can recover the original instruction
19011 * from it and kp->opcode.
19012 */
19013- memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
19014+ memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
19015 buf[0] = kp->opcode;
19016- return (unsigned long)buf;
19017+ return ktva_ktla((unsigned long)buf);
19018 }
19019
19020 /*
19021@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
19022 /* Another subsystem puts a breakpoint, failed to recover */
19023 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
19024 return 0;
19025+ pax_open_kernel();
19026 memcpy(dest, insn.kaddr, insn.length);
19027+ pax_close_kernel();
19028
19029 #ifdef CONFIG_X86_64
19030 if (insn_rip_relative(&insn)) {
19031@@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
19032 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
19033 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
19034 disp = (u8 *) dest + insn_offset_displacement(&insn);
19035+ pax_open_kernel();
19036 *(s32 *) disp = (s32) newdisp;
19037+ pax_close_kernel();
19038 }
19039 #endif
19040 return insn.length;
19041@@ -485,7 +492,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
19042 * nor set current_kprobe, because it doesn't use single
19043 * stepping.
19044 */
19045- regs->ip = (unsigned long)p->ainsn.insn;
19046+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
19047 preempt_enable_no_resched();
19048 return;
19049 }
19050@@ -502,9 +509,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
19051 regs->flags &= ~X86_EFLAGS_IF;
19052 /* single step inline if the instruction is an int3 */
19053 if (p->opcode == BREAKPOINT_INSTRUCTION)
19054- regs->ip = (unsigned long)p->addr;
19055+ regs->ip = ktla_ktva((unsigned long)p->addr);
19056 else
19057- regs->ip = (unsigned long)p->ainsn.insn;
19058+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
19059 }
19060
19061 /*
19062@@ -600,7 +607,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
19063 setup_singlestep(p, regs, kcb, 0);
19064 return 1;
19065 }
19066- } else if (*addr != BREAKPOINT_INSTRUCTION) {
19067+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
19068 /*
19069 * The breakpoint instruction was removed right
19070 * after we hit it. Another cpu has removed
19071@@ -651,6 +658,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
19072 " movq %rax, 152(%rsp)\n"
19073 RESTORE_REGS_STRING
19074 " popfq\n"
19075+#ifdef KERNEXEC_PLUGIN
19076+ " btsq $63,(%rsp)\n"
19077+#endif
19078 #else
19079 " pushf\n"
19080 SAVE_REGS_STRING
19081@@ -788,7 +798,7 @@ static void __kprobes
19082 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
19083 {
19084 unsigned long *tos = stack_addr(regs);
19085- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
19086+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
19087 unsigned long orig_ip = (unsigned long)p->addr;
19088 kprobe_opcode_t *insn = p->ainsn.insn;
19089
19090@@ -970,7 +980,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
19091 struct die_args *args = data;
19092 int ret = NOTIFY_DONE;
19093
19094- if (args->regs && user_mode_vm(args->regs))
19095+ if (args->regs && user_mode(args->regs))
19096 return ret;
19097
19098 switch (val) {
19099diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
19100index ebc9873..1b9724b 100644
19101--- a/arch/x86/kernel/ldt.c
19102+++ b/arch/x86/kernel/ldt.c
19103@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
19104 if (reload) {
19105 #ifdef CONFIG_SMP
19106 preempt_disable();
19107- load_LDT(pc);
19108+ load_LDT_nolock(pc);
19109 if (!cpumask_equal(mm_cpumask(current->mm),
19110 cpumask_of(smp_processor_id())))
19111 smp_call_function(flush_ldt, current->mm, 1);
19112 preempt_enable();
19113 #else
19114- load_LDT(pc);
19115+ load_LDT_nolock(pc);
19116 #endif
19117 }
19118 if (oldsize) {
19119@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
19120 return err;
19121
19122 for (i = 0; i < old->size; i++)
19123- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
19124+ write_ldt_entry(new->ldt, i, old->ldt + i);
19125 return 0;
19126 }
19127
19128@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
19129 retval = copy_ldt(&mm->context, &old_mm->context);
19130 mutex_unlock(&old_mm->context.lock);
19131 }
19132+
19133+ if (tsk == current) {
19134+ mm->context.vdso = 0;
19135+
19136+#ifdef CONFIG_X86_32
19137+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
19138+ mm->context.user_cs_base = 0UL;
19139+ mm->context.user_cs_limit = ~0UL;
19140+
19141+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
19142+ cpus_clear(mm->context.cpu_user_cs_mask);
19143+#endif
19144+
19145+#endif
19146+#endif
19147+
19148+ }
19149+
19150 return retval;
19151 }
19152
19153@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
19154 }
19155 }
19156
19157+#ifdef CONFIG_PAX_SEGMEXEC
19158+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
19159+ error = -EINVAL;
19160+ goto out_unlock;
19161+ }
19162+#endif
19163+
19164 fill_ldt(&ldt, &ldt_info);
19165 if (oldmode)
19166 ldt.avl = 0;
19167diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
19168index 5b19e4d..6476a76 100644
19169--- a/arch/x86/kernel/machine_kexec_32.c
19170+++ b/arch/x86/kernel/machine_kexec_32.c
19171@@ -26,7 +26,7 @@
19172 #include <asm/cacheflush.h>
19173 #include <asm/debugreg.h>
19174
19175-static void set_idt(void *newidt, __u16 limit)
19176+static void set_idt(struct desc_struct *newidt, __u16 limit)
19177 {
19178 struct desc_ptr curidt;
19179
19180@@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
19181 }
19182
19183
19184-static void set_gdt(void *newgdt, __u16 limit)
19185+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
19186 {
19187 struct desc_ptr curgdt;
19188
19189@@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
19190 }
19191
19192 control_page = page_address(image->control_code_page);
19193- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
19194+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
19195
19196 relocate_kernel_ptr = control_page;
19197 page_list[PA_CONTROL_PAGE] = __pa(control_page);
19198diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
19199index 3544aed..01ddc1c 100644
19200--- a/arch/x86/kernel/microcode_intel.c
19201+++ b/arch/x86/kernel/microcode_intel.c
19202@@ -431,13 +431,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
19203
19204 static int get_ucode_user(void *to, const void *from, size_t n)
19205 {
19206- return copy_from_user(to, from, n);
19207+ return copy_from_user(to, (const void __force_user *)from, n);
19208 }
19209
19210 static enum ucode_state
19211 request_microcode_user(int cpu, const void __user *buf, size_t size)
19212 {
19213- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
19214+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
19215 }
19216
19217 static void microcode_fini_cpu(int cpu)
19218diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
19219index 216a4d7..b328f09 100644
19220--- a/arch/x86/kernel/module.c
19221+++ b/arch/x86/kernel/module.c
19222@@ -43,15 +43,60 @@ do { \
19223 } while (0)
19224 #endif
19225
19226-void *module_alloc(unsigned long size)
19227+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
19228 {
19229- if (PAGE_ALIGN(size) > MODULES_LEN)
19230+ if (size == 0 || PAGE_ALIGN(size) > MODULES_LEN)
19231 return NULL;
19232 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
19233- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
19234+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
19235 -1, __builtin_return_address(0));
19236 }
19237
19238+void *module_alloc(unsigned long size)
19239+{
19240+
19241+#ifdef CONFIG_PAX_KERNEXEC
19242+ return __module_alloc(size, PAGE_KERNEL);
19243+#else
19244+ return __module_alloc(size, PAGE_KERNEL_EXEC);
19245+#endif
19246+
19247+}
19248+
19249+#ifdef CONFIG_PAX_KERNEXEC
19250+#ifdef CONFIG_X86_32
19251+void *module_alloc_exec(unsigned long size)
19252+{
19253+ struct vm_struct *area;
19254+
19255+ if (size == 0)
19256+ return NULL;
19257+
19258+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
19259+ return area ? area->addr : NULL;
19260+}
19261+EXPORT_SYMBOL(module_alloc_exec);
19262+
19263+void module_free_exec(struct module *mod, void *module_region)
19264+{
19265+ vunmap(module_region);
19266+}
19267+EXPORT_SYMBOL(module_free_exec);
19268+#else
19269+void module_free_exec(struct module *mod, void *module_region)
19270+{
19271+ module_free(mod, module_region);
19272+}
19273+EXPORT_SYMBOL(module_free_exec);
19274+
19275+void *module_alloc_exec(unsigned long size)
19276+{
19277+ return __module_alloc(size, PAGE_KERNEL_RX);
19278+}
19279+EXPORT_SYMBOL(module_alloc_exec);
19280+#endif
19281+#endif
19282+
19283 #ifdef CONFIG_X86_32
19284 int apply_relocate(Elf32_Shdr *sechdrs,
19285 const char *strtab,
19286@@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
19287 unsigned int i;
19288 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
19289 Elf32_Sym *sym;
19290- uint32_t *location;
19291+ uint32_t *plocation, location;
19292
19293 DEBUGP("Applying relocate section %u to %u\n",
19294 relsec, sechdrs[relsec].sh_info);
19295 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
19296 /* This is where to make the change */
19297- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
19298- + rel[i].r_offset;
19299+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
19300+ location = (uint32_t)plocation;
19301+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
19302+ plocation = ktla_ktva((void *)plocation);
19303 /* This is the symbol it is referring to. Note that all
19304 undefined symbols have been resolved. */
19305 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
19306@@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
19307 switch (ELF32_R_TYPE(rel[i].r_info)) {
19308 case R_386_32:
19309 /* We add the value into the location given */
19310- *location += sym->st_value;
19311+ pax_open_kernel();
19312+ *plocation += sym->st_value;
19313+ pax_close_kernel();
19314 break;
19315 case R_386_PC32:
19316 /* Add the value, subtract its position */
19317- *location += sym->st_value - (uint32_t)location;
19318+ pax_open_kernel();
19319+ *plocation += sym->st_value - location;
19320+ pax_close_kernel();
19321 break;
19322 default:
19323 pr_err("%s: Unknown relocation: %u\n",
19324@@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
19325 case R_X86_64_NONE:
19326 break;
19327 case R_X86_64_64:
19328+ pax_open_kernel();
19329 *(u64 *)loc = val;
19330+ pax_close_kernel();
19331 break;
19332 case R_X86_64_32:
19333+ pax_open_kernel();
19334 *(u32 *)loc = val;
19335+ pax_close_kernel();
19336 if (val != *(u32 *)loc)
19337 goto overflow;
19338 break;
19339 case R_X86_64_32S:
19340+ pax_open_kernel();
19341 *(s32 *)loc = val;
19342+ pax_close_kernel();
19343 if ((s64)val != *(s32 *)loc)
19344 goto overflow;
19345 break;
19346 case R_X86_64_PC32:
19347 val -= (u64)loc;
19348+ pax_open_kernel();
19349 *(u32 *)loc = val;
19350+ pax_close_kernel();
19351+
19352 #if 0
19353 if ((s64)val != *(s32 *)loc)
19354 goto overflow;
19355diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
19356index f84f5c5..e27e54b 100644
19357--- a/arch/x86/kernel/nmi.c
19358+++ b/arch/x86/kernel/nmi.c
19359@@ -479,6 +479,17 @@ static inline void nmi_nesting_postprocess(void)
19360 dotraplinkage notrace __kprobes void
19361 do_nmi(struct pt_regs *regs, long error_code)
19362 {
19363+
19364+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19365+ if (!user_mode(regs)) {
19366+ unsigned long cs = regs->cs & 0xFFFF;
19367+ unsigned long ip = ktva_ktla(regs->ip);
19368+
19369+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
19370+ regs->ip = ip;
19371+ }
19372+#endif
19373+
19374 nmi_nesting_preprocess(regs);
19375
19376 nmi_enter();
19377diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
19378index 676b8c7..870ba04 100644
19379--- a/arch/x86/kernel/paravirt-spinlocks.c
19380+++ b/arch/x86/kernel/paravirt-spinlocks.c
19381@@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
19382 arch_spin_lock(lock);
19383 }
19384
19385-struct pv_lock_ops pv_lock_ops = {
19386+struct pv_lock_ops pv_lock_ops __read_only = {
19387 #ifdef CONFIG_SMP
19388 .spin_is_locked = __ticket_spin_is_locked,
19389 .spin_is_contended = __ticket_spin_is_contended,
19390diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
19391index 17fff18..7bb2088 100644
19392--- a/arch/x86/kernel/paravirt.c
19393+++ b/arch/x86/kernel/paravirt.c
19394@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
19395 {
19396 return x;
19397 }
19398+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
19399+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
19400+#endif
19401
19402 void __init default_banner(void)
19403 {
19404@@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
19405 if (opfunc == NULL)
19406 /* If there's no function, patch it with a ud2a (BUG) */
19407 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
19408- else if (opfunc == _paravirt_nop)
19409+ else if (opfunc == (void *)_paravirt_nop)
19410 /* If the operation is a nop, then nop the callsite */
19411 ret = paravirt_patch_nop();
19412
19413 /* identity functions just return their single argument */
19414- else if (opfunc == _paravirt_ident_32)
19415+ else if (opfunc == (void *)_paravirt_ident_32)
19416 ret = paravirt_patch_ident_32(insnbuf, len);
19417- else if (opfunc == _paravirt_ident_64)
19418+ else if (opfunc == (void *)_paravirt_ident_64)
19419 ret = paravirt_patch_ident_64(insnbuf, len);
19420+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
19421+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
19422+ ret = paravirt_patch_ident_64(insnbuf, len);
19423+#endif
19424
19425 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
19426 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
19427@@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
19428 if (insn_len > len || start == NULL)
19429 insn_len = len;
19430 else
19431- memcpy(insnbuf, start, insn_len);
19432+ memcpy(insnbuf, ktla_ktva(start), insn_len);
19433
19434 return insn_len;
19435 }
19436@@ -304,7 +311,7 @@ void arch_flush_lazy_mmu_mode(void)
19437 preempt_enable();
19438 }
19439
19440-struct pv_info pv_info = {
19441+struct pv_info pv_info __read_only = {
19442 .name = "bare hardware",
19443 .paravirt_enabled = 0,
19444 .kernel_rpl = 0,
19445@@ -315,16 +322,16 @@ struct pv_info pv_info = {
19446 #endif
19447 };
19448
19449-struct pv_init_ops pv_init_ops = {
19450+struct pv_init_ops pv_init_ops __read_only = {
19451 .patch = native_patch,
19452 };
19453
19454-struct pv_time_ops pv_time_ops = {
19455+struct pv_time_ops pv_time_ops __read_only = {
19456 .sched_clock = native_sched_clock,
19457 .steal_clock = native_steal_clock,
19458 };
19459
19460-struct pv_irq_ops pv_irq_ops = {
19461+struct pv_irq_ops pv_irq_ops __read_only = {
19462 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
19463 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
19464 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
19465@@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
19466 #endif
19467 };
19468
19469-struct pv_cpu_ops pv_cpu_ops = {
19470+struct pv_cpu_ops pv_cpu_ops __read_only = {
19471 .cpuid = native_cpuid,
19472 .get_debugreg = native_get_debugreg,
19473 .set_debugreg = native_set_debugreg,
19474@@ -395,21 +402,26 @@ struct pv_cpu_ops pv_cpu_ops = {
19475 .end_context_switch = paravirt_nop,
19476 };
19477
19478-struct pv_apic_ops pv_apic_ops = {
19479+struct pv_apic_ops pv_apic_ops __read_only = {
19480 #ifdef CONFIG_X86_LOCAL_APIC
19481 .startup_ipi_hook = paravirt_nop,
19482 #endif
19483 };
19484
19485-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
19486+#ifdef CONFIG_X86_32
19487+#ifdef CONFIG_X86_PAE
19488+/* 64-bit pagetable entries */
19489+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
19490+#else
19491 /* 32-bit pagetable entries */
19492 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
19493+#endif
19494 #else
19495 /* 64-bit pagetable entries */
19496 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
19497 #endif
19498
19499-struct pv_mmu_ops pv_mmu_ops = {
19500+struct pv_mmu_ops pv_mmu_ops __read_only = {
19501
19502 .read_cr2 = native_read_cr2,
19503 .write_cr2 = native_write_cr2,
19504@@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
19505 .make_pud = PTE_IDENT,
19506
19507 .set_pgd = native_set_pgd,
19508+ .set_pgd_batched = native_set_pgd_batched,
19509 #endif
19510 #endif /* PAGETABLE_LEVELS >= 3 */
19511
19512@@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
19513 },
19514
19515 .set_fixmap = native_set_fixmap,
19516+
19517+#ifdef CONFIG_PAX_KERNEXEC
19518+ .pax_open_kernel = native_pax_open_kernel,
19519+ .pax_close_kernel = native_pax_close_kernel,
19520+#endif
19521+
19522 };
19523
19524 EXPORT_SYMBOL_GPL(pv_time_ops);
19525diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
19526index 35ccf75..7a15747 100644
19527--- a/arch/x86/kernel/pci-iommu_table.c
19528+++ b/arch/x86/kernel/pci-iommu_table.c
19529@@ -2,7 +2,7 @@
19530 #include <asm/iommu_table.h>
19531 #include <linux/string.h>
19532 #include <linux/kallsyms.h>
19533-
19534+#include <linux/sched.h>
19535
19536 #define DEBUG 1
19537
19538diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
19539index b644e1c..4a6d379 100644
19540--- a/arch/x86/kernel/process.c
19541+++ b/arch/x86/kernel/process.c
19542@@ -36,7 +36,8 @@
19543 * section. Since TSS's are completely CPU-local, we want them
19544 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
19545 */
19546-DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
19547+struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
19548+EXPORT_SYMBOL(init_tss);
19549
19550 #ifdef CONFIG_X86_64
19551 static DEFINE_PER_CPU(unsigned char, is_idle);
19552@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
19553 task_xstate_cachep =
19554 kmem_cache_create("task_xstate", xstate_size,
19555 __alignof__(union thread_xstate),
19556- SLAB_PANIC | SLAB_NOTRACK, NULL);
19557+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
19558 }
19559
19560 /*
19561@@ -105,7 +106,7 @@ void exit_thread(void)
19562 unsigned long *bp = t->io_bitmap_ptr;
19563
19564 if (bp) {
19565- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
19566+ struct tss_struct *tss = init_tss + get_cpu();
19567
19568 t->io_bitmap_ptr = NULL;
19569 clear_thread_flag(TIF_IO_BITMAP);
19570@@ -136,7 +137,7 @@ void show_regs_common(void)
19571 board = dmi_get_system_info(DMI_BOARD_NAME);
19572
19573 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s %s %s%s%s\n",
19574- current->pid, current->comm, print_tainted(),
19575+ task_pid_nr(current), current->comm, print_tainted(),
19576 init_utsname()->release,
19577 (int)strcspn(init_utsname()->version, " "),
19578 init_utsname()->version,
19579@@ -149,6 +150,9 @@ void flush_thread(void)
19580 {
19581 struct task_struct *tsk = current;
19582
19583+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
19584+ loadsegment(gs, 0);
19585+#endif
19586 flush_ptrace_hw_breakpoint(tsk);
19587 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
19588 drop_init_fpu(tsk);
19589@@ -336,7 +340,7 @@ static void __exit_idle(void)
19590 void exit_idle(void)
19591 {
19592 /* idle loop has pid 0 */
19593- if (current->pid)
19594+ if (task_pid_nr(current))
19595 return;
19596 __exit_idle();
19597 }
19598@@ -445,7 +449,7 @@ bool set_pm_idle_to_default(void)
19599
19600 return ret;
19601 }
19602-void stop_this_cpu(void *dummy)
19603+__noreturn void stop_this_cpu(void *dummy)
19604 {
19605 local_irq_disable();
19606 /*
19607@@ -673,16 +677,37 @@ static int __init idle_setup(char *str)
19608 }
19609 early_param("idle", idle_setup);
19610
19611-unsigned long arch_align_stack(unsigned long sp)
19612+#ifdef CONFIG_PAX_RANDKSTACK
19613+void pax_randomize_kstack(struct pt_regs *regs)
19614 {
19615- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
19616- sp -= get_random_int() % 8192;
19617- return sp & ~0xf;
19618-}
19619+ struct thread_struct *thread = &current->thread;
19620+ unsigned long time;
19621
19622-unsigned long arch_randomize_brk(struct mm_struct *mm)
19623-{
19624- unsigned long range_end = mm->brk + 0x02000000;
19625- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
19626-}
19627+ if (!randomize_va_space)
19628+ return;
19629+
19630+ if (v8086_mode(regs))
19631+ return;
19632
19633+ rdtscl(time);
19634+
19635+ /* P4 seems to return a 0 LSB, ignore it */
19636+#ifdef CONFIG_MPENTIUM4
19637+ time &= 0x3EUL;
19638+ time <<= 2;
19639+#elif defined(CONFIG_X86_64)
19640+ time &= 0xFUL;
19641+ time <<= 4;
19642+#else
19643+ time &= 0x1FUL;
19644+ time <<= 3;
19645+#endif
19646+
19647+ thread->sp0 ^= time;
19648+ load_sp0(init_tss + smp_processor_id(), thread);
19649+
19650+#ifdef CONFIG_X86_64
19651+ this_cpu_write(kernel_stack, thread->sp0);
19652+#endif
19653+}
19654+#endif
19655diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
19656index 44e0bff..5ceb99c 100644
19657--- a/arch/x86/kernel/process_32.c
19658+++ b/arch/x86/kernel/process_32.c
19659@@ -65,6 +65,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
19660 unsigned long thread_saved_pc(struct task_struct *tsk)
19661 {
19662 return ((unsigned long *)tsk->thread.sp)[3];
19663+//XXX return tsk->thread.eip;
19664 }
19665
19666 void __show_regs(struct pt_regs *regs, int all)
19667@@ -74,21 +75,20 @@ void __show_regs(struct pt_regs *regs, int all)
19668 unsigned long sp;
19669 unsigned short ss, gs;
19670
19671- if (user_mode_vm(regs)) {
19672+ if (user_mode(regs)) {
19673 sp = regs->sp;
19674 ss = regs->ss & 0xffff;
19675- gs = get_user_gs(regs);
19676 } else {
19677 sp = kernel_stack_pointer(regs);
19678 savesegment(ss, ss);
19679- savesegment(gs, gs);
19680 }
19681+ gs = get_user_gs(regs);
19682
19683 show_regs_common();
19684
19685 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
19686 (u16)regs->cs, regs->ip, regs->flags,
19687- smp_processor_id());
19688+ raw_smp_processor_id());
19689 print_symbol("EIP is at %s\n", regs->ip);
19690
19691 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
19692@@ -131,20 +131,21 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
19693 unsigned long arg,
19694 struct task_struct *p, struct pt_regs *regs)
19695 {
19696- struct pt_regs *childregs = task_pt_regs(p);
19697+ struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
19698 struct task_struct *tsk;
19699 int err;
19700
19701 p->thread.sp = (unsigned long) childregs;
19702 p->thread.sp0 = (unsigned long) (childregs+1);
19703+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
19704
19705 if (unlikely(!regs)) {
19706 /* kernel thread */
19707 memset(childregs, 0, sizeof(struct pt_regs));
19708 p->thread.ip = (unsigned long) ret_from_kernel_thread;
19709- task_user_gs(p) = __KERNEL_STACK_CANARY;
19710- childregs->ds = __USER_DS;
19711- childregs->es = __USER_DS;
19712+ savesegment(gs, childregs->gs);
19713+ childregs->ds = __KERNEL_DS;
19714+ childregs->es = __KERNEL_DS;
19715 childregs->fs = __KERNEL_PERCPU;
19716 childregs->bx = sp; /* function */
19717 childregs->bp = arg;
19718@@ -250,7 +251,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
19719 struct thread_struct *prev = &prev_p->thread,
19720 *next = &next_p->thread;
19721 int cpu = smp_processor_id();
19722- struct tss_struct *tss = &per_cpu(init_tss, cpu);
19723+ struct tss_struct *tss = init_tss + cpu;
19724 fpu_switch_t fpu;
19725
19726 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
19727@@ -274,6 +275,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
19728 */
19729 lazy_save_gs(prev->gs);
19730
19731+#ifdef CONFIG_PAX_MEMORY_UDEREF
19732+ __set_fs(task_thread_info(next_p)->addr_limit);
19733+#endif
19734+
19735 /*
19736 * Load the per-thread Thread-Local Storage descriptor.
19737 */
19738@@ -304,6 +309,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
19739 */
19740 arch_end_context_switch(next_p);
19741
19742+ this_cpu_write(current_task, next_p);
19743+ this_cpu_write(current_tinfo, &next_p->tinfo);
19744+
19745 /*
19746 * Restore %gs if needed (which is common)
19747 */
19748@@ -312,8 +320,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
19749
19750 switch_fpu_finish(next_p, fpu);
19751
19752- this_cpu_write(current_task, next_p);
19753-
19754 return prev_p;
19755 }
19756
19757@@ -343,4 +349,3 @@ unsigned long get_wchan(struct task_struct *p)
19758 } while (count++ < 16);
19759 return 0;
19760 }
19761-
19762diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
19763index 16c6365..5d32218 100644
19764--- a/arch/x86/kernel/process_64.c
19765+++ b/arch/x86/kernel/process_64.c
19766@@ -153,10 +153,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
19767 struct pt_regs *childregs;
19768 struct task_struct *me = current;
19769
19770- p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
19771+ p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
19772 childregs = task_pt_regs(p);
19773 p->thread.sp = (unsigned long) childregs;
19774 p->thread.usersp = me->thread.usersp;
19775+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
19776 set_tsk_thread_flag(p, TIF_FORK);
19777 p->fpu_counter = 0;
19778 p->thread.io_bitmap_ptr = NULL;
19779@@ -274,7 +275,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
19780 struct thread_struct *prev = &prev_p->thread;
19781 struct thread_struct *next = &next_p->thread;
19782 int cpu = smp_processor_id();
19783- struct tss_struct *tss = &per_cpu(init_tss, cpu);
19784+ struct tss_struct *tss = init_tss + cpu;
19785 unsigned fsindex, gsindex;
19786 fpu_switch_t fpu;
19787
19788@@ -356,10 +357,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
19789 prev->usersp = this_cpu_read(old_rsp);
19790 this_cpu_write(old_rsp, next->usersp);
19791 this_cpu_write(current_task, next_p);
19792+ this_cpu_write(current_tinfo, &next_p->tinfo);
19793
19794- this_cpu_write(kernel_stack,
19795- (unsigned long)task_stack_page(next_p) +
19796- THREAD_SIZE - KERNEL_STACK_OFFSET);
19797+ this_cpu_write(kernel_stack, next->sp0);
19798
19799 /*
19800 * Now maybe reload the debug registers and handle I/O bitmaps
19801@@ -428,12 +428,11 @@ unsigned long get_wchan(struct task_struct *p)
19802 if (!p || p == current || p->state == TASK_RUNNING)
19803 return 0;
19804 stack = (unsigned long)task_stack_page(p);
19805- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
19806+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
19807 return 0;
19808 fp = *(u64 *)(p->thread.sp);
19809 do {
19810- if (fp < (unsigned long)stack ||
19811- fp >= (unsigned long)stack+THREAD_SIZE)
19812+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
19813 return 0;
19814 ip = *(u64 *)(fp+8);
19815 if (!in_sched_functions(ip))
19816diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
19817index 974b67e..044111b 100644
19818--- a/arch/x86/kernel/ptrace.c
19819+++ b/arch/x86/kernel/ptrace.c
19820@@ -183,14 +183,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
19821 {
19822 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
19823 unsigned long sp = (unsigned long)&regs->sp;
19824- struct thread_info *tinfo;
19825
19826- if (context == (sp & ~(THREAD_SIZE - 1)))
19827+ if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
19828 return sp;
19829
19830- tinfo = (struct thread_info *)context;
19831- if (tinfo->previous_esp)
19832- return tinfo->previous_esp;
19833+ sp = *(unsigned long *)context;
19834+ if (sp)
19835+ return sp;
19836
19837 return (unsigned long)regs;
19838 }
19839@@ -855,7 +854,7 @@ long arch_ptrace(struct task_struct *child, long request,
19840 unsigned long addr, unsigned long data)
19841 {
19842 int ret;
19843- unsigned long __user *datap = (unsigned long __user *)data;
19844+ unsigned long __user *datap = (__force unsigned long __user *)data;
19845
19846 switch (request) {
19847 /* read the word at location addr in the USER area. */
19848@@ -940,14 +939,14 @@ long arch_ptrace(struct task_struct *child, long request,
19849 if ((int) addr < 0)
19850 return -EIO;
19851 ret = do_get_thread_area(child, addr,
19852- (struct user_desc __user *)data);
19853+ (__force struct user_desc __user *) data);
19854 break;
19855
19856 case PTRACE_SET_THREAD_AREA:
19857 if ((int) addr < 0)
19858 return -EIO;
19859 ret = do_set_thread_area(child, addr,
19860- (struct user_desc __user *)data, 0);
19861+ (__force struct user_desc __user *) data, 0);
19862 break;
19863 #endif
19864
19865@@ -1325,7 +1324,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
19866
19867 #ifdef CONFIG_X86_64
19868
19869-static struct user_regset x86_64_regsets[] __read_mostly = {
19870+static struct user_regset x86_64_regsets[] = {
19871 [REGSET_GENERAL] = {
19872 .core_note_type = NT_PRSTATUS,
19873 .n = sizeof(struct user_regs_struct) / sizeof(long),
19874@@ -1366,7 +1365,7 @@ static const struct user_regset_view user_x86_64_view = {
19875 #endif /* CONFIG_X86_64 */
19876
19877 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
19878-static struct user_regset x86_32_regsets[] __read_mostly = {
19879+static struct user_regset x86_32_regsets[] = {
19880 [REGSET_GENERAL] = {
19881 .core_note_type = NT_PRSTATUS,
19882 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
19883@@ -1419,13 +1418,13 @@ static const struct user_regset_view user_x86_32_view = {
19884 */
19885 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
19886
19887-void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
19888+void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
19889 {
19890 #ifdef CONFIG_X86_64
19891- x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
19892+ *(unsigned int *)&x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
19893 #endif
19894 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
19895- x86_32_regsets[REGSET_XSTATE].n = size / sizeof(u64);
19896+ *(unsigned int *)&x86_32_regsets[REGSET_XSTATE].n = size / sizeof(u64);
19897 #endif
19898 xstate_fx_sw_bytes[USER_XSTATE_XCR0_WORD] = xstate_mask;
19899 }
19900@@ -1454,7 +1453,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
19901 memset(info, 0, sizeof(*info));
19902 info->si_signo = SIGTRAP;
19903 info->si_code = si_code;
19904- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
19905+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
19906 }
19907
19908 void user_single_step_siginfo(struct task_struct *tsk,
19909@@ -1483,6 +1482,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
19910 # define IS_IA32 0
19911 #endif
19912
19913+#ifdef CONFIG_GRKERNSEC_SETXID
19914+extern void gr_delayed_cred_worker(void);
19915+#endif
19916+
19917 /*
19918 * We must return the syscall number to actually look up in the table.
19919 * This can be -1L to skip running any syscall at all.
19920@@ -1493,6 +1496,11 @@ long syscall_trace_enter(struct pt_regs *regs)
19921
19922 rcu_user_exit();
19923
19924+#ifdef CONFIG_GRKERNSEC_SETXID
19925+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
19926+ gr_delayed_cred_worker();
19927+#endif
19928+
19929 /*
19930 * If we stepped into a sysenter/syscall insn, it trapped in
19931 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
19932@@ -1548,6 +1556,11 @@ void syscall_trace_leave(struct pt_regs *regs)
19933 */
19934 rcu_user_exit();
19935
19936+#ifdef CONFIG_GRKERNSEC_SETXID
19937+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
19938+ gr_delayed_cred_worker();
19939+#endif
19940+
19941 audit_syscall_exit(regs);
19942
19943 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
19944diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
19945index 42eb330..139955c 100644
19946--- a/arch/x86/kernel/pvclock.c
19947+++ b/arch/x86/kernel/pvclock.c
19948@@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
19949 return pv_tsc_khz;
19950 }
19951
19952-static atomic64_t last_value = ATOMIC64_INIT(0);
19953+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
19954
19955 void pvclock_resume(void)
19956 {
19957- atomic64_set(&last_value, 0);
19958+ atomic64_set_unchecked(&last_value, 0);
19959 }
19960
19961 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
19962@@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
19963 * updating at the same time, and one of them could be slightly behind,
19964 * making the assumption that last_value always go forward fail to hold.
19965 */
19966- last = atomic64_read(&last_value);
19967+ last = atomic64_read_unchecked(&last_value);
19968 do {
19969 if (ret < last)
19970 return last;
19971- last = atomic64_cmpxchg(&last_value, last, ret);
19972+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
19973 } while (unlikely(last != ret));
19974
19975 return ret;
19976diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
19977index 4e8ba39..e0186b3 100644
19978--- a/arch/x86/kernel/reboot.c
19979+++ b/arch/x86/kernel/reboot.c
19980@@ -36,7 +36,7 @@ void (*pm_power_off)(void);
19981 EXPORT_SYMBOL(pm_power_off);
19982
19983 static const struct desc_ptr no_idt = {};
19984-static int reboot_mode;
19985+static unsigned short reboot_mode;
19986 enum reboot_type reboot_type = BOOT_ACPI;
19987 int reboot_force;
19988
19989@@ -157,6 +157,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
19990
19991 void __noreturn machine_real_restart(unsigned int type)
19992 {
19993+
19994+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
19995+ struct desc_struct *gdt;
19996+#endif
19997+
19998 local_irq_disable();
19999
20000 /*
20001@@ -184,7 +189,29 @@ void __noreturn machine_real_restart(unsigned int type)
20002
20003 /* Jump to the identity-mapped low memory code */
20004 #ifdef CONFIG_X86_32
20005- asm volatile("jmpl *%0" : :
20006+
20007+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
20008+ gdt = get_cpu_gdt_table(smp_processor_id());
20009+ pax_open_kernel();
20010+#ifdef CONFIG_PAX_MEMORY_UDEREF
20011+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
20012+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
20013+ loadsegment(ds, __KERNEL_DS);
20014+ loadsegment(es, __KERNEL_DS);
20015+ loadsegment(ss, __KERNEL_DS);
20016+#endif
20017+#ifdef CONFIG_PAX_KERNEXEC
20018+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
20019+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
20020+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
20021+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
20022+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
20023+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
20024+#endif
20025+ pax_close_kernel();
20026+#endif
20027+
20028+ asm volatile("ljmpl *%0" : :
20029 "rm" (real_mode_header->machine_real_restart_asm),
20030 "a" (type));
20031 #else
20032@@ -531,7 +558,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
20033 * try to force a triple fault and then cycle between hitting the keyboard
20034 * controller and doing that
20035 */
20036-static void native_machine_emergency_restart(void)
20037+static void __noreturn native_machine_emergency_restart(void)
20038 {
20039 int i;
20040 int attempt = 0;
20041@@ -654,13 +681,13 @@ void native_machine_shutdown(void)
20042 #endif
20043 }
20044
20045-static void __machine_emergency_restart(int emergency)
20046+static void __noreturn __machine_emergency_restart(int emergency)
20047 {
20048 reboot_emergency = emergency;
20049 machine_ops.emergency_restart();
20050 }
20051
20052-static void native_machine_restart(char *__unused)
20053+static void __noreturn native_machine_restart(char *__unused)
20054 {
20055 pr_notice("machine restart\n");
20056
20057@@ -669,7 +696,7 @@ static void native_machine_restart(char *__unused)
20058 __machine_emergency_restart(0);
20059 }
20060
20061-static void native_machine_halt(void)
20062+static void __noreturn native_machine_halt(void)
20063 {
20064 /* Stop other cpus and apics */
20065 machine_shutdown();
20066@@ -679,7 +706,7 @@ static void native_machine_halt(void)
20067 stop_this_cpu(NULL);
20068 }
20069
20070-static void native_machine_power_off(void)
20071+static void __noreturn native_machine_power_off(void)
20072 {
20073 if (pm_power_off) {
20074 if (!reboot_force)
20075@@ -688,6 +715,7 @@ static void native_machine_power_off(void)
20076 }
20077 /* A fallback in case there is no PM info available */
20078 tboot_shutdown(TB_SHUTDOWN_HALT);
20079+ unreachable();
20080 }
20081
20082 struct machine_ops machine_ops = {
20083diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
20084index 7a6f3b3..bed145d7 100644
20085--- a/arch/x86/kernel/relocate_kernel_64.S
20086+++ b/arch/x86/kernel/relocate_kernel_64.S
20087@@ -11,6 +11,7 @@
20088 #include <asm/kexec.h>
20089 #include <asm/processor-flags.h>
20090 #include <asm/pgtable_types.h>
20091+#include <asm/alternative-asm.h>
20092
20093 /*
20094 * Must be relocatable PIC code callable as a C function
20095@@ -160,13 +161,14 @@ identity_mapped:
20096 xorq %rbp, %rbp
20097 xorq %r8, %r8
20098 xorq %r9, %r9
20099- xorq %r10, %r9
20100+ xorq %r10, %r10
20101 xorq %r11, %r11
20102 xorq %r12, %r12
20103 xorq %r13, %r13
20104 xorq %r14, %r14
20105 xorq %r15, %r15
20106
20107+ pax_force_retaddr 0, 1
20108 ret
20109
20110 1:
20111diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
20112index ca45696..6384a09 100644
20113--- a/arch/x86/kernel/setup.c
20114+++ b/arch/x86/kernel/setup.c
20115@@ -441,7 +441,7 @@ static void __init parse_setup_data(void)
20116
20117 switch (data->type) {
20118 case SETUP_E820_EXT:
20119- parse_e820_ext(data);
20120+ parse_e820_ext((struct setup_data __force_kernel *)data);
20121 break;
20122 case SETUP_DTB:
20123 add_dtb(pa_data);
20124@@ -633,7 +633,7 @@ static void __init trim_bios_range(void)
20125 * area (640->1Mb) as ram even though it is not.
20126 * take them out.
20127 */
20128- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
20129+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
20130 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
20131 }
20132
20133@@ -756,14 +756,14 @@ void __init setup_arch(char **cmdline_p)
20134
20135 if (!boot_params.hdr.root_flags)
20136 root_mountflags &= ~MS_RDONLY;
20137- init_mm.start_code = (unsigned long) _text;
20138- init_mm.end_code = (unsigned long) _etext;
20139+ init_mm.start_code = ktla_ktva((unsigned long) _text);
20140+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
20141 init_mm.end_data = (unsigned long) _edata;
20142 init_mm.brk = _brk_end;
20143
20144- code_resource.start = virt_to_phys(_text);
20145- code_resource.end = virt_to_phys(_etext)-1;
20146- data_resource.start = virt_to_phys(_etext);
20147+ code_resource.start = virt_to_phys(ktla_ktva(_text));
20148+ code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
20149+ data_resource.start = virt_to_phys(_sdata);
20150 data_resource.end = virt_to_phys(_edata)-1;
20151 bss_resource.start = virt_to_phys(&__bss_start);
20152 bss_resource.end = virt_to_phys(&__bss_stop)-1;
20153diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
20154index 5cdff03..5810740 100644
20155--- a/arch/x86/kernel/setup_percpu.c
20156+++ b/arch/x86/kernel/setup_percpu.c
20157@@ -21,19 +21,17 @@
20158 #include <asm/cpu.h>
20159 #include <asm/stackprotector.h>
20160
20161-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
20162+#ifdef CONFIG_SMP
20163+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
20164 EXPORT_PER_CPU_SYMBOL(cpu_number);
20165+#endif
20166
20167-#ifdef CONFIG_X86_64
20168 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
20169-#else
20170-#define BOOT_PERCPU_OFFSET 0
20171-#endif
20172
20173 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
20174 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
20175
20176-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
20177+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
20178 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
20179 };
20180 EXPORT_SYMBOL(__per_cpu_offset);
20181@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
20182 {
20183 #ifdef CONFIG_X86_32
20184 struct desc_struct gdt;
20185+ unsigned long base = per_cpu_offset(cpu);
20186
20187- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
20188- 0x2 | DESCTYPE_S, 0x8);
20189- gdt.s = 1;
20190+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
20191+ 0x83 | DESCTYPE_S, 0xC);
20192 write_gdt_entry(get_cpu_gdt_table(cpu),
20193 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
20194 #endif
20195@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
20196 /* alrighty, percpu areas up and running */
20197 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
20198 for_each_possible_cpu(cpu) {
20199+#ifdef CONFIG_CC_STACKPROTECTOR
20200+#ifdef CONFIG_X86_32
20201+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
20202+#endif
20203+#endif
20204 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
20205 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
20206 per_cpu(cpu_number, cpu) = cpu;
20207@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
20208 */
20209 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
20210 #endif
20211+#ifdef CONFIG_CC_STACKPROTECTOR
20212+#ifdef CONFIG_X86_32
20213+ if (!cpu)
20214+ per_cpu(stack_canary.canary, cpu) = canary;
20215+#endif
20216+#endif
20217 /*
20218 * Up to this point, the boot CPU has been using .init.data
20219 * area. Reload any changed state for the boot CPU.
20220diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
20221index 70b27ee..fcf827f 100644
20222--- a/arch/x86/kernel/signal.c
20223+++ b/arch/x86/kernel/signal.c
20224@@ -195,7 +195,7 @@ static unsigned long align_sigframe(unsigned long sp)
20225 * Align the stack pointer according to the i386 ABI,
20226 * i.e. so that on function entry ((sp + 4) & 15) == 0.
20227 */
20228- sp = ((sp + 4) & -16ul) - 4;
20229+ sp = ((sp - 12) & -16ul) - 4;
20230 #else /* !CONFIG_X86_32 */
20231 sp = round_down(sp, 16) - 8;
20232 #endif
20233@@ -303,9 +303,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
20234 }
20235
20236 if (current->mm->context.vdso)
20237- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
20238+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
20239 else
20240- restorer = &frame->retcode;
20241+ restorer = (void __user *)&frame->retcode;
20242 if (ka->sa.sa_flags & SA_RESTORER)
20243 restorer = ka->sa.sa_restorer;
20244
20245@@ -319,7 +319,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
20246 * reasons and because gdb uses it as a signature to notice
20247 * signal handler stack frames.
20248 */
20249- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
20250+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
20251
20252 if (err)
20253 return -EFAULT;
20254@@ -369,7 +369,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
20255 put_user_ex(current->sas_ss_size, &frame->uc.uc_stack.ss_size);
20256
20257 /* Set up to return from userspace. */
20258- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
20259+ if (current->mm->context.vdso)
20260+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
20261+ else
20262+ restorer = (void __user *)&frame->retcode;
20263 if (ka->sa.sa_flags & SA_RESTORER)
20264 restorer = ka->sa.sa_restorer;
20265 put_user_ex(restorer, &frame->pretcode);
20266@@ -381,7 +384,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
20267 * reasons and because gdb uses it as a signature to notice
20268 * signal handler stack frames.
20269 */
20270- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
20271+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
20272 } put_user_catch(err);
20273
20274 err |= copy_siginfo_to_user(&frame->info, info);
20275diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
20276index f3e2ec8..ad5287a 100644
20277--- a/arch/x86/kernel/smpboot.c
20278+++ b/arch/x86/kernel/smpboot.c
20279@@ -673,6 +673,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
20280 idle->thread.sp = (unsigned long) (((struct pt_regs *)
20281 (THREAD_SIZE + task_stack_page(idle))) - 1);
20282 per_cpu(current_task, cpu) = idle;
20283+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
20284
20285 #ifdef CONFIG_X86_32
20286 /* Stack for startup_32 can be just as for start_secondary onwards */
20287@@ -680,11 +681,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
20288 #else
20289 clear_tsk_thread_flag(idle, TIF_FORK);
20290 initial_gs = per_cpu_offset(cpu);
20291- per_cpu(kernel_stack, cpu) =
20292- (unsigned long)task_stack_page(idle) -
20293- KERNEL_STACK_OFFSET + THREAD_SIZE;
20294+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
20295 #endif
20296+
20297+ pax_open_kernel();
20298 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
20299+ pax_close_kernel();
20300+
20301 initial_code = (unsigned long)start_secondary;
20302 stack_start = idle->thread.sp;
20303
20304@@ -823,6 +826,15 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
20305 /* the FPU context is blank, nobody can own it */
20306 __cpu_disable_lazy_restore(cpu);
20307
20308+#ifdef CONFIG_PAX_PER_CPU_PGD
20309+ clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
20310+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
20311+ KERNEL_PGD_PTRS);
20312+#endif
20313+
20314+ /* the FPU context is blank, nobody can own it */
20315+ __cpu_disable_lazy_restore(cpu);
20316+
20317 err = do_boot_cpu(apicid, cpu, tidle);
20318 if (err) {
20319 pr_debug("do_boot_cpu failed %d\n", err);
20320diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
20321index cd3b243..4ba27a4 100644
20322--- a/arch/x86/kernel/step.c
20323+++ b/arch/x86/kernel/step.c
20324@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
20325 struct desc_struct *desc;
20326 unsigned long base;
20327
20328- seg &= ~7UL;
20329+ seg >>= 3;
20330
20331 mutex_lock(&child->mm->context.lock);
20332- if (unlikely((seg >> 3) >= child->mm->context.size))
20333+ if (unlikely(seg >= child->mm->context.size))
20334 addr = -1L; /* bogus selector, access would fault */
20335 else {
20336 desc = child->mm->context.ldt + seg;
20337@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
20338 addr += base;
20339 }
20340 mutex_unlock(&child->mm->context.lock);
20341- }
20342+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
20343+ addr = ktla_ktva(addr);
20344
20345 return addr;
20346 }
20347@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
20348 unsigned char opcode[15];
20349 unsigned long addr = convert_ip_to_linear(child, regs);
20350
20351+ if (addr == -EINVAL)
20352+ return 0;
20353+
20354 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
20355 for (i = 0; i < copied; i++) {
20356 switch (opcode[i]) {
20357diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
20358new file mode 100644
20359index 0000000..db6b9ed
20360--- /dev/null
20361+++ b/arch/x86/kernel/sys_i386_32.c
20362@@ -0,0 +1,247 @@
20363+/*
20364+ * This file contains various random system calls that
20365+ * have a non-standard calling sequence on the Linux/i386
20366+ * platform.
20367+ */
20368+
20369+#include <linux/errno.h>
20370+#include <linux/sched.h>
20371+#include <linux/mm.h>
20372+#include <linux/fs.h>
20373+#include <linux/smp.h>
20374+#include <linux/sem.h>
20375+#include <linux/msg.h>
20376+#include <linux/shm.h>
20377+#include <linux/stat.h>
20378+#include <linux/syscalls.h>
20379+#include <linux/mman.h>
20380+#include <linux/file.h>
20381+#include <linux/utsname.h>
20382+#include <linux/ipc.h>
20383+
20384+#include <linux/uaccess.h>
20385+#include <linux/unistd.h>
20386+
20387+#include <asm/syscalls.h>
20388+
20389+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
20390+{
20391+ unsigned long pax_task_size = TASK_SIZE;
20392+
20393+#ifdef CONFIG_PAX_SEGMEXEC
20394+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
20395+ pax_task_size = SEGMEXEC_TASK_SIZE;
20396+#endif
20397+
20398+ if (len > pax_task_size || addr > pax_task_size - len)
20399+ return -EINVAL;
20400+
20401+ return 0;
20402+}
20403+
20404+unsigned long
20405+arch_get_unmapped_area(struct file *filp, unsigned long addr,
20406+ unsigned long len, unsigned long pgoff, unsigned long flags)
20407+{
20408+ struct mm_struct *mm = current->mm;
20409+ struct vm_area_struct *vma;
20410+ unsigned long start_addr, pax_task_size = TASK_SIZE;
20411+
20412+#ifdef CONFIG_PAX_SEGMEXEC
20413+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
20414+ pax_task_size = SEGMEXEC_TASK_SIZE;
20415+#endif
20416+
20417+ pax_task_size -= PAGE_SIZE;
20418+
20419+ if (len > pax_task_size)
20420+ return -ENOMEM;
20421+
20422+ if (flags & MAP_FIXED)
20423+ return addr;
20424+
20425+#ifdef CONFIG_PAX_RANDMMAP
20426+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
20427+#endif
20428+
20429+ if (addr) {
20430+ addr = PAGE_ALIGN(addr);
20431+ if (pax_task_size - len >= addr) {
20432+ vma = find_vma(mm, addr);
20433+ if (check_heap_stack_gap(vma, addr, len))
20434+ return addr;
20435+ }
20436+ }
20437+ if (len > mm->cached_hole_size) {
20438+ start_addr = addr = mm->free_area_cache;
20439+ } else {
20440+ start_addr = addr = mm->mmap_base;
20441+ mm->cached_hole_size = 0;
20442+ }
20443+
20444+#ifdef CONFIG_PAX_PAGEEXEC
20445+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
20446+ start_addr = 0x00110000UL;
20447+
20448+#ifdef CONFIG_PAX_RANDMMAP
20449+ if (mm->pax_flags & MF_PAX_RANDMMAP)
20450+ start_addr += mm->delta_mmap & 0x03FFF000UL;
20451+#endif
20452+
20453+ if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
20454+ start_addr = addr = mm->mmap_base;
20455+ else
20456+ addr = start_addr;
20457+ }
20458+#endif
20459+
20460+full_search:
20461+ for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
20462+ /* At this point: (!vma || addr < vma->vm_end). */
20463+ if (pax_task_size - len < addr) {
20464+ /*
20465+ * Start a new search - just in case we missed
20466+ * some holes.
20467+ */
20468+ if (start_addr != mm->mmap_base) {
20469+ start_addr = addr = mm->mmap_base;
20470+ mm->cached_hole_size = 0;
20471+ goto full_search;
20472+ }
20473+ return -ENOMEM;
20474+ }
20475+ if (check_heap_stack_gap(vma, addr, len))
20476+ break;
20477+ if (addr + mm->cached_hole_size < vma->vm_start)
20478+ mm->cached_hole_size = vma->vm_start - addr;
20479+ addr = vma->vm_end;
20480+ if (mm->start_brk <= addr && addr < mm->mmap_base) {
20481+ start_addr = addr = mm->mmap_base;
20482+ mm->cached_hole_size = 0;
20483+ goto full_search;
20484+ }
20485+ }
20486+
20487+ /*
20488+ * Remember the place where we stopped the search:
20489+ */
20490+ mm->free_area_cache = addr + len;
20491+ return addr;
20492+}
20493+
20494+unsigned long
20495+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
20496+ const unsigned long len, const unsigned long pgoff,
20497+ const unsigned long flags)
20498+{
20499+ struct vm_area_struct *vma;
20500+ struct mm_struct *mm = current->mm;
20501+ unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
20502+
20503+#ifdef CONFIG_PAX_SEGMEXEC
20504+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
20505+ pax_task_size = SEGMEXEC_TASK_SIZE;
20506+#endif
20507+
20508+ pax_task_size -= PAGE_SIZE;
20509+
20510+ /* requested length too big for entire address space */
20511+ if (len > pax_task_size)
20512+ return -ENOMEM;
20513+
20514+ if (flags & MAP_FIXED)
20515+ return addr;
20516+
20517+#ifdef CONFIG_PAX_PAGEEXEC
20518+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
20519+ goto bottomup;
20520+#endif
20521+
20522+#ifdef CONFIG_PAX_RANDMMAP
20523+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
20524+#endif
20525+
20526+ /* requesting a specific address */
20527+ if (addr) {
20528+ addr = PAGE_ALIGN(addr);
20529+ if (pax_task_size - len >= addr) {
20530+ vma = find_vma(mm, addr);
20531+ if (check_heap_stack_gap(vma, addr, len))
20532+ return addr;
20533+ }
20534+ }
20535+
20536+ /* check if free_area_cache is useful for us */
20537+ if (len <= mm->cached_hole_size) {
20538+ mm->cached_hole_size = 0;
20539+ mm->free_area_cache = mm->mmap_base;
20540+ }
20541+
20542+ /* either no address requested or can't fit in requested address hole */
20543+ addr = mm->free_area_cache;
20544+
20545+ /* make sure it can fit in the remaining address space */
20546+ if (addr > len) {
20547+ vma = find_vma(mm, addr-len);
20548+ if (check_heap_stack_gap(vma, addr - len, len))
20549+ /* remember the address as a hint for next time */
20550+ return (mm->free_area_cache = addr-len);
20551+ }
20552+
20553+ if (mm->mmap_base < len)
20554+ goto bottomup;
20555+
20556+ addr = mm->mmap_base-len;
20557+
20558+ do {
20559+ /*
20560+ * Lookup failure means no vma is above this address,
20561+ * else if new region fits below vma->vm_start,
20562+ * return with success:
20563+ */
20564+ vma = find_vma(mm, addr);
20565+ if (check_heap_stack_gap(vma, addr, len))
20566+ /* remember the address as a hint for next time */
20567+ return (mm->free_area_cache = addr);
20568+
20569+ /* remember the largest hole we saw so far */
20570+ if (addr + mm->cached_hole_size < vma->vm_start)
20571+ mm->cached_hole_size = vma->vm_start - addr;
20572+
20573+ /* try just below the current vma->vm_start */
20574+ addr = skip_heap_stack_gap(vma, len);
20575+ } while (!IS_ERR_VALUE(addr));
20576+
20577+bottomup:
20578+ /*
20579+ * A failed mmap() very likely causes application failure,
20580+ * so fall back to the bottom-up function here. This scenario
20581+ * can happen with large stack limits and large mmap()
20582+ * allocations.
20583+ */
20584+
20585+#ifdef CONFIG_PAX_SEGMEXEC
20586+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
20587+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
20588+ else
20589+#endif
20590+
20591+ mm->mmap_base = TASK_UNMAPPED_BASE;
20592+
20593+#ifdef CONFIG_PAX_RANDMMAP
20594+ if (mm->pax_flags & MF_PAX_RANDMMAP)
20595+ mm->mmap_base += mm->delta_mmap;
20596+#endif
20597+
20598+ mm->free_area_cache = mm->mmap_base;
20599+ mm->cached_hole_size = ~0UL;
20600+ addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
20601+ /*
20602+ * Restore the topdown base:
20603+ */
20604+ mm->mmap_base = base;
20605+ mm->free_area_cache = base;
20606+ mm->cached_hole_size = ~0UL;
20607+
20608+ return addr;
20609+}
20610diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
20611index b4d3c39..82bb73b 100644
20612--- a/arch/x86/kernel/sys_x86_64.c
20613+++ b/arch/x86/kernel/sys_x86_64.c
20614@@ -95,8 +95,8 @@ out:
20615 return error;
20616 }
20617
20618-static void find_start_end(unsigned long flags, unsigned long *begin,
20619- unsigned long *end)
20620+static void find_start_end(struct mm_struct *mm, unsigned long flags,
20621+ unsigned long *begin, unsigned long *end)
20622 {
20623 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
20624 unsigned long new_begin;
20625@@ -115,7 +115,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
20626 *begin = new_begin;
20627 }
20628 } else {
20629- *begin = TASK_UNMAPPED_BASE;
20630+ *begin = mm->mmap_base;
20631 *end = TASK_SIZE;
20632 }
20633 }
20634@@ -132,16 +132,19 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
20635 if (flags & MAP_FIXED)
20636 return addr;
20637
20638- find_start_end(flags, &begin, &end);
20639+ find_start_end(mm, flags, &begin, &end);
20640
20641 if (len > end)
20642 return -ENOMEM;
20643
20644+#ifdef CONFIG_PAX_RANDMMAP
20645+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
20646+#endif
20647+
20648 if (addr) {
20649 addr = PAGE_ALIGN(addr);
20650 vma = find_vma(mm, addr);
20651- if (end - len >= addr &&
20652- (!vma || addr + len <= vma->vm_start))
20653+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
20654 return addr;
20655 }
20656 if (((flags & MAP_32BIT) || test_thread_flag(TIF_ADDR32))
20657@@ -172,7 +175,7 @@ full_search:
20658 }
20659 return -ENOMEM;
20660 }
20661- if (!vma || addr + len <= vma->vm_start) {
20662+ if (check_heap_stack_gap(vma, addr, len)) {
20663 /*
20664 * Remember the place where we stopped the search:
20665 */
20666@@ -195,7 +198,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
20667 {
20668 struct vm_area_struct *vma;
20669 struct mm_struct *mm = current->mm;
20670- unsigned long addr = addr0, start_addr;
20671+ unsigned long base = mm->mmap_base, addr = addr0, start_addr;
20672
20673 /* requested length too big for entire address space */
20674 if (len > TASK_SIZE)
20675@@ -208,13 +211,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
20676 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
20677 goto bottomup;
20678
20679+#ifdef CONFIG_PAX_RANDMMAP
20680+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
20681+#endif
20682+
20683 /* requesting a specific address */
20684 if (addr) {
20685 addr = PAGE_ALIGN(addr);
20686- vma = find_vma(mm, addr);
20687- if (TASK_SIZE - len >= addr &&
20688- (!vma || addr + len <= vma->vm_start))
20689- return addr;
20690+ if (TASK_SIZE - len >= addr) {
20691+ vma = find_vma(mm, addr);
20692+ if (check_heap_stack_gap(vma, addr, len))
20693+ return addr;
20694+ }
20695 }
20696
20697 /* check if free_area_cache is useful for us */
20698@@ -240,7 +248,7 @@ try_again:
20699 * return with success:
20700 */
20701 vma = find_vma(mm, addr);
20702- if (!vma || addr+len <= vma->vm_start)
20703+ if (check_heap_stack_gap(vma, addr, len))
20704 /* remember the address as a hint for next time */
20705 return mm->free_area_cache = addr;
20706
20707@@ -249,8 +257,8 @@ try_again:
20708 mm->cached_hole_size = vma->vm_start - addr;
20709
20710 /* try just below the current vma->vm_start */
20711- addr = vma->vm_start-len;
20712- } while (len < vma->vm_start);
20713+ addr = skip_heap_stack_gap(vma, len);
20714+ } while (!IS_ERR_VALUE(addr));
20715
20716 fail:
20717 /*
20718@@ -270,13 +278,21 @@ bottomup:
20719 * can happen with large stack limits and large mmap()
20720 * allocations.
20721 */
20722+ mm->mmap_base = TASK_UNMAPPED_BASE;
20723+
20724+#ifdef CONFIG_PAX_RANDMMAP
20725+ if (mm->pax_flags & MF_PAX_RANDMMAP)
20726+ mm->mmap_base += mm->delta_mmap;
20727+#endif
20728+
20729+ mm->free_area_cache = mm->mmap_base;
20730 mm->cached_hole_size = ~0UL;
20731- mm->free_area_cache = TASK_UNMAPPED_BASE;
20732 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
20733 /*
20734 * Restore the topdown base:
20735 */
20736- mm->free_area_cache = mm->mmap_base;
20737+ mm->mmap_base = base;
20738+ mm->free_area_cache = base;
20739 mm->cached_hole_size = ~0UL;
20740
20741 return addr;
20742diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
20743index f84fe00..93fe08f 100644
20744--- a/arch/x86/kernel/tboot.c
20745+++ b/arch/x86/kernel/tboot.c
20746@@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
20747
20748 void tboot_shutdown(u32 shutdown_type)
20749 {
20750- void (*shutdown)(void);
20751+ void (* __noreturn shutdown)(void);
20752
20753 if (!tboot_enabled())
20754 return;
20755@@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
20756
20757 switch_to_tboot_pt();
20758
20759- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
20760+ shutdown = (void *)tboot->shutdown_entry;
20761 shutdown();
20762
20763 /* should not reach here */
20764@@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
20765 return 0;
20766 }
20767
20768-static atomic_t ap_wfs_count;
20769+static atomic_unchecked_t ap_wfs_count;
20770
20771 static int tboot_wait_for_aps(int num_aps)
20772 {
20773@@ -324,9 +324,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
20774 {
20775 switch (action) {
20776 case CPU_DYING:
20777- atomic_inc(&ap_wfs_count);
20778+ atomic_inc_unchecked(&ap_wfs_count);
20779 if (num_online_cpus() == 1)
20780- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
20781+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
20782 return NOTIFY_BAD;
20783 break;
20784 }
20785@@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
20786
20787 tboot_create_trampoline();
20788
20789- atomic_set(&ap_wfs_count, 0);
20790+ atomic_set_unchecked(&ap_wfs_count, 0);
20791 register_hotcpu_notifier(&tboot_cpu_notifier);
20792
20793 acpi_os_set_prepare_sleep(&tboot_sleep);
20794diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
20795index 24d3c91..d06b473 100644
20796--- a/arch/x86/kernel/time.c
20797+++ b/arch/x86/kernel/time.c
20798@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
20799 {
20800 unsigned long pc = instruction_pointer(regs);
20801
20802- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
20803+ if (!user_mode(regs) && in_lock_functions(pc)) {
20804 #ifdef CONFIG_FRAME_POINTER
20805- return *(unsigned long *)(regs->bp + sizeof(long));
20806+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
20807 #else
20808 unsigned long *sp =
20809 (unsigned long *)kernel_stack_pointer(regs);
20810@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
20811 * or above a saved flags. Eflags has bits 22-31 zero,
20812 * kernel addresses don't.
20813 */
20814+
20815+#ifdef CONFIG_PAX_KERNEXEC
20816+ return ktla_ktva(sp[0]);
20817+#else
20818 if (sp[0] >> 22)
20819 return sp[0];
20820 if (sp[1] >> 22)
20821 return sp[1];
20822 #endif
20823+
20824+#endif
20825 }
20826 return pc;
20827 }
20828diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
20829index 9d9d2f9..cad418a 100644
20830--- a/arch/x86/kernel/tls.c
20831+++ b/arch/x86/kernel/tls.c
20832@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
20833 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
20834 return -EINVAL;
20835
20836+#ifdef CONFIG_PAX_SEGMEXEC
20837+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
20838+ return -EINVAL;
20839+#endif
20840+
20841 set_tls_desc(p, idx, &info, 1);
20842
20843 return 0;
20844@@ -204,7 +209,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
20845
20846 if (kbuf)
20847 info = kbuf;
20848- else if (__copy_from_user(infobuf, ubuf, count))
20849+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
20850 return -EFAULT;
20851 else
20852 info = infobuf;
20853diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
20854index 8276dc6..4ca48a2 100644
20855--- a/arch/x86/kernel/traps.c
20856+++ b/arch/x86/kernel/traps.c
20857@@ -71,12 +71,6 @@ asmlinkage int system_call(void);
20858
20859 /* Do we ignore FPU interrupts ? */
20860 char ignore_fpu_irq;
20861-
20862-/*
20863- * The IDT has to be page-aligned to simplify the Pentium
20864- * F0 0F bug workaround.
20865- */
20866-gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
20867 #endif
20868
20869 DECLARE_BITMAP(used_vectors, NR_VECTORS);
20870@@ -109,11 +103,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
20871 }
20872
20873 static int __kprobes
20874-do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
20875+do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
20876 struct pt_regs *regs, long error_code)
20877 {
20878 #ifdef CONFIG_X86_32
20879- if (regs->flags & X86_VM_MASK) {
20880+ if (v8086_mode(regs)) {
20881 /*
20882 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
20883 * On nmi (interrupt 2), do_trap should not be called.
20884@@ -126,12 +120,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
20885 return -1;
20886 }
20887 #endif
20888- if (!user_mode(regs)) {
20889+ if (!user_mode_novm(regs)) {
20890 if (!fixup_exception(regs)) {
20891 tsk->thread.error_code = error_code;
20892 tsk->thread.trap_nr = trapnr;
20893+
20894+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20895+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
20896+ str = "PAX: suspicious stack segment fault";
20897+#endif
20898+
20899 die(str, regs, error_code);
20900 }
20901+
20902+#ifdef CONFIG_PAX_REFCOUNT
20903+ if (trapnr == 4)
20904+ pax_report_refcount_overflow(regs);
20905+#endif
20906+
20907 return 0;
20908 }
20909
20910@@ -139,7 +145,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
20911 }
20912
20913 static void __kprobes
20914-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
20915+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
20916 long error_code, siginfo_t *info)
20917 {
20918 struct task_struct *tsk = current;
20919@@ -163,7 +169,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
20920 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
20921 printk_ratelimit()) {
20922 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
20923- tsk->comm, tsk->pid, str,
20924+ tsk->comm, task_pid_nr(tsk), str,
20925 regs->ip, regs->sp, error_code);
20926 print_vma_addr(" in ", regs->ip);
20927 pr_cont("\n");
20928@@ -269,7 +275,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
20929 conditional_sti(regs);
20930
20931 #ifdef CONFIG_X86_32
20932- if (regs->flags & X86_VM_MASK) {
20933+ if (v8086_mode(regs)) {
20934 local_irq_enable();
20935 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
20936 goto exit;
20937@@ -277,18 +283,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
20938 #endif
20939
20940 tsk = current;
20941- if (!user_mode(regs)) {
20942+ if (!user_mode_novm(regs)) {
20943 if (fixup_exception(regs))
20944 goto exit;
20945
20946 tsk->thread.error_code = error_code;
20947 tsk->thread.trap_nr = X86_TRAP_GP;
20948 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
20949- X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
20950+ X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
20951+
20952+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20953+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
20954+ die("PAX: suspicious general protection fault", regs, error_code);
20955+ else
20956+#endif
20957+
20958 die("general protection fault", regs, error_code);
20959+ }
20960 goto exit;
20961 }
20962
20963+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
20964+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
20965+ struct mm_struct *mm = tsk->mm;
20966+ unsigned long limit;
20967+
20968+ down_write(&mm->mmap_sem);
20969+ limit = mm->context.user_cs_limit;
20970+ if (limit < TASK_SIZE) {
20971+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
20972+ up_write(&mm->mmap_sem);
20973+ return;
20974+ }
20975+ up_write(&mm->mmap_sem);
20976+ }
20977+#endif
20978+
20979 tsk->thread.error_code = error_code;
20980 tsk->thread.trap_nr = X86_TRAP_GP;
20981
20982@@ -443,7 +473,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
20983 /* It's safe to allow irq's after DR6 has been saved */
20984 preempt_conditional_sti(regs);
20985
20986- if (regs->flags & X86_VM_MASK) {
20987+ if (v8086_mode(regs)) {
20988 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
20989 X86_TRAP_DB);
20990 preempt_conditional_cli(regs);
20991@@ -458,7 +488,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
20992 * We already checked v86 mode above, so we can check for kernel mode
20993 * by just checking the CPL of CS.
20994 */
20995- if ((dr6 & DR_STEP) && !user_mode(regs)) {
20996+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
20997 tsk->thread.debugreg6 &= ~DR_STEP;
20998 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
20999 regs->flags &= ~X86_EFLAGS_TF;
21000@@ -490,7 +520,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
21001 return;
21002 conditional_sti(regs);
21003
21004- if (!user_mode_vm(regs))
21005+ if (!user_mode(regs))
21006 {
21007 if (!fixup_exception(regs)) {
21008 task->thread.error_code = error_code;
21009diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
21010index aafa555..a04691a 100644
21011--- a/arch/x86/kernel/uprobes.c
21012+++ b/arch/x86/kernel/uprobes.c
21013@@ -614,7 +614,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
21014 int ret = NOTIFY_DONE;
21015
21016 /* We are only interested in userspace traps */
21017- if (regs && !user_mode_vm(regs))
21018+ if (regs && !user_mode(regs))
21019 return NOTIFY_DONE;
21020
21021 switch (val) {
21022diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
21023index b9242ba..50c5edd 100644
21024--- a/arch/x86/kernel/verify_cpu.S
21025+++ b/arch/x86/kernel/verify_cpu.S
21026@@ -20,6 +20,7 @@
21027 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
21028 * arch/x86/kernel/trampoline_64.S: secondary processor verification
21029 * arch/x86/kernel/head_32.S: processor startup
21030+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
21031 *
21032 * verify_cpu, returns the status of longmode and SSE in register %eax.
21033 * 0: Success 1: Failure
21034diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
21035index 5c9687b..5f857d3 100644
21036--- a/arch/x86/kernel/vm86_32.c
21037+++ b/arch/x86/kernel/vm86_32.c
21038@@ -43,6 +43,7 @@
21039 #include <linux/ptrace.h>
21040 #include <linux/audit.h>
21041 #include <linux/stddef.h>
21042+#include <linux/grsecurity.h>
21043
21044 #include <asm/uaccess.h>
21045 #include <asm/io.h>
21046@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
21047 do_exit(SIGSEGV);
21048 }
21049
21050- tss = &per_cpu(init_tss, get_cpu());
21051+ tss = init_tss + get_cpu();
21052 current->thread.sp0 = current->thread.saved_sp0;
21053 current->thread.sysenter_cs = __KERNEL_CS;
21054 load_sp0(tss, &current->thread);
21055@@ -212,6 +213,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
21056 struct task_struct *tsk;
21057 int tmp, ret = -EPERM;
21058
21059+#ifdef CONFIG_GRKERNSEC_VM86
21060+ if (!capable(CAP_SYS_RAWIO)) {
21061+ gr_handle_vm86();
21062+ goto out;
21063+ }
21064+#endif
21065+
21066 tsk = current;
21067 if (tsk->thread.saved_sp0)
21068 goto out;
21069@@ -242,6 +250,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
21070 int tmp, ret;
21071 struct vm86plus_struct __user *v86;
21072
21073+#ifdef CONFIG_GRKERNSEC_VM86
21074+ if (!capable(CAP_SYS_RAWIO)) {
21075+ gr_handle_vm86();
21076+ ret = -EPERM;
21077+ goto out;
21078+ }
21079+#endif
21080+
21081 tsk = current;
21082 switch (cmd) {
21083 case VM86_REQUEST_IRQ:
21084@@ -328,7 +344,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
21085 tsk->thread.saved_fs = info->regs32->fs;
21086 tsk->thread.saved_gs = get_user_gs(info->regs32);
21087
21088- tss = &per_cpu(init_tss, get_cpu());
21089+ tss = init_tss + get_cpu();
21090 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
21091 if (cpu_has_sep)
21092 tsk->thread.sysenter_cs = 0;
21093@@ -535,7 +551,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
21094 goto cannot_handle;
21095 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
21096 goto cannot_handle;
21097- intr_ptr = (unsigned long __user *) (i << 2);
21098+ intr_ptr = (__force unsigned long __user *) (i << 2);
21099 if (get_user(segoffs, intr_ptr))
21100 goto cannot_handle;
21101 if ((segoffs >> 16) == BIOSSEG)
21102diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
21103index 22a1530..8fbaaad 100644
21104--- a/arch/x86/kernel/vmlinux.lds.S
21105+++ b/arch/x86/kernel/vmlinux.lds.S
21106@@ -26,6 +26,13 @@
21107 #include <asm/page_types.h>
21108 #include <asm/cache.h>
21109 #include <asm/boot.h>
21110+#include <asm/segment.h>
21111+
21112+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21113+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
21114+#else
21115+#define __KERNEL_TEXT_OFFSET 0
21116+#endif
21117
21118 #undef i386 /* in case the preprocessor is a 32bit one */
21119
21120@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
21121
21122 PHDRS {
21123 text PT_LOAD FLAGS(5); /* R_E */
21124+#ifdef CONFIG_X86_32
21125+ module PT_LOAD FLAGS(5); /* R_E */
21126+#endif
21127+#ifdef CONFIG_XEN
21128+ rodata PT_LOAD FLAGS(5); /* R_E */
21129+#else
21130+ rodata PT_LOAD FLAGS(4); /* R__ */
21131+#endif
21132 data PT_LOAD FLAGS(6); /* RW_ */
21133-#ifdef CONFIG_X86_64
21134+ init.begin PT_LOAD FLAGS(6); /* RW_ */
21135 #ifdef CONFIG_SMP
21136 percpu PT_LOAD FLAGS(6); /* RW_ */
21137 #endif
21138+ text.init PT_LOAD FLAGS(5); /* R_E */
21139+ text.exit PT_LOAD FLAGS(5); /* R_E */
21140 init PT_LOAD FLAGS(7); /* RWE */
21141-#endif
21142 note PT_NOTE FLAGS(0); /* ___ */
21143 }
21144
21145 SECTIONS
21146 {
21147 #ifdef CONFIG_X86_32
21148- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
21149- phys_startup_32 = startup_32 - LOAD_OFFSET;
21150+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
21151 #else
21152- . = __START_KERNEL;
21153- phys_startup_64 = startup_64 - LOAD_OFFSET;
21154+ . = __START_KERNEL;
21155 #endif
21156
21157 /* Text and read-only data */
21158- .text : AT(ADDR(.text) - LOAD_OFFSET) {
21159- _text = .;
21160+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
21161 /* bootstrapping code */
21162+#ifdef CONFIG_X86_32
21163+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
21164+#else
21165+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
21166+#endif
21167+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
21168+ _text = .;
21169 HEAD_TEXT
21170 #ifdef CONFIG_X86_32
21171 . = ALIGN(PAGE_SIZE);
21172@@ -108,13 +128,48 @@ SECTIONS
21173 IRQENTRY_TEXT
21174 *(.fixup)
21175 *(.gnu.warning)
21176- /* End of text section */
21177- _etext = .;
21178 } :text = 0x9090
21179
21180- NOTES :text :note
21181+ . += __KERNEL_TEXT_OFFSET;
21182
21183- EXCEPTION_TABLE(16) :text = 0x9090
21184+#ifdef CONFIG_X86_32
21185+ . = ALIGN(PAGE_SIZE);
21186+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
21187+
21188+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
21189+ MODULES_EXEC_VADDR = .;
21190+ BYTE(0)
21191+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
21192+ . = ALIGN(HPAGE_SIZE) - 1;
21193+ MODULES_EXEC_END = .;
21194+#endif
21195+
21196+ } :module
21197+#endif
21198+
21199+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
21200+ /* End of text section */
21201+ BYTE(0)
21202+ _etext = . - __KERNEL_TEXT_OFFSET;
21203+ }
21204+
21205+#ifdef CONFIG_X86_32
21206+ . = ALIGN(PAGE_SIZE);
21207+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
21208+ *(.idt)
21209+ . = ALIGN(PAGE_SIZE);
21210+ *(.empty_zero_page)
21211+ *(.initial_pg_fixmap)
21212+ *(.initial_pg_pmd)
21213+ *(.initial_page_table)
21214+ *(.swapper_pg_dir)
21215+ } :rodata
21216+#endif
21217+
21218+ . = ALIGN(PAGE_SIZE);
21219+ NOTES :rodata :note
21220+
21221+ EXCEPTION_TABLE(16) :rodata
21222
21223 #if defined(CONFIG_DEBUG_RODATA)
21224 /* .text should occupy whole number of pages */
21225@@ -126,16 +181,20 @@ SECTIONS
21226
21227 /* Data */
21228 .data : AT(ADDR(.data) - LOAD_OFFSET) {
21229+
21230+#ifdef CONFIG_PAX_KERNEXEC
21231+ . = ALIGN(HPAGE_SIZE);
21232+#else
21233+ . = ALIGN(PAGE_SIZE);
21234+#endif
21235+
21236 /* Start of data section */
21237 _sdata = .;
21238
21239 /* init_task */
21240 INIT_TASK_DATA(THREAD_SIZE)
21241
21242-#ifdef CONFIG_X86_32
21243- /* 32 bit has nosave before _edata */
21244 NOSAVE_DATA
21245-#endif
21246
21247 PAGE_ALIGNED_DATA(PAGE_SIZE)
21248
21249@@ -176,12 +235,19 @@ SECTIONS
21250 #endif /* CONFIG_X86_64 */
21251
21252 /* Init code and data - will be freed after init */
21253- . = ALIGN(PAGE_SIZE);
21254 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
21255+ BYTE(0)
21256+
21257+#ifdef CONFIG_PAX_KERNEXEC
21258+ . = ALIGN(HPAGE_SIZE);
21259+#else
21260+ . = ALIGN(PAGE_SIZE);
21261+#endif
21262+
21263 __init_begin = .; /* paired with __init_end */
21264- }
21265+ } :init.begin
21266
21267-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
21268+#ifdef CONFIG_SMP
21269 /*
21270 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
21271 * output PHDR, so the next output section - .init.text - should
21272@@ -190,12 +256,27 @@ SECTIONS
21273 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
21274 #endif
21275
21276- INIT_TEXT_SECTION(PAGE_SIZE)
21277-#ifdef CONFIG_X86_64
21278- :init
21279-#endif
21280+ . = ALIGN(PAGE_SIZE);
21281+ init_begin = .;
21282+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
21283+ VMLINUX_SYMBOL(_sinittext) = .;
21284+ INIT_TEXT
21285+ VMLINUX_SYMBOL(_einittext) = .;
21286+ . = ALIGN(PAGE_SIZE);
21287+ } :text.init
21288
21289- INIT_DATA_SECTION(16)
21290+ /*
21291+ * .exit.text is discard at runtime, not link time, to deal with
21292+ * references from .altinstructions and .eh_frame
21293+ */
21294+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
21295+ EXIT_TEXT
21296+ . = ALIGN(16);
21297+ } :text.exit
21298+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
21299+
21300+ . = ALIGN(PAGE_SIZE);
21301+ INIT_DATA_SECTION(16) :init
21302
21303 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
21304 __x86_cpu_dev_start = .;
21305@@ -257,19 +338,12 @@ SECTIONS
21306 }
21307
21308 . = ALIGN(8);
21309- /*
21310- * .exit.text is discard at runtime, not link time, to deal with
21311- * references from .altinstructions and .eh_frame
21312- */
21313- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
21314- EXIT_TEXT
21315- }
21316
21317 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
21318 EXIT_DATA
21319 }
21320
21321-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
21322+#ifndef CONFIG_SMP
21323 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
21324 #endif
21325
21326@@ -288,16 +362,10 @@ SECTIONS
21327 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
21328 __smp_locks = .;
21329 *(.smp_locks)
21330- . = ALIGN(PAGE_SIZE);
21331 __smp_locks_end = .;
21332+ . = ALIGN(PAGE_SIZE);
21333 }
21334
21335-#ifdef CONFIG_X86_64
21336- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
21337- NOSAVE_DATA
21338- }
21339-#endif
21340-
21341 /* BSS */
21342 . = ALIGN(PAGE_SIZE);
21343 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
21344@@ -313,6 +381,7 @@ SECTIONS
21345 __brk_base = .;
21346 . += 64 * 1024; /* 64k alignment slop space */
21347 *(.brk_reservation) /* areas brk users have reserved */
21348+ . = ALIGN(HPAGE_SIZE);
21349 __brk_limit = .;
21350 }
21351
21352@@ -339,13 +408,12 @@ SECTIONS
21353 * for the boot processor.
21354 */
21355 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
21356-INIT_PER_CPU(gdt_page);
21357 INIT_PER_CPU(irq_stack_union);
21358
21359 /*
21360 * Build-time check on the image size:
21361 */
21362-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
21363+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
21364 "kernel image bigger than KERNEL_IMAGE_SIZE");
21365
21366 #ifdef CONFIG_SMP
21367diff --git a/arch/x86/kernel/vsmp_64.c b/arch/x86/kernel/vsmp_64.c
21368index 992f890..fc38904 100644
21369--- a/arch/x86/kernel/vsmp_64.c
21370+++ b/arch/x86/kernel/vsmp_64.c
21371@@ -217,8 +217,8 @@ static void fill_vector_allocation_domain(int cpu, struct cpumask *retmask,
21372 static void vsmp_apic_post_init(void)
21373 {
21374 /* need to update phys_pkg_id */
21375- apic->phys_pkg_id = apicid_phys_pkg_id;
21376- apic->vector_allocation_domain = fill_vector_allocation_domain;
21377+ *(void **)&apic->phys_pkg_id = apicid_phys_pkg_id;
21378+ *(void **)&apic->vector_allocation_domain = fill_vector_allocation_domain;
21379 }
21380
21381 void __init vsmp_init(void)
21382diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
21383index 3a3e8c9..1af9465 100644
21384--- a/arch/x86/kernel/vsyscall_64.c
21385+++ b/arch/x86/kernel/vsyscall_64.c
21386@@ -56,15 +56,13 @@
21387 DEFINE_VVAR(int, vgetcpu_mode);
21388 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
21389
21390-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
21391+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
21392
21393 static int __init vsyscall_setup(char *str)
21394 {
21395 if (str) {
21396 if (!strcmp("emulate", str))
21397 vsyscall_mode = EMULATE;
21398- else if (!strcmp("native", str))
21399- vsyscall_mode = NATIVE;
21400 else if (!strcmp("none", str))
21401 vsyscall_mode = NONE;
21402 else
21403@@ -315,8 +313,7 @@ done:
21404 return true;
21405
21406 sigsegv:
21407- force_sig(SIGSEGV, current);
21408- return true;
21409+ do_group_exit(SIGKILL);
21410 }
21411
21412 /*
21413@@ -369,10 +366,7 @@ void __init map_vsyscall(void)
21414 extern char __vvar_page;
21415 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
21416
21417- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
21418- vsyscall_mode == NATIVE
21419- ? PAGE_KERNEL_VSYSCALL
21420- : PAGE_KERNEL_VVAR);
21421+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
21422 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
21423 (unsigned long)VSYSCALL_START);
21424
21425diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
21426index 1330dd1..d220b99 100644
21427--- a/arch/x86/kernel/x8664_ksyms_64.c
21428+++ b/arch/x86/kernel/x8664_ksyms_64.c
21429@@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
21430 EXPORT_SYMBOL(copy_user_generic_unrolled);
21431 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
21432 EXPORT_SYMBOL(__copy_user_nocache);
21433-EXPORT_SYMBOL(_copy_from_user);
21434-EXPORT_SYMBOL(_copy_to_user);
21435
21436 EXPORT_SYMBOL(copy_page);
21437 EXPORT_SYMBOL(clear_page);
21438diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
21439index ada87a3..afea76d 100644
21440--- a/arch/x86/kernel/xsave.c
21441+++ b/arch/x86/kernel/xsave.c
21442@@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
21443 {
21444 int err;
21445
21446+ buf = (struct xsave_struct __user *)____m(buf);
21447 if (use_xsave())
21448 err = xsave_user(buf);
21449 else if (use_fxsr())
21450@@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
21451 */
21452 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
21453 {
21454+ buf = (void __user *)____m(buf);
21455 if (use_xsave()) {
21456 if ((unsigned long)buf % 64 || fx_only) {
21457 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
21458diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
21459index ec79e77..420f5cc 100644
21460--- a/arch/x86/kvm/cpuid.c
21461+++ b/arch/x86/kvm/cpuid.c
21462@@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
21463 struct kvm_cpuid2 *cpuid,
21464 struct kvm_cpuid_entry2 __user *entries)
21465 {
21466- int r;
21467+ int r, i;
21468
21469 r = -E2BIG;
21470 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
21471 goto out;
21472 r = -EFAULT;
21473- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
21474- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
21475+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
21476 goto out;
21477+ for (i = 0; i < cpuid->nent; ++i) {
21478+ struct kvm_cpuid_entry2 cpuid_entry;
21479+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
21480+ goto out;
21481+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
21482+ }
21483 vcpu->arch.cpuid_nent = cpuid->nent;
21484 kvm_apic_set_version(vcpu);
21485 kvm_x86_ops->cpuid_update(vcpu);
21486@@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
21487 struct kvm_cpuid2 *cpuid,
21488 struct kvm_cpuid_entry2 __user *entries)
21489 {
21490- int r;
21491+ int r, i;
21492
21493 r = -E2BIG;
21494 if (cpuid->nent < vcpu->arch.cpuid_nent)
21495 goto out;
21496 r = -EFAULT;
21497- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
21498- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
21499+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
21500 goto out;
21501+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
21502+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
21503+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
21504+ goto out;
21505+ }
21506 return 0;
21507
21508 out:
21509diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
21510index bba39bf..296540a 100644
21511--- a/arch/x86/kvm/emulate.c
21512+++ b/arch/x86/kvm/emulate.c
21513@@ -292,6 +292,7 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
21514
21515 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
21516 do { \
21517+ unsigned long _tmp; \
21518 __asm__ __volatile__ ( \
21519 _PRE_EFLAGS("0", "4", "2") \
21520 _op _suffix " %"_x"3,%1; " \
21521@@ -306,8 +307,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
21522 /* Raw emulation: instruction has two explicit operands. */
21523 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
21524 do { \
21525- unsigned long _tmp; \
21526- \
21527 switch ((ctxt)->dst.bytes) { \
21528 case 2: \
21529 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
21530@@ -323,7 +322,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
21531
21532 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
21533 do { \
21534- unsigned long _tmp; \
21535 switch ((ctxt)->dst.bytes) { \
21536 case 1: \
21537 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
21538diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
21539index 43e9fad..3b7c059 100644
21540--- a/arch/x86/kvm/lapic.c
21541+++ b/arch/x86/kvm/lapic.c
21542@@ -55,7 +55,7 @@
21543 #define APIC_BUS_CYCLE_NS 1
21544
21545 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
21546-#define apic_debug(fmt, arg...)
21547+#define apic_debug(fmt, arg...) do {} while (0)
21548
21549 #define APIC_LVT_NUM 6
21550 /* 14 is the version for Xeon and Pentium 8.4.8*/
21551diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
21552index 714e2c0..3f7a086 100644
21553--- a/arch/x86/kvm/paging_tmpl.h
21554+++ b/arch/x86/kvm/paging_tmpl.h
21555@@ -208,7 +208,7 @@ retry_walk:
21556 if (unlikely(kvm_is_error_hva(host_addr)))
21557 goto error;
21558
21559- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
21560+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
21561 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
21562 goto error;
21563 walker->ptep_user[walker->level - 1] = ptep_user;
21564diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
21565index d017df3..61ae42e 100644
21566--- a/arch/x86/kvm/svm.c
21567+++ b/arch/x86/kvm/svm.c
21568@@ -3500,7 +3500,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
21569 int cpu = raw_smp_processor_id();
21570
21571 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
21572+
21573+ pax_open_kernel();
21574 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
21575+ pax_close_kernel();
21576+
21577 load_TR_desc();
21578 }
21579
21580@@ -3874,6 +3878,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
21581 #endif
21582 #endif
21583
21584+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
21585+ __set_fs(current_thread_info()->addr_limit);
21586+#endif
21587+
21588 reload_tss(vcpu);
21589
21590 local_irq_disable();
21591diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
21592index f858159..4ab7dba 100644
21593--- a/arch/x86/kvm/vmx.c
21594+++ b/arch/x86/kvm/vmx.c
21595@@ -1332,7 +1332,11 @@ static void reload_tss(void)
21596 struct desc_struct *descs;
21597
21598 descs = (void *)gdt->address;
21599+
21600+ pax_open_kernel();
21601 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
21602+ pax_close_kernel();
21603+
21604 load_TR_desc();
21605 }
21606
21607@@ -1546,6 +1550,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
21608 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
21609 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
21610
21611+#ifdef CONFIG_PAX_PER_CPU_PGD
21612+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
21613+#endif
21614+
21615 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
21616 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
21617 vmx->loaded_vmcs->cpu = cpu;
21618@@ -2669,8 +2677,11 @@ static __init int hardware_setup(void)
21619 if (!cpu_has_vmx_flexpriority())
21620 flexpriority_enabled = 0;
21621
21622- if (!cpu_has_vmx_tpr_shadow())
21623- kvm_x86_ops->update_cr8_intercept = NULL;
21624+ if (!cpu_has_vmx_tpr_shadow()) {
21625+ pax_open_kernel();
21626+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
21627+ pax_close_kernel();
21628+ }
21629
21630 if (enable_ept && !cpu_has_vmx_ept_2m_page())
21631 kvm_disable_largepages();
21632@@ -3712,7 +3723,10 @@ static void vmx_set_constant_host_state(void)
21633
21634 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
21635 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
21636+
21637+#ifndef CONFIG_PAX_PER_CPU_PGD
21638 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
21639+#endif
21640
21641 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
21642 #ifdef CONFIG_X86_64
21643@@ -3733,7 +3747,7 @@ static void vmx_set_constant_host_state(void)
21644 native_store_idt(&dt);
21645 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
21646
21647- vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
21648+ vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
21649
21650 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
21651 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
21652@@ -6279,6 +6293,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
21653 "jmp 2f \n\t"
21654 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
21655 "2: "
21656+
21657+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21658+ "ljmp %[cs],$3f\n\t"
21659+ "3: "
21660+#endif
21661+
21662 /* Save guest registers, load host registers, keep flags */
21663 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
21664 "pop %0 \n\t"
21665@@ -6331,6 +6351,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
21666 #endif
21667 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
21668 [wordsize]"i"(sizeof(ulong))
21669+
21670+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21671+ ,[cs]"i"(__KERNEL_CS)
21672+#endif
21673+
21674 : "cc", "memory"
21675 #ifdef CONFIG_X86_64
21676 , "rax", "rbx", "rdi", "rsi"
21677@@ -6344,7 +6369,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
21678 if (debugctlmsr)
21679 update_debugctlmsr(debugctlmsr);
21680
21681-#ifndef CONFIG_X86_64
21682+#ifdef CONFIG_X86_32
21683 /*
21684 * The sysexit path does not restore ds/es, so we must set them to
21685 * a reasonable value ourselves.
21686@@ -6353,8 +6378,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
21687 * may be executed in interrupt context, which saves and restore segments
21688 * around it, nullifying its effect.
21689 */
21690- loadsegment(ds, __USER_DS);
21691- loadsegment(es, __USER_DS);
21692+ loadsegment(ds, __KERNEL_DS);
21693+ loadsegment(es, __KERNEL_DS);
21694+ loadsegment(ss, __KERNEL_DS);
21695+
21696+#ifdef CONFIG_PAX_KERNEXEC
21697+ loadsegment(fs, __KERNEL_PERCPU);
21698+#endif
21699+
21700+#ifdef CONFIG_PAX_MEMORY_UDEREF
21701+ __set_fs(current_thread_info()->addr_limit);
21702+#endif
21703+
21704 #endif
21705
21706 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
21707diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
21708index 4f76417..93429b5 100644
21709--- a/arch/x86/kvm/x86.c
21710+++ b/arch/x86/kvm/x86.c
21711@@ -1390,8 +1390,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
21712 {
21713 struct kvm *kvm = vcpu->kvm;
21714 int lm = is_long_mode(vcpu);
21715- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
21716- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
21717+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
21718+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
21719 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
21720 : kvm->arch.xen_hvm_config.blob_size_32;
21721 u32 page_num = data & ~PAGE_MASK;
21722@@ -2255,6 +2255,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
21723 if (n < msr_list.nmsrs)
21724 goto out;
21725 r = -EFAULT;
21726+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
21727+ goto out;
21728 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
21729 num_msrs_to_save * sizeof(u32)))
21730 goto out;
21731@@ -2379,7 +2381,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
21732 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
21733 struct kvm_interrupt *irq)
21734 {
21735- if (irq->irq < 0 || irq->irq >= KVM_NR_INTERRUPTS)
21736+ if (irq->irq >= KVM_NR_INTERRUPTS)
21737 return -EINVAL;
21738 if (irqchip_in_kernel(vcpu->kvm))
21739 return -ENXIO;
21740@@ -4881,7 +4883,7 @@ static void kvm_set_mmio_spte_mask(void)
21741 kvm_mmu_set_mmio_spte_mask(mask);
21742 }
21743
21744-int kvm_arch_init(void *opaque)
21745+int kvm_arch_init(const void *opaque)
21746 {
21747 int r;
21748 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
21749diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
21750index 642d880..cc9ebac 100644
21751--- a/arch/x86/lguest/boot.c
21752+++ b/arch/x86/lguest/boot.c
21753@@ -1116,12 +1116,12 @@ static u32 lguest_apic_safe_wait_icr_idle(void)
21754
21755 static void set_lguest_basic_apic_ops(void)
21756 {
21757- apic->read = lguest_apic_read;
21758- apic->write = lguest_apic_write;
21759- apic->icr_read = lguest_apic_icr_read;
21760- apic->icr_write = lguest_apic_icr_write;
21761- apic->wait_icr_idle = lguest_apic_wait_icr_idle;
21762- apic->safe_wait_icr_idle = lguest_apic_safe_wait_icr_idle;
21763+ *(void **)&apic->read = lguest_apic_read;
21764+ *(void **)&apic->write = lguest_apic_write;
21765+ *(void **)&apic->icr_read = lguest_apic_icr_read;
21766+ *(void **)&apic->icr_write = lguest_apic_icr_write;
21767+ *(void **)&apic->wait_icr_idle = lguest_apic_wait_icr_idle;
21768+ *(void **)&apic->safe_wait_icr_idle = lguest_apic_safe_wait_icr_idle;
21769 };
21770 #endif
21771
21772@@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
21773 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
21774 * Launcher to reboot us.
21775 */
21776-static void lguest_restart(char *reason)
21777+static __noreturn void lguest_restart(char *reason)
21778 {
21779 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
21780+ BUG();
21781 }
21782
21783 /*G:050
21784diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
21785index 00933d5..3a64af9 100644
21786--- a/arch/x86/lib/atomic64_386_32.S
21787+++ b/arch/x86/lib/atomic64_386_32.S
21788@@ -48,6 +48,10 @@ BEGIN(read)
21789 movl (v), %eax
21790 movl 4(v), %edx
21791 RET_ENDP
21792+BEGIN(read_unchecked)
21793+ movl (v), %eax
21794+ movl 4(v), %edx
21795+RET_ENDP
21796 #undef v
21797
21798 #define v %esi
21799@@ -55,6 +59,10 @@ BEGIN(set)
21800 movl %ebx, (v)
21801 movl %ecx, 4(v)
21802 RET_ENDP
21803+BEGIN(set_unchecked)
21804+ movl %ebx, (v)
21805+ movl %ecx, 4(v)
21806+RET_ENDP
21807 #undef v
21808
21809 #define v %esi
21810@@ -70,6 +78,20 @@ RET_ENDP
21811 BEGIN(add)
21812 addl %eax, (v)
21813 adcl %edx, 4(v)
21814+
21815+#ifdef CONFIG_PAX_REFCOUNT
21816+ jno 0f
21817+ subl %eax, (v)
21818+ sbbl %edx, 4(v)
21819+ int $4
21820+0:
21821+ _ASM_EXTABLE(0b, 0b)
21822+#endif
21823+
21824+RET_ENDP
21825+BEGIN(add_unchecked)
21826+ addl %eax, (v)
21827+ adcl %edx, 4(v)
21828 RET_ENDP
21829 #undef v
21830
21831@@ -77,6 +99,24 @@ RET_ENDP
21832 BEGIN(add_return)
21833 addl (v), %eax
21834 adcl 4(v), %edx
21835+
21836+#ifdef CONFIG_PAX_REFCOUNT
21837+ into
21838+1234:
21839+ _ASM_EXTABLE(1234b, 2f)
21840+#endif
21841+
21842+ movl %eax, (v)
21843+ movl %edx, 4(v)
21844+
21845+#ifdef CONFIG_PAX_REFCOUNT
21846+2:
21847+#endif
21848+
21849+RET_ENDP
21850+BEGIN(add_return_unchecked)
21851+ addl (v), %eax
21852+ adcl 4(v), %edx
21853 movl %eax, (v)
21854 movl %edx, 4(v)
21855 RET_ENDP
21856@@ -86,6 +126,20 @@ RET_ENDP
21857 BEGIN(sub)
21858 subl %eax, (v)
21859 sbbl %edx, 4(v)
21860+
21861+#ifdef CONFIG_PAX_REFCOUNT
21862+ jno 0f
21863+ addl %eax, (v)
21864+ adcl %edx, 4(v)
21865+ int $4
21866+0:
21867+ _ASM_EXTABLE(0b, 0b)
21868+#endif
21869+
21870+RET_ENDP
21871+BEGIN(sub_unchecked)
21872+ subl %eax, (v)
21873+ sbbl %edx, 4(v)
21874 RET_ENDP
21875 #undef v
21876
21877@@ -96,6 +150,27 @@ BEGIN(sub_return)
21878 sbbl $0, %edx
21879 addl (v), %eax
21880 adcl 4(v), %edx
21881+
21882+#ifdef CONFIG_PAX_REFCOUNT
21883+ into
21884+1234:
21885+ _ASM_EXTABLE(1234b, 2f)
21886+#endif
21887+
21888+ movl %eax, (v)
21889+ movl %edx, 4(v)
21890+
21891+#ifdef CONFIG_PAX_REFCOUNT
21892+2:
21893+#endif
21894+
21895+RET_ENDP
21896+BEGIN(sub_return_unchecked)
21897+ negl %edx
21898+ negl %eax
21899+ sbbl $0, %edx
21900+ addl (v), %eax
21901+ adcl 4(v), %edx
21902 movl %eax, (v)
21903 movl %edx, 4(v)
21904 RET_ENDP
21905@@ -105,6 +180,20 @@ RET_ENDP
21906 BEGIN(inc)
21907 addl $1, (v)
21908 adcl $0, 4(v)
21909+
21910+#ifdef CONFIG_PAX_REFCOUNT
21911+ jno 0f
21912+ subl $1, (v)
21913+ sbbl $0, 4(v)
21914+ int $4
21915+0:
21916+ _ASM_EXTABLE(0b, 0b)
21917+#endif
21918+
21919+RET_ENDP
21920+BEGIN(inc_unchecked)
21921+ addl $1, (v)
21922+ adcl $0, 4(v)
21923 RET_ENDP
21924 #undef v
21925
21926@@ -114,6 +203,26 @@ BEGIN(inc_return)
21927 movl 4(v), %edx
21928 addl $1, %eax
21929 adcl $0, %edx
21930+
21931+#ifdef CONFIG_PAX_REFCOUNT
21932+ into
21933+1234:
21934+ _ASM_EXTABLE(1234b, 2f)
21935+#endif
21936+
21937+ movl %eax, (v)
21938+ movl %edx, 4(v)
21939+
21940+#ifdef CONFIG_PAX_REFCOUNT
21941+2:
21942+#endif
21943+
21944+RET_ENDP
21945+BEGIN(inc_return_unchecked)
21946+ movl (v), %eax
21947+ movl 4(v), %edx
21948+ addl $1, %eax
21949+ adcl $0, %edx
21950 movl %eax, (v)
21951 movl %edx, 4(v)
21952 RET_ENDP
21953@@ -123,6 +232,20 @@ RET_ENDP
21954 BEGIN(dec)
21955 subl $1, (v)
21956 sbbl $0, 4(v)
21957+
21958+#ifdef CONFIG_PAX_REFCOUNT
21959+ jno 0f
21960+ addl $1, (v)
21961+ adcl $0, 4(v)
21962+ int $4
21963+0:
21964+ _ASM_EXTABLE(0b, 0b)
21965+#endif
21966+
21967+RET_ENDP
21968+BEGIN(dec_unchecked)
21969+ subl $1, (v)
21970+ sbbl $0, 4(v)
21971 RET_ENDP
21972 #undef v
21973
21974@@ -132,6 +255,26 @@ BEGIN(dec_return)
21975 movl 4(v), %edx
21976 subl $1, %eax
21977 sbbl $0, %edx
21978+
21979+#ifdef CONFIG_PAX_REFCOUNT
21980+ into
21981+1234:
21982+ _ASM_EXTABLE(1234b, 2f)
21983+#endif
21984+
21985+ movl %eax, (v)
21986+ movl %edx, 4(v)
21987+
21988+#ifdef CONFIG_PAX_REFCOUNT
21989+2:
21990+#endif
21991+
21992+RET_ENDP
21993+BEGIN(dec_return_unchecked)
21994+ movl (v), %eax
21995+ movl 4(v), %edx
21996+ subl $1, %eax
21997+ sbbl $0, %edx
21998 movl %eax, (v)
21999 movl %edx, 4(v)
22000 RET_ENDP
22001@@ -143,6 +286,13 @@ BEGIN(add_unless)
22002 adcl %edx, %edi
22003 addl (v), %eax
22004 adcl 4(v), %edx
22005+
22006+#ifdef CONFIG_PAX_REFCOUNT
22007+ into
22008+1234:
22009+ _ASM_EXTABLE(1234b, 2f)
22010+#endif
22011+
22012 cmpl %eax, %ecx
22013 je 3f
22014 1:
22015@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
22016 1:
22017 addl $1, %eax
22018 adcl $0, %edx
22019+
22020+#ifdef CONFIG_PAX_REFCOUNT
22021+ into
22022+1234:
22023+ _ASM_EXTABLE(1234b, 2f)
22024+#endif
22025+
22026 movl %eax, (v)
22027 movl %edx, 4(v)
22028 movl $1, %eax
22029@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
22030 movl 4(v), %edx
22031 subl $1, %eax
22032 sbbl $0, %edx
22033+
22034+#ifdef CONFIG_PAX_REFCOUNT
22035+ into
22036+1234:
22037+ _ASM_EXTABLE(1234b, 1f)
22038+#endif
22039+
22040 js 1f
22041 movl %eax, (v)
22042 movl %edx, 4(v)
22043diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
22044index f5cc9eb..51fa319 100644
22045--- a/arch/x86/lib/atomic64_cx8_32.S
22046+++ b/arch/x86/lib/atomic64_cx8_32.S
22047@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
22048 CFI_STARTPROC
22049
22050 read64 %ecx
22051+ pax_force_retaddr
22052 ret
22053 CFI_ENDPROC
22054 ENDPROC(atomic64_read_cx8)
22055
22056+ENTRY(atomic64_read_unchecked_cx8)
22057+ CFI_STARTPROC
22058+
22059+ read64 %ecx
22060+ pax_force_retaddr
22061+ ret
22062+ CFI_ENDPROC
22063+ENDPROC(atomic64_read_unchecked_cx8)
22064+
22065 ENTRY(atomic64_set_cx8)
22066 CFI_STARTPROC
22067
22068@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
22069 cmpxchg8b (%esi)
22070 jne 1b
22071
22072+ pax_force_retaddr
22073 ret
22074 CFI_ENDPROC
22075 ENDPROC(atomic64_set_cx8)
22076
22077+ENTRY(atomic64_set_unchecked_cx8)
22078+ CFI_STARTPROC
22079+
22080+1:
22081+/* we don't need LOCK_PREFIX since aligned 64-bit writes
22082+ * are atomic on 586 and newer */
22083+ cmpxchg8b (%esi)
22084+ jne 1b
22085+
22086+ pax_force_retaddr
22087+ ret
22088+ CFI_ENDPROC
22089+ENDPROC(atomic64_set_unchecked_cx8)
22090+
22091 ENTRY(atomic64_xchg_cx8)
22092 CFI_STARTPROC
22093
22094@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
22095 cmpxchg8b (%esi)
22096 jne 1b
22097
22098+ pax_force_retaddr
22099 ret
22100 CFI_ENDPROC
22101 ENDPROC(atomic64_xchg_cx8)
22102
22103-.macro addsub_return func ins insc
22104-ENTRY(atomic64_\func\()_return_cx8)
22105+.macro addsub_return func ins insc unchecked=""
22106+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
22107 CFI_STARTPROC
22108 SAVE ebp
22109 SAVE ebx
22110@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
22111 movl %edx, %ecx
22112 \ins\()l %esi, %ebx
22113 \insc\()l %edi, %ecx
22114+
22115+.ifb \unchecked
22116+#ifdef CONFIG_PAX_REFCOUNT
22117+ into
22118+2:
22119+ _ASM_EXTABLE(2b, 3f)
22120+#endif
22121+.endif
22122+
22123 LOCK_PREFIX
22124 cmpxchg8b (%ebp)
22125 jne 1b
22126-
22127-10:
22128 movl %ebx, %eax
22129 movl %ecx, %edx
22130+
22131+.ifb \unchecked
22132+#ifdef CONFIG_PAX_REFCOUNT
22133+3:
22134+#endif
22135+.endif
22136+
22137 RESTORE edi
22138 RESTORE esi
22139 RESTORE ebx
22140 RESTORE ebp
22141+ pax_force_retaddr
22142 ret
22143 CFI_ENDPROC
22144-ENDPROC(atomic64_\func\()_return_cx8)
22145+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
22146 .endm
22147
22148 addsub_return add add adc
22149 addsub_return sub sub sbb
22150+addsub_return add add adc _unchecked
22151+addsub_return sub sub sbb _unchecked
22152
22153-.macro incdec_return func ins insc
22154-ENTRY(atomic64_\func\()_return_cx8)
22155+.macro incdec_return func ins insc unchecked=""
22156+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
22157 CFI_STARTPROC
22158 SAVE ebx
22159
22160@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
22161 movl %edx, %ecx
22162 \ins\()l $1, %ebx
22163 \insc\()l $0, %ecx
22164+
22165+.ifb \unchecked
22166+#ifdef CONFIG_PAX_REFCOUNT
22167+ into
22168+2:
22169+ _ASM_EXTABLE(2b, 3f)
22170+#endif
22171+.endif
22172+
22173 LOCK_PREFIX
22174 cmpxchg8b (%esi)
22175 jne 1b
22176
22177-10:
22178 movl %ebx, %eax
22179 movl %ecx, %edx
22180+
22181+.ifb \unchecked
22182+#ifdef CONFIG_PAX_REFCOUNT
22183+3:
22184+#endif
22185+.endif
22186+
22187 RESTORE ebx
22188+ pax_force_retaddr
22189 ret
22190 CFI_ENDPROC
22191-ENDPROC(atomic64_\func\()_return_cx8)
22192+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
22193 .endm
22194
22195 incdec_return inc add adc
22196 incdec_return dec sub sbb
22197+incdec_return inc add adc _unchecked
22198+incdec_return dec sub sbb _unchecked
22199
22200 ENTRY(atomic64_dec_if_positive_cx8)
22201 CFI_STARTPROC
22202@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
22203 movl %edx, %ecx
22204 subl $1, %ebx
22205 sbb $0, %ecx
22206+
22207+#ifdef CONFIG_PAX_REFCOUNT
22208+ into
22209+1234:
22210+ _ASM_EXTABLE(1234b, 2f)
22211+#endif
22212+
22213 js 2f
22214 LOCK_PREFIX
22215 cmpxchg8b (%esi)
22216@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
22217 movl %ebx, %eax
22218 movl %ecx, %edx
22219 RESTORE ebx
22220+ pax_force_retaddr
22221 ret
22222 CFI_ENDPROC
22223 ENDPROC(atomic64_dec_if_positive_cx8)
22224@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
22225 movl %edx, %ecx
22226 addl %ebp, %ebx
22227 adcl %edi, %ecx
22228+
22229+#ifdef CONFIG_PAX_REFCOUNT
22230+ into
22231+1234:
22232+ _ASM_EXTABLE(1234b, 3f)
22233+#endif
22234+
22235 LOCK_PREFIX
22236 cmpxchg8b (%esi)
22237 jne 1b
22238@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
22239 CFI_ADJUST_CFA_OFFSET -8
22240 RESTORE ebx
22241 RESTORE ebp
22242+ pax_force_retaddr
22243 ret
22244 4:
22245 cmpl %edx, 4(%esp)
22246@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
22247 xorl %ecx, %ecx
22248 addl $1, %ebx
22249 adcl %edx, %ecx
22250+
22251+#ifdef CONFIG_PAX_REFCOUNT
22252+ into
22253+1234:
22254+ _ASM_EXTABLE(1234b, 3f)
22255+#endif
22256+
22257 LOCK_PREFIX
22258 cmpxchg8b (%esi)
22259 jne 1b
22260@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
22261 movl $1, %eax
22262 3:
22263 RESTORE ebx
22264+ pax_force_retaddr
22265 ret
22266 CFI_ENDPROC
22267 ENDPROC(atomic64_inc_not_zero_cx8)
22268diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
22269index 2af5df3..62b1a5a 100644
22270--- a/arch/x86/lib/checksum_32.S
22271+++ b/arch/x86/lib/checksum_32.S
22272@@ -29,7 +29,8 @@
22273 #include <asm/dwarf2.h>
22274 #include <asm/errno.h>
22275 #include <asm/asm.h>
22276-
22277+#include <asm/segment.h>
22278+
22279 /*
22280 * computes a partial checksum, e.g. for TCP/UDP fragments
22281 */
22282@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
22283
22284 #define ARGBASE 16
22285 #define FP 12
22286-
22287-ENTRY(csum_partial_copy_generic)
22288+
22289+ENTRY(csum_partial_copy_generic_to_user)
22290 CFI_STARTPROC
22291+
22292+#ifdef CONFIG_PAX_MEMORY_UDEREF
22293+ pushl_cfi %gs
22294+ popl_cfi %es
22295+ jmp csum_partial_copy_generic
22296+#endif
22297+
22298+ENTRY(csum_partial_copy_generic_from_user)
22299+
22300+#ifdef CONFIG_PAX_MEMORY_UDEREF
22301+ pushl_cfi %gs
22302+ popl_cfi %ds
22303+#endif
22304+
22305+ENTRY(csum_partial_copy_generic)
22306 subl $4,%esp
22307 CFI_ADJUST_CFA_OFFSET 4
22308 pushl_cfi %edi
22309@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
22310 jmp 4f
22311 SRC(1: movw (%esi), %bx )
22312 addl $2, %esi
22313-DST( movw %bx, (%edi) )
22314+DST( movw %bx, %es:(%edi) )
22315 addl $2, %edi
22316 addw %bx, %ax
22317 adcl $0, %eax
22318@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
22319 SRC(1: movl (%esi), %ebx )
22320 SRC( movl 4(%esi), %edx )
22321 adcl %ebx, %eax
22322-DST( movl %ebx, (%edi) )
22323+DST( movl %ebx, %es:(%edi) )
22324 adcl %edx, %eax
22325-DST( movl %edx, 4(%edi) )
22326+DST( movl %edx, %es:4(%edi) )
22327
22328 SRC( movl 8(%esi), %ebx )
22329 SRC( movl 12(%esi), %edx )
22330 adcl %ebx, %eax
22331-DST( movl %ebx, 8(%edi) )
22332+DST( movl %ebx, %es:8(%edi) )
22333 adcl %edx, %eax
22334-DST( movl %edx, 12(%edi) )
22335+DST( movl %edx, %es:12(%edi) )
22336
22337 SRC( movl 16(%esi), %ebx )
22338 SRC( movl 20(%esi), %edx )
22339 adcl %ebx, %eax
22340-DST( movl %ebx, 16(%edi) )
22341+DST( movl %ebx, %es:16(%edi) )
22342 adcl %edx, %eax
22343-DST( movl %edx, 20(%edi) )
22344+DST( movl %edx, %es:20(%edi) )
22345
22346 SRC( movl 24(%esi), %ebx )
22347 SRC( movl 28(%esi), %edx )
22348 adcl %ebx, %eax
22349-DST( movl %ebx, 24(%edi) )
22350+DST( movl %ebx, %es:24(%edi) )
22351 adcl %edx, %eax
22352-DST( movl %edx, 28(%edi) )
22353+DST( movl %edx, %es:28(%edi) )
22354
22355 lea 32(%esi), %esi
22356 lea 32(%edi), %edi
22357@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
22358 shrl $2, %edx # This clears CF
22359 SRC(3: movl (%esi), %ebx )
22360 adcl %ebx, %eax
22361-DST( movl %ebx, (%edi) )
22362+DST( movl %ebx, %es:(%edi) )
22363 lea 4(%esi), %esi
22364 lea 4(%edi), %edi
22365 dec %edx
22366@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
22367 jb 5f
22368 SRC( movw (%esi), %cx )
22369 leal 2(%esi), %esi
22370-DST( movw %cx, (%edi) )
22371+DST( movw %cx, %es:(%edi) )
22372 leal 2(%edi), %edi
22373 je 6f
22374 shll $16,%ecx
22375 SRC(5: movb (%esi), %cl )
22376-DST( movb %cl, (%edi) )
22377+DST( movb %cl, %es:(%edi) )
22378 6: addl %ecx, %eax
22379 adcl $0, %eax
22380 7:
22381@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
22382
22383 6001:
22384 movl ARGBASE+20(%esp), %ebx # src_err_ptr
22385- movl $-EFAULT, (%ebx)
22386+ movl $-EFAULT, %ss:(%ebx)
22387
22388 # zero the complete destination - computing the rest
22389 # is too much work
22390@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
22391
22392 6002:
22393 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
22394- movl $-EFAULT,(%ebx)
22395+ movl $-EFAULT,%ss:(%ebx)
22396 jmp 5000b
22397
22398 .previous
22399
22400+ pushl_cfi %ss
22401+ popl_cfi %ds
22402+ pushl_cfi %ss
22403+ popl_cfi %es
22404 popl_cfi %ebx
22405 CFI_RESTORE ebx
22406 popl_cfi %esi
22407@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
22408 popl_cfi %ecx # equivalent to addl $4,%esp
22409 ret
22410 CFI_ENDPROC
22411-ENDPROC(csum_partial_copy_generic)
22412+ENDPROC(csum_partial_copy_generic_to_user)
22413
22414 #else
22415
22416 /* Version for PentiumII/PPro */
22417
22418 #define ROUND1(x) \
22419+ nop; nop; nop; \
22420 SRC(movl x(%esi), %ebx ) ; \
22421 addl %ebx, %eax ; \
22422- DST(movl %ebx, x(%edi) ) ;
22423+ DST(movl %ebx, %es:x(%edi)) ;
22424
22425 #define ROUND(x) \
22426+ nop; nop; nop; \
22427 SRC(movl x(%esi), %ebx ) ; \
22428 adcl %ebx, %eax ; \
22429- DST(movl %ebx, x(%edi) ) ;
22430+ DST(movl %ebx, %es:x(%edi)) ;
22431
22432 #define ARGBASE 12
22433-
22434-ENTRY(csum_partial_copy_generic)
22435+
22436+ENTRY(csum_partial_copy_generic_to_user)
22437 CFI_STARTPROC
22438+
22439+#ifdef CONFIG_PAX_MEMORY_UDEREF
22440+ pushl_cfi %gs
22441+ popl_cfi %es
22442+ jmp csum_partial_copy_generic
22443+#endif
22444+
22445+ENTRY(csum_partial_copy_generic_from_user)
22446+
22447+#ifdef CONFIG_PAX_MEMORY_UDEREF
22448+ pushl_cfi %gs
22449+ popl_cfi %ds
22450+#endif
22451+
22452+ENTRY(csum_partial_copy_generic)
22453 pushl_cfi %ebx
22454 CFI_REL_OFFSET ebx, 0
22455 pushl_cfi %edi
22456@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
22457 subl %ebx, %edi
22458 lea -1(%esi),%edx
22459 andl $-32,%edx
22460- lea 3f(%ebx,%ebx), %ebx
22461+ lea 3f(%ebx,%ebx,2), %ebx
22462 testl %esi, %esi
22463 jmp *%ebx
22464 1: addl $64,%esi
22465@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
22466 jb 5f
22467 SRC( movw (%esi), %dx )
22468 leal 2(%esi), %esi
22469-DST( movw %dx, (%edi) )
22470+DST( movw %dx, %es:(%edi) )
22471 leal 2(%edi), %edi
22472 je 6f
22473 shll $16,%edx
22474 5:
22475 SRC( movb (%esi), %dl )
22476-DST( movb %dl, (%edi) )
22477+DST( movb %dl, %es:(%edi) )
22478 6: addl %edx, %eax
22479 adcl $0, %eax
22480 7:
22481 .section .fixup, "ax"
22482 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
22483- movl $-EFAULT, (%ebx)
22484+ movl $-EFAULT, %ss:(%ebx)
22485 # zero the complete destination (computing the rest is too much work)
22486 movl ARGBASE+8(%esp),%edi # dst
22487 movl ARGBASE+12(%esp),%ecx # len
22488@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
22489 rep; stosb
22490 jmp 7b
22491 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
22492- movl $-EFAULT, (%ebx)
22493+ movl $-EFAULT, %ss:(%ebx)
22494 jmp 7b
22495 .previous
22496
22497+#ifdef CONFIG_PAX_MEMORY_UDEREF
22498+ pushl_cfi %ss
22499+ popl_cfi %ds
22500+ pushl_cfi %ss
22501+ popl_cfi %es
22502+#endif
22503+
22504 popl_cfi %esi
22505 CFI_RESTORE esi
22506 popl_cfi %edi
22507@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
22508 CFI_RESTORE ebx
22509 ret
22510 CFI_ENDPROC
22511-ENDPROC(csum_partial_copy_generic)
22512+ENDPROC(csum_partial_copy_generic_to_user)
22513
22514 #undef ROUND
22515 #undef ROUND1
22516diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
22517index f2145cf..cea889d 100644
22518--- a/arch/x86/lib/clear_page_64.S
22519+++ b/arch/x86/lib/clear_page_64.S
22520@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
22521 movl $4096/8,%ecx
22522 xorl %eax,%eax
22523 rep stosq
22524+ pax_force_retaddr
22525 ret
22526 CFI_ENDPROC
22527 ENDPROC(clear_page_c)
22528@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
22529 movl $4096,%ecx
22530 xorl %eax,%eax
22531 rep stosb
22532+ pax_force_retaddr
22533 ret
22534 CFI_ENDPROC
22535 ENDPROC(clear_page_c_e)
22536@@ -43,6 +45,7 @@ ENTRY(clear_page)
22537 leaq 64(%rdi),%rdi
22538 jnz .Lloop
22539 nop
22540+ pax_force_retaddr
22541 ret
22542 CFI_ENDPROC
22543 .Lclear_page_end:
22544@@ -58,7 +61,7 @@ ENDPROC(clear_page)
22545
22546 #include <asm/cpufeature.h>
22547
22548- .section .altinstr_replacement,"ax"
22549+ .section .altinstr_replacement,"a"
22550 1: .byte 0xeb /* jmp <disp8> */
22551 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
22552 2: .byte 0xeb /* jmp <disp8> */
22553diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
22554index 1e572c5..2a162cd 100644
22555--- a/arch/x86/lib/cmpxchg16b_emu.S
22556+++ b/arch/x86/lib/cmpxchg16b_emu.S
22557@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
22558
22559 popf
22560 mov $1, %al
22561+ pax_force_retaddr
22562 ret
22563
22564 not_same:
22565 popf
22566 xor %al,%al
22567+ pax_force_retaddr
22568 ret
22569
22570 CFI_ENDPROC
22571diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
22572index 6b34d04..dccb07f 100644
22573--- a/arch/x86/lib/copy_page_64.S
22574+++ b/arch/x86/lib/copy_page_64.S
22575@@ -9,6 +9,7 @@ copy_page_c:
22576 CFI_STARTPROC
22577 movl $4096/8,%ecx
22578 rep movsq
22579+ pax_force_retaddr
22580 ret
22581 CFI_ENDPROC
22582 ENDPROC(copy_page_c)
22583@@ -20,12 +21,14 @@ ENDPROC(copy_page_c)
22584
22585 ENTRY(copy_page)
22586 CFI_STARTPROC
22587- subq $2*8,%rsp
22588- CFI_ADJUST_CFA_OFFSET 2*8
22589+ subq $3*8,%rsp
22590+ CFI_ADJUST_CFA_OFFSET 3*8
22591 movq %rbx,(%rsp)
22592 CFI_REL_OFFSET rbx, 0
22593 movq %r12,1*8(%rsp)
22594 CFI_REL_OFFSET r12, 1*8
22595+ movq %r13,2*8(%rsp)
22596+ CFI_REL_OFFSET r13, 2*8
22597
22598 movl $(4096/64)-5,%ecx
22599 .p2align 4
22600@@ -37,7 +40,7 @@ ENTRY(copy_page)
22601 movq 16 (%rsi), %rdx
22602 movq 24 (%rsi), %r8
22603 movq 32 (%rsi), %r9
22604- movq 40 (%rsi), %r10
22605+ movq 40 (%rsi), %r13
22606 movq 48 (%rsi), %r11
22607 movq 56 (%rsi), %r12
22608
22609@@ -48,7 +51,7 @@ ENTRY(copy_page)
22610 movq %rdx, 16 (%rdi)
22611 movq %r8, 24 (%rdi)
22612 movq %r9, 32 (%rdi)
22613- movq %r10, 40 (%rdi)
22614+ movq %r13, 40 (%rdi)
22615 movq %r11, 48 (%rdi)
22616 movq %r12, 56 (%rdi)
22617
22618@@ -67,7 +70,7 @@ ENTRY(copy_page)
22619 movq 16 (%rsi), %rdx
22620 movq 24 (%rsi), %r8
22621 movq 32 (%rsi), %r9
22622- movq 40 (%rsi), %r10
22623+ movq 40 (%rsi), %r13
22624 movq 48 (%rsi), %r11
22625 movq 56 (%rsi), %r12
22626
22627@@ -76,7 +79,7 @@ ENTRY(copy_page)
22628 movq %rdx, 16 (%rdi)
22629 movq %r8, 24 (%rdi)
22630 movq %r9, 32 (%rdi)
22631- movq %r10, 40 (%rdi)
22632+ movq %r13, 40 (%rdi)
22633 movq %r11, 48 (%rdi)
22634 movq %r12, 56 (%rdi)
22635
22636@@ -89,8 +92,11 @@ ENTRY(copy_page)
22637 CFI_RESTORE rbx
22638 movq 1*8(%rsp),%r12
22639 CFI_RESTORE r12
22640- addq $2*8,%rsp
22641- CFI_ADJUST_CFA_OFFSET -2*8
22642+ movq 2*8(%rsp),%r13
22643+ CFI_RESTORE r13
22644+ addq $3*8,%rsp
22645+ CFI_ADJUST_CFA_OFFSET -3*8
22646+ pax_force_retaddr
22647 ret
22648 .Lcopy_page_end:
22649 CFI_ENDPROC
22650@@ -101,7 +107,7 @@ ENDPROC(copy_page)
22651
22652 #include <asm/cpufeature.h>
22653
22654- .section .altinstr_replacement,"ax"
22655+ .section .altinstr_replacement,"a"
22656 1: .byte 0xeb /* jmp <disp8> */
22657 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
22658 2:
22659diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
22660index a30ca15..d25fab6 100644
22661--- a/arch/x86/lib/copy_user_64.S
22662+++ b/arch/x86/lib/copy_user_64.S
22663@@ -18,6 +18,7 @@
22664 #include <asm/alternative-asm.h>
22665 #include <asm/asm.h>
22666 #include <asm/smap.h>
22667+#include <asm/pgtable.h>
22668
22669 /*
22670 * By placing feature2 after feature1 in altinstructions section, we logically
22671@@ -31,7 +32,7 @@
22672 .byte 0xe9 /* 32bit jump */
22673 .long \orig-1f /* by default jump to orig */
22674 1:
22675- .section .altinstr_replacement,"ax"
22676+ .section .altinstr_replacement,"a"
22677 2: .byte 0xe9 /* near jump with 32bit immediate */
22678 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
22679 3: .byte 0xe9 /* near jump with 32bit immediate */
22680@@ -70,47 +71,20 @@
22681 #endif
22682 .endm
22683
22684-/* Standard copy_to_user with segment limit checking */
22685-ENTRY(_copy_to_user)
22686- CFI_STARTPROC
22687- GET_THREAD_INFO(%rax)
22688- movq %rdi,%rcx
22689- addq %rdx,%rcx
22690- jc bad_to_user
22691- cmpq TI_addr_limit(%rax),%rcx
22692- ja bad_to_user
22693- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
22694- copy_user_generic_unrolled,copy_user_generic_string, \
22695- copy_user_enhanced_fast_string
22696- CFI_ENDPROC
22697-ENDPROC(_copy_to_user)
22698-
22699-/* Standard copy_from_user with segment limit checking */
22700-ENTRY(_copy_from_user)
22701- CFI_STARTPROC
22702- GET_THREAD_INFO(%rax)
22703- movq %rsi,%rcx
22704- addq %rdx,%rcx
22705- jc bad_from_user
22706- cmpq TI_addr_limit(%rax),%rcx
22707- ja bad_from_user
22708- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
22709- copy_user_generic_unrolled,copy_user_generic_string, \
22710- copy_user_enhanced_fast_string
22711- CFI_ENDPROC
22712-ENDPROC(_copy_from_user)
22713-
22714 .section .fixup,"ax"
22715 /* must zero dest */
22716 ENTRY(bad_from_user)
22717 bad_from_user:
22718 CFI_STARTPROC
22719+ testl %edx,%edx
22720+ js bad_to_user
22721 movl %edx,%ecx
22722 xorl %eax,%eax
22723 rep
22724 stosb
22725 bad_to_user:
22726 movl %edx,%eax
22727+ pax_force_retaddr
22728 ret
22729 CFI_ENDPROC
22730 ENDPROC(bad_from_user)
22731@@ -141,19 +115,19 @@ ENTRY(copy_user_generic_unrolled)
22732 jz 17f
22733 1: movq (%rsi),%r8
22734 2: movq 1*8(%rsi),%r9
22735-3: movq 2*8(%rsi),%r10
22736+3: movq 2*8(%rsi),%rax
22737 4: movq 3*8(%rsi),%r11
22738 5: movq %r8,(%rdi)
22739 6: movq %r9,1*8(%rdi)
22740-7: movq %r10,2*8(%rdi)
22741+7: movq %rax,2*8(%rdi)
22742 8: movq %r11,3*8(%rdi)
22743 9: movq 4*8(%rsi),%r8
22744 10: movq 5*8(%rsi),%r9
22745-11: movq 6*8(%rsi),%r10
22746+11: movq 6*8(%rsi),%rax
22747 12: movq 7*8(%rsi),%r11
22748 13: movq %r8,4*8(%rdi)
22749 14: movq %r9,5*8(%rdi)
22750-15: movq %r10,6*8(%rdi)
22751+15: movq %rax,6*8(%rdi)
22752 16: movq %r11,7*8(%rdi)
22753 leaq 64(%rsi),%rsi
22754 leaq 64(%rdi),%rdi
22755@@ -180,6 +154,7 @@ ENTRY(copy_user_generic_unrolled)
22756 jnz 21b
22757 23: xor %eax,%eax
22758 ASM_CLAC
22759+ pax_force_retaddr
22760 ret
22761
22762 .section .fixup,"ax"
22763@@ -251,6 +226,7 @@ ENTRY(copy_user_generic_string)
22764 movsb
22765 4: xorl %eax,%eax
22766 ASM_CLAC
22767+ pax_force_retaddr
22768 ret
22769
22770 .section .fixup,"ax"
22771@@ -286,6 +262,7 @@ ENTRY(copy_user_enhanced_fast_string)
22772 movsb
22773 2: xorl %eax,%eax
22774 ASM_CLAC
22775+ pax_force_retaddr
22776 ret
22777
22778 .section .fixup,"ax"
22779diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
22780index 6a4f43c..f5f9e26 100644
22781--- a/arch/x86/lib/copy_user_nocache_64.S
22782+++ b/arch/x86/lib/copy_user_nocache_64.S
22783@@ -8,6 +8,7 @@
22784
22785 #include <linux/linkage.h>
22786 #include <asm/dwarf2.h>
22787+#include <asm/alternative-asm.h>
22788
22789 #define FIX_ALIGNMENT 1
22790
22791@@ -16,6 +17,7 @@
22792 #include <asm/thread_info.h>
22793 #include <asm/asm.h>
22794 #include <asm/smap.h>
22795+#include <asm/pgtable.h>
22796
22797 .macro ALIGN_DESTINATION
22798 #ifdef FIX_ALIGNMENT
22799@@ -49,6 +51,15 @@
22800 */
22801 ENTRY(__copy_user_nocache)
22802 CFI_STARTPROC
22803+
22804+#ifdef CONFIG_PAX_MEMORY_UDEREF
22805+ mov $PAX_USER_SHADOW_BASE,%rcx
22806+ cmp %rcx,%rsi
22807+ jae 1f
22808+ add %rcx,%rsi
22809+1:
22810+#endif
22811+
22812 ASM_STAC
22813 cmpl $8,%edx
22814 jb 20f /* less then 8 bytes, go to byte copy loop */
22815@@ -59,19 +70,19 @@ ENTRY(__copy_user_nocache)
22816 jz 17f
22817 1: movq (%rsi),%r8
22818 2: movq 1*8(%rsi),%r9
22819-3: movq 2*8(%rsi),%r10
22820+3: movq 2*8(%rsi),%rax
22821 4: movq 3*8(%rsi),%r11
22822 5: movnti %r8,(%rdi)
22823 6: movnti %r9,1*8(%rdi)
22824-7: movnti %r10,2*8(%rdi)
22825+7: movnti %rax,2*8(%rdi)
22826 8: movnti %r11,3*8(%rdi)
22827 9: movq 4*8(%rsi),%r8
22828 10: movq 5*8(%rsi),%r9
22829-11: movq 6*8(%rsi),%r10
22830+11: movq 6*8(%rsi),%rax
22831 12: movq 7*8(%rsi),%r11
22832 13: movnti %r8,4*8(%rdi)
22833 14: movnti %r9,5*8(%rdi)
22834-15: movnti %r10,6*8(%rdi)
22835+15: movnti %rax,6*8(%rdi)
22836 16: movnti %r11,7*8(%rdi)
22837 leaq 64(%rsi),%rsi
22838 leaq 64(%rdi),%rdi
22839@@ -99,6 +110,7 @@ ENTRY(__copy_user_nocache)
22840 23: xorl %eax,%eax
22841 ASM_CLAC
22842 sfence
22843+ pax_force_retaddr
22844 ret
22845
22846 .section .fixup,"ax"
22847diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
22848index 2419d5f..953ee51 100644
22849--- a/arch/x86/lib/csum-copy_64.S
22850+++ b/arch/x86/lib/csum-copy_64.S
22851@@ -9,6 +9,7 @@
22852 #include <asm/dwarf2.h>
22853 #include <asm/errno.h>
22854 #include <asm/asm.h>
22855+#include <asm/alternative-asm.h>
22856
22857 /*
22858 * Checksum copy with exception handling.
22859@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
22860 CFI_RESTORE rbp
22861 addq $7*8, %rsp
22862 CFI_ADJUST_CFA_OFFSET -7*8
22863+ pax_force_retaddr 0, 1
22864 ret
22865 CFI_RESTORE_STATE
22866
22867diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
22868index 25b7ae8..169fafc 100644
22869--- a/arch/x86/lib/csum-wrappers_64.c
22870+++ b/arch/x86/lib/csum-wrappers_64.c
22871@@ -52,7 +52,7 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
22872 len -= 2;
22873 }
22874 }
22875- isum = csum_partial_copy_generic((__force const void *)src,
22876+ isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
22877 dst, len, isum, errp, NULL);
22878 if (unlikely(*errp))
22879 goto out_err;
22880@@ -105,7 +105,7 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
22881 }
22882
22883 *errp = 0;
22884- return csum_partial_copy_generic(src, (void __force *)dst,
22885+ return csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
22886 len, isum, NULL, errp);
22887 }
22888 EXPORT_SYMBOL(csum_partial_copy_to_user);
22889diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
22890index 156b9c8..b144132 100644
22891--- a/arch/x86/lib/getuser.S
22892+++ b/arch/x86/lib/getuser.S
22893@@ -34,17 +34,40 @@
22894 #include <asm/thread_info.h>
22895 #include <asm/asm.h>
22896 #include <asm/smap.h>
22897+#include <asm/segment.h>
22898+#include <asm/pgtable.h>
22899+#include <asm/alternative-asm.h>
22900+
22901+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
22902+#define __copyuser_seg gs;
22903+#else
22904+#define __copyuser_seg
22905+#endif
22906
22907 .text
22908 ENTRY(__get_user_1)
22909 CFI_STARTPROC
22910+
22911+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22912 GET_THREAD_INFO(%_ASM_DX)
22913 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
22914 jae bad_get_user
22915 ASM_STAC
22916-1: movzb (%_ASM_AX),%edx
22917+
22918+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22919+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
22920+ cmp %_ASM_DX,%_ASM_AX
22921+ jae 1234f
22922+ add %_ASM_DX,%_ASM_AX
22923+1234:
22924+#endif
22925+
22926+#endif
22927+
22928+1: __copyuser_seg movzb (%_ASM_AX),%edx
22929 xor %eax,%eax
22930 ASM_CLAC
22931+ pax_force_retaddr
22932 ret
22933 CFI_ENDPROC
22934 ENDPROC(__get_user_1)
22935@@ -52,14 +75,28 @@ ENDPROC(__get_user_1)
22936 ENTRY(__get_user_2)
22937 CFI_STARTPROC
22938 add $1,%_ASM_AX
22939+
22940+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22941 jc bad_get_user
22942 GET_THREAD_INFO(%_ASM_DX)
22943 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
22944 jae bad_get_user
22945 ASM_STAC
22946-2: movzwl -1(%_ASM_AX),%edx
22947+
22948+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22949+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
22950+ cmp %_ASM_DX,%_ASM_AX
22951+ jae 1234f
22952+ add %_ASM_DX,%_ASM_AX
22953+1234:
22954+#endif
22955+
22956+#endif
22957+
22958+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
22959 xor %eax,%eax
22960 ASM_CLAC
22961+ pax_force_retaddr
22962 ret
22963 CFI_ENDPROC
22964 ENDPROC(__get_user_2)
22965@@ -67,14 +104,28 @@ ENDPROC(__get_user_2)
22966 ENTRY(__get_user_4)
22967 CFI_STARTPROC
22968 add $3,%_ASM_AX
22969+
22970+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22971 jc bad_get_user
22972 GET_THREAD_INFO(%_ASM_DX)
22973 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
22974 jae bad_get_user
22975 ASM_STAC
22976-3: mov -3(%_ASM_AX),%edx
22977+
22978+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22979+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
22980+ cmp %_ASM_DX,%_ASM_AX
22981+ jae 1234f
22982+ add %_ASM_DX,%_ASM_AX
22983+1234:
22984+#endif
22985+
22986+#endif
22987+
22988+3: __copyuser_seg mov -3(%_ASM_AX),%edx
22989 xor %eax,%eax
22990 ASM_CLAC
22991+ pax_force_retaddr
22992 ret
22993 CFI_ENDPROC
22994 ENDPROC(__get_user_4)
22995@@ -87,10 +138,20 @@ ENTRY(__get_user_8)
22996 GET_THREAD_INFO(%_ASM_DX)
22997 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
22998 jae bad_get_user
22999+
23000+#ifdef CONFIG_PAX_MEMORY_UDEREF
23001+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
23002+ cmp %_ASM_DX,%_ASM_AX
23003+ jae 1234f
23004+ add %_ASM_DX,%_ASM_AX
23005+1234:
23006+#endif
23007+
23008 ASM_STAC
23009 4: movq -7(%_ASM_AX),%_ASM_DX
23010 xor %eax,%eax
23011 ASM_CLAC
23012+ pax_force_retaddr
23013 ret
23014 CFI_ENDPROC
23015 ENDPROC(__get_user_8)
23016@@ -101,6 +162,7 @@ bad_get_user:
23017 xor %edx,%edx
23018 mov $(-EFAULT),%_ASM_AX
23019 ASM_CLAC
23020+ pax_force_retaddr
23021 ret
23022 CFI_ENDPROC
23023 END(bad_get_user)
23024diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
23025index 54fcffe..7be149e 100644
23026--- a/arch/x86/lib/insn.c
23027+++ b/arch/x86/lib/insn.c
23028@@ -20,8 +20,10 @@
23029
23030 #ifdef __KERNEL__
23031 #include <linux/string.h>
23032+#include <asm/pgtable_types.h>
23033 #else
23034 #include <string.h>
23035+#define ktla_ktva(addr) addr
23036 #endif
23037 #include <asm/inat.h>
23038 #include <asm/insn.h>
23039@@ -53,8 +55,8 @@
23040 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
23041 {
23042 memset(insn, 0, sizeof(*insn));
23043- insn->kaddr = kaddr;
23044- insn->next_byte = kaddr;
23045+ insn->kaddr = ktla_ktva(kaddr);
23046+ insn->next_byte = ktla_ktva(kaddr);
23047 insn->x86_64 = x86_64 ? 1 : 0;
23048 insn->opnd_bytes = 4;
23049 if (x86_64)
23050diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
23051index 05a95e7..326f2fa 100644
23052--- a/arch/x86/lib/iomap_copy_64.S
23053+++ b/arch/x86/lib/iomap_copy_64.S
23054@@ -17,6 +17,7 @@
23055
23056 #include <linux/linkage.h>
23057 #include <asm/dwarf2.h>
23058+#include <asm/alternative-asm.h>
23059
23060 /*
23061 * override generic version in lib/iomap_copy.c
23062@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
23063 CFI_STARTPROC
23064 movl %edx,%ecx
23065 rep movsd
23066+ pax_force_retaddr
23067 ret
23068 CFI_ENDPROC
23069 ENDPROC(__iowrite32_copy)
23070diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
23071index 1c273be..da9cc0e 100644
23072--- a/arch/x86/lib/memcpy_64.S
23073+++ b/arch/x86/lib/memcpy_64.S
23074@@ -33,6 +33,7 @@
23075 rep movsq
23076 movl %edx, %ecx
23077 rep movsb
23078+ pax_force_retaddr
23079 ret
23080 .Lmemcpy_e:
23081 .previous
23082@@ -49,6 +50,7 @@
23083 movq %rdi, %rax
23084 movq %rdx, %rcx
23085 rep movsb
23086+ pax_force_retaddr
23087 ret
23088 .Lmemcpy_e_e:
23089 .previous
23090@@ -76,13 +78,13 @@ ENTRY(memcpy)
23091 */
23092 movq 0*8(%rsi), %r8
23093 movq 1*8(%rsi), %r9
23094- movq 2*8(%rsi), %r10
23095+ movq 2*8(%rsi), %rcx
23096 movq 3*8(%rsi), %r11
23097 leaq 4*8(%rsi), %rsi
23098
23099 movq %r8, 0*8(%rdi)
23100 movq %r9, 1*8(%rdi)
23101- movq %r10, 2*8(%rdi)
23102+ movq %rcx, 2*8(%rdi)
23103 movq %r11, 3*8(%rdi)
23104 leaq 4*8(%rdi), %rdi
23105 jae .Lcopy_forward_loop
23106@@ -105,12 +107,12 @@ ENTRY(memcpy)
23107 subq $0x20, %rdx
23108 movq -1*8(%rsi), %r8
23109 movq -2*8(%rsi), %r9
23110- movq -3*8(%rsi), %r10
23111+ movq -3*8(%rsi), %rcx
23112 movq -4*8(%rsi), %r11
23113 leaq -4*8(%rsi), %rsi
23114 movq %r8, -1*8(%rdi)
23115 movq %r9, -2*8(%rdi)
23116- movq %r10, -3*8(%rdi)
23117+ movq %rcx, -3*8(%rdi)
23118 movq %r11, -4*8(%rdi)
23119 leaq -4*8(%rdi), %rdi
23120 jae .Lcopy_backward_loop
23121@@ -130,12 +132,13 @@ ENTRY(memcpy)
23122 */
23123 movq 0*8(%rsi), %r8
23124 movq 1*8(%rsi), %r9
23125- movq -2*8(%rsi, %rdx), %r10
23126+ movq -2*8(%rsi, %rdx), %rcx
23127 movq -1*8(%rsi, %rdx), %r11
23128 movq %r8, 0*8(%rdi)
23129 movq %r9, 1*8(%rdi)
23130- movq %r10, -2*8(%rdi, %rdx)
23131+ movq %rcx, -2*8(%rdi, %rdx)
23132 movq %r11, -1*8(%rdi, %rdx)
23133+ pax_force_retaddr
23134 retq
23135 .p2align 4
23136 .Lless_16bytes:
23137@@ -148,6 +151,7 @@ ENTRY(memcpy)
23138 movq -1*8(%rsi, %rdx), %r9
23139 movq %r8, 0*8(%rdi)
23140 movq %r9, -1*8(%rdi, %rdx)
23141+ pax_force_retaddr
23142 retq
23143 .p2align 4
23144 .Lless_8bytes:
23145@@ -161,6 +165,7 @@ ENTRY(memcpy)
23146 movl -4(%rsi, %rdx), %r8d
23147 movl %ecx, (%rdi)
23148 movl %r8d, -4(%rdi, %rdx)
23149+ pax_force_retaddr
23150 retq
23151 .p2align 4
23152 .Lless_3bytes:
23153@@ -179,6 +184,7 @@ ENTRY(memcpy)
23154 movb %cl, (%rdi)
23155
23156 .Lend:
23157+ pax_force_retaddr
23158 retq
23159 CFI_ENDPROC
23160 ENDPROC(memcpy)
23161diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
23162index ee16461..c39c199 100644
23163--- a/arch/x86/lib/memmove_64.S
23164+++ b/arch/x86/lib/memmove_64.S
23165@@ -61,13 +61,13 @@ ENTRY(memmove)
23166 5:
23167 sub $0x20, %rdx
23168 movq 0*8(%rsi), %r11
23169- movq 1*8(%rsi), %r10
23170+ movq 1*8(%rsi), %rcx
23171 movq 2*8(%rsi), %r9
23172 movq 3*8(%rsi), %r8
23173 leaq 4*8(%rsi), %rsi
23174
23175 movq %r11, 0*8(%rdi)
23176- movq %r10, 1*8(%rdi)
23177+ movq %rcx, 1*8(%rdi)
23178 movq %r9, 2*8(%rdi)
23179 movq %r8, 3*8(%rdi)
23180 leaq 4*8(%rdi), %rdi
23181@@ -81,10 +81,10 @@ ENTRY(memmove)
23182 4:
23183 movq %rdx, %rcx
23184 movq -8(%rsi, %rdx), %r11
23185- lea -8(%rdi, %rdx), %r10
23186+ lea -8(%rdi, %rdx), %r9
23187 shrq $3, %rcx
23188 rep movsq
23189- movq %r11, (%r10)
23190+ movq %r11, (%r9)
23191 jmp 13f
23192 .Lmemmove_end_forward:
23193
23194@@ -95,14 +95,14 @@ ENTRY(memmove)
23195 7:
23196 movq %rdx, %rcx
23197 movq (%rsi), %r11
23198- movq %rdi, %r10
23199+ movq %rdi, %r9
23200 leaq -8(%rsi, %rdx), %rsi
23201 leaq -8(%rdi, %rdx), %rdi
23202 shrq $3, %rcx
23203 std
23204 rep movsq
23205 cld
23206- movq %r11, (%r10)
23207+ movq %r11, (%r9)
23208 jmp 13f
23209
23210 /*
23211@@ -127,13 +127,13 @@ ENTRY(memmove)
23212 8:
23213 subq $0x20, %rdx
23214 movq -1*8(%rsi), %r11
23215- movq -2*8(%rsi), %r10
23216+ movq -2*8(%rsi), %rcx
23217 movq -3*8(%rsi), %r9
23218 movq -4*8(%rsi), %r8
23219 leaq -4*8(%rsi), %rsi
23220
23221 movq %r11, -1*8(%rdi)
23222- movq %r10, -2*8(%rdi)
23223+ movq %rcx, -2*8(%rdi)
23224 movq %r9, -3*8(%rdi)
23225 movq %r8, -4*8(%rdi)
23226 leaq -4*8(%rdi), %rdi
23227@@ -151,11 +151,11 @@ ENTRY(memmove)
23228 * Move data from 16 bytes to 31 bytes.
23229 */
23230 movq 0*8(%rsi), %r11
23231- movq 1*8(%rsi), %r10
23232+ movq 1*8(%rsi), %rcx
23233 movq -2*8(%rsi, %rdx), %r9
23234 movq -1*8(%rsi, %rdx), %r8
23235 movq %r11, 0*8(%rdi)
23236- movq %r10, 1*8(%rdi)
23237+ movq %rcx, 1*8(%rdi)
23238 movq %r9, -2*8(%rdi, %rdx)
23239 movq %r8, -1*8(%rdi, %rdx)
23240 jmp 13f
23241@@ -167,9 +167,9 @@ ENTRY(memmove)
23242 * Move data from 8 bytes to 15 bytes.
23243 */
23244 movq 0*8(%rsi), %r11
23245- movq -1*8(%rsi, %rdx), %r10
23246+ movq -1*8(%rsi, %rdx), %r9
23247 movq %r11, 0*8(%rdi)
23248- movq %r10, -1*8(%rdi, %rdx)
23249+ movq %r9, -1*8(%rdi, %rdx)
23250 jmp 13f
23251 10:
23252 cmpq $4, %rdx
23253@@ -178,9 +178,9 @@ ENTRY(memmove)
23254 * Move data from 4 bytes to 7 bytes.
23255 */
23256 movl (%rsi), %r11d
23257- movl -4(%rsi, %rdx), %r10d
23258+ movl -4(%rsi, %rdx), %r9d
23259 movl %r11d, (%rdi)
23260- movl %r10d, -4(%rdi, %rdx)
23261+ movl %r9d, -4(%rdi, %rdx)
23262 jmp 13f
23263 11:
23264 cmp $2, %rdx
23265@@ -189,9 +189,9 @@ ENTRY(memmove)
23266 * Move data from 2 bytes to 3 bytes.
23267 */
23268 movw (%rsi), %r11w
23269- movw -2(%rsi, %rdx), %r10w
23270+ movw -2(%rsi, %rdx), %r9w
23271 movw %r11w, (%rdi)
23272- movw %r10w, -2(%rdi, %rdx)
23273+ movw %r9w, -2(%rdi, %rdx)
23274 jmp 13f
23275 12:
23276 cmp $1, %rdx
23277@@ -202,6 +202,7 @@ ENTRY(memmove)
23278 movb (%rsi), %r11b
23279 movb %r11b, (%rdi)
23280 13:
23281+ pax_force_retaddr
23282 retq
23283 CFI_ENDPROC
23284
23285@@ -210,6 +211,7 @@ ENTRY(memmove)
23286 /* Forward moving data. */
23287 movq %rdx, %rcx
23288 rep movsb
23289+ pax_force_retaddr
23290 retq
23291 .Lmemmove_end_forward_efs:
23292 .previous
23293diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
23294index 2dcb380..963660a 100644
23295--- a/arch/x86/lib/memset_64.S
23296+++ b/arch/x86/lib/memset_64.S
23297@@ -30,6 +30,7 @@
23298 movl %edx,%ecx
23299 rep stosb
23300 movq %r9,%rax
23301+ pax_force_retaddr
23302 ret
23303 .Lmemset_e:
23304 .previous
23305@@ -52,6 +53,7 @@
23306 movq %rdx,%rcx
23307 rep stosb
23308 movq %r9,%rax
23309+ pax_force_retaddr
23310 ret
23311 .Lmemset_e_e:
23312 .previous
23313@@ -59,7 +61,7 @@
23314 ENTRY(memset)
23315 ENTRY(__memset)
23316 CFI_STARTPROC
23317- movq %rdi,%r10
23318+ movq %rdi,%r11
23319
23320 /* expand byte value */
23321 movzbl %sil,%ecx
23322@@ -117,7 +119,8 @@ ENTRY(__memset)
23323 jnz .Lloop_1
23324
23325 .Lende:
23326- movq %r10,%rax
23327+ movq %r11,%rax
23328+ pax_force_retaddr
23329 ret
23330
23331 CFI_RESTORE_STATE
23332diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
23333index c9f2d9b..e7fd2c0 100644
23334--- a/arch/x86/lib/mmx_32.c
23335+++ b/arch/x86/lib/mmx_32.c
23336@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
23337 {
23338 void *p;
23339 int i;
23340+ unsigned long cr0;
23341
23342 if (unlikely(in_interrupt()))
23343 return __memcpy(to, from, len);
23344@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
23345 kernel_fpu_begin();
23346
23347 __asm__ __volatile__ (
23348- "1: prefetch (%0)\n" /* This set is 28 bytes */
23349- " prefetch 64(%0)\n"
23350- " prefetch 128(%0)\n"
23351- " prefetch 192(%0)\n"
23352- " prefetch 256(%0)\n"
23353+ "1: prefetch (%1)\n" /* This set is 28 bytes */
23354+ " prefetch 64(%1)\n"
23355+ " prefetch 128(%1)\n"
23356+ " prefetch 192(%1)\n"
23357+ " prefetch 256(%1)\n"
23358 "2: \n"
23359 ".section .fixup, \"ax\"\n"
23360- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
23361+ "3: \n"
23362+
23363+#ifdef CONFIG_PAX_KERNEXEC
23364+ " movl %%cr0, %0\n"
23365+ " movl %0, %%eax\n"
23366+ " andl $0xFFFEFFFF, %%eax\n"
23367+ " movl %%eax, %%cr0\n"
23368+#endif
23369+
23370+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
23371+
23372+#ifdef CONFIG_PAX_KERNEXEC
23373+ " movl %0, %%cr0\n"
23374+#endif
23375+
23376 " jmp 2b\n"
23377 ".previous\n"
23378 _ASM_EXTABLE(1b, 3b)
23379- : : "r" (from));
23380+ : "=&r" (cr0) : "r" (from) : "ax");
23381
23382 for ( ; i > 5; i--) {
23383 __asm__ __volatile__ (
23384- "1: prefetch 320(%0)\n"
23385- "2: movq (%0), %%mm0\n"
23386- " movq 8(%0), %%mm1\n"
23387- " movq 16(%0), %%mm2\n"
23388- " movq 24(%0), %%mm3\n"
23389- " movq %%mm0, (%1)\n"
23390- " movq %%mm1, 8(%1)\n"
23391- " movq %%mm2, 16(%1)\n"
23392- " movq %%mm3, 24(%1)\n"
23393- " movq 32(%0), %%mm0\n"
23394- " movq 40(%0), %%mm1\n"
23395- " movq 48(%0), %%mm2\n"
23396- " movq 56(%0), %%mm3\n"
23397- " movq %%mm0, 32(%1)\n"
23398- " movq %%mm1, 40(%1)\n"
23399- " movq %%mm2, 48(%1)\n"
23400- " movq %%mm3, 56(%1)\n"
23401+ "1: prefetch 320(%1)\n"
23402+ "2: movq (%1), %%mm0\n"
23403+ " movq 8(%1), %%mm1\n"
23404+ " movq 16(%1), %%mm2\n"
23405+ " movq 24(%1), %%mm3\n"
23406+ " movq %%mm0, (%2)\n"
23407+ " movq %%mm1, 8(%2)\n"
23408+ " movq %%mm2, 16(%2)\n"
23409+ " movq %%mm3, 24(%2)\n"
23410+ " movq 32(%1), %%mm0\n"
23411+ " movq 40(%1), %%mm1\n"
23412+ " movq 48(%1), %%mm2\n"
23413+ " movq 56(%1), %%mm3\n"
23414+ " movq %%mm0, 32(%2)\n"
23415+ " movq %%mm1, 40(%2)\n"
23416+ " movq %%mm2, 48(%2)\n"
23417+ " movq %%mm3, 56(%2)\n"
23418 ".section .fixup, \"ax\"\n"
23419- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
23420+ "3:\n"
23421+
23422+#ifdef CONFIG_PAX_KERNEXEC
23423+ " movl %%cr0, %0\n"
23424+ " movl %0, %%eax\n"
23425+ " andl $0xFFFEFFFF, %%eax\n"
23426+ " movl %%eax, %%cr0\n"
23427+#endif
23428+
23429+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
23430+
23431+#ifdef CONFIG_PAX_KERNEXEC
23432+ " movl %0, %%cr0\n"
23433+#endif
23434+
23435 " jmp 2b\n"
23436 ".previous\n"
23437 _ASM_EXTABLE(1b, 3b)
23438- : : "r" (from), "r" (to) : "memory");
23439+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
23440
23441 from += 64;
23442 to += 64;
23443@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
23444 static void fast_copy_page(void *to, void *from)
23445 {
23446 int i;
23447+ unsigned long cr0;
23448
23449 kernel_fpu_begin();
23450
23451@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
23452 * but that is for later. -AV
23453 */
23454 __asm__ __volatile__(
23455- "1: prefetch (%0)\n"
23456- " prefetch 64(%0)\n"
23457- " prefetch 128(%0)\n"
23458- " prefetch 192(%0)\n"
23459- " prefetch 256(%0)\n"
23460+ "1: prefetch (%1)\n"
23461+ " prefetch 64(%1)\n"
23462+ " prefetch 128(%1)\n"
23463+ " prefetch 192(%1)\n"
23464+ " prefetch 256(%1)\n"
23465 "2: \n"
23466 ".section .fixup, \"ax\"\n"
23467- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
23468+ "3: \n"
23469+
23470+#ifdef CONFIG_PAX_KERNEXEC
23471+ " movl %%cr0, %0\n"
23472+ " movl %0, %%eax\n"
23473+ " andl $0xFFFEFFFF, %%eax\n"
23474+ " movl %%eax, %%cr0\n"
23475+#endif
23476+
23477+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
23478+
23479+#ifdef CONFIG_PAX_KERNEXEC
23480+ " movl %0, %%cr0\n"
23481+#endif
23482+
23483 " jmp 2b\n"
23484 ".previous\n"
23485- _ASM_EXTABLE(1b, 3b) : : "r" (from));
23486+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
23487
23488 for (i = 0; i < (4096-320)/64; i++) {
23489 __asm__ __volatile__ (
23490- "1: prefetch 320(%0)\n"
23491- "2: movq (%0), %%mm0\n"
23492- " movntq %%mm0, (%1)\n"
23493- " movq 8(%0), %%mm1\n"
23494- " movntq %%mm1, 8(%1)\n"
23495- " movq 16(%0), %%mm2\n"
23496- " movntq %%mm2, 16(%1)\n"
23497- " movq 24(%0), %%mm3\n"
23498- " movntq %%mm3, 24(%1)\n"
23499- " movq 32(%0), %%mm4\n"
23500- " movntq %%mm4, 32(%1)\n"
23501- " movq 40(%0), %%mm5\n"
23502- " movntq %%mm5, 40(%1)\n"
23503- " movq 48(%0), %%mm6\n"
23504- " movntq %%mm6, 48(%1)\n"
23505- " movq 56(%0), %%mm7\n"
23506- " movntq %%mm7, 56(%1)\n"
23507+ "1: prefetch 320(%1)\n"
23508+ "2: movq (%1), %%mm0\n"
23509+ " movntq %%mm0, (%2)\n"
23510+ " movq 8(%1), %%mm1\n"
23511+ " movntq %%mm1, 8(%2)\n"
23512+ " movq 16(%1), %%mm2\n"
23513+ " movntq %%mm2, 16(%2)\n"
23514+ " movq 24(%1), %%mm3\n"
23515+ " movntq %%mm3, 24(%2)\n"
23516+ " movq 32(%1), %%mm4\n"
23517+ " movntq %%mm4, 32(%2)\n"
23518+ " movq 40(%1), %%mm5\n"
23519+ " movntq %%mm5, 40(%2)\n"
23520+ " movq 48(%1), %%mm6\n"
23521+ " movntq %%mm6, 48(%2)\n"
23522+ " movq 56(%1), %%mm7\n"
23523+ " movntq %%mm7, 56(%2)\n"
23524 ".section .fixup, \"ax\"\n"
23525- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
23526+ "3:\n"
23527+
23528+#ifdef CONFIG_PAX_KERNEXEC
23529+ " movl %%cr0, %0\n"
23530+ " movl %0, %%eax\n"
23531+ " andl $0xFFFEFFFF, %%eax\n"
23532+ " movl %%eax, %%cr0\n"
23533+#endif
23534+
23535+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
23536+
23537+#ifdef CONFIG_PAX_KERNEXEC
23538+ " movl %0, %%cr0\n"
23539+#endif
23540+
23541 " jmp 2b\n"
23542 ".previous\n"
23543- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
23544+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
23545
23546 from += 64;
23547 to += 64;
23548@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
23549 static void fast_copy_page(void *to, void *from)
23550 {
23551 int i;
23552+ unsigned long cr0;
23553
23554 kernel_fpu_begin();
23555
23556 __asm__ __volatile__ (
23557- "1: prefetch (%0)\n"
23558- " prefetch 64(%0)\n"
23559- " prefetch 128(%0)\n"
23560- " prefetch 192(%0)\n"
23561- " prefetch 256(%0)\n"
23562+ "1: prefetch (%1)\n"
23563+ " prefetch 64(%1)\n"
23564+ " prefetch 128(%1)\n"
23565+ " prefetch 192(%1)\n"
23566+ " prefetch 256(%1)\n"
23567 "2: \n"
23568 ".section .fixup, \"ax\"\n"
23569- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
23570+ "3: \n"
23571+
23572+#ifdef CONFIG_PAX_KERNEXEC
23573+ " movl %%cr0, %0\n"
23574+ " movl %0, %%eax\n"
23575+ " andl $0xFFFEFFFF, %%eax\n"
23576+ " movl %%eax, %%cr0\n"
23577+#endif
23578+
23579+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
23580+
23581+#ifdef CONFIG_PAX_KERNEXEC
23582+ " movl %0, %%cr0\n"
23583+#endif
23584+
23585 " jmp 2b\n"
23586 ".previous\n"
23587- _ASM_EXTABLE(1b, 3b) : : "r" (from));
23588+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
23589
23590 for (i = 0; i < 4096/64; i++) {
23591 __asm__ __volatile__ (
23592- "1: prefetch 320(%0)\n"
23593- "2: movq (%0), %%mm0\n"
23594- " movq 8(%0), %%mm1\n"
23595- " movq 16(%0), %%mm2\n"
23596- " movq 24(%0), %%mm3\n"
23597- " movq %%mm0, (%1)\n"
23598- " movq %%mm1, 8(%1)\n"
23599- " movq %%mm2, 16(%1)\n"
23600- " movq %%mm3, 24(%1)\n"
23601- " movq 32(%0), %%mm0\n"
23602- " movq 40(%0), %%mm1\n"
23603- " movq 48(%0), %%mm2\n"
23604- " movq 56(%0), %%mm3\n"
23605- " movq %%mm0, 32(%1)\n"
23606- " movq %%mm1, 40(%1)\n"
23607- " movq %%mm2, 48(%1)\n"
23608- " movq %%mm3, 56(%1)\n"
23609+ "1: prefetch 320(%1)\n"
23610+ "2: movq (%1), %%mm0\n"
23611+ " movq 8(%1), %%mm1\n"
23612+ " movq 16(%1), %%mm2\n"
23613+ " movq 24(%1), %%mm3\n"
23614+ " movq %%mm0, (%2)\n"
23615+ " movq %%mm1, 8(%2)\n"
23616+ " movq %%mm2, 16(%2)\n"
23617+ " movq %%mm3, 24(%2)\n"
23618+ " movq 32(%1), %%mm0\n"
23619+ " movq 40(%1), %%mm1\n"
23620+ " movq 48(%1), %%mm2\n"
23621+ " movq 56(%1), %%mm3\n"
23622+ " movq %%mm0, 32(%2)\n"
23623+ " movq %%mm1, 40(%2)\n"
23624+ " movq %%mm2, 48(%2)\n"
23625+ " movq %%mm3, 56(%2)\n"
23626 ".section .fixup, \"ax\"\n"
23627- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
23628+ "3:\n"
23629+
23630+#ifdef CONFIG_PAX_KERNEXEC
23631+ " movl %%cr0, %0\n"
23632+ " movl %0, %%eax\n"
23633+ " andl $0xFFFEFFFF, %%eax\n"
23634+ " movl %%eax, %%cr0\n"
23635+#endif
23636+
23637+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
23638+
23639+#ifdef CONFIG_PAX_KERNEXEC
23640+ " movl %0, %%cr0\n"
23641+#endif
23642+
23643 " jmp 2b\n"
23644 ".previous\n"
23645 _ASM_EXTABLE(1b, 3b)
23646- : : "r" (from), "r" (to) : "memory");
23647+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
23648
23649 from += 64;
23650 to += 64;
23651diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
23652index f6d13ee..aca5f0b 100644
23653--- a/arch/x86/lib/msr-reg.S
23654+++ b/arch/x86/lib/msr-reg.S
23655@@ -3,6 +3,7 @@
23656 #include <asm/dwarf2.h>
23657 #include <asm/asm.h>
23658 #include <asm/msr.h>
23659+#include <asm/alternative-asm.h>
23660
23661 #ifdef CONFIG_X86_64
23662 /*
23663@@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
23664 CFI_STARTPROC
23665 pushq_cfi %rbx
23666 pushq_cfi %rbp
23667- movq %rdi, %r10 /* Save pointer */
23668+ movq %rdi, %r9 /* Save pointer */
23669 xorl %r11d, %r11d /* Return value */
23670 movl (%rdi), %eax
23671 movl 4(%rdi), %ecx
23672@@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
23673 movl 28(%rdi), %edi
23674 CFI_REMEMBER_STATE
23675 1: \op
23676-2: movl %eax, (%r10)
23677+2: movl %eax, (%r9)
23678 movl %r11d, %eax /* Return value */
23679- movl %ecx, 4(%r10)
23680- movl %edx, 8(%r10)
23681- movl %ebx, 12(%r10)
23682- movl %ebp, 20(%r10)
23683- movl %esi, 24(%r10)
23684- movl %edi, 28(%r10)
23685+ movl %ecx, 4(%r9)
23686+ movl %edx, 8(%r9)
23687+ movl %ebx, 12(%r9)
23688+ movl %ebp, 20(%r9)
23689+ movl %esi, 24(%r9)
23690+ movl %edi, 28(%r9)
23691 popq_cfi %rbp
23692 popq_cfi %rbx
23693+ pax_force_retaddr
23694 ret
23695 3:
23696 CFI_RESTORE_STATE
23697diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
23698index fc6ba17..04471c5 100644
23699--- a/arch/x86/lib/putuser.S
23700+++ b/arch/x86/lib/putuser.S
23701@@ -16,7 +16,9 @@
23702 #include <asm/errno.h>
23703 #include <asm/asm.h>
23704 #include <asm/smap.h>
23705-
23706+#include <asm/segment.h>
23707+#include <asm/pgtable.h>
23708+#include <asm/alternative-asm.h>
23709
23710 /*
23711 * __put_user_X
23712@@ -30,57 +32,125 @@
23713 * as they get called from within inline assembly.
23714 */
23715
23716-#define ENTER CFI_STARTPROC ; \
23717- GET_THREAD_INFO(%_ASM_BX)
23718-#define EXIT ASM_CLAC ; \
23719- ret ; \
23720+#define ENTER CFI_STARTPROC
23721+#define EXIT ASM_CLAC ; \
23722+ pax_force_retaddr ; \
23723+ ret ; \
23724 CFI_ENDPROC
23725
23726+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23727+#define _DEST %_ASM_CX,%_ASM_BX
23728+#else
23729+#define _DEST %_ASM_CX
23730+#endif
23731+
23732+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
23733+#define __copyuser_seg gs;
23734+#else
23735+#define __copyuser_seg
23736+#endif
23737+
23738 .text
23739 ENTRY(__put_user_1)
23740 ENTER
23741+
23742+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
23743+ GET_THREAD_INFO(%_ASM_BX)
23744 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
23745 jae bad_put_user
23746 ASM_STAC
23747-1: movb %al,(%_ASM_CX)
23748+
23749+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23750+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
23751+ cmp %_ASM_BX,%_ASM_CX
23752+ jb 1234f
23753+ xor %ebx,%ebx
23754+1234:
23755+#endif
23756+
23757+#endif
23758+
23759+1: __copyuser_seg movb %al,(_DEST)
23760 xor %eax,%eax
23761 EXIT
23762 ENDPROC(__put_user_1)
23763
23764 ENTRY(__put_user_2)
23765 ENTER
23766+
23767+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
23768+ GET_THREAD_INFO(%_ASM_BX)
23769 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
23770 sub $1,%_ASM_BX
23771 cmp %_ASM_BX,%_ASM_CX
23772 jae bad_put_user
23773 ASM_STAC
23774-2: movw %ax,(%_ASM_CX)
23775+
23776+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23777+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
23778+ cmp %_ASM_BX,%_ASM_CX
23779+ jb 1234f
23780+ xor %ebx,%ebx
23781+1234:
23782+#endif
23783+
23784+#endif
23785+
23786+2: __copyuser_seg movw %ax,(_DEST)
23787 xor %eax,%eax
23788 EXIT
23789 ENDPROC(__put_user_2)
23790
23791 ENTRY(__put_user_4)
23792 ENTER
23793+
23794+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
23795+ GET_THREAD_INFO(%_ASM_BX)
23796 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
23797 sub $3,%_ASM_BX
23798 cmp %_ASM_BX,%_ASM_CX
23799 jae bad_put_user
23800 ASM_STAC
23801-3: movl %eax,(%_ASM_CX)
23802+
23803+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23804+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
23805+ cmp %_ASM_BX,%_ASM_CX
23806+ jb 1234f
23807+ xor %ebx,%ebx
23808+1234:
23809+#endif
23810+
23811+#endif
23812+
23813+3: __copyuser_seg movl %eax,(_DEST)
23814 xor %eax,%eax
23815 EXIT
23816 ENDPROC(__put_user_4)
23817
23818 ENTRY(__put_user_8)
23819 ENTER
23820+
23821+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
23822+ GET_THREAD_INFO(%_ASM_BX)
23823 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
23824 sub $7,%_ASM_BX
23825 cmp %_ASM_BX,%_ASM_CX
23826 jae bad_put_user
23827 ASM_STAC
23828-4: mov %_ASM_AX,(%_ASM_CX)
23829+
23830+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23831+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
23832+ cmp %_ASM_BX,%_ASM_CX
23833+ jb 1234f
23834+ xor %ebx,%ebx
23835+1234:
23836+#endif
23837+
23838+#endif
23839+
23840+4: __copyuser_seg mov %_ASM_AX,(_DEST)
23841 #ifdef CONFIG_X86_32
23842-5: movl %edx,4(%_ASM_CX)
23843+5: __copyuser_seg movl %edx,4(_DEST)
23844 #endif
23845 xor %eax,%eax
23846 EXIT
23847diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
23848index 1cad221..de671ee 100644
23849--- a/arch/x86/lib/rwlock.S
23850+++ b/arch/x86/lib/rwlock.S
23851@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
23852 FRAME
23853 0: LOCK_PREFIX
23854 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
23855+
23856+#ifdef CONFIG_PAX_REFCOUNT
23857+ jno 1234f
23858+ LOCK_PREFIX
23859+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
23860+ int $4
23861+1234:
23862+ _ASM_EXTABLE(1234b, 1234b)
23863+#endif
23864+
23865 1: rep; nop
23866 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
23867 jne 1b
23868 LOCK_PREFIX
23869 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
23870+
23871+#ifdef CONFIG_PAX_REFCOUNT
23872+ jno 1234f
23873+ LOCK_PREFIX
23874+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
23875+ int $4
23876+1234:
23877+ _ASM_EXTABLE(1234b, 1234b)
23878+#endif
23879+
23880 jnz 0b
23881 ENDFRAME
23882+ pax_force_retaddr
23883 ret
23884 CFI_ENDPROC
23885 END(__write_lock_failed)
23886@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
23887 FRAME
23888 0: LOCK_PREFIX
23889 READ_LOCK_SIZE(inc) (%__lock_ptr)
23890+
23891+#ifdef CONFIG_PAX_REFCOUNT
23892+ jno 1234f
23893+ LOCK_PREFIX
23894+ READ_LOCK_SIZE(dec) (%__lock_ptr)
23895+ int $4
23896+1234:
23897+ _ASM_EXTABLE(1234b, 1234b)
23898+#endif
23899+
23900 1: rep; nop
23901 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
23902 js 1b
23903 LOCK_PREFIX
23904 READ_LOCK_SIZE(dec) (%__lock_ptr)
23905+
23906+#ifdef CONFIG_PAX_REFCOUNT
23907+ jno 1234f
23908+ LOCK_PREFIX
23909+ READ_LOCK_SIZE(inc) (%__lock_ptr)
23910+ int $4
23911+1234:
23912+ _ASM_EXTABLE(1234b, 1234b)
23913+#endif
23914+
23915 js 0b
23916 ENDFRAME
23917+ pax_force_retaddr
23918 ret
23919 CFI_ENDPROC
23920 END(__read_lock_failed)
23921diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
23922index 5dff5f0..cadebf4 100644
23923--- a/arch/x86/lib/rwsem.S
23924+++ b/arch/x86/lib/rwsem.S
23925@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
23926 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
23927 CFI_RESTORE __ASM_REG(dx)
23928 restore_common_regs
23929+ pax_force_retaddr
23930 ret
23931 CFI_ENDPROC
23932 ENDPROC(call_rwsem_down_read_failed)
23933@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
23934 movq %rax,%rdi
23935 call rwsem_down_write_failed
23936 restore_common_regs
23937+ pax_force_retaddr
23938 ret
23939 CFI_ENDPROC
23940 ENDPROC(call_rwsem_down_write_failed)
23941@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
23942 movq %rax,%rdi
23943 call rwsem_wake
23944 restore_common_regs
23945-1: ret
23946+1: pax_force_retaddr
23947+ ret
23948 CFI_ENDPROC
23949 ENDPROC(call_rwsem_wake)
23950
23951@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
23952 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
23953 CFI_RESTORE __ASM_REG(dx)
23954 restore_common_regs
23955+ pax_force_retaddr
23956 ret
23957 CFI_ENDPROC
23958 ENDPROC(call_rwsem_downgrade_wake)
23959diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
23960index a63efd6..ccecad8 100644
23961--- a/arch/x86/lib/thunk_64.S
23962+++ b/arch/x86/lib/thunk_64.S
23963@@ -8,6 +8,7 @@
23964 #include <linux/linkage.h>
23965 #include <asm/dwarf2.h>
23966 #include <asm/calling.h>
23967+#include <asm/alternative-asm.h>
23968
23969 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
23970 .macro THUNK name, func, put_ret_addr_in_rdi=0
23971@@ -41,5 +42,6 @@
23972 SAVE_ARGS
23973 restore:
23974 RESTORE_ARGS
23975+ pax_force_retaddr
23976 ret
23977 CFI_ENDPROC
23978diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
23979index 98f6d6b6..d27f045 100644
23980--- a/arch/x86/lib/usercopy_32.c
23981+++ b/arch/x86/lib/usercopy_32.c
23982@@ -42,11 +42,13 @@ do { \
23983 int __d0; \
23984 might_fault(); \
23985 __asm__ __volatile__( \
23986+ __COPYUSER_SET_ES \
23987 ASM_STAC "\n" \
23988 "0: rep; stosl\n" \
23989 " movl %2,%0\n" \
23990 "1: rep; stosb\n" \
23991 "2: " ASM_CLAC "\n" \
23992+ __COPYUSER_RESTORE_ES \
23993 ".section .fixup,\"ax\"\n" \
23994 "3: lea 0(%2,%0,4),%0\n" \
23995 " jmp 2b\n" \
23996@@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
23997
23998 #ifdef CONFIG_X86_INTEL_USERCOPY
23999 static unsigned long
24000-__copy_user_intel(void __user *to, const void *from, unsigned long size)
24001+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
24002 {
24003 int d0, d1;
24004 __asm__ __volatile__(
24005@@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
24006 " .align 2,0x90\n"
24007 "3: movl 0(%4), %%eax\n"
24008 "4: movl 4(%4), %%edx\n"
24009- "5: movl %%eax, 0(%3)\n"
24010- "6: movl %%edx, 4(%3)\n"
24011+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
24012+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
24013 "7: movl 8(%4), %%eax\n"
24014 "8: movl 12(%4),%%edx\n"
24015- "9: movl %%eax, 8(%3)\n"
24016- "10: movl %%edx, 12(%3)\n"
24017+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
24018+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
24019 "11: movl 16(%4), %%eax\n"
24020 "12: movl 20(%4), %%edx\n"
24021- "13: movl %%eax, 16(%3)\n"
24022- "14: movl %%edx, 20(%3)\n"
24023+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
24024+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
24025 "15: movl 24(%4), %%eax\n"
24026 "16: movl 28(%4), %%edx\n"
24027- "17: movl %%eax, 24(%3)\n"
24028- "18: movl %%edx, 28(%3)\n"
24029+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
24030+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
24031 "19: movl 32(%4), %%eax\n"
24032 "20: movl 36(%4), %%edx\n"
24033- "21: movl %%eax, 32(%3)\n"
24034- "22: movl %%edx, 36(%3)\n"
24035+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
24036+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
24037 "23: movl 40(%4), %%eax\n"
24038 "24: movl 44(%4), %%edx\n"
24039- "25: movl %%eax, 40(%3)\n"
24040- "26: movl %%edx, 44(%3)\n"
24041+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
24042+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
24043 "27: movl 48(%4), %%eax\n"
24044 "28: movl 52(%4), %%edx\n"
24045- "29: movl %%eax, 48(%3)\n"
24046- "30: movl %%edx, 52(%3)\n"
24047+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
24048+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
24049 "31: movl 56(%4), %%eax\n"
24050 "32: movl 60(%4), %%edx\n"
24051- "33: movl %%eax, 56(%3)\n"
24052- "34: movl %%edx, 60(%3)\n"
24053+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
24054+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
24055 " addl $-64, %0\n"
24056 " addl $64, %4\n"
24057 " addl $64, %3\n"
24058@@ -149,10 +151,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
24059 " shrl $2, %0\n"
24060 " andl $3, %%eax\n"
24061 " cld\n"
24062+ __COPYUSER_SET_ES
24063 "99: rep; movsl\n"
24064 "36: movl %%eax, %0\n"
24065 "37: rep; movsb\n"
24066 "100:\n"
24067+ __COPYUSER_RESTORE_ES
24068 ".section .fixup,\"ax\"\n"
24069 "101: lea 0(%%eax,%0,4),%0\n"
24070 " jmp 100b\n"
24071@@ -202,46 +206,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
24072 }
24073
24074 static unsigned long
24075+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
24076+{
24077+ int d0, d1;
24078+ __asm__ __volatile__(
24079+ " .align 2,0x90\n"
24080+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
24081+ " cmpl $67, %0\n"
24082+ " jbe 3f\n"
24083+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
24084+ " .align 2,0x90\n"
24085+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
24086+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
24087+ "5: movl %%eax, 0(%3)\n"
24088+ "6: movl %%edx, 4(%3)\n"
24089+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
24090+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
24091+ "9: movl %%eax, 8(%3)\n"
24092+ "10: movl %%edx, 12(%3)\n"
24093+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
24094+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
24095+ "13: movl %%eax, 16(%3)\n"
24096+ "14: movl %%edx, 20(%3)\n"
24097+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
24098+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
24099+ "17: movl %%eax, 24(%3)\n"
24100+ "18: movl %%edx, 28(%3)\n"
24101+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
24102+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
24103+ "21: movl %%eax, 32(%3)\n"
24104+ "22: movl %%edx, 36(%3)\n"
24105+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
24106+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
24107+ "25: movl %%eax, 40(%3)\n"
24108+ "26: movl %%edx, 44(%3)\n"
24109+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
24110+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
24111+ "29: movl %%eax, 48(%3)\n"
24112+ "30: movl %%edx, 52(%3)\n"
24113+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
24114+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
24115+ "33: movl %%eax, 56(%3)\n"
24116+ "34: movl %%edx, 60(%3)\n"
24117+ " addl $-64, %0\n"
24118+ " addl $64, %4\n"
24119+ " addl $64, %3\n"
24120+ " cmpl $63, %0\n"
24121+ " ja 1b\n"
24122+ "35: movl %0, %%eax\n"
24123+ " shrl $2, %0\n"
24124+ " andl $3, %%eax\n"
24125+ " cld\n"
24126+ "99: rep; "__copyuser_seg" movsl\n"
24127+ "36: movl %%eax, %0\n"
24128+ "37: rep; "__copyuser_seg" movsb\n"
24129+ "100:\n"
24130+ ".section .fixup,\"ax\"\n"
24131+ "101: lea 0(%%eax,%0,4),%0\n"
24132+ " jmp 100b\n"
24133+ ".previous\n"
24134+ _ASM_EXTABLE(1b,100b)
24135+ _ASM_EXTABLE(2b,100b)
24136+ _ASM_EXTABLE(3b,100b)
24137+ _ASM_EXTABLE(4b,100b)
24138+ _ASM_EXTABLE(5b,100b)
24139+ _ASM_EXTABLE(6b,100b)
24140+ _ASM_EXTABLE(7b,100b)
24141+ _ASM_EXTABLE(8b,100b)
24142+ _ASM_EXTABLE(9b,100b)
24143+ _ASM_EXTABLE(10b,100b)
24144+ _ASM_EXTABLE(11b,100b)
24145+ _ASM_EXTABLE(12b,100b)
24146+ _ASM_EXTABLE(13b,100b)
24147+ _ASM_EXTABLE(14b,100b)
24148+ _ASM_EXTABLE(15b,100b)
24149+ _ASM_EXTABLE(16b,100b)
24150+ _ASM_EXTABLE(17b,100b)
24151+ _ASM_EXTABLE(18b,100b)
24152+ _ASM_EXTABLE(19b,100b)
24153+ _ASM_EXTABLE(20b,100b)
24154+ _ASM_EXTABLE(21b,100b)
24155+ _ASM_EXTABLE(22b,100b)
24156+ _ASM_EXTABLE(23b,100b)
24157+ _ASM_EXTABLE(24b,100b)
24158+ _ASM_EXTABLE(25b,100b)
24159+ _ASM_EXTABLE(26b,100b)
24160+ _ASM_EXTABLE(27b,100b)
24161+ _ASM_EXTABLE(28b,100b)
24162+ _ASM_EXTABLE(29b,100b)
24163+ _ASM_EXTABLE(30b,100b)
24164+ _ASM_EXTABLE(31b,100b)
24165+ _ASM_EXTABLE(32b,100b)
24166+ _ASM_EXTABLE(33b,100b)
24167+ _ASM_EXTABLE(34b,100b)
24168+ _ASM_EXTABLE(35b,100b)
24169+ _ASM_EXTABLE(36b,100b)
24170+ _ASM_EXTABLE(37b,100b)
24171+ _ASM_EXTABLE(99b,101b)
24172+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
24173+ : "1"(to), "2"(from), "0"(size)
24174+ : "eax", "edx", "memory");
24175+ return size;
24176+}
24177+
24178+static unsigned long __size_overflow(3)
24179 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
24180 {
24181 int d0, d1;
24182 __asm__ __volatile__(
24183 " .align 2,0x90\n"
24184- "0: movl 32(%4), %%eax\n"
24185+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
24186 " cmpl $67, %0\n"
24187 " jbe 2f\n"
24188- "1: movl 64(%4), %%eax\n"
24189+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
24190 " .align 2,0x90\n"
24191- "2: movl 0(%4), %%eax\n"
24192- "21: movl 4(%4), %%edx\n"
24193+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
24194+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
24195 " movl %%eax, 0(%3)\n"
24196 " movl %%edx, 4(%3)\n"
24197- "3: movl 8(%4), %%eax\n"
24198- "31: movl 12(%4),%%edx\n"
24199+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
24200+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
24201 " movl %%eax, 8(%3)\n"
24202 " movl %%edx, 12(%3)\n"
24203- "4: movl 16(%4), %%eax\n"
24204- "41: movl 20(%4), %%edx\n"
24205+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
24206+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
24207 " movl %%eax, 16(%3)\n"
24208 " movl %%edx, 20(%3)\n"
24209- "10: movl 24(%4), %%eax\n"
24210- "51: movl 28(%4), %%edx\n"
24211+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
24212+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
24213 " movl %%eax, 24(%3)\n"
24214 " movl %%edx, 28(%3)\n"
24215- "11: movl 32(%4), %%eax\n"
24216- "61: movl 36(%4), %%edx\n"
24217+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
24218+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
24219 " movl %%eax, 32(%3)\n"
24220 " movl %%edx, 36(%3)\n"
24221- "12: movl 40(%4), %%eax\n"
24222- "71: movl 44(%4), %%edx\n"
24223+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
24224+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
24225 " movl %%eax, 40(%3)\n"
24226 " movl %%edx, 44(%3)\n"
24227- "13: movl 48(%4), %%eax\n"
24228- "81: movl 52(%4), %%edx\n"
24229+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
24230+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
24231 " movl %%eax, 48(%3)\n"
24232 " movl %%edx, 52(%3)\n"
24233- "14: movl 56(%4), %%eax\n"
24234- "91: movl 60(%4), %%edx\n"
24235+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
24236+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
24237 " movl %%eax, 56(%3)\n"
24238 " movl %%edx, 60(%3)\n"
24239 " addl $-64, %0\n"
24240@@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
24241 " shrl $2, %0\n"
24242 " andl $3, %%eax\n"
24243 " cld\n"
24244- "6: rep; movsl\n"
24245+ "6: rep; "__copyuser_seg" movsl\n"
24246 " movl %%eax,%0\n"
24247- "7: rep; movsb\n"
24248+ "7: rep; "__copyuser_seg" movsb\n"
24249 "8:\n"
24250 ".section .fixup,\"ax\"\n"
24251 "9: lea 0(%%eax,%0,4),%0\n"
24252@@ -298,48 +406,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
24253 * hyoshiok@miraclelinux.com
24254 */
24255
24256-static unsigned long __copy_user_zeroing_intel_nocache(void *to,
24257+static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
24258 const void __user *from, unsigned long size)
24259 {
24260 int d0, d1;
24261
24262 __asm__ __volatile__(
24263 " .align 2,0x90\n"
24264- "0: movl 32(%4), %%eax\n"
24265+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
24266 " cmpl $67, %0\n"
24267 " jbe 2f\n"
24268- "1: movl 64(%4), %%eax\n"
24269+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
24270 " .align 2,0x90\n"
24271- "2: movl 0(%4), %%eax\n"
24272- "21: movl 4(%4), %%edx\n"
24273+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
24274+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
24275 " movnti %%eax, 0(%3)\n"
24276 " movnti %%edx, 4(%3)\n"
24277- "3: movl 8(%4), %%eax\n"
24278- "31: movl 12(%4),%%edx\n"
24279+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
24280+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
24281 " movnti %%eax, 8(%3)\n"
24282 " movnti %%edx, 12(%3)\n"
24283- "4: movl 16(%4), %%eax\n"
24284- "41: movl 20(%4), %%edx\n"
24285+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
24286+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
24287 " movnti %%eax, 16(%3)\n"
24288 " movnti %%edx, 20(%3)\n"
24289- "10: movl 24(%4), %%eax\n"
24290- "51: movl 28(%4), %%edx\n"
24291+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
24292+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
24293 " movnti %%eax, 24(%3)\n"
24294 " movnti %%edx, 28(%3)\n"
24295- "11: movl 32(%4), %%eax\n"
24296- "61: movl 36(%4), %%edx\n"
24297+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
24298+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
24299 " movnti %%eax, 32(%3)\n"
24300 " movnti %%edx, 36(%3)\n"
24301- "12: movl 40(%4), %%eax\n"
24302- "71: movl 44(%4), %%edx\n"
24303+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
24304+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
24305 " movnti %%eax, 40(%3)\n"
24306 " movnti %%edx, 44(%3)\n"
24307- "13: movl 48(%4), %%eax\n"
24308- "81: movl 52(%4), %%edx\n"
24309+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
24310+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
24311 " movnti %%eax, 48(%3)\n"
24312 " movnti %%edx, 52(%3)\n"
24313- "14: movl 56(%4), %%eax\n"
24314- "91: movl 60(%4), %%edx\n"
24315+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
24316+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
24317 " movnti %%eax, 56(%3)\n"
24318 " movnti %%edx, 60(%3)\n"
24319 " addl $-64, %0\n"
24320@@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
24321 " shrl $2, %0\n"
24322 " andl $3, %%eax\n"
24323 " cld\n"
24324- "6: rep; movsl\n"
24325+ "6: rep; "__copyuser_seg" movsl\n"
24326 " movl %%eax,%0\n"
24327- "7: rep; movsb\n"
24328+ "7: rep; "__copyuser_seg" movsb\n"
24329 "8:\n"
24330 ".section .fixup,\"ax\"\n"
24331 "9: lea 0(%%eax,%0,4),%0\n"
24332@@ -392,48 +500,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
24333 return size;
24334 }
24335
24336-static unsigned long __copy_user_intel_nocache(void *to,
24337+static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
24338 const void __user *from, unsigned long size)
24339 {
24340 int d0, d1;
24341
24342 __asm__ __volatile__(
24343 " .align 2,0x90\n"
24344- "0: movl 32(%4), %%eax\n"
24345+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
24346 " cmpl $67, %0\n"
24347 " jbe 2f\n"
24348- "1: movl 64(%4), %%eax\n"
24349+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
24350 " .align 2,0x90\n"
24351- "2: movl 0(%4), %%eax\n"
24352- "21: movl 4(%4), %%edx\n"
24353+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
24354+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
24355 " movnti %%eax, 0(%3)\n"
24356 " movnti %%edx, 4(%3)\n"
24357- "3: movl 8(%4), %%eax\n"
24358- "31: movl 12(%4),%%edx\n"
24359+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
24360+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
24361 " movnti %%eax, 8(%3)\n"
24362 " movnti %%edx, 12(%3)\n"
24363- "4: movl 16(%4), %%eax\n"
24364- "41: movl 20(%4), %%edx\n"
24365+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
24366+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
24367 " movnti %%eax, 16(%3)\n"
24368 " movnti %%edx, 20(%3)\n"
24369- "10: movl 24(%4), %%eax\n"
24370- "51: movl 28(%4), %%edx\n"
24371+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
24372+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
24373 " movnti %%eax, 24(%3)\n"
24374 " movnti %%edx, 28(%3)\n"
24375- "11: movl 32(%4), %%eax\n"
24376- "61: movl 36(%4), %%edx\n"
24377+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
24378+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
24379 " movnti %%eax, 32(%3)\n"
24380 " movnti %%edx, 36(%3)\n"
24381- "12: movl 40(%4), %%eax\n"
24382- "71: movl 44(%4), %%edx\n"
24383+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
24384+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
24385 " movnti %%eax, 40(%3)\n"
24386 " movnti %%edx, 44(%3)\n"
24387- "13: movl 48(%4), %%eax\n"
24388- "81: movl 52(%4), %%edx\n"
24389+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
24390+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
24391 " movnti %%eax, 48(%3)\n"
24392 " movnti %%edx, 52(%3)\n"
24393- "14: movl 56(%4), %%eax\n"
24394- "91: movl 60(%4), %%edx\n"
24395+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
24396+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
24397 " movnti %%eax, 56(%3)\n"
24398 " movnti %%edx, 60(%3)\n"
24399 " addl $-64, %0\n"
24400@@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
24401 " shrl $2, %0\n"
24402 " andl $3, %%eax\n"
24403 " cld\n"
24404- "6: rep; movsl\n"
24405+ "6: rep; "__copyuser_seg" movsl\n"
24406 " movl %%eax,%0\n"
24407- "7: rep; movsb\n"
24408+ "7: rep; "__copyuser_seg" movsb\n"
24409 "8:\n"
24410 ".section .fixup,\"ax\"\n"
24411 "9: lea 0(%%eax,%0,4),%0\n"
24412@@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
24413 */
24414 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
24415 unsigned long size);
24416-unsigned long __copy_user_intel(void __user *to, const void *from,
24417+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
24418+ unsigned long size);
24419+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
24420 unsigned long size);
24421 unsigned long __copy_user_zeroing_intel_nocache(void *to,
24422 const void __user *from, unsigned long size);
24423 #endif /* CONFIG_X86_INTEL_USERCOPY */
24424
24425 /* Generic arbitrary sized copy. */
24426-#define __copy_user(to, from, size) \
24427+#define __copy_user(to, from, size, prefix, set, restore) \
24428 do { \
24429 int __d0, __d1, __d2; \
24430 __asm__ __volatile__( \
24431+ set \
24432 " cmp $7,%0\n" \
24433 " jbe 1f\n" \
24434 " movl %1,%0\n" \
24435 " negl %0\n" \
24436 " andl $7,%0\n" \
24437 " subl %0,%3\n" \
24438- "4: rep; movsb\n" \
24439+ "4: rep; "prefix"movsb\n" \
24440 " movl %3,%0\n" \
24441 " shrl $2,%0\n" \
24442 " andl $3,%3\n" \
24443 " .align 2,0x90\n" \
24444- "0: rep; movsl\n" \
24445+ "0: rep; "prefix"movsl\n" \
24446 " movl %3,%0\n" \
24447- "1: rep; movsb\n" \
24448+ "1: rep; "prefix"movsb\n" \
24449 "2:\n" \
24450+ restore \
24451 ".section .fixup,\"ax\"\n" \
24452 "5: addl %3,%0\n" \
24453 " jmp 2b\n" \
24454@@ -538,14 +650,14 @@ do { \
24455 " negl %0\n" \
24456 " andl $7,%0\n" \
24457 " subl %0,%3\n" \
24458- "4: rep; movsb\n" \
24459+ "4: rep; "__copyuser_seg"movsb\n" \
24460 " movl %3,%0\n" \
24461 " shrl $2,%0\n" \
24462 " andl $3,%3\n" \
24463 " .align 2,0x90\n" \
24464- "0: rep; movsl\n" \
24465+ "0: rep; "__copyuser_seg"movsl\n" \
24466 " movl %3,%0\n" \
24467- "1: rep; movsb\n" \
24468+ "1: rep; "__copyuser_seg"movsb\n" \
24469 "2:\n" \
24470 ".section .fixup,\"ax\"\n" \
24471 "5: addl %3,%0\n" \
24472@@ -629,9 +741,9 @@ survive:
24473 #endif
24474 stac();
24475 if (movsl_is_ok(to, from, n))
24476- __copy_user(to, from, n);
24477+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
24478 else
24479- n = __copy_user_intel(to, from, n);
24480+ n = __generic_copy_to_user_intel(to, from, n);
24481 clac();
24482 return n;
24483 }
24484@@ -655,10 +767,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
24485 {
24486 stac();
24487 if (movsl_is_ok(to, from, n))
24488- __copy_user(to, from, n);
24489+ __copy_user(to, from, n, __copyuser_seg, "", "");
24490 else
24491- n = __copy_user_intel((void __user *)to,
24492- (const void *)from, n);
24493+ n = __generic_copy_from_user_intel(to, from, n);
24494 clac();
24495 return n;
24496 }
24497@@ -689,66 +800,51 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
24498 if (n > 64 && cpu_has_xmm2)
24499 n = __copy_user_intel_nocache(to, from, n);
24500 else
24501- __copy_user(to, from, n);
24502+ __copy_user(to, from, n, __copyuser_seg, "", "");
24503 #else
24504- __copy_user(to, from, n);
24505+ __copy_user(to, from, n, __copyuser_seg, "", "");
24506 #endif
24507 clac();
24508 return n;
24509 }
24510 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
24511
24512-/**
24513- * copy_to_user: - Copy a block of data into user space.
24514- * @to: Destination address, in user space.
24515- * @from: Source address, in kernel space.
24516- * @n: Number of bytes to copy.
24517- *
24518- * Context: User context only. This function may sleep.
24519- *
24520- * Copy data from kernel space to user space.
24521- *
24522- * Returns number of bytes that could not be copied.
24523- * On success, this will be zero.
24524- */
24525-unsigned long
24526-copy_to_user(void __user *to, const void *from, unsigned long n)
24527-{
24528- if (access_ok(VERIFY_WRITE, to, n))
24529- n = __copy_to_user(to, from, n);
24530- return n;
24531-}
24532-EXPORT_SYMBOL(copy_to_user);
24533-
24534-/**
24535- * copy_from_user: - Copy a block of data from user space.
24536- * @to: Destination address, in kernel space.
24537- * @from: Source address, in user space.
24538- * @n: Number of bytes to copy.
24539- *
24540- * Context: User context only. This function may sleep.
24541- *
24542- * Copy data from user space to kernel space.
24543- *
24544- * Returns number of bytes that could not be copied.
24545- * On success, this will be zero.
24546- *
24547- * If some data could not be copied, this function will pad the copied
24548- * data to the requested size using zero bytes.
24549- */
24550-unsigned long
24551-_copy_from_user(void *to, const void __user *from, unsigned long n)
24552-{
24553- if (access_ok(VERIFY_READ, from, n))
24554- n = __copy_from_user(to, from, n);
24555- else
24556- memset(to, 0, n);
24557- return n;
24558-}
24559-EXPORT_SYMBOL(_copy_from_user);
24560-
24561 void copy_from_user_overflow(void)
24562 {
24563 WARN(1, "Buffer overflow detected!\n");
24564 }
24565 EXPORT_SYMBOL(copy_from_user_overflow);
24566+
24567+void copy_to_user_overflow(void)
24568+{
24569+ WARN(1, "Buffer overflow detected!\n");
24570+}
24571+EXPORT_SYMBOL(copy_to_user_overflow);
24572+
24573+#ifdef CONFIG_PAX_MEMORY_UDEREF
24574+void __set_fs(mm_segment_t x)
24575+{
24576+ switch (x.seg) {
24577+ case 0:
24578+ loadsegment(gs, 0);
24579+ break;
24580+ case TASK_SIZE_MAX:
24581+ loadsegment(gs, __USER_DS);
24582+ break;
24583+ case -1UL:
24584+ loadsegment(gs, __KERNEL_DS);
24585+ break;
24586+ default:
24587+ BUG();
24588+ }
24589+ return;
24590+}
24591+EXPORT_SYMBOL(__set_fs);
24592+
24593+void set_fs(mm_segment_t x)
24594+{
24595+ current_thread_info()->addr_limit = x;
24596+ __set_fs(x);
24597+}
24598+EXPORT_SYMBOL(set_fs);
24599+#endif
24600diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
24601index 05928aa..b33dea1 100644
24602--- a/arch/x86/lib/usercopy_64.c
24603+++ b/arch/x86/lib/usercopy_64.c
24604@@ -39,7 +39,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
24605 _ASM_EXTABLE(0b,3b)
24606 _ASM_EXTABLE(1b,2b)
24607 : [size8] "=&c"(size), [dst] "=&D" (__d0)
24608- : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
24609+ : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
24610 [zero] "r" (0UL), [eight] "r" (8UL));
24611 clac();
24612 return size;
24613@@ -54,12 +54,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
24614 }
24615 EXPORT_SYMBOL(clear_user);
24616
24617-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
24618+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
24619 {
24620- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
24621- return copy_user_generic((__force void *)to, (__force void *)from, len);
24622- }
24623- return len;
24624+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
24625+ return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
24626+ return len;
24627 }
24628 EXPORT_SYMBOL(copy_in_user);
24629
24630@@ -69,7 +68,7 @@ EXPORT_SYMBOL(copy_in_user);
24631 * it is not necessary to optimize tail handling.
24632 */
24633 unsigned long
24634-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
24635+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
24636 {
24637 char c;
24638 unsigned zero_len;
24639@@ -87,3 +86,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
24640 clac();
24641 return len;
24642 }
24643+
24644+void copy_from_user_overflow(void)
24645+{
24646+ WARN(1, "Buffer overflow detected!\n");
24647+}
24648+EXPORT_SYMBOL(copy_from_user_overflow);
24649+
24650+void copy_to_user_overflow(void)
24651+{
24652+ WARN(1, "Buffer overflow detected!\n");
24653+}
24654+EXPORT_SYMBOL(copy_to_user_overflow);
24655diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
24656index 903ec1e..c4166b2 100644
24657--- a/arch/x86/mm/extable.c
24658+++ b/arch/x86/mm/extable.c
24659@@ -6,12 +6,24 @@
24660 static inline unsigned long
24661 ex_insn_addr(const struct exception_table_entry *x)
24662 {
24663- return (unsigned long)&x->insn + x->insn;
24664+ unsigned long reloc = 0;
24665+
24666+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
24667+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
24668+#endif
24669+
24670+ return (unsigned long)&x->insn + x->insn + reloc;
24671 }
24672 static inline unsigned long
24673 ex_fixup_addr(const struct exception_table_entry *x)
24674 {
24675- return (unsigned long)&x->fixup + x->fixup;
24676+ unsigned long reloc = 0;
24677+
24678+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
24679+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
24680+#endif
24681+
24682+ return (unsigned long)&x->fixup + x->fixup + reloc;
24683 }
24684
24685 int fixup_exception(struct pt_regs *regs)
24686@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
24687 unsigned long new_ip;
24688
24689 #ifdef CONFIG_PNPBIOS
24690- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
24691+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
24692 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
24693 extern u32 pnp_bios_is_utter_crap;
24694 pnp_bios_is_utter_crap = 1;
24695@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
24696 i += 4;
24697 p->fixup -= i;
24698 i += 4;
24699+
24700+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
24701+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
24702+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
24703+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
24704+#endif
24705+
24706 }
24707 }
24708
24709diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
24710index 8e13ecb..831f2d0 100644
24711--- a/arch/x86/mm/fault.c
24712+++ b/arch/x86/mm/fault.c
24713@@ -13,12 +13,19 @@
24714 #include <linux/perf_event.h> /* perf_sw_event */
24715 #include <linux/hugetlb.h> /* hstate_index_to_shift */
24716 #include <linux/prefetch.h> /* prefetchw */
24717+#include <linux/unistd.h>
24718+#include <linux/compiler.h>
24719
24720 #include <asm/traps.h> /* dotraplinkage, ... */
24721 #include <asm/pgalloc.h> /* pgd_*(), ... */
24722 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
24723 #include <asm/fixmap.h> /* VSYSCALL_START */
24724 #include <asm/rcu.h> /* exception_enter(), ... */
24725+#include <asm/tlbflush.h>
24726+
24727+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24728+#include <asm/stacktrace.h>
24729+#endif
24730
24731 /*
24732 * Page fault error code bits:
24733@@ -56,7 +63,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
24734 int ret = 0;
24735
24736 /* kprobe_running() needs smp_processor_id() */
24737- if (kprobes_built_in() && !user_mode_vm(regs)) {
24738+ if (kprobes_built_in() && !user_mode(regs)) {
24739 preempt_disable();
24740 if (kprobe_running() && kprobe_fault_handler(regs, 14))
24741 ret = 1;
24742@@ -117,7 +124,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
24743 return !instr_lo || (instr_lo>>1) == 1;
24744 case 0x00:
24745 /* Prefetch instruction is 0x0F0D or 0x0F18 */
24746- if (probe_kernel_address(instr, opcode))
24747+ if (user_mode(regs)) {
24748+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
24749+ return 0;
24750+ } else if (probe_kernel_address(instr, opcode))
24751 return 0;
24752
24753 *prefetch = (instr_lo == 0xF) &&
24754@@ -151,7 +161,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
24755 while (instr < max_instr) {
24756 unsigned char opcode;
24757
24758- if (probe_kernel_address(instr, opcode))
24759+ if (user_mode(regs)) {
24760+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
24761+ break;
24762+ } else if (probe_kernel_address(instr, opcode))
24763 break;
24764
24765 instr++;
24766@@ -182,6 +195,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
24767 force_sig_info(si_signo, &info, tsk);
24768 }
24769
24770+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24771+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
24772+#endif
24773+
24774+#ifdef CONFIG_PAX_EMUTRAMP
24775+static int pax_handle_fetch_fault(struct pt_regs *regs);
24776+#endif
24777+
24778+#ifdef CONFIG_PAX_PAGEEXEC
24779+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
24780+{
24781+ pgd_t *pgd;
24782+ pud_t *pud;
24783+ pmd_t *pmd;
24784+
24785+ pgd = pgd_offset(mm, address);
24786+ if (!pgd_present(*pgd))
24787+ return NULL;
24788+ pud = pud_offset(pgd, address);
24789+ if (!pud_present(*pud))
24790+ return NULL;
24791+ pmd = pmd_offset(pud, address);
24792+ if (!pmd_present(*pmd))
24793+ return NULL;
24794+ return pmd;
24795+}
24796+#endif
24797+
24798 DEFINE_SPINLOCK(pgd_lock);
24799 LIST_HEAD(pgd_list);
24800
24801@@ -232,10 +273,22 @@ void vmalloc_sync_all(void)
24802 for (address = VMALLOC_START & PMD_MASK;
24803 address >= TASK_SIZE && address < FIXADDR_TOP;
24804 address += PMD_SIZE) {
24805+
24806+#ifdef CONFIG_PAX_PER_CPU_PGD
24807+ unsigned long cpu;
24808+#else
24809 struct page *page;
24810+#endif
24811
24812 spin_lock(&pgd_lock);
24813+
24814+#ifdef CONFIG_PAX_PER_CPU_PGD
24815+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
24816+ pgd_t *pgd = get_cpu_pgd(cpu);
24817+ pmd_t *ret;
24818+#else
24819 list_for_each_entry(page, &pgd_list, lru) {
24820+ pgd_t *pgd = page_address(page);
24821 spinlock_t *pgt_lock;
24822 pmd_t *ret;
24823
24824@@ -243,8 +296,13 @@ void vmalloc_sync_all(void)
24825 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
24826
24827 spin_lock(pgt_lock);
24828- ret = vmalloc_sync_one(page_address(page), address);
24829+#endif
24830+
24831+ ret = vmalloc_sync_one(pgd, address);
24832+
24833+#ifndef CONFIG_PAX_PER_CPU_PGD
24834 spin_unlock(pgt_lock);
24835+#endif
24836
24837 if (!ret)
24838 break;
24839@@ -278,6 +336,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
24840 * an interrupt in the middle of a task switch..
24841 */
24842 pgd_paddr = read_cr3();
24843+
24844+#ifdef CONFIG_PAX_PER_CPU_PGD
24845+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
24846+#endif
24847+
24848 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
24849 if (!pmd_k)
24850 return -1;
24851@@ -373,7 +436,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
24852 * happen within a race in page table update. In the later
24853 * case just flush:
24854 */
24855+
24856+#ifdef CONFIG_PAX_PER_CPU_PGD
24857+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
24858+ pgd = pgd_offset_cpu(smp_processor_id(), address);
24859+#else
24860 pgd = pgd_offset(current->active_mm, address);
24861+#endif
24862+
24863 pgd_ref = pgd_offset_k(address);
24864 if (pgd_none(*pgd_ref))
24865 return -1;
24866@@ -541,7 +611,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
24867 static int is_errata100(struct pt_regs *regs, unsigned long address)
24868 {
24869 #ifdef CONFIG_X86_64
24870- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
24871+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
24872 return 1;
24873 #endif
24874 return 0;
24875@@ -568,7 +638,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
24876 }
24877
24878 static const char nx_warning[] = KERN_CRIT
24879-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
24880+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
24881
24882 static void
24883 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
24884@@ -577,15 +647,26 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
24885 if (!oops_may_print())
24886 return;
24887
24888- if (error_code & PF_INSTR) {
24889+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
24890 unsigned int level;
24891
24892 pte_t *pte = lookup_address(address, &level);
24893
24894 if (pte && pte_present(*pte) && !pte_exec(*pte))
24895- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
24896+ printk(nx_warning, from_kuid(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
24897 }
24898
24899+#ifdef CONFIG_PAX_KERNEXEC
24900+ if (init_mm.start_code <= address && address < init_mm.end_code) {
24901+ if (current->signal->curr_ip)
24902+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
24903+ &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
24904+ else
24905+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
24906+ current->comm, task_pid_nr(current), current_uid(), current_euid());
24907+ }
24908+#endif
24909+
24910 printk(KERN_ALERT "BUG: unable to handle kernel ");
24911 if (address < PAGE_SIZE)
24912 printk(KERN_CONT "NULL pointer dereference");
24913@@ -749,6 +830,21 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
24914 }
24915 #endif
24916
24917+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24918+ if (pax_is_fetch_fault(regs, error_code, address)) {
24919+
24920+#ifdef CONFIG_PAX_EMUTRAMP
24921+ switch (pax_handle_fetch_fault(regs)) {
24922+ case 2:
24923+ return;
24924+ }
24925+#endif
24926+
24927+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
24928+ do_group_exit(SIGKILL);
24929+ }
24930+#endif
24931+
24932 if (unlikely(show_unhandled_signals))
24933 show_signal_msg(regs, error_code, address, tsk);
24934
24935@@ -845,7 +941,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
24936 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
24937 printk(KERN_ERR
24938 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
24939- tsk->comm, tsk->pid, address);
24940+ tsk->comm, task_pid_nr(tsk), address);
24941 code = BUS_MCEERR_AR;
24942 }
24943 #endif
24944@@ -901,6 +997,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
24945 return 1;
24946 }
24947
24948+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
24949+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
24950+{
24951+ pte_t *pte;
24952+ pmd_t *pmd;
24953+ spinlock_t *ptl;
24954+ unsigned char pte_mask;
24955+
24956+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
24957+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
24958+ return 0;
24959+
24960+ /* PaX: it's our fault, let's handle it if we can */
24961+
24962+ /* PaX: take a look at read faults before acquiring any locks */
24963+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
24964+ /* instruction fetch attempt from a protected page in user mode */
24965+ up_read(&mm->mmap_sem);
24966+
24967+#ifdef CONFIG_PAX_EMUTRAMP
24968+ switch (pax_handle_fetch_fault(regs)) {
24969+ case 2:
24970+ return 1;
24971+ }
24972+#endif
24973+
24974+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
24975+ do_group_exit(SIGKILL);
24976+ }
24977+
24978+ pmd = pax_get_pmd(mm, address);
24979+ if (unlikely(!pmd))
24980+ return 0;
24981+
24982+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
24983+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
24984+ pte_unmap_unlock(pte, ptl);
24985+ return 0;
24986+ }
24987+
24988+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
24989+ /* write attempt to a protected page in user mode */
24990+ pte_unmap_unlock(pte, ptl);
24991+ return 0;
24992+ }
24993+
24994+#ifdef CONFIG_SMP
24995+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
24996+#else
24997+ if (likely(address > get_limit(regs->cs)))
24998+#endif
24999+ {
25000+ set_pte(pte, pte_mkread(*pte));
25001+ __flush_tlb_one(address);
25002+ pte_unmap_unlock(pte, ptl);
25003+ up_read(&mm->mmap_sem);
25004+ return 1;
25005+ }
25006+
25007+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
25008+
25009+ /*
25010+ * PaX: fill DTLB with user rights and retry
25011+ */
25012+ __asm__ __volatile__ (
25013+ "orb %2,(%1)\n"
25014+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
25015+/*
25016+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
25017+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
25018+ * page fault when examined during a TLB load attempt. this is true not only
25019+ * for PTEs holding a non-present entry but also present entries that will
25020+ * raise a page fault (such as those set up by PaX, or the copy-on-write
25021+ * mechanism). in effect it means that we do *not* need to flush the TLBs
25022+ * for our target pages since their PTEs are simply not in the TLBs at all.
25023+
25024+ * the best thing in omitting it is that we gain around 15-20% speed in the
25025+ * fast path of the page fault handler and can get rid of tracing since we
25026+ * can no longer flush unintended entries.
25027+ */
25028+ "invlpg (%0)\n"
25029+#endif
25030+ __copyuser_seg"testb $0,(%0)\n"
25031+ "xorb %3,(%1)\n"
25032+ :
25033+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
25034+ : "memory", "cc");
25035+ pte_unmap_unlock(pte, ptl);
25036+ up_read(&mm->mmap_sem);
25037+ return 1;
25038+}
25039+#endif
25040+
25041 /*
25042 * Handle a spurious fault caused by a stale TLB entry.
25043 *
25044@@ -973,6 +1162,9 @@ int show_unhandled_signals = 1;
25045 static inline int
25046 access_error(unsigned long error_code, struct vm_area_struct *vma)
25047 {
25048+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
25049+ return 1;
25050+
25051 if (error_code & PF_WRITE) {
25052 /* write, present and write, not present: */
25053 if (unlikely(!(vma->vm_flags & VM_WRITE)))
25054@@ -1001,7 +1193,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
25055 if (error_code & PF_USER)
25056 return false;
25057
25058- if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
25059+ if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
25060 return false;
25061
25062 return true;
25063@@ -1017,18 +1209,33 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
25064 {
25065 struct vm_area_struct *vma;
25066 struct task_struct *tsk;
25067- unsigned long address;
25068 struct mm_struct *mm;
25069 int fault;
25070 int write = error_code & PF_WRITE;
25071 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
25072 (write ? FAULT_FLAG_WRITE : 0);
25073
25074- tsk = current;
25075- mm = tsk->mm;
25076-
25077 /* Get the faulting address: */
25078- address = read_cr2();
25079+ unsigned long address = read_cr2();
25080+
25081+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25082+ if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
25083+ if (!search_exception_tables(regs->ip)) {
25084+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
25085+ bad_area_nosemaphore(regs, error_code, address);
25086+ return;
25087+ }
25088+ if (address < PAX_USER_SHADOW_BASE) {
25089+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
25090+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
25091+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
25092+ } else
25093+ address -= PAX_USER_SHADOW_BASE;
25094+ }
25095+#endif
25096+
25097+ tsk = current;
25098+ mm = tsk->mm;
25099
25100 /*
25101 * Detect and handle instructions that would cause a page fault for
25102@@ -1089,7 +1296,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
25103 * User-mode registers count as a user access even for any
25104 * potential system fault or CPU buglet:
25105 */
25106- if (user_mode_vm(regs)) {
25107+ if (user_mode(regs)) {
25108 local_irq_enable();
25109 error_code |= PF_USER;
25110 } else {
25111@@ -1151,6 +1358,11 @@ retry:
25112 might_sleep();
25113 }
25114
25115+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
25116+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
25117+ return;
25118+#endif
25119+
25120 vma = find_vma(mm, address);
25121 if (unlikely(!vma)) {
25122 bad_area(regs, error_code, address);
25123@@ -1162,18 +1374,24 @@ retry:
25124 bad_area(regs, error_code, address);
25125 return;
25126 }
25127- if (error_code & PF_USER) {
25128- /*
25129- * Accessing the stack below %sp is always a bug.
25130- * The large cushion allows instructions like enter
25131- * and pusha to work. ("enter $65535, $31" pushes
25132- * 32 pointers and then decrements %sp by 65535.)
25133- */
25134- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
25135- bad_area(regs, error_code, address);
25136- return;
25137- }
25138+ /*
25139+ * Accessing the stack below %sp is always a bug.
25140+ * The large cushion allows instructions like enter
25141+ * and pusha to work. ("enter $65535, $31" pushes
25142+ * 32 pointers and then decrements %sp by 65535.)
25143+ */
25144+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
25145+ bad_area(regs, error_code, address);
25146+ return;
25147 }
25148+
25149+#ifdef CONFIG_PAX_SEGMEXEC
25150+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
25151+ bad_area(regs, error_code, address);
25152+ return;
25153+ }
25154+#endif
25155+
25156 if (unlikely(expand_stack(vma, address))) {
25157 bad_area(regs, error_code, address);
25158 return;
25159@@ -1237,3 +1455,292 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
25160 __do_page_fault(regs, error_code);
25161 exception_exit(regs);
25162 }
25163+
25164+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25165+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
25166+{
25167+ struct mm_struct *mm = current->mm;
25168+ unsigned long ip = regs->ip;
25169+
25170+ if (v8086_mode(regs))
25171+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
25172+
25173+#ifdef CONFIG_PAX_PAGEEXEC
25174+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
25175+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
25176+ return true;
25177+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
25178+ return true;
25179+ return false;
25180+ }
25181+#endif
25182+
25183+#ifdef CONFIG_PAX_SEGMEXEC
25184+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
25185+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
25186+ return true;
25187+ return false;
25188+ }
25189+#endif
25190+
25191+ return false;
25192+}
25193+#endif
25194+
25195+#ifdef CONFIG_PAX_EMUTRAMP
25196+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
25197+{
25198+ int err;
25199+
25200+ do { /* PaX: libffi trampoline emulation */
25201+ unsigned char mov, jmp;
25202+ unsigned int addr1, addr2;
25203+
25204+#ifdef CONFIG_X86_64
25205+ if ((regs->ip + 9) >> 32)
25206+ break;
25207+#endif
25208+
25209+ err = get_user(mov, (unsigned char __user *)regs->ip);
25210+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
25211+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
25212+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
25213+
25214+ if (err)
25215+ break;
25216+
25217+ if (mov == 0xB8 && jmp == 0xE9) {
25218+ regs->ax = addr1;
25219+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
25220+ return 2;
25221+ }
25222+ } while (0);
25223+
25224+ do { /* PaX: gcc trampoline emulation #1 */
25225+ unsigned char mov1, mov2;
25226+ unsigned short jmp;
25227+ unsigned int addr1, addr2;
25228+
25229+#ifdef CONFIG_X86_64
25230+ if ((regs->ip + 11) >> 32)
25231+ break;
25232+#endif
25233+
25234+ err = get_user(mov1, (unsigned char __user *)regs->ip);
25235+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
25236+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
25237+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
25238+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
25239+
25240+ if (err)
25241+ break;
25242+
25243+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
25244+ regs->cx = addr1;
25245+ regs->ax = addr2;
25246+ regs->ip = addr2;
25247+ return 2;
25248+ }
25249+ } while (0);
25250+
25251+ do { /* PaX: gcc trampoline emulation #2 */
25252+ unsigned char mov, jmp;
25253+ unsigned int addr1, addr2;
25254+
25255+#ifdef CONFIG_X86_64
25256+ if ((regs->ip + 9) >> 32)
25257+ break;
25258+#endif
25259+
25260+ err = get_user(mov, (unsigned char __user *)regs->ip);
25261+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
25262+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
25263+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
25264+
25265+ if (err)
25266+ break;
25267+
25268+ if (mov == 0xB9 && jmp == 0xE9) {
25269+ regs->cx = addr1;
25270+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
25271+ return 2;
25272+ }
25273+ } while (0);
25274+
25275+ return 1; /* PaX in action */
25276+}
25277+
25278+#ifdef CONFIG_X86_64
25279+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
25280+{
25281+ int err;
25282+
25283+ do { /* PaX: libffi trampoline emulation */
25284+ unsigned short mov1, mov2, jmp1;
25285+ unsigned char stcclc, jmp2;
25286+ unsigned long addr1, addr2;
25287+
25288+ err = get_user(mov1, (unsigned short __user *)regs->ip);
25289+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
25290+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
25291+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
25292+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
25293+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
25294+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
25295+
25296+ if (err)
25297+ break;
25298+
25299+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
25300+ regs->r11 = addr1;
25301+ regs->r10 = addr2;
25302+ if (stcclc == 0xF8)
25303+ regs->flags &= ~X86_EFLAGS_CF;
25304+ else
25305+ regs->flags |= X86_EFLAGS_CF;
25306+ regs->ip = addr1;
25307+ return 2;
25308+ }
25309+ } while (0);
25310+
25311+ do { /* PaX: gcc trampoline emulation #1 */
25312+ unsigned short mov1, mov2, jmp1;
25313+ unsigned char jmp2;
25314+ unsigned int addr1;
25315+ unsigned long addr2;
25316+
25317+ err = get_user(mov1, (unsigned short __user *)regs->ip);
25318+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
25319+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
25320+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
25321+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
25322+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
25323+
25324+ if (err)
25325+ break;
25326+
25327+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
25328+ regs->r11 = addr1;
25329+ regs->r10 = addr2;
25330+ regs->ip = addr1;
25331+ return 2;
25332+ }
25333+ } while (0);
25334+
25335+ do { /* PaX: gcc trampoline emulation #2 */
25336+ unsigned short mov1, mov2, jmp1;
25337+ unsigned char jmp2;
25338+ unsigned long addr1, addr2;
25339+
25340+ err = get_user(mov1, (unsigned short __user *)regs->ip);
25341+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
25342+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
25343+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
25344+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
25345+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
25346+
25347+ if (err)
25348+ break;
25349+
25350+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
25351+ regs->r11 = addr1;
25352+ regs->r10 = addr2;
25353+ regs->ip = addr1;
25354+ return 2;
25355+ }
25356+ } while (0);
25357+
25358+ return 1; /* PaX in action */
25359+}
25360+#endif
25361+
25362+/*
25363+ * PaX: decide what to do with offenders (regs->ip = fault address)
25364+ *
25365+ * returns 1 when task should be killed
25366+ * 2 when gcc trampoline was detected
25367+ */
25368+static int pax_handle_fetch_fault(struct pt_regs *regs)
25369+{
25370+ if (v8086_mode(regs))
25371+ return 1;
25372+
25373+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
25374+ return 1;
25375+
25376+#ifdef CONFIG_X86_32
25377+ return pax_handle_fetch_fault_32(regs);
25378+#else
25379+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
25380+ return pax_handle_fetch_fault_32(regs);
25381+ else
25382+ return pax_handle_fetch_fault_64(regs);
25383+#endif
25384+}
25385+#endif
25386+
25387+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25388+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
25389+{
25390+ long i;
25391+
25392+ printk(KERN_ERR "PAX: bytes at PC: ");
25393+ for (i = 0; i < 20; i++) {
25394+ unsigned char c;
25395+ if (get_user(c, (unsigned char __force_user *)pc+i))
25396+ printk(KERN_CONT "?? ");
25397+ else
25398+ printk(KERN_CONT "%02x ", c);
25399+ }
25400+ printk("\n");
25401+
25402+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
25403+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
25404+ unsigned long c;
25405+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
25406+#ifdef CONFIG_X86_32
25407+ printk(KERN_CONT "???????? ");
25408+#else
25409+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
25410+ printk(KERN_CONT "???????? ???????? ");
25411+ else
25412+ printk(KERN_CONT "???????????????? ");
25413+#endif
25414+ } else {
25415+#ifdef CONFIG_X86_64
25416+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
25417+ printk(KERN_CONT "%08x ", (unsigned int)c);
25418+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
25419+ } else
25420+#endif
25421+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
25422+ }
25423+ }
25424+ printk("\n");
25425+}
25426+#endif
25427+
25428+/**
25429+ * probe_kernel_write(): safely attempt to write to a location
25430+ * @dst: address to write to
25431+ * @src: pointer to the data that shall be written
25432+ * @size: size of the data chunk
25433+ *
25434+ * Safely write to address @dst from the buffer at @src. If a kernel fault
25435+ * happens, handle that and return -EFAULT.
25436+ */
25437+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
25438+{
25439+ long ret;
25440+ mm_segment_t old_fs = get_fs();
25441+
25442+ set_fs(KERNEL_DS);
25443+ pagefault_disable();
25444+ pax_open_kernel();
25445+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
25446+ pax_close_kernel();
25447+ pagefault_enable();
25448+ set_fs(old_fs);
25449+
25450+ return ret ? -EFAULT : 0;
25451+}
25452diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
25453index dd74e46..7d26398 100644
25454--- a/arch/x86/mm/gup.c
25455+++ b/arch/x86/mm/gup.c
25456@@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
25457 addr = start;
25458 len = (unsigned long) nr_pages << PAGE_SHIFT;
25459 end = start + len;
25460- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
25461+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
25462 (void __user *)start, len)))
25463 return 0;
25464
25465diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
25466index 6f31ee5..8ee4164 100644
25467--- a/arch/x86/mm/highmem_32.c
25468+++ b/arch/x86/mm/highmem_32.c
25469@@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
25470 idx = type + KM_TYPE_NR*smp_processor_id();
25471 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
25472 BUG_ON(!pte_none(*(kmap_pte-idx)));
25473+
25474+ pax_open_kernel();
25475 set_pte(kmap_pte-idx, mk_pte(page, prot));
25476+ pax_close_kernel();
25477+
25478 arch_flush_lazy_mmu_mode();
25479
25480 return (void *)vaddr;
25481diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
25482index 937bff5..d777418 100644
25483--- a/arch/x86/mm/hugetlbpage.c
25484+++ b/arch/x86/mm/hugetlbpage.c
25485@@ -276,13 +276,20 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
25486 struct hstate *h = hstate_file(file);
25487 struct mm_struct *mm = current->mm;
25488 struct vm_area_struct *vma;
25489- unsigned long start_addr;
25490+ unsigned long start_addr, pax_task_size = TASK_SIZE;
25491+
25492+#ifdef CONFIG_PAX_SEGMEXEC
25493+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25494+ pax_task_size = SEGMEXEC_TASK_SIZE;
25495+#endif
25496+
25497+ pax_task_size -= PAGE_SIZE;
25498
25499 if (len > mm->cached_hole_size) {
25500- start_addr = mm->free_area_cache;
25501+ start_addr = mm->free_area_cache;
25502 } else {
25503- start_addr = TASK_UNMAPPED_BASE;
25504- mm->cached_hole_size = 0;
25505+ start_addr = mm->mmap_base;
25506+ mm->cached_hole_size = 0;
25507 }
25508
25509 full_search:
25510@@ -290,26 +297,27 @@ full_search:
25511
25512 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
25513 /* At this point: (!vma || addr < vma->vm_end). */
25514- if (TASK_SIZE - len < addr) {
25515+ if (pax_task_size - len < addr) {
25516 /*
25517 * Start a new search - just in case we missed
25518 * some holes.
25519 */
25520- if (start_addr != TASK_UNMAPPED_BASE) {
25521- start_addr = TASK_UNMAPPED_BASE;
25522+ if (start_addr != mm->mmap_base) {
25523+ start_addr = mm->mmap_base;
25524 mm->cached_hole_size = 0;
25525 goto full_search;
25526 }
25527 return -ENOMEM;
25528 }
25529- if (!vma || addr + len <= vma->vm_start) {
25530- mm->free_area_cache = addr + len;
25531- return addr;
25532- }
25533+ if (check_heap_stack_gap(vma, addr, len))
25534+ break;
25535 if (addr + mm->cached_hole_size < vma->vm_start)
25536 mm->cached_hole_size = vma->vm_start - addr;
25537 addr = ALIGN(vma->vm_end, huge_page_size(h));
25538 }
25539+
25540+ mm->free_area_cache = addr + len;
25541+ return addr;
25542 }
25543
25544 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
25545@@ -320,9 +328,8 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
25546 struct mm_struct *mm = current->mm;
25547 struct vm_area_struct *vma;
25548 unsigned long base = mm->mmap_base;
25549- unsigned long addr = addr0;
25550+ unsigned long addr;
25551 unsigned long largest_hole = mm->cached_hole_size;
25552- unsigned long start_addr;
25553
25554 /* don't allow allocations above current base */
25555 if (mm->free_area_cache > base)
25556@@ -332,16 +339,15 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
25557 largest_hole = 0;
25558 mm->free_area_cache = base;
25559 }
25560-try_again:
25561- start_addr = mm->free_area_cache;
25562
25563 /* make sure it can fit in the remaining address space */
25564 if (mm->free_area_cache < len)
25565 goto fail;
25566
25567 /* either no address requested or can't fit in requested address hole */
25568- addr = (mm->free_area_cache - len) & huge_page_mask(h);
25569+ addr = mm->free_area_cache - len;
25570 do {
25571+ addr &= huge_page_mask(h);
25572 /*
25573 * Lookup failure means no vma is above this address,
25574 * i.e. return with success:
25575@@ -350,10 +356,10 @@ try_again:
25576 if (!vma)
25577 return addr;
25578
25579- if (addr + len <= vma->vm_start) {
25580+ if (check_heap_stack_gap(vma, addr, len)) {
25581 /* remember the address as a hint for next time */
25582- mm->cached_hole_size = largest_hole;
25583- return (mm->free_area_cache = addr);
25584+ mm->cached_hole_size = largest_hole;
25585+ return (mm->free_area_cache = addr);
25586 } else if (mm->free_area_cache == vma->vm_end) {
25587 /* pull free_area_cache down to the first hole */
25588 mm->free_area_cache = vma->vm_start;
25589@@ -362,29 +368,34 @@ try_again:
25590
25591 /* remember the largest hole we saw so far */
25592 if (addr + largest_hole < vma->vm_start)
25593- largest_hole = vma->vm_start - addr;
25594+ largest_hole = vma->vm_start - addr;
25595
25596 /* try just below the current vma->vm_start */
25597- addr = (vma->vm_start - len) & huge_page_mask(h);
25598- } while (len <= vma->vm_start);
25599+ addr = skip_heap_stack_gap(vma, len);
25600+ } while (!IS_ERR_VALUE(addr));
25601
25602 fail:
25603 /*
25604- * if hint left us with no space for the requested
25605- * mapping then try again:
25606- */
25607- if (start_addr != base) {
25608- mm->free_area_cache = base;
25609- largest_hole = 0;
25610- goto try_again;
25611- }
25612- /*
25613 * A failed mmap() very likely causes application failure,
25614 * so fall back to the bottom-up function here. This scenario
25615 * can happen with large stack limits and large mmap()
25616 * allocations.
25617 */
25618- mm->free_area_cache = TASK_UNMAPPED_BASE;
25619+
25620+#ifdef CONFIG_PAX_SEGMEXEC
25621+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25622+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
25623+ else
25624+#endif
25625+
25626+ mm->mmap_base = TASK_UNMAPPED_BASE;
25627+
25628+#ifdef CONFIG_PAX_RANDMMAP
25629+ if (mm->pax_flags & MF_PAX_RANDMMAP)
25630+ mm->mmap_base += mm->delta_mmap;
25631+#endif
25632+
25633+ mm->free_area_cache = mm->mmap_base;
25634 mm->cached_hole_size = ~0UL;
25635 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
25636 len, pgoff, flags);
25637@@ -392,6 +403,7 @@ fail:
25638 /*
25639 * Restore the topdown base:
25640 */
25641+ mm->mmap_base = base;
25642 mm->free_area_cache = base;
25643 mm->cached_hole_size = ~0UL;
25644
25645@@ -405,10 +417,19 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
25646 struct hstate *h = hstate_file(file);
25647 struct mm_struct *mm = current->mm;
25648 struct vm_area_struct *vma;
25649+ unsigned long pax_task_size = TASK_SIZE;
25650
25651 if (len & ~huge_page_mask(h))
25652 return -EINVAL;
25653- if (len > TASK_SIZE)
25654+
25655+#ifdef CONFIG_PAX_SEGMEXEC
25656+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25657+ pax_task_size = SEGMEXEC_TASK_SIZE;
25658+#endif
25659+
25660+ pax_task_size -= PAGE_SIZE;
25661+
25662+ if (len > pax_task_size)
25663 return -ENOMEM;
25664
25665 if (flags & MAP_FIXED) {
25666@@ -420,8 +441,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
25667 if (addr) {
25668 addr = ALIGN(addr, huge_page_size(h));
25669 vma = find_vma(mm, addr);
25670- if (TASK_SIZE - len >= addr &&
25671- (!vma || addr + len <= vma->vm_start))
25672+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
25673 return addr;
25674 }
25675 if (mm->get_unmapped_area == arch_get_unmapped_area)
25676diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
25677index d7aea41..0fc945b 100644
25678--- a/arch/x86/mm/init.c
25679+++ b/arch/x86/mm/init.c
25680@@ -4,6 +4,7 @@
25681 #include <linux/swap.h>
25682 #include <linux/memblock.h>
25683 #include <linux/bootmem.h> /* for max_low_pfn */
25684+#include <linux/tboot.h>
25685
25686 #include <asm/cacheflush.h>
25687 #include <asm/e820.h>
25688@@ -16,6 +17,8 @@
25689 #include <asm/tlb.h>
25690 #include <asm/proto.h>
25691 #include <asm/dma.h> /* for MAX_DMA_PFN */
25692+#include <asm/desc.h>
25693+#include <asm/bios_ebda.h>
25694
25695 unsigned long __initdata pgt_buf_start;
25696 unsigned long __meminitdata pgt_buf_end;
25697@@ -44,7 +47,7 @@ static void __init find_early_table_space(struct map_range *mr, int nr_range)
25698 {
25699 int i;
25700 unsigned long puds = 0, pmds = 0, ptes = 0, tables;
25701- unsigned long start = 0, good_end;
25702+ unsigned long start = 0x100000, good_end;
25703 phys_addr_t base;
25704
25705 for (i = 0; i < nr_range; i++) {
25706@@ -321,10 +324,40 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
25707 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
25708 * mmio resources as well as potential bios/acpi data regions.
25709 */
25710+
25711+#ifdef CONFIG_GRKERNSEC_KMEM
25712+static unsigned int ebda_start __read_only;
25713+static unsigned int ebda_end __read_only;
25714+#endif
25715+
25716 int devmem_is_allowed(unsigned long pagenr)
25717 {
25718- if (pagenr < 256)
25719+#ifdef CONFIG_GRKERNSEC_KMEM
25720+ /* allow BDA */
25721+ if (!pagenr)
25722 return 1;
25723+ /* allow EBDA */
25724+ if (pagenr >= ebda_start && pagenr < ebda_end)
25725+ return 1;
25726+ /* if tboot is in use, allow access to its hardcoded serial log range */
25727+ if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
25728+ return 1;
25729+#else
25730+ if (!pagenr)
25731+ return 1;
25732+#ifdef CONFIG_VM86
25733+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
25734+ return 1;
25735+#endif
25736+#endif
25737+
25738+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
25739+ return 1;
25740+#ifdef CONFIG_GRKERNSEC_KMEM
25741+ /* throw out everything else below 1MB */
25742+ if (pagenr <= 256)
25743+ return 0;
25744+#endif
25745 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
25746 return 0;
25747 if (!page_is_ram(pagenr))
25748@@ -381,8 +414,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
25749 #endif
25750 }
25751
25752+#ifdef CONFIG_GRKERNSEC_KMEM
25753+static inline void gr_init_ebda(void)
25754+{
25755+ unsigned int ebda_addr;
25756+ unsigned int ebda_size = 0;
25757+
25758+ ebda_addr = get_bios_ebda();
25759+ if (ebda_addr) {
25760+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
25761+ ebda_size <<= 10;
25762+ }
25763+ if (ebda_addr && ebda_size) {
25764+ ebda_start = ebda_addr >> PAGE_SHIFT;
25765+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
25766+ } else {
25767+ ebda_start = 0x9f000 >> PAGE_SHIFT;
25768+ ebda_end = 0xa0000 >> PAGE_SHIFT;
25769+ }
25770+}
25771+#else
25772+static inline void gr_init_ebda(void) { }
25773+#endif
25774+
25775 void free_initmem(void)
25776 {
25777+#ifdef CONFIG_PAX_KERNEXEC
25778+#ifdef CONFIG_X86_32
25779+ /* PaX: limit KERNEL_CS to actual size */
25780+ unsigned long addr, limit;
25781+ struct desc_struct d;
25782+ int cpu;
25783+#else
25784+ pgd_t *pgd;
25785+ pud_t *pud;
25786+ pmd_t *pmd;
25787+ unsigned long addr, end;
25788+#endif
25789+#endif
25790+
25791+ gr_init_ebda();
25792+
25793+#ifdef CONFIG_PAX_KERNEXEC
25794+#ifdef CONFIG_X86_32
25795+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
25796+ limit = (limit - 1UL) >> PAGE_SHIFT;
25797+
25798+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
25799+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
25800+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
25801+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
25802+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
25803+ }
25804+
25805+ /* PaX: make KERNEL_CS read-only */
25806+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
25807+ if (!paravirt_enabled())
25808+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
25809+/*
25810+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
25811+ pgd = pgd_offset_k(addr);
25812+ pud = pud_offset(pgd, addr);
25813+ pmd = pmd_offset(pud, addr);
25814+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
25815+ }
25816+*/
25817+#ifdef CONFIG_X86_PAE
25818+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
25819+/*
25820+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
25821+ pgd = pgd_offset_k(addr);
25822+ pud = pud_offset(pgd, addr);
25823+ pmd = pmd_offset(pud, addr);
25824+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
25825+ }
25826+*/
25827+#endif
25828+
25829+#ifdef CONFIG_MODULES
25830+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
25831+#endif
25832+
25833+#else
25834+ /* PaX: make kernel code/rodata read-only, rest non-executable */
25835+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
25836+ pgd = pgd_offset_k(addr);
25837+ pud = pud_offset(pgd, addr);
25838+ pmd = pmd_offset(pud, addr);
25839+ if (!pmd_present(*pmd))
25840+ continue;
25841+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
25842+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
25843+ else
25844+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
25845+ }
25846+
25847+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
25848+ end = addr + KERNEL_IMAGE_SIZE;
25849+ for (; addr < end; addr += PMD_SIZE) {
25850+ pgd = pgd_offset_k(addr);
25851+ pud = pud_offset(pgd, addr);
25852+ pmd = pmd_offset(pud, addr);
25853+ if (!pmd_present(*pmd))
25854+ continue;
25855+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
25856+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
25857+ }
25858+#endif
25859+
25860+ flush_tlb_all();
25861+#endif
25862+
25863 free_init_pages("unused kernel memory",
25864 (unsigned long)(&__init_begin),
25865 (unsigned long)(&__init_end));
25866diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
25867index 11a5800..4bd9977 100644
25868--- a/arch/x86/mm/init_32.c
25869+++ b/arch/x86/mm/init_32.c
25870@@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
25871 }
25872
25873 /*
25874- * Creates a middle page table and puts a pointer to it in the
25875- * given global directory entry. This only returns the gd entry
25876- * in non-PAE compilation mode, since the middle layer is folded.
25877- */
25878-static pmd_t * __init one_md_table_init(pgd_t *pgd)
25879-{
25880- pud_t *pud;
25881- pmd_t *pmd_table;
25882-
25883-#ifdef CONFIG_X86_PAE
25884- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
25885- if (after_bootmem)
25886- pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
25887- else
25888- pmd_table = (pmd_t *)alloc_low_page();
25889- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
25890- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
25891- pud = pud_offset(pgd, 0);
25892- BUG_ON(pmd_table != pmd_offset(pud, 0));
25893-
25894- return pmd_table;
25895- }
25896-#endif
25897- pud = pud_offset(pgd, 0);
25898- pmd_table = pmd_offset(pud, 0);
25899-
25900- return pmd_table;
25901-}
25902-
25903-/*
25904 * Create a page table and place a pointer to it in a middle page
25905 * directory entry:
25906 */
25907@@ -122,13 +92,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
25908 page_table = (pte_t *)alloc_low_page();
25909
25910 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
25911+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25912+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
25913+#else
25914 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
25915+#endif
25916 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
25917 }
25918
25919 return pte_offset_kernel(pmd, 0);
25920 }
25921
25922+static pmd_t * __init one_md_table_init(pgd_t *pgd)
25923+{
25924+ pud_t *pud;
25925+ pmd_t *pmd_table;
25926+
25927+ pud = pud_offset(pgd, 0);
25928+ pmd_table = pmd_offset(pud, 0);
25929+
25930+ return pmd_table;
25931+}
25932+
25933 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
25934 {
25935 int pgd_idx = pgd_index(vaddr);
25936@@ -202,6 +187,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
25937 int pgd_idx, pmd_idx;
25938 unsigned long vaddr;
25939 pgd_t *pgd;
25940+ pud_t *pud;
25941 pmd_t *pmd;
25942 pte_t *pte = NULL;
25943
25944@@ -211,8 +197,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
25945 pgd = pgd_base + pgd_idx;
25946
25947 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
25948- pmd = one_md_table_init(pgd);
25949- pmd = pmd + pmd_index(vaddr);
25950+ pud = pud_offset(pgd, vaddr);
25951+ pmd = pmd_offset(pud, vaddr);
25952+
25953+#ifdef CONFIG_X86_PAE
25954+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
25955+#endif
25956+
25957 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
25958 pmd++, pmd_idx++) {
25959 pte = page_table_kmap_check(one_page_table_init(pmd),
25960@@ -224,11 +215,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
25961 }
25962 }
25963
25964-static inline int is_kernel_text(unsigned long addr)
25965+static inline int is_kernel_text(unsigned long start, unsigned long end)
25966 {
25967- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
25968- return 1;
25969- return 0;
25970+ if ((start > ktla_ktva((unsigned long)_etext) ||
25971+ end <= ktla_ktva((unsigned long)_stext)) &&
25972+ (start > ktla_ktva((unsigned long)_einittext) ||
25973+ end <= ktla_ktva((unsigned long)_sinittext)) &&
25974+
25975+#ifdef CONFIG_ACPI_SLEEP
25976+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
25977+#endif
25978+
25979+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
25980+ return 0;
25981+ return 1;
25982 }
25983
25984 /*
25985@@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned long start,
25986 unsigned long last_map_addr = end;
25987 unsigned long start_pfn, end_pfn;
25988 pgd_t *pgd_base = swapper_pg_dir;
25989- int pgd_idx, pmd_idx, pte_ofs;
25990+ unsigned int pgd_idx, pmd_idx, pte_ofs;
25991 unsigned long pfn;
25992 pgd_t *pgd;
25993+ pud_t *pud;
25994 pmd_t *pmd;
25995 pte_t *pte;
25996 unsigned pages_2m, pages_4k;
25997@@ -280,8 +281,13 @@ repeat:
25998 pfn = start_pfn;
25999 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
26000 pgd = pgd_base + pgd_idx;
26001- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
26002- pmd = one_md_table_init(pgd);
26003+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
26004+ pud = pud_offset(pgd, 0);
26005+ pmd = pmd_offset(pud, 0);
26006+
26007+#ifdef CONFIG_X86_PAE
26008+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
26009+#endif
26010
26011 if (pfn >= end_pfn)
26012 continue;
26013@@ -293,14 +299,13 @@ repeat:
26014 #endif
26015 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
26016 pmd++, pmd_idx++) {
26017- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
26018+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
26019
26020 /*
26021 * Map with big pages if possible, otherwise
26022 * create normal page tables:
26023 */
26024 if (use_pse) {
26025- unsigned int addr2;
26026 pgprot_t prot = PAGE_KERNEL_LARGE;
26027 /*
26028 * first pass will use the same initial
26029@@ -310,11 +315,7 @@ repeat:
26030 __pgprot(PTE_IDENT_ATTR |
26031 _PAGE_PSE);
26032
26033- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
26034- PAGE_OFFSET + PAGE_SIZE-1;
26035-
26036- if (is_kernel_text(addr) ||
26037- is_kernel_text(addr2))
26038+ if (is_kernel_text(address, address + PMD_SIZE))
26039 prot = PAGE_KERNEL_LARGE_EXEC;
26040
26041 pages_2m++;
26042@@ -331,7 +332,7 @@ repeat:
26043 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
26044 pte += pte_ofs;
26045 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
26046- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
26047+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
26048 pgprot_t prot = PAGE_KERNEL;
26049 /*
26050 * first pass will use the same initial
26051@@ -339,7 +340,7 @@ repeat:
26052 */
26053 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
26054
26055- if (is_kernel_text(addr))
26056+ if (is_kernel_text(address, address + PAGE_SIZE))
26057 prot = PAGE_KERNEL_EXEC;
26058
26059 pages_4k++;
26060@@ -465,7 +466,7 @@ void __init native_pagetable_init(void)
26061
26062 pud = pud_offset(pgd, va);
26063 pmd = pmd_offset(pud, va);
26064- if (!pmd_present(*pmd))
26065+ if (!pmd_present(*pmd) || pmd_huge(*pmd))
26066 break;
26067
26068 pte = pte_offset_kernel(pmd, va);
26069@@ -514,12 +515,10 @@ void __init early_ioremap_page_table_range_init(void)
26070
26071 static void __init pagetable_init(void)
26072 {
26073- pgd_t *pgd_base = swapper_pg_dir;
26074-
26075- permanent_kmaps_init(pgd_base);
26076+ permanent_kmaps_init(swapper_pg_dir);
26077 }
26078
26079-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
26080+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
26081 EXPORT_SYMBOL_GPL(__supported_pte_mask);
26082
26083 /* user-defined highmem size */
26084@@ -731,6 +730,12 @@ void __init mem_init(void)
26085
26086 pci_iommu_alloc();
26087
26088+#ifdef CONFIG_PAX_PER_CPU_PGD
26089+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
26090+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
26091+ KERNEL_PGD_PTRS);
26092+#endif
26093+
26094 #ifdef CONFIG_FLATMEM
26095 BUG_ON(!mem_map);
26096 #endif
26097@@ -757,7 +762,7 @@ void __init mem_init(void)
26098 reservedpages++;
26099
26100 codesize = (unsigned long) &_etext - (unsigned long) &_text;
26101- datasize = (unsigned long) &_edata - (unsigned long) &_etext;
26102+ datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
26103 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
26104
26105 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
26106@@ -798,10 +803,10 @@ void __init mem_init(void)
26107 ((unsigned long)&__init_end -
26108 (unsigned long)&__init_begin) >> 10,
26109
26110- (unsigned long)&_etext, (unsigned long)&_edata,
26111- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
26112+ (unsigned long)&_sdata, (unsigned long)&_edata,
26113+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
26114
26115- (unsigned long)&_text, (unsigned long)&_etext,
26116+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
26117 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
26118
26119 /*
26120@@ -879,6 +884,7 @@ void set_kernel_text_rw(void)
26121 if (!kernel_set_to_readonly)
26122 return;
26123
26124+ start = ktla_ktva(start);
26125 pr_debug("Set kernel text: %lx - %lx for read write\n",
26126 start, start+size);
26127
26128@@ -893,6 +899,7 @@ void set_kernel_text_ro(void)
26129 if (!kernel_set_to_readonly)
26130 return;
26131
26132+ start = ktla_ktva(start);
26133 pr_debug("Set kernel text: %lx - %lx for read only\n",
26134 start, start+size);
26135
26136@@ -921,6 +928,7 @@ void mark_rodata_ro(void)
26137 unsigned long start = PFN_ALIGN(_text);
26138 unsigned long size = PFN_ALIGN(_etext) - start;
26139
26140+ start = ktla_ktva(start);
26141 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
26142 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
26143 size >> 10);
26144diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
26145index 3baff25..8b37564 100644
26146--- a/arch/x86/mm/init_64.c
26147+++ b/arch/x86/mm/init_64.c
26148@@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpages_on);
26149 * around without checking the pgd every time.
26150 */
26151
26152-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
26153+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
26154 EXPORT_SYMBOL_GPL(__supported_pte_mask);
26155
26156 int force_personality32;
26157@@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
26158
26159 for (address = start; address <= end; address += PGDIR_SIZE) {
26160 const pgd_t *pgd_ref = pgd_offset_k(address);
26161+
26162+#ifdef CONFIG_PAX_PER_CPU_PGD
26163+ unsigned long cpu;
26164+#else
26165 struct page *page;
26166+#endif
26167
26168 if (pgd_none(*pgd_ref))
26169 continue;
26170
26171 spin_lock(&pgd_lock);
26172+
26173+#ifdef CONFIG_PAX_PER_CPU_PGD
26174+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
26175+ pgd_t *pgd = pgd_offset_cpu(cpu, address);
26176+#else
26177 list_for_each_entry(page, &pgd_list, lru) {
26178 pgd_t *pgd;
26179 spinlock_t *pgt_lock;
26180@@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
26181 /* the pgt_lock only for Xen */
26182 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
26183 spin_lock(pgt_lock);
26184+#endif
26185
26186 if (pgd_none(*pgd))
26187 set_pgd(pgd, *pgd_ref);
26188@@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
26189 BUG_ON(pgd_page_vaddr(*pgd)
26190 != pgd_page_vaddr(*pgd_ref));
26191
26192+#ifndef CONFIG_PAX_PER_CPU_PGD
26193 spin_unlock(pgt_lock);
26194+#endif
26195+
26196 }
26197 spin_unlock(&pgd_lock);
26198 }
26199@@ -161,7 +175,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
26200 {
26201 if (pgd_none(*pgd)) {
26202 pud_t *pud = (pud_t *)spp_getpage();
26203- pgd_populate(&init_mm, pgd, pud);
26204+ pgd_populate_kernel(&init_mm, pgd, pud);
26205 if (pud != pud_offset(pgd, 0))
26206 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
26207 pud, pud_offset(pgd, 0));
26208@@ -173,7 +187,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
26209 {
26210 if (pud_none(*pud)) {
26211 pmd_t *pmd = (pmd_t *) spp_getpage();
26212- pud_populate(&init_mm, pud, pmd);
26213+ pud_populate_kernel(&init_mm, pud, pmd);
26214 if (pmd != pmd_offset(pud, 0))
26215 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
26216 pmd, pmd_offset(pud, 0));
26217@@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
26218 pmd = fill_pmd(pud, vaddr);
26219 pte = fill_pte(pmd, vaddr);
26220
26221+ pax_open_kernel();
26222 set_pte(pte, new_pte);
26223+ pax_close_kernel();
26224
26225 /*
26226 * It's enough to flush this one mapping.
26227@@ -261,14 +277,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
26228 pgd = pgd_offset_k((unsigned long)__va(phys));
26229 if (pgd_none(*pgd)) {
26230 pud = (pud_t *) spp_getpage();
26231- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
26232- _PAGE_USER));
26233+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
26234 }
26235 pud = pud_offset(pgd, (unsigned long)__va(phys));
26236 if (pud_none(*pud)) {
26237 pmd = (pmd_t *) spp_getpage();
26238- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
26239- _PAGE_USER));
26240+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
26241 }
26242 pmd = pmd_offset(pud, phys);
26243 BUG_ON(!pmd_none(*pmd));
26244@@ -329,7 +343,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
26245 if (pfn >= pgt_buf_top)
26246 panic("alloc_low_page: ran out of memory");
26247
26248- adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
26249+ adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
26250 clear_page(adr);
26251 *phys = pfn * PAGE_SIZE;
26252 return adr;
26253@@ -345,7 +359,7 @@ static __ref void *map_low_page(void *virt)
26254
26255 phys = __pa(virt);
26256 left = phys & (PAGE_SIZE - 1);
26257- adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
26258+ adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
26259 adr = (void *)(((unsigned long)adr) | left);
26260
26261 return adr;
26262@@ -553,7 +567,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
26263 unmap_low_page(pmd);
26264
26265 spin_lock(&init_mm.page_table_lock);
26266- pud_populate(&init_mm, pud, __va(pmd_phys));
26267+ pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
26268 spin_unlock(&init_mm.page_table_lock);
26269 }
26270 __flush_tlb_all();
26271@@ -599,7 +613,7 @@ kernel_physical_mapping_init(unsigned long start,
26272 unmap_low_page(pud);
26273
26274 spin_lock(&init_mm.page_table_lock);
26275- pgd_populate(&init_mm, pgd, __va(pud_phys));
26276+ pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
26277 spin_unlock(&init_mm.page_table_lock);
26278 pgd_changed = true;
26279 }
26280@@ -691,6 +705,12 @@ void __init mem_init(void)
26281
26282 pci_iommu_alloc();
26283
26284+#ifdef CONFIG_PAX_PER_CPU_PGD
26285+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
26286+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
26287+ KERNEL_PGD_PTRS);
26288+#endif
26289+
26290 /* clear_bss() already clear the empty_zero_page */
26291
26292 reservedpages = 0;
26293@@ -851,8 +871,8 @@ int kern_addr_valid(unsigned long addr)
26294 static struct vm_area_struct gate_vma = {
26295 .vm_start = VSYSCALL_START,
26296 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
26297- .vm_page_prot = PAGE_READONLY_EXEC,
26298- .vm_flags = VM_READ | VM_EXEC
26299+ .vm_page_prot = PAGE_READONLY,
26300+ .vm_flags = VM_READ
26301 };
26302
26303 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
26304@@ -886,7 +906,7 @@ int in_gate_area_no_mm(unsigned long addr)
26305
26306 const char *arch_vma_name(struct vm_area_struct *vma)
26307 {
26308- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
26309+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
26310 return "[vdso]";
26311 if (vma == &gate_vma)
26312 return "[vsyscall]";
26313diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
26314index 7b179b4..6bd1777 100644
26315--- a/arch/x86/mm/iomap_32.c
26316+++ b/arch/x86/mm/iomap_32.c
26317@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
26318 type = kmap_atomic_idx_push();
26319 idx = type + KM_TYPE_NR * smp_processor_id();
26320 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
26321+
26322+ pax_open_kernel();
26323 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
26324+ pax_close_kernel();
26325+
26326 arch_flush_lazy_mmu_mode();
26327
26328 return (void *)vaddr;
26329diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
26330index 78fe3f1..2f9433c 100644
26331--- a/arch/x86/mm/ioremap.c
26332+++ b/arch/x86/mm/ioremap.c
26333@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
26334 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
26335 int is_ram = page_is_ram(pfn);
26336
26337- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
26338+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
26339 return NULL;
26340 WARN_ON_ONCE(is_ram);
26341 }
26342@@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
26343 *
26344 * Caller must ensure there is only one unmapping for the same pointer.
26345 */
26346-void iounmap(volatile void __iomem *addr)
26347+void iounmap(const volatile void __iomem *addr)
26348 {
26349 struct vm_struct *p, *o;
26350
26351@@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
26352
26353 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
26354 if (page_is_ram(start >> PAGE_SHIFT))
26355+#ifdef CONFIG_HIGHMEM
26356+ if ((start >> PAGE_SHIFT) < max_low_pfn)
26357+#endif
26358 return __va(phys);
26359
26360 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
26361@@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
26362 early_param("early_ioremap_debug", early_ioremap_debug_setup);
26363
26364 static __initdata int after_paging_init;
26365-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
26366+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
26367
26368 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
26369 {
26370@@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
26371 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
26372
26373 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
26374- memset(bm_pte, 0, sizeof(bm_pte));
26375- pmd_populate_kernel(&init_mm, pmd, bm_pte);
26376+ pmd_populate_user(&init_mm, pmd, bm_pte);
26377
26378 /*
26379 * The boot-ioremap range spans multiple pmds, for which
26380diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
26381index d87dd6d..bf3fa66 100644
26382--- a/arch/x86/mm/kmemcheck/kmemcheck.c
26383+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
26384@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
26385 * memory (e.g. tracked pages)? For now, we need this to avoid
26386 * invoking kmemcheck for PnP BIOS calls.
26387 */
26388- if (regs->flags & X86_VM_MASK)
26389+ if (v8086_mode(regs))
26390 return false;
26391- if (regs->cs != __KERNEL_CS)
26392+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
26393 return false;
26394
26395 pte = kmemcheck_pte_lookup(address);
26396diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
26397index 845df68..1d8d29f 100644
26398--- a/arch/x86/mm/mmap.c
26399+++ b/arch/x86/mm/mmap.c
26400@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
26401 * Leave an at least ~128 MB hole with possible stack randomization.
26402 */
26403 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
26404-#define MAX_GAP (TASK_SIZE/6*5)
26405+#define MAX_GAP (pax_task_size/6*5)
26406
26407 static int mmap_is_legacy(void)
26408 {
26409@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
26410 return rnd << PAGE_SHIFT;
26411 }
26412
26413-static unsigned long mmap_base(void)
26414+static unsigned long mmap_base(struct mm_struct *mm)
26415 {
26416 unsigned long gap = rlimit(RLIMIT_STACK);
26417+ unsigned long pax_task_size = TASK_SIZE;
26418+
26419+#ifdef CONFIG_PAX_SEGMEXEC
26420+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
26421+ pax_task_size = SEGMEXEC_TASK_SIZE;
26422+#endif
26423
26424 if (gap < MIN_GAP)
26425 gap = MIN_GAP;
26426 else if (gap > MAX_GAP)
26427 gap = MAX_GAP;
26428
26429- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
26430+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
26431 }
26432
26433 /*
26434 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
26435 * does, but not when emulating X86_32
26436 */
26437-static unsigned long mmap_legacy_base(void)
26438+static unsigned long mmap_legacy_base(struct mm_struct *mm)
26439 {
26440- if (mmap_is_ia32())
26441+ if (mmap_is_ia32()) {
26442+
26443+#ifdef CONFIG_PAX_SEGMEXEC
26444+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
26445+ return SEGMEXEC_TASK_UNMAPPED_BASE;
26446+ else
26447+#endif
26448+
26449 return TASK_UNMAPPED_BASE;
26450- else
26451+ } else
26452 return TASK_UNMAPPED_BASE + mmap_rnd();
26453 }
26454
26455@@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
26456 void arch_pick_mmap_layout(struct mm_struct *mm)
26457 {
26458 if (mmap_is_legacy()) {
26459- mm->mmap_base = mmap_legacy_base();
26460+ mm->mmap_base = mmap_legacy_base(mm);
26461+
26462+#ifdef CONFIG_PAX_RANDMMAP
26463+ if (mm->pax_flags & MF_PAX_RANDMMAP)
26464+ mm->mmap_base += mm->delta_mmap;
26465+#endif
26466+
26467 mm->get_unmapped_area = arch_get_unmapped_area;
26468 mm->unmap_area = arch_unmap_area;
26469 } else {
26470- mm->mmap_base = mmap_base();
26471+ mm->mmap_base = mmap_base(mm);
26472+
26473+#ifdef CONFIG_PAX_RANDMMAP
26474+ if (mm->pax_flags & MF_PAX_RANDMMAP)
26475+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
26476+#endif
26477+
26478 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
26479 mm->unmap_area = arch_unmap_area_topdown;
26480 }
26481diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
26482index dc0b727..f612039 100644
26483--- a/arch/x86/mm/mmio-mod.c
26484+++ b/arch/x86/mm/mmio-mod.c
26485@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
26486 break;
26487 default:
26488 {
26489- unsigned char *ip = (unsigned char *)instptr;
26490+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
26491 my_trace->opcode = MMIO_UNKNOWN_OP;
26492 my_trace->width = 0;
26493 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
26494@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
26495 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
26496 void __iomem *addr)
26497 {
26498- static atomic_t next_id;
26499+ static atomic_unchecked_t next_id;
26500 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
26501 /* These are page-unaligned. */
26502 struct mmiotrace_map map = {
26503@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
26504 .private = trace
26505 },
26506 .phys = offset,
26507- .id = atomic_inc_return(&next_id)
26508+ .id = atomic_inc_return_unchecked(&next_id)
26509 };
26510 map.map_id = trace->id;
26511
26512@@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
26513 ioremap_trace_core(offset, size, addr);
26514 }
26515
26516-static void iounmap_trace_core(volatile void __iomem *addr)
26517+static void iounmap_trace_core(const volatile void __iomem *addr)
26518 {
26519 struct mmiotrace_map map = {
26520 .phys = 0,
26521@@ -328,7 +328,7 @@ not_enabled:
26522 }
26523 }
26524
26525-void mmiotrace_iounmap(volatile void __iomem *addr)
26526+void mmiotrace_iounmap(const volatile void __iomem *addr)
26527 {
26528 might_sleep();
26529 if (is_enabled()) /* recheck and proper locking in *_core() */
26530diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
26531index b008656..773eac2 100644
26532--- a/arch/x86/mm/pageattr-test.c
26533+++ b/arch/x86/mm/pageattr-test.c
26534@@ -36,7 +36,7 @@ enum {
26535
26536 static int pte_testbit(pte_t pte)
26537 {
26538- return pte_flags(pte) & _PAGE_UNUSED1;
26539+ return pte_flags(pte) & _PAGE_CPA_TEST;
26540 }
26541
26542 struct split_state {
26543diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
26544index a718e0d..77419bc 100644
26545--- a/arch/x86/mm/pageattr.c
26546+++ b/arch/x86/mm/pageattr.c
26547@@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
26548 */
26549 #ifdef CONFIG_PCI_BIOS
26550 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
26551- pgprot_val(forbidden) |= _PAGE_NX;
26552+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
26553 #endif
26554
26555 /*
26556@@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
26557 * Does not cover __inittext since that is gone later on. On
26558 * 64bit we do not enforce !NX on the low mapping
26559 */
26560- if (within(address, (unsigned long)_text, (unsigned long)_etext))
26561- pgprot_val(forbidden) |= _PAGE_NX;
26562+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
26563+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
26564
26565+#ifdef CONFIG_DEBUG_RODATA
26566 /*
26567 * The .rodata section needs to be read-only. Using the pfn
26568 * catches all aliases.
26569@@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
26570 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
26571 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
26572 pgprot_val(forbidden) |= _PAGE_RW;
26573+#endif
26574
26575 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
26576 /*
26577@@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
26578 }
26579 #endif
26580
26581+#ifdef CONFIG_PAX_KERNEXEC
26582+ if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
26583+ pgprot_val(forbidden) |= _PAGE_RW;
26584+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
26585+ }
26586+#endif
26587+
26588 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
26589
26590 return prot;
26591@@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
26592 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
26593 {
26594 /* change init_mm */
26595+ pax_open_kernel();
26596 set_pte_atomic(kpte, pte);
26597+
26598 #ifdef CONFIG_X86_32
26599 if (!SHARED_KERNEL_PMD) {
26600+
26601+#ifdef CONFIG_PAX_PER_CPU_PGD
26602+ unsigned long cpu;
26603+#else
26604 struct page *page;
26605+#endif
26606
26607+#ifdef CONFIG_PAX_PER_CPU_PGD
26608+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
26609+ pgd_t *pgd = get_cpu_pgd(cpu);
26610+#else
26611 list_for_each_entry(page, &pgd_list, lru) {
26612- pgd_t *pgd;
26613+ pgd_t *pgd = (pgd_t *)page_address(page);
26614+#endif
26615+
26616 pud_t *pud;
26617 pmd_t *pmd;
26618
26619- pgd = (pgd_t *)page_address(page) + pgd_index(address);
26620+ pgd += pgd_index(address);
26621 pud = pud_offset(pgd, address);
26622 pmd = pmd_offset(pud, address);
26623 set_pte_atomic((pte_t *)pmd, pte);
26624 }
26625 }
26626 #endif
26627+ pax_close_kernel();
26628 }
26629
26630 static int
26631diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
26632index 0eb572e..92f5c1e 100644
26633--- a/arch/x86/mm/pat.c
26634+++ b/arch/x86/mm/pat.c
26635@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
26636
26637 if (!entry) {
26638 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
26639- current->comm, current->pid, start, end - 1);
26640+ current->comm, task_pid_nr(current), start, end - 1);
26641 return -EINVAL;
26642 }
26643
26644@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
26645
26646 while (cursor < to) {
26647 if (!devmem_is_allowed(pfn)) {
26648- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
26649- current->comm, from, to - 1);
26650+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
26651+ current->comm, from, to - 1, cursor);
26652 return 0;
26653 }
26654 cursor += PAGE_SIZE;
26655@@ -570,7 +570,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
26656 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
26657 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
26658 "for [mem %#010Lx-%#010Lx]\n",
26659- current->comm, current->pid,
26660+ current->comm, task_pid_nr(current),
26661 cattr_name(flags),
26662 base, (unsigned long long)(base + size-1));
26663 return -EINVAL;
26664@@ -605,7 +605,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
26665 flags = lookup_memtype(paddr);
26666 if (want_flags != flags) {
26667 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
26668- current->comm, current->pid,
26669+ current->comm, task_pid_nr(current),
26670 cattr_name(want_flags),
26671 (unsigned long long)paddr,
26672 (unsigned long long)(paddr + size - 1),
26673@@ -627,7 +627,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
26674 free_memtype(paddr, paddr + size);
26675 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
26676 " for [mem %#010Lx-%#010Lx], got %s\n",
26677- current->comm, current->pid,
26678+ current->comm, task_pid_nr(current),
26679 cattr_name(want_flags),
26680 (unsigned long long)paddr,
26681 (unsigned long long)(paddr + size - 1),
26682diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
26683index 9f0614d..92ae64a 100644
26684--- a/arch/x86/mm/pf_in.c
26685+++ b/arch/x86/mm/pf_in.c
26686@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
26687 int i;
26688 enum reason_type rv = OTHERS;
26689
26690- p = (unsigned char *)ins_addr;
26691+ p = (unsigned char *)ktla_ktva(ins_addr);
26692 p += skip_prefix(p, &prf);
26693 p += get_opcode(p, &opcode);
26694
26695@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
26696 struct prefix_bits prf;
26697 int i;
26698
26699- p = (unsigned char *)ins_addr;
26700+ p = (unsigned char *)ktla_ktva(ins_addr);
26701 p += skip_prefix(p, &prf);
26702 p += get_opcode(p, &opcode);
26703
26704@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
26705 struct prefix_bits prf;
26706 int i;
26707
26708- p = (unsigned char *)ins_addr;
26709+ p = (unsigned char *)ktla_ktva(ins_addr);
26710 p += skip_prefix(p, &prf);
26711 p += get_opcode(p, &opcode);
26712
26713@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
26714 struct prefix_bits prf;
26715 int i;
26716
26717- p = (unsigned char *)ins_addr;
26718+ p = (unsigned char *)ktla_ktva(ins_addr);
26719 p += skip_prefix(p, &prf);
26720 p += get_opcode(p, &opcode);
26721 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
26722@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
26723 struct prefix_bits prf;
26724 int i;
26725
26726- p = (unsigned char *)ins_addr;
26727+ p = (unsigned char *)ktla_ktva(ins_addr);
26728 p += skip_prefix(p, &prf);
26729 p += get_opcode(p, &opcode);
26730 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
26731diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
26732index 8573b83..4f3ed7e 100644
26733--- a/arch/x86/mm/pgtable.c
26734+++ b/arch/x86/mm/pgtable.c
26735@@ -84,10 +84,64 @@ static inline void pgd_list_del(pgd_t *pgd)
26736 list_del(&page->lru);
26737 }
26738
26739-#define UNSHARED_PTRS_PER_PGD \
26740- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
26741+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26742+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
26743
26744+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
26745+{
26746+ unsigned int count = USER_PGD_PTRS;
26747
26748+ while (count--)
26749+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
26750+}
26751+#endif
26752+
26753+#ifdef CONFIG_PAX_PER_CPU_PGD
26754+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
26755+{
26756+ unsigned int count = USER_PGD_PTRS;
26757+
26758+ while (count--) {
26759+ pgd_t pgd;
26760+
26761+#ifdef CONFIG_X86_64
26762+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
26763+#else
26764+ pgd = *src++;
26765+#endif
26766+
26767+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26768+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
26769+#endif
26770+
26771+ *dst++ = pgd;
26772+ }
26773+
26774+}
26775+#endif
26776+
26777+#ifdef CONFIG_X86_64
26778+#define pxd_t pud_t
26779+#define pyd_t pgd_t
26780+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
26781+#define pxd_free(mm, pud) pud_free((mm), (pud))
26782+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
26783+#define pyd_offset(mm, address) pgd_offset((mm), (address))
26784+#define PYD_SIZE PGDIR_SIZE
26785+#else
26786+#define pxd_t pmd_t
26787+#define pyd_t pud_t
26788+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
26789+#define pxd_free(mm, pud) pmd_free((mm), (pud))
26790+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
26791+#define pyd_offset(mm, address) pud_offset((mm), (address))
26792+#define PYD_SIZE PUD_SIZE
26793+#endif
26794+
26795+#ifdef CONFIG_PAX_PER_CPU_PGD
26796+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
26797+static inline void pgd_dtor(pgd_t *pgd) {}
26798+#else
26799 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
26800 {
26801 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
26802@@ -128,6 +182,7 @@ static void pgd_dtor(pgd_t *pgd)
26803 pgd_list_del(pgd);
26804 spin_unlock(&pgd_lock);
26805 }
26806+#endif
26807
26808 /*
26809 * List of all pgd's needed for non-PAE so it can invalidate entries
26810@@ -140,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
26811 * -- wli
26812 */
26813
26814-#ifdef CONFIG_X86_PAE
26815+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
26816 /*
26817 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
26818 * updating the top-level pagetable entries to guarantee the
26819@@ -152,7 +207,7 @@ static void pgd_dtor(pgd_t *pgd)
26820 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
26821 * and initialize the kernel pmds here.
26822 */
26823-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
26824+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
26825
26826 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
26827 {
26828@@ -170,36 +225,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
26829 */
26830 flush_tlb_mm(mm);
26831 }
26832+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
26833+#define PREALLOCATED_PXDS USER_PGD_PTRS
26834 #else /* !CONFIG_X86_PAE */
26835
26836 /* No need to prepopulate any pagetable entries in non-PAE modes. */
26837-#define PREALLOCATED_PMDS 0
26838+#define PREALLOCATED_PXDS 0
26839
26840 #endif /* CONFIG_X86_PAE */
26841
26842-static void free_pmds(pmd_t *pmds[])
26843+static void free_pxds(pxd_t *pxds[])
26844 {
26845 int i;
26846
26847- for(i = 0; i < PREALLOCATED_PMDS; i++)
26848- if (pmds[i])
26849- free_page((unsigned long)pmds[i]);
26850+ for(i = 0; i < PREALLOCATED_PXDS; i++)
26851+ if (pxds[i])
26852+ free_page((unsigned long)pxds[i]);
26853 }
26854
26855-static int preallocate_pmds(pmd_t *pmds[])
26856+static int preallocate_pxds(pxd_t *pxds[])
26857 {
26858 int i;
26859 bool failed = false;
26860
26861- for(i = 0; i < PREALLOCATED_PMDS; i++) {
26862- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
26863- if (pmd == NULL)
26864+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
26865+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
26866+ if (pxd == NULL)
26867 failed = true;
26868- pmds[i] = pmd;
26869+ pxds[i] = pxd;
26870 }
26871
26872 if (failed) {
26873- free_pmds(pmds);
26874+ free_pxds(pxds);
26875 return -ENOMEM;
26876 }
26877
26878@@ -212,51 +269,55 @@ static int preallocate_pmds(pmd_t *pmds[])
26879 * preallocate which never got a corresponding vma will need to be
26880 * freed manually.
26881 */
26882-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
26883+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
26884 {
26885 int i;
26886
26887- for(i = 0; i < PREALLOCATED_PMDS; i++) {
26888+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
26889 pgd_t pgd = pgdp[i];
26890
26891 if (pgd_val(pgd) != 0) {
26892- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
26893+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
26894
26895- pgdp[i] = native_make_pgd(0);
26896+ set_pgd(pgdp + i, native_make_pgd(0));
26897
26898- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
26899- pmd_free(mm, pmd);
26900+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
26901+ pxd_free(mm, pxd);
26902 }
26903 }
26904 }
26905
26906-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
26907+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
26908 {
26909- pud_t *pud;
26910+ pyd_t *pyd;
26911 unsigned long addr;
26912 int i;
26913
26914- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
26915+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
26916 return;
26917
26918- pud = pud_offset(pgd, 0);
26919+#ifdef CONFIG_X86_64
26920+ pyd = pyd_offset(mm, 0L);
26921+#else
26922+ pyd = pyd_offset(pgd, 0L);
26923+#endif
26924
26925- for (addr = i = 0; i < PREALLOCATED_PMDS;
26926- i++, pud++, addr += PUD_SIZE) {
26927- pmd_t *pmd = pmds[i];
26928+ for (addr = i = 0; i < PREALLOCATED_PXDS;
26929+ i++, pyd++, addr += PYD_SIZE) {
26930+ pxd_t *pxd = pxds[i];
26931
26932 if (i >= KERNEL_PGD_BOUNDARY)
26933- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
26934- sizeof(pmd_t) * PTRS_PER_PMD);
26935+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
26936+ sizeof(pxd_t) * PTRS_PER_PMD);
26937
26938- pud_populate(mm, pud, pmd);
26939+ pyd_populate(mm, pyd, pxd);
26940 }
26941 }
26942
26943 pgd_t *pgd_alloc(struct mm_struct *mm)
26944 {
26945 pgd_t *pgd;
26946- pmd_t *pmds[PREALLOCATED_PMDS];
26947+ pxd_t *pxds[PREALLOCATED_PXDS];
26948
26949 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
26950
26951@@ -265,11 +326,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
26952
26953 mm->pgd = pgd;
26954
26955- if (preallocate_pmds(pmds) != 0)
26956+ if (preallocate_pxds(pxds) != 0)
26957 goto out_free_pgd;
26958
26959 if (paravirt_pgd_alloc(mm) != 0)
26960- goto out_free_pmds;
26961+ goto out_free_pxds;
26962
26963 /*
26964 * Make sure that pre-populating the pmds is atomic with
26965@@ -279,14 +340,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
26966 spin_lock(&pgd_lock);
26967
26968 pgd_ctor(mm, pgd);
26969- pgd_prepopulate_pmd(mm, pgd, pmds);
26970+ pgd_prepopulate_pxd(mm, pgd, pxds);
26971
26972 spin_unlock(&pgd_lock);
26973
26974 return pgd;
26975
26976-out_free_pmds:
26977- free_pmds(pmds);
26978+out_free_pxds:
26979+ free_pxds(pxds);
26980 out_free_pgd:
26981 free_page((unsigned long)pgd);
26982 out:
26983@@ -295,7 +356,7 @@ out:
26984
26985 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
26986 {
26987- pgd_mop_up_pmds(mm, pgd);
26988+ pgd_mop_up_pxds(mm, pgd);
26989 pgd_dtor(pgd);
26990 paravirt_pgd_free(mm, pgd);
26991 free_page((unsigned long)pgd);
26992diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
26993index a69bcb8..19068ab 100644
26994--- a/arch/x86/mm/pgtable_32.c
26995+++ b/arch/x86/mm/pgtable_32.c
26996@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
26997 return;
26998 }
26999 pte = pte_offset_kernel(pmd, vaddr);
27000+
27001+ pax_open_kernel();
27002 if (pte_val(pteval))
27003 set_pte_at(&init_mm, vaddr, pte, pteval);
27004 else
27005 pte_clear(&init_mm, vaddr, pte);
27006+ pax_close_kernel();
27007
27008 /*
27009 * It's enough to flush this one mapping.
27010diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
27011index 410531d..0f16030 100644
27012--- a/arch/x86/mm/setup_nx.c
27013+++ b/arch/x86/mm/setup_nx.c
27014@@ -5,8 +5,10 @@
27015 #include <asm/pgtable.h>
27016 #include <asm/proto.h>
27017
27018+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
27019 static int disable_nx __cpuinitdata;
27020
27021+#ifndef CONFIG_PAX_PAGEEXEC
27022 /*
27023 * noexec = on|off
27024 *
27025@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
27026 return 0;
27027 }
27028 early_param("noexec", noexec_setup);
27029+#endif
27030+
27031+#endif
27032
27033 void __cpuinit x86_configure_nx(void)
27034 {
27035+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
27036 if (cpu_has_nx && !disable_nx)
27037 __supported_pte_mask |= _PAGE_NX;
27038 else
27039+#endif
27040 __supported_pte_mask &= ~_PAGE_NX;
27041 }
27042
27043diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
27044index 60f926c..a710970 100644
27045--- a/arch/x86/mm/tlb.c
27046+++ b/arch/x86/mm/tlb.c
27047@@ -48,7 +48,11 @@ void leave_mm(int cpu)
27048 BUG();
27049 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
27050 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
27051+
27052+#ifndef CONFIG_PAX_PER_CPU_PGD
27053 load_cr3(swapper_pg_dir);
27054+#endif
27055+
27056 }
27057 }
27058 EXPORT_SYMBOL_GPL(leave_mm);
27059diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
27060index 877b9a1..a8ecf42 100644
27061--- a/arch/x86/net/bpf_jit.S
27062+++ b/arch/x86/net/bpf_jit.S
27063@@ -9,6 +9,7 @@
27064 */
27065 #include <linux/linkage.h>
27066 #include <asm/dwarf2.h>
27067+#include <asm/alternative-asm.h>
27068
27069 /*
27070 * Calling convention :
27071@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
27072 jle bpf_slow_path_word
27073 mov (SKBDATA,%rsi),%eax
27074 bswap %eax /* ntohl() */
27075+ pax_force_retaddr
27076 ret
27077
27078 sk_load_half:
27079@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
27080 jle bpf_slow_path_half
27081 movzwl (SKBDATA,%rsi),%eax
27082 rol $8,%ax # ntohs()
27083+ pax_force_retaddr
27084 ret
27085
27086 sk_load_byte:
27087@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
27088 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
27089 jle bpf_slow_path_byte
27090 movzbl (SKBDATA,%rsi),%eax
27091+ pax_force_retaddr
27092 ret
27093
27094 /**
27095@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
27096 movzbl (SKBDATA,%rsi),%ebx
27097 and $15,%bl
27098 shl $2,%bl
27099+ pax_force_retaddr
27100 ret
27101
27102 /* rsi contains offset and can be scratched */
27103@@ -109,6 +114,7 @@ bpf_slow_path_word:
27104 js bpf_error
27105 mov -12(%rbp),%eax
27106 bswap %eax
27107+ pax_force_retaddr
27108 ret
27109
27110 bpf_slow_path_half:
27111@@ -117,12 +123,14 @@ bpf_slow_path_half:
27112 mov -12(%rbp),%ax
27113 rol $8,%ax
27114 movzwl %ax,%eax
27115+ pax_force_retaddr
27116 ret
27117
27118 bpf_slow_path_byte:
27119 bpf_slow_path_common(1)
27120 js bpf_error
27121 movzbl -12(%rbp),%eax
27122+ pax_force_retaddr
27123 ret
27124
27125 bpf_slow_path_byte_msh:
27126@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
27127 and $15,%al
27128 shl $2,%al
27129 xchg %eax,%ebx
27130+ pax_force_retaddr
27131 ret
27132
27133 #define sk_negative_common(SIZE) \
27134@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
27135 sk_negative_common(4)
27136 mov (%rax), %eax
27137 bswap %eax
27138+ pax_force_retaddr
27139 ret
27140
27141 bpf_slow_path_half_neg:
27142@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
27143 mov (%rax),%ax
27144 rol $8,%ax
27145 movzwl %ax,%eax
27146+ pax_force_retaddr
27147 ret
27148
27149 bpf_slow_path_byte_neg:
27150@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
27151 .globl sk_load_byte_negative_offset
27152 sk_negative_common(1)
27153 movzbl (%rax), %eax
27154+ pax_force_retaddr
27155 ret
27156
27157 bpf_slow_path_byte_msh_neg:
27158@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
27159 and $15,%al
27160 shl $2,%al
27161 xchg %eax,%ebx
27162+ pax_force_retaddr
27163 ret
27164
27165 bpf_error:
27166@@ -197,4 +210,5 @@ bpf_error:
27167 xor %eax,%eax
27168 mov -8(%rbp),%rbx
27169 leaveq
27170+ pax_force_retaddr
27171 ret
27172diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
27173index 520d2bd..b895ef4 100644
27174--- a/arch/x86/net/bpf_jit_comp.c
27175+++ b/arch/x86/net/bpf_jit_comp.c
27176@@ -11,6 +11,7 @@
27177 #include <asm/cacheflush.h>
27178 #include <linux/netdevice.h>
27179 #include <linux/filter.h>
27180+#include <linux/random.h>
27181
27182 /*
27183 * Conventions :
27184@@ -48,13 +49,87 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
27185 return ptr + len;
27186 }
27187
27188+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27189+#define MAX_INSTR_CODE_SIZE 96
27190+#else
27191+#define MAX_INSTR_CODE_SIZE 64
27192+#endif
27193+
27194 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
27195
27196 #define EMIT1(b1) EMIT(b1, 1)
27197 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
27198 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
27199 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
27200+
27201+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27202+/* original constant will appear in ecx */
27203+#define DILUTE_CONST_SEQUENCE(_off, _key) \
27204+do { \
27205+ /* mov ecx, randkey */ \
27206+ EMIT1(0xb9); \
27207+ EMIT(_key, 4); \
27208+ /* xor ecx, randkey ^ off */ \
27209+ EMIT2(0x81, 0xf1); \
27210+ EMIT((_key) ^ (_off), 4); \
27211+} while (0)
27212+
27213+#define EMIT1_off32(b1, _off) \
27214+do { \
27215+ switch (b1) { \
27216+ case 0x05: /* add eax, imm32 */ \
27217+ case 0x2d: /* sub eax, imm32 */ \
27218+ case 0x25: /* and eax, imm32 */ \
27219+ case 0x0d: /* or eax, imm32 */ \
27220+ case 0xb8: /* mov eax, imm32 */ \
27221+ case 0x3d: /* cmp eax, imm32 */ \
27222+ case 0xa9: /* test eax, imm32 */ \
27223+ DILUTE_CONST_SEQUENCE(_off, randkey); \
27224+ EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
27225+ break; \
27226+ case 0xbb: /* mov ebx, imm32 */ \
27227+ DILUTE_CONST_SEQUENCE(_off, randkey); \
27228+ /* mov ebx, ecx */ \
27229+ EMIT2(0x89, 0xcb); \
27230+ break; \
27231+ case 0xbe: /* mov esi, imm32 */ \
27232+ DILUTE_CONST_SEQUENCE(_off, randkey); \
27233+ /* mov esi, ecx */ \
27234+ EMIT2(0x89, 0xce); \
27235+ break; \
27236+ case 0xe9: /* jmp rel imm32 */ \
27237+ EMIT1(b1); \
27238+ EMIT(_off, 4); \
27239+ /* prevent fall-through, we're not called if off = 0 */ \
27240+ EMIT(0xcccccccc, 4); \
27241+ EMIT(0xcccccccc, 4); \
27242+ break; \
27243+ default: \
27244+ EMIT1(b1); \
27245+ EMIT(_off, 4); \
27246+ } \
27247+} while (0)
27248+
27249+#define EMIT2_off32(b1, b2, _off) \
27250+do { \
27251+ if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
27252+ EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
27253+ EMIT(randkey, 4); \
27254+ EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
27255+ EMIT((_off) - randkey, 4); \
27256+ } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
27257+ DILUTE_CONST_SEQUENCE(_off, randkey); \
27258+ /* imul eax, ecx */ \
27259+ EMIT3(0x0f, 0xaf, 0xc1); \
27260+ } else { \
27261+ EMIT2(b1, b2); \
27262+ EMIT(_off, 4); \
27263+ } \
27264+} while (0)
27265+#else
27266 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
27267+#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
27268+#endif
27269
27270 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
27271 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
27272@@ -89,6 +164,24 @@ do { \
27273 #define X86_JBE 0x76
27274 #define X86_JA 0x77
27275
27276+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27277+#define APPEND_FLOW_VERIFY() \
27278+do { \
27279+ /* mov ecx, randkey */ \
27280+ EMIT1(0xb9); \
27281+ EMIT(randkey, 4); \
27282+ /* cmp ecx, randkey */ \
27283+ EMIT2(0x81, 0xf9); \
27284+ EMIT(randkey, 4); \
27285+ /* jz after 8 int 3s */ \
27286+ EMIT2(0x74, 0x08); \
27287+ EMIT(0xcccccccc, 4); \
27288+ EMIT(0xcccccccc, 4); \
27289+} while (0)
27290+#else
27291+#define APPEND_FLOW_VERIFY() do { } while (0)
27292+#endif
27293+
27294 #define EMIT_COND_JMP(op, offset) \
27295 do { \
27296 if (is_near(offset)) \
27297@@ -96,6 +189,7 @@ do { \
27298 else { \
27299 EMIT2(0x0f, op + 0x10); \
27300 EMIT(offset, 4); /* jxx .+off32 */ \
27301+ APPEND_FLOW_VERIFY(); \
27302 } \
27303 } while (0)
27304
27305@@ -120,12 +214,17 @@ static inline void bpf_flush_icache(void *start, void *end)
27306 set_fs(old_fs);
27307 }
27308
27309+struct bpf_jit_work {
27310+ struct work_struct work;
27311+ void *image;
27312+};
27313+
27314 #define CHOOSE_LOAD_FUNC(K, func) \
27315 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
27316
27317 void bpf_jit_compile(struct sk_filter *fp)
27318 {
27319- u8 temp[64];
27320+ u8 temp[MAX_INSTR_CODE_SIZE];
27321 u8 *prog;
27322 unsigned int proglen, oldproglen = 0;
27323 int ilen, i;
27324@@ -138,6 +237,9 @@ void bpf_jit_compile(struct sk_filter *fp)
27325 unsigned int *addrs;
27326 const struct sock_filter *filter = fp->insns;
27327 int flen = fp->len;
27328+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27329+ unsigned int randkey;
27330+#endif
27331
27332 if (!bpf_jit_enable)
27333 return;
27334@@ -146,11 +248,19 @@ void bpf_jit_compile(struct sk_filter *fp)
27335 if (addrs == NULL)
27336 return;
27337
27338+ fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
27339+ if (!fp->work)
27340+ goto out;
27341+
27342+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27343+ randkey = get_random_int();
27344+#endif
27345+
27346 /* Before first pass, make a rough estimation of addrs[]
27347- * each bpf instruction is translated to less than 64 bytes
27348+ * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
27349 */
27350 for (proglen = 0, i = 0; i < flen; i++) {
27351- proglen += 64;
27352+ proglen += MAX_INSTR_CODE_SIZE;
27353 addrs[i] = proglen;
27354 }
27355 cleanup_addr = proglen; /* epilogue address */
27356@@ -258,10 +368,8 @@ void bpf_jit_compile(struct sk_filter *fp)
27357 case BPF_S_ALU_MUL_K: /* A *= K */
27358 if (is_imm8(K))
27359 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
27360- else {
27361- EMIT2(0x69, 0xc0); /* imul imm32,%eax */
27362- EMIT(K, 4);
27363- }
27364+ else
27365+ EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
27366 break;
27367 case BPF_S_ALU_DIV_X: /* A /= X; */
27368 seen |= SEEN_XREG;
27369@@ -301,13 +409,23 @@ void bpf_jit_compile(struct sk_filter *fp)
27370 break;
27371 case BPF_S_ALU_MOD_K: /* A %= K; */
27372 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
27373+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27374+ DILUTE_CONST_SEQUENCE(K, randkey);
27375+#else
27376 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
27377+#endif
27378 EMIT2(0xf7, 0xf1); /* div %ecx */
27379 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
27380 break;
27381 case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */
27382+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27383+ DILUTE_CONST_SEQUENCE(K, randkey);
27384+ // imul rax, rcx
27385+ EMIT4(0x48, 0x0f, 0xaf, 0xc1);
27386+#else
27387 EMIT3(0x48, 0x69, 0xc0); /* imul imm32,%rax,%rax */
27388 EMIT(K, 4);
27389+#endif
27390 EMIT4(0x48, 0xc1, 0xe8, 0x20); /* shr $0x20,%rax */
27391 break;
27392 case BPF_S_ALU_AND_X:
27393@@ -543,8 +661,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
27394 if (is_imm8(K)) {
27395 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
27396 } else {
27397- EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
27398- EMIT(K, 4);
27399+ EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
27400 }
27401 } else {
27402 EMIT2(0x89,0xde); /* mov %ebx,%esi */
27403@@ -627,17 +744,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
27404 break;
27405 default:
27406 /* hmm, too complex filter, give up with jit compiler */
27407- goto out;
27408+ goto error;
27409 }
27410 ilen = prog - temp;
27411 if (image) {
27412 if (unlikely(proglen + ilen > oldproglen)) {
27413 pr_err("bpb_jit_compile fatal error\n");
27414- kfree(addrs);
27415- module_free(NULL, image);
27416- return;
27417+ module_free_exec(NULL, image);
27418+ goto error;
27419 }
27420+ pax_open_kernel();
27421 memcpy(image + proglen, temp, ilen);
27422+ pax_close_kernel();
27423 }
27424 proglen += ilen;
27425 addrs[i] = proglen;
27426@@ -658,11 +776,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
27427 break;
27428 }
27429 if (proglen == oldproglen) {
27430- image = module_alloc(max_t(unsigned int,
27431- proglen,
27432- sizeof(struct work_struct)));
27433+ image = module_alloc_exec(proglen);
27434 if (!image)
27435- goto out;
27436+ goto error;
27437 }
27438 oldproglen = proglen;
27439 }
27440@@ -678,7 +794,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
27441 bpf_flush_icache(image, image + proglen);
27442
27443 fp->bpf_func = (void *)image;
27444- }
27445+ } else
27446+error:
27447+ kfree(fp->work);
27448+
27449 out:
27450 kfree(addrs);
27451 return;
27452@@ -686,18 +805,20 @@ out:
27453
27454 static void jit_free_defer(struct work_struct *arg)
27455 {
27456- module_free(NULL, arg);
27457+ module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
27458+ kfree(arg);
27459 }
27460
27461 /* run from softirq, we must use a work_struct to call
27462- * module_free() from process context
27463+ * module_free_exec() from process context
27464 */
27465 void bpf_jit_free(struct sk_filter *fp)
27466 {
27467 if (fp->bpf_func != sk_run_filter) {
27468- struct work_struct *work = (struct work_struct *)fp->bpf_func;
27469+ struct work_struct *work = &fp->work->work;
27470
27471 INIT_WORK(work, jit_free_defer);
27472+ fp->work->image = fp->bpf_func;
27473 schedule_work(work);
27474 }
27475 }
27476diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
27477index d6aa6e8..266395a 100644
27478--- a/arch/x86/oprofile/backtrace.c
27479+++ b/arch/x86/oprofile/backtrace.c
27480@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
27481 struct stack_frame_ia32 *fp;
27482 unsigned long bytes;
27483
27484- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
27485+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
27486 if (bytes != sizeof(bufhead))
27487 return NULL;
27488
27489- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
27490+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
27491
27492 oprofile_add_trace(bufhead[0].return_address);
27493
27494@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
27495 struct stack_frame bufhead[2];
27496 unsigned long bytes;
27497
27498- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
27499+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
27500 if (bytes != sizeof(bufhead))
27501 return NULL;
27502
27503@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
27504 {
27505 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
27506
27507- if (!user_mode_vm(regs)) {
27508+ if (!user_mode(regs)) {
27509 unsigned long stack = kernel_stack_pointer(regs);
27510 if (depth)
27511 dump_trace(NULL, regs, (unsigned long *)stack, 0,
27512diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
27513index e14a2ff..3fd6b58 100644
27514--- a/arch/x86/pci/mrst.c
27515+++ b/arch/x86/pci/mrst.c
27516@@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
27517 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
27518 pci_mmcfg_late_init();
27519 pcibios_enable_irq = mrst_pci_irq_enable;
27520- pci_root_ops = pci_mrst_ops;
27521+ pax_open_kernel();
27522+ memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
27523+ pax_close_kernel();
27524 pci_soc_mode = 1;
27525 /* Continue with standard init */
27526 return 1;
27527diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
27528index da8fe05..7ee6704 100644
27529--- a/arch/x86/pci/pcbios.c
27530+++ b/arch/x86/pci/pcbios.c
27531@@ -79,50 +79,93 @@ union bios32 {
27532 static struct {
27533 unsigned long address;
27534 unsigned short segment;
27535-} bios32_indirect = { 0, __KERNEL_CS };
27536+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
27537
27538 /*
27539 * Returns the entry point for the given service, NULL on error
27540 */
27541
27542-static unsigned long bios32_service(unsigned long service)
27543+static unsigned long __devinit bios32_service(unsigned long service)
27544 {
27545 unsigned char return_code; /* %al */
27546 unsigned long address; /* %ebx */
27547 unsigned long length; /* %ecx */
27548 unsigned long entry; /* %edx */
27549 unsigned long flags;
27550+ struct desc_struct d, *gdt;
27551
27552 local_irq_save(flags);
27553- __asm__("lcall *(%%edi); cld"
27554+
27555+ gdt = get_cpu_gdt_table(smp_processor_id());
27556+
27557+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
27558+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
27559+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
27560+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
27561+
27562+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
27563 : "=a" (return_code),
27564 "=b" (address),
27565 "=c" (length),
27566 "=d" (entry)
27567 : "0" (service),
27568 "1" (0),
27569- "D" (&bios32_indirect));
27570+ "D" (&bios32_indirect),
27571+ "r"(__PCIBIOS_DS)
27572+ : "memory");
27573+
27574+ pax_open_kernel();
27575+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
27576+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
27577+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
27578+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
27579+ pax_close_kernel();
27580+
27581 local_irq_restore(flags);
27582
27583 switch (return_code) {
27584- case 0:
27585- return address + entry;
27586- case 0x80: /* Not present */
27587- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
27588- return 0;
27589- default: /* Shouldn't happen */
27590- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
27591- service, return_code);
27592+ case 0: {
27593+ int cpu;
27594+ unsigned char flags;
27595+
27596+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
27597+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
27598+ printk(KERN_WARNING "bios32_service: not valid\n");
27599 return 0;
27600+ }
27601+ address = address + PAGE_OFFSET;
27602+ length += 16UL; /* some BIOSs underreport this... */
27603+ flags = 4;
27604+ if (length >= 64*1024*1024) {
27605+ length >>= PAGE_SHIFT;
27606+ flags |= 8;
27607+ }
27608+
27609+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
27610+ gdt = get_cpu_gdt_table(cpu);
27611+ pack_descriptor(&d, address, length, 0x9b, flags);
27612+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
27613+ pack_descriptor(&d, address, length, 0x93, flags);
27614+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
27615+ }
27616+ return entry;
27617+ }
27618+ case 0x80: /* Not present */
27619+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
27620+ return 0;
27621+ default: /* Shouldn't happen */
27622+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
27623+ service, return_code);
27624+ return 0;
27625 }
27626 }
27627
27628 static struct {
27629 unsigned long address;
27630 unsigned short segment;
27631-} pci_indirect = { 0, __KERNEL_CS };
27632+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
27633
27634-static int pci_bios_present;
27635+static int pci_bios_present __read_only;
27636
27637 static int __devinit check_pcibios(void)
27638 {
27639@@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
27640 unsigned long flags, pcibios_entry;
27641
27642 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
27643- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
27644+ pci_indirect.address = pcibios_entry;
27645
27646 local_irq_save(flags);
27647- __asm__(
27648- "lcall *(%%edi); cld\n\t"
27649+ __asm__("movw %w6, %%ds\n\t"
27650+ "lcall *%%ss:(%%edi); cld\n\t"
27651+ "push %%ss\n\t"
27652+ "pop %%ds\n\t"
27653 "jc 1f\n\t"
27654 "xor %%ah, %%ah\n"
27655 "1:"
27656@@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
27657 "=b" (ebx),
27658 "=c" (ecx)
27659 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
27660- "D" (&pci_indirect)
27661+ "D" (&pci_indirect),
27662+ "r" (__PCIBIOS_DS)
27663 : "memory");
27664 local_irq_restore(flags);
27665
27666@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
27667
27668 switch (len) {
27669 case 1:
27670- __asm__("lcall *(%%esi); cld\n\t"
27671+ __asm__("movw %w6, %%ds\n\t"
27672+ "lcall *%%ss:(%%esi); cld\n\t"
27673+ "push %%ss\n\t"
27674+ "pop %%ds\n\t"
27675 "jc 1f\n\t"
27676 "xor %%ah, %%ah\n"
27677 "1:"
27678@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
27679 : "1" (PCIBIOS_READ_CONFIG_BYTE),
27680 "b" (bx),
27681 "D" ((long)reg),
27682- "S" (&pci_indirect));
27683+ "S" (&pci_indirect),
27684+ "r" (__PCIBIOS_DS));
27685 /*
27686 * Zero-extend the result beyond 8 bits, do not trust the
27687 * BIOS having done it:
27688@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
27689 *value &= 0xff;
27690 break;
27691 case 2:
27692- __asm__("lcall *(%%esi); cld\n\t"
27693+ __asm__("movw %w6, %%ds\n\t"
27694+ "lcall *%%ss:(%%esi); cld\n\t"
27695+ "push %%ss\n\t"
27696+ "pop %%ds\n\t"
27697 "jc 1f\n\t"
27698 "xor %%ah, %%ah\n"
27699 "1:"
27700@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
27701 : "1" (PCIBIOS_READ_CONFIG_WORD),
27702 "b" (bx),
27703 "D" ((long)reg),
27704- "S" (&pci_indirect));
27705+ "S" (&pci_indirect),
27706+ "r" (__PCIBIOS_DS));
27707 /*
27708 * Zero-extend the result beyond 16 bits, do not trust the
27709 * BIOS having done it:
27710@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
27711 *value &= 0xffff;
27712 break;
27713 case 4:
27714- __asm__("lcall *(%%esi); cld\n\t"
27715+ __asm__("movw %w6, %%ds\n\t"
27716+ "lcall *%%ss:(%%esi); cld\n\t"
27717+ "push %%ss\n\t"
27718+ "pop %%ds\n\t"
27719 "jc 1f\n\t"
27720 "xor %%ah, %%ah\n"
27721 "1:"
27722@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
27723 : "1" (PCIBIOS_READ_CONFIG_DWORD),
27724 "b" (bx),
27725 "D" ((long)reg),
27726- "S" (&pci_indirect));
27727+ "S" (&pci_indirect),
27728+ "r" (__PCIBIOS_DS));
27729 break;
27730 }
27731
27732@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
27733
27734 switch (len) {
27735 case 1:
27736- __asm__("lcall *(%%esi); cld\n\t"
27737+ __asm__("movw %w6, %%ds\n\t"
27738+ "lcall *%%ss:(%%esi); cld\n\t"
27739+ "push %%ss\n\t"
27740+ "pop %%ds\n\t"
27741 "jc 1f\n\t"
27742 "xor %%ah, %%ah\n"
27743 "1:"
27744@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
27745 "c" (value),
27746 "b" (bx),
27747 "D" ((long)reg),
27748- "S" (&pci_indirect));
27749+ "S" (&pci_indirect),
27750+ "r" (__PCIBIOS_DS));
27751 break;
27752 case 2:
27753- __asm__("lcall *(%%esi); cld\n\t"
27754+ __asm__("movw %w6, %%ds\n\t"
27755+ "lcall *%%ss:(%%esi); cld\n\t"
27756+ "push %%ss\n\t"
27757+ "pop %%ds\n\t"
27758 "jc 1f\n\t"
27759 "xor %%ah, %%ah\n"
27760 "1:"
27761@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
27762 "c" (value),
27763 "b" (bx),
27764 "D" ((long)reg),
27765- "S" (&pci_indirect));
27766+ "S" (&pci_indirect),
27767+ "r" (__PCIBIOS_DS));
27768 break;
27769 case 4:
27770- __asm__("lcall *(%%esi); cld\n\t"
27771+ __asm__("movw %w6, %%ds\n\t"
27772+ "lcall *%%ss:(%%esi); cld\n\t"
27773+ "push %%ss\n\t"
27774+ "pop %%ds\n\t"
27775 "jc 1f\n\t"
27776 "xor %%ah, %%ah\n"
27777 "1:"
27778@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
27779 "c" (value),
27780 "b" (bx),
27781 "D" ((long)reg),
27782- "S" (&pci_indirect));
27783+ "S" (&pci_indirect),
27784+ "r" (__PCIBIOS_DS));
27785 break;
27786 }
27787
27788@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
27789
27790 DBG("PCI: Fetching IRQ routing table... ");
27791 __asm__("push %%es\n\t"
27792+ "movw %w8, %%ds\n\t"
27793 "push %%ds\n\t"
27794 "pop %%es\n\t"
27795- "lcall *(%%esi); cld\n\t"
27796+ "lcall *%%ss:(%%esi); cld\n\t"
27797 "pop %%es\n\t"
27798+ "push %%ss\n\t"
27799+ "pop %%ds\n"
27800 "jc 1f\n\t"
27801 "xor %%ah, %%ah\n"
27802 "1:"
27803@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
27804 "1" (0),
27805 "D" ((long) &opt),
27806 "S" (&pci_indirect),
27807- "m" (opt)
27808+ "m" (opt),
27809+ "r" (__PCIBIOS_DS)
27810 : "memory");
27811 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
27812 if (ret & 0xff00)
27813@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
27814 {
27815 int ret;
27816
27817- __asm__("lcall *(%%esi); cld\n\t"
27818+ __asm__("movw %w5, %%ds\n\t"
27819+ "lcall *%%ss:(%%esi); cld\n\t"
27820+ "push %%ss\n\t"
27821+ "pop %%ds\n"
27822 "jc 1f\n\t"
27823 "xor %%ah, %%ah\n"
27824 "1:"
27825@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
27826 : "0" (PCIBIOS_SET_PCI_HW_INT),
27827 "b" ((dev->bus->number << 8) | dev->devfn),
27828 "c" ((irq << 8) | (pin + 10)),
27829- "S" (&pci_indirect));
27830+ "S" (&pci_indirect),
27831+ "r" (__PCIBIOS_DS));
27832 return !(ret & 0xff00);
27833 }
27834 EXPORT_SYMBOL(pcibios_set_irq_routing);
27835diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
27836index 40e4469..1ab536e 100644
27837--- a/arch/x86/platform/efi/efi_32.c
27838+++ b/arch/x86/platform/efi/efi_32.c
27839@@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
27840 {
27841 struct desc_ptr gdt_descr;
27842
27843+#ifdef CONFIG_PAX_KERNEXEC
27844+ struct desc_struct d;
27845+#endif
27846+
27847 local_irq_save(efi_rt_eflags);
27848
27849 load_cr3(initial_page_table);
27850 __flush_tlb_all();
27851
27852+#ifdef CONFIG_PAX_KERNEXEC
27853+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
27854+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
27855+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
27856+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
27857+#endif
27858+
27859 gdt_descr.address = __pa(get_cpu_gdt_table(0));
27860 gdt_descr.size = GDT_SIZE - 1;
27861 load_gdt(&gdt_descr);
27862@@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
27863 {
27864 struct desc_ptr gdt_descr;
27865
27866+#ifdef CONFIG_PAX_KERNEXEC
27867+ struct desc_struct d;
27868+
27869+ memset(&d, 0, sizeof d);
27870+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
27871+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
27872+#endif
27873+
27874 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
27875 gdt_descr.size = GDT_SIZE - 1;
27876 load_gdt(&gdt_descr);
27877diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
27878index fbe66e6..eae5e38 100644
27879--- a/arch/x86/platform/efi/efi_stub_32.S
27880+++ b/arch/x86/platform/efi/efi_stub_32.S
27881@@ -6,7 +6,9 @@
27882 */
27883
27884 #include <linux/linkage.h>
27885+#include <linux/init.h>
27886 #include <asm/page_types.h>
27887+#include <asm/segment.h>
27888
27889 /*
27890 * efi_call_phys(void *, ...) is a function with variable parameters.
27891@@ -20,7 +22,7 @@
27892 * service functions will comply with gcc calling convention, too.
27893 */
27894
27895-.text
27896+__INIT
27897 ENTRY(efi_call_phys)
27898 /*
27899 * 0. The function can only be called in Linux kernel. So CS has been
27900@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
27901 * The mapping of lower virtual memory has been created in prelog and
27902 * epilog.
27903 */
27904- movl $1f, %edx
27905- subl $__PAGE_OFFSET, %edx
27906- jmp *%edx
27907+#ifdef CONFIG_PAX_KERNEXEC
27908+ movl $(__KERNEXEC_EFI_DS), %edx
27909+ mov %edx, %ds
27910+ mov %edx, %es
27911+ mov %edx, %ss
27912+ addl $2f,(1f)
27913+ ljmp *(1f)
27914+
27915+__INITDATA
27916+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
27917+.previous
27918+
27919+2:
27920+ subl $2b,(1b)
27921+#else
27922+ jmp 1f-__PAGE_OFFSET
27923 1:
27924+#endif
27925
27926 /*
27927 * 2. Now on the top of stack is the return
27928@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
27929 * parameter 2, ..., param n. To make things easy, we save the return
27930 * address of efi_call_phys in a global variable.
27931 */
27932- popl %edx
27933- movl %edx, saved_return_addr
27934- /* get the function pointer into ECX*/
27935- popl %ecx
27936- movl %ecx, efi_rt_function_ptr
27937- movl $2f, %edx
27938- subl $__PAGE_OFFSET, %edx
27939- pushl %edx
27940+ popl (saved_return_addr)
27941+ popl (efi_rt_function_ptr)
27942
27943 /*
27944 * 3. Clear PG bit in %CR0.
27945@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
27946 /*
27947 * 5. Call the physical function.
27948 */
27949- jmp *%ecx
27950+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
27951
27952-2:
27953 /*
27954 * 6. After EFI runtime service returns, control will return to
27955 * following instruction. We'd better readjust stack pointer first.
27956@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
27957 movl %cr0, %edx
27958 orl $0x80000000, %edx
27959 movl %edx, %cr0
27960- jmp 1f
27961-1:
27962+
27963 /*
27964 * 8. Now restore the virtual mode from flat mode by
27965 * adding EIP with PAGE_OFFSET.
27966 */
27967- movl $1f, %edx
27968- jmp *%edx
27969+#ifdef CONFIG_PAX_KERNEXEC
27970+ movl $(__KERNEL_DS), %edx
27971+ mov %edx, %ds
27972+ mov %edx, %es
27973+ mov %edx, %ss
27974+ ljmp $(__KERNEL_CS),$1f
27975+#else
27976+ jmp 1f+__PAGE_OFFSET
27977+#endif
27978 1:
27979
27980 /*
27981 * 9. Balance the stack. And because EAX contain the return value,
27982 * we'd better not clobber it.
27983 */
27984- leal efi_rt_function_ptr, %edx
27985- movl (%edx), %ecx
27986- pushl %ecx
27987+ pushl (efi_rt_function_ptr)
27988
27989 /*
27990- * 10. Push the saved return address onto the stack and return.
27991+ * 10. Return to the saved return address.
27992 */
27993- leal saved_return_addr, %edx
27994- movl (%edx), %ecx
27995- pushl %ecx
27996- ret
27997+ jmpl *(saved_return_addr)
27998 ENDPROC(efi_call_phys)
27999 .previous
28000
28001-.data
28002+__INITDATA
28003 saved_return_addr:
28004 .long 0
28005 efi_rt_function_ptr:
28006diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
28007index 4c07cca..2c8427d 100644
28008--- a/arch/x86/platform/efi/efi_stub_64.S
28009+++ b/arch/x86/platform/efi/efi_stub_64.S
28010@@ -7,6 +7,7 @@
28011 */
28012
28013 #include <linux/linkage.h>
28014+#include <asm/alternative-asm.h>
28015
28016 #define SAVE_XMM \
28017 mov %rsp, %rax; \
28018@@ -40,6 +41,7 @@ ENTRY(efi_call0)
28019 call *%rdi
28020 addq $32, %rsp
28021 RESTORE_XMM
28022+ pax_force_retaddr 0, 1
28023 ret
28024 ENDPROC(efi_call0)
28025
28026@@ -50,6 +52,7 @@ ENTRY(efi_call1)
28027 call *%rdi
28028 addq $32, %rsp
28029 RESTORE_XMM
28030+ pax_force_retaddr 0, 1
28031 ret
28032 ENDPROC(efi_call1)
28033
28034@@ -60,6 +63,7 @@ ENTRY(efi_call2)
28035 call *%rdi
28036 addq $32, %rsp
28037 RESTORE_XMM
28038+ pax_force_retaddr 0, 1
28039 ret
28040 ENDPROC(efi_call2)
28041
28042@@ -71,6 +75,7 @@ ENTRY(efi_call3)
28043 call *%rdi
28044 addq $32, %rsp
28045 RESTORE_XMM
28046+ pax_force_retaddr 0, 1
28047 ret
28048 ENDPROC(efi_call3)
28049
28050@@ -83,6 +88,7 @@ ENTRY(efi_call4)
28051 call *%rdi
28052 addq $32, %rsp
28053 RESTORE_XMM
28054+ pax_force_retaddr 0, 1
28055 ret
28056 ENDPROC(efi_call4)
28057
28058@@ -96,6 +102,7 @@ ENTRY(efi_call5)
28059 call *%rdi
28060 addq $48, %rsp
28061 RESTORE_XMM
28062+ pax_force_retaddr 0, 1
28063 ret
28064 ENDPROC(efi_call5)
28065
28066@@ -112,5 +119,6 @@ ENTRY(efi_call6)
28067 call *%rdi
28068 addq $48, %rsp
28069 RESTORE_XMM
28070+ pax_force_retaddr 0, 1
28071 ret
28072 ENDPROC(efi_call6)
28073diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
28074index fd41a92..9c33628 100644
28075--- a/arch/x86/platform/mrst/mrst.c
28076+++ b/arch/x86/platform/mrst/mrst.c
28077@@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
28078 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
28079 int sfi_mrtc_num;
28080
28081-static void mrst_power_off(void)
28082+static __noreturn void mrst_power_off(void)
28083 {
28084+ BUG();
28085 }
28086
28087-static void mrst_reboot(void)
28088+static __noreturn void mrst_reboot(void)
28089 {
28090 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
28091+ BUG();
28092 }
28093
28094 /* parse all the mtimer info to a static mtimer array */
28095diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
28096index 218cdb1..c1178eb 100644
28097--- a/arch/x86/power/cpu.c
28098+++ b/arch/x86/power/cpu.c
28099@@ -132,7 +132,7 @@ static void do_fpu_end(void)
28100 static void fix_processor_context(void)
28101 {
28102 int cpu = smp_processor_id();
28103- struct tss_struct *t = &per_cpu(init_tss, cpu);
28104+ struct tss_struct *t = init_tss + cpu;
28105
28106 set_tss_desc(cpu, t); /*
28107 * This just modifies memory; should not be
28108@@ -142,8 +142,6 @@ static void fix_processor_context(void)
28109 */
28110
28111 #ifdef CONFIG_X86_64
28112- get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
28113-
28114 syscall_init(); /* This sets MSR_*STAR and related */
28115 #endif
28116 load_TR_desc(); /* This does ltr */
28117diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
28118index cbca565..bae7133 100644
28119--- a/arch/x86/realmode/init.c
28120+++ b/arch/x86/realmode/init.c
28121@@ -62,7 +62,13 @@ void __init setup_real_mode(void)
28122 __va(real_mode_header->trampoline_header);
28123
28124 #ifdef CONFIG_X86_32
28125- trampoline_header->start = __pa(startup_32_smp);
28126+ trampoline_header->start = __pa(ktla_ktva(startup_32_smp));
28127+
28128+#ifdef CONFIG_PAX_KERNEXEC
28129+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
28130+#endif
28131+
28132+ trampoline_header->boot_cs = __BOOT_CS;
28133 trampoline_header->gdt_limit = __BOOT_DS + 7;
28134 trampoline_header->gdt_base = __pa(boot_gdt);
28135 #else
28136diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
28137index 8869287..d577672 100644
28138--- a/arch/x86/realmode/rm/Makefile
28139+++ b/arch/x86/realmode/rm/Makefile
28140@@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
28141 $(call cc-option, -fno-unit-at-a-time)) \
28142 $(call cc-option, -fno-stack-protector) \
28143 $(call cc-option, -mpreferred-stack-boundary=2)
28144+ifdef CONSTIFY_PLUGIN
28145+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
28146+endif
28147 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
28148 GCOV_PROFILE := n
28149diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
28150index a28221d..93c40f1 100644
28151--- a/arch/x86/realmode/rm/header.S
28152+++ b/arch/x86/realmode/rm/header.S
28153@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
28154 #endif
28155 /* APM/BIOS reboot */
28156 .long pa_machine_real_restart_asm
28157-#ifdef CONFIG_X86_64
28158+#ifdef CONFIG_X86_32
28159+ .long __KERNEL_CS
28160+#else
28161 .long __KERNEL32_CS
28162 #endif
28163 END(real_mode_header)
28164diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
28165index c1b2791..f9e31c7 100644
28166--- a/arch/x86/realmode/rm/trampoline_32.S
28167+++ b/arch/x86/realmode/rm/trampoline_32.S
28168@@ -25,6 +25,12 @@
28169 #include <asm/page_types.h>
28170 #include "realmode.h"
28171
28172+#ifdef CONFIG_PAX_KERNEXEC
28173+#define ta(X) (X)
28174+#else
28175+#define ta(X) (pa_ ## X)
28176+#endif
28177+
28178 .text
28179 .code16
28180
28181@@ -39,8 +45,6 @@ ENTRY(trampoline_start)
28182
28183 cli # We should be safe anyway
28184
28185- movl tr_start, %eax # where we need to go
28186-
28187 movl $0xA5A5A5A5, trampoline_status
28188 # write marker for master knows we're running
28189
28190@@ -56,7 +60,7 @@ ENTRY(trampoline_start)
28191 movw $1, %dx # protected mode (PE) bit
28192 lmsw %dx # into protected mode
28193
28194- ljmpl $__BOOT_CS, $pa_startup_32
28195+ ljmpl *(trampoline_header)
28196
28197 .section ".text32","ax"
28198 .code32
28199@@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
28200 .balign 8
28201 GLOBAL(trampoline_header)
28202 tr_start: .space 4
28203- tr_gdt_pad: .space 2
28204+ tr_boot_cs: .space 2
28205 tr_gdt: .space 6
28206 END(trampoline_header)
28207
28208diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
28209index bb360dc..3e5945f 100644
28210--- a/arch/x86/realmode/rm/trampoline_64.S
28211+++ b/arch/x86/realmode/rm/trampoline_64.S
28212@@ -107,7 +107,7 @@ ENTRY(startup_32)
28213 wrmsr
28214
28215 # Enable paging and in turn activate Long Mode
28216- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
28217+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
28218 movl %eax, %cr0
28219
28220 /*
28221diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
28222index 5a1847d..deccb30 100644
28223--- a/arch/x86/tools/relocs.c
28224+++ b/arch/x86/tools/relocs.c
28225@@ -12,10 +12,13 @@
28226 #include <regex.h>
28227 #include <tools/le_byteshift.h>
28228
28229+#include "../../../include/generated/autoconf.h"
28230+
28231 static void die(char *fmt, ...);
28232
28233 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
28234 static Elf32_Ehdr ehdr;
28235+static Elf32_Phdr *phdr;
28236 static unsigned long reloc_count, reloc_idx;
28237 static unsigned long *relocs;
28238 static unsigned long reloc16_count, reloc16_idx;
28239@@ -330,9 +333,39 @@ static void read_ehdr(FILE *fp)
28240 }
28241 }
28242
28243+static void read_phdrs(FILE *fp)
28244+{
28245+ unsigned int i;
28246+
28247+ phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
28248+ if (!phdr) {
28249+ die("Unable to allocate %d program headers\n",
28250+ ehdr.e_phnum);
28251+ }
28252+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
28253+ die("Seek to %d failed: %s\n",
28254+ ehdr.e_phoff, strerror(errno));
28255+ }
28256+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
28257+ die("Cannot read ELF program headers: %s\n",
28258+ strerror(errno));
28259+ }
28260+ for(i = 0; i < ehdr.e_phnum; i++) {
28261+ phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
28262+ phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
28263+ phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
28264+ phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
28265+ phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
28266+ phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
28267+ phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
28268+ phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
28269+ }
28270+
28271+}
28272+
28273 static void read_shdrs(FILE *fp)
28274 {
28275- int i;
28276+ unsigned int i;
28277 Elf32_Shdr shdr;
28278
28279 secs = calloc(ehdr.e_shnum, sizeof(struct section));
28280@@ -367,7 +400,7 @@ static void read_shdrs(FILE *fp)
28281
28282 static void read_strtabs(FILE *fp)
28283 {
28284- int i;
28285+ unsigned int i;
28286 for (i = 0; i < ehdr.e_shnum; i++) {
28287 struct section *sec = &secs[i];
28288 if (sec->shdr.sh_type != SHT_STRTAB) {
28289@@ -392,7 +425,7 @@ static void read_strtabs(FILE *fp)
28290
28291 static void read_symtabs(FILE *fp)
28292 {
28293- int i,j;
28294+ unsigned int i,j;
28295 for (i = 0; i < ehdr.e_shnum; i++) {
28296 struct section *sec = &secs[i];
28297 if (sec->shdr.sh_type != SHT_SYMTAB) {
28298@@ -423,9 +456,11 @@ static void read_symtabs(FILE *fp)
28299 }
28300
28301
28302-static void read_relocs(FILE *fp)
28303+static void read_relocs(FILE *fp, int use_real_mode)
28304 {
28305- int i,j;
28306+ unsigned int i,j;
28307+ uint32_t base;
28308+
28309 for (i = 0; i < ehdr.e_shnum; i++) {
28310 struct section *sec = &secs[i];
28311 if (sec->shdr.sh_type != SHT_REL) {
28312@@ -445,9 +480,22 @@ static void read_relocs(FILE *fp)
28313 die("Cannot read symbol table: %s\n",
28314 strerror(errno));
28315 }
28316+ base = 0;
28317+
28318+#ifdef CONFIG_X86_32
28319+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
28320+ if (phdr[j].p_type != PT_LOAD )
28321+ continue;
28322+ 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)
28323+ continue;
28324+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
28325+ break;
28326+ }
28327+#endif
28328+
28329 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
28330 Elf32_Rel *rel = &sec->reltab[j];
28331- rel->r_offset = elf32_to_cpu(rel->r_offset);
28332+ rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
28333 rel->r_info = elf32_to_cpu(rel->r_info);
28334 }
28335 }
28336@@ -456,13 +504,13 @@ static void read_relocs(FILE *fp)
28337
28338 static void print_absolute_symbols(void)
28339 {
28340- int i;
28341+ unsigned int i;
28342 printf("Absolute symbols\n");
28343 printf(" Num: Value Size Type Bind Visibility Name\n");
28344 for (i = 0; i < ehdr.e_shnum; i++) {
28345 struct section *sec = &secs[i];
28346 char *sym_strtab;
28347- int j;
28348+ unsigned int j;
28349
28350 if (sec->shdr.sh_type != SHT_SYMTAB) {
28351 continue;
28352@@ -489,14 +537,14 @@ static void print_absolute_symbols(void)
28353
28354 static void print_absolute_relocs(void)
28355 {
28356- int i, printed = 0;
28357+ unsigned int i, printed = 0;
28358
28359 for (i = 0; i < ehdr.e_shnum; i++) {
28360 struct section *sec = &secs[i];
28361 struct section *sec_applies, *sec_symtab;
28362 char *sym_strtab;
28363 Elf32_Sym *sh_symtab;
28364- int j;
28365+ unsigned int j;
28366 if (sec->shdr.sh_type != SHT_REL) {
28367 continue;
28368 }
28369@@ -558,13 +606,13 @@ static void print_absolute_relocs(void)
28370 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
28371 int use_real_mode)
28372 {
28373- int i;
28374+ unsigned int i;
28375 /* Walk through the relocations */
28376 for (i = 0; i < ehdr.e_shnum; i++) {
28377 char *sym_strtab;
28378 Elf32_Sym *sh_symtab;
28379 struct section *sec_applies, *sec_symtab;
28380- int j;
28381+ unsigned int j;
28382 struct section *sec = &secs[i];
28383
28384 if (sec->shdr.sh_type != SHT_REL) {
28385@@ -588,6 +636,24 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
28386 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
28387 r_type = ELF32_R_TYPE(rel->r_info);
28388
28389+ if (!use_real_mode) {
28390+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
28391+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
28392+ continue;
28393+
28394+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
28395+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
28396+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
28397+ continue;
28398+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
28399+ continue;
28400+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
28401+ continue;
28402+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
28403+ continue;
28404+#endif
28405+ }
28406+
28407 shn_abs = sym->st_shndx == SHN_ABS;
28408
28409 switch (r_type) {
28410@@ -681,7 +747,7 @@ static int write32(unsigned int v, FILE *f)
28411
28412 static void emit_relocs(int as_text, int use_real_mode)
28413 {
28414- int i;
28415+ unsigned int i;
28416 /* Count how many relocations I have and allocate space for them. */
28417 reloc_count = 0;
28418 walk_relocs(count_reloc, use_real_mode);
28419@@ -808,10 +874,11 @@ int main(int argc, char **argv)
28420 fname, strerror(errno));
28421 }
28422 read_ehdr(fp);
28423+ read_phdrs(fp);
28424 read_shdrs(fp);
28425 read_strtabs(fp);
28426 read_symtabs(fp);
28427- read_relocs(fp);
28428+ read_relocs(fp, use_real_mode);
28429 if (show_absolute_syms) {
28430 print_absolute_symbols();
28431 return 0;
28432diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
28433index fd14be1..e3c79c0 100644
28434--- a/arch/x86/vdso/Makefile
28435+++ b/arch/x86/vdso/Makefile
28436@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
28437 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
28438 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
28439
28440-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
28441+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
28442 GCOV_PROFILE := n
28443
28444 #
28445diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
28446index 0faad64..39ef157 100644
28447--- a/arch/x86/vdso/vdso32-setup.c
28448+++ b/arch/x86/vdso/vdso32-setup.c
28449@@ -25,6 +25,7 @@
28450 #include <asm/tlbflush.h>
28451 #include <asm/vdso.h>
28452 #include <asm/proto.h>
28453+#include <asm/mman.h>
28454
28455 enum {
28456 VDSO_DISABLED = 0,
28457@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
28458 void enable_sep_cpu(void)
28459 {
28460 int cpu = get_cpu();
28461- struct tss_struct *tss = &per_cpu(init_tss, cpu);
28462+ struct tss_struct *tss = init_tss + cpu;
28463
28464 if (!boot_cpu_has(X86_FEATURE_SEP)) {
28465 put_cpu();
28466@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
28467 gate_vma.vm_start = FIXADDR_USER_START;
28468 gate_vma.vm_end = FIXADDR_USER_END;
28469 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
28470- gate_vma.vm_page_prot = __P101;
28471+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
28472
28473 return 0;
28474 }
28475@@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
28476 if (compat)
28477 addr = VDSO_HIGH_BASE;
28478 else {
28479- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
28480+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
28481 if (IS_ERR_VALUE(addr)) {
28482 ret = addr;
28483 goto up_fail;
28484 }
28485 }
28486
28487- current->mm->context.vdso = (void *)addr;
28488+ current->mm->context.vdso = addr;
28489
28490 if (compat_uses_vma || !compat) {
28491 /*
28492@@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
28493 }
28494
28495 current_thread_info()->sysenter_return =
28496- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
28497+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
28498
28499 up_fail:
28500 if (ret)
28501- current->mm->context.vdso = NULL;
28502+ current->mm->context.vdso = 0;
28503
28504 up_write(&mm->mmap_sem);
28505
28506@@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
28507
28508 const char *arch_vma_name(struct vm_area_struct *vma)
28509 {
28510- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
28511+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
28512 return "[vdso]";
28513+
28514+#ifdef CONFIG_PAX_SEGMEXEC
28515+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
28516+ return "[vdso]";
28517+#endif
28518+
28519 return NULL;
28520 }
28521
28522@@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
28523 * Check to see if the corresponding task was created in compat vdso
28524 * mode.
28525 */
28526- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
28527+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
28528 return &gate_vma;
28529 return NULL;
28530 }
28531diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
28532index 00aaf04..4a26505 100644
28533--- a/arch/x86/vdso/vma.c
28534+++ b/arch/x86/vdso/vma.c
28535@@ -16,8 +16,6 @@
28536 #include <asm/vdso.h>
28537 #include <asm/page.h>
28538
28539-unsigned int __read_mostly vdso_enabled = 1;
28540-
28541 extern char vdso_start[], vdso_end[];
28542 extern unsigned short vdso_sync_cpuid;
28543
28544@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
28545 * unaligned here as a result of stack start randomization.
28546 */
28547 addr = PAGE_ALIGN(addr);
28548- addr = align_addr(addr, NULL, ALIGN_VDSO);
28549
28550 return addr;
28551 }
28552@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
28553 unsigned size)
28554 {
28555 struct mm_struct *mm = current->mm;
28556- unsigned long addr;
28557+ unsigned long addr = 0;
28558 int ret;
28559
28560- if (!vdso_enabled)
28561- return 0;
28562-
28563 down_write(&mm->mmap_sem);
28564+
28565+#ifdef CONFIG_PAX_RANDMMAP
28566+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
28567+#endif
28568+
28569 addr = vdso_addr(mm->start_stack, size);
28570+ addr = align_addr(addr, NULL, ALIGN_VDSO);
28571 addr = get_unmapped_area(NULL, addr, size, 0, 0);
28572 if (IS_ERR_VALUE(addr)) {
28573 ret = addr;
28574 goto up_fail;
28575 }
28576
28577- current->mm->context.vdso = (void *)addr;
28578+ mm->context.vdso = addr;
28579
28580 ret = install_special_mapping(mm, addr, size,
28581 VM_READ|VM_EXEC|
28582 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
28583 pages);
28584- if (ret) {
28585- current->mm->context.vdso = NULL;
28586- goto up_fail;
28587- }
28588+ if (ret)
28589+ mm->context.vdso = 0;
28590
28591 up_fail:
28592 up_write(&mm->mmap_sem);
28593@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
28594 vdsox32_size);
28595 }
28596 #endif
28597-
28598-static __init int vdso_setup(char *s)
28599-{
28600- vdso_enabled = simple_strtoul(s, NULL, 0);
28601- return 0;
28602-}
28603-__setup("vdso=", vdso_setup);
28604diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
28605index 586d838..38cb3ff 100644
28606--- a/arch/x86/xen/enlighten.c
28607+++ b/arch/x86/xen/enlighten.c
28608@@ -99,8 +99,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
28609
28610 struct shared_info xen_dummy_shared_info;
28611
28612-void *xen_initial_gdt;
28613-
28614 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
28615 __read_mostly int xen_have_vector_callback;
28616 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
28617@@ -918,21 +916,21 @@ static u32 xen_safe_apic_wait_icr_idle(void)
28618
28619 static void set_xen_basic_apic_ops(void)
28620 {
28621- apic->read = xen_apic_read;
28622- apic->write = xen_apic_write;
28623- apic->icr_read = xen_apic_icr_read;
28624- apic->icr_write = xen_apic_icr_write;
28625- apic->wait_icr_idle = xen_apic_wait_icr_idle;
28626- apic->safe_wait_icr_idle = xen_safe_apic_wait_icr_idle;
28627- apic->set_apic_id = xen_set_apic_id;
28628- apic->get_apic_id = xen_get_apic_id;
28629+ *(void **)&apic->read = xen_apic_read;
28630+ *(void **)&apic->write = xen_apic_write;
28631+ *(void **)&apic->icr_read = xen_apic_icr_read;
28632+ *(void **)&apic->icr_write = xen_apic_icr_write;
28633+ *(void **)&apic->wait_icr_idle = xen_apic_wait_icr_idle;
28634+ *(void **)&apic->safe_wait_icr_idle = xen_safe_apic_wait_icr_idle;
28635+ *(void **)&apic->set_apic_id = xen_set_apic_id;
28636+ *(void **)&apic->get_apic_id = xen_get_apic_id;
28637
28638 #ifdef CONFIG_SMP
28639- apic->send_IPI_allbutself = xen_send_IPI_allbutself;
28640- apic->send_IPI_mask_allbutself = xen_send_IPI_mask_allbutself;
28641- apic->send_IPI_mask = xen_send_IPI_mask;
28642- apic->send_IPI_all = xen_send_IPI_all;
28643- apic->send_IPI_self = xen_send_IPI_self;
28644+ *(void **)&apic->send_IPI_allbutself = xen_send_IPI_allbutself;
28645+ *(void **)&apic->send_IPI_mask_allbutself = xen_send_IPI_mask_allbutself;
28646+ *(void **)&apic->send_IPI_mask = xen_send_IPI_mask;
28647+ *(void **)&apic->send_IPI_all = xen_send_IPI_all;
28648+ *(void **)&apic->send_IPI_self = xen_send_IPI_self;
28649 #endif
28650 }
28651
28652@@ -1222,30 +1220,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
28653 #endif
28654 };
28655
28656-static void xen_reboot(int reason)
28657+static __noreturn void xen_reboot(int reason)
28658 {
28659 struct sched_shutdown r = { .reason = reason };
28660
28661- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
28662- BUG();
28663+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
28664+ BUG();
28665 }
28666
28667-static void xen_restart(char *msg)
28668+static __noreturn void xen_restart(char *msg)
28669 {
28670 xen_reboot(SHUTDOWN_reboot);
28671 }
28672
28673-static void xen_emergency_restart(void)
28674+static __noreturn void xen_emergency_restart(void)
28675 {
28676 xen_reboot(SHUTDOWN_reboot);
28677 }
28678
28679-static void xen_machine_halt(void)
28680+static __noreturn void xen_machine_halt(void)
28681 {
28682 xen_reboot(SHUTDOWN_poweroff);
28683 }
28684
28685-static void xen_machine_power_off(void)
28686+static __noreturn void xen_machine_power_off(void)
28687 {
28688 if (pm_power_off)
28689 pm_power_off();
28690@@ -1347,7 +1345,17 @@ asmlinkage void __init xen_start_kernel(void)
28691 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
28692
28693 /* Work out if we support NX */
28694- x86_configure_nx();
28695+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
28696+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
28697+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
28698+ unsigned l, h;
28699+
28700+ __supported_pte_mask |= _PAGE_NX;
28701+ rdmsr(MSR_EFER, l, h);
28702+ l |= EFER_NX;
28703+ wrmsr(MSR_EFER, l, h);
28704+ }
28705+#endif
28706
28707 xen_setup_features();
28708
28709@@ -1378,13 +1386,6 @@ asmlinkage void __init xen_start_kernel(void)
28710
28711 machine_ops = xen_machine_ops;
28712
28713- /*
28714- * The only reliable way to retain the initial address of the
28715- * percpu gdt_page is to remember it here, so we can go and
28716- * mark it RW later, when the initial percpu area is freed.
28717- */
28718- xen_initial_gdt = &per_cpu(gdt_page, 0);
28719-
28720 xen_smp_init();
28721
28722 #ifdef CONFIG_ACPI_NUMA
28723diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
28724index dcf5f2d..d804c25 100644
28725--- a/arch/x86/xen/mmu.c
28726+++ b/arch/x86/xen/mmu.c
28727@@ -1881,6 +1881,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
28728 /* L3_k[510] -> level2_kernel_pgt
28729 * L3_i[511] -> level2_fixmap_pgt */
28730 convert_pfn_mfn(level3_kernel_pgt);
28731+ convert_pfn_mfn(level3_vmalloc_start_pgt);
28732+ convert_pfn_mfn(level3_vmalloc_end_pgt);
28733+ convert_pfn_mfn(level3_vmemmap_pgt);
28734
28735 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
28736 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
28737@@ -1910,8 +1913,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
28738 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
28739 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
28740 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
28741+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
28742+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
28743+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
28744 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
28745 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
28746+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
28747 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
28748 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
28749
28750@@ -2097,6 +2104,7 @@ static void __init xen_post_allocator_init(void)
28751 pv_mmu_ops.set_pud = xen_set_pud;
28752 #if PAGETABLE_LEVELS == 4
28753 pv_mmu_ops.set_pgd = xen_set_pgd;
28754+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
28755 #endif
28756
28757 /* This will work as long as patching hasn't happened yet
28758@@ -2178,6 +2186,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
28759 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
28760 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
28761 .set_pgd = xen_set_pgd_hyper,
28762+ .set_pgd_batched = xen_set_pgd_hyper,
28763
28764 .alloc_pud = xen_alloc_pmd_init,
28765 .release_pud = xen_release_pmd_init,
28766diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
28767index 353c50f..5b7cb95 100644
28768--- a/arch/x86/xen/smp.c
28769+++ b/arch/x86/xen/smp.c
28770@@ -229,11 +229,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
28771 {
28772 BUG_ON(smp_processor_id() != 0);
28773 native_smp_prepare_boot_cpu();
28774-
28775- /* We've switched to the "real" per-cpu gdt, so make sure the
28776- old memory can be recycled */
28777- make_lowmem_page_readwrite(xen_initial_gdt);
28778-
28779 xen_filter_cpu_maps();
28780 xen_setup_vcpu_info_placement();
28781 }
28782@@ -300,12 +295,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
28783 gdt = get_cpu_gdt_table(cpu);
28784
28785 ctxt->flags = VGCF_IN_KERNEL;
28786- ctxt->user_regs.ds = __USER_DS;
28787- ctxt->user_regs.es = __USER_DS;
28788+ ctxt->user_regs.ds = __KERNEL_DS;
28789+ ctxt->user_regs.es = __KERNEL_DS;
28790 ctxt->user_regs.ss = __KERNEL_DS;
28791 #ifdef CONFIG_X86_32
28792 ctxt->user_regs.fs = __KERNEL_PERCPU;
28793- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
28794+ savesegment(gs, ctxt->user_regs.gs);
28795 #else
28796 ctxt->gs_base_kernel = per_cpu_offset(cpu);
28797 #endif
28798@@ -355,13 +350,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
28799 int rc;
28800
28801 per_cpu(current_task, cpu) = idle;
28802+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
28803 #ifdef CONFIG_X86_32
28804 irq_ctx_init(cpu);
28805 #else
28806 clear_tsk_thread_flag(idle, TIF_FORK);
28807- per_cpu(kernel_stack, cpu) =
28808- (unsigned long)task_stack_page(idle) -
28809- KERNEL_STACK_OFFSET + THREAD_SIZE;
28810+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
28811 #endif
28812 xen_setup_runstate_info(cpu);
28813 xen_setup_timer(cpu);
28814diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
28815index f9643fc..602e8af 100644
28816--- a/arch/x86/xen/xen-asm_32.S
28817+++ b/arch/x86/xen/xen-asm_32.S
28818@@ -84,14 +84,14 @@ ENTRY(xen_iret)
28819 ESP_OFFSET=4 # bytes pushed onto stack
28820
28821 /*
28822- * Store vcpu_info pointer for easy access. Do it this way to
28823- * avoid having to reload %fs
28824+ * Store vcpu_info pointer for easy access.
28825 */
28826 #ifdef CONFIG_SMP
28827- GET_THREAD_INFO(%eax)
28828- movl TI_cpu(%eax), %eax
28829- movl __per_cpu_offset(,%eax,4), %eax
28830- mov xen_vcpu(%eax), %eax
28831+ push %fs
28832+ mov $(__KERNEL_PERCPU), %eax
28833+ mov %eax, %fs
28834+ mov PER_CPU_VAR(xen_vcpu), %eax
28835+ pop %fs
28836 #else
28837 movl xen_vcpu, %eax
28838 #endif
28839diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
28840index 7faed58..ba4427c 100644
28841--- a/arch/x86/xen/xen-head.S
28842+++ b/arch/x86/xen/xen-head.S
28843@@ -19,6 +19,17 @@ ENTRY(startup_xen)
28844 #ifdef CONFIG_X86_32
28845 mov %esi,xen_start_info
28846 mov $init_thread_union+THREAD_SIZE,%esp
28847+#ifdef CONFIG_SMP
28848+ movl $cpu_gdt_table,%edi
28849+ movl $__per_cpu_load,%eax
28850+ movw %ax,__KERNEL_PERCPU + 2(%edi)
28851+ rorl $16,%eax
28852+ movb %al,__KERNEL_PERCPU + 4(%edi)
28853+ movb %ah,__KERNEL_PERCPU + 7(%edi)
28854+ movl $__per_cpu_end - 1,%eax
28855+ subl $__per_cpu_start,%eax
28856+ movw %ax,__KERNEL_PERCPU + 0(%edi)
28857+#endif
28858 #else
28859 mov %rsi,xen_start_info
28860 mov $init_thread_union+THREAD_SIZE,%rsp
28861diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
28862index a95b417..b6dbd0b 100644
28863--- a/arch/x86/xen/xen-ops.h
28864+++ b/arch/x86/xen/xen-ops.h
28865@@ -10,8 +10,6 @@
28866 extern const char xen_hypervisor_callback[];
28867 extern const char xen_failsafe_callback[];
28868
28869-extern void *xen_initial_gdt;
28870-
28871 struct trap_info;
28872 void xen_copy_trap_info(struct trap_info *traps);
28873
28874diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
28875index 525bd3d..ef888b1 100644
28876--- a/arch/xtensa/variants/dc232b/include/variant/core.h
28877+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
28878@@ -119,9 +119,9 @@
28879 ----------------------------------------------------------------------*/
28880
28881 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
28882-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
28883 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
28884 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
28885+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
28886
28887 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
28888 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
28889diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
28890index 2f33760..835e50a 100644
28891--- a/arch/xtensa/variants/fsf/include/variant/core.h
28892+++ b/arch/xtensa/variants/fsf/include/variant/core.h
28893@@ -11,6 +11,7 @@
28894 #ifndef _XTENSA_CORE_H
28895 #define _XTENSA_CORE_H
28896
28897+#include <linux/const.h>
28898
28899 /****************************************************************************
28900 Parameters Useful for Any Code, USER or PRIVILEGED
28901@@ -112,9 +113,9 @@
28902 ----------------------------------------------------------------------*/
28903
28904 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
28905-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
28906 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
28907 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
28908+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
28909
28910 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
28911 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
28912diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
28913index af00795..2bb8105 100644
28914--- a/arch/xtensa/variants/s6000/include/variant/core.h
28915+++ b/arch/xtensa/variants/s6000/include/variant/core.h
28916@@ -11,6 +11,7 @@
28917 #ifndef _XTENSA_CORE_CONFIGURATION_H
28918 #define _XTENSA_CORE_CONFIGURATION_H
28919
28920+#include <linux/const.h>
28921
28922 /****************************************************************************
28923 Parameters Useful for Any Code, USER or PRIVILEGED
28924@@ -118,9 +119,9 @@
28925 ----------------------------------------------------------------------*/
28926
28927 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
28928-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
28929 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
28930 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
28931+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
28932
28933 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
28934 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
28935diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
28936index 58916af..9cb880b 100644
28937--- a/block/blk-iopoll.c
28938+++ b/block/blk-iopoll.c
28939@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
28940 }
28941 EXPORT_SYMBOL(blk_iopoll_complete);
28942
28943-static void blk_iopoll_softirq(struct softirq_action *h)
28944+static void blk_iopoll_softirq(void)
28945 {
28946 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
28947 int rearm = 0, budget = blk_iopoll_budget;
28948diff --git a/block/blk-map.c b/block/blk-map.c
28949index 623e1cd..ca1e109 100644
28950--- a/block/blk-map.c
28951+++ b/block/blk-map.c
28952@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
28953 if (!len || !kbuf)
28954 return -EINVAL;
28955
28956- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
28957+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
28958 if (do_copy)
28959 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
28960 else
28961diff --git a/block/blk-softirq.c b/block/blk-softirq.c
28962index 467c8de..4bddc6d 100644
28963--- a/block/blk-softirq.c
28964+++ b/block/blk-softirq.c
28965@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
28966 * Softirq action handler - move entries to local list and loop over them
28967 * while passing them to the queue registered handler.
28968 */
28969-static void blk_done_softirq(struct softirq_action *h)
28970+static void blk_done_softirq(void)
28971 {
28972 struct list_head *cpu_list, local_list;
28973
28974diff --git a/block/bsg.c b/block/bsg.c
28975index ff64ae3..593560c 100644
28976--- a/block/bsg.c
28977+++ b/block/bsg.c
28978@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
28979 struct sg_io_v4 *hdr, struct bsg_device *bd,
28980 fmode_t has_write_perm)
28981 {
28982+ unsigned char tmpcmd[sizeof(rq->__cmd)];
28983+ unsigned char *cmdptr;
28984+
28985 if (hdr->request_len > BLK_MAX_CDB) {
28986 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
28987 if (!rq->cmd)
28988 return -ENOMEM;
28989- }
28990+ cmdptr = rq->cmd;
28991+ } else
28992+ cmdptr = tmpcmd;
28993
28994- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
28995+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
28996 hdr->request_len))
28997 return -EFAULT;
28998
28999+ if (cmdptr != rq->cmd)
29000+ memcpy(rq->cmd, cmdptr, hdr->request_len);
29001+
29002 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
29003 if (blk_verify_command(rq->cmd, has_write_perm))
29004 return -EPERM;
29005diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
29006index 7c668c8..db3521c 100644
29007--- a/block/compat_ioctl.c
29008+++ b/block/compat_ioctl.c
29009@@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
29010 err |= __get_user(f->spec1, &uf->spec1);
29011 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
29012 err |= __get_user(name, &uf->name);
29013- f->name = compat_ptr(name);
29014+ f->name = (void __force_kernel *)compat_ptr(name);
29015 if (err) {
29016 err = -EFAULT;
29017 goto out;
29018diff --git a/block/partitions/efi.c b/block/partitions/efi.c
29019index 6296b40..417c00f 100644
29020--- a/block/partitions/efi.c
29021+++ b/block/partitions/efi.c
29022@@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
29023 if (!gpt)
29024 return NULL;
29025
29026+ if (!le32_to_cpu(gpt->num_partition_entries))
29027+ return NULL;
29028+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
29029+ if (!pte)
29030+ return NULL;
29031+
29032 count = le32_to_cpu(gpt->num_partition_entries) *
29033 le32_to_cpu(gpt->sizeof_partition_entry);
29034- if (!count)
29035- return NULL;
29036- pte = kzalloc(count, GFP_KERNEL);
29037- if (!pte)
29038- return NULL;
29039-
29040 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
29041 (u8 *) pte,
29042 count) < count) {
29043diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
29044index 9a87daa..fb17486 100644
29045--- a/block/scsi_ioctl.c
29046+++ b/block/scsi_ioctl.c
29047@@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
29048 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
29049 struct sg_io_hdr *hdr, fmode_t mode)
29050 {
29051- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
29052+ unsigned char tmpcmd[sizeof(rq->__cmd)];
29053+ unsigned char *cmdptr;
29054+
29055+ if (rq->cmd != rq->__cmd)
29056+ cmdptr = rq->cmd;
29057+ else
29058+ cmdptr = tmpcmd;
29059+
29060+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
29061 return -EFAULT;
29062+
29063+ if (cmdptr != rq->cmd)
29064+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
29065+
29066 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
29067 return -EPERM;
29068
29069@@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
29070 int err;
29071 unsigned int in_len, out_len, bytes, opcode, cmdlen;
29072 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
29073+ unsigned char tmpcmd[sizeof(rq->__cmd)];
29074+ unsigned char *cmdptr;
29075
29076 if (!sic)
29077 return -EINVAL;
29078@@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
29079 */
29080 err = -EFAULT;
29081 rq->cmd_len = cmdlen;
29082- if (copy_from_user(rq->cmd, sic->data, cmdlen))
29083+
29084+ if (rq->cmd != rq->__cmd)
29085+ cmdptr = rq->cmd;
29086+ else
29087+ cmdptr = tmpcmd;
29088+
29089+ if (copy_from_user(cmdptr, sic->data, cmdlen))
29090 goto error;
29091
29092+ if (rq->cmd != cmdptr)
29093+ memcpy(rq->cmd, cmdptr, cmdlen);
29094+
29095 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
29096 goto error;
29097
29098diff --git a/crypto/cryptd.c b/crypto/cryptd.c
29099index 7bdd61b..afec999 100644
29100--- a/crypto/cryptd.c
29101+++ b/crypto/cryptd.c
29102@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
29103
29104 struct cryptd_blkcipher_request_ctx {
29105 crypto_completion_t complete;
29106-};
29107+} __no_const;
29108
29109 struct cryptd_hash_ctx {
29110 struct crypto_shash *child;
29111@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
29112
29113 struct cryptd_aead_request_ctx {
29114 crypto_completion_t complete;
29115-};
29116+} __no_const;
29117
29118 static void cryptd_queue_worker(struct work_struct *work);
29119
29120diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
29121index b2c99dc..2a10085 100644
29122--- a/crypto/pcrypt.c
29123+++ b/crypto/pcrypt.c
29124@@ -52,7 +52,7 @@ struct padata_pcrypt {
29125 struct pcrypt_cpumask {
29126 cpumask_var_t mask;
29127 } *cb_cpumask;
29128- struct notifier_block nblock;
29129+ notifier_block_no_const nblock;
29130 };
29131
29132 static struct padata_pcrypt pencrypt;
29133diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
29134index e6defd8..c26a225 100644
29135--- a/drivers/acpi/apei/cper.c
29136+++ b/drivers/acpi/apei/cper.c
29137@@ -38,12 +38,12 @@
29138 */
29139 u64 cper_next_record_id(void)
29140 {
29141- static atomic64_t seq;
29142+ static atomic64_unchecked_t seq;
29143
29144- if (!atomic64_read(&seq))
29145- atomic64_set(&seq, ((u64)get_seconds()) << 32);
29146+ if (!atomic64_read_unchecked(&seq))
29147+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
29148
29149- return atomic64_inc_return(&seq);
29150+ return atomic64_inc_return_unchecked(&seq);
29151 }
29152 EXPORT_SYMBOL_GPL(cper_next_record_id);
29153
29154diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
29155index 7efaeaa..53372fb 100644
29156--- a/drivers/acpi/battery.c
29157+++ b/drivers/acpi/battery.c
29158@@ -115,7 +115,7 @@ struct acpi_battery {
29159 struct mutex sysfs_lock;
29160 struct power_supply bat;
29161 struct acpi_device *device;
29162- struct notifier_block pm_nb;
29163+ notifier_block_no_const pm_nb;
29164 unsigned long update_time;
29165 int rate_now;
29166 int capacity_now;
29167diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
29168index 7586544..636a2f0 100644
29169--- a/drivers/acpi/ec_sys.c
29170+++ b/drivers/acpi/ec_sys.c
29171@@ -12,6 +12,7 @@
29172 #include <linux/acpi.h>
29173 #include <linux/debugfs.h>
29174 #include <linux/module.h>
29175+#include <linux/uaccess.h>
29176 #include "internal.h"
29177
29178 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
29179@@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
29180 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
29181 */
29182 unsigned int size = EC_SPACE_SIZE;
29183- u8 *data = (u8 *) buf;
29184+ u8 data;
29185 loff_t init_off = *off;
29186 int err = 0;
29187
29188@@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
29189 size = count;
29190
29191 while (size) {
29192- err = ec_read(*off, &data[*off - init_off]);
29193+ err = ec_read(*off, &data);
29194 if (err)
29195 return err;
29196+ if (put_user(data, &buf[*off - init_off]))
29197+ return -EFAULT;
29198 *off += 1;
29199 size--;
29200 }
29201@@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
29202
29203 unsigned int size = count;
29204 loff_t init_off = *off;
29205- u8 *data = (u8 *) buf;
29206 int err = 0;
29207
29208 if (*off >= EC_SPACE_SIZE)
29209@@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
29210 }
29211
29212 while (size) {
29213- u8 byte_write = data[*off - init_off];
29214+ u8 byte_write;
29215+ if (get_user(byte_write, &buf[*off - init_off]))
29216+ return -EFAULT;
29217 err = ec_write(*off, byte_write);
29218 if (err)
29219 return err;
29220diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
29221index 27adb09..1ed412d 100644
29222--- a/drivers/acpi/proc.c
29223+++ b/drivers/acpi/proc.c
29224@@ -360,19 +360,13 @@ acpi_system_write_wakeup_device(struct file *file,
29225 size_t count, loff_t * ppos)
29226 {
29227 struct list_head *node, *next;
29228- char strbuf[5];
29229- char str[5] = "";
29230- unsigned int len = count;
29231+ char strbuf[5] = {0};
29232
29233- if (len > 4)
29234- len = 4;
29235- if (len < 0)
29236+ if (count > 4)
29237+ count = 4;
29238+ if (copy_from_user(strbuf, buffer, count))
29239 return -EFAULT;
29240-
29241- if (copy_from_user(strbuf, buffer, len))
29242- return -EFAULT;
29243- strbuf[len] = '\0';
29244- sscanf(strbuf, "%s", str);
29245+ strbuf[count] = '\0';
29246
29247 mutex_lock(&acpi_device_lock);
29248 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
29249@@ -381,7 +375,7 @@ acpi_system_write_wakeup_device(struct file *file,
29250 if (!dev->wakeup.flags.valid)
29251 continue;
29252
29253- if (!strncmp(dev->pnp.bus_id, str, 4)) {
29254+ if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
29255 if (device_can_wakeup(&dev->dev)) {
29256 bool enable = !device_may_wakeup(&dev->dev);
29257 device_set_wakeup_enable(&dev->dev, enable);
29258diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
29259index bd4e5dc..0497b66 100644
29260--- a/drivers/acpi/processor_driver.c
29261+++ b/drivers/acpi/processor_driver.c
29262@@ -552,7 +552,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
29263 return 0;
29264 #endif
29265
29266- BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
29267+ BUG_ON(pr->id >= nr_cpu_ids);
29268
29269 /*
29270 * Buggy BIOS check
29271diff --git a/drivers/acpi/video.c b/drivers/acpi/video.c
29272index ac9a69c..6b2a391 100644
29273--- a/drivers/acpi/video.c
29274+++ b/drivers/acpi/video.c
29275@@ -157,7 +157,7 @@ struct acpi_video_bus {
29276 struct mutex device_list_lock; /* protects video_device_list */
29277 struct input_dev *input;
29278 char phys[32]; /* for input device */
29279- struct notifier_block pm_nb;
29280+ notifier_block_no_const pm_nb;
29281 };
29282
29283 struct acpi_video_device_flags {
29284diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
29285index f46fbd3..b8341f3 100644
29286--- a/drivers/ata/libata-core.c
29287+++ b/drivers/ata/libata-core.c
29288@@ -4774,7 +4774,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
29289 struct ata_port *ap;
29290 unsigned int tag;
29291
29292- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
29293+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
29294 ap = qc->ap;
29295
29296 qc->flags = 0;
29297@@ -4790,7 +4790,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
29298 struct ata_port *ap;
29299 struct ata_link *link;
29300
29301- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
29302+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
29303 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
29304 ap = qc->ap;
29305 link = qc->dev->link;
29306@@ -5886,6 +5886,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
29307 return;
29308
29309 spin_lock(&lock);
29310+ pax_open_kernel();
29311
29312 for (cur = ops->inherits; cur; cur = cur->inherits) {
29313 void **inherit = (void **)cur;
29314@@ -5899,8 +5900,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
29315 if (IS_ERR(*pp))
29316 *pp = NULL;
29317
29318- ops->inherits = NULL;
29319+ *(struct ata_port_operations **)&ops->inherits = NULL;
29320
29321+ pax_close_kernel();
29322 spin_unlock(&lock);
29323 }
29324
29325diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
29326index 371fd2c..0836c78 100644
29327--- a/drivers/ata/pata_arasan_cf.c
29328+++ b/drivers/ata/pata_arasan_cf.c
29329@@ -861,7 +861,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
29330 /* Handle platform specific quirks */
29331 if (pdata->quirk) {
29332 if (pdata->quirk & CF_BROKEN_PIO) {
29333- ap->ops->set_piomode = NULL;
29334+ pax_open_kernel();
29335+ *(void **)&ap->ops->set_piomode = NULL;
29336+ pax_close_kernel();
29337 ap->pio_mask = 0;
29338 }
29339 if (pdata->quirk & CF_BROKEN_MWDMA)
29340diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
29341index f9b983a..887b9d8 100644
29342--- a/drivers/atm/adummy.c
29343+++ b/drivers/atm/adummy.c
29344@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
29345 vcc->pop(vcc, skb);
29346 else
29347 dev_kfree_skb_any(skb);
29348- atomic_inc(&vcc->stats->tx);
29349+ atomic_inc_unchecked(&vcc->stats->tx);
29350
29351 return 0;
29352 }
29353diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
29354index ff7bb8a..568fc0b 100644
29355--- a/drivers/atm/ambassador.c
29356+++ b/drivers/atm/ambassador.c
29357@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
29358 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
29359
29360 // VC layer stats
29361- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
29362+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
29363
29364 // free the descriptor
29365 kfree (tx_descr);
29366@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
29367 dump_skb ("<<<", vc, skb);
29368
29369 // VC layer stats
29370- atomic_inc(&atm_vcc->stats->rx);
29371+ atomic_inc_unchecked(&atm_vcc->stats->rx);
29372 __net_timestamp(skb);
29373 // end of our responsibility
29374 atm_vcc->push (atm_vcc, skb);
29375@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
29376 } else {
29377 PRINTK (KERN_INFO, "dropped over-size frame");
29378 // should we count this?
29379- atomic_inc(&atm_vcc->stats->rx_drop);
29380+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
29381 }
29382
29383 } else {
29384@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
29385 }
29386
29387 if (check_area (skb->data, skb->len)) {
29388- atomic_inc(&atm_vcc->stats->tx_err);
29389+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
29390 return -ENOMEM; // ?
29391 }
29392
29393diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
29394index b22d71c..d6e1049 100644
29395--- a/drivers/atm/atmtcp.c
29396+++ b/drivers/atm/atmtcp.c
29397@@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
29398 if (vcc->pop) vcc->pop(vcc,skb);
29399 else dev_kfree_skb(skb);
29400 if (dev_data) return 0;
29401- atomic_inc(&vcc->stats->tx_err);
29402+ atomic_inc_unchecked(&vcc->stats->tx_err);
29403 return -ENOLINK;
29404 }
29405 size = skb->len+sizeof(struct atmtcp_hdr);
29406@@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
29407 if (!new_skb) {
29408 if (vcc->pop) vcc->pop(vcc,skb);
29409 else dev_kfree_skb(skb);
29410- atomic_inc(&vcc->stats->tx_err);
29411+ atomic_inc_unchecked(&vcc->stats->tx_err);
29412 return -ENOBUFS;
29413 }
29414 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
29415@@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
29416 if (vcc->pop) vcc->pop(vcc,skb);
29417 else dev_kfree_skb(skb);
29418 out_vcc->push(out_vcc,new_skb);
29419- atomic_inc(&vcc->stats->tx);
29420- atomic_inc(&out_vcc->stats->rx);
29421+ atomic_inc_unchecked(&vcc->stats->tx);
29422+ atomic_inc_unchecked(&out_vcc->stats->rx);
29423 return 0;
29424 }
29425
29426@@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
29427 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
29428 read_unlock(&vcc_sklist_lock);
29429 if (!out_vcc) {
29430- atomic_inc(&vcc->stats->tx_err);
29431+ atomic_inc_unchecked(&vcc->stats->tx_err);
29432 goto done;
29433 }
29434 skb_pull(skb,sizeof(struct atmtcp_hdr));
29435@@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
29436 __net_timestamp(new_skb);
29437 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
29438 out_vcc->push(out_vcc,new_skb);
29439- atomic_inc(&vcc->stats->tx);
29440- atomic_inc(&out_vcc->stats->rx);
29441+ atomic_inc_unchecked(&vcc->stats->tx);
29442+ atomic_inc_unchecked(&out_vcc->stats->rx);
29443 done:
29444 if (vcc->pop) vcc->pop(vcc,skb);
29445 else dev_kfree_skb(skb);
29446diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
29447index 81e44f7..498ea36 100644
29448--- a/drivers/atm/eni.c
29449+++ b/drivers/atm/eni.c
29450@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
29451 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
29452 vcc->dev->number);
29453 length = 0;
29454- atomic_inc(&vcc->stats->rx_err);
29455+ atomic_inc_unchecked(&vcc->stats->rx_err);
29456 }
29457 else {
29458 length = ATM_CELL_SIZE-1; /* no HEC */
29459@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
29460 size);
29461 }
29462 eff = length = 0;
29463- atomic_inc(&vcc->stats->rx_err);
29464+ atomic_inc_unchecked(&vcc->stats->rx_err);
29465 }
29466 else {
29467 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
29468@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
29469 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
29470 vcc->dev->number,vcc->vci,length,size << 2,descr);
29471 length = eff = 0;
29472- atomic_inc(&vcc->stats->rx_err);
29473+ atomic_inc_unchecked(&vcc->stats->rx_err);
29474 }
29475 }
29476 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
29477@@ -767,7 +767,7 @@ rx_dequeued++;
29478 vcc->push(vcc,skb);
29479 pushed++;
29480 }
29481- atomic_inc(&vcc->stats->rx);
29482+ atomic_inc_unchecked(&vcc->stats->rx);
29483 }
29484 wake_up(&eni_dev->rx_wait);
29485 }
29486@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
29487 PCI_DMA_TODEVICE);
29488 if (vcc->pop) vcc->pop(vcc,skb);
29489 else dev_kfree_skb_irq(skb);
29490- atomic_inc(&vcc->stats->tx);
29491+ atomic_inc_unchecked(&vcc->stats->tx);
29492 wake_up(&eni_dev->tx_wait);
29493 dma_complete++;
29494 }
29495diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
29496index 86fed1b..6dc4721 100644
29497--- a/drivers/atm/firestream.c
29498+++ b/drivers/atm/firestream.c
29499@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
29500 }
29501 }
29502
29503- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
29504+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
29505
29506 fs_dprintk (FS_DEBUG_TXMEM, "i");
29507 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
29508@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
29509 #endif
29510 skb_put (skb, qe->p1 & 0xffff);
29511 ATM_SKB(skb)->vcc = atm_vcc;
29512- atomic_inc(&atm_vcc->stats->rx);
29513+ atomic_inc_unchecked(&atm_vcc->stats->rx);
29514 __net_timestamp(skb);
29515 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
29516 atm_vcc->push (atm_vcc, skb);
29517@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
29518 kfree (pe);
29519 }
29520 if (atm_vcc)
29521- atomic_inc(&atm_vcc->stats->rx_drop);
29522+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
29523 break;
29524 case 0x1f: /* Reassembly abort: no buffers. */
29525 /* Silently increment error counter. */
29526 if (atm_vcc)
29527- atomic_inc(&atm_vcc->stats->rx_drop);
29528+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
29529 break;
29530 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
29531 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
29532diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
29533index 361f5ae..7fc552d 100644
29534--- a/drivers/atm/fore200e.c
29535+++ b/drivers/atm/fore200e.c
29536@@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
29537 #endif
29538 /* check error condition */
29539 if (*entry->status & STATUS_ERROR)
29540- atomic_inc(&vcc->stats->tx_err);
29541+ atomic_inc_unchecked(&vcc->stats->tx_err);
29542 else
29543- atomic_inc(&vcc->stats->tx);
29544+ atomic_inc_unchecked(&vcc->stats->tx);
29545 }
29546 }
29547
29548@@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
29549 if (skb == NULL) {
29550 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
29551
29552- atomic_inc(&vcc->stats->rx_drop);
29553+ atomic_inc_unchecked(&vcc->stats->rx_drop);
29554 return -ENOMEM;
29555 }
29556
29557@@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
29558
29559 dev_kfree_skb_any(skb);
29560
29561- atomic_inc(&vcc->stats->rx_drop);
29562+ atomic_inc_unchecked(&vcc->stats->rx_drop);
29563 return -ENOMEM;
29564 }
29565
29566 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
29567
29568 vcc->push(vcc, skb);
29569- atomic_inc(&vcc->stats->rx);
29570+ atomic_inc_unchecked(&vcc->stats->rx);
29571
29572 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
29573
29574@@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
29575 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
29576 fore200e->atm_dev->number,
29577 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
29578- atomic_inc(&vcc->stats->rx_err);
29579+ atomic_inc_unchecked(&vcc->stats->rx_err);
29580 }
29581 }
29582
29583@@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
29584 goto retry_here;
29585 }
29586
29587- atomic_inc(&vcc->stats->tx_err);
29588+ atomic_inc_unchecked(&vcc->stats->tx_err);
29589
29590 fore200e->tx_sat++;
29591 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
29592diff --git a/drivers/atm/he.c b/drivers/atm/he.c
29593index b182c2f..1c6fa8a 100644
29594--- a/drivers/atm/he.c
29595+++ b/drivers/atm/he.c
29596@@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
29597
29598 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
29599 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
29600- atomic_inc(&vcc->stats->rx_drop);
29601+ atomic_inc_unchecked(&vcc->stats->rx_drop);
29602 goto return_host_buffers;
29603 }
29604
29605@@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
29606 RBRQ_LEN_ERR(he_dev->rbrq_head)
29607 ? "LEN_ERR" : "",
29608 vcc->vpi, vcc->vci);
29609- atomic_inc(&vcc->stats->rx_err);
29610+ atomic_inc_unchecked(&vcc->stats->rx_err);
29611 goto return_host_buffers;
29612 }
29613
29614@@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
29615 vcc->push(vcc, skb);
29616 spin_lock(&he_dev->global_lock);
29617
29618- atomic_inc(&vcc->stats->rx);
29619+ atomic_inc_unchecked(&vcc->stats->rx);
29620
29621 return_host_buffers:
29622 ++pdus_assembled;
29623@@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
29624 tpd->vcc->pop(tpd->vcc, tpd->skb);
29625 else
29626 dev_kfree_skb_any(tpd->skb);
29627- atomic_inc(&tpd->vcc->stats->tx_err);
29628+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
29629 }
29630 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
29631 return;
29632@@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
29633 vcc->pop(vcc, skb);
29634 else
29635 dev_kfree_skb_any(skb);
29636- atomic_inc(&vcc->stats->tx_err);
29637+ atomic_inc_unchecked(&vcc->stats->tx_err);
29638 return -EINVAL;
29639 }
29640
29641@@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
29642 vcc->pop(vcc, skb);
29643 else
29644 dev_kfree_skb_any(skb);
29645- atomic_inc(&vcc->stats->tx_err);
29646+ atomic_inc_unchecked(&vcc->stats->tx_err);
29647 return -EINVAL;
29648 }
29649 #endif
29650@@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
29651 vcc->pop(vcc, skb);
29652 else
29653 dev_kfree_skb_any(skb);
29654- atomic_inc(&vcc->stats->tx_err);
29655+ atomic_inc_unchecked(&vcc->stats->tx_err);
29656 spin_unlock_irqrestore(&he_dev->global_lock, flags);
29657 return -ENOMEM;
29658 }
29659@@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
29660 vcc->pop(vcc, skb);
29661 else
29662 dev_kfree_skb_any(skb);
29663- atomic_inc(&vcc->stats->tx_err);
29664+ atomic_inc_unchecked(&vcc->stats->tx_err);
29665 spin_unlock_irqrestore(&he_dev->global_lock, flags);
29666 return -ENOMEM;
29667 }
29668@@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
29669 __enqueue_tpd(he_dev, tpd, cid);
29670 spin_unlock_irqrestore(&he_dev->global_lock, flags);
29671
29672- atomic_inc(&vcc->stats->tx);
29673+ atomic_inc_unchecked(&vcc->stats->tx);
29674
29675 return 0;
29676 }
29677diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
29678index 7d01c2a..4e3ac01 100644
29679--- a/drivers/atm/horizon.c
29680+++ b/drivers/atm/horizon.c
29681@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
29682 {
29683 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
29684 // VC layer stats
29685- atomic_inc(&vcc->stats->rx);
29686+ atomic_inc_unchecked(&vcc->stats->rx);
29687 __net_timestamp(skb);
29688 // end of our responsibility
29689 vcc->push (vcc, skb);
29690@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
29691 dev->tx_iovec = NULL;
29692
29693 // VC layer stats
29694- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
29695+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
29696
29697 // free the skb
29698 hrz_kfree_skb (skb);
29699diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
29700index 8974bd2..b856f85 100644
29701--- a/drivers/atm/idt77252.c
29702+++ b/drivers/atm/idt77252.c
29703@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
29704 else
29705 dev_kfree_skb(skb);
29706
29707- atomic_inc(&vcc->stats->tx);
29708+ atomic_inc_unchecked(&vcc->stats->tx);
29709 }
29710
29711 atomic_dec(&scq->used);
29712@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
29713 if ((sb = dev_alloc_skb(64)) == NULL) {
29714 printk("%s: Can't allocate buffers for aal0.\n",
29715 card->name);
29716- atomic_add(i, &vcc->stats->rx_drop);
29717+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
29718 break;
29719 }
29720 if (!atm_charge(vcc, sb->truesize)) {
29721 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
29722 card->name);
29723- atomic_add(i - 1, &vcc->stats->rx_drop);
29724+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
29725 dev_kfree_skb(sb);
29726 break;
29727 }
29728@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
29729 ATM_SKB(sb)->vcc = vcc;
29730 __net_timestamp(sb);
29731 vcc->push(vcc, sb);
29732- atomic_inc(&vcc->stats->rx);
29733+ atomic_inc_unchecked(&vcc->stats->rx);
29734
29735 cell += ATM_CELL_PAYLOAD;
29736 }
29737@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
29738 "(CDC: %08x)\n",
29739 card->name, len, rpp->len, readl(SAR_REG_CDC));
29740 recycle_rx_pool_skb(card, rpp);
29741- atomic_inc(&vcc->stats->rx_err);
29742+ atomic_inc_unchecked(&vcc->stats->rx_err);
29743 return;
29744 }
29745 if (stat & SAR_RSQE_CRC) {
29746 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
29747 recycle_rx_pool_skb(card, rpp);
29748- atomic_inc(&vcc->stats->rx_err);
29749+ atomic_inc_unchecked(&vcc->stats->rx_err);
29750 return;
29751 }
29752 if (skb_queue_len(&rpp->queue) > 1) {
29753@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
29754 RXPRINTK("%s: Can't alloc RX skb.\n",
29755 card->name);
29756 recycle_rx_pool_skb(card, rpp);
29757- atomic_inc(&vcc->stats->rx_err);
29758+ atomic_inc_unchecked(&vcc->stats->rx_err);
29759 return;
29760 }
29761 if (!atm_charge(vcc, skb->truesize)) {
29762@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
29763 __net_timestamp(skb);
29764
29765 vcc->push(vcc, skb);
29766- atomic_inc(&vcc->stats->rx);
29767+ atomic_inc_unchecked(&vcc->stats->rx);
29768
29769 return;
29770 }
29771@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
29772 __net_timestamp(skb);
29773
29774 vcc->push(vcc, skb);
29775- atomic_inc(&vcc->stats->rx);
29776+ atomic_inc_unchecked(&vcc->stats->rx);
29777
29778 if (skb->truesize > SAR_FB_SIZE_3)
29779 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
29780@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
29781 if (vcc->qos.aal != ATM_AAL0) {
29782 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
29783 card->name, vpi, vci);
29784- atomic_inc(&vcc->stats->rx_drop);
29785+ atomic_inc_unchecked(&vcc->stats->rx_drop);
29786 goto drop;
29787 }
29788
29789 if ((sb = dev_alloc_skb(64)) == NULL) {
29790 printk("%s: Can't allocate buffers for AAL0.\n",
29791 card->name);
29792- atomic_inc(&vcc->stats->rx_err);
29793+ atomic_inc_unchecked(&vcc->stats->rx_err);
29794 goto drop;
29795 }
29796
29797@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
29798 ATM_SKB(sb)->vcc = vcc;
29799 __net_timestamp(sb);
29800 vcc->push(vcc, sb);
29801- atomic_inc(&vcc->stats->rx);
29802+ atomic_inc_unchecked(&vcc->stats->rx);
29803
29804 drop:
29805 skb_pull(queue, 64);
29806@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
29807
29808 if (vc == NULL) {
29809 printk("%s: NULL connection in send().\n", card->name);
29810- atomic_inc(&vcc->stats->tx_err);
29811+ atomic_inc_unchecked(&vcc->stats->tx_err);
29812 dev_kfree_skb(skb);
29813 return -EINVAL;
29814 }
29815 if (!test_bit(VCF_TX, &vc->flags)) {
29816 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
29817- atomic_inc(&vcc->stats->tx_err);
29818+ atomic_inc_unchecked(&vcc->stats->tx_err);
29819 dev_kfree_skb(skb);
29820 return -EINVAL;
29821 }
29822@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
29823 break;
29824 default:
29825 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
29826- atomic_inc(&vcc->stats->tx_err);
29827+ atomic_inc_unchecked(&vcc->stats->tx_err);
29828 dev_kfree_skb(skb);
29829 return -EINVAL;
29830 }
29831
29832 if (skb_shinfo(skb)->nr_frags != 0) {
29833 printk("%s: No scatter-gather yet.\n", card->name);
29834- atomic_inc(&vcc->stats->tx_err);
29835+ atomic_inc_unchecked(&vcc->stats->tx_err);
29836 dev_kfree_skb(skb);
29837 return -EINVAL;
29838 }
29839@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
29840
29841 err = queue_skb(card, vc, skb, oam);
29842 if (err) {
29843- atomic_inc(&vcc->stats->tx_err);
29844+ atomic_inc_unchecked(&vcc->stats->tx_err);
29845 dev_kfree_skb(skb);
29846 return err;
29847 }
29848@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
29849 skb = dev_alloc_skb(64);
29850 if (!skb) {
29851 printk("%s: Out of memory in send_oam().\n", card->name);
29852- atomic_inc(&vcc->stats->tx_err);
29853+ atomic_inc_unchecked(&vcc->stats->tx_err);
29854 return -ENOMEM;
29855 }
29856 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
29857diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
29858index 96cce6d..62c3ec5 100644
29859--- a/drivers/atm/iphase.c
29860+++ b/drivers/atm/iphase.c
29861@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
29862 status = (u_short) (buf_desc_ptr->desc_mode);
29863 if (status & (RX_CER | RX_PTE | RX_OFL))
29864 {
29865- atomic_inc(&vcc->stats->rx_err);
29866+ atomic_inc_unchecked(&vcc->stats->rx_err);
29867 IF_ERR(printk("IA: bad packet, dropping it");)
29868 if (status & RX_CER) {
29869 IF_ERR(printk(" cause: packet CRC error\n");)
29870@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
29871 len = dma_addr - buf_addr;
29872 if (len > iadev->rx_buf_sz) {
29873 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
29874- atomic_inc(&vcc->stats->rx_err);
29875+ atomic_inc_unchecked(&vcc->stats->rx_err);
29876 goto out_free_desc;
29877 }
29878
29879@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
29880 ia_vcc = INPH_IA_VCC(vcc);
29881 if (ia_vcc == NULL)
29882 {
29883- atomic_inc(&vcc->stats->rx_err);
29884+ atomic_inc_unchecked(&vcc->stats->rx_err);
29885 atm_return(vcc, skb->truesize);
29886 dev_kfree_skb_any(skb);
29887 goto INCR_DLE;
29888@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
29889 if ((length > iadev->rx_buf_sz) || (length >
29890 (skb->len - sizeof(struct cpcs_trailer))))
29891 {
29892- atomic_inc(&vcc->stats->rx_err);
29893+ atomic_inc_unchecked(&vcc->stats->rx_err);
29894 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
29895 length, skb->len);)
29896 atm_return(vcc, skb->truesize);
29897@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
29898
29899 IF_RX(printk("rx_dle_intr: skb push");)
29900 vcc->push(vcc,skb);
29901- atomic_inc(&vcc->stats->rx);
29902+ atomic_inc_unchecked(&vcc->stats->rx);
29903 iadev->rx_pkt_cnt++;
29904 }
29905 INCR_DLE:
29906@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
29907 {
29908 struct k_sonet_stats *stats;
29909 stats = &PRIV(_ia_dev[board])->sonet_stats;
29910- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
29911- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
29912- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
29913- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
29914- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
29915- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
29916- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
29917- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
29918- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
29919+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
29920+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
29921+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
29922+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
29923+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
29924+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
29925+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
29926+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
29927+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
29928 }
29929 ia_cmds.status = 0;
29930 break;
29931@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
29932 if ((desc == 0) || (desc > iadev->num_tx_desc))
29933 {
29934 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
29935- atomic_inc(&vcc->stats->tx);
29936+ atomic_inc_unchecked(&vcc->stats->tx);
29937 if (vcc->pop)
29938 vcc->pop(vcc, skb);
29939 else
29940@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
29941 ATM_DESC(skb) = vcc->vci;
29942 skb_queue_tail(&iadev->tx_dma_q, skb);
29943
29944- atomic_inc(&vcc->stats->tx);
29945+ atomic_inc_unchecked(&vcc->stats->tx);
29946 iadev->tx_pkt_cnt++;
29947 /* Increment transaction counter */
29948 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
29949
29950 #if 0
29951 /* add flow control logic */
29952- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
29953+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
29954 if (iavcc->vc_desc_cnt > 10) {
29955 vcc->tx_quota = vcc->tx_quota * 3 / 4;
29956 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
29957diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
29958index 68c7588..7036683 100644
29959--- a/drivers/atm/lanai.c
29960+++ b/drivers/atm/lanai.c
29961@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
29962 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
29963 lanai_endtx(lanai, lvcc);
29964 lanai_free_skb(lvcc->tx.atmvcc, skb);
29965- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
29966+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
29967 }
29968
29969 /* Try to fill the buffer - don't call unless there is backlog */
29970@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
29971 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
29972 __net_timestamp(skb);
29973 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
29974- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
29975+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
29976 out:
29977 lvcc->rx.buf.ptr = end;
29978 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
29979@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
29980 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
29981 "vcc %d\n", lanai->number, (unsigned int) s, vci);
29982 lanai->stats.service_rxnotaal5++;
29983- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
29984+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
29985 return 0;
29986 }
29987 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
29988@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
29989 int bytes;
29990 read_unlock(&vcc_sklist_lock);
29991 DPRINTK("got trashed rx pdu on vci %d\n", vci);
29992- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
29993+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
29994 lvcc->stats.x.aal5.service_trash++;
29995 bytes = (SERVICE_GET_END(s) * 16) -
29996 (((unsigned long) lvcc->rx.buf.ptr) -
29997@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
29998 }
29999 if (s & SERVICE_STREAM) {
30000 read_unlock(&vcc_sklist_lock);
30001- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
30002+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
30003 lvcc->stats.x.aal5.service_stream++;
30004 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
30005 "PDU on VCI %d!\n", lanai->number, vci);
30006@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
30007 return 0;
30008 }
30009 DPRINTK("got rx crc error on vci %d\n", vci);
30010- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
30011+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
30012 lvcc->stats.x.aal5.service_rxcrc++;
30013 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
30014 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
30015diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
30016index 1c70c45..300718d 100644
30017--- a/drivers/atm/nicstar.c
30018+++ b/drivers/atm/nicstar.c
30019@@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
30020 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
30021 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
30022 card->index);
30023- atomic_inc(&vcc->stats->tx_err);
30024+ atomic_inc_unchecked(&vcc->stats->tx_err);
30025 dev_kfree_skb_any(skb);
30026 return -EINVAL;
30027 }
30028@@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
30029 if (!vc->tx) {
30030 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
30031 card->index);
30032- atomic_inc(&vcc->stats->tx_err);
30033+ atomic_inc_unchecked(&vcc->stats->tx_err);
30034 dev_kfree_skb_any(skb);
30035 return -EINVAL;
30036 }
30037@@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
30038 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
30039 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
30040 card->index);
30041- atomic_inc(&vcc->stats->tx_err);
30042+ atomic_inc_unchecked(&vcc->stats->tx_err);
30043 dev_kfree_skb_any(skb);
30044 return -EINVAL;
30045 }
30046
30047 if (skb_shinfo(skb)->nr_frags != 0) {
30048 printk("nicstar%d: No scatter-gather yet.\n", card->index);
30049- atomic_inc(&vcc->stats->tx_err);
30050+ atomic_inc_unchecked(&vcc->stats->tx_err);
30051 dev_kfree_skb_any(skb);
30052 return -EINVAL;
30053 }
30054@@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
30055 }
30056
30057 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
30058- atomic_inc(&vcc->stats->tx_err);
30059+ atomic_inc_unchecked(&vcc->stats->tx_err);
30060 dev_kfree_skb_any(skb);
30061 return -EIO;
30062 }
30063- atomic_inc(&vcc->stats->tx);
30064+ atomic_inc_unchecked(&vcc->stats->tx);
30065
30066 return 0;
30067 }
30068@@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30069 printk
30070 ("nicstar%d: Can't allocate buffers for aal0.\n",
30071 card->index);
30072- atomic_add(i, &vcc->stats->rx_drop);
30073+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
30074 break;
30075 }
30076 if (!atm_charge(vcc, sb->truesize)) {
30077 RXPRINTK
30078 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
30079 card->index);
30080- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
30081+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
30082 dev_kfree_skb_any(sb);
30083 break;
30084 }
30085@@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30086 ATM_SKB(sb)->vcc = vcc;
30087 __net_timestamp(sb);
30088 vcc->push(vcc, sb);
30089- atomic_inc(&vcc->stats->rx);
30090+ atomic_inc_unchecked(&vcc->stats->rx);
30091 cell += ATM_CELL_PAYLOAD;
30092 }
30093
30094@@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30095 if (iovb == NULL) {
30096 printk("nicstar%d: Out of iovec buffers.\n",
30097 card->index);
30098- atomic_inc(&vcc->stats->rx_drop);
30099+ atomic_inc_unchecked(&vcc->stats->rx_drop);
30100 recycle_rx_buf(card, skb);
30101 return;
30102 }
30103@@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30104 small or large buffer itself. */
30105 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
30106 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
30107- atomic_inc(&vcc->stats->rx_err);
30108+ atomic_inc_unchecked(&vcc->stats->rx_err);
30109 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
30110 NS_MAX_IOVECS);
30111 NS_PRV_IOVCNT(iovb) = 0;
30112@@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30113 ("nicstar%d: Expected a small buffer, and this is not one.\n",
30114 card->index);
30115 which_list(card, skb);
30116- atomic_inc(&vcc->stats->rx_err);
30117+ atomic_inc_unchecked(&vcc->stats->rx_err);
30118 recycle_rx_buf(card, skb);
30119 vc->rx_iov = NULL;
30120 recycle_iov_buf(card, iovb);
30121@@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30122 ("nicstar%d: Expected a large buffer, and this is not one.\n",
30123 card->index);
30124 which_list(card, skb);
30125- atomic_inc(&vcc->stats->rx_err);
30126+ atomic_inc_unchecked(&vcc->stats->rx_err);
30127 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
30128 NS_PRV_IOVCNT(iovb));
30129 vc->rx_iov = NULL;
30130@@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30131 printk(" - PDU size mismatch.\n");
30132 else
30133 printk(".\n");
30134- atomic_inc(&vcc->stats->rx_err);
30135+ atomic_inc_unchecked(&vcc->stats->rx_err);
30136 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
30137 NS_PRV_IOVCNT(iovb));
30138 vc->rx_iov = NULL;
30139@@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30140 /* skb points to a small buffer */
30141 if (!atm_charge(vcc, skb->truesize)) {
30142 push_rxbufs(card, skb);
30143- atomic_inc(&vcc->stats->rx_drop);
30144+ atomic_inc_unchecked(&vcc->stats->rx_drop);
30145 } else {
30146 skb_put(skb, len);
30147 dequeue_sm_buf(card, skb);
30148@@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30149 ATM_SKB(skb)->vcc = vcc;
30150 __net_timestamp(skb);
30151 vcc->push(vcc, skb);
30152- atomic_inc(&vcc->stats->rx);
30153+ atomic_inc_unchecked(&vcc->stats->rx);
30154 }
30155 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
30156 struct sk_buff *sb;
30157@@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30158 if (len <= NS_SMBUFSIZE) {
30159 if (!atm_charge(vcc, sb->truesize)) {
30160 push_rxbufs(card, sb);
30161- atomic_inc(&vcc->stats->rx_drop);
30162+ atomic_inc_unchecked(&vcc->stats->rx_drop);
30163 } else {
30164 skb_put(sb, len);
30165 dequeue_sm_buf(card, sb);
30166@@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30167 ATM_SKB(sb)->vcc = vcc;
30168 __net_timestamp(sb);
30169 vcc->push(vcc, sb);
30170- atomic_inc(&vcc->stats->rx);
30171+ atomic_inc_unchecked(&vcc->stats->rx);
30172 }
30173
30174 push_rxbufs(card, skb);
30175@@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30176
30177 if (!atm_charge(vcc, skb->truesize)) {
30178 push_rxbufs(card, skb);
30179- atomic_inc(&vcc->stats->rx_drop);
30180+ atomic_inc_unchecked(&vcc->stats->rx_drop);
30181 } else {
30182 dequeue_lg_buf(card, skb);
30183 #ifdef NS_USE_DESTRUCTORS
30184@@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30185 ATM_SKB(skb)->vcc = vcc;
30186 __net_timestamp(skb);
30187 vcc->push(vcc, skb);
30188- atomic_inc(&vcc->stats->rx);
30189+ atomic_inc_unchecked(&vcc->stats->rx);
30190 }
30191
30192 push_rxbufs(card, sb);
30193@@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30194 printk
30195 ("nicstar%d: Out of huge buffers.\n",
30196 card->index);
30197- atomic_inc(&vcc->stats->rx_drop);
30198+ atomic_inc_unchecked(&vcc->stats->rx_drop);
30199 recycle_iovec_rx_bufs(card,
30200 (struct iovec *)
30201 iovb->data,
30202@@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30203 card->hbpool.count++;
30204 } else
30205 dev_kfree_skb_any(hb);
30206- atomic_inc(&vcc->stats->rx_drop);
30207+ atomic_inc_unchecked(&vcc->stats->rx_drop);
30208 } else {
30209 /* Copy the small buffer to the huge buffer */
30210 sb = (struct sk_buff *)iov->iov_base;
30211@@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30212 #endif /* NS_USE_DESTRUCTORS */
30213 __net_timestamp(hb);
30214 vcc->push(vcc, hb);
30215- atomic_inc(&vcc->stats->rx);
30216+ atomic_inc_unchecked(&vcc->stats->rx);
30217 }
30218 }
30219
30220diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
30221index 9851093..adb2b1e 100644
30222--- a/drivers/atm/solos-pci.c
30223+++ b/drivers/atm/solos-pci.c
30224@@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
30225 }
30226 atm_charge(vcc, skb->truesize);
30227 vcc->push(vcc, skb);
30228- atomic_inc(&vcc->stats->rx);
30229+ atomic_inc_unchecked(&vcc->stats->rx);
30230 break;
30231
30232 case PKT_STATUS:
30233@@ -1009,7 +1009,7 @@ static uint32_t fpga_tx(struct solos_card *card)
30234 vcc = SKB_CB(oldskb)->vcc;
30235
30236 if (vcc) {
30237- atomic_inc(&vcc->stats->tx);
30238+ atomic_inc_unchecked(&vcc->stats->tx);
30239 solos_pop(vcc, oldskb);
30240 } else
30241 dev_kfree_skb_irq(oldskb);
30242diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
30243index 0215934..ce9f5b1 100644
30244--- a/drivers/atm/suni.c
30245+++ b/drivers/atm/suni.c
30246@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
30247
30248
30249 #define ADD_LIMITED(s,v) \
30250- atomic_add((v),&stats->s); \
30251- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
30252+ atomic_add_unchecked((v),&stats->s); \
30253+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
30254
30255
30256 static void suni_hz(unsigned long from_timer)
30257diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
30258index 5120a96..e2572bd 100644
30259--- a/drivers/atm/uPD98402.c
30260+++ b/drivers/atm/uPD98402.c
30261@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
30262 struct sonet_stats tmp;
30263 int error = 0;
30264
30265- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
30266+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
30267 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
30268 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
30269 if (zero && !error) {
30270@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
30271
30272
30273 #define ADD_LIMITED(s,v) \
30274- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
30275- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
30276- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
30277+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
30278+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
30279+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
30280
30281
30282 static void stat_event(struct atm_dev *dev)
30283@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
30284 if (reason & uPD98402_INT_PFM) stat_event(dev);
30285 if (reason & uPD98402_INT_PCO) {
30286 (void) GET(PCOCR); /* clear interrupt cause */
30287- atomic_add(GET(HECCT),
30288+ atomic_add_unchecked(GET(HECCT),
30289 &PRIV(dev)->sonet_stats.uncorr_hcs);
30290 }
30291 if ((reason & uPD98402_INT_RFO) &&
30292@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
30293 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
30294 uPD98402_INT_LOS),PIMR); /* enable them */
30295 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
30296- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
30297- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
30298- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
30299+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
30300+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
30301+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
30302 return 0;
30303 }
30304
30305diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
30306index abe4e20..83c4727 100644
30307--- a/drivers/atm/zatm.c
30308+++ b/drivers/atm/zatm.c
30309@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
30310 }
30311 if (!size) {
30312 dev_kfree_skb_irq(skb);
30313- if (vcc) atomic_inc(&vcc->stats->rx_err);
30314+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
30315 continue;
30316 }
30317 if (!atm_charge(vcc,skb->truesize)) {
30318@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
30319 skb->len = size;
30320 ATM_SKB(skb)->vcc = vcc;
30321 vcc->push(vcc,skb);
30322- atomic_inc(&vcc->stats->rx);
30323+ atomic_inc_unchecked(&vcc->stats->rx);
30324 }
30325 zout(pos & 0xffff,MTA(mbx));
30326 #if 0 /* probably a stupid idea */
30327@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
30328 skb_queue_head(&zatm_vcc->backlog,skb);
30329 break;
30330 }
30331- atomic_inc(&vcc->stats->tx);
30332+ atomic_inc_unchecked(&vcc->stats->tx);
30333 wake_up(&zatm_vcc->tx_wait);
30334 }
30335
30336diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
30337index 147d1a4..d0fd4b0 100644
30338--- a/drivers/base/devtmpfs.c
30339+++ b/drivers/base/devtmpfs.c
30340@@ -347,7 +347,7 @@ int devtmpfs_mount(const char *mntdir)
30341 if (!thread)
30342 return 0;
30343
30344- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
30345+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
30346 if (err)
30347 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
30348 else
30349diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
30350index 8945f4e..4b47cf4 100644
30351--- a/drivers/base/firmware_class.c
30352+++ b/drivers/base/firmware_class.c
30353@@ -118,7 +118,7 @@ struct firmware_cache {
30354
30355 struct delayed_work work;
30356
30357- struct notifier_block pm_notify;
30358+ notifier_block_no_const pm_notify;
30359 #endif
30360 };
30361
30362diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
30363index e6ee5e8..98ad7fc 100644
30364--- a/drivers/base/power/wakeup.c
30365+++ b/drivers/base/power/wakeup.c
30366@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
30367 * They need to be modified together atomically, so it's better to use one
30368 * atomic variable to hold them both.
30369 */
30370-static atomic_t combined_event_count = ATOMIC_INIT(0);
30371+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
30372
30373 #define IN_PROGRESS_BITS (sizeof(int) * 4)
30374 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
30375
30376 static void split_counters(unsigned int *cnt, unsigned int *inpr)
30377 {
30378- unsigned int comb = atomic_read(&combined_event_count);
30379+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
30380
30381 *cnt = (comb >> IN_PROGRESS_BITS);
30382 *inpr = comb & MAX_IN_PROGRESS;
30383@@ -389,7 +389,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
30384 ws->start_prevent_time = ws->last_time;
30385
30386 /* Increment the counter of events in progress. */
30387- cec = atomic_inc_return(&combined_event_count);
30388+ cec = atomic_inc_return_unchecked(&combined_event_count);
30389
30390 trace_wakeup_source_activate(ws->name, cec);
30391 }
30392@@ -515,7 +515,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
30393 * Increment the counter of registered wakeup events and decrement the
30394 * couter of wakeup events in progress simultaneously.
30395 */
30396- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
30397+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
30398 trace_wakeup_source_deactivate(ws->name, cec);
30399
30400 split_counters(&cnt, &inpr);
30401diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
30402index ca83f96..69d4ea9 100644
30403--- a/drivers/block/cciss.c
30404+++ b/drivers/block/cciss.c
30405@@ -1198,6 +1198,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
30406 int err;
30407 u32 cp;
30408
30409+ memset(&arg64, 0, sizeof(arg64));
30410+
30411 err = 0;
30412 err |=
30413 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
30414@@ -3007,7 +3009,7 @@ static void start_io(ctlr_info_t *h)
30415 while (!list_empty(&h->reqQ)) {
30416 c = list_entry(h->reqQ.next, CommandList_struct, list);
30417 /* can't do anything if fifo is full */
30418- if ((h->access.fifo_full(h))) {
30419+ if ((h->access->fifo_full(h))) {
30420 dev_warn(&h->pdev->dev, "fifo full\n");
30421 break;
30422 }
30423@@ -3017,7 +3019,7 @@ static void start_io(ctlr_info_t *h)
30424 h->Qdepth--;
30425
30426 /* Tell the controller execute command */
30427- h->access.submit_command(h, c);
30428+ h->access->submit_command(h, c);
30429
30430 /* Put job onto the completed Q */
30431 addQ(&h->cmpQ, c);
30432@@ -3443,17 +3445,17 @@ startio:
30433
30434 static inline unsigned long get_next_completion(ctlr_info_t *h)
30435 {
30436- return h->access.command_completed(h);
30437+ return h->access->command_completed(h);
30438 }
30439
30440 static inline int interrupt_pending(ctlr_info_t *h)
30441 {
30442- return h->access.intr_pending(h);
30443+ return h->access->intr_pending(h);
30444 }
30445
30446 static inline long interrupt_not_for_us(ctlr_info_t *h)
30447 {
30448- return ((h->access.intr_pending(h) == 0) ||
30449+ return ((h->access->intr_pending(h) == 0) ||
30450 (h->interrupts_enabled == 0));
30451 }
30452
30453@@ -3486,7 +3488,7 @@ static inline u32 next_command(ctlr_info_t *h)
30454 u32 a;
30455
30456 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
30457- return h->access.command_completed(h);
30458+ return h->access->command_completed(h);
30459
30460 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
30461 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
30462@@ -4044,7 +4046,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
30463 trans_support & CFGTBL_Trans_use_short_tags);
30464
30465 /* Change the access methods to the performant access methods */
30466- h->access = SA5_performant_access;
30467+ h->access = &SA5_performant_access;
30468 h->transMethod = CFGTBL_Trans_Performant;
30469
30470 return;
30471@@ -4316,7 +4318,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
30472 if (prod_index < 0)
30473 return -ENODEV;
30474 h->product_name = products[prod_index].product_name;
30475- h->access = *(products[prod_index].access);
30476+ h->access = products[prod_index].access;
30477
30478 if (cciss_board_disabled(h)) {
30479 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
30480@@ -5041,7 +5043,7 @@ reinit_after_soft_reset:
30481 }
30482
30483 /* make sure the board interrupts are off */
30484- h->access.set_intr_mask(h, CCISS_INTR_OFF);
30485+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
30486 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
30487 if (rc)
30488 goto clean2;
30489@@ -5093,7 +5095,7 @@ reinit_after_soft_reset:
30490 * fake ones to scoop up any residual completions.
30491 */
30492 spin_lock_irqsave(&h->lock, flags);
30493- h->access.set_intr_mask(h, CCISS_INTR_OFF);
30494+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
30495 spin_unlock_irqrestore(&h->lock, flags);
30496 free_irq(h->intr[h->intr_mode], h);
30497 rc = cciss_request_irq(h, cciss_msix_discard_completions,
30498@@ -5113,9 +5115,9 @@ reinit_after_soft_reset:
30499 dev_info(&h->pdev->dev, "Board READY.\n");
30500 dev_info(&h->pdev->dev,
30501 "Waiting for stale completions to drain.\n");
30502- h->access.set_intr_mask(h, CCISS_INTR_ON);
30503+ h->access->set_intr_mask(h, CCISS_INTR_ON);
30504 msleep(10000);
30505- h->access.set_intr_mask(h, CCISS_INTR_OFF);
30506+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
30507
30508 rc = controller_reset_failed(h->cfgtable);
30509 if (rc)
30510@@ -5138,7 +5140,7 @@ reinit_after_soft_reset:
30511 cciss_scsi_setup(h);
30512
30513 /* Turn the interrupts on so we can service requests */
30514- h->access.set_intr_mask(h, CCISS_INTR_ON);
30515+ h->access->set_intr_mask(h, CCISS_INTR_ON);
30516
30517 /* Get the firmware version */
30518 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
30519@@ -5210,7 +5212,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
30520 kfree(flush_buf);
30521 if (return_code != IO_OK)
30522 dev_warn(&h->pdev->dev, "Error flushing cache\n");
30523- h->access.set_intr_mask(h, CCISS_INTR_OFF);
30524+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
30525 free_irq(h->intr[h->intr_mode], h);
30526 }
30527
30528diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
30529index 7fda30e..eb5dfe0 100644
30530--- a/drivers/block/cciss.h
30531+++ b/drivers/block/cciss.h
30532@@ -101,7 +101,7 @@ struct ctlr_info
30533 /* information about each logical volume */
30534 drive_info_struct *drv[CISS_MAX_LUN];
30535
30536- struct access_method access;
30537+ struct access_method *access;
30538
30539 /* queue and queue Info */
30540 struct list_head reqQ;
30541diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
30542index 9125bbe..eede5c8 100644
30543--- a/drivers/block/cpqarray.c
30544+++ b/drivers/block/cpqarray.c
30545@@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
30546 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
30547 goto Enomem4;
30548 }
30549- hba[i]->access.set_intr_mask(hba[i], 0);
30550+ hba[i]->access->set_intr_mask(hba[i], 0);
30551 if (request_irq(hba[i]->intr, do_ida_intr,
30552 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
30553 {
30554@@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
30555 add_timer(&hba[i]->timer);
30556
30557 /* Enable IRQ now that spinlock and rate limit timer are set up */
30558- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
30559+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
30560
30561 for(j=0; j<NWD; j++) {
30562 struct gendisk *disk = ida_gendisk[i][j];
30563@@ -694,7 +694,7 @@ DBGINFO(
30564 for(i=0; i<NR_PRODUCTS; i++) {
30565 if (board_id == products[i].board_id) {
30566 c->product_name = products[i].product_name;
30567- c->access = *(products[i].access);
30568+ c->access = products[i].access;
30569 break;
30570 }
30571 }
30572@@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
30573 hba[ctlr]->intr = intr;
30574 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
30575 hba[ctlr]->product_name = products[j].product_name;
30576- hba[ctlr]->access = *(products[j].access);
30577+ hba[ctlr]->access = products[j].access;
30578 hba[ctlr]->ctlr = ctlr;
30579 hba[ctlr]->board_id = board_id;
30580 hba[ctlr]->pci_dev = NULL; /* not PCI */
30581@@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
30582
30583 while((c = h->reqQ) != NULL) {
30584 /* Can't do anything if we're busy */
30585- if (h->access.fifo_full(h) == 0)
30586+ if (h->access->fifo_full(h) == 0)
30587 return;
30588
30589 /* Get the first entry from the request Q */
30590@@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
30591 h->Qdepth--;
30592
30593 /* Tell the controller to do our bidding */
30594- h->access.submit_command(h, c);
30595+ h->access->submit_command(h, c);
30596
30597 /* Get onto the completion Q */
30598 addQ(&h->cmpQ, c);
30599@@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
30600 unsigned long flags;
30601 __u32 a,a1;
30602
30603- istat = h->access.intr_pending(h);
30604+ istat = h->access->intr_pending(h);
30605 /* Is this interrupt for us? */
30606 if (istat == 0)
30607 return IRQ_NONE;
30608@@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
30609 */
30610 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
30611 if (istat & FIFO_NOT_EMPTY) {
30612- while((a = h->access.command_completed(h))) {
30613+ while((a = h->access->command_completed(h))) {
30614 a1 = a; a &= ~3;
30615 if ((c = h->cmpQ) == NULL)
30616 {
30617@@ -1449,11 +1449,11 @@ static int sendcmd(
30618 /*
30619 * Disable interrupt
30620 */
30621- info_p->access.set_intr_mask(info_p, 0);
30622+ info_p->access->set_intr_mask(info_p, 0);
30623 /* Make sure there is room in the command FIFO */
30624 /* Actually it should be completely empty at this time. */
30625 for (i = 200000; i > 0; i--) {
30626- temp = info_p->access.fifo_full(info_p);
30627+ temp = info_p->access->fifo_full(info_p);
30628 if (temp != 0) {
30629 break;
30630 }
30631@@ -1466,7 +1466,7 @@ DBG(
30632 /*
30633 * Send the cmd
30634 */
30635- info_p->access.submit_command(info_p, c);
30636+ info_p->access->submit_command(info_p, c);
30637 complete = pollcomplete(ctlr);
30638
30639 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
30640@@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
30641 * we check the new geometry. Then turn interrupts back on when
30642 * we're done.
30643 */
30644- host->access.set_intr_mask(host, 0);
30645+ host->access->set_intr_mask(host, 0);
30646 getgeometry(ctlr);
30647- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
30648+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
30649
30650 for(i=0; i<NWD; i++) {
30651 struct gendisk *disk = ida_gendisk[ctlr][i];
30652@@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
30653 /* Wait (up to 2 seconds) for a command to complete */
30654
30655 for (i = 200000; i > 0; i--) {
30656- done = hba[ctlr]->access.command_completed(hba[ctlr]);
30657+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
30658 if (done == 0) {
30659 udelay(10); /* a short fixed delay */
30660 } else
30661diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
30662index be73e9d..7fbf140 100644
30663--- a/drivers/block/cpqarray.h
30664+++ b/drivers/block/cpqarray.h
30665@@ -99,7 +99,7 @@ struct ctlr_info {
30666 drv_info_t drv[NWD];
30667 struct proc_dir_entry *proc;
30668
30669- struct access_method access;
30670+ struct access_method *access;
30671
30672 cmdlist_t *reqQ;
30673 cmdlist_t *cmpQ;
30674diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
30675index b953cc7..e3dc580 100644
30676--- a/drivers/block/drbd/drbd_int.h
30677+++ b/drivers/block/drbd/drbd_int.h
30678@@ -735,7 +735,7 @@ struct drbd_request;
30679 struct drbd_epoch {
30680 struct list_head list;
30681 unsigned int barrier_nr;
30682- atomic_t epoch_size; /* increased on every request added. */
30683+ atomic_unchecked_t epoch_size; /* increased on every request added. */
30684 atomic_t active; /* increased on every req. added, and dec on every finished. */
30685 unsigned long flags;
30686 };
30687@@ -1116,7 +1116,7 @@ struct drbd_conf {
30688 void *int_dig_in;
30689 void *int_dig_vv;
30690 wait_queue_head_t seq_wait;
30691- atomic_t packet_seq;
30692+ atomic_unchecked_t packet_seq;
30693 unsigned int peer_seq;
30694 spinlock_t peer_seq_lock;
30695 unsigned int minor;
30696@@ -1658,30 +1658,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
30697
30698 static inline void drbd_tcp_cork(struct socket *sock)
30699 {
30700- int __user val = 1;
30701+ int val = 1;
30702 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
30703- (char __user *)&val, sizeof(val));
30704+ (char __force_user *)&val, sizeof(val));
30705 }
30706
30707 static inline void drbd_tcp_uncork(struct socket *sock)
30708 {
30709- int __user val = 0;
30710+ int val = 0;
30711 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
30712- (char __user *)&val, sizeof(val));
30713+ (char __force_user *)&val, sizeof(val));
30714 }
30715
30716 static inline void drbd_tcp_nodelay(struct socket *sock)
30717 {
30718- int __user val = 1;
30719+ int val = 1;
30720 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
30721- (char __user *)&val, sizeof(val));
30722+ (char __force_user *)&val, sizeof(val));
30723 }
30724
30725 static inline void drbd_tcp_quickack(struct socket *sock)
30726 {
30727- int __user val = 2;
30728+ int val = 2;
30729 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
30730- (char __user *)&val, sizeof(val));
30731+ (char __force_user *)&val, sizeof(val));
30732 }
30733
30734 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
30735diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
30736index f55683a..2101b96 100644
30737--- a/drivers/block/drbd/drbd_main.c
30738+++ b/drivers/block/drbd/drbd_main.c
30739@@ -2556,7 +2556,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
30740 p.sector = sector;
30741 p.block_id = block_id;
30742 p.blksize = blksize;
30743- p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
30744+ p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
30745
30746 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
30747 return false;
30748@@ -2854,7 +2854,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
30749
30750 p.sector = cpu_to_be64(req->sector);
30751 p.block_id = (unsigned long)req;
30752- p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
30753+ p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
30754
30755 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
30756
30757@@ -3139,7 +3139,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
30758 atomic_set(&mdev->unacked_cnt, 0);
30759 atomic_set(&mdev->local_cnt, 0);
30760 atomic_set(&mdev->net_cnt, 0);
30761- atomic_set(&mdev->packet_seq, 0);
30762+ atomic_set_unchecked(&mdev->packet_seq, 0);
30763 atomic_set(&mdev->pp_in_use, 0);
30764 atomic_set(&mdev->pp_in_use_by_net, 0);
30765 atomic_set(&mdev->rs_sect_in, 0);
30766@@ -3221,8 +3221,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
30767 mdev->receiver.t_state);
30768
30769 /* no need to lock it, I'm the only thread alive */
30770- if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
30771- dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
30772+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
30773+ dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
30774 mdev->al_writ_cnt =
30775 mdev->bm_writ_cnt =
30776 mdev->read_cnt =
30777diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
30778index edb490a..ecd69da 100644
30779--- a/drivers/block/drbd/drbd_nl.c
30780+++ b/drivers/block/drbd/drbd_nl.c
30781@@ -2407,7 +2407,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
30782 module_put(THIS_MODULE);
30783 }
30784
30785-static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
30786+static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
30787
30788 static unsigned short *
30789 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
30790@@ -2478,7 +2478,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
30791 cn_reply->id.idx = CN_IDX_DRBD;
30792 cn_reply->id.val = CN_VAL_DRBD;
30793
30794- cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
30795+ cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
30796 cn_reply->ack = 0; /* not used here. */
30797 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
30798 (int)((char *)tl - (char *)reply->tag_list);
30799@@ -2510,7 +2510,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
30800 cn_reply->id.idx = CN_IDX_DRBD;
30801 cn_reply->id.val = CN_VAL_DRBD;
30802
30803- cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
30804+ cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
30805 cn_reply->ack = 0; /* not used here. */
30806 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
30807 (int)((char *)tl - (char *)reply->tag_list);
30808@@ -2588,7 +2588,7 @@ void drbd_bcast_ee(struct drbd_conf *mdev,
30809 cn_reply->id.idx = CN_IDX_DRBD;
30810 cn_reply->id.val = CN_VAL_DRBD;
30811
30812- cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
30813+ cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
30814 cn_reply->ack = 0; // not used here.
30815 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
30816 (int)((char*)tl - (char*)reply->tag_list);
30817@@ -2627,7 +2627,7 @@ void drbd_bcast_sync_progress(struct drbd_conf *mdev)
30818 cn_reply->id.idx = CN_IDX_DRBD;
30819 cn_reply->id.val = CN_VAL_DRBD;
30820
30821- cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
30822+ cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
30823 cn_reply->ack = 0; /* not used here. */
30824 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
30825 (int)((char *)tl - (char *)reply->tag_list);
30826diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
30827index c74ca2d..860c819 100644
30828--- a/drivers/block/drbd/drbd_receiver.c
30829+++ b/drivers/block/drbd/drbd_receiver.c
30830@@ -898,7 +898,7 @@ retry:
30831 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
30832 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
30833
30834- atomic_set(&mdev->packet_seq, 0);
30835+ atomic_set_unchecked(&mdev->packet_seq, 0);
30836 mdev->peer_seq = 0;
30837
30838 if (drbd_send_protocol(mdev) == -1)
30839@@ -999,7 +999,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
30840 do {
30841 next_epoch = NULL;
30842
30843- epoch_size = atomic_read(&epoch->epoch_size);
30844+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
30845
30846 switch (ev & ~EV_CLEANUP) {
30847 case EV_PUT:
30848@@ -1035,7 +1035,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
30849 rv = FE_DESTROYED;
30850 } else {
30851 epoch->flags = 0;
30852- atomic_set(&epoch->epoch_size, 0);
30853+ atomic_set_unchecked(&epoch->epoch_size, 0);
30854 /* atomic_set(&epoch->active, 0); is already zero */
30855 if (rv == FE_STILL_LIVE)
30856 rv = FE_RECYCLED;
30857@@ -1210,14 +1210,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
30858 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
30859 drbd_flush(mdev);
30860
30861- if (atomic_read(&mdev->current_epoch->epoch_size)) {
30862+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
30863 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
30864 if (epoch)
30865 break;
30866 }
30867
30868 epoch = mdev->current_epoch;
30869- wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
30870+ wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
30871
30872 D_ASSERT(atomic_read(&epoch->active) == 0);
30873 D_ASSERT(epoch->flags == 0);
30874@@ -1229,11 +1229,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
30875 }
30876
30877 epoch->flags = 0;
30878- atomic_set(&epoch->epoch_size, 0);
30879+ atomic_set_unchecked(&epoch->epoch_size, 0);
30880 atomic_set(&epoch->active, 0);
30881
30882 spin_lock(&mdev->epoch_lock);
30883- if (atomic_read(&mdev->current_epoch->epoch_size)) {
30884+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
30885 list_add(&epoch->list, &mdev->current_epoch->list);
30886 mdev->current_epoch = epoch;
30887 mdev->epochs++;
30888@@ -1702,7 +1702,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
30889 spin_unlock(&mdev->peer_seq_lock);
30890
30891 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
30892- atomic_inc(&mdev->current_epoch->epoch_size);
30893+ atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
30894 return drbd_drain_block(mdev, data_size);
30895 }
30896
30897@@ -1732,7 +1732,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
30898
30899 spin_lock(&mdev->epoch_lock);
30900 e->epoch = mdev->current_epoch;
30901- atomic_inc(&e->epoch->epoch_size);
30902+ atomic_inc_unchecked(&e->epoch->epoch_size);
30903 atomic_inc(&e->epoch->active);
30904 spin_unlock(&mdev->epoch_lock);
30905
30906@@ -3954,7 +3954,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
30907 D_ASSERT(list_empty(&mdev->done_ee));
30908
30909 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
30910- atomic_set(&mdev->current_epoch->epoch_size, 0);
30911+ atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
30912 D_ASSERT(list_empty(&mdev->current_epoch->list));
30913 }
30914
30915diff --git a/drivers/block/loop.c b/drivers/block/loop.c
30916index 54046e5..7759c55 100644
30917--- a/drivers/block/loop.c
30918+++ b/drivers/block/loop.c
30919@@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
30920 mm_segment_t old_fs = get_fs();
30921
30922 set_fs(get_ds());
30923- bw = file->f_op->write(file, buf, len, &pos);
30924+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
30925 set_fs(old_fs);
30926 if (likely(bw == len))
30927 return 0;
30928diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
30929index d620b44..587561e 100644
30930--- a/drivers/cdrom/cdrom.c
30931+++ b/drivers/cdrom/cdrom.c
30932@@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
30933 ENSURE(reset, CDC_RESET);
30934 ENSURE(generic_packet, CDC_GENERIC_PACKET);
30935 cdi->mc_flags = 0;
30936- cdo->n_minors = 0;
30937 cdi->options = CDO_USE_FFLAGS;
30938
30939 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
30940@@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
30941 else
30942 cdi->cdda_method = CDDA_OLD;
30943
30944- if (!cdo->generic_packet)
30945- cdo->generic_packet = cdrom_dummy_generic_packet;
30946+ if (!cdo->generic_packet) {
30947+ pax_open_kernel();
30948+ *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
30949+ pax_close_kernel();
30950+ }
30951
30952 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
30953 mutex_lock(&cdrom_mutex);
30954@@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
30955 if (cdi->exit)
30956 cdi->exit(cdi);
30957
30958- cdi->ops->n_minors--;
30959 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
30960 }
30961
30962diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
30963index 75d485a..2809958 100644
30964--- a/drivers/cdrom/gdrom.c
30965+++ b/drivers/cdrom/gdrom.c
30966@@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
30967 .audio_ioctl = gdrom_audio_ioctl,
30968 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
30969 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
30970- .n_minors = 1,
30971 };
30972
30973 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
30974diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
30975index 72bedad..8181ce1 100644
30976--- a/drivers/char/Kconfig
30977+++ b/drivers/char/Kconfig
30978@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
30979
30980 config DEVKMEM
30981 bool "/dev/kmem virtual device support"
30982- default y
30983+ default n
30984+ depends on !GRKERNSEC_KMEM
30985 help
30986 Say Y here if you want to support the /dev/kmem device. The
30987 /dev/kmem device is rarely used, but can be used for certain
30988@@ -581,6 +582,7 @@ config DEVPORT
30989 bool
30990 depends on !M68K
30991 depends on ISA || PCI
30992+ depends on !GRKERNSEC_KMEM
30993 default y
30994
30995 source "drivers/s390/char/Kconfig"
30996diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
30997index 2e04433..22afc64 100644
30998--- a/drivers/char/agp/frontend.c
30999+++ b/drivers/char/agp/frontend.c
31000@@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
31001 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
31002 return -EFAULT;
31003
31004- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
31005+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
31006 return -EFAULT;
31007
31008 client = agp_find_client_by_pid(reserve.pid);
31009diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
31010index 21cb980..f15107c 100644
31011--- a/drivers/char/genrtc.c
31012+++ b/drivers/char/genrtc.c
31013@@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
31014 switch (cmd) {
31015
31016 case RTC_PLL_GET:
31017+ memset(&pll, 0, sizeof(pll));
31018 if (get_rtc_pll(&pll))
31019 return -EINVAL;
31020 else
31021diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
31022index dfd7876..c0b0885 100644
31023--- a/drivers/char/hpet.c
31024+++ b/drivers/char/hpet.c
31025@@ -571,7 +571,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
31026 }
31027
31028 static int
31029-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
31030+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
31031 struct hpet_info *info)
31032 {
31033 struct hpet_timer __iomem *timer;
31034diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
31035index a0c84bb..9edcf60 100644
31036--- a/drivers/char/ipmi/ipmi_msghandler.c
31037+++ b/drivers/char/ipmi/ipmi_msghandler.c
31038@@ -420,7 +420,7 @@ struct ipmi_smi {
31039 struct proc_dir_entry *proc_dir;
31040 char proc_dir_name[10];
31041
31042- atomic_t stats[IPMI_NUM_STATS];
31043+ atomic_unchecked_t stats[IPMI_NUM_STATS];
31044
31045 /*
31046 * run_to_completion duplicate of smb_info, smi_info
31047@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
31048
31049
31050 #define ipmi_inc_stat(intf, stat) \
31051- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
31052+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
31053 #define ipmi_get_stat(intf, stat) \
31054- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
31055+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
31056
31057 static int is_lan_addr(struct ipmi_addr *addr)
31058 {
31059@@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
31060 INIT_LIST_HEAD(&intf->cmd_rcvrs);
31061 init_waitqueue_head(&intf->waitq);
31062 for (i = 0; i < IPMI_NUM_STATS; i++)
31063- atomic_set(&intf->stats[i], 0);
31064+ atomic_set_unchecked(&intf->stats[i], 0);
31065
31066 intf->proc_dir = NULL;
31067
31068diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
31069index 32a6c7e..f6966a9 100644
31070--- a/drivers/char/ipmi/ipmi_si_intf.c
31071+++ b/drivers/char/ipmi/ipmi_si_intf.c
31072@@ -275,7 +275,7 @@ struct smi_info {
31073 unsigned char slave_addr;
31074
31075 /* Counters and things for the proc filesystem. */
31076- atomic_t stats[SI_NUM_STATS];
31077+ atomic_unchecked_t stats[SI_NUM_STATS];
31078
31079 struct task_struct *thread;
31080
31081@@ -284,9 +284,9 @@ struct smi_info {
31082 };
31083
31084 #define smi_inc_stat(smi, stat) \
31085- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
31086+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
31087 #define smi_get_stat(smi, stat) \
31088- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
31089+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
31090
31091 #define SI_MAX_PARMS 4
31092
31093@@ -3225,7 +3225,7 @@ static int try_smi_init(struct smi_info *new_smi)
31094 atomic_set(&new_smi->req_events, 0);
31095 new_smi->run_to_completion = 0;
31096 for (i = 0; i < SI_NUM_STATS; i++)
31097- atomic_set(&new_smi->stats[i], 0);
31098+ atomic_set_unchecked(&new_smi->stats[i], 0);
31099
31100 new_smi->interrupt_disabled = 1;
31101 atomic_set(&new_smi->stop_operation, 0);
31102diff --git a/drivers/char/mem.c b/drivers/char/mem.c
31103index 0537903..121c699 100644
31104--- a/drivers/char/mem.c
31105+++ b/drivers/char/mem.c
31106@@ -18,6 +18,7 @@
31107 #include <linux/raw.h>
31108 #include <linux/tty.h>
31109 #include <linux/capability.h>
31110+#include <linux/security.h>
31111 #include <linux/ptrace.h>
31112 #include <linux/device.h>
31113 #include <linux/highmem.h>
31114@@ -37,6 +38,10 @@
31115
31116 #define DEVPORT_MINOR 4
31117
31118+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
31119+extern const struct file_operations grsec_fops;
31120+#endif
31121+
31122 static inline unsigned long size_inside_page(unsigned long start,
31123 unsigned long size)
31124 {
31125@@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31126
31127 while (cursor < to) {
31128 if (!devmem_is_allowed(pfn)) {
31129+#ifdef CONFIG_GRKERNSEC_KMEM
31130+ gr_handle_mem_readwrite(from, to);
31131+#else
31132 printk(KERN_INFO
31133 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
31134 current->comm, from, to);
31135+#endif
31136 return 0;
31137 }
31138 cursor += PAGE_SIZE;
31139@@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31140 }
31141 return 1;
31142 }
31143+#elif defined(CONFIG_GRKERNSEC_KMEM)
31144+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31145+{
31146+ return 0;
31147+}
31148 #else
31149 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31150 {
31151@@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
31152
31153 while (count > 0) {
31154 unsigned long remaining;
31155+ char *temp;
31156
31157 sz = size_inside_page(p, count);
31158
31159@@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
31160 if (!ptr)
31161 return -EFAULT;
31162
31163- remaining = copy_to_user(buf, ptr, sz);
31164+#ifdef CONFIG_PAX_USERCOPY
31165+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
31166+ if (!temp) {
31167+ unxlate_dev_mem_ptr(p, ptr);
31168+ return -ENOMEM;
31169+ }
31170+ memcpy(temp, ptr, sz);
31171+#else
31172+ temp = ptr;
31173+#endif
31174+
31175+ remaining = copy_to_user(buf, temp, sz);
31176+
31177+#ifdef CONFIG_PAX_USERCOPY
31178+ kfree(temp);
31179+#endif
31180+
31181 unxlate_dev_mem_ptr(p, ptr);
31182 if (remaining)
31183 return -EFAULT;
31184@@ -398,9 +429,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
31185 size_t count, loff_t *ppos)
31186 {
31187 unsigned long p = *ppos;
31188- ssize_t low_count, read, sz;
31189+ ssize_t low_count, read, sz, err = 0;
31190 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
31191- int err = 0;
31192
31193 read = 0;
31194 if (p < (unsigned long) high_memory) {
31195@@ -422,6 +452,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
31196 }
31197 #endif
31198 while (low_count > 0) {
31199+ char *temp;
31200+
31201 sz = size_inside_page(p, low_count);
31202
31203 /*
31204@@ -431,7 +463,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
31205 */
31206 kbuf = xlate_dev_kmem_ptr((char *)p);
31207
31208- if (copy_to_user(buf, kbuf, sz))
31209+#ifdef CONFIG_PAX_USERCOPY
31210+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
31211+ if (!temp)
31212+ return -ENOMEM;
31213+ memcpy(temp, kbuf, sz);
31214+#else
31215+ temp = kbuf;
31216+#endif
31217+
31218+ err = copy_to_user(buf, temp, sz);
31219+
31220+#ifdef CONFIG_PAX_USERCOPY
31221+ kfree(temp);
31222+#endif
31223+
31224+ if (err)
31225 return -EFAULT;
31226 buf += sz;
31227 p += sz;
31228@@ -833,6 +880,9 @@ static const struct memdev {
31229 #ifdef CONFIG_CRASH_DUMP
31230 [12] = { "oldmem", 0, &oldmem_fops, NULL },
31231 #endif
31232+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
31233+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
31234+#endif
31235 };
31236
31237 static int memory_open(struct inode *inode, struct file *filp)
31238diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
31239index 9df78e2..01ba9ae 100644
31240--- a/drivers/char/nvram.c
31241+++ b/drivers/char/nvram.c
31242@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
31243
31244 spin_unlock_irq(&rtc_lock);
31245
31246- if (copy_to_user(buf, contents, tmp - contents))
31247+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
31248 return -EFAULT;
31249
31250 *ppos = i;
31251diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
31252index 21721d2..4e98777 100644
31253--- a/drivers/char/pcmcia/synclink_cs.c
31254+++ b/drivers/char/pcmcia/synclink_cs.c
31255@@ -2346,9 +2346,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
31256
31257 if (debug_level >= DEBUG_LEVEL_INFO)
31258 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
31259- __FILE__,__LINE__, info->device_name, port->count);
31260+ __FILE__,__LINE__, info->device_name, atomic_read(&port->count));
31261
31262- WARN_ON(!port->count);
31263+ WARN_ON(!atomic_read(&port->count));
31264
31265 if (tty_port_close_start(port, tty, filp) == 0)
31266 goto cleanup;
31267@@ -2366,7 +2366,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
31268 cleanup:
31269 if (debug_level >= DEBUG_LEVEL_INFO)
31270 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__,
31271- tty->driver->name, port->count);
31272+ tty->driver->name, atomic_read(&port->count));
31273 }
31274
31275 /* Wait until the transmitter is empty.
31276@@ -2508,7 +2508,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
31277
31278 if (debug_level >= DEBUG_LEVEL_INFO)
31279 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
31280- __FILE__,__LINE__,tty->driver->name, port->count);
31281+ __FILE__,__LINE__,tty->driver->name, atomic_read(&port->count));
31282
31283 /* If port is closing, signal caller to try again */
31284 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
31285@@ -2528,11 +2528,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
31286 goto cleanup;
31287 }
31288 spin_lock(&port->lock);
31289- port->count++;
31290+ atomic_inc(&port->count);
31291 spin_unlock(&port->lock);
31292 spin_unlock_irqrestore(&info->netlock, flags);
31293
31294- if (port->count == 1) {
31295+ if (atomic_read(&port->count) == 1) {
31296 /* 1st open on this device, init hardware */
31297 retval = startup(info, tty);
31298 if (retval < 0)
31299@@ -3886,7 +3886,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
31300 unsigned short new_crctype;
31301
31302 /* return error if TTY interface open */
31303- if (info->port.count)
31304+ if (atomic_read(&info->port.count))
31305 return -EBUSY;
31306
31307 switch (encoding)
31308@@ -3989,7 +3989,7 @@ static int hdlcdev_open(struct net_device *dev)
31309
31310 /* arbitrate between network and tty opens */
31311 spin_lock_irqsave(&info->netlock, flags);
31312- if (info->port.count != 0 || info->netcount != 0) {
31313+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
31314 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
31315 spin_unlock_irqrestore(&info->netlock, flags);
31316 return -EBUSY;
31317@@ -4078,7 +4078,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
31318 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
31319
31320 /* return error if TTY interface open */
31321- if (info->port.count)
31322+ if (atomic_read(&info->port.count))
31323 return -EBUSY;
31324
31325 if (cmd != SIOCWANDEV)
31326diff --git a/drivers/char/random.c b/drivers/char/random.c
31327index b86eae9..b9c2ed7 100644
31328--- a/drivers/char/random.c
31329+++ b/drivers/char/random.c
31330@@ -272,8 +272,13 @@
31331 /*
31332 * Configuration information
31333 */
31334+#ifdef CONFIG_GRKERNSEC_RANDNET
31335+#define INPUT_POOL_WORDS 512
31336+#define OUTPUT_POOL_WORDS 128
31337+#else
31338 #define INPUT_POOL_WORDS 128
31339 #define OUTPUT_POOL_WORDS 32
31340+#endif
31341 #define SEC_XFER_SIZE 512
31342 #define EXTRACT_SIZE 10
31343
31344@@ -313,10 +318,17 @@ static struct poolinfo {
31345 int poolwords;
31346 int tap1, tap2, tap3, tap4, tap5;
31347 } poolinfo_table[] = {
31348+#ifdef CONFIG_GRKERNSEC_RANDNET
31349+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
31350+ { 512, 411, 308, 208, 104, 1 },
31351+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
31352+ { 128, 103, 76, 51, 25, 1 },
31353+#else
31354 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
31355 { 128, 103, 76, 51, 25, 1 },
31356 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
31357 { 32, 26, 20, 14, 7, 1 },
31358+#endif
31359 #if 0
31360 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
31361 { 2048, 1638, 1231, 819, 411, 1 },
31362@@ -437,6 +449,7 @@ struct entropy_store {
31363 int entropy_count;
31364 int entropy_total;
31365 unsigned int initialized:1;
31366+ bool last_data_init;
31367 __u8 last_data[EXTRACT_SIZE];
31368 };
31369
31370@@ -527,8 +540,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
31371 input_rotate += i ? 7 : 14;
31372 }
31373
31374- ACCESS_ONCE(r->input_rotate) = input_rotate;
31375- ACCESS_ONCE(r->add_ptr) = i;
31376+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
31377+ ACCESS_ONCE_RW(r->add_ptr) = i;
31378 smp_wmb();
31379
31380 if (out)
31381@@ -957,6 +970,10 @@ static ssize_t extract_entropy(struct entropy_store *r, void *buf,
31382 ssize_t ret = 0, i;
31383 __u8 tmp[EXTRACT_SIZE];
31384
31385+ /* if last_data isn't primed, we need EXTRACT_SIZE extra bytes */
31386+ if (fips_enabled && !r->last_data_init)
31387+ nbytes += EXTRACT_SIZE;
31388+
31389 trace_extract_entropy(r->name, nbytes, r->entropy_count, _RET_IP_);
31390 xfer_secondary_pool(r, nbytes);
31391 nbytes = account(r, nbytes, min, reserved);
31392@@ -967,6 +984,17 @@ static ssize_t extract_entropy(struct entropy_store *r, void *buf,
31393 if (fips_enabled) {
31394 unsigned long flags;
31395
31396+
31397+ /* prime last_data value if need be, per fips 140-2 */
31398+ if (!r->last_data_init) {
31399+ spin_lock_irqsave(&r->lock, flags);
31400+ memcpy(r->last_data, tmp, EXTRACT_SIZE);
31401+ r->last_data_init = true;
31402+ nbytes -= EXTRACT_SIZE;
31403+ spin_unlock_irqrestore(&r->lock, flags);
31404+ extract_buf(r, tmp);
31405+ }
31406+
31407 spin_lock_irqsave(&r->lock, flags);
31408 if (!memcmp(tmp, r->last_data, EXTRACT_SIZE))
31409 panic("Hardware RNG duplicated output!\n");
31410@@ -1008,7 +1036,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
31411
31412 extract_buf(r, tmp);
31413 i = min_t(int, nbytes, EXTRACT_SIZE);
31414- if (copy_to_user(buf, tmp, i)) {
31415+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
31416 ret = -EFAULT;
31417 break;
31418 }
31419@@ -1086,6 +1114,7 @@ static void init_std_data(struct entropy_store *r)
31420
31421 r->entropy_count = 0;
31422 r->entropy_total = 0;
31423+ r->last_data_init = false;
31424 mix_pool_bytes(r, &now, sizeof(now), NULL);
31425 for (i = r->poolinfo->POOLBYTES; i > 0; i -= sizeof(rv)) {
31426 if (!arch_get_random_long(&rv))
31427@@ -1342,7 +1371,7 @@ EXPORT_SYMBOL(generate_random_uuid);
31428 #include <linux/sysctl.h>
31429
31430 static int min_read_thresh = 8, min_write_thresh;
31431-static int max_read_thresh = INPUT_POOL_WORDS * 32;
31432+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
31433 static int max_write_thresh = INPUT_POOL_WORDS * 32;
31434 static char sysctl_bootid[16];
31435
31436diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
31437index 9b4f011..b7e0a1a 100644
31438--- a/drivers/char/sonypi.c
31439+++ b/drivers/char/sonypi.c
31440@@ -54,6 +54,7 @@
31441
31442 #include <asm/uaccess.h>
31443 #include <asm/io.h>
31444+#include <asm/local.h>
31445
31446 #include <linux/sonypi.h>
31447
31448@@ -490,7 +491,7 @@ static struct sonypi_device {
31449 spinlock_t fifo_lock;
31450 wait_queue_head_t fifo_proc_list;
31451 struct fasync_struct *fifo_async;
31452- int open_count;
31453+ local_t open_count;
31454 int model;
31455 struct input_dev *input_jog_dev;
31456 struct input_dev *input_key_dev;
31457@@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
31458 static int sonypi_misc_release(struct inode *inode, struct file *file)
31459 {
31460 mutex_lock(&sonypi_device.lock);
31461- sonypi_device.open_count--;
31462+ local_dec(&sonypi_device.open_count);
31463 mutex_unlock(&sonypi_device.lock);
31464 return 0;
31465 }
31466@@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
31467 {
31468 mutex_lock(&sonypi_device.lock);
31469 /* Flush input queue on first open */
31470- if (!sonypi_device.open_count)
31471+ if (!local_read(&sonypi_device.open_count))
31472 kfifo_reset(&sonypi_device.fifo);
31473- sonypi_device.open_count++;
31474+ local_inc(&sonypi_device.open_count);
31475 mutex_unlock(&sonypi_device.lock);
31476
31477 return 0;
31478diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
31479index 93211df..c7805f7 100644
31480--- a/drivers/char/tpm/tpm.c
31481+++ b/drivers/char/tpm/tpm.c
31482@@ -410,7 +410,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
31483 chip->vendor.req_complete_val)
31484 goto out_recv;
31485
31486- if ((status == chip->vendor.req_canceled)) {
31487+ if (status == chip->vendor.req_canceled) {
31488 dev_err(chip->dev, "Operation Canceled\n");
31489 rc = -ECANCELED;
31490 goto out;
31491diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
31492index 56051d0..11cf3b7 100644
31493--- a/drivers/char/tpm/tpm_acpi.c
31494+++ b/drivers/char/tpm/tpm_acpi.c
31495@@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
31496 virt = acpi_os_map_memory(start, len);
31497 if (!virt) {
31498 kfree(log->bios_event_log);
31499+ log->bios_event_log = NULL;
31500 printk("%s: ERROR - Unable to map memory\n", __func__);
31501 return -EIO;
31502 }
31503
31504- memcpy_fromio(log->bios_event_log, virt, len);
31505+ memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
31506
31507 acpi_os_unmap_memory(virt, len);
31508 return 0;
31509diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
31510index 84ddc55..1d32f1e 100644
31511--- a/drivers/char/tpm/tpm_eventlog.c
31512+++ b/drivers/char/tpm/tpm_eventlog.c
31513@@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
31514 event = addr;
31515
31516 if ((event->event_type == 0 && event->event_size == 0) ||
31517- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
31518+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
31519 return NULL;
31520
31521 return addr;
31522@@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
31523 return NULL;
31524
31525 if ((event->event_type == 0 && event->event_size == 0) ||
31526- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
31527+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
31528 return NULL;
31529
31530 (*pos)++;
31531@@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
31532 int i;
31533
31534 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
31535- seq_putc(m, data[i]);
31536+ if (!seq_putc(m, data[i]))
31537+ return -EFAULT;
31538
31539 return 0;
31540 }
31541diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
31542index 8ab9c3d..c3e65d3 100644
31543--- a/drivers/char/virtio_console.c
31544+++ b/drivers/char/virtio_console.c
31545@@ -622,7 +622,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
31546 if (to_user) {
31547 ssize_t ret;
31548
31549- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
31550+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
31551 if (ret)
31552 return -EFAULT;
31553 } else {
31554@@ -721,7 +721,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
31555 if (!port_has_data(port) && !port->host_connected)
31556 return 0;
31557
31558- return fill_readbuf(port, ubuf, count, true);
31559+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
31560 }
31561
31562 static int wait_port_writable(struct port *port, bool nonblock)
31563diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
31564index e164c55..3aabb50 100644
31565--- a/drivers/edac/edac_pci_sysfs.c
31566+++ b/drivers/edac/edac_pci_sysfs.c
31567@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
31568 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
31569 static int edac_pci_poll_msec = 1000; /* one second workq period */
31570
31571-static atomic_t pci_parity_count = ATOMIC_INIT(0);
31572-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
31573+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
31574+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
31575
31576 static struct kobject *edac_pci_top_main_kobj;
31577 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
31578@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
31579 edac_printk(KERN_CRIT, EDAC_PCI,
31580 "Signaled System Error on %s\n",
31581 pci_name(dev));
31582- atomic_inc(&pci_nonparity_count);
31583+ atomic_inc_unchecked(&pci_nonparity_count);
31584 }
31585
31586 if (status & (PCI_STATUS_PARITY)) {
31587@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
31588 "Master Data Parity Error on %s\n",
31589 pci_name(dev));
31590
31591- atomic_inc(&pci_parity_count);
31592+ atomic_inc_unchecked(&pci_parity_count);
31593 }
31594
31595 if (status & (PCI_STATUS_DETECTED_PARITY)) {
31596@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
31597 "Detected Parity Error on %s\n",
31598 pci_name(dev));
31599
31600- atomic_inc(&pci_parity_count);
31601+ atomic_inc_unchecked(&pci_parity_count);
31602 }
31603 }
31604
31605@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
31606 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
31607 "Signaled System Error on %s\n",
31608 pci_name(dev));
31609- atomic_inc(&pci_nonparity_count);
31610+ atomic_inc_unchecked(&pci_nonparity_count);
31611 }
31612
31613 if (status & (PCI_STATUS_PARITY)) {
31614@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
31615 "Master Data Parity Error on "
31616 "%s\n", pci_name(dev));
31617
31618- atomic_inc(&pci_parity_count);
31619+ atomic_inc_unchecked(&pci_parity_count);
31620 }
31621
31622 if (status & (PCI_STATUS_DETECTED_PARITY)) {
31623@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
31624 "Detected Parity Error on %s\n",
31625 pci_name(dev));
31626
31627- atomic_inc(&pci_parity_count);
31628+ atomic_inc_unchecked(&pci_parity_count);
31629 }
31630 }
31631 }
31632@@ -676,7 +676,7 @@ void edac_pci_do_parity_check(void)
31633 if (!check_pci_errors)
31634 return;
31635
31636- before_count = atomic_read(&pci_parity_count);
31637+ before_count = atomic_read_unchecked(&pci_parity_count);
31638
31639 /* scan all PCI devices looking for a Parity Error on devices and
31640 * bridges.
31641@@ -688,7 +688,7 @@ void edac_pci_do_parity_check(void)
31642 /* Only if operator has selected panic on PCI Error */
31643 if (edac_pci_get_panic_on_pe()) {
31644 /* If the count is different 'after' from 'before' */
31645- if (before_count != atomic_read(&pci_parity_count))
31646+ if (before_count != atomic_read_unchecked(&pci_parity_count))
31647 panic("EDAC: PCI Parity Error");
31648 }
31649 }
31650diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
31651index 8c87a5e..a19cbd7 100644
31652--- a/drivers/edac/mce_amd.h
31653+++ b/drivers/edac/mce_amd.h
31654@@ -80,7 +80,7 @@ extern const char * const ii_msgs[];
31655 struct amd_decoder_ops {
31656 bool (*dc_mce)(u16, u8);
31657 bool (*ic_mce)(u16, u8);
31658-};
31659+} __no_const;
31660
31661 void amd_report_gart_errors(bool);
31662 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
31663diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
31664index 57ea7f4..789e3c3 100644
31665--- a/drivers/firewire/core-card.c
31666+++ b/drivers/firewire/core-card.c
31667@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
31668
31669 void fw_core_remove_card(struct fw_card *card)
31670 {
31671- struct fw_card_driver dummy_driver = dummy_driver_template;
31672+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
31673
31674 card->driver->update_phy_reg(card, 4,
31675 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
31676diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
31677index f8d2287..5aaf4db 100644
31678--- a/drivers/firewire/core-cdev.c
31679+++ b/drivers/firewire/core-cdev.c
31680@@ -1365,8 +1365,7 @@ static int init_iso_resource(struct client *client,
31681 int ret;
31682
31683 if ((request->channels == 0 && request->bandwidth == 0) ||
31684- request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
31685- request->bandwidth < 0)
31686+ request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
31687 return -EINVAL;
31688
31689 r = kmalloc(sizeof(*r), GFP_KERNEL);
31690diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
31691index 28a94c7..58da63a 100644
31692--- a/drivers/firewire/core-transaction.c
31693+++ b/drivers/firewire/core-transaction.c
31694@@ -38,6 +38,7 @@
31695 #include <linux/timer.h>
31696 #include <linux/types.h>
31697 #include <linux/workqueue.h>
31698+#include <linux/sched.h>
31699
31700 #include <asm/byteorder.h>
31701
31702diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
31703index 515a42c..5ecf3ba 100644
31704--- a/drivers/firewire/core.h
31705+++ b/drivers/firewire/core.h
31706@@ -111,6 +111,7 @@ struct fw_card_driver {
31707
31708 int (*stop_iso)(struct fw_iso_context *ctx);
31709 };
31710+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
31711
31712 void fw_card_initialize(struct fw_card *card,
31713 const struct fw_card_driver *driver, struct device *device);
31714diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
31715index b298158..7ed8432 100644
31716--- a/drivers/firmware/dmi_scan.c
31717+++ b/drivers/firmware/dmi_scan.c
31718@@ -452,11 +452,6 @@ void __init dmi_scan_machine(void)
31719 }
31720 }
31721 else {
31722- /*
31723- * no iounmap() for that ioremap(); it would be a no-op, but
31724- * it's so early in setup that sucker gets confused into doing
31725- * what it shouldn't if we actually call it.
31726- */
31727 p = dmi_ioremap(0xF0000, 0x10000);
31728 if (p == NULL)
31729 goto error;
31730@@ -726,7 +721,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
31731 if (buf == NULL)
31732 return -1;
31733
31734- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
31735+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
31736
31737 iounmap(buf);
31738 return 0;
31739diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
31740index 82d5c20..44a7177 100644
31741--- a/drivers/gpio/gpio-vr41xx.c
31742+++ b/drivers/gpio/gpio-vr41xx.c
31743@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
31744 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
31745 maskl, pendl, maskh, pendh);
31746
31747- atomic_inc(&irq_err_count);
31748+ atomic_inc_unchecked(&irq_err_count);
31749
31750 return -EINVAL;
31751 }
31752diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
31753index 1227adf..f2301c2 100644
31754--- a/drivers/gpu/drm/drm_crtc_helper.c
31755+++ b/drivers/gpu/drm/drm_crtc_helper.c
31756@@ -286,7 +286,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
31757 struct drm_crtc *tmp;
31758 int crtc_mask = 1;
31759
31760- WARN(!crtc, "checking null crtc?\n");
31761+ BUG_ON(!crtc);
31762
31763 dev = crtc->dev;
31764
31765diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
31766index be174ca..0bcbb71 100644
31767--- a/drivers/gpu/drm/drm_drv.c
31768+++ b/drivers/gpu/drm/drm_drv.c
31769@@ -307,7 +307,7 @@ module_exit(drm_core_exit);
31770 /**
31771 * Copy and IOCTL return string to user space
31772 */
31773-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
31774+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
31775 {
31776 int len;
31777
31778@@ -390,7 +390,7 @@ long drm_ioctl(struct file *filp,
31779 return -ENODEV;
31780
31781 atomic_inc(&dev->ioctl_count);
31782- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
31783+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
31784 ++file_priv->ioctl_count;
31785
31786 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
31787diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
31788index 133b413..fd68225 100644
31789--- a/drivers/gpu/drm/drm_fops.c
31790+++ b/drivers/gpu/drm/drm_fops.c
31791@@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
31792 }
31793
31794 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
31795- atomic_set(&dev->counts[i], 0);
31796+ atomic_set_unchecked(&dev->counts[i], 0);
31797
31798 dev->sigdata.lock = NULL;
31799
31800@@ -134,7 +134,7 @@ int drm_open(struct inode *inode, struct file *filp)
31801 if (drm_device_is_unplugged(dev))
31802 return -ENODEV;
31803
31804- if (!dev->open_count++)
31805+ if (local_inc_return(&dev->open_count) == 1)
31806 need_setup = 1;
31807 mutex_lock(&dev->struct_mutex);
31808 old_mapping = dev->dev_mapping;
31809@@ -149,7 +149,7 @@ int drm_open(struct inode *inode, struct file *filp)
31810 retcode = drm_open_helper(inode, filp, dev);
31811 if (retcode)
31812 goto err_undo;
31813- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
31814+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
31815 if (need_setup) {
31816 retcode = drm_setup(dev);
31817 if (retcode)
31818@@ -164,7 +164,7 @@ err_undo:
31819 iput(container_of(dev->dev_mapping, struct inode, i_data));
31820 dev->dev_mapping = old_mapping;
31821 mutex_unlock(&dev->struct_mutex);
31822- dev->open_count--;
31823+ local_dec(&dev->open_count);
31824 return retcode;
31825 }
31826 EXPORT_SYMBOL(drm_open);
31827@@ -438,7 +438,7 @@ int drm_release(struct inode *inode, struct file *filp)
31828
31829 mutex_lock(&drm_global_mutex);
31830
31831- DRM_DEBUG("open_count = %d\n", dev->open_count);
31832+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
31833
31834 if (dev->driver->preclose)
31835 dev->driver->preclose(dev, file_priv);
31836@@ -447,10 +447,10 @@ int drm_release(struct inode *inode, struct file *filp)
31837 * Begin inline drm_release
31838 */
31839
31840- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
31841+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
31842 task_pid_nr(current),
31843 (long)old_encode_dev(file_priv->minor->device),
31844- dev->open_count);
31845+ local_read(&dev->open_count));
31846
31847 /* Release any auth tokens that might point to this file_priv,
31848 (do that under the drm_global_mutex) */
31849@@ -547,8 +547,8 @@ int drm_release(struct inode *inode, struct file *filp)
31850 * End inline drm_release
31851 */
31852
31853- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
31854- if (!--dev->open_count) {
31855+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
31856+ if (local_dec_and_test(&dev->open_count)) {
31857 if (atomic_read(&dev->ioctl_count)) {
31858 DRM_ERROR("Device busy: %d\n",
31859 atomic_read(&dev->ioctl_count));
31860diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
31861index f731116..629842c 100644
31862--- a/drivers/gpu/drm/drm_global.c
31863+++ b/drivers/gpu/drm/drm_global.c
31864@@ -36,7 +36,7 @@
31865 struct drm_global_item {
31866 struct mutex mutex;
31867 void *object;
31868- int refcount;
31869+ atomic_t refcount;
31870 };
31871
31872 static struct drm_global_item glob[DRM_GLOBAL_NUM];
31873@@ -49,7 +49,7 @@ void drm_global_init(void)
31874 struct drm_global_item *item = &glob[i];
31875 mutex_init(&item->mutex);
31876 item->object = NULL;
31877- item->refcount = 0;
31878+ atomic_set(&item->refcount, 0);
31879 }
31880 }
31881
31882@@ -59,7 +59,7 @@ void drm_global_release(void)
31883 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
31884 struct drm_global_item *item = &glob[i];
31885 BUG_ON(item->object != NULL);
31886- BUG_ON(item->refcount != 0);
31887+ BUG_ON(atomic_read(&item->refcount) != 0);
31888 }
31889 }
31890
31891@@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
31892 void *object;
31893
31894 mutex_lock(&item->mutex);
31895- if (item->refcount == 0) {
31896+ if (atomic_read(&item->refcount) == 0) {
31897 item->object = kzalloc(ref->size, GFP_KERNEL);
31898 if (unlikely(item->object == NULL)) {
31899 ret = -ENOMEM;
31900@@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
31901 goto out_err;
31902
31903 }
31904- ++item->refcount;
31905+ atomic_inc(&item->refcount);
31906 ref->object = item->object;
31907 object = item->object;
31908 mutex_unlock(&item->mutex);
31909@@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
31910 struct drm_global_item *item = &glob[ref->global_type];
31911
31912 mutex_lock(&item->mutex);
31913- BUG_ON(item->refcount == 0);
31914+ BUG_ON(atomic_read(&item->refcount) == 0);
31915 BUG_ON(ref->object != item->object);
31916- if (--item->refcount == 0) {
31917+ if (atomic_dec_and_test(&item->refcount)) {
31918 ref->release(ref);
31919 item->object = NULL;
31920 }
31921diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
31922index d4b20ce..77a8d41 100644
31923--- a/drivers/gpu/drm/drm_info.c
31924+++ b/drivers/gpu/drm/drm_info.c
31925@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
31926 struct drm_local_map *map;
31927 struct drm_map_list *r_list;
31928
31929- /* Hardcoded from _DRM_FRAME_BUFFER,
31930- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
31931- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
31932- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
31933+ static const char * const types[] = {
31934+ [_DRM_FRAME_BUFFER] = "FB",
31935+ [_DRM_REGISTERS] = "REG",
31936+ [_DRM_SHM] = "SHM",
31937+ [_DRM_AGP] = "AGP",
31938+ [_DRM_SCATTER_GATHER] = "SG",
31939+ [_DRM_CONSISTENT] = "PCI",
31940+ [_DRM_GEM] = "GEM" };
31941 const char *type;
31942 int i;
31943
31944@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
31945 map = r_list->map;
31946 if (!map)
31947 continue;
31948- if (map->type < 0 || map->type > 5)
31949+ if (map->type >= ARRAY_SIZE(types))
31950 type = "??";
31951 else
31952 type = types[map->type];
31953@@ -253,7 +257,11 @@ int drm_vma_info(struct seq_file *m, void *data)
31954 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
31955 vma->vm_flags & VM_LOCKED ? 'l' : '-',
31956 vma->vm_flags & VM_IO ? 'i' : '-',
31957+#ifdef CONFIG_GRKERNSEC_HIDESYM
31958+ 0);
31959+#else
31960 vma->vm_pgoff);
31961+#endif
31962
31963 #if defined(__i386__)
31964 pgprot = pgprot_val(vma->vm_page_prot);
31965diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
31966index 2f4c434..764794b 100644
31967--- a/drivers/gpu/drm/drm_ioc32.c
31968+++ b/drivers/gpu/drm/drm_ioc32.c
31969@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
31970 request = compat_alloc_user_space(nbytes);
31971 if (!access_ok(VERIFY_WRITE, request, nbytes))
31972 return -EFAULT;
31973- list = (struct drm_buf_desc *) (request + 1);
31974+ list = (struct drm_buf_desc __user *) (request + 1);
31975
31976 if (__put_user(count, &request->count)
31977 || __put_user(list, &request->list))
31978@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
31979 request = compat_alloc_user_space(nbytes);
31980 if (!access_ok(VERIFY_WRITE, request, nbytes))
31981 return -EFAULT;
31982- list = (struct drm_buf_pub *) (request + 1);
31983+ list = (struct drm_buf_pub __user *) (request + 1);
31984
31985 if (__put_user(count, &request->count)
31986 || __put_user(list, &request->list))
31987diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
31988index 23dd975..63e9801 100644
31989--- a/drivers/gpu/drm/drm_ioctl.c
31990+++ b/drivers/gpu/drm/drm_ioctl.c
31991@@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
31992 stats->data[i].value =
31993 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
31994 else
31995- stats->data[i].value = atomic_read(&dev->counts[i]);
31996+ stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
31997 stats->data[i].type = dev->types[i];
31998 }
31999
32000diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
32001index d752c96..fe08455 100644
32002--- a/drivers/gpu/drm/drm_lock.c
32003+++ b/drivers/gpu/drm/drm_lock.c
32004@@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
32005 if (drm_lock_take(&master->lock, lock->context)) {
32006 master->lock.file_priv = file_priv;
32007 master->lock.lock_time = jiffies;
32008- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
32009+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
32010 break; /* Got lock */
32011 }
32012
32013@@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
32014 return -EINVAL;
32015 }
32016
32017- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
32018+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
32019
32020 if (drm_lock_free(&master->lock, lock->context)) {
32021 /* FIXME: Should really bail out here. */
32022diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
32023index c236fd2..6b5f2e7 100644
32024--- a/drivers/gpu/drm/drm_stub.c
32025+++ b/drivers/gpu/drm/drm_stub.c
32026@@ -511,7 +511,7 @@ void drm_unplug_dev(struct drm_device *dev)
32027
32028 drm_device_set_unplugged(dev);
32029
32030- if (dev->open_count == 0) {
32031+ if (local_read(&dev->open_count) == 0) {
32032 drm_put_dev(dev);
32033 }
32034 mutex_unlock(&drm_global_mutex);
32035diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
32036index 004ecdf..db1f6e0 100644
32037--- a/drivers/gpu/drm/i810/i810_dma.c
32038+++ b/drivers/gpu/drm/i810/i810_dma.c
32039@@ -945,8 +945,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
32040 dma->buflist[vertex->idx],
32041 vertex->discard, vertex->used);
32042
32043- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
32044- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
32045+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
32046+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
32047 sarea_priv->last_enqueue = dev_priv->counter - 1;
32048 sarea_priv->last_dispatch = (int)hw_status[5];
32049
32050@@ -1106,8 +1106,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
32051 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
32052 mc->last_render);
32053
32054- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
32055- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
32056+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
32057+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
32058 sarea_priv->last_enqueue = dev_priv->counter - 1;
32059 sarea_priv->last_dispatch = (int)hw_status[5];
32060
32061diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
32062index 6e0acad..93c8289 100644
32063--- a/drivers/gpu/drm/i810/i810_drv.h
32064+++ b/drivers/gpu/drm/i810/i810_drv.h
32065@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
32066 int page_flipping;
32067
32068 wait_queue_head_t irq_queue;
32069- atomic_t irq_received;
32070- atomic_t irq_emitted;
32071+ atomic_unchecked_t irq_received;
32072+ atomic_unchecked_t irq_emitted;
32073
32074 int front_offset;
32075 } drm_i810_private_t;
32076diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
32077index dde8b50..da88e32 100644
32078--- a/drivers/gpu/drm/i915/i915_debugfs.c
32079+++ b/drivers/gpu/drm/i915/i915_debugfs.c
32080@@ -495,7 +495,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
32081 I915_READ(GTIMR));
32082 }
32083 seq_printf(m, "Interrupts received: %d\n",
32084- atomic_read(&dev_priv->irq_received));
32085+ atomic_read_unchecked(&dev_priv->irq_received));
32086 for_each_ring(ring, dev_priv, i) {
32087 if (IS_GEN6(dev) || IS_GEN7(dev)) {
32088 seq_printf(m,
32089diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
32090index 61ae104..f8a4bc1 100644
32091--- a/drivers/gpu/drm/i915/i915_dma.c
32092+++ b/drivers/gpu/drm/i915/i915_dma.c
32093@@ -1274,7 +1274,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
32094 bool can_switch;
32095
32096 spin_lock(&dev->count_lock);
32097- can_switch = (dev->open_count == 0);
32098+ can_switch = (local_read(&dev->open_count) == 0);
32099 spin_unlock(&dev->count_lock);
32100 return can_switch;
32101 }
32102diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
32103index f511fa2..cebdc1c 100644
32104--- a/drivers/gpu/drm/i915/i915_drv.h
32105+++ b/drivers/gpu/drm/i915/i915_drv.h
32106@@ -274,12 +274,12 @@ struct drm_i915_display_funcs {
32107 /* render clock increase/decrease */
32108 /* display clock increase/decrease */
32109 /* pll clock increase/decrease */
32110-};
32111+} __no_const;
32112
32113 struct drm_i915_gt_funcs {
32114 void (*force_wake_get)(struct drm_i915_private *dev_priv);
32115 void (*force_wake_put)(struct drm_i915_private *dev_priv);
32116-};
32117+} __no_const;
32118
32119 #define DEV_INFO_FLAGS \
32120 DEV_INFO_FLAG(is_mobile) DEV_INFO_SEP \
32121@@ -430,7 +430,7 @@ typedef struct drm_i915_private {
32122
32123 struct resource mch_res;
32124
32125- atomic_t irq_received;
32126+ atomic_unchecked_t irq_received;
32127
32128 /* protects the irq masks */
32129 spinlock_t irq_lock;
32130@@ -500,7 +500,7 @@ typedef struct drm_i915_private {
32131 } edp;
32132 bool no_aux_handshake;
32133
32134- struct notifier_block lid_notifier;
32135+ notifier_block_no_const lid_notifier;
32136
32137 int crt_ddc_pin;
32138 struct drm_i915_fence_reg fence_regs[I915_MAX_NUM_FENCES]; /* assume 965 */
32139@@ -1055,7 +1055,7 @@ struct drm_i915_gem_object {
32140 * will be page flipped away on the next vblank. When it
32141 * reaches 0, dev_priv->pending_flip_queue will be woken up.
32142 */
32143- atomic_t pending_flip;
32144+ atomic_unchecked_t pending_flip;
32145 };
32146
32147 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
32148@@ -1558,7 +1558,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
32149 struct drm_i915_private *dev_priv, unsigned port);
32150 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
32151 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
32152-extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
32153+static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
32154 {
32155 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
32156 }
32157diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
32158index 3eea143..a0b77db 100644
32159--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
32160+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
32161@@ -660,7 +660,7 @@ i915_gem_execbuffer_move_to_gpu(struct intel_ring_buffer *ring,
32162 i915_gem_clflush_object(obj);
32163
32164 if (obj->base.pending_write_domain)
32165- flips |= atomic_read(&obj->pending_flip);
32166+ flips |= atomic_read_unchecked(&obj->pending_flip);
32167
32168 flush_domains |= obj->base.write_domain;
32169 }
32170@@ -691,9 +691,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
32171
32172 static int
32173 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
32174- int count)
32175+ unsigned int count)
32176 {
32177- int i;
32178+ unsigned int i;
32179
32180 for (i = 0; i < count; i++) {
32181 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
32182diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
32183index 32e1bda..9b2ca91 100644
32184--- a/drivers/gpu/drm/i915/i915_irq.c
32185+++ b/drivers/gpu/drm/i915/i915_irq.c
32186@@ -531,7 +531,7 @@ static irqreturn_t valleyview_irq_handler(DRM_IRQ_ARGS)
32187 u32 pipe_stats[I915_MAX_PIPES];
32188 bool blc_event;
32189
32190- atomic_inc(&dev_priv->irq_received);
32191+ atomic_inc_unchecked(&dev_priv->irq_received);
32192
32193 while (true) {
32194 iir = I915_READ(VLV_IIR);
32195@@ -678,7 +678,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
32196 irqreturn_t ret = IRQ_NONE;
32197 int i;
32198
32199- atomic_inc(&dev_priv->irq_received);
32200+ atomic_inc_unchecked(&dev_priv->irq_received);
32201
32202 /* disable master interrupt before clearing iir */
32203 de_ier = I915_READ(DEIER);
32204@@ -753,7 +753,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
32205 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
32206 u32 hotplug_mask;
32207
32208- atomic_inc(&dev_priv->irq_received);
32209+ atomic_inc_unchecked(&dev_priv->irq_received);
32210
32211 /* disable master interrupt before clearing iir */
32212 de_ier = I915_READ(DEIER);
32213@@ -1760,7 +1760,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
32214 {
32215 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
32216
32217- atomic_set(&dev_priv->irq_received, 0);
32218+ atomic_set_unchecked(&dev_priv->irq_received, 0);
32219
32220 I915_WRITE(HWSTAM, 0xeffe);
32221
32222@@ -1786,7 +1786,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
32223 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
32224 int pipe;
32225
32226- atomic_set(&dev_priv->irq_received, 0);
32227+ atomic_set_unchecked(&dev_priv->irq_received, 0);
32228
32229 /* VLV magic */
32230 I915_WRITE(VLV_IMR, 0);
32231@@ -2091,7 +2091,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
32232 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
32233 int pipe;
32234
32235- atomic_set(&dev_priv->irq_received, 0);
32236+ atomic_set_unchecked(&dev_priv->irq_received, 0);
32237
32238 for_each_pipe(pipe)
32239 I915_WRITE(PIPESTAT(pipe), 0);
32240@@ -2142,7 +2142,7 @@ static irqreturn_t i8xx_irq_handler(DRM_IRQ_ARGS)
32241 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
32242 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
32243
32244- atomic_inc(&dev_priv->irq_received);
32245+ atomic_inc_unchecked(&dev_priv->irq_received);
32246
32247 iir = I915_READ16(IIR);
32248 if (iir == 0)
32249@@ -2227,7 +2227,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
32250 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
32251 int pipe;
32252
32253- atomic_set(&dev_priv->irq_received, 0);
32254+ atomic_set_unchecked(&dev_priv->irq_received, 0);
32255
32256 if (I915_HAS_HOTPLUG(dev)) {
32257 I915_WRITE(PORT_HOTPLUG_EN, 0);
32258@@ -2322,7 +2322,7 @@ static irqreturn_t i915_irq_handler(DRM_IRQ_ARGS)
32259 };
32260 int pipe, ret = IRQ_NONE;
32261
32262- atomic_inc(&dev_priv->irq_received);
32263+ atomic_inc_unchecked(&dev_priv->irq_received);
32264
32265 iir = I915_READ(IIR);
32266 do {
32267@@ -2448,7 +2448,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
32268 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
32269 int pipe;
32270
32271- atomic_set(&dev_priv->irq_received, 0);
32272+ atomic_set_unchecked(&dev_priv->irq_received, 0);
32273
32274 I915_WRITE(PORT_HOTPLUG_EN, 0);
32275 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
32276@@ -2555,7 +2555,7 @@ static irqreturn_t i965_irq_handler(DRM_IRQ_ARGS)
32277 int irq_received;
32278 int ret = IRQ_NONE, pipe;
32279
32280- atomic_inc(&dev_priv->irq_received);
32281+ atomic_inc_unchecked(&dev_priv->irq_received);
32282
32283 iir = I915_READ(IIR);
32284
32285diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
32286index b426d44..1b9038d 100644
32287--- a/drivers/gpu/drm/i915/intel_display.c
32288+++ b/drivers/gpu/drm/i915/intel_display.c
32289@@ -2131,7 +2131,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
32290
32291 wait_event(dev_priv->pending_flip_queue,
32292 atomic_read(&dev_priv->mm.wedged) ||
32293- atomic_read(&obj->pending_flip) == 0);
32294+ atomic_read_unchecked(&obj->pending_flip) == 0);
32295
32296 /* Big Hammer, we also need to ensure that any pending
32297 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
32298@@ -6236,8 +6236,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
32299
32300 obj = work->old_fb_obj;
32301
32302- atomic_clear_mask(1 << intel_crtc->plane,
32303- &obj->pending_flip.counter);
32304+ atomic_clear_mask_unchecked(1 << intel_crtc->plane, &obj->pending_flip);
32305
32306 wake_up(&dev_priv->pending_flip_queue);
32307 schedule_work(&work->work);
32308@@ -6583,7 +6582,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
32309 /* Block clients from rendering to the new back buffer until
32310 * the flip occurs and the object is no longer visible.
32311 */
32312- atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
32313+ atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
32314
32315 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
32316 if (ret)
32317@@ -6598,7 +6597,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
32318 return 0;
32319
32320 cleanup_pending:
32321- atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
32322+ atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
32323 drm_gem_object_unreference(&work->old_fb_obj->base);
32324 drm_gem_object_unreference(&obj->base);
32325 mutex_unlock(&dev->struct_mutex);
32326diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
32327index 54558a0..2d97005 100644
32328--- a/drivers/gpu/drm/mga/mga_drv.h
32329+++ b/drivers/gpu/drm/mga/mga_drv.h
32330@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
32331 u32 clear_cmd;
32332 u32 maccess;
32333
32334- atomic_t vbl_received; /**< Number of vblanks received. */
32335+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
32336 wait_queue_head_t fence_queue;
32337- atomic_t last_fence_retired;
32338+ atomic_unchecked_t last_fence_retired;
32339 u32 next_fence_to_post;
32340
32341 unsigned int fb_cpp;
32342diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
32343index 598c281..60d590e 100644
32344--- a/drivers/gpu/drm/mga/mga_irq.c
32345+++ b/drivers/gpu/drm/mga/mga_irq.c
32346@@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
32347 if (crtc != 0)
32348 return 0;
32349
32350- return atomic_read(&dev_priv->vbl_received);
32351+ return atomic_read_unchecked(&dev_priv->vbl_received);
32352 }
32353
32354
32355@@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
32356 /* VBLANK interrupt */
32357 if (status & MGA_VLINEPEN) {
32358 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
32359- atomic_inc(&dev_priv->vbl_received);
32360+ atomic_inc_unchecked(&dev_priv->vbl_received);
32361 drm_handle_vblank(dev, 0);
32362 handled = 1;
32363 }
32364@@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
32365 if ((prim_start & ~0x03) != (prim_end & ~0x03))
32366 MGA_WRITE(MGA_PRIMEND, prim_end);
32367
32368- atomic_inc(&dev_priv->last_fence_retired);
32369+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
32370 DRM_WAKEUP(&dev_priv->fence_queue);
32371 handled = 1;
32372 }
32373@@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
32374 * using fences.
32375 */
32376 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
32377- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
32378+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
32379 - *sequence) <= (1 << 23)));
32380
32381 *sequence = cur_fence;
32382diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
32383index 09fdef2..57f5c3b 100644
32384--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
32385+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
32386@@ -1240,7 +1240,7 @@ parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
32387 struct bit_table {
32388 const char id;
32389 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
32390-};
32391+} __no_const;
32392
32393 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
32394
32395diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
32396index a101699..a163f0a 100644
32397--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
32398+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
32399@@ -80,7 +80,7 @@ struct nouveau_drm {
32400 struct drm_global_reference mem_global_ref;
32401 struct ttm_bo_global_ref bo_global_ref;
32402 struct ttm_bo_device bdev;
32403- atomic_t validate_sequence;
32404+ atomic_unchecked_t validate_sequence;
32405 int (*move)(struct nouveau_channel *,
32406 struct ttm_buffer_object *,
32407 struct ttm_mem_reg *, struct ttm_mem_reg *);
32408diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.h b/drivers/gpu/drm/nouveau/nouveau_fence.h
32409index bedafd1..ca5330a 100644
32410--- a/drivers/gpu/drm/nouveau/nouveau_fence.h
32411+++ b/drivers/gpu/drm/nouveau/nouveau_fence.h
32412@@ -43,7 +43,7 @@ struct nouveau_fence_priv {
32413 int (*sync)(struct nouveau_fence *, struct nouveau_channel *,
32414 struct nouveau_channel *);
32415 u32 (*read)(struct nouveau_channel *);
32416-};
32417+} __no_const;
32418
32419 #define nouveau_fence(drm) ((struct nouveau_fence_priv *)(drm)->fence)
32420
32421diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
32422index 5e2f521..0d21436 100644
32423--- a/drivers/gpu/drm/nouveau/nouveau_gem.c
32424+++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
32425@@ -321,7 +321,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
32426 int trycnt = 0;
32427 int ret, i;
32428
32429- sequence = atomic_add_return(1, &drm->ttm.validate_sequence);
32430+ sequence = atomic_add_return_unchecked(1, &drm->ttm.validate_sequence);
32431 retry:
32432 if (++trycnt > 100000) {
32433 NV_ERROR(drm, "%s failed and gave up.\n", __func__);
32434diff --git a/drivers/gpu/drm/nouveau/nouveau_pm.h b/drivers/gpu/drm/nouveau/nouveau_pm.h
32435index 73b789c..ca5aa90 100644
32436--- a/drivers/gpu/drm/nouveau/nouveau_pm.h
32437+++ b/drivers/gpu/drm/nouveau/nouveau_pm.h
32438@@ -168,7 +168,7 @@ struct nouveau_pm {
32439 struct nouveau_pm_level *cur;
32440
32441 struct device *hwmon;
32442- struct notifier_block acpi_nb;
32443+ notifier_block_no_const acpi_nb;
32444
32445 int (*clocks_get)(struct drm_device *, struct nouveau_pm_level *);
32446 void *(*clocks_pre)(struct drm_device *, struct nouveau_pm_level *);
32447diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
32448index 6f0ac64..9c2dfb4 100644
32449--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
32450+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
32451@@ -63,7 +63,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
32452 bool can_switch;
32453
32454 spin_lock(&dev->count_lock);
32455- can_switch = (dev->open_count == 0);
32456+ can_switch = (local_read(&dev->open_count) == 0);
32457 spin_unlock(&dev->count_lock);
32458 return can_switch;
32459 }
32460diff --git a/drivers/gpu/drm/nouveau/nv50_evo.c b/drivers/gpu/drm/nouveau/nv50_evo.c
32461index 9f6f55c..30e3a29 100644
32462--- a/drivers/gpu/drm/nouveau/nv50_evo.c
32463+++ b/drivers/gpu/drm/nouveau/nv50_evo.c
32464@@ -152,9 +152,9 @@ nv50_evo_channel_new(struct drm_device *dev, int chid,
32465 kzalloc(sizeof(*evo->object->oclass), GFP_KERNEL);
32466 evo->object->oclass->ofuncs =
32467 kzalloc(sizeof(*evo->object->oclass->ofuncs), GFP_KERNEL);
32468- evo->object->oclass->ofuncs->rd32 = nv50_evo_rd32;
32469- evo->object->oclass->ofuncs->wr32 = nv50_evo_wr32;
32470- evo->object->oclass->ofuncs->rd08 =
32471+ *(void**)&evo->object->oclass->ofuncs->rd32 = nv50_evo_rd32;
32472+ *(void**)&evo->object->oclass->ofuncs->wr32 = nv50_evo_wr32;
32473+ *(void**)&evo->object->oclass->ofuncs->rd08 =
32474 ioremap(pci_resource_start(dev->pdev, 0) +
32475 NV50_PDISPLAY_USER(evo->handle), PAGE_SIZE);
32476 return 0;
32477diff --git a/drivers/gpu/drm/nouveau/nv50_sor.c b/drivers/gpu/drm/nouveau/nv50_sor.c
32478index b562b59..9d725a8 100644
32479--- a/drivers/gpu/drm/nouveau/nv50_sor.c
32480+++ b/drivers/gpu/drm/nouveau/nv50_sor.c
32481@@ -317,7 +317,7 @@ nv50_sor_dpms(struct drm_encoder *encoder, int mode)
32482 }
32483
32484 if (nv_encoder->dcb->type == DCB_OUTPUT_DP) {
32485- struct dp_train_func func = {
32486+ static struct dp_train_func func = {
32487 .link_set = nv50_sor_dp_link_set,
32488 .train_set = nv50_sor_dp_train_set,
32489 .train_adj = nv50_sor_dp_train_adj
32490diff --git a/drivers/gpu/drm/nouveau/nvd0_display.c b/drivers/gpu/drm/nouveau/nvd0_display.c
32491index c402fca..f1d694b 100644
32492--- a/drivers/gpu/drm/nouveau/nvd0_display.c
32493+++ b/drivers/gpu/drm/nouveau/nvd0_display.c
32494@@ -1389,7 +1389,7 @@ nvd0_sor_dpms(struct drm_encoder *encoder, int mode)
32495 nv_wait(device, 0x61c030 + (or * 0x0800), 0x10000000, 0x00000000);
32496
32497 if (nv_encoder->dcb->type == DCB_OUTPUT_DP) {
32498- struct dp_train_func func = {
32499+ static struct dp_train_func func = {
32500 .link_set = nvd0_sor_dp_link_set,
32501 .train_set = nvd0_sor_dp_train_set,
32502 .train_adj = nvd0_sor_dp_train_adj
32503diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
32504index d4660cf..70dbe65 100644
32505--- a/drivers/gpu/drm/r128/r128_cce.c
32506+++ b/drivers/gpu/drm/r128/r128_cce.c
32507@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
32508
32509 /* GH: Simple idle check.
32510 */
32511- atomic_set(&dev_priv->idle_count, 0);
32512+ atomic_set_unchecked(&dev_priv->idle_count, 0);
32513
32514 /* We don't support anything other than bus-mastering ring mode,
32515 * but the ring can be in either AGP or PCI space for the ring
32516diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
32517index 930c71b..499aded 100644
32518--- a/drivers/gpu/drm/r128/r128_drv.h
32519+++ b/drivers/gpu/drm/r128/r128_drv.h
32520@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
32521 int is_pci;
32522 unsigned long cce_buffers_offset;
32523
32524- atomic_t idle_count;
32525+ atomic_unchecked_t idle_count;
32526
32527 int page_flipping;
32528 int current_page;
32529 u32 crtc_offset;
32530 u32 crtc_offset_cntl;
32531
32532- atomic_t vbl_received;
32533+ atomic_unchecked_t vbl_received;
32534
32535 u32 color_fmt;
32536 unsigned int front_offset;
32537diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
32538index 2ea4f09..d391371 100644
32539--- a/drivers/gpu/drm/r128/r128_irq.c
32540+++ b/drivers/gpu/drm/r128/r128_irq.c
32541@@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
32542 if (crtc != 0)
32543 return 0;
32544
32545- return atomic_read(&dev_priv->vbl_received);
32546+ return atomic_read_unchecked(&dev_priv->vbl_received);
32547 }
32548
32549 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
32550@@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
32551 /* VBLANK interrupt */
32552 if (status & R128_CRTC_VBLANK_INT) {
32553 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
32554- atomic_inc(&dev_priv->vbl_received);
32555+ atomic_inc_unchecked(&dev_priv->vbl_received);
32556 drm_handle_vblank(dev, 0);
32557 return IRQ_HANDLED;
32558 }
32559diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
32560index 19bb7e6..de7e2a2 100644
32561--- a/drivers/gpu/drm/r128/r128_state.c
32562+++ b/drivers/gpu/drm/r128/r128_state.c
32563@@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
32564
32565 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
32566 {
32567- if (atomic_read(&dev_priv->idle_count) == 0)
32568+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
32569 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
32570 else
32571- atomic_set(&dev_priv->idle_count, 0);
32572+ atomic_set_unchecked(&dev_priv->idle_count, 0);
32573 }
32574
32575 #endif
32576diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
32577index 5a82b6b..9e69c73 100644
32578--- a/drivers/gpu/drm/radeon/mkregtable.c
32579+++ b/drivers/gpu/drm/radeon/mkregtable.c
32580@@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
32581 regex_t mask_rex;
32582 regmatch_t match[4];
32583 char buf[1024];
32584- size_t end;
32585+ long end;
32586 int len;
32587 int done = 0;
32588 int r;
32589 unsigned o;
32590 struct offset *offset;
32591 char last_reg_s[10];
32592- int last_reg;
32593+ unsigned long last_reg;
32594
32595 if (regcomp
32596 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
32597diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
32598index 8c42d54..5b6b963 100644
32599--- a/drivers/gpu/drm/radeon/radeon.h
32600+++ b/drivers/gpu/drm/radeon/radeon.h
32601@@ -728,7 +728,7 @@ struct r600_blit_cp_primitives {
32602 int x2, int y2);
32603 void (*draw_auto)(struct radeon_device *rdev);
32604 void (*set_default_state)(struct radeon_device *rdev);
32605-};
32606+} __no_const;
32607
32608 struct r600_blit {
32609 struct radeon_bo *shader_obj;
32610@@ -1248,7 +1248,7 @@ struct radeon_asic {
32611 u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
32612 void (*post_page_flip)(struct radeon_device *rdev, int crtc);
32613 } pflip;
32614-};
32615+} __no_const;
32616
32617 /*
32618 * Asic structures
32619@@ -1590,7 +1590,7 @@ struct radeon_device {
32620 struct mutex dc_hw_i2c_mutex; /* display controller hw i2c mutex */
32621 bool audio_enabled;
32622 struct r600_audio audio_status; /* audio stuff */
32623- struct notifier_block acpi_nb;
32624+ notifier_block_no_const acpi_nb;
32625 /* only one userspace can use Hyperz features or CMASK at a time */
32626 struct drm_file *hyperz_filp;
32627 struct drm_file *cmask_filp;
32628diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
32629index e2f5f88..82f22da 100644
32630--- a/drivers/gpu/drm/radeon/radeon_device.c
32631+++ b/drivers/gpu/drm/radeon/radeon_device.c
32632@@ -940,7 +940,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
32633 bool can_switch;
32634
32635 spin_lock(&dev->count_lock);
32636- can_switch = (dev->open_count == 0);
32637+ can_switch = (local_read(&dev->open_count) == 0);
32638 spin_unlock(&dev->count_lock);
32639 return can_switch;
32640 }
32641diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
32642index a1b59ca..86f2d44 100644
32643--- a/drivers/gpu/drm/radeon/radeon_drv.h
32644+++ b/drivers/gpu/drm/radeon/radeon_drv.h
32645@@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
32646
32647 /* SW interrupt */
32648 wait_queue_head_t swi_queue;
32649- atomic_t swi_emitted;
32650+ atomic_unchecked_t swi_emitted;
32651 int vblank_crtc;
32652 uint32_t irq_enable_reg;
32653 uint32_t r500_disp_irq_reg;
32654diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
32655index c180df8..cd80dd2d 100644
32656--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
32657+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
32658@@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
32659 request = compat_alloc_user_space(sizeof(*request));
32660 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
32661 || __put_user(req32.param, &request->param)
32662- || __put_user((void __user *)(unsigned long)req32.value,
32663+ || __put_user((unsigned long)req32.value,
32664 &request->value))
32665 return -EFAULT;
32666
32667diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
32668index e771033..a0bc6b3 100644
32669--- a/drivers/gpu/drm/radeon/radeon_irq.c
32670+++ b/drivers/gpu/drm/radeon/radeon_irq.c
32671@@ -224,8 +224,8 @@ static int radeon_emit_irq(struct drm_device * dev)
32672 unsigned int ret;
32673 RING_LOCALS;
32674
32675- atomic_inc(&dev_priv->swi_emitted);
32676- ret = atomic_read(&dev_priv->swi_emitted);
32677+ atomic_inc_unchecked(&dev_priv->swi_emitted);
32678+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
32679
32680 BEGIN_RING(4);
32681 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
32682@@ -351,7 +351,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
32683 drm_radeon_private_t *dev_priv =
32684 (drm_radeon_private_t *) dev->dev_private;
32685
32686- atomic_set(&dev_priv->swi_emitted, 0);
32687+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
32688 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
32689
32690 dev->max_vblank_count = 0x001fffff;
32691diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
32692index 8e9057b..af6dacb 100644
32693--- a/drivers/gpu/drm/radeon/radeon_state.c
32694+++ b/drivers/gpu/drm/radeon/radeon_state.c
32695@@ -2166,7 +2166,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
32696 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
32697 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
32698
32699- if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
32700+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
32701 sarea_priv->nbox * sizeof(depth_boxes[0])))
32702 return -EFAULT;
32703
32704@@ -3029,7 +3029,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
32705 {
32706 drm_radeon_private_t *dev_priv = dev->dev_private;
32707 drm_radeon_getparam_t *param = data;
32708- int value;
32709+ int value = 0;
32710
32711 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
32712
32713diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
32714index 5ebe1b3..1ed9426 100644
32715--- a/drivers/gpu/drm/radeon/radeon_ttm.c
32716+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
32717@@ -822,8 +822,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
32718 }
32719 if (unlikely(ttm_vm_ops == NULL)) {
32720 ttm_vm_ops = vma->vm_ops;
32721- radeon_ttm_vm_ops = *ttm_vm_ops;
32722- radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
32723+ pax_open_kernel();
32724+ memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
32725+ *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
32726+ pax_close_kernel();
32727 }
32728 vma->vm_ops = &radeon_ttm_vm_ops;
32729 return 0;
32730diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
32731index 5706d2a..17aedaa 100644
32732--- a/drivers/gpu/drm/radeon/rs690.c
32733+++ b/drivers/gpu/drm/radeon/rs690.c
32734@@ -304,9 +304,11 @@ static void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
32735 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
32736 rdev->pm.sideport_bandwidth.full)
32737 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
32738- read_delay_latency.full = dfixed_const(370 * 800 * 1000);
32739+ read_delay_latency.full = dfixed_const(800 * 1000);
32740 read_delay_latency.full = dfixed_div(read_delay_latency,
32741 rdev->pm.igp_sideport_mclk);
32742+ a.full = dfixed_const(370);
32743+ read_delay_latency.full = dfixed_mul(read_delay_latency, a);
32744 } else {
32745 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
32746 rdev->pm.k8_bandwidth.full)
32747diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
32748index bd2a3b4..122d9ad 100644
32749--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
32750+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
32751@@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
32752 static int ttm_pool_mm_shrink(struct shrinker *shrink,
32753 struct shrink_control *sc)
32754 {
32755- static atomic_t start_pool = ATOMIC_INIT(0);
32756+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
32757 unsigned i;
32758- unsigned pool_offset = atomic_add_return(1, &start_pool);
32759+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
32760 struct ttm_page_pool *pool;
32761 int shrink_pages = sc->nr_to_scan;
32762
32763diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
32764index 893a650..6190d3b 100644
32765--- a/drivers/gpu/drm/via/via_drv.h
32766+++ b/drivers/gpu/drm/via/via_drv.h
32767@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
32768 typedef uint32_t maskarray_t[5];
32769
32770 typedef struct drm_via_irq {
32771- atomic_t irq_received;
32772+ atomic_unchecked_t irq_received;
32773 uint32_t pending_mask;
32774 uint32_t enable_mask;
32775 wait_queue_head_t irq_queue;
32776@@ -75,7 +75,7 @@ typedef struct drm_via_private {
32777 struct timeval last_vblank;
32778 int last_vblank_valid;
32779 unsigned usec_per_vblank;
32780- atomic_t vbl_received;
32781+ atomic_unchecked_t vbl_received;
32782 drm_via_state_t hc_state;
32783 char pci_buf[VIA_PCI_BUF_SIZE];
32784 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
32785diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
32786index ac98964..5dbf512 100644
32787--- a/drivers/gpu/drm/via/via_irq.c
32788+++ b/drivers/gpu/drm/via/via_irq.c
32789@@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
32790 if (crtc != 0)
32791 return 0;
32792
32793- return atomic_read(&dev_priv->vbl_received);
32794+ return atomic_read_unchecked(&dev_priv->vbl_received);
32795 }
32796
32797 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
32798@@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
32799
32800 status = VIA_READ(VIA_REG_INTERRUPT);
32801 if (status & VIA_IRQ_VBLANK_PENDING) {
32802- atomic_inc(&dev_priv->vbl_received);
32803- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
32804+ atomic_inc_unchecked(&dev_priv->vbl_received);
32805+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
32806 do_gettimeofday(&cur_vblank);
32807 if (dev_priv->last_vblank_valid) {
32808 dev_priv->usec_per_vblank =
32809@@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
32810 dev_priv->last_vblank = cur_vblank;
32811 dev_priv->last_vblank_valid = 1;
32812 }
32813- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
32814+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
32815 DRM_DEBUG("US per vblank is: %u\n",
32816 dev_priv->usec_per_vblank);
32817 }
32818@@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
32819
32820 for (i = 0; i < dev_priv->num_irqs; ++i) {
32821 if (status & cur_irq->pending_mask) {
32822- atomic_inc(&cur_irq->irq_received);
32823+ atomic_inc_unchecked(&cur_irq->irq_received);
32824 DRM_WAKEUP(&cur_irq->irq_queue);
32825 handled = 1;
32826 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
32827@@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
32828 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
32829 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
32830 masks[irq][4]));
32831- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
32832+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
32833 } else {
32834 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
32835 (((cur_irq_sequence =
32836- atomic_read(&cur_irq->irq_received)) -
32837+ atomic_read_unchecked(&cur_irq->irq_received)) -
32838 *sequence) <= (1 << 23)));
32839 }
32840 *sequence = cur_irq_sequence;
32841@@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
32842 }
32843
32844 for (i = 0; i < dev_priv->num_irqs; ++i) {
32845- atomic_set(&cur_irq->irq_received, 0);
32846+ atomic_set_unchecked(&cur_irq->irq_received, 0);
32847 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
32848 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
32849 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
32850@@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
32851 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
32852 case VIA_IRQ_RELATIVE:
32853 irqwait->request.sequence +=
32854- atomic_read(&cur_irq->irq_received);
32855+ atomic_read_unchecked(&cur_irq->irq_received);
32856 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
32857 case VIA_IRQ_ABSOLUTE:
32858 break;
32859diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
32860index 88a179e..cf13317 100644
32861--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
32862+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
32863@@ -263,7 +263,7 @@ struct vmw_private {
32864 * Fencing and IRQs.
32865 */
32866
32867- atomic_t marker_seq;
32868+ atomic_unchecked_t marker_seq;
32869 wait_queue_head_t fence_queue;
32870 wait_queue_head_t fifo_queue;
32871 int fence_queue_waiters; /* Protected by hw_mutex */
32872@@ -306,7 +306,7 @@ struct vmw_private {
32873
32874 struct vmw_master *active_master;
32875 struct vmw_master fbdev_master;
32876- struct notifier_block pm_nb;
32877+ notifier_block_no_const pm_nb;
32878 bool suspended;
32879
32880 struct mutex release_mutex;
32881diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
32882index 3eb1486..0a47ee9 100644
32883--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
32884+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
32885@@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
32886 (unsigned int) min,
32887 (unsigned int) fifo->capabilities);
32888
32889- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
32890+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
32891 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
32892 vmw_marker_queue_init(&fifo->marker_queue);
32893 return vmw_fifo_send_fence(dev_priv, &dummy);
32894@@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
32895 if (reserveable)
32896 iowrite32(bytes, fifo_mem +
32897 SVGA_FIFO_RESERVED);
32898- return fifo_mem + (next_cmd >> 2);
32899+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
32900 } else {
32901 need_bounce = true;
32902 }
32903@@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
32904
32905 fm = vmw_fifo_reserve(dev_priv, bytes);
32906 if (unlikely(fm == NULL)) {
32907- *seqno = atomic_read(&dev_priv->marker_seq);
32908+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
32909 ret = -ENOMEM;
32910 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
32911 false, 3*HZ);
32912@@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
32913 }
32914
32915 do {
32916- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
32917+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
32918 } while (*seqno == 0);
32919
32920 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
32921diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
32922index 4640adb..e1384ed 100644
32923--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
32924+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
32925@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
32926 * emitted. Then the fence is stale and signaled.
32927 */
32928
32929- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
32930+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
32931 > VMW_FENCE_WRAP);
32932
32933 return ret;
32934@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
32935
32936 if (fifo_idle)
32937 down_read(&fifo_state->rwsem);
32938- signal_seq = atomic_read(&dev_priv->marker_seq);
32939+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
32940 ret = 0;
32941
32942 for (;;) {
32943diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
32944index 8a8725c..afed796 100644
32945--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
32946+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
32947@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
32948 while (!vmw_lag_lt(queue, us)) {
32949 spin_lock(&queue->lock);
32950 if (list_empty(&queue->head))
32951- seqno = atomic_read(&dev_priv->marker_seq);
32952+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
32953 else {
32954 marker = list_first_entry(&queue->head,
32955 struct vmw_marker, head);
32956diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
32957index f4109fd..7c62889 100644
32958--- a/drivers/hid/hid-core.c
32959+++ b/drivers/hid/hid-core.c
32960@@ -2200,7 +2200,7 @@ static bool hid_ignore(struct hid_device *hdev)
32961
32962 int hid_add_device(struct hid_device *hdev)
32963 {
32964- static atomic_t id = ATOMIC_INIT(0);
32965+ static atomic_unchecked_t id = ATOMIC_INIT(0);
32966 int ret;
32967
32968 if (WARN_ON(hdev->status & HID_STAT_ADDED))
32969@@ -2235,7 +2235,7 @@ int hid_add_device(struct hid_device *hdev)
32970 /* XXX hack, any other cleaner solution after the driver core
32971 * is converted to allow more than 20 bytes as the device name? */
32972 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
32973- hdev->vendor, hdev->product, atomic_inc_return(&id));
32974+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
32975
32976 hid_debug_register(hdev, dev_name(&hdev->dev));
32977 ret = device_add(&hdev->dev);
32978diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
32979index eec3291..8ed706b 100644
32980--- a/drivers/hid/hid-wiimote-debug.c
32981+++ b/drivers/hid/hid-wiimote-debug.c
32982@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
32983 else if (size == 0)
32984 return -EIO;
32985
32986- if (copy_to_user(u, buf, size))
32987+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
32988 return -EFAULT;
32989
32990 *off += size;
32991diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
32992index 14599e2..711c965 100644
32993--- a/drivers/hid/usbhid/hiddev.c
32994+++ b/drivers/hid/usbhid/hiddev.c
32995@@ -625,7 +625,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
32996 break;
32997
32998 case HIDIOCAPPLICATION:
32999- if (arg < 0 || arg >= hid->maxapplication)
33000+ if (arg >= hid->maxapplication)
33001 break;
33002
33003 for (i = 0; i < hid->maxcollection; i++)
33004diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
33005index f4c3d28..82f45a9 100644
33006--- a/drivers/hv/channel.c
33007+++ b/drivers/hv/channel.c
33008@@ -402,8 +402,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
33009 int ret = 0;
33010 int t;
33011
33012- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
33013- atomic_inc(&vmbus_connection.next_gpadl_handle);
33014+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
33015+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
33016
33017 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
33018 if (ret)
33019diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
33020index 3648f8f..30ef30d 100644
33021--- a/drivers/hv/hv.c
33022+++ b/drivers/hv/hv.c
33023@@ -111,7 +111,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
33024 u64 output_address = (output) ? virt_to_phys(output) : 0;
33025 u32 output_address_hi = output_address >> 32;
33026 u32 output_address_lo = output_address & 0xFFFFFFFF;
33027- void *hypercall_page = hv_context.hypercall_page;
33028+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
33029
33030 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
33031 "=a"(hv_status_lo) : "d" (control_hi),
33032diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
33033index d8d1fad..b91caf7 100644
33034--- a/drivers/hv/hyperv_vmbus.h
33035+++ b/drivers/hv/hyperv_vmbus.h
33036@@ -594,7 +594,7 @@ enum vmbus_connect_state {
33037 struct vmbus_connection {
33038 enum vmbus_connect_state conn_state;
33039
33040- atomic_t next_gpadl_handle;
33041+ atomic_unchecked_t next_gpadl_handle;
33042
33043 /*
33044 * Represents channel interrupts. Each bit position represents a
33045diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
33046index 8e1a9ec..4687821 100644
33047--- a/drivers/hv/vmbus_drv.c
33048+++ b/drivers/hv/vmbus_drv.c
33049@@ -629,10 +629,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
33050 {
33051 int ret = 0;
33052
33053- static atomic_t device_num = ATOMIC_INIT(0);
33054+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
33055
33056 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
33057- atomic_inc_return(&device_num));
33058+ atomic_inc_return_unchecked(&device_num));
33059
33060 child_device_obj->device.bus = &hv_bus;
33061 child_device_obj->device.parent = &hv_acpi_dev->dev;
33062diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
33063index 07a0c1a..9fa531f 100644
33064--- a/drivers/hwmon/sht15.c
33065+++ b/drivers/hwmon/sht15.c
33066@@ -165,11 +165,11 @@ struct sht15_data {
33067 struct device *dev;
33068 struct device *hwmon_dev;
33069 struct regulator *reg;
33070- struct notifier_block nb;
33071+ notifier_block_no_const nb;
33072 int supply_uV;
33073 bool supply_uV_valid;
33074 struct work_struct update_supply_work;
33075- atomic_t interrupt_handled;
33076+ atomic_unchecked_t interrupt_handled;
33077 };
33078
33079 /**
33080@@ -512,13 +512,13 @@ static int sht15_measurement(struct sht15_data *data,
33081 return ret;
33082
33083 gpio_direction_input(data->pdata->gpio_data);
33084- atomic_set(&data->interrupt_handled, 0);
33085+ atomic_set_unchecked(&data->interrupt_handled, 0);
33086
33087 enable_irq(gpio_to_irq(data->pdata->gpio_data));
33088 if (gpio_get_value(data->pdata->gpio_data) == 0) {
33089 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
33090 /* Only relevant if the interrupt hasn't occurred. */
33091- if (!atomic_read(&data->interrupt_handled))
33092+ if (!atomic_read_unchecked(&data->interrupt_handled))
33093 schedule_work(&data->read_work);
33094 }
33095 ret = wait_event_timeout(data->wait_queue,
33096@@ -785,7 +785,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
33097
33098 /* First disable the interrupt */
33099 disable_irq_nosync(irq);
33100- atomic_inc(&data->interrupt_handled);
33101+ atomic_inc_unchecked(&data->interrupt_handled);
33102 /* Then schedule a reading work struct */
33103 if (data->state != SHT15_READING_NOTHING)
33104 schedule_work(&data->read_work);
33105@@ -807,11 +807,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
33106 * If not, then start the interrupt again - care here as could
33107 * have gone low in meantime so verify it hasn't!
33108 */
33109- atomic_set(&data->interrupt_handled, 0);
33110+ atomic_set_unchecked(&data->interrupt_handled, 0);
33111 enable_irq(gpio_to_irq(data->pdata->gpio_data));
33112 /* If still not occurred or another handler was scheduled */
33113 if (gpio_get_value(data->pdata->gpio_data)
33114- || atomic_read(&data->interrupt_handled))
33115+ || atomic_read_unchecked(&data->interrupt_handled))
33116 return;
33117 }
33118
33119diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
33120index 378fcb5..5e91fa8 100644
33121--- a/drivers/i2c/busses/i2c-amd756-s4882.c
33122+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
33123@@ -43,7 +43,7 @@
33124 extern struct i2c_adapter amd756_smbus;
33125
33126 static struct i2c_adapter *s4882_adapter;
33127-static struct i2c_algorithm *s4882_algo;
33128+static i2c_algorithm_no_const *s4882_algo;
33129
33130 /* Wrapper access functions for multiplexed SMBus */
33131 static DEFINE_MUTEX(amd756_lock);
33132diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
33133index 29015eb..af2d8e9 100644
33134--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
33135+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
33136@@ -41,7 +41,7 @@
33137 extern struct i2c_adapter *nforce2_smbus;
33138
33139 static struct i2c_adapter *s4985_adapter;
33140-static struct i2c_algorithm *s4985_algo;
33141+static i2c_algorithm_no_const *s4985_algo;
33142
33143 /* Wrapper access functions for multiplexed SMBus */
33144 static DEFINE_MUTEX(nforce2_lock);
33145diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
33146index d94e0ce..7055125 100644
33147--- a/drivers/i2c/i2c-mux.c
33148+++ b/drivers/i2c/i2c-mux.c
33149@@ -30,7 +30,7 @@
33150 /* multiplexer per channel data */
33151 struct i2c_mux_priv {
33152 struct i2c_adapter adap;
33153- struct i2c_algorithm algo;
33154+ i2c_algorithm_no_const algo;
33155
33156 struct i2c_adapter *parent;
33157 void *mux_priv; /* the mux chip/device */
33158diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
33159index 8126824..55a2798 100644
33160--- a/drivers/ide/ide-cd.c
33161+++ b/drivers/ide/ide-cd.c
33162@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
33163 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
33164 if ((unsigned long)buf & alignment
33165 || blk_rq_bytes(rq) & q->dma_pad_mask
33166- || object_is_on_stack(buf))
33167+ || object_starts_on_stack(buf))
33168 drive->dma = 0;
33169 }
33170 }
33171diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
33172index 394fea2..c833880 100644
33173--- a/drivers/infiniband/core/cm.c
33174+++ b/drivers/infiniband/core/cm.c
33175@@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
33176
33177 struct cm_counter_group {
33178 struct kobject obj;
33179- atomic_long_t counter[CM_ATTR_COUNT];
33180+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
33181 };
33182
33183 struct cm_counter_attribute {
33184@@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
33185 struct ib_mad_send_buf *msg = NULL;
33186 int ret;
33187
33188- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33189+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33190 counter[CM_REQ_COUNTER]);
33191
33192 /* Quick state check to discard duplicate REQs. */
33193@@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
33194 if (!cm_id_priv)
33195 return;
33196
33197- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33198+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33199 counter[CM_REP_COUNTER]);
33200 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
33201 if (ret)
33202@@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
33203 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
33204 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
33205 spin_unlock_irq(&cm_id_priv->lock);
33206- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33207+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33208 counter[CM_RTU_COUNTER]);
33209 goto out;
33210 }
33211@@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
33212 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
33213 dreq_msg->local_comm_id);
33214 if (!cm_id_priv) {
33215- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33216+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33217 counter[CM_DREQ_COUNTER]);
33218 cm_issue_drep(work->port, work->mad_recv_wc);
33219 return -EINVAL;
33220@@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
33221 case IB_CM_MRA_REP_RCVD:
33222 break;
33223 case IB_CM_TIMEWAIT:
33224- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33225+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33226 counter[CM_DREQ_COUNTER]);
33227 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
33228 goto unlock;
33229@@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
33230 cm_free_msg(msg);
33231 goto deref;
33232 case IB_CM_DREQ_RCVD:
33233- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33234+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33235 counter[CM_DREQ_COUNTER]);
33236 goto unlock;
33237 default:
33238@@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
33239 ib_modify_mad(cm_id_priv->av.port->mad_agent,
33240 cm_id_priv->msg, timeout)) {
33241 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
33242- atomic_long_inc(&work->port->
33243+ atomic_long_inc_unchecked(&work->port->
33244 counter_group[CM_RECV_DUPLICATES].
33245 counter[CM_MRA_COUNTER]);
33246 goto out;
33247@@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
33248 break;
33249 case IB_CM_MRA_REQ_RCVD:
33250 case IB_CM_MRA_REP_RCVD:
33251- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33252+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33253 counter[CM_MRA_COUNTER]);
33254 /* fall through */
33255 default:
33256@@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
33257 case IB_CM_LAP_IDLE:
33258 break;
33259 case IB_CM_MRA_LAP_SENT:
33260- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33261+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33262 counter[CM_LAP_COUNTER]);
33263 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
33264 goto unlock;
33265@@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
33266 cm_free_msg(msg);
33267 goto deref;
33268 case IB_CM_LAP_RCVD:
33269- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33270+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33271 counter[CM_LAP_COUNTER]);
33272 goto unlock;
33273 default:
33274@@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
33275 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
33276 if (cur_cm_id_priv) {
33277 spin_unlock_irq(&cm.lock);
33278- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33279+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33280 counter[CM_SIDR_REQ_COUNTER]);
33281 goto out; /* Duplicate message. */
33282 }
33283@@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
33284 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
33285 msg->retries = 1;
33286
33287- atomic_long_add(1 + msg->retries,
33288+ atomic_long_add_unchecked(1 + msg->retries,
33289 &port->counter_group[CM_XMIT].counter[attr_index]);
33290 if (msg->retries)
33291- atomic_long_add(msg->retries,
33292+ atomic_long_add_unchecked(msg->retries,
33293 &port->counter_group[CM_XMIT_RETRIES].
33294 counter[attr_index]);
33295
33296@@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
33297 }
33298
33299 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
33300- atomic_long_inc(&port->counter_group[CM_RECV].
33301+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
33302 counter[attr_id - CM_ATTR_ID_OFFSET]);
33303
33304 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
33305@@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
33306 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
33307
33308 return sprintf(buf, "%ld\n",
33309- atomic_long_read(&group->counter[cm_attr->index]));
33310+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
33311 }
33312
33313 static const struct sysfs_ops cm_counter_ops = {
33314diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
33315index 176c8f9..2627b62 100644
33316--- a/drivers/infiniband/core/fmr_pool.c
33317+++ b/drivers/infiniband/core/fmr_pool.c
33318@@ -98,8 +98,8 @@ struct ib_fmr_pool {
33319
33320 struct task_struct *thread;
33321
33322- atomic_t req_ser;
33323- atomic_t flush_ser;
33324+ atomic_unchecked_t req_ser;
33325+ atomic_unchecked_t flush_ser;
33326
33327 wait_queue_head_t force_wait;
33328 };
33329@@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
33330 struct ib_fmr_pool *pool = pool_ptr;
33331
33332 do {
33333- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
33334+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
33335 ib_fmr_batch_release(pool);
33336
33337- atomic_inc(&pool->flush_ser);
33338+ atomic_inc_unchecked(&pool->flush_ser);
33339 wake_up_interruptible(&pool->force_wait);
33340
33341 if (pool->flush_function)
33342@@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
33343 }
33344
33345 set_current_state(TASK_INTERRUPTIBLE);
33346- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
33347+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
33348 !kthread_should_stop())
33349 schedule();
33350 __set_current_state(TASK_RUNNING);
33351@@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
33352 pool->dirty_watermark = params->dirty_watermark;
33353 pool->dirty_len = 0;
33354 spin_lock_init(&pool->pool_lock);
33355- atomic_set(&pool->req_ser, 0);
33356- atomic_set(&pool->flush_ser, 0);
33357+ atomic_set_unchecked(&pool->req_ser, 0);
33358+ atomic_set_unchecked(&pool->flush_ser, 0);
33359 init_waitqueue_head(&pool->force_wait);
33360
33361 pool->thread = kthread_run(ib_fmr_cleanup_thread,
33362@@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
33363 }
33364 spin_unlock_irq(&pool->pool_lock);
33365
33366- serial = atomic_inc_return(&pool->req_ser);
33367+ serial = atomic_inc_return_unchecked(&pool->req_ser);
33368 wake_up_process(pool->thread);
33369
33370 if (wait_event_interruptible(pool->force_wait,
33371- atomic_read(&pool->flush_ser) - serial >= 0))
33372+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
33373 return -EINTR;
33374
33375 return 0;
33376@@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
33377 } else {
33378 list_add_tail(&fmr->list, &pool->dirty_list);
33379 if (++pool->dirty_len >= pool->dirty_watermark) {
33380- atomic_inc(&pool->req_ser);
33381+ atomic_inc_unchecked(&pool->req_ser);
33382 wake_up_process(pool->thread);
33383 }
33384 }
33385diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
33386index afd8179..598063f 100644
33387--- a/drivers/infiniband/hw/cxgb4/mem.c
33388+++ b/drivers/infiniband/hw/cxgb4/mem.c
33389@@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
33390 int err;
33391 struct fw_ri_tpte tpt;
33392 u32 stag_idx;
33393- static atomic_t key;
33394+ static atomic_unchecked_t key;
33395
33396 if (c4iw_fatal_error(rdev))
33397 return -EIO;
33398@@ -139,7 +139,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
33399 if (rdev->stats.stag.cur > rdev->stats.stag.max)
33400 rdev->stats.stag.max = rdev->stats.stag.cur;
33401 mutex_unlock(&rdev->stats.lock);
33402- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
33403+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
33404 }
33405 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
33406 __func__, stag_state, type, pdid, stag_idx);
33407diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
33408index 79b3dbc..96e5fcc 100644
33409--- a/drivers/infiniband/hw/ipath/ipath_rc.c
33410+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
33411@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
33412 struct ib_atomic_eth *ateth;
33413 struct ipath_ack_entry *e;
33414 u64 vaddr;
33415- atomic64_t *maddr;
33416+ atomic64_unchecked_t *maddr;
33417 u64 sdata;
33418 u32 rkey;
33419 u8 next;
33420@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
33421 IB_ACCESS_REMOTE_ATOMIC)))
33422 goto nack_acc_unlck;
33423 /* Perform atomic OP and save result. */
33424- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
33425+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
33426 sdata = be64_to_cpu(ateth->swap_data);
33427 e = &qp->s_ack_queue[qp->r_head_ack_queue];
33428 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
33429- (u64) atomic64_add_return(sdata, maddr) - sdata :
33430+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
33431 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
33432 be64_to_cpu(ateth->compare_data),
33433 sdata);
33434diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
33435index 1f95bba..9530f87 100644
33436--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
33437+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
33438@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
33439 unsigned long flags;
33440 struct ib_wc wc;
33441 u64 sdata;
33442- atomic64_t *maddr;
33443+ atomic64_unchecked_t *maddr;
33444 enum ib_wc_status send_status;
33445
33446 /*
33447@@ -382,11 +382,11 @@ again:
33448 IB_ACCESS_REMOTE_ATOMIC)))
33449 goto acc_err;
33450 /* Perform atomic OP and save result. */
33451- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
33452+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
33453 sdata = wqe->wr.wr.atomic.compare_add;
33454 *(u64 *) sqp->s_sge.sge.vaddr =
33455 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
33456- (u64) atomic64_add_return(sdata, maddr) - sdata :
33457+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
33458 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
33459 sdata, wqe->wr.wr.atomic.swap);
33460 goto send_comp;
33461diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
33462index e04cbc9..8c247a7 100644
33463--- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
33464+++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
33465@@ -416,7 +416,7 @@ struct mlx4_ib_sriov {
33466 struct mlx4_ib_iboe {
33467 spinlock_t lock;
33468 struct net_device *netdevs[MLX4_MAX_PORTS];
33469- struct notifier_block nb;
33470+ notifier_block_no_const nb;
33471 union ib_gid gid_table[MLX4_MAX_PORTS][128];
33472 };
33473
33474diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
33475index 748db2d..5f75cc3 100644
33476--- a/drivers/infiniband/hw/nes/nes.c
33477+++ b/drivers/infiniband/hw/nes/nes.c
33478@@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
33479 LIST_HEAD(nes_adapter_list);
33480 static LIST_HEAD(nes_dev_list);
33481
33482-atomic_t qps_destroyed;
33483+atomic_unchecked_t qps_destroyed;
33484
33485 static unsigned int ee_flsh_adapter;
33486 static unsigned int sysfs_nonidx_addr;
33487@@ -267,7 +267,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
33488 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
33489 struct nes_adapter *nesadapter = nesdev->nesadapter;
33490
33491- atomic_inc(&qps_destroyed);
33492+ atomic_inc_unchecked(&qps_destroyed);
33493
33494 /* Free the control structures */
33495
33496diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
33497index 5cac29e..c471744 100644
33498--- a/drivers/infiniband/hw/nes/nes.h
33499+++ b/drivers/infiniband/hw/nes/nes.h
33500@@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
33501 extern unsigned int wqm_quanta;
33502 extern struct list_head nes_adapter_list;
33503
33504-extern atomic_t cm_connects;
33505-extern atomic_t cm_accepts;
33506-extern atomic_t cm_disconnects;
33507-extern atomic_t cm_closes;
33508-extern atomic_t cm_connecteds;
33509-extern atomic_t cm_connect_reqs;
33510-extern atomic_t cm_rejects;
33511-extern atomic_t mod_qp_timouts;
33512-extern atomic_t qps_created;
33513-extern atomic_t qps_destroyed;
33514-extern atomic_t sw_qps_destroyed;
33515+extern atomic_unchecked_t cm_connects;
33516+extern atomic_unchecked_t cm_accepts;
33517+extern atomic_unchecked_t cm_disconnects;
33518+extern atomic_unchecked_t cm_closes;
33519+extern atomic_unchecked_t cm_connecteds;
33520+extern atomic_unchecked_t cm_connect_reqs;
33521+extern atomic_unchecked_t cm_rejects;
33522+extern atomic_unchecked_t mod_qp_timouts;
33523+extern atomic_unchecked_t qps_created;
33524+extern atomic_unchecked_t qps_destroyed;
33525+extern atomic_unchecked_t sw_qps_destroyed;
33526 extern u32 mh_detected;
33527 extern u32 mh_pauses_sent;
33528 extern u32 cm_packets_sent;
33529@@ -196,16 +196,16 @@ extern u32 cm_packets_created;
33530 extern u32 cm_packets_received;
33531 extern u32 cm_packets_dropped;
33532 extern u32 cm_packets_retrans;
33533-extern atomic_t cm_listens_created;
33534-extern atomic_t cm_listens_destroyed;
33535+extern atomic_unchecked_t cm_listens_created;
33536+extern atomic_unchecked_t cm_listens_destroyed;
33537 extern u32 cm_backlog_drops;
33538-extern atomic_t cm_loopbacks;
33539-extern atomic_t cm_nodes_created;
33540-extern atomic_t cm_nodes_destroyed;
33541-extern atomic_t cm_accel_dropped_pkts;
33542-extern atomic_t cm_resets_recvd;
33543-extern atomic_t pau_qps_created;
33544-extern atomic_t pau_qps_destroyed;
33545+extern atomic_unchecked_t cm_loopbacks;
33546+extern atomic_unchecked_t cm_nodes_created;
33547+extern atomic_unchecked_t cm_nodes_destroyed;
33548+extern atomic_unchecked_t cm_accel_dropped_pkts;
33549+extern atomic_unchecked_t cm_resets_recvd;
33550+extern atomic_unchecked_t pau_qps_created;
33551+extern atomic_unchecked_t pau_qps_destroyed;
33552
33553 extern u32 int_mod_timer_init;
33554 extern u32 int_mod_cq_depth_256;
33555diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
33556index cfaacaf..fa0722e 100644
33557--- a/drivers/infiniband/hw/nes/nes_cm.c
33558+++ b/drivers/infiniband/hw/nes/nes_cm.c
33559@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
33560 u32 cm_packets_retrans;
33561 u32 cm_packets_created;
33562 u32 cm_packets_received;
33563-atomic_t cm_listens_created;
33564-atomic_t cm_listens_destroyed;
33565+atomic_unchecked_t cm_listens_created;
33566+atomic_unchecked_t cm_listens_destroyed;
33567 u32 cm_backlog_drops;
33568-atomic_t cm_loopbacks;
33569-atomic_t cm_nodes_created;
33570-atomic_t cm_nodes_destroyed;
33571-atomic_t cm_accel_dropped_pkts;
33572-atomic_t cm_resets_recvd;
33573+atomic_unchecked_t cm_loopbacks;
33574+atomic_unchecked_t cm_nodes_created;
33575+atomic_unchecked_t cm_nodes_destroyed;
33576+atomic_unchecked_t cm_accel_dropped_pkts;
33577+atomic_unchecked_t cm_resets_recvd;
33578
33579 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
33580 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
33581@@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
33582
33583 static struct nes_cm_core *g_cm_core;
33584
33585-atomic_t cm_connects;
33586-atomic_t cm_accepts;
33587-atomic_t cm_disconnects;
33588-atomic_t cm_closes;
33589-atomic_t cm_connecteds;
33590-atomic_t cm_connect_reqs;
33591-atomic_t cm_rejects;
33592+atomic_unchecked_t cm_connects;
33593+atomic_unchecked_t cm_accepts;
33594+atomic_unchecked_t cm_disconnects;
33595+atomic_unchecked_t cm_closes;
33596+atomic_unchecked_t cm_connecteds;
33597+atomic_unchecked_t cm_connect_reqs;
33598+atomic_unchecked_t cm_rejects;
33599
33600 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
33601 {
33602@@ -1281,7 +1281,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
33603 kfree(listener);
33604 listener = NULL;
33605 ret = 0;
33606- atomic_inc(&cm_listens_destroyed);
33607+ atomic_inc_unchecked(&cm_listens_destroyed);
33608 } else {
33609 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
33610 }
33611@@ -1480,7 +1480,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
33612 cm_node->rem_mac);
33613
33614 add_hte_node(cm_core, cm_node);
33615- atomic_inc(&cm_nodes_created);
33616+ atomic_inc_unchecked(&cm_nodes_created);
33617
33618 return cm_node;
33619 }
33620@@ -1538,7 +1538,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
33621 }
33622
33623 atomic_dec(&cm_core->node_cnt);
33624- atomic_inc(&cm_nodes_destroyed);
33625+ atomic_inc_unchecked(&cm_nodes_destroyed);
33626 nesqp = cm_node->nesqp;
33627 if (nesqp) {
33628 nesqp->cm_node = NULL;
33629@@ -1602,7 +1602,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
33630
33631 static void drop_packet(struct sk_buff *skb)
33632 {
33633- atomic_inc(&cm_accel_dropped_pkts);
33634+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
33635 dev_kfree_skb_any(skb);
33636 }
33637
33638@@ -1665,7 +1665,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
33639 {
33640
33641 int reset = 0; /* whether to send reset in case of err.. */
33642- atomic_inc(&cm_resets_recvd);
33643+ atomic_inc_unchecked(&cm_resets_recvd);
33644 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
33645 " refcnt=%d\n", cm_node, cm_node->state,
33646 atomic_read(&cm_node->ref_count));
33647@@ -2306,7 +2306,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
33648 rem_ref_cm_node(cm_node->cm_core, cm_node);
33649 return NULL;
33650 }
33651- atomic_inc(&cm_loopbacks);
33652+ atomic_inc_unchecked(&cm_loopbacks);
33653 loopbackremotenode->loopbackpartner = cm_node;
33654 loopbackremotenode->tcp_cntxt.rcv_wscale =
33655 NES_CM_DEFAULT_RCV_WND_SCALE;
33656@@ -2581,7 +2581,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
33657 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
33658 else {
33659 rem_ref_cm_node(cm_core, cm_node);
33660- atomic_inc(&cm_accel_dropped_pkts);
33661+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
33662 dev_kfree_skb_any(skb);
33663 }
33664 break;
33665@@ -2889,7 +2889,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
33666
33667 if ((cm_id) && (cm_id->event_handler)) {
33668 if (issue_disconn) {
33669- atomic_inc(&cm_disconnects);
33670+ atomic_inc_unchecked(&cm_disconnects);
33671 cm_event.event = IW_CM_EVENT_DISCONNECT;
33672 cm_event.status = disconn_status;
33673 cm_event.local_addr = cm_id->local_addr;
33674@@ -2911,7 +2911,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
33675 }
33676
33677 if (issue_close) {
33678- atomic_inc(&cm_closes);
33679+ atomic_inc_unchecked(&cm_closes);
33680 nes_disconnect(nesqp, 1);
33681
33682 cm_id->provider_data = nesqp;
33683@@ -3047,7 +3047,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
33684
33685 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
33686 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
33687- atomic_inc(&cm_accepts);
33688+ atomic_inc_unchecked(&cm_accepts);
33689
33690 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
33691 netdev_refcnt_read(nesvnic->netdev));
33692@@ -3242,7 +3242,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
33693 struct nes_cm_core *cm_core;
33694 u8 *start_buff;
33695
33696- atomic_inc(&cm_rejects);
33697+ atomic_inc_unchecked(&cm_rejects);
33698 cm_node = (struct nes_cm_node *)cm_id->provider_data;
33699 loopback = cm_node->loopbackpartner;
33700 cm_core = cm_node->cm_core;
33701@@ -3302,7 +3302,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
33702 ntohl(cm_id->local_addr.sin_addr.s_addr),
33703 ntohs(cm_id->local_addr.sin_port));
33704
33705- atomic_inc(&cm_connects);
33706+ atomic_inc_unchecked(&cm_connects);
33707 nesqp->active_conn = 1;
33708
33709 /* cache the cm_id in the qp */
33710@@ -3412,7 +3412,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
33711 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
33712 return err;
33713 }
33714- atomic_inc(&cm_listens_created);
33715+ atomic_inc_unchecked(&cm_listens_created);
33716 }
33717
33718 cm_id->add_ref(cm_id);
33719@@ -3513,7 +3513,7 @@ static void cm_event_connected(struct nes_cm_event *event)
33720
33721 if (nesqp->destroyed)
33722 return;
33723- atomic_inc(&cm_connecteds);
33724+ atomic_inc_unchecked(&cm_connecteds);
33725 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
33726 " local port 0x%04X. jiffies = %lu.\n",
33727 nesqp->hwqp.qp_id,
33728@@ -3693,7 +3693,7 @@ static void cm_event_reset(struct nes_cm_event *event)
33729
33730 cm_id->add_ref(cm_id);
33731 ret = cm_id->event_handler(cm_id, &cm_event);
33732- atomic_inc(&cm_closes);
33733+ atomic_inc_unchecked(&cm_closes);
33734 cm_event.event = IW_CM_EVENT_CLOSE;
33735 cm_event.status = 0;
33736 cm_event.provider_data = cm_id->provider_data;
33737@@ -3729,7 +3729,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
33738 return;
33739 cm_id = cm_node->cm_id;
33740
33741- atomic_inc(&cm_connect_reqs);
33742+ atomic_inc_unchecked(&cm_connect_reqs);
33743 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
33744 cm_node, cm_id, jiffies);
33745
33746@@ -3769,7 +3769,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
33747 return;
33748 cm_id = cm_node->cm_id;
33749
33750- atomic_inc(&cm_connect_reqs);
33751+ atomic_inc_unchecked(&cm_connect_reqs);
33752 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
33753 cm_node, cm_id, jiffies);
33754
33755diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
33756index 3ba7be3..c81f6ff 100644
33757--- a/drivers/infiniband/hw/nes/nes_mgt.c
33758+++ b/drivers/infiniband/hw/nes/nes_mgt.c
33759@@ -40,8 +40,8 @@
33760 #include "nes.h"
33761 #include "nes_mgt.h"
33762
33763-atomic_t pau_qps_created;
33764-atomic_t pau_qps_destroyed;
33765+atomic_unchecked_t pau_qps_created;
33766+atomic_unchecked_t pau_qps_destroyed;
33767
33768 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
33769 {
33770@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
33771 {
33772 struct sk_buff *skb;
33773 unsigned long flags;
33774- atomic_inc(&pau_qps_destroyed);
33775+ atomic_inc_unchecked(&pau_qps_destroyed);
33776
33777 /* Free packets that have not yet been forwarded */
33778 /* Lock is acquired by skb_dequeue when removing the skb */
33779@@ -812,7 +812,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
33780 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
33781 skb_queue_head_init(&nesqp->pau_list);
33782 spin_lock_init(&nesqp->pau_lock);
33783- atomic_inc(&pau_qps_created);
33784+ atomic_inc_unchecked(&pau_qps_created);
33785 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
33786 }
33787
33788diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
33789index 0564be7..f68b0f1 100644
33790--- a/drivers/infiniband/hw/nes/nes_nic.c
33791+++ b/drivers/infiniband/hw/nes/nes_nic.c
33792@@ -1272,39 +1272,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
33793 target_stat_values[++index] = mh_detected;
33794 target_stat_values[++index] = mh_pauses_sent;
33795 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
33796- target_stat_values[++index] = atomic_read(&cm_connects);
33797- target_stat_values[++index] = atomic_read(&cm_accepts);
33798- target_stat_values[++index] = atomic_read(&cm_disconnects);
33799- target_stat_values[++index] = atomic_read(&cm_connecteds);
33800- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
33801- target_stat_values[++index] = atomic_read(&cm_rejects);
33802- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
33803- target_stat_values[++index] = atomic_read(&qps_created);
33804- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
33805- target_stat_values[++index] = atomic_read(&qps_destroyed);
33806- target_stat_values[++index] = atomic_read(&cm_closes);
33807+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
33808+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
33809+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
33810+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
33811+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
33812+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
33813+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
33814+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
33815+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
33816+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
33817+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
33818 target_stat_values[++index] = cm_packets_sent;
33819 target_stat_values[++index] = cm_packets_bounced;
33820 target_stat_values[++index] = cm_packets_created;
33821 target_stat_values[++index] = cm_packets_received;
33822 target_stat_values[++index] = cm_packets_dropped;
33823 target_stat_values[++index] = cm_packets_retrans;
33824- target_stat_values[++index] = atomic_read(&cm_listens_created);
33825- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
33826+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
33827+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
33828 target_stat_values[++index] = cm_backlog_drops;
33829- target_stat_values[++index] = atomic_read(&cm_loopbacks);
33830- target_stat_values[++index] = atomic_read(&cm_nodes_created);
33831- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
33832- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
33833- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
33834+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
33835+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
33836+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
33837+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
33838+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
33839 target_stat_values[++index] = nesadapter->free_4kpbl;
33840 target_stat_values[++index] = nesadapter->free_256pbl;
33841 target_stat_values[++index] = int_mod_timer_init;
33842 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
33843 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
33844 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
33845- target_stat_values[++index] = atomic_read(&pau_qps_created);
33846- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
33847+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
33848+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
33849 }
33850
33851 /**
33852diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
33853index cd0ecb2..7099ff0 100644
33854--- a/drivers/infiniband/hw/nes/nes_verbs.c
33855+++ b/drivers/infiniband/hw/nes/nes_verbs.c
33856@@ -46,9 +46,9 @@
33857
33858 #include <rdma/ib_umem.h>
33859
33860-atomic_t mod_qp_timouts;
33861-atomic_t qps_created;
33862-atomic_t sw_qps_destroyed;
33863+atomic_unchecked_t mod_qp_timouts;
33864+atomic_unchecked_t qps_created;
33865+atomic_unchecked_t sw_qps_destroyed;
33866
33867 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
33868
33869@@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
33870 if (init_attr->create_flags)
33871 return ERR_PTR(-EINVAL);
33872
33873- atomic_inc(&qps_created);
33874+ atomic_inc_unchecked(&qps_created);
33875 switch (init_attr->qp_type) {
33876 case IB_QPT_RC:
33877 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
33878@@ -1460,7 +1460,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
33879 struct iw_cm_event cm_event;
33880 int ret = 0;
33881
33882- atomic_inc(&sw_qps_destroyed);
33883+ atomic_inc_unchecked(&sw_qps_destroyed);
33884 nesqp->destroyed = 1;
33885
33886 /* Blow away the connection if it exists. */
33887diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
33888index 4d11575..3e890e5 100644
33889--- a/drivers/infiniband/hw/qib/qib.h
33890+++ b/drivers/infiniband/hw/qib/qib.h
33891@@ -51,6 +51,7 @@
33892 #include <linux/completion.h>
33893 #include <linux/kref.h>
33894 #include <linux/sched.h>
33895+#include <linux/slab.h>
33896
33897 #include "qib_common.h"
33898 #include "qib_verbs.h"
33899diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
33900index da739d9..da1c7f4 100644
33901--- a/drivers/input/gameport/gameport.c
33902+++ b/drivers/input/gameport/gameport.c
33903@@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
33904 */
33905 static void gameport_init_port(struct gameport *gameport)
33906 {
33907- static atomic_t gameport_no = ATOMIC_INIT(0);
33908+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
33909
33910 __module_get(THIS_MODULE);
33911
33912 mutex_init(&gameport->drv_mutex);
33913 device_initialize(&gameport->dev);
33914 dev_set_name(&gameport->dev, "gameport%lu",
33915- (unsigned long)atomic_inc_return(&gameport_no) - 1);
33916+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
33917 gameport->dev.bus = &gameport_bus;
33918 gameport->dev.release = gameport_release_port;
33919 if (gameport->parent)
33920diff --git a/drivers/input/input.c b/drivers/input/input.c
33921index 53a0dde..abffda7 100644
33922--- a/drivers/input/input.c
33923+++ b/drivers/input/input.c
33924@@ -1902,7 +1902,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
33925 */
33926 int input_register_device(struct input_dev *dev)
33927 {
33928- static atomic_t input_no = ATOMIC_INIT(0);
33929+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
33930 struct input_handler *handler;
33931 unsigned int packet_size;
33932 const char *path;
33933@@ -1945,7 +1945,7 @@ int input_register_device(struct input_dev *dev)
33934 dev->setkeycode = input_default_setkeycode;
33935
33936 dev_set_name(&dev->dev, "input%ld",
33937- (unsigned long) atomic_inc_return(&input_no) - 1);
33938+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
33939
33940 error = device_add(&dev->dev);
33941 if (error)
33942diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
33943index 04c69af..5f92d00 100644
33944--- a/drivers/input/joystick/sidewinder.c
33945+++ b/drivers/input/joystick/sidewinder.c
33946@@ -30,6 +30,7 @@
33947 #include <linux/kernel.h>
33948 #include <linux/module.h>
33949 #include <linux/slab.h>
33950+#include <linux/sched.h>
33951 #include <linux/init.h>
33952 #include <linux/input.h>
33953 #include <linux/gameport.h>
33954diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
33955index 83811e4..0822b90 100644
33956--- a/drivers/input/joystick/xpad.c
33957+++ b/drivers/input/joystick/xpad.c
33958@@ -726,7 +726,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
33959
33960 static int xpad_led_probe(struct usb_xpad *xpad)
33961 {
33962- static atomic_t led_seq = ATOMIC_INIT(0);
33963+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
33964 long led_no;
33965 struct xpad_led *led;
33966 struct led_classdev *led_cdev;
33967@@ -739,7 +739,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
33968 if (!led)
33969 return -ENOMEM;
33970
33971- led_no = (long)atomic_inc_return(&led_seq) - 1;
33972+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
33973
33974 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
33975 led->xpad = xpad;
33976diff --git a/drivers/input/keyboard/adp5520-keys.c b/drivers/input/keyboard/adp5520-keys.c
33977index e9e8674..f098622 100644
33978--- a/drivers/input/keyboard/adp5520-keys.c
33979+++ b/drivers/input/keyboard/adp5520-keys.c
33980@@ -16,7 +16,7 @@
33981
33982 struct adp5520_keys {
33983 struct input_dev *input;
33984- struct notifier_block notifier;
33985+ notifier_block_no_const notifier;
33986 struct device *master;
33987 unsigned short keycode[ADP5520_KEYMAPSIZE];
33988 };
33989diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
33990index 4c842c3..590b0bf 100644
33991--- a/drivers/input/mousedev.c
33992+++ b/drivers/input/mousedev.c
33993@@ -738,7 +738,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
33994
33995 spin_unlock_irq(&client->packet_lock);
33996
33997- if (copy_to_user(buffer, data, count))
33998+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
33999 return -EFAULT;
34000
34001 return count;
34002diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
34003index d0f7533..fb8215b 100644
34004--- a/drivers/input/serio/serio.c
34005+++ b/drivers/input/serio/serio.c
34006@@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
34007 */
34008 static void serio_init_port(struct serio *serio)
34009 {
34010- static atomic_t serio_no = ATOMIC_INIT(0);
34011+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
34012
34013 __module_get(THIS_MODULE);
34014
34015@@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
34016 mutex_init(&serio->drv_mutex);
34017 device_initialize(&serio->dev);
34018 dev_set_name(&serio->dev, "serio%ld",
34019- (long)atomic_inc_return(&serio_no) - 1);
34020+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
34021 serio->dev.bus = &serio_bus;
34022 serio->dev.release = serio_release_port;
34023 serio->dev.groups = serio_device_attr_groups;
34024diff --git a/drivers/input/touchscreen/da9034-ts.c b/drivers/input/touchscreen/da9034-ts.c
34025index 36b65cf..6fbd367 100644
34026--- a/drivers/input/touchscreen/da9034-ts.c
34027+++ b/drivers/input/touchscreen/da9034-ts.c
34028@@ -55,7 +55,7 @@ struct da9034_touch {
34029 struct input_dev *input_dev;
34030
34031 struct delayed_work tsi_work;
34032- struct notifier_block notifier;
34033+ notifier_block_no_const notifier;
34034
34035 int state;
34036
34037diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
34038index c679867..6e2e34d 100644
34039--- a/drivers/isdn/capi/capi.c
34040+++ b/drivers/isdn/capi/capi.c
34041@@ -83,8 +83,8 @@ struct capiminor {
34042
34043 struct capi20_appl *ap;
34044 u32 ncci;
34045- atomic_t datahandle;
34046- atomic_t msgid;
34047+ atomic_unchecked_t datahandle;
34048+ atomic_unchecked_t msgid;
34049
34050 struct tty_port port;
34051 int ttyinstop;
34052@@ -393,7 +393,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
34053 capimsg_setu16(s, 2, mp->ap->applid);
34054 capimsg_setu8 (s, 4, CAPI_DATA_B3);
34055 capimsg_setu8 (s, 5, CAPI_RESP);
34056- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
34057+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
34058 capimsg_setu32(s, 8, mp->ncci);
34059 capimsg_setu16(s, 12, datahandle);
34060 }
34061@@ -514,14 +514,14 @@ static void handle_minor_send(struct capiminor *mp)
34062 mp->outbytes -= len;
34063 spin_unlock_bh(&mp->outlock);
34064
34065- datahandle = atomic_inc_return(&mp->datahandle);
34066+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
34067 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
34068 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
34069 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
34070 capimsg_setu16(skb->data, 2, mp->ap->applid);
34071 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
34072 capimsg_setu8 (skb->data, 5, CAPI_REQ);
34073- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
34074+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
34075 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
34076 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
34077 capimsg_setu16(skb->data, 16, len); /* Data length */
34078diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
34079index 67abf3f..076b3a6 100644
34080--- a/drivers/isdn/gigaset/interface.c
34081+++ b/drivers/isdn/gigaset/interface.c
34082@@ -160,9 +160,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
34083 }
34084 tty->driver_data = cs;
34085
34086- ++cs->port.count;
34087+ atomic_inc(&cs->port.count);
34088
34089- if (cs->port.count == 1) {
34090+ if (atomic_read(&cs->port.count) == 1) {
34091 tty_port_tty_set(&cs->port, tty);
34092 tty->low_latency = 1;
34093 }
34094@@ -186,9 +186,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
34095
34096 if (!cs->connected)
34097 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
34098- else if (!cs->port.count)
34099+ else if (!atomic_read(&cs->port.count))
34100 dev_warn(cs->dev, "%s: device not opened\n", __func__);
34101- else if (!--cs->port.count)
34102+ else if (!atomic_dec_return(&cs->port.count))
34103 tty_port_tty_set(&cs->port, NULL);
34104
34105 mutex_unlock(&cs->mutex);
34106diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
34107index 821f7ac..28d4030 100644
34108--- a/drivers/isdn/hardware/avm/b1.c
34109+++ b/drivers/isdn/hardware/avm/b1.c
34110@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
34111 }
34112 if (left) {
34113 if (t4file->user) {
34114- if (copy_from_user(buf, dp, left))
34115+ if (left > sizeof buf || copy_from_user(buf, dp, left))
34116 return -EFAULT;
34117 } else {
34118 memcpy(buf, dp, left);
34119@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
34120 }
34121 if (left) {
34122 if (config->user) {
34123- if (copy_from_user(buf, dp, left))
34124+ if (left > sizeof buf || copy_from_user(buf, dp, left))
34125 return -EFAULT;
34126 } else {
34127 memcpy(buf, dp, left);
34128diff --git a/drivers/isdn/hardware/eicon/divasync.h b/drivers/isdn/hardware/eicon/divasync.h
34129index dd6b53a..19d9ee6 100644
34130--- a/drivers/isdn/hardware/eicon/divasync.h
34131+++ b/drivers/isdn/hardware/eicon/divasync.h
34132@@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
34133 } diva_didd_add_adapter_t;
34134 typedef struct _diva_didd_remove_adapter {
34135 IDI_CALL p_request;
34136-} diva_didd_remove_adapter_t;
34137+} __no_const diva_didd_remove_adapter_t;
34138 typedef struct _diva_didd_read_adapter_array {
34139 void *buffer;
34140 dword length;
34141diff --git a/drivers/isdn/hardware/eicon/xdi_adapter.h b/drivers/isdn/hardware/eicon/xdi_adapter.h
34142index d303e65..28bcb7b 100644
34143--- a/drivers/isdn/hardware/eicon/xdi_adapter.h
34144+++ b/drivers/isdn/hardware/eicon/xdi_adapter.h
34145@@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
34146 typedef struct _diva_os_idi_adapter_interface {
34147 diva_init_card_proc_t cleanup_adapter_proc;
34148 diva_cmd_card_proc_t cmd_proc;
34149-} diva_os_idi_adapter_interface_t;
34150+} __no_const diva_os_idi_adapter_interface_t;
34151
34152 typedef struct _diva_os_xdi_adapter {
34153 struct list_head link;
34154diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
34155index b817809..409caff 100644
34156--- a/drivers/isdn/i4l/isdn_tty.c
34157+++ b/drivers/isdn/i4l/isdn_tty.c
34158@@ -1513,9 +1513,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
34159
34160 #ifdef ISDN_DEBUG_MODEM_OPEN
34161 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
34162- port->count);
34163+ atomic_read(&port->count));
34164 #endif
34165- port->count++;
34166+ atomic_inc(&port->count);
34167 port->tty = tty;
34168 /*
34169 * Start up serial port
34170@@ -1559,7 +1559,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
34171 #endif
34172 return;
34173 }
34174- if ((tty->count == 1) && (port->count != 1)) {
34175+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
34176 /*
34177 * Uh, oh. tty->count is 1, which means that the tty
34178 * structure will be freed. Info->count should always
34179@@ -1568,15 +1568,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
34180 * serial port won't be shutdown.
34181 */
34182 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
34183- "info->count is %d\n", port->count);
34184- port->count = 1;
34185+ "info->count is %d\n", atomic_read(&port->count));
34186+ atomic_set(&port->count, 1);
34187 }
34188- if (--port->count < 0) {
34189+ if (atomic_dec_return(&port->count) < 0) {
34190 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
34191- info->line, port->count);
34192- port->count = 0;
34193+ info->line, atomic_read(&port->count));
34194+ atomic_set(&port->count, 0);
34195 }
34196- if (port->count) {
34197+ if (atomic_read(&port->count)) {
34198 #ifdef ISDN_DEBUG_MODEM_OPEN
34199 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
34200 #endif
34201@@ -1630,7 +1630,7 @@ isdn_tty_hangup(struct tty_struct *tty)
34202 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
34203 return;
34204 isdn_tty_shutdown(info);
34205- port->count = 0;
34206+ atomic_set(&port->count, 0);
34207 port->flags &= ~ASYNC_NORMAL_ACTIVE;
34208 port->tty = NULL;
34209 wake_up_interruptible(&port->open_wait);
34210@@ -1971,7 +1971,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
34211 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
34212 modem_info *info = &dev->mdm.info[i];
34213
34214- if (info->port.count == 0)
34215+ if (atomic_read(&info->port.count) == 0)
34216 continue;
34217 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
34218 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
34219diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
34220index e74df7c..03a03ba 100644
34221--- a/drivers/isdn/icn/icn.c
34222+++ b/drivers/isdn/icn/icn.c
34223@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
34224 if (count > len)
34225 count = len;
34226 if (user) {
34227- if (copy_from_user(msg, buf, count))
34228+ if (count > sizeof msg || copy_from_user(msg, buf, count))
34229 return -EFAULT;
34230 } else
34231 memcpy(msg, buf, count);
34232diff --git a/drivers/leds/ledtrig-backlight.c b/drivers/leds/ledtrig-backlight.c
34233index b941685..f7e816b 100644
34234--- a/drivers/leds/ledtrig-backlight.c
34235+++ b/drivers/leds/ledtrig-backlight.c
34236@@ -25,7 +25,7 @@ struct bl_trig_notifier {
34237 struct led_classdev *led;
34238 int brightness;
34239 int old_status;
34240- struct notifier_block notifier;
34241+ notifier_block_no_const notifier;
34242 unsigned invert;
34243 };
34244
34245diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
34246index b5fdcb7..5b6c59f 100644
34247--- a/drivers/lguest/core.c
34248+++ b/drivers/lguest/core.c
34249@@ -92,9 +92,17 @@ static __init int map_switcher(void)
34250 * it's worked so far. The end address needs +1 because __get_vm_area
34251 * allocates an extra guard page, so we need space for that.
34252 */
34253+
34254+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
34255+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
34256+ VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
34257+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
34258+#else
34259 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
34260 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
34261 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
34262+#endif
34263+
34264 if (!switcher_vma) {
34265 err = -ENOMEM;
34266 printk("lguest: could not map switcher pages high\n");
34267@@ -119,7 +127,7 @@ static __init int map_switcher(void)
34268 * Now the Switcher is mapped at the right address, we can't fail!
34269 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
34270 */
34271- memcpy(switcher_vma->addr, start_switcher_text,
34272+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
34273 end_switcher_text - start_switcher_text);
34274
34275 printk(KERN_INFO "lguest: mapped switcher at %p\n",
34276diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
34277index 4af12e1..0e89afe 100644
34278--- a/drivers/lguest/x86/core.c
34279+++ b/drivers/lguest/x86/core.c
34280@@ -59,7 +59,7 @@ static struct {
34281 /* Offset from where switcher.S was compiled to where we've copied it */
34282 static unsigned long switcher_offset(void)
34283 {
34284- return SWITCHER_ADDR - (unsigned long)start_switcher_text;
34285+ return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
34286 }
34287
34288 /* This cpu's struct lguest_pages. */
34289@@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
34290 * These copies are pretty cheap, so we do them unconditionally: */
34291 /* Save the current Host top-level page directory.
34292 */
34293+
34294+#ifdef CONFIG_PAX_PER_CPU_PGD
34295+ pages->state.host_cr3 = read_cr3();
34296+#else
34297 pages->state.host_cr3 = __pa(current->mm->pgd);
34298+#endif
34299+
34300 /*
34301 * Set up the Guest's page tables to see this CPU's pages (and no
34302 * other CPU's pages).
34303@@ -476,7 +482,7 @@ void __init lguest_arch_host_init(void)
34304 * compiled-in switcher code and the high-mapped copy we just made.
34305 */
34306 for (i = 0; i < IDT_ENTRIES; i++)
34307- default_idt_entries[i] += switcher_offset();
34308+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
34309
34310 /*
34311 * Set up the Switcher's per-cpu areas.
34312@@ -559,7 +565,7 @@ void __init lguest_arch_host_init(void)
34313 * it will be undisturbed when we switch. To change %cs and jump we
34314 * need this structure to feed to Intel's "lcall" instruction.
34315 */
34316- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
34317+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
34318 lguest_entry.segment = LGUEST_CS;
34319
34320 /*
34321diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
34322index 40634b0..4f5855e 100644
34323--- a/drivers/lguest/x86/switcher_32.S
34324+++ b/drivers/lguest/x86/switcher_32.S
34325@@ -87,6 +87,7 @@
34326 #include <asm/page.h>
34327 #include <asm/segment.h>
34328 #include <asm/lguest.h>
34329+#include <asm/processor-flags.h>
34330
34331 // We mark the start of the code to copy
34332 // It's placed in .text tho it's never run here
34333@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
34334 // Changes type when we load it: damn Intel!
34335 // For after we switch over our page tables
34336 // That entry will be read-only: we'd crash.
34337+
34338+#ifdef CONFIG_PAX_KERNEXEC
34339+ mov %cr0, %edx
34340+ xor $X86_CR0_WP, %edx
34341+ mov %edx, %cr0
34342+#endif
34343+
34344 movl $(GDT_ENTRY_TSS*8), %edx
34345 ltr %dx
34346
34347@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
34348 // Let's clear it again for our return.
34349 // The GDT descriptor of the Host
34350 // Points to the table after two "size" bytes
34351- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
34352+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
34353 // Clear "used" from type field (byte 5, bit 2)
34354- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
34355+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
34356+
34357+#ifdef CONFIG_PAX_KERNEXEC
34358+ mov %cr0, %eax
34359+ xor $X86_CR0_WP, %eax
34360+ mov %eax, %cr0
34361+#endif
34362
34363 // Once our page table's switched, the Guest is live!
34364 // The Host fades as we run this final step.
34365@@ -295,13 +309,12 @@ deliver_to_host:
34366 // I consulted gcc, and it gave
34367 // These instructions, which I gladly credit:
34368 leal (%edx,%ebx,8), %eax
34369- movzwl (%eax),%edx
34370- movl 4(%eax), %eax
34371- xorw %ax, %ax
34372- orl %eax, %edx
34373+ movl 4(%eax), %edx
34374+ movw (%eax), %dx
34375 // Now the address of the handler's in %edx
34376 // We call it now: its "iret" drops us home.
34377- jmp *%edx
34378+ ljmp $__KERNEL_CS, $1f
34379+1: jmp *%edx
34380
34381 // Every interrupt can come to us here
34382 // But we must truly tell each apart.
34383diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
34384index 7155945..4bcc562 100644
34385--- a/drivers/md/bitmap.c
34386+++ b/drivers/md/bitmap.c
34387@@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
34388 chunk_kb ? "KB" : "B");
34389 if (bitmap->storage.file) {
34390 seq_printf(seq, ", file: ");
34391- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
34392+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
34393 }
34394
34395 seq_printf(seq, "\n");
34396diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
34397index afd9598..528d8f9 100644
34398--- a/drivers/md/dm-ioctl.c
34399+++ b/drivers/md/dm-ioctl.c
34400@@ -1593,7 +1593,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
34401 cmd == DM_LIST_VERSIONS_CMD)
34402 return 0;
34403
34404- if ((cmd == DM_DEV_CREATE_CMD)) {
34405+ if (cmd == DM_DEV_CREATE_CMD) {
34406 if (!*param->name) {
34407 DMWARN("name not supplied when creating device");
34408 return -EINVAL;
34409diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
34410index fd61f98..8050783 100644
34411--- a/drivers/md/dm-raid1.c
34412+++ b/drivers/md/dm-raid1.c
34413@@ -40,7 +40,7 @@ enum dm_raid1_error {
34414
34415 struct mirror {
34416 struct mirror_set *ms;
34417- atomic_t error_count;
34418+ atomic_unchecked_t error_count;
34419 unsigned long error_type;
34420 struct dm_dev *dev;
34421 sector_t offset;
34422@@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
34423 struct mirror *m;
34424
34425 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
34426- if (!atomic_read(&m->error_count))
34427+ if (!atomic_read_unchecked(&m->error_count))
34428 return m;
34429
34430 return NULL;
34431@@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
34432 * simple way to tell if a device has encountered
34433 * errors.
34434 */
34435- atomic_inc(&m->error_count);
34436+ atomic_inc_unchecked(&m->error_count);
34437
34438 if (test_and_set_bit(error_type, &m->error_type))
34439 return;
34440@@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
34441 struct mirror *m = get_default_mirror(ms);
34442
34443 do {
34444- if (likely(!atomic_read(&m->error_count)))
34445+ if (likely(!atomic_read_unchecked(&m->error_count)))
34446 return m;
34447
34448 if (m-- == ms->mirror)
34449@@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
34450 {
34451 struct mirror *default_mirror = get_default_mirror(m->ms);
34452
34453- return !atomic_read(&default_mirror->error_count);
34454+ return !atomic_read_unchecked(&default_mirror->error_count);
34455 }
34456
34457 static int mirror_available(struct mirror_set *ms, struct bio *bio)
34458@@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
34459 */
34460 if (likely(region_in_sync(ms, region, 1)))
34461 m = choose_mirror(ms, bio->bi_sector);
34462- else if (m && atomic_read(&m->error_count))
34463+ else if (m && atomic_read_unchecked(&m->error_count))
34464 m = NULL;
34465
34466 if (likely(m))
34467@@ -938,7 +938,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
34468 }
34469
34470 ms->mirror[mirror].ms = ms;
34471- atomic_set(&(ms->mirror[mirror].error_count), 0);
34472+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
34473 ms->mirror[mirror].error_type = 0;
34474 ms->mirror[mirror].offset = offset;
34475
34476@@ -1356,7 +1356,7 @@ static void mirror_resume(struct dm_target *ti)
34477 */
34478 static char device_status_char(struct mirror *m)
34479 {
34480- if (!atomic_read(&(m->error_count)))
34481+ if (!atomic_read_unchecked(&(m->error_count)))
34482 return 'A';
34483
34484 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
34485diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
34486index e2f87653..f279abe 100644
34487--- a/drivers/md/dm-stripe.c
34488+++ b/drivers/md/dm-stripe.c
34489@@ -20,7 +20,7 @@ struct stripe {
34490 struct dm_dev *dev;
34491 sector_t physical_start;
34492
34493- atomic_t error_count;
34494+ atomic_unchecked_t error_count;
34495 };
34496
34497 struct stripe_c {
34498@@ -183,7 +183,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
34499 kfree(sc);
34500 return r;
34501 }
34502- atomic_set(&(sc->stripe[i].error_count), 0);
34503+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
34504 }
34505
34506 ti->private = sc;
34507@@ -324,7 +324,7 @@ static int stripe_status(struct dm_target *ti, status_type_t type,
34508 DMEMIT("%d ", sc->stripes);
34509 for (i = 0; i < sc->stripes; i++) {
34510 DMEMIT("%s ", sc->stripe[i].dev->name);
34511- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
34512+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
34513 'D' : 'A';
34514 }
34515 buffer[i] = '\0';
34516@@ -371,8 +371,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
34517 */
34518 for (i = 0; i < sc->stripes; i++)
34519 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
34520- atomic_inc(&(sc->stripe[i].error_count));
34521- if (atomic_read(&(sc->stripe[i].error_count)) <
34522+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
34523+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
34524 DM_IO_ERROR_THRESHOLD)
34525 schedule_work(&sc->trigger_event);
34526 }
34527diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
34528index 100368e..64262ce 100644
34529--- a/drivers/md/dm-table.c
34530+++ b/drivers/md/dm-table.c
34531@@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
34532 if (!dev_size)
34533 return 0;
34534
34535- if ((start >= dev_size) || (start + len > dev_size)) {
34536+ if ((start >= dev_size) || (len > dev_size - start)) {
34537 DMWARN("%s: %s too small for target: "
34538 "start=%llu, len=%llu, dev_size=%llu",
34539 dm_device_name(ti->table->md), bdevname(bdev, b),
34540diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
34541index 693e149..b7e0fde 100644
34542--- a/drivers/md/dm-thin-metadata.c
34543+++ b/drivers/md/dm-thin-metadata.c
34544@@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
34545 {
34546 pmd->info.tm = pmd->tm;
34547 pmd->info.levels = 2;
34548- pmd->info.value_type.context = pmd->data_sm;
34549+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
34550 pmd->info.value_type.size = sizeof(__le64);
34551 pmd->info.value_type.inc = data_block_inc;
34552 pmd->info.value_type.dec = data_block_dec;
34553@@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
34554
34555 pmd->bl_info.tm = pmd->tm;
34556 pmd->bl_info.levels = 1;
34557- pmd->bl_info.value_type.context = pmd->data_sm;
34558+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
34559 pmd->bl_info.value_type.size = sizeof(__le64);
34560 pmd->bl_info.value_type.inc = data_block_inc;
34561 pmd->bl_info.value_type.dec = data_block_dec;
34562diff --git a/drivers/md/dm.c b/drivers/md/dm.c
34563index 77e6eff..913d695 100644
34564--- a/drivers/md/dm.c
34565+++ b/drivers/md/dm.c
34566@@ -182,9 +182,9 @@ struct mapped_device {
34567 /*
34568 * Event handling.
34569 */
34570- atomic_t event_nr;
34571+ atomic_unchecked_t event_nr;
34572 wait_queue_head_t eventq;
34573- atomic_t uevent_seq;
34574+ atomic_unchecked_t uevent_seq;
34575 struct list_head uevent_list;
34576 spinlock_t uevent_lock; /* Protect access to uevent_list */
34577
34578@@ -1847,8 +1847,8 @@ static struct mapped_device *alloc_dev(int minor)
34579 rwlock_init(&md->map_lock);
34580 atomic_set(&md->holders, 1);
34581 atomic_set(&md->open_count, 0);
34582- atomic_set(&md->event_nr, 0);
34583- atomic_set(&md->uevent_seq, 0);
34584+ atomic_set_unchecked(&md->event_nr, 0);
34585+ atomic_set_unchecked(&md->uevent_seq, 0);
34586 INIT_LIST_HEAD(&md->uevent_list);
34587 spin_lock_init(&md->uevent_lock);
34588
34589@@ -1982,7 +1982,7 @@ static void event_callback(void *context)
34590
34591 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
34592
34593- atomic_inc(&md->event_nr);
34594+ atomic_inc_unchecked(&md->event_nr);
34595 wake_up(&md->eventq);
34596 }
34597
34598@@ -2637,18 +2637,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
34599
34600 uint32_t dm_next_uevent_seq(struct mapped_device *md)
34601 {
34602- return atomic_add_return(1, &md->uevent_seq);
34603+ return atomic_add_return_unchecked(1, &md->uevent_seq);
34604 }
34605
34606 uint32_t dm_get_event_nr(struct mapped_device *md)
34607 {
34608- return atomic_read(&md->event_nr);
34609+ return atomic_read_unchecked(&md->event_nr);
34610 }
34611
34612 int dm_wait_event(struct mapped_device *md, int event_nr)
34613 {
34614 return wait_event_interruptible(md->eventq,
34615- (event_nr != atomic_read(&md->event_nr)));
34616+ (event_nr != atomic_read_unchecked(&md->event_nr)));
34617 }
34618
34619 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
34620diff --git a/drivers/md/md.c b/drivers/md/md.c
34621index 6120071..31d9be2 100644
34622--- a/drivers/md/md.c
34623+++ b/drivers/md/md.c
34624@@ -240,10 +240,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
34625 * start build, activate spare
34626 */
34627 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
34628-static atomic_t md_event_count;
34629+static atomic_unchecked_t md_event_count;
34630 void md_new_event(struct mddev *mddev)
34631 {
34632- atomic_inc(&md_event_count);
34633+ atomic_inc_unchecked(&md_event_count);
34634 wake_up(&md_event_waiters);
34635 }
34636 EXPORT_SYMBOL_GPL(md_new_event);
34637@@ -253,7 +253,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
34638 */
34639 static void md_new_event_inintr(struct mddev *mddev)
34640 {
34641- atomic_inc(&md_event_count);
34642+ atomic_inc_unchecked(&md_event_count);
34643 wake_up(&md_event_waiters);
34644 }
34645
34646@@ -1504,7 +1504,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
34647 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
34648 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
34649 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
34650- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
34651+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
34652
34653 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
34654 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
34655@@ -1748,7 +1748,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
34656 else
34657 sb->resync_offset = cpu_to_le64(0);
34658
34659- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
34660+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
34661
34662 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
34663 sb->size = cpu_to_le64(mddev->dev_sectors);
34664@@ -2748,7 +2748,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
34665 static ssize_t
34666 errors_show(struct md_rdev *rdev, char *page)
34667 {
34668- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
34669+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
34670 }
34671
34672 static ssize_t
34673@@ -2757,7 +2757,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
34674 char *e;
34675 unsigned long n = simple_strtoul(buf, &e, 10);
34676 if (*buf && (*e == 0 || *e == '\n')) {
34677- atomic_set(&rdev->corrected_errors, n);
34678+ atomic_set_unchecked(&rdev->corrected_errors, n);
34679 return len;
34680 }
34681 return -EINVAL;
34682@@ -3204,8 +3204,8 @@ int md_rdev_init(struct md_rdev *rdev)
34683 rdev->sb_loaded = 0;
34684 rdev->bb_page = NULL;
34685 atomic_set(&rdev->nr_pending, 0);
34686- atomic_set(&rdev->read_errors, 0);
34687- atomic_set(&rdev->corrected_errors, 0);
34688+ atomic_set_unchecked(&rdev->read_errors, 0);
34689+ atomic_set_unchecked(&rdev->corrected_errors, 0);
34690
34691 INIT_LIST_HEAD(&rdev->same_set);
34692 init_waitqueue_head(&rdev->blocked_wait);
34693@@ -6984,7 +6984,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
34694
34695 spin_unlock(&pers_lock);
34696 seq_printf(seq, "\n");
34697- seq->poll_event = atomic_read(&md_event_count);
34698+ seq->poll_event = atomic_read_unchecked(&md_event_count);
34699 return 0;
34700 }
34701 if (v == (void*)2) {
34702@@ -7087,7 +7087,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
34703 return error;
34704
34705 seq = file->private_data;
34706- seq->poll_event = atomic_read(&md_event_count);
34707+ seq->poll_event = atomic_read_unchecked(&md_event_count);
34708 return error;
34709 }
34710
34711@@ -7101,7 +7101,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
34712 /* always allow read */
34713 mask = POLLIN | POLLRDNORM;
34714
34715- if (seq->poll_event != atomic_read(&md_event_count))
34716+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
34717 mask |= POLLERR | POLLPRI;
34718 return mask;
34719 }
34720@@ -7145,7 +7145,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
34721 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
34722 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
34723 (int)part_stat_read(&disk->part0, sectors[1]) -
34724- atomic_read(&disk->sync_io);
34725+ atomic_read_unchecked(&disk->sync_io);
34726 /* sync IO will cause sync_io to increase before the disk_stats
34727 * as sync_io is counted when a request starts, and
34728 * disk_stats is counted when it completes.
34729diff --git a/drivers/md/md.h b/drivers/md/md.h
34730index af443ab..0f93be3 100644
34731--- a/drivers/md/md.h
34732+++ b/drivers/md/md.h
34733@@ -94,13 +94,13 @@ struct md_rdev {
34734 * only maintained for arrays that
34735 * support hot removal
34736 */
34737- atomic_t read_errors; /* number of consecutive read errors that
34738+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
34739 * we have tried to ignore.
34740 */
34741 struct timespec last_read_error; /* monotonic time since our
34742 * last read error
34743 */
34744- atomic_t corrected_errors; /* number of corrected read errors,
34745+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
34746 * for reporting to userspace and storing
34747 * in superblock.
34748 */
34749@@ -432,7 +432,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
34750
34751 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
34752 {
34753- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
34754+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
34755 }
34756
34757 struct md_personality
34758diff --git a/drivers/md/persistent-data/dm-space-map-disk.c b/drivers/md/persistent-data/dm-space-map-disk.c
34759index f6d29e6..7917f5e 100644
34760--- a/drivers/md/persistent-data/dm-space-map-disk.c
34761+++ b/drivers/md/persistent-data/dm-space-map-disk.c
34762@@ -22,7 +22,7 @@
34763 * Space map interface.
34764 */
34765 struct sm_disk {
34766- struct dm_space_map sm;
34767+ dm_space_map_no_const sm;
34768
34769 struct ll_disk ll;
34770 struct ll_disk old_ll;
34771diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
34772index e89ae5e..062e4c2 100644
34773--- a/drivers/md/persistent-data/dm-space-map-metadata.c
34774+++ b/drivers/md/persistent-data/dm-space-map-metadata.c
34775@@ -43,7 +43,7 @@ struct block_op {
34776 };
34777
34778 struct sm_metadata {
34779- struct dm_space_map sm;
34780+ dm_space_map_no_const sm;
34781
34782 struct ll_disk ll;
34783 struct ll_disk old_ll;
34784diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
34785index 1cbfc6b..56e1dbb 100644
34786--- a/drivers/md/persistent-data/dm-space-map.h
34787+++ b/drivers/md/persistent-data/dm-space-map.h
34788@@ -60,6 +60,7 @@ struct dm_space_map {
34789 int (*root_size)(struct dm_space_map *sm, size_t *result);
34790 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
34791 };
34792+typedef struct dm_space_map __no_const dm_space_map_no_const;
34793
34794 /*----------------------------------------------------------------*/
34795
34796diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
34797index a0f7309..5599dbc 100644
34798--- a/drivers/md/raid1.c
34799+++ b/drivers/md/raid1.c
34800@@ -1819,7 +1819,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
34801 if (r1_sync_page_io(rdev, sect, s,
34802 bio->bi_io_vec[idx].bv_page,
34803 READ) != 0)
34804- atomic_add(s, &rdev->corrected_errors);
34805+ atomic_add_unchecked(s, &rdev->corrected_errors);
34806 }
34807 sectors -= s;
34808 sect += s;
34809@@ -2041,7 +2041,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
34810 test_bit(In_sync, &rdev->flags)) {
34811 if (r1_sync_page_io(rdev, sect, s,
34812 conf->tmppage, READ)) {
34813- atomic_add(s, &rdev->corrected_errors);
34814+ atomic_add_unchecked(s, &rdev->corrected_errors);
34815 printk(KERN_INFO
34816 "md/raid1:%s: read error corrected "
34817 "(%d sectors at %llu on %s)\n",
34818diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
34819index c9acbd7..386cd3e 100644
34820--- a/drivers/md/raid10.c
34821+++ b/drivers/md/raid10.c
34822@@ -1878,7 +1878,7 @@ static void end_sync_read(struct bio *bio, int error)
34823 /* The write handler will notice the lack of
34824 * R10BIO_Uptodate and record any errors etc
34825 */
34826- atomic_add(r10_bio->sectors,
34827+ atomic_add_unchecked(r10_bio->sectors,
34828 &conf->mirrors[d].rdev->corrected_errors);
34829
34830 /* for reconstruct, we always reschedule after a read.
34831@@ -2227,7 +2227,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
34832 {
34833 struct timespec cur_time_mon;
34834 unsigned long hours_since_last;
34835- unsigned int read_errors = atomic_read(&rdev->read_errors);
34836+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
34837
34838 ktime_get_ts(&cur_time_mon);
34839
34840@@ -2249,9 +2249,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
34841 * overflowing the shift of read_errors by hours_since_last.
34842 */
34843 if (hours_since_last >= 8 * sizeof(read_errors))
34844- atomic_set(&rdev->read_errors, 0);
34845+ atomic_set_unchecked(&rdev->read_errors, 0);
34846 else
34847- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
34848+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
34849 }
34850
34851 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
34852@@ -2305,8 +2305,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
34853 return;
34854
34855 check_decay_read_errors(mddev, rdev);
34856- atomic_inc(&rdev->read_errors);
34857- if (atomic_read(&rdev->read_errors) > max_read_errors) {
34858+ atomic_inc_unchecked(&rdev->read_errors);
34859+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
34860 char b[BDEVNAME_SIZE];
34861 bdevname(rdev->bdev, b);
34862
34863@@ -2314,7 +2314,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
34864 "md/raid10:%s: %s: Raid device exceeded "
34865 "read_error threshold [cur %d:max %d]\n",
34866 mdname(mddev), b,
34867- atomic_read(&rdev->read_errors), max_read_errors);
34868+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
34869 printk(KERN_NOTICE
34870 "md/raid10:%s: %s: Failing raid device\n",
34871 mdname(mddev), b);
34872@@ -2469,7 +2469,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
34873 sect +
34874 choose_data_offset(r10_bio, rdev)),
34875 bdevname(rdev->bdev, b));
34876- atomic_add(s, &rdev->corrected_errors);
34877+ atomic_add_unchecked(s, &rdev->corrected_errors);
34878 }
34879
34880 rdev_dec_pending(rdev, mddev);
34881diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
34882index a450268..c4168a9 100644
34883--- a/drivers/md/raid5.c
34884+++ b/drivers/md/raid5.c
34885@@ -1789,21 +1789,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
34886 mdname(conf->mddev), STRIPE_SECTORS,
34887 (unsigned long long)s,
34888 bdevname(rdev->bdev, b));
34889- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
34890+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
34891 clear_bit(R5_ReadError, &sh->dev[i].flags);
34892 clear_bit(R5_ReWrite, &sh->dev[i].flags);
34893 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
34894 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
34895
34896- if (atomic_read(&rdev->read_errors))
34897- atomic_set(&rdev->read_errors, 0);
34898+ if (atomic_read_unchecked(&rdev->read_errors))
34899+ atomic_set_unchecked(&rdev->read_errors, 0);
34900 } else {
34901 const char *bdn = bdevname(rdev->bdev, b);
34902 int retry = 0;
34903 int set_bad = 0;
34904
34905 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
34906- atomic_inc(&rdev->read_errors);
34907+ atomic_inc_unchecked(&rdev->read_errors);
34908 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
34909 printk_ratelimited(
34910 KERN_WARNING
34911@@ -1831,7 +1831,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
34912 mdname(conf->mddev),
34913 (unsigned long long)s,
34914 bdn);
34915- } else if (atomic_read(&rdev->read_errors)
34916+ } else if (atomic_read_unchecked(&rdev->read_errors)
34917 > conf->max_nr_stripes)
34918 printk(KERN_WARNING
34919 "md/raid:%s: Too many read errors, failing device %s.\n",
34920diff --git a/drivers/md/raid5.h b/drivers/md/raid5.h
34921index 18b2c4a..3d7d59f 100644
34922--- a/drivers/md/raid5.h
34923+++ b/drivers/md/raid5.h
34924@@ -439,7 +439,7 @@ struct r5conf {
34925 * cpu hotplug while reshaping
34926 */
34927 #ifdef CONFIG_HOTPLUG_CPU
34928- struct notifier_block cpu_notify;
34929+ notifier_block_no_const cpu_notify;
34930 #endif
34931
34932 /*
34933diff --git a/drivers/media/dvb-core/dvb_demux.h b/drivers/media/dvb-core/dvb_demux.h
34934index fa7188a..04a045e 100644
34935--- a/drivers/media/dvb-core/dvb_demux.h
34936+++ b/drivers/media/dvb-core/dvb_demux.h
34937@@ -73,7 +73,7 @@ struct dvb_demux_feed {
34938 union {
34939 dmx_ts_cb ts;
34940 dmx_section_cb sec;
34941- } cb;
34942+ } __no_const cb;
34943
34944 struct dvb_demux *demux;
34945 void *priv;
34946diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
34947index d33101a..6b13069 100644
34948--- a/drivers/media/dvb-core/dvbdev.c
34949+++ b/drivers/media/dvb-core/dvbdev.c
34950@@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
34951 const struct dvb_device *template, void *priv, int type)
34952 {
34953 struct dvb_device *dvbdev;
34954- struct file_operations *dvbdevfops;
34955+ file_operations_no_const *dvbdevfops;
34956 struct device *clsdev;
34957 int minor;
34958 int id;
34959diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
34960index 404f63a..4796533 100644
34961--- a/drivers/media/dvb-frontends/dib3000.h
34962+++ b/drivers/media/dvb-frontends/dib3000.h
34963@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
34964 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
34965 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
34966 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
34967-};
34968+} __no_const;
34969
34970 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
34971 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
34972diff --git a/drivers/media/pci/cx88/cx88-alsa.c b/drivers/media/pci/cx88/cx88-alsa.c
34973index 3aa6856..435ad25 100644
34974--- a/drivers/media/pci/cx88/cx88-alsa.c
34975+++ b/drivers/media/pci/cx88/cx88-alsa.c
34976@@ -749,7 +749,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
34977 * Only boards with eeprom and byte 1 at eeprom=1 have it
34978 */
34979
34980-static const struct pci_device_id cx88_audio_pci_tbl[] __devinitdata = {
34981+static const struct pci_device_id cx88_audio_pci_tbl[] __devinitconst = {
34982 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
34983 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
34984 {0, }
34985diff --git a/drivers/media/pci/ddbridge/ddbridge-core.c b/drivers/media/pci/ddbridge/ddbridge-core.c
34986index feff57e..66a2c67 100644
34987--- a/drivers/media/pci/ddbridge/ddbridge-core.c
34988+++ b/drivers/media/pci/ddbridge/ddbridge-core.c
34989@@ -1679,7 +1679,7 @@ static struct ddb_info ddb_v6 = {
34990 .subvendor = _subvend, .subdevice = _subdev, \
34991 .driver_data = (unsigned long)&_driverdata }
34992
34993-static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
34994+static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
34995 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
34996 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
34997 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
34998diff --git a/drivers/media/pci/ngene/ngene-cards.c b/drivers/media/pci/ngene/ngene-cards.c
34999index 96a13ed..6df45b4 100644
35000--- a/drivers/media/pci/ngene/ngene-cards.c
35001+++ b/drivers/media/pci/ngene/ngene-cards.c
35002@@ -741,7 +741,7 @@ static struct ngene_info ngene_info_terratec = {
35003
35004 /****************************************************************************/
35005
35006-static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
35007+static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
35008 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
35009 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
35010 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
35011diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
35012index a3b1a34..71ce0e3 100644
35013--- a/drivers/media/platform/omap/omap_vout.c
35014+++ b/drivers/media/platform/omap/omap_vout.c
35015@@ -65,7 +65,6 @@ enum omap_vout_channels {
35016 OMAP_VIDEO2,
35017 };
35018
35019-static struct videobuf_queue_ops video_vbq_ops;
35020 /* Variables configurable through module params*/
35021 static u32 video1_numbuffers = 3;
35022 static u32 video2_numbuffers = 3;
35023@@ -1012,6 +1011,12 @@ static int omap_vout_open(struct file *file)
35024 {
35025 struct videobuf_queue *q;
35026 struct omap_vout_device *vout = NULL;
35027+ static struct videobuf_queue_ops video_vbq_ops = {
35028+ .buf_setup = omap_vout_buffer_setup,
35029+ .buf_prepare = omap_vout_buffer_prepare,
35030+ .buf_release = omap_vout_buffer_release,
35031+ .buf_queue = omap_vout_buffer_queue,
35032+ };
35033
35034 vout = video_drvdata(file);
35035 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
35036@@ -1029,10 +1034,6 @@ static int omap_vout_open(struct file *file)
35037 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
35038
35039 q = &vout->vbq;
35040- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
35041- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
35042- video_vbq_ops.buf_release = omap_vout_buffer_release;
35043- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
35044 spin_lock_init(&vout->vbq_lock);
35045
35046 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
35047diff --git a/drivers/media/platform/timblogiw.c b/drivers/media/platform/timblogiw.c
35048index 02194c0..091733b 100644
35049--- a/drivers/media/platform/timblogiw.c
35050+++ b/drivers/media/platform/timblogiw.c
35051@@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
35052
35053 /* Platform device functions */
35054
35055-static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
35056+static __devinitconst v4l2_ioctl_ops_no_const timblogiw_ioctl_ops = {
35057 .vidioc_querycap = timblogiw_querycap,
35058 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
35059 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
35060@@ -767,7 +767,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
35061 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
35062 };
35063
35064-static __devinitconst struct v4l2_file_operations timblogiw_fops = {
35065+static __devinitconst v4l2_file_operations_no_const timblogiw_fops = {
35066 .owner = THIS_MODULE,
35067 .open = timblogiw_open,
35068 .release = timblogiw_close,
35069diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
35070index 697a421..16c5a5f 100644
35071--- a/drivers/media/radio/radio-cadet.c
35072+++ b/drivers/media/radio/radio-cadet.c
35073@@ -302,6 +302,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
35074 unsigned char readbuf[RDS_BUFFER];
35075 int i = 0;
35076
35077+ if (count > RDS_BUFFER)
35078+ return -EFAULT;
35079 mutex_lock(&dev->lock);
35080 if (dev->rdsstat == 0)
35081 cadet_start_rds(dev);
35082@@ -317,7 +319,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
35083 while (i < count && dev->rdsin != dev->rdsout)
35084 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
35085
35086- if (i && copy_to_user(data, readbuf, i))
35087+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
35088 i = -EFAULT;
35089 unlock:
35090 mutex_unlock(&dev->lock);
35091diff --git a/drivers/media/radio/radio-tea5777.h b/drivers/media/radio/radio-tea5777.h
35092index 4ea43a9..66f4a8f 100644
35093--- a/drivers/media/radio/radio-tea5777.h
35094+++ b/drivers/media/radio/radio-tea5777.h
35095@@ -63,7 +63,7 @@ struct radio_tea5777_ops {
35096
35097 struct radio_tea5777 {
35098 struct v4l2_device *v4l2_dev;
35099- struct v4l2_file_operations fops;
35100+ v4l2_file_operations_no_const fops;
35101 struct video_device vd; /* video device */
35102 bool has_am; /* Device can tune to AM freqs */
35103 bool write_before_read; /* must write before read quirk */
35104diff --git a/drivers/media/usb/au0828/au0828.h b/drivers/media/usb/au0828/au0828.h
35105index 66a56ef..d139911 100644
35106--- a/drivers/media/usb/au0828/au0828.h
35107+++ b/drivers/media/usb/au0828/au0828.h
35108@@ -191,7 +191,7 @@ struct au0828_dev {
35109
35110 /* I2C */
35111 struct i2c_adapter i2c_adap;
35112- struct i2c_algorithm i2c_algo;
35113+ i2c_algorithm_no_const i2c_algo;
35114 struct i2c_client i2c_client;
35115 u32 i2c_rc;
35116
35117diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
35118index 3940bb0..fb3952a 100644
35119--- a/drivers/media/usb/dvb-usb/cxusb.c
35120+++ b/drivers/media/usb/dvb-usb/cxusb.c
35121@@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
35122
35123 struct dib0700_adapter_state {
35124 int (*set_param_save) (struct dvb_frontend *);
35125-};
35126+} __no_const;
35127
35128 static int dib7070_set_param_override(struct dvb_frontend *fe)
35129 {
35130diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
35131index 9382895..ac8093c 100644
35132--- a/drivers/media/usb/dvb-usb/dw2102.c
35133+++ b/drivers/media/usb/dvb-usb/dw2102.c
35134@@ -95,7 +95,7 @@ struct su3000_state {
35135
35136 struct s6x0_state {
35137 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
35138-};
35139+} __no_const;
35140
35141 /* debug */
35142 static int dvb_usb_dw2102_debug;
35143diff --git a/drivers/media/usb/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/usb/pvrusb2/pvrusb2-hdw-internal.h
35144index 036952f..80d356d 100644
35145--- a/drivers/media/usb/pvrusb2/pvrusb2-hdw-internal.h
35146+++ b/drivers/media/usb/pvrusb2/pvrusb2-hdw-internal.h
35147@@ -196,7 +196,7 @@ struct pvr2_hdw {
35148
35149 /* I2C stuff */
35150 struct i2c_adapter i2c_adap;
35151- struct i2c_algorithm i2c_algo;
35152+ i2c_algorithm_no_const i2c_algo;
35153 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
35154 int i2c_cx25840_hack_state;
35155 int i2c_linked;
35156diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
35157index fb69baa..cf7ad22 100644
35158--- a/drivers/message/fusion/mptbase.c
35159+++ b/drivers/message/fusion/mptbase.c
35160@@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
35161 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
35162 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
35163
35164+#ifdef CONFIG_GRKERNSEC_HIDESYM
35165+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
35166+#else
35167 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
35168 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
35169+#endif
35170+
35171 /*
35172 * Rounding UP to nearest 4-kB boundary here...
35173 */
35174diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
35175index 551262e..7551198 100644
35176--- a/drivers/message/fusion/mptsas.c
35177+++ b/drivers/message/fusion/mptsas.c
35178@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
35179 return 0;
35180 }
35181
35182+static inline void
35183+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
35184+{
35185+ if (phy_info->port_details) {
35186+ phy_info->port_details->rphy = rphy;
35187+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
35188+ ioc->name, rphy));
35189+ }
35190+
35191+ if (rphy) {
35192+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
35193+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
35194+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
35195+ ioc->name, rphy, rphy->dev.release));
35196+ }
35197+}
35198+
35199 /* no mutex */
35200 static void
35201 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
35202@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
35203 return NULL;
35204 }
35205
35206-static inline void
35207-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
35208-{
35209- if (phy_info->port_details) {
35210- phy_info->port_details->rphy = rphy;
35211- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
35212- ioc->name, rphy));
35213- }
35214-
35215- if (rphy) {
35216- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
35217- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
35218- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
35219- ioc->name, rphy, rphy->dev.release));
35220- }
35221-}
35222-
35223 static inline struct sas_port *
35224 mptsas_get_port(struct mptsas_phyinfo *phy_info)
35225 {
35226diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
35227index 0c3ced7..1fe34ec 100644
35228--- a/drivers/message/fusion/mptscsih.c
35229+++ b/drivers/message/fusion/mptscsih.c
35230@@ -1270,15 +1270,16 @@ mptscsih_info(struct Scsi_Host *SChost)
35231
35232 h = shost_priv(SChost);
35233
35234- if (h) {
35235- if (h->info_kbuf == NULL)
35236- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
35237- return h->info_kbuf;
35238- h->info_kbuf[0] = '\0';
35239+ if (!h)
35240+ return NULL;
35241
35242- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
35243- h->info_kbuf[size-1] = '\0';
35244- }
35245+ if (h->info_kbuf == NULL)
35246+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
35247+ return h->info_kbuf;
35248+ h->info_kbuf[0] = '\0';
35249+
35250+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
35251+ h->info_kbuf[size-1] = '\0';
35252
35253 return h->info_kbuf;
35254 }
35255diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
35256index 8001aa6..b137580 100644
35257--- a/drivers/message/i2o/i2o_proc.c
35258+++ b/drivers/message/i2o/i2o_proc.c
35259@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
35260 "Array Controller Device"
35261 };
35262
35263-static char *chtostr(char *tmp, u8 *chars, int n)
35264-{
35265- tmp[0] = 0;
35266- return strncat(tmp, (char *)chars, n);
35267-}
35268-
35269 static int i2o_report_query_status(struct seq_file *seq, int block_status,
35270 char *group)
35271 {
35272@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
35273 } *result;
35274
35275 i2o_exec_execute_ddm_table ddm_table;
35276- char tmp[28 + 1];
35277
35278 result = kmalloc(sizeof(*result), GFP_KERNEL);
35279 if (!result)
35280@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
35281
35282 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
35283 seq_printf(seq, "%-#8x", ddm_table.module_id);
35284- seq_printf(seq, "%-29s",
35285- chtostr(tmp, ddm_table.module_name_version, 28));
35286+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
35287 seq_printf(seq, "%9d ", ddm_table.data_size);
35288 seq_printf(seq, "%8d", ddm_table.code_size);
35289
35290@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
35291
35292 i2o_driver_result_table *result;
35293 i2o_driver_store_table *dst;
35294- char tmp[28 + 1];
35295
35296 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
35297 if (result == NULL)
35298@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
35299
35300 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
35301 seq_printf(seq, "%-#8x", dst->module_id);
35302- seq_printf(seq, "%-29s",
35303- chtostr(tmp, dst->module_name_version, 28));
35304- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
35305+ seq_printf(seq, "%-.28s", dst->module_name_version);
35306+ seq_printf(seq, "%-.8s", dst->date);
35307 seq_printf(seq, "%8d ", dst->module_size);
35308 seq_printf(seq, "%8d ", dst->mpb_size);
35309 seq_printf(seq, "0x%04x", dst->module_flags);
35310@@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
35311 // == (allow) 512d bytes (max)
35312 static u16 *work16 = (u16 *) work32;
35313 int token;
35314- char tmp[16 + 1];
35315
35316 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
35317
35318@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
35319 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
35320 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
35321 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
35322- seq_printf(seq, "Vendor info : %s\n",
35323- chtostr(tmp, (u8 *) (work32 + 2), 16));
35324- seq_printf(seq, "Product info : %s\n",
35325- chtostr(tmp, (u8 *) (work32 + 6), 16));
35326- seq_printf(seq, "Description : %s\n",
35327- chtostr(tmp, (u8 *) (work32 + 10), 16));
35328- seq_printf(seq, "Product rev. : %s\n",
35329- chtostr(tmp, (u8 *) (work32 + 14), 8));
35330+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
35331+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
35332+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
35333+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
35334
35335 seq_printf(seq, "Serial number : ");
35336 print_serial_number(seq, (u8 *) (work32 + 16),
35337@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
35338 u8 pad[256]; // allow up to 256 byte (max) serial number
35339 } result;
35340
35341- char tmp[24 + 1];
35342-
35343 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
35344
35345 if (token < 0) {
35346@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
35347 }
35348
35349 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
35350- seq_printf(seq, "Module name : %s\n",
35351- chtostr(tmp, result.module_name, 24));
35352- seq_printf(seq, "Module revision : %s\n",
35353- chtostr(tmp, result.module_rev, 8));
35354+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
35355+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
35356
35357 seq_printf(seq, "Serial number : ");
35358 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
35359@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
35360 u8 instance_number[4];
35361 } result;
35362
35363- char tmp[64 + 1];
35364-
35365 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
35366
35367 if (token < 0) {
35368@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
35369 return 0;
35370 }
35371
35372- seq_printf(seq, "Device name : %s\n",
35373- chtostr(tmp, result.device_name, 64));
35374- seq_printf(seq, "Service name : %s\n",
35375- chtostr(tmp, result.service_name, 64));
35376- seq_printf(seq, "Physical name : %s\n",
35377- chtostr(tmp, result.physical_location, 64));
35378- seq_printf(seq, "Instance number : %s\n",
35379- chtostr(tmp, result.instance_number, 4));
35380+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
35381+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
35382+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
35383+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
35384
35385 return 0;
35386 }
35387diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
35388index a8c08f3..155fe3d 100644
35389--- a/drivers/message/i2o/iop.c
35390+++ b/drivers/message/i2o/iop.c
35391@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
35392
35393 spin_lock_irqsave(&c->context_list_lock, flags);
35394
35395- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
35396- atomic_inc(&c->context_list_counter);
35397+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
35398+ atomic_inc_unchecked(&c->context_list_counter);
35399
35400- entry->context = atomic_read(&c->context_list_counter);
35401+ entry->context = atomic_read_unchecked(&c->context_list_counter);
35402
35403 list_add(&entry->list, &c->context_list);
35404
35405@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
35406
35407 #if BITS_PER_LONG == 64
35408 spin_lock_init(&c->context_list_lock);
35409- atomic_set(&c->context_list_counter, 0);
35410+ atomic_set_unchecked(&c->context_list_counter, 0);
35411 INIT_LIST_HEAD(&c->context_list);
35412 #endif
35413
35414diff --git a/drivers/mfd/abx500-core.c b/drivers/mfd/abx500-core.c
35415index 7ce65f4..e66e9bc 100644
35416--- a/drivers/mfd/abx500-core.c
35417+++ b/drivers/mfd/abx500-core.c
35418@@ -15,7 +15,7 @@ static LIST_HEAD(abx500_list);
35419
35420 struct abx500_device_entry {
35421 struct list_head list;
35422- struct abx500_ops ops;
35423+ abx500_ops_no_const ops;
35424 struct device *dev;
35425 };
35426
35427diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
35428index 965c480..71f2db9 100644
35429--- a/drivers/mfd/janz-cmodio.c
35430+++ b/drivers/mfd/janz-cmodio.c
35431@@ -13,6 +13,7 @@
35432
35433 #include <linux/kernel.h>
35434 #include <linux/module.h>
35435+#include <linux/slab.h>
35436 #include <linux/init.h>
35437 #include <linux/pci.h>
35438 #include <linux/interrupt.h>
35439diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
35440index 3aa9a96..59cf685 100644
35441--- a/drivers/misc/kgdbts.c
35442+++ b/drivers/misc/kgdbts.c
35443@@ -832,7 +832,7 @@ static void run_plant_and_detach_test(int is_early)
35444 char before[BREAK_INSTR_SIZE];
35445 char after[BREAK_INSTR_SIZE];
35446
35447- probe_kernel_read(before, (char *)kgdbts_break_test,
35448+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
35449 BREAK_INSTR_SIZE);
35450 init_simple_test();
35451 ts.tst = plant_and_detach_test;
35452@@ -840,7 +840,7 @@ static void run_plant_and_detach_test(int is_early)
35453 /* Activate test with initial breakpoint */
35454 if (!is_early)
35455 kgdb_breakpoint();
35456- probe_kernel_read(after, (char *)kgdbts_break_test,
35457+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
35458 BREAK_INSTR_SIZE);
35459 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
35460 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
35461diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
35462index 4a87e5c..76bdf5c 100644
35463--- a/drivers/misc/lis3lv02d/lis3lv02d.c
35464+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
35465@@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
35466 * the lid is closed. This leads to interrupts as soon as a little move
35467 * is done.
35468 */
35469- atomic_inc(&lis3->count);
35470+ atomic_inc_unchecked(&lis3->count);
35471
35472 wake_up_interruptible(&lis3->misc_wait);
35473 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
35474@@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
35475 if (lis3->pm_dev)
35476 pm_runtime_get_sync(lis3->pm_dev);
35477
35478- atomic_set(&lis3->count, 0);
35479+ atomic_set_unchecked(&lis3->count, 0);
35480 return 0;
35481 }
35482
35483@@ -617,7 +617,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
35484 add_wait_queue(&lis3->misc_wait, &wait);
35485 while (true) {
35486 set_current_state(TASK_INTERRUPTIBLE);
35487- data = atomic_xchg(&lis3->count, 0);
35488+ data = atomic_xchg_unchecked(&lis3->count, 0);
35489 if (data)
35490 break;
35491
35492@@ -658,7 +658,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
35493 struct lis3lv02d, miscdev);
35494
35495 poll_wait(file, &lis3->misc_wait, wait);
35496- if (atomic_read(&lis3->count))
35497+ if (atomic_read_unchecked(&lis3->count))
35498 return POLLIN | POLLRDNORM;
35499 return 0;
35500 }
35501diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
35502index c439c82..1f20f57 100644
35503--- a/drivers/misc/lis3lv02d/lis3lv02d.h
35504+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
35505@@ -297,7 +297,7 @@ struct lis3lv02d {
35506 struct input_polled_dev *idev; /* input device */
35507 struct platform_device *pdev; /* platform device */
35508 struct regulator_bulk_data regulators[2];
35509- atomic_t count; /* interrupt count after last read */
35510+ atomic_unchecked_t count; /* interrupt count after last read */
35511 union axis_conversion ac; /* hw -> logical axis */
35512 int mapped_btns[3];
35513
35514diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
35515index 2f30bad..c4c13d0 100644
35516--- a/drivers/misc/sgi-gru/gruhandles.c
35517+++ b/drivers/misc/sgi-gru/gruhandles.c
35518@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
35519 unsigned long nsec;
35520
35521 nsec = CLKS2NSEC(clks);
35522- atomic_long_inc(&mcs_op_statistics[op].count);
35523- atomic_long_add(nsec, &mcs_op_statistics[op].total);
35524+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
35525+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
35526 if (mcs_op_statistics[op].max < nsec)
35527 mcs_op_statistics[op].max = nsec;
35528 }
35529diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
35530index 950dbe9..eeef0f8 100644
35531--- a/drivers/misc/sgi-gru/gruprocfs.c
35532+++ b/drivers/misc/sgi-gru/gruprocfs.c
35533@@ -32,9 +32,9 @@
35534
35535 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
35536
35537-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
35538+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
35539 {
35540- unsigned long val = atomic_long_read(v);
35541+ unsigned long val = atomic_long_read_unchecked(v);
35542
35543 seq_printf(s, "%16lu %s\n", val, id);
35544 }
35545@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
35546
35547 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
35548 for (op = 0; op < mcsop_last; op++) {
35549- count = atomic_long_read(&mcs_op_statistics[op].count);
35550- total = atomic_long_read(&mcs_op_statistics[op].total);
35551+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
35552+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
35553 max = mcs_op_statistics[op].max;
35554 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
35555 count ? total / count : 0, max);
35556diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
35557index 5c3ce24..4915ccb 100644
35558--- a/drivers/misc/sgi-gru/grutables.h
35559+++ b/drivers/misc/sgi-gru/grutables.h
35560@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
35561 * GRU statistics.
35562 */
35563 struct gru_stats_s {
35564- atomic_long_t vdata_alloc;
35565- atomic_long_t vdata_free;
35566- atomic_long_t gts_alloc;
35567- atomic_long_t gts_free;
35568- atomic_long_t gms_alloc;
35569- atomic_long_t gms_free;
35570- atomic_long_t gts_double_allocate;
35571- atomic_long_t assign_context;
35572- atomic_long_t assign_context_failed;
35573- atomic_long_t free_context;
35574- atomic_long_t load_user_context;
35575- atomic_long_t load_kernel_context;
35576- atomic_long_t lock_kernel_context;
35577- atomic_long_t unlock_kernel_context;
35578- atomic_long_t steal_user_context;
35579- atomic_long_t steal_kernel_context;
35580- atomic_long_t steal_context_failed;
35581- atomic_long_t nopfn;
35582- atomic_long_t asid_new;
35583- atomic_long_t asid_next;
35584- atomic_long_t asid_wrap;
35585- atomic_long_t asid_reuse;
35586- atomic_long_t intr;
35587- atomic_long_t intr_cbr;
35588- atomic_long_t intr_tfh;
35589- atomic_long_t intr_spurious;
35590- atomic_long_t intr_mm_lock_failed;
35591- atomic_long_t call_os;
35592- atomic_long_t call_os_wait_queue;
35593- atomic_long_t user_flush_tlb;
35594- atomic_long_t user_unload_context;
35595- atomic_long_t user_exception;
35596- atomic_long_t set_context_option;
35597- atomic_long_t check_context_retarget_intr;
35598- atomic_long_t check_context_unload;
35599- atomic_long_t tlb_dropin;
35600- atomic_long_t tlb_preload_page;
35601- atomic_long_t tlb_dropin_fail_no_asid;
35602- atomic_long_t tlb_dropin_fail_upm;
35603- atomic_long_t tlb_dropin_fail_invalid;
35604- atomic_long_t tlb_dropin_fail_range_active;
35605- atomic_long_t tlb_dropin_fail_idle;
35606- atomic_long_t tlb_dropin_fail_fmm;
35607- atomic_long_t tlb_dropin_fail_no_exception;
35608- atomic_long_t tfh_stale_on_fault;
35609- atomic_long_t mmu_invalidate_range;
35610- atomic_long_t mmu_invalidate_page;
35611- atomic_long_t flush_tlb;
35612- atomic_long_t flush_tlb_gru;
35613- atomic_long_t flush_tlb_gru_tgh;
35614- atomic_long_t flush_tlb_gru_zero_asid;
35615+ atomic_long_unchecked_t vdata_alloc;
35616+ atomic_long_unchecked_t vdata_free;
35617+ atomic_long_unchecked_t gts_alloc;
35618+ atomic_long_unchecked_t gts_free;
35619+ atomic_long_unchecked_t gms_alloc;
35620+ atomic_long_unchecked_t gms_free;
35621+ atomic_long_unchecked_t gts_double_allocate;
35622+ atomic_long_unchecked_t assign_context;
35623+ atomic_long_unchecked_t assign_context_failed;
35624+ atomic_long_unchecked_t free_context;
35625+ atomic_long_unchecked_t load_user_context;
35626+ atomic_long_unchecked_t load_kernel_context;
35627+ atomic_long_unchecked_t lock_kernel_context;
35628+ atomic_long_unchecked_t unlock_kernel_context;
35629+ atomic_long_unchecked_t steal_user_context;
35630+ atomic_long_unchecked_t steal_kernel_context;
35631+ atomic_long_unchecked_t steal_context_failed;
35632+ atomic_long_unchecked_t nopfn;
35633+ atomic_long_unchecked_t asid_new;
35634+ atomic_long_unchecked_t asid_next;
35635+ atomic_long_unchecked_t asid_wrap;
35636+ atomic_long_unchecked_t asid_reuse;
35637+ atomic_long_unchecked_t intr;
35638+ atomic_long_unchecked_t intr_cbr;
35639+ atomic_long_unchecked_t intr_tfh;
35640+ atomic_long_unchecked_t intr_spurious;
35641+ atomic_long_unchecked_t intr_mm_lock_failed;
35642+ atomic_long_unchecked_t call_os;
35643+ atomic_long_unchecked_t call_os_wait_queue;
35644+ atomic_long_unchecked_t user_flush_tlb;
35645+ atomic_long_unchecked_t user_unload_context;
35646+ atomic_long_unchecked_t user_exception;
35647+ atomic_long_unchecked_t set_context_option;
35648+ atomic_long_unchecked_t check_context_retarget_intr;
35649+ atomic_long_unchecked_t check_context_unload;
35650+ atomic_long_unchecked_t tlb_dropin;
35651+ atomic_long_unchecked_t tlb_preload_page;
35652+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
35653+ atomic_long_unchecked_t tlb_dropin_fail_upm;
35654+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
35655+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
35656+ atomic_long_unchecked_t tlb_dropin_fail_idle;
35657+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
35658+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
35659+ atomic_long_unchecked_t tfh_stale_on_fault;
35660+ atomic_long_unchecked_t mmu_invalidate_range;
35661+ atomic_long_unchecked_t mmu_invalidate_page;
35662+ atomic_long_unchecked_t flush_tlb;
35663+ atomic_long_unchecked_t flush_tlb_gru;
35664+ atomic_long_unchecked_t flush_tlb_gru_tgh;
35665+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
35666
35667- atomic_long_t copy_gpa;
35668- atomic_long_t read_gpa;
35669+ atomic_long_unchecked_t copy_gpa;
35670+ atomic_long_unchecked_t read_gpa;
35671
35672- atomic_long_t mesq_receive;
35673- atomic_long_t mesq_receive_none;
35674- atomic_long_t mesq_send;
35675- atomic_long_t mesq_send_failed;
35676- atomic_long_t mesq_noop;
35677- atomic_long_t mesq_send_unexpected_error;
35678- atomic_long_t mesq_send_lb_overflow;
35679- atomic_long_t mesq_send_qlimit_reached;
35680- atomic_long_t mesq_send_amo_nacked;
35681- atomic_long_t mesq_send_put_nacked;
35682- atomic_long_t mesq_page_overflow;
35683- atomic_long_t mesq_qf_locked;
35684- atomic_long_t mesq_qf_noop_not_full;
35685- atomic_long_t mesq_qf_switch_head_failed;
35686- atomic_long_t mesq_qf_unexpected_error;
35687- atomic_long_t mesq_noop_unexpected_error;
35688- atomic_long_t mesq_noop_lb_overflow;
35689- atomic_long_t mesq_noop_qlimit_reached;
35690- atomic_long_t mesq_noop_amo_nacked;
35691- atomic_long_t mesq_noop_put_nacked;
35692- atomic_long_t mesq_noop_page_overflow;
35693+ atomic_long_unchecked_t mesq_receive;
35694+ atomic_long_unchecked_t mesq_receive_none;
35695+ atomic_long_unchecked_t mesq_send;
35696+ atomic_long_unchecked_t mesq_send_failed;
35697+ atomic_long_unchecked_t mesq_noop;
35698+ atomic_long_unchecked_t mesq_send_unexpected_error;
35699+ atomic_long_unchecked_t mesq_send_lb_overflow;
35700+ atomic_long_unchecked_t mesq_send_qlimit_reached;
35701+ atomic_long_unchecked_t mesq_send_amo_nacked;
35702+ atomic_long_unchecked_t mesq_send_put_nacked;
35703+ atomic_long_unchecked_t mesq_page_overflow;
35704+ atomic_long_unchecked_t mesq_qf_locked;
35705+ atomic_long_unchecked_t mesq_qf_noop_not_full;
35706+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
35707+ atomic_long_unchecked_t mesq_qf_unexpected_error;
35708+ atomic_long_unchecked_t mesq_noop_unexpected_error;
35709+ atomic_long_unchecked_t mesq_noop_lb_overflow;
35710+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
35711+ atomic_long_unchecked_t mesq_noop_amo_nacked;
35712+ atomic_long_unchecked_t mesq_noop_put_nacked;
35713+ atomic_long_unchecked_t mesq_noop_page_overflow;
35714
35715 };
35716
35717@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
35718 tghop_invalidate, mcsop_last};
35719
35720 struct mcs_op_statistic {
35721- atomic_long_t count;
35722- atomic_long_t total;
35723+ atomic_long_unchecked_t count;
35724+ atomic_long_unchecked_t total;
35725 unsigned long max;
35726 };
35727
35728@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
35729
35730 #define STAT(id) do { \
35731 if (gru_options & OPT_STATS) \
35732- atomic_long_inc(&gru_stats.id); \
35733+ atomic_long_inc_unchecked(&gru_stats.id); \
35734 } while (0)
35735
35736 #ifdef CONFIG_SGI_GRU_DEBUG
35737diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
35738index c862cd4..0d176fe 100644
35739--- a/drivers/misc/sgi-xp/xp.h
35740+++ b/drivers/misc/sgi-xp/xp.h
35741@@ -288,7 +288,7 @@ struct xpc_interface {
35742 xpc_notify_func, void *);
35743 void (*received) (short, int, void *);
35744 enum xp_retval (*partid_to_nasids) (short, void *);
35745-};
35746+} __no_const;
35747
35748 extern struct xpc_interface xpc_interface;
35749
35750diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
35751index b94d5f7..7f494c5 100644
35752--- a/drivers/misc/sgi-xp/xpc.h
35753+++ b/drivers/misc/sgi-xp/xpc.h
35754@@ -835,6 +835,7 @@ struct xpc_arch_operations {
35755 void (*received_payload) (struct xpc_channel *, void *);
35756 void (*notify_senders_of_disconnect) (struct xpc_channel *);
35757 };
35758+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
35759
35760 /* struct xpc_partition act_state values (for XPC HB) */
35761
35762@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
35763 /* found in xpc_main.c */
35764 extern struct device *xpc_part;
35765 extern struct device *xpc_chan;
35766-extern struct xpc_arch_operations xpc_arch_ops;
35767+extern xpc_arch_operations_no_const xpc_arch_ops;
35768 extern int xpc_disengage_timelimit;
35769 extern int xpc_disengage_timedout;
35770 extern int xpc_activate_IRQ_rcvd;
35771diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
35772index 8d082b4..aa749ae 100644
35773--- a/drivers/misc/sgi-xp/xpc_main.c
35774+++ b/drivers/misc/sgi-xp/xpc_main.c
35775@@ -162,7 +162,7 @@ static struct notifier_block xpc_die_notifier = {
35776 .notifier_call = xpc_system_die,
35777 };
35778
35779-struct xpc_arch_operations xpc_arch_ops;
35780+xpc_arch_operations_no_const xpc_arch_ops;
35781
35782 /*
35783 * Timer function to enforce the timelimit on the partition disengage.
35784diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
35785index a0e1720..ee63d0b 100644
35786--- a/drivers/mmc/core/mmc_ops.c
35787+++ b/drivers/mmc/core/mmc_ops.c
35788@@ -245,7 +245,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
35789 void *data_buf;
35790 int is_on_stack;
35791
35792- is_on_stack = object_is_on_stack(buf);
35793+ is_on_stack = object_starts_on_stack(buf);
35794 if (is_on_stack) {
35795 /*
35796 * dma onto stack is unsafe/nonportable, but callers to this
35797diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
35798index 53b8fd9..615b462 100644
35799--- a/drivers/mmc/host/dw_mmc.h
35800+++ b/drivers/mmc/host/dw_mmc.h
35801@@ -205,5 +205,5 @@ struct dw_mci_drv_data {
35802 int (*parse_dt)(struct dw_mci *host);
35803 int (*setup_bus)(struct dw_mci *host,
35804 struct device_node *slot_np, u8 bus_width);
35805-};
35806+} __do_const;
35807 #endif /* _DW_MMC_H_ */
35808diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
35809index a4eb8b5..8c0628f 100644
35810--- a/drivers/mtd/devices/doc2000.c
35811+++ b/drivers/mtd/devices/doc2000.c
35812@@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
35813
35814 /* The ECC will not be calculated correctly if less than 512 is written */
35815 /* DBB-
35816- if (len != 0x200 && eccbuf)
35817+ if (len != 0x200)
35818 printk(KERN_WARNING
35819 "ECC needs a full sector write (adr: %lx size %lx)\n",
35820 (long) to, (long) len);
35821diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
35822index e706a23..b3d262f 100644
35823--- a/drivers/mtd/nand/denali.c
35824+++ b/drivers/mtd/nand/denali.c
35825@@ -26,6 +26,7 @@
35826 #include <linux/pci.h>
35827 #include <linux/mtd/mtd.h>
35828 #include <linux/module.h>
35829+#include <linux/slab.h>
35830
35831 #include "denali.h"
35832
35833diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
35834index 51b9d6a..52af9a7 100644
35835--- a/drivers/mtd/nftlmount.c
35836+++ b/drivers/mtd/nftlmount.c
35837@@ -24,6 +24,7 @@
35838 #include <asm/errno.h>
35839 #include <linux/delay.h>
35840 #include <linux/slab.h>
35841+#include <linux/sched.h>
35842 #include <linux/mtd/mtd.h>
35843 #include <linux/mtd/nand.h>
35844 #include <linux/mtd/nftl.h>
35845diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
35846index 203ff9d..0968ca8 100644
35847--- a/drivers/net/ethernet/8390/ax88796.c
35848+++ b/drivers/net/ethernet/8390/ax88796.c
35849@@ -872,9 +872,11 @@ static int ax_probe(struct platform_device *pdev)
35850 if (ax->plat->reg_offsets)
35851 ei_local->reg_offset = ax->plat->reg_offsets;
35852 else {
35853+ resource_size_t _mem_size = mem_size;
35854+ do_div(_mem_size, 0x18);
35855 ei_local->reg_offset = ax->reg_offsets;
35856 for (ret = 0; ret < 0x18; ret++)
35857- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
35858+ ax->reg_offsets[ret] = _mem_size * ret;
35859 }
35860
35861 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
35862diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
35863index acf2fe4..25cf8fd 100644
35864--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
35865+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
35866@@ -486,7 +486,7 @@ struct bnx2x_rx_mode_obj {
35867
35868 int (*wait_comp)(struct bnx2x *bp,
35869 struct bnx2x_rx_mode_ramrod_params *p);
35870-};
35871+} __no_const;
35872
35873 /********************** Set multicast group ***********************************/
35874
35875diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
35876index d9308c32..d87b824 100644
35877--- a/drivers/net/ethernet/broadcom/tg3.h
35878+++ b/drivers/net/ethernet/broadcom/tg3.h
35879@@ -140,6 +140,7 @@
35880 #define CHIPREV_ID_5750_A0 0x4000
35881 #define CHIPREV_ID_5750_A1 0x4001
35882 #define CHIPREV_ID_5750_A3 0x4003
35883+#define CHIPREV_ID_5750_C1 0x4201
35884 #define CHIPREV_ID_5750_C2 0x4202
35885 #define CHIPREV_ID_5752_A0_HW 0x5000
35886 #define CHIPREV_ID_5752_A0 0x6000
35887diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
35888index 8cffcdf..aadf043 100644
35889--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
35890+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
35891@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
35892 */
35893 struct l2t_skb_cb {
35894 arp_failure_handler_func arp_failure_handler;
35895-};
35896+} __no_const;
35897
35898 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
35899
35900diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
35901index f879e92..726f20f 100644
35902--- a/drivers/net/ethernet/dec/tulip/de4x5.c
35903+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
35904@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
35905 for (i=0; i<ETH_ALEN; i++) {
35906 tmp.addr[i] = dev->dev_addr[i];
35907 }
35908- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
35909+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
35910 break;
35911
35912 case DE4X5_SET_HWADDR: /* Set the hardware address */
35913@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
35914 spin_lock_irqsave(&lp->lock, flags);
35915 memcpy(&statbuf, &lp->pktStats, ioc->len);
35916 spin_unlock_irqrestore(&lp->lock, flags);
35917- if (copy_to_user(ioc->data, &statbuf, ioc->len))
35918+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
35919 return -EFAULT;
35920 break;
35921 }
35922diff --git a/drivers/net/ethernet/dec/tulip/uli526x.c b/drivers/net/ethernet/dec/tulip/uli526x.c
35923index 75d45f8..3d9c55b 100644
35924--- a/drivers/net/ethernet/dec/tulip/uli526x.c
35925+++ b/drivers/net/ethernet/dec/tulip/uli526x.c
35926@@ -129,7 +129,7 @@ struct uli526x_board_info {
35927 struct uli_phy_ops {
35928 void (*write)(struct uli526x_board_info *, u8, u8, u16);
35929 u16 (*read)(struct uli526x_board_info *, u8, u8);
35930- } phy;
35931+ } __no_const phy;
35932 struct net_device *next_dev; /* next device */
35933 struct pci_dev *pdev; /* PCI device */
35934 spinlock_t lock;
35935diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
35936index d1b6cc5..cde0d97 100644
35937--- a/drivers/net/ethernet/emulex/benet/be_main.c
35938+++ b/drivers/net/ethernet/emulex/benet/be_main.c
35939@@ -403,7 +403,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
35940
35941 if (wrapped)
35942 newacc += 65536;
35943- ACCESS_ONCE(*acc) = newacc;
35944+ ACCESS_ONCE_RW(*acc) = newacc;
35945 }
35946
35947 void be_parse_stats(struct be_adapter *adapter)
35948diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
35949index 74d749e..eefb1bd 100644
35950--- a/drivers/net/ethernet/faraday/ftgmac100.c
35951+++ b/drivers/net/ethernet/faraday/ftgmac100.c
35952@@ -31,6 +31,8 @@
35953 #include <linux/netdevice.h>
35954 #include <linux/phy.h>
35955 #include <linux/platform_device.h>
35956+#include <linux/interrupt.h>
35957+#include <linux/irqreturn.h>
35958 #include <net/ip.h>
35959
35960 #include "ftgmac100.h"
35961diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
35962index b901a01..1ff32ee 100644
35963--- a/drivers/net/ethernet/faraday/ftmac100.c
35964+++ b/drivers/net/ethernet/faraday/ftmac100.c
35965@@ -31,6 +31,8 @@
35966 #include <linux/module.h>
35967 #include <linux/netdevice.h>
35968 #include <linux/platform_device.h>
35969+#include <linux/interrupt.h>
35970+#include <linux/irqreturn.h>
35971
35972 #include "ftmac100.h"
35973
35974diff --git a/drivers/net/ethernet/intel/e1000e/hw.h b/drivers/net/ethernet/intel/e1000e/hw.h
35975index d37bfd9..5e13032 100644
35976--- a/drivers/net/ethernet/intel/e1000e/hw.h
35977+++ b/drivers/net/ethernet/intel/e1000e/hw.h
35978@@ -799,6 +799,7 @@ struct e1000_mac_operations {
35979 void (*rar_set)(struct e1000_hw *, u8 *, u32);
35980 s32 (*read_mac_addr)(struct e1000_hw *);
35981 };
35982+typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35983
35984 /*
35985 * When to use various PHY register access functions:
35986@@ -839,6 +840,7 @@ struct e1000_phy_operations {
35987 void (*power_up)(struct e1000_hw *);
35988 void (*power_down)(struct e1000_hw *);
35989 };
35990+typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
35991
35992 /* Function pointers for the NVM. */
35993 struct e1000_nvm_operations {
35994@@ -851,9 +853,10 @@ struct e1000_nvm_operations {
35995 s32 (*validate)(struct e1000_hw *);
35996 s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
35997 };
35998+typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
35999
36000 struct e1000_mac_info {
36001- struct e1000_mac_operations ops;
36002+ e1000_mac_operations_no_const ops;
36003 u8 addr[ETH_ALEN];
36004 u8 perm_addr[ETH_ALEN];
36005
36006@@ -894,7 +897,7 @@ struct e1000_mac_info {
36007 };
36008
36009 struct e1000_phy_info {
36010- struct e1000_phy_operations ops;
36011+ e1000_phy_operations_no_const ops;
36012
36013 enum e1000_phy_type type;
36014
36015@@ -928,7 +931,7 @@ struct e1000_phy_info {
36016 };
36017
36018 struct e1000_nvm_info {
36019- struct e1000_nvm_operations ops;
36020+ e1000_nvm_operations_no_const ops;
36021
36022 enum e1000_nvm_type type;
36023 enum e1000_nvm_override override;
36024diff --git a/drivers/net/ethernet/intel/igb/e1000_hw.h b/drivers/net/ethernet/intel/igb/e1000_hw.h
36025index c2a51dc..c2bd262 100644
36026--- a/drivers/net/ethernet/intel/igb/e1000_hw.h
36027+++ b/drivers/net/ethernet/intel/igb/e1000_hw.h
36028@@ -327,6 +327,7 @@ struct e1000_mac_operations {
36029 void (*release_swfw_sync)(struct e1000_hw *, u16);
36030
36031 };
36032+typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
36033
36034 struct e1000_phy_operations {
36035 s32 (*acquire)(struct e1000_hw *);
36036@@ -343,6 +344,7 @@ struct e1000_phy_operations {
36037 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
36038 s32 (*write_reg)(struct e1000_hw *, u32, u16);
36039 };
36040+typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
36041
36042 struct e1000_nvm_operations {
36043 s32 (*acquire)(struct e1000_hw *);
36044@@ -353,6 +355,7 @@ struct e1000_nvm_operations {
36045 s32 (*validate)(struct e1000_hw *);
36046 s32 (*valid_led_default)(struct e1000_hw *, u16 *);
36047 };
36048+typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
36049
36050 struct e1000_info {
36051 s32 (*get_invariants)(struct e1000_hw *);
36052@@ -364,7 +367,7 @@ struct e1000_info {
36053 extern const struct e1000_info e1000_82575_info;
36054
36055 struct e1000_mac_info {
36056- struct e1000_mac_operations ops;
36057+ e1000_mac_operations_no_const ops;
36058
36059 u8 addr[6];
36060 u8 perm_addr[6];
36061@@ -402,7 +405,7 @@ struct e1000_mac_info {
36062 };
36063
36064 struct e1000_phy_info {
36065- struct e1000_phy_operations ops;
36066+ e1000_phy_operations_no_const ops;
36067
36068 enum e1000_phy_type type;
36069
36070@@ -437,7 +440,7 @@ struct e1000_phy_info {
36071 };
36072
36073 struct e1000_nvm_info {
36074- struct e1000_nvm_operations ops;
36075+ e1000_nvm_operations_no_const ops;
36076 enum e1000_nvm_type type;
36077 enum e1000_nvm_override override;
36078
36079@@ -482,6 +485,7 @@ struct e1000_mbx_operations {
36080 s32 (*check_for_ack)(struct e1000_hw *, u16);
36081 s32 (*check_for_rst)(struct e1000_hw *, u16);
36082 };
36083+typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
36084
36085 struct e1000_mbx_stats {
36086 u32 msgs_tx;
36087@@ -493,7 +497,7 @@ struct e1000_mbx_stats {
36088 };
36089
36090 struct e1000_mbx_info {
36091- struct e1000_mbx_operations ops;
36092+ e1000_mbx_operations_no_const ops;
36093 struct e1000_mbx_stats stats;
36094 u32 timeout;
36095 u32 usec_delay;
36096diff --git a/drivers/net/ethernet/intel/igbvf/vf.h b/drivers/net/ethernet/intel/igbvf/vf.h
36097index 57db3c6..aa825fc 100644
36098--- a/drivers/net/ethernet/intel/igbvf/vf.h
36099+++ b/drivers/net/ethernet/intel/igbvf/vf.h
36100@@ -189,9 +189,10 @@ struct e1000_mac_operations {
36101 s32 (*read_mac_addr)(struct e1000_hw *);
36102 s32 (*set_vfta)(struct e1000_hw *, u16, bool);
36103 };
36104+typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
36105
36106 struct e1000_mac_info {
36107- struct e1000_mac_operations ops;
36108+ e1000_mac_operations_no_const ops;
36109 u8 addr[6];
36110 u8 perm_addr[6];
36111
36112@@ -213,6 +214,7 @@ struct e1000_mbx_operations {
36113 s32 (*check_for_ack)(struct e1000_hw *);
36114 s32 (*check_for_rst)(struct e1000_hw *);
36115 };
36116+typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
36117
36118 struct e1000_mbx_stats {
36119 u32 msgs_tx;
36120@@ -224,7 +226,7 @@ struct e1000_mbx_stats {
36121 };
36122
36123 struct e1000_mbx_info {
36124- struct e1000_mbx_operations ops;
36125+ e1000_mbx_operations_no_const ops;
36126 struct e1000_mbx_stats stats;
36127 u32 timeout;
36128 u32 usec_delay;
36129diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
36130index d929131..aed108f 100644
36131--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
36132+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
36133@@ -865,7 +865,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
36134 /* store the new cycle speed */
36135 adapter->cycle_speed = cycle_speed;
36136
36137- ACCESS_ONCE(adapter->base_incval) = incval;
36138+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
36139 smp_mb();
36140
36141 /* grab the ptp lock */
36142diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
36143index 0722f33..771758a 100644
36144--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
36145+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
36146@@ -2800,6 +2800,7 @@ struct ixgbe_eeprom_operations {
36147 s32 (*update_checksum)(struct ixgbe_hw *);
36148 u16 (*calc_checksum)(struct ixgbe_hw *);
36149 };
36150+typedef struct ixgbe_eeprom_operations __no_const ixgbe_eeprom_operations_no_const;
36151
36152 struct ixgbe_mac_operations {
36153 s32 (*init_hw)(struct ixgbe_hw *);
36154@@ -2866,6 +2867,7 @@ struct ixgbe_mac_operations {
36155 s32 (*get_thermal_sensor_data)(struct ixgbe_hw *);
36156 s32 (*init_thermal_sensor_thresh)(struct ixgbe_hw *hw);
36157 };
36158+typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
36159
36160 struct ixgbe_phy_operations {
36161 s32 (*identify)(struct ixgbe_hw *);
36162@@ -2885,9 +2887,10 @@ struct ixgbe_phy_operations {
36163 s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
36164 s32 (*check_overtemp)(struct ixgbe_hw *);
36165 };
36166+typedef struct ixgbe_phy_operations __no_const ixgbe_phy_operations_no_const;
36167
36168 struct ixgbe_eeprom_info {
36169- struct ixgbe_eeprom_operations ops;
36170+ ixgbe_eeprom_operations_no_const ops;
36171 enum ixgbe_eeprom_type type;
36172 u32 semaphore_delay;
36173 u16 word_size;
36174@@ -2897,7 +2900,7 @@ struct ixgbe_eeprom_info {
36175
36176 #define IXGBE_FLAGS_DOUBLE_RESET_REQUIRED 0x01
36177 struct ixgbe_mac_info {
36178- struct ixgbe_mac_operations ops;
36179+ ixgbe_mac_operations_no_const ops;
36180 enum ixgbe_mac_type type;
36181 u8 addr[ETH_ALEN];
36182 u8 perm_addr[ETH_ALEN];
36183@@ -2927,7 +2930,7 @@ struct ixgbe_mac_info {
36184 };
36185
36186 struct ixgbe_phy_info {
36187- struct ixgbe_phy_operations ops;
36188+ ixgbe_phy_operations_no_const ops;
36189 struct mdio_if_info mdio;
36190 enum ixgbe_phy_type type;
36191 u32 id;
36192@@ -2955,6 +2958,7 @@ struct ixgbe_mbx_operations {
36193 s32 (*check_for_ack)(struct ixgbe_hw *, u16);
36194 s32 (*check_for_rst)(struct ixgbe_hw *, u16);
36195 };
36196+typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
36197
36198 struct ixgbe_mbx_stats {
36199 u32 msgs_tx;
36200@@ -2966,7 +2970,7 @@ struct ixgbe_mbx_stats {
36201 };
36202
36203 struct ixgbe_mbx_info {
36204- struct ixgbe_mbx_operations ops;
36205+ ixgbe_mbx_operations_no_const ops;
36206 struct ixgbe_mbx_stats stats;
36207 u32 timeout;
36208 u32 usec_delay;
36209diff --git a/drivers/net/ethernet/intel/ixgbevf/vf.h b/drivers/net/ethernet/intel/ixgbevf/vf.h
36210index 47f11a5..c817d97 100644
36211--- a/drivers/net/ethernet/intel/ixgbevf/vf.h
36212+++ b/drivers/net/ethernet/intel/ixgbevf/vf.h
36213@@ -70,6 +70,7 @@ struct ixgbe_mac_operations {
36214 s32 (*clear_vfta)(struct ixgbe_hw *);
36215 s32 (*set_vfta)(struct ixgbe_hw *, u32, u32, bool);
36216 };
36217+typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
36218
36219 enum ixgbe_mac_type {
36220 ixgbe_mac_unknown = 0,
36221@@ -79,7 +80,7 @@ enum ixgbe_mac_type {
36222 };
36223
36224 struct ixgbe_mac_info {
36225- struct ixgbe_mac_operations ops;
36226+ ixgbe_mac_operations_no_const ops;
36227 u8 addr[6];
36228 u8 perm_addr[6];
36229
36230@@ -103,6 +104,7 @@ struct ixgbe_mbx_operations {
36231 s32 (*check_for_ack)(struct ixgbe_hw *);
36232 s32 (*check_for_rst)(struct ixgbe_hw *);
36233 };
36234+typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
36235
36236 struct ixgbe_mbx_stats {
36237 u32 msgs_tx;
36238@@ -114,7 +116,7 @@ struct ixgbe_mbx_stats {
36239 };
36240
36241 struct ixgbe_mbx_info {
36242- struct ixgbe_mbx_operations ops;
36243+ ixgbe_mbx_operations_no_const ops;
36244 struct ixgbe_mbx_stats stats;
36245 u32 timeout;
36246 u32 udelay;
36247diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.h b/drivers/net/ethernet/neterion/vxge/vxge-config.h
36248index 9e0c1ee..8471f77 100644
36249--- a/drivers/net/ethernet/neterion/vxge/vxge-config.h
36250+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.h
36251@@ -514,7 +514,7 @@ struct vxge_hw_uld_cbs {
36252 void (*link_down)(struct __vxge_hw_device *devh);
36253 void (*crit_err)(struct __vxge_hw_device *devh,
36254 enum vxge_hw_event type, u64 ext_data);
36255-};
36256+} __no_const;
36257
36258 /*
36259 * struct __vxge_hw_blockpool_entry - Block private data structure
36260diff --git a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
36261index 4a518a3..936b334 100644
36262--- a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
36263+++ b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
36264@@ -2088,7 +2088,7 @@ struct vxge_hw_mempool_cbs {
36265 struct vxge_hw_mempool_dma *dma_object,
36266 u32 index,
36267 u32 is_last);
36268-};
36269+} __no_const;
36270
36271 #define VXGE_HW_VIRTUAL_PATH_HANDLE(vpath) \
36272 ((struct __vxge_hw_vpath_handle *)(vpath)->vpath_handles.next)
36273diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
36274index 927aa33..a6c2518 100644
36275--- a/drivers/net/ethernet/realtek/r8169.c
36276+++ b/drivers/net/ethernet/realtek/r8169.c
36277@@ -747,22 +747,22 @@ struct rtl8169_private {
36278 struct mdio_ops {
36279 void (*write)(struct rtl8169_private *, int, int);
36280 int (*read)(struct rtl8169_private *, int);
36281- } mdio_ops;
36282+ } __no_const mdio_ops;
36283
36284 struct pll_power_ops {
36285 void (*down)(struct rtl8169_private *);
36286 void (*up)(struct rtl8169_private *);
36287- } pll_power_ops;
36288+ } __no_const pll_power_ops;
36289
36290 struct jumbo_ops {
36291 void (*enable)(struct rtl8169_private *);
36292 void (*disable)(struct rtl8169_private *);
36293- } jumbo_ops;
36294+ } __no_const jumbo_ops;
36295
36296 struct csi_ops {
36297 void (*write)(struct rtl8169_private *, int, int);
36298 u32 (*read)(struct rtl8169_private *, int);
36299- } csi_ops;
36300+ } __no_const csi_ops;
36301
36302 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
36303 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
36304diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
36305index 0767043f..08c2553 100644
36306--- a/drivers/net/ethernet/sfc/ptp.c
36307+++ b/drivers/net/ethernet/sfc/ptp.c
36308@@ -553,7 +553,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
36309 (u32)((u64)ptp->start.dma_addr >> 32));
36310
36311 /* Clear flag that signals MC ready */
36312- ACCESS_ONCE(*start) = 0;
36313+ ACCESS_ONCE_RW(*start) = 0;
36314 efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
36315 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
36316
36317diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
36318index 0c74a70..3bc6f68 100644
36319--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
36320+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
36321@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
36322
36323 writel(value, ioaddr + MMC_CNTRL);
36324
36325- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
36326- MMC_CNTRL, value);
36327+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
36328+// MMC_CNTRL, value);
36329 }
36330
36331 /* To mask all all interrupts.*/
36332diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
36333index 5fd6f46..ee1f265 100644
36334--- a/drivers/net/hyperv/hyperv_net.h
36335+++ b/drivers/net/hyperv/hyperv_net.h
36336@@ -101,7 +101,7 @@ struct rndis_device {
36337
36338 enum rndis_device_state state;
36339 bool link_state;
36340- atomic_t new_req_id;
36341+ atomic_unchecked_t new_req_id;
36342
36343 spinlock_t request_lock;
36344 struct list_head req_list;
36345diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
36346index 928148c..d83298e 100644
36347--- a/drivers/net/hyperv/rndis_filter.c
36348+++ b/drivers/net/hyperv/rndis_filter.c
36349@@ -107,7 +107,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
36350 * template
36351 */
36352 set = &rndis_msg->msg.set_req;
36353- set->req_id = atomic_inc_return(&dev->new_req_id);
36354+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
36355
36356 /* Add to the request list */
36357 spin_lock_irqsave(&dev->request_lock, flags);
36358@@ -760,7 +760,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
36359
36360 /* Setup the rndis set */
36361 halt = &request->request_msg.msg.halt_req;
36362- halt->req_id = atomic_inc_return(&dev->new_req_id);
36363+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
36364
36365 /* Ignore return since this msg is optional. */
36366 rndis_filter_send_request(dev, request);
36367diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
36368index 7d39add..037e1da 100644
36369--- a/drivers/net/ieee802154/fakehard.c
36370+++ b/drivers/net/ieee802154/fakehard.c
36371@@ -386,7 +386,7 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
36372 phy->transmit_power = 0xbf;
36373
36374 dev->netdev_ops = &fake_ops;
36375- dev->ml_priv = &fake_mlme;
36376+ dev->ml_priv = (void *)&fake_mlme;
36377
36378 priv = netdev_priv(dev);
36379 priv->phy = phy;
36380diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
36381index 0f0f9ce..0ca5819 100644
36382--- a/drivers/net/macvtap.c
36383+++ b/drivers/net/macvtap.c
36384@@ -1100,7 +1100,7 @@ static int macvtap_device_event(struct notifier_block *unused,
36385 return NOTIFY_DONE;
36386 }
36387
36388-static struct notifier_block macvtap_notifier_block __read_mostly = {
36389+static struct notifier_block macvtap_notifier_block = {
36390 .notifier_call = macvtap_device_event,
36391 };
36392
36393diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
36394index daec9b0..6428fcb 100644
36395--- a/drivers/net/phy/mdio-bitbang.c
36396+++ b/drivers/net/phy/mdio-bitbang.c
36397@@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
36398 struct mdiobb_ctrl *ctrl = bus->priv;
36399
36400 module_put(ctrl->ops->owner);
36401+ mdiobus_unregister(bus);
36402 mdiobus_free(bus);
36403 }
36404 EXPORT_SYMBOL(free_mdio_bitbang);
36405diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
36406index eb3f5ce..d773730 100644
36407--- a/drivers/net/ppp/ppp_generic.c
36408+++ b/drivers/net/ppp/ppp_generic.c
36409@@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
36410 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
36411 struct ppp_stats stats;
36412 struct ppp_comp_stats cstats;
36413- char *vers;
36414
36415 switch (cmd) {
36416 case SIOCGPPPSTATS:
36417@@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
36418 break;
36419
36420 case SIOCGPPPVER:
36421- vers = PPP_VERSION;
36422- if (copy_to_user(addr, vers, strlen(vers) + 1))
36423+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
36424 break;
36425 err = 0;
36426 break;
36427diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
36428index ad86660..9fd0884 100644
36429--- a/drivers/net/team/team.c
36430+++ b/drivers/net/team/team.c
36431@@ -2601,7 +2601,7 @@ static int team_device_event(struct notifier_block *unused,
36432 return NOTIFY_DONE;
36433 }
36434
36435-static struct notifier_block team_notifier_block __read_mostly = {
36436+static struct notifier_block team_notifier_block = {
36437 .notifier_call = team_device_event,
36438 };
36439
36440diff --git a/drivers/net/tun.c b/drivers/net/tun.c
36441index 0873cdc..ddb178e 100644
36442--- a/drivers/net/tun.c
36443+++ b/drivers/net/tun.c
36444@@ -1374,7 +1374,7 @@ static int set_offload(struct tun_struct *tun, unsigned long arg)
36445 }
36446
36447 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
36448- unsigned long arg, int ifreq_len)
36449+ unsigned long arg, size_t ifreq_len)
36450 {
36451 struct tun_file *tfile = file->private_data;
36452 struct tun_struct *tun;
36453@@ -1387,6 +1387,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
36454 int vnet_hdr_sz;
36455 int ret;
36456
36457+ if (ifreq_len > sizeof ifr)
36458+ return -EFAULT;
36459+
36460 if (cmd == TUNSETIFF || _IOC_TYPE(cmd) == 0x89) {
36461 if (copy_from_user(&ifr, argp, ifreq_len))
36462 return -EFAULT;
36463diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
36464index 605a4ba..a883dd1 100644
36465--- a/drivers/net/usb/hso.c
36466+++ b/drivers/net/usb/hso.c
36467@@ -71,7 +71,7 @@
36468 #include <asm/byteorder.h>
36469 #include <linux/serial_core.h>
36470 #include <linux/serial.h>
36471-
36472+#include <asm/local.h>
36473
36474 #define MOD_AUTHOR "Option Wireless"
36475 #define MOD_DESCRIPTION "USB High Speed Option driver"
36476@@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
36477 struct urb *urb;
36478
36479 urb = serial->rx_urb[0];
36480- if (serial->port.count > 0) {
36481+ if (atomic_read(&serial->port.count) > 0) {
36482 count = put_rxbuf_data(urb, serial);
36483 if (count == -1)
36484 return;
36485@@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
36486 DUMP1(urb->transfer_buffer, urb->actual_length);
36487
36488 /* Anyone listening? */
36489- if (serial->port.count == 0)
36490+ if (atomic_read(&serial->port.count) == 0)
36491 return;
36492
36493 if (status == 0) {
36494@@ -1298,8 +1298,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
36495 tty_port_tty_set(&serial->port, tty);
36496
36497 /* check for port already opened, if not set the termios */
36498- serial->port.count++;
36499- if (serial->port.count == 1) {
36500+ if (atomic_inc_return(&serial->port.count) == 1) {
36501 serial->rx_state = RX_IDLE;
36502 /* Force default termio settings */
36503 _hso_serial_set_termios(tty, NULL);
36504@@ -1311,7 +1310,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
36505 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
36506 if (result) {
36507 hso_stop_serial_device(serial->parent);
36508- serial->port.count--;
36509+ atomic_dec(&serial->port.count);
36510 kref_put(&serial->parent->ref, hso_serial_ref_free);
36511 }
36512 } else {
36513@@ -1348,10 +1347,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
36514
36515 /* reset the rts and dtr */
36516 /* do the actual close */
36517- serial->port.count--;
36518+ atomic_dec(&serial->port.count);
36519
36520- if (serial->port.count <= 0) {
36521- serial->port.count = 0;
36522+ if (atomic_read(&serial->port.count) <= 0) {
36523+ atomic_set(&serial->port.count, 0);
36524 tty_port_tty_set(&serial->port, NULL);
36525 if (!usb_gone)
36526 hso_stop_serial_device(serial->parent);
36527@@ -1427,7 +1426,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
36528
36529 /* the actual setup */
36530 spin_lock_irqsave(&serial->serial_lock, flags);
36531- if (serial->port.count)
36532+ if (atomic_read(&serial->port.count))
36533 _hso_serial_set_termios(tty, old);
36534 else
36535 tty->termios = *old;
36536@@ -1886,7 +1885,7 @@ static void intr_callback(struct urb *urb)
36537 D1("Pending read interrupt on port %d\n", i);
36538 spin_lock(&serial->serial_lock);
36539 if (serial->rx_state == RX_IDLE &&
36540- serial->port.count > 0) {
36541+ atomic_read(&serial->port.count) > 0) {
36542 /* Setup and send a ctrl req read on
36543 * port i */
36544 if (!serial->rx_urb_filled[0]) {
36545@@ -3078,7 +3077,7 @@ static int hso_resume(struct usb_interface *iface)
36546 /* Start all serial ports */
36547 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
36548 if (serial_table[i] && (serial_table[i]->interface == iface)) {
36549- if (dev2ser(serial_table[i])->port.count) {
36550+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
36551 result =
36552 hso_start_serial_device(serial_table[i], GFP_NOIO);
36553 hso_kick_transmit(dev2ser(serial_table[i]));
36554diff --git a/drivers/net/wimax/i2400m/i2400m.h b/drivers/net/wimax/i2400m/i2400m.h
36555index 79c6505..3d957fd 100644
36556--- a/drivers/net/wimax/i2400m/i2400m.h
36557+++ b/drivers/net/wimax/i2400m/i2400m.h
36558@@ -643,7 +643,7 @@ struct i2400m {
36559 struct i2400m_fw *fw_cached; /* protected by rx_lock */
36560 struct i2400m_barker_db *barker;
36561
36562- struct notifier_block pm_notifier;
36563+ notifier_block_no_const pm_notifier;
36564
36565 /* counting bus reset retries in this boot */
36566 atomic_t bus_reset_retries;
36567diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
36568index 4521342..9f0a994d 100644
36569--- a/drivers/net/wireless/ath/ath.h
36570+++ b/drivers/net/wireless/ath/ath.h
36571@@ -119,6 +119,7 @@ struct ath_ops {
36572 void (*write_flush) (void *);
36573 u32 (*rmw)(void *, u32 reg_offset, u32 set, u32 clr);
36574 };
36575+typedef struct ath_ops __no_const ath_ops_no_const;
36576
36577 struct ath_common;
36578 struct ath_bus_ops;
36579diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
36580index 8d78253..bebbb68 100644
36581--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
36582+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
36583@@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
36584 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
36585 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
36586
36587- ACCESS_ONCE(ads->ds_link) = i->link;
36588- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
36589+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
36590+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
36591
36592 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
36593 ctl6 = SM(i->keytype, AR_EncrType);
36594@@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
36595
36596 if ((i->is_first || i->is_last) &&
36597 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
36598- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
36599+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
36600 | set11nTries(i->rates, 1)
36601 | set11nTries(i->rates, 2)
36602 | set11nTries(i->rates, 3)
36603 | (i->dur_update ? AR_DurUpdateEna : 0)
36604 | SM(0, AR_BurstDur);
36605
36606- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
36607+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
36608 | set11nRate(i->rates, 1)
36609 | set11nRate(i->rates, 2)
36610 | set11nRate(i->rates, 3);
36611 } else {
36612- ACCESS_ONCE(ads->ds_ctl2) = 0;
36613- ACCESS_ONCE(ads->ds_ctl3) = 0;
36614+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
36615+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
36616 }
36617
36618 if (!i->is_first) {
36619- ACCESS_ONCE(ads->ds_ctl0) = 0;
36620- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
36621- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
36622+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
36623+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
36624+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
36625 return;
36626 }
36627
36628@@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
36629 break;
36630 }
36631
36632- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
36633+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
36634 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
36635 | SM(i->txpower, AR_XmitPower)
36636 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
36637@@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
36638 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
36639 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
36640
36641- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
36642- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
36643+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
36644+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
36645
36646 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
36647 return;
36648
36649- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
36650+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
36651 | set11nPktDurRTSCTS(i->rates, 1);
36652
36653- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
36654+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
36655 | set11nPktDurRTSCTS(i->rates, 3);
36656
36657- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
36658+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
36659 | set11nRateFlags(i->rates, 1)
36660 | set11nRateFlags(i->rates, 2)
36661 | set11nRateFlags(i->rates, 3)
36662diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
36663index 301bf72..3f5654f 100644
36664--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
36665+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
36666@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
36667 (i->qcu << AR_TxQcuNum_S) | desc_len;
36668
36669 checksum += val;
36670- ACCESS_ONCE(ads->info) = val;
36671+ ACCESS_ONCE_RW(ads->info) = val;
36672
36673 checksum += i->link;
36674- ACCESS_ONCE(ads->link) = i->link;
36675+ ACCESS_ONCE_RW(ads->link) = i->link;
36676
36677 checksum += i->buf_addr[0];
36678- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
36679+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
36680 checksum += i->buf_addr[1];
36681- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
36682+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
36683 checksum += i->buf_addr[2];
36684- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
36685+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
36686 checksum += i->buf_addr[3];
36687- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
36688+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
36689
36690 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
36691- ACCESS_ONCE(ads->ctl3) = val;
36692+ ACCESS_ONCE_RW(ads->ctl3) = val;
36693 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
36694- ACCESS_ONCE(ads->ctl5) = val;
36695+ ACCESS_ONCE_RW(ads->ctl5) = val;
36696 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
36697- ACCESS_ONCE(ads->ctl7) = val;
36698+ ACCESS_ONCE_RW(ads->ctl7) = val;
36699 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
36700- ACCESS_ONCE(ads->ctl9) = val;
36701+ ACCESS_ONCE_RW(ads->ctl9) = val;
36702
36703 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
36704- ACCESS_ONCE(ads->ctl10) = checksum;
36705+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
36706
36707 if (i->is_first || i->is_last) {
36708- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
36709+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
36710 | set11nTries(i->rates, 1)
36711 | set11nTries(i->rates, 2)
36712 | set11nTries(i->rates, 3)
36713 | (i->dur_update ? AR_DurUpdateEna : 0)
36714 | SM(0, AR_BurstDur);
36715
36716- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
36717+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
36718 | set11nRate(i->rates, 1)
36719 | set11nRate(i->rates, 2)
36720 | set11nRate(i->rates, 3);
36721 } else {
36722- ACCESS_ONCE(ads->ctl13) = 0;
36723- ACCESS_ONCE(ads->ctl14) = 0;
36724+ ACCESS_ONCE_RW(ads->ctl13) = 0;
36725+ ACCESS_ONCE_RW(ads->ctl14) = 0;
36726 }
36727
36728 ads->ctl20 = 0;
36729@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
36730
36731 ctl17 = SM(i->keytype, AR_EncrType);
36732 if (!i->is_first) {
36733- ACCESS_ONCE(ads->ctl11) = 0;
36734- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
36735- ACCESS_ONCE(ads->ctl15) = 0;
36736- ACCESS_ONCE(ads->ctl16) = 0;
36737- ACCESS_ONCE(ads->ctl17) = ctl17;
36738- ACCESS_ONCE(ads->ctl18) = 0;
36739- ACCESS_ONCE(ads->ctl19) = 0;
36740+ ACCESS_ONCE_RW(ads->ctl11) = 0;
36741+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
36742+ ACCESS_ONCE_RW(ads->ctl15) = 0;
36743+ ACCESS_ONCE_RW(ads->ctl16) = 0;
36744+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
36745+ ACCESS_ONCE_RW(ads->ctl18) = 0;
36746+ ACCESS_ONCE_RW(ads->ctl19) = 0;
36747 return;
36748 }
36749
36750- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
36751+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
36752 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
36753 | SM(i->txpower, AR_XmitPower)
36754 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
36755@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
36756 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
36757 ctl12 |= SM(val, AR_PAPRDChainMask);
36758
36759- ACCESS_ONCE(ads->ctl12) = ctl12;
36760- ACCESS_ONCE(ads->ctl17) = ctl17;
36761+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
36762+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
36763
36764- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
36765+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
36766 | set11nPktDurRTSCTS(i->rates, 1);
36767
36768- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
36769+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
36770 | set11nPktDurRTSCTS(i->rates, 3);
36771
36772- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
36773+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
36774 | set11nRateFlags(i->rates, 1)
36775 | set11nRateFlags(i->rates, 2)
36776 | set11nRateFlags(i->rates, 3)
36777 | SM(i->rtscts_rate, AR_RTSCTSRate);
36778
36779- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
36780+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
36781 }
36782
36783 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
36784diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
36785index dbc1b7a..addccc0 100644
36786--- a/drivers/net/wireless/ath/ath9k/hw.h
36787+++ b/drivers/net/wireless/ath/ath9k/hw.h
36788@@ -657,7 +657,7 @@ struct ath_hw_private_ops {
36789
36790 /* ANI */
36791 void (*ani_cache_ini_regs)(struct ath_hw *ah);
36792-};
36793+} __no_const;
36794
36795 /**
36796 * struct ath_hw_ops - callbacks used by hardware code and driver code
36797@@ -687,7 +687,7 @@ struct ath_hw_ops {
36798 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
36799 struct ath_hw_antcomb_conf *antconf);
36800 void (*antctrl_shared_chain_lnadiv)(struct ath_hw *hw, bool enable);
36801-};
36802+} __no_const;
36803
36804 struct ath_nf_limits {
36805 s16 max;
36806@@ -707,7 +707,7 @@ enum ath_cal_list {
36807 #define AH_FASTCC 0x4
36808
36809 struct ath_hw {
36810- struct ath_ops reg_ops;
36811+ ath_ops_no_const reg_ops;
36812
36813 struct ieee80211_hw *hw;
36814 struct ath_common common;
36815diff --git a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
36816index af00e2c..ab04d34 100644
36817--- a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
36818+++ b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
36819@@ -545,7 +545,7 @@ struct phy_func_ptr {
36820 void (*carrsuppr)(struct brcms_phy *);
36821 s32 (*rxsigpwr)(struct brcms_phy *, s32);
36822 void (*detach)(struct brcms_phy *);
36823-};
36824+} __no_const;
36825
36826 struct brcms_phy {
36827 struct brcms_phy_pub pubpi_ro;
36828diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
36829index e252acb..6ad1e65 100644
36830--- a/drivers/net/wireless/iwlegacy/3945-mac.c
36831+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
36832@@ -3615,7 +3615,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
36833 */
36834 if (il3945_mod_params.disable_hw_scan) {
36835 D_INFO("Disabling hw_scan\n");
36836- il3945_mac_ops.hw_scan = NULL;
36837+ pax_open_kernel();
36838+ *(void **)&il3945_mac_ops.hw_scan = NULL;
36839+ pax_close_kernel();
36840 }
36841
36842 D_INFO("*** LOAD DRIVER ***\n");
36843diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
36844index 1a98fa3..51e6661 100644
36845--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
36846+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
36847@@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
36848 {
36849 struct iwl_priv *priv = file->private_data;
36850 char buf[64];
36851- int buf_size;
36852+ size_t buf_size;
36853 u32 offset, len;
36854
36855 memset(buf, 0, sizeof(buf));
36856@@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
36857 struct iwl_priv *priv = file->private_data;
36858
36859 char buf[8];
36860- int buf_size;
36861+ size_t buf_size;
36862 u32 reset_flag;
36863
36864 memset(buf, 0, sizeof(buf));
36865@@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
36866 {
36867 struct iwl_priv *priv = file->private_data;
36868 char buf[8];
36869- int buf_size;
36870+ size_t buf_size;
36871 int ht40;
36872
36873 memset(buf, 0, sizeof(buf));
36874@@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
36875 {
36876 struct iwl_priv *priv = file->private_data;
36877 char buf[8];
36878- int buf_size;
36879+ size_t buf_size;
36880 int value;
36881
36882 memset(buf, 0, sizeof(buf));
36883@@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
36884 {
36885 struct iwl_priv *priv = file->private_data;
36886 char buf[8];
36887- int buf_size;
36888+ size_t buf_size;
36889 int clear;
36890
36891 memset(buf, 0, sizeof(buf));
36892@@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
36893 {
36894 struct iwl_priv *priv = file->private_data;
36895 char buf[8];
36896- int buf_size;
36897+ size_t buf_size;
36898 int trace;
36899
36900 memset(buf, 0, sizeof(buf));
36901@@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
36902 {
36903 struct iwl_priv *priv = file->private_data;
36904 char buf[8];
36905- int buf_size;
36906+ size_t buf_size;
36907 int missed;
36908
36909 memset(buf, 0, sizeof(buf));
36910@@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
36911
36912 struct iwl_priv *priv = file->private_data;
36913 char buf[8];
36914- int buf_size;
36915+ size_t buf_size;
36916 int plcp;
36917
36918 memset(buf, 0, sizeof(buf));
36919@@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
36920
36921 struct iwl_priv *priv = file->private_data;
36922 char buf[8];
36923- int buf_size;
36924+ size_t buf_size;
36925 int flush;
36926
36927 memset(buf, 0, sizeof(buf));
36928@@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
36929
36930 struct iwl_priv *priv = file->private_data;
36931 char buf[8];
36932- int buf_size;
36933+ size_t buf_size;
36934 int rts;
36935
36936 if (!priv->cfg->ht_params)
36937@@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
36938 {
36939 struct iwl_priv *priv = file->private_data;
36940 char buf[8];
36941- int buf_size;
36942+ size_t buf_size;
36943
36944 memset(buf, 0, sizeof(buf));
36945 buf_size = min(count, sizeof(buf) - 1);
36946@@ -2256,7 +2256,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
36947 struct iwl_priv *priv = file->private_data;
36948 u32 event_log_flag;
36949 char buf[8];
36950- int buf_size;
36951+ size_t buf_size;
36952
36953 /* check that the interface is up */
36954 if (!iwl_is_ready(priv))
36955@@ -2310,7 +2310,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
36956 struct iwl_priv *priv = file->private_data;
36957 char buf[8];
36958 u32 calib_disabled;
36959- int buf_size;
36960+ size_t buf_size;
36961
36962 memset(buf, 0, sizeof(buf));
36963 buf_size = min(count, sizeof(buf) - 1);
36964diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
36965index fe0fffd..b4c5724 100644
36966--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
36967+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
36968@@ -1967,7 +1967,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
36969 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
36970
36971 char buf[8];
36972- int buf_size;
36973+ size_t buf_size;
36974 u32 reset_flag;
36975
36976 memset(buf, 0, sizeof(buf));
36977@@ -1988,7 +1988,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
36978 {
36979 struct iwl_trans *trans = file->private_data;
36980 char buf[8];
36981- int buf_size;
36982+ size_t buf_size;
36983 int csr;
36984
36985 memset(buf, 0, sizeof(buf));
36986diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
36987index 429ca32..f86236b 100644
36988--- a/drivers/net/wireless/mac80211_hwsim.c
36989+++ b/drivers/net/wireless/mac80211_hwsim.c
36990@@ -1751,9 +1751,11 @@ static int __init init_mac80211_hwsim(void)
36991 return -EINVAL;
36992
36993 if (fake_hw_scan) {
36994- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
36995- mac80211_hwsim_ops.sw_scan_start = NULL;
36996- mac80211_hwsim_ops.sw_scan_complete = NULL;
36997+ pax_open_kernel();
36998+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
36999+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
37000+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
37001+ pax_close_kernel();
37002 }
37003
37004 spin_lock_init(&hwsim_radio_lock);
37005diff --git a/drivers/net/wireless/mwifiex/main.h b/drivers/net/wireless/mwifiex/main.h
37006index c2d0ab1..fb9afe2 100644
37007--- a/drivers/net/wireless/mwifiex/main.h
37008+++ b/drivers/net/wireless/mwifiex/main.h
37009@@ -603,7 +603,7 @@ struct mwifiex_if_ops {
37010 int (*event_complete) (struct mwifiex_adapter *, struct sk_buff *);
37011 int (*data_complete) (struct mwifiex_adapter *, struct sk_buff *);
37012 int (*dnld_fw) (struct mwifiex_adapter *, struct mwifiex_fw_image *);
37013-};
37014+} __no_const;
37015
37016 struct mwifiex_adapter {
37017 u8 iface_type;
37018diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
37019index bd1f0cb..db85ab0 100644
37020--- a/drivers/net/wireless/rndis_wlan.c
37021+++ b/drivers/net/wireless/rndis_wlan.c
37022@@ -1235,7 +1235,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
37023
37024 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
37025
37026- if (rts_threshold < 0 || rts_threshold > 2347)
37027+ if (rts_threshold > 2347)
37028 rts_threshold = 2347;
37029
37030 tmp = cpu_to_le32(rts_threshold);
37031diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
37032index 0751b35..246ba3e 100644
37033--- a/drivers/net/wireless/rt2x00/rt2x00.h
37034+++ b/drivers/net/wireless/rt2x00/rt2x00.h
37035@@ -398,7 +398,7 @@ struct rt2x00_intf {
37036 * for hardware which doesn't support hardware
37037 * sequence counting.
37038 */
37039- atomic_t seqno;
37040+ atomic_unchecked_t seqno;
37041 };
37042
37043 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
37044diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
37045index e488b94..14b6a0c 100644
37046--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
37047+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
37048@@ -240,9 +240,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
37049 * sequence counter given by mac80211.
37050 */
37051 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
37052- seqno = atomic_add_return(0x10, &intf->seqno);
37053+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
37054 else
37055- seqno = atomic_read(&intf->seqno);
37056+ seqno = atomic_read_unchecked(&intf->seqno);
37057
37058 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
37059 hdr->seq_ctrl |= cpu_to_le16(seqno);
37060diff --git a/drivers/net/wireless/ti/wl1251/wl1251.h b/drivers/net/wireless/ti/wl1251/wl1251.h
37061index fd02060..74ee481 100644
37062--- a/drivers/net/wireless/ti/wl1251/wl1251.h
37063+++ b/drivers/net/wireless/ti/wl1251/wl1251.h
37064@@ -266,7 +266,7 @@ struct wl1251_if_operations {
37065 void (*reset)(struct wl1251 *wl);
37066 void (*enable_irq)(struct wl1251 *wl);
37067 void (*disable_irq)(struct wl1251 *wl);
37068-};
37069+} __no_const;
37070
37071 struct wl1251 {
37072 struct ieee80211_hw *hw;
37073diff --git a/drivers/net/wireless/ti/wlcore/wlcore.h b/drivers/net/wireless/ti/wlcore/wlcore.h
37074index 68584aa..10fc178 100644
37075--- a/drivers/net/wireless/ti/wlcore/wlcore.h
37076+++ b/drivers/net/wireless/ti/wlcore/wlcore.h
37077@@ -88,7 +88,7 @@ struct wlcore_ops {
37078 struct ieee80211_sta *sta,
37079 struct ieee80211_key_conf *key_conf);
37080 u32 (*pre_pkt_send)(struct wl1271 *wl, u32 buf_offset, u32 last_len);
37081-};
37082+} __no_const;
37083
37084 enum wlcore_partitions {
37085 PART_DOWN,
37086diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
37087index d93b2b6..ae50401 100644
37088--- a/drivers/oprofile/buffer_sync.c
37089+++ b/drivers/oprofile/buffer_sync.c
37090@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
37091 if (cookie == NO_COOKIE)
37092 offset = pc;
37093 if (cookie == INVALID_COOKIE) {
37094- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
37095+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
37096 offset = pc;
37097 }
37098 if (cookie != last_cookie) {
37099@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
37100 /* add userspace sample */
37101
37102 if (!mm) {
37103- atomic_inc(&oprofile_stats.sample_lost_no_mm);
37104+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
37105 return 0;
37106 }
37107
37108 cookie = lookup_dcookie(mm, s->eip, &offset);
37109
37110 if (cookie == INVALID_COOKIE) {
37111- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
37112+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
37113 return 0;
37114 }
37115
37116@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
37117 /* ignore backtraces if failed to add a sample */
37118 if (state == sb_bt_start) {
37119 state = sb_bt_ignore;
37120- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
37121+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
37122 }
37123 }
37124 release_mm(mm);
37125diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
37126index c0cc4e7..44d4e54 100644
37127--- a/drivers/oprofile/event_buffer.c
37128+++ b/drivers/oprofile/event_buffer.c
37129@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
37130 }
37131
37132 if (buffer_pos == buffer_size) {
37133- atomic_inc(&oprofile_stats.event_lost_overflow);
37134+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
37135 return;
37136 }
37137
37138diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
37139index ed2c3ec..deda85a 100644
37140--- a/drivers/oprofile/oprof.c
37141+++ b/drivers/oprofile/oprof.c
37142@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
37143 if (oprofile_ops.switch_events())
37144 return;
37145
37146- atomic_inc(&oprofile_stats.multiplex_counter);
37147+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
37148 start_switch_worker();
37149 }
37150
37151diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
37152index 917d28e..d62d981 100644
37153--- a/drivers/oprofile/oprofile_stats.c
37154+++ b/drivers/oprofile/oprofile_stats.c
37155@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
37156 cpu_buf->sample_invalid_eip = 0;
37157 }
37158
37159- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
37160- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
37161- atomic_set(&oprofile_stats.event_lost_overflow, 0);
37162- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
37163- atomic_set(&oprofile_stats.multiplex_counter, 0);
37164+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
37165+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
37166+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
37167+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
37168+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
37169 }
37170
37171
37172diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
37173index 38b6fc0..b5cbfce 100644
37174--- a/drivers/oprofile/oprofile_stats.h
37175+++ b/drivers/oprofile/oprofile_stats.h
37176@@ -13,11 +13,11 @@
37177 #include <linux/atomic.h>
37178
37179 struct oprofile_stat_struct {
37180- atomic_t sample_lost_no_mm;
37181- atomic_t sample_lost_no_mapping;
37182- atomic_t bt_lost_no_mapping;
37183- atomic_t event_lost_overflow;
37184- atomic_t multiplex_counter;
37185+ atomic_unchecked_t sample_lost_no_mm;
37186+ atomic_unchecked_t sample_lost_no_mapping;
37187+ atomic_unchecked_t bt_lost_no_mapping;
37188+ atomic_unchecked_t event_lost_overflow;
37189+ atomic_unchecked_t multiplex_counter;
37190 };
37191
37192 extern struct oprofile_stat_struct oprofile_stats;
37193diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
37194index 849357c..b83c1e0 100644
37195--- a/drivers/oprofile/oprofilefs.c
37196+++ b/drivers/oprofile/oprofilefs.c
37197@@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
37198
37199
37200 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
37201- char const *name, atomic_t *val)
37202+ char const *name, atomic_unchecked_t *val)
37203 {
37204 return __oprofilefs_create_file(sb, root, name,
37205 &atomic_ro_fops, 0444, val);
37206diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
37207index 3f56bc0..707d642 100644
37208--- a/drivers/parport/procfs.c
37209+++ b/drivers/parport/procfs.c
37210@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
37211
37212 *ppos += len;
37213
37214- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
37215+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
37216 }
37217
37218 #ifdef CONFIG_PARPORT_1284
37219@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
37220
37221 *ppos += len;
37222
37223- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
37224+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
37225 }
37226 #endif /* IEEE1284.3 support. */
37227
37228diff --git a/drivers/pci/hotplug/acpiphp.h b/drivers/pci/hotplug/acpiphp.h
37229index a1afb5b..e6baac9 100644
37230--- a/drivers/pci/hotplug/acpiphp.h
37231+++ b/drivers/pci/hotplug/acpiphp.h
37232@@ -123,7 +123,7 @@ struct acpiphp_func {
37233 struct acpiphp_bridge *bridge; /* Ejectable PCI-to-PCI bridge */
37234
37235 struct list_head sibling;
37236- struct notifier_block nb;
37237+ notifier_block_no_const nb;
37238 acpi_handle handle;
37239
37240 u8 function; /* pci function# */
37241diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
37242index 9fff878..ad0ad53 100644
37243--- a/drivers/pci/hotplug/cpci_hotplug.h
37244+++ b/drivers/pci/hotplug/cpci_hotplug.h
37245@@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
37246 int (*hardware_test) (struct slot* slot, u32 value);
37247 u8 (*get_power) (struct slot* slot);
37248 int (*set_power) (struct slot* slot, int value);
37249-};
37250+} __no_const;
37251
37252 struct cpci_hp_controller {
37253 unsigned int irq;
37254diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
37255index 76ba8a1..20ca857 100644
37256--- a/drivers/pci/hotplug/cpqphp_nvram.c
37257+++ b/drivers/pci/hotplug/cpqphp_nvram.c
37258@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
37259
37260 void compaq_nvram_init (void __iomem *rom_start)
37261 {
37262+
37263+#ifndef CONFIG_PAX_KERNEXEC
37264 if (rom_start) {
37265 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
37266 }
37267+#endif
37268+
37269 dbg("int15 entry = %p\n", compaq_int15_entry_point);
37270
37271 /* initialize our int15 lock */
37272diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
37273index 213753b..b4abaac 100644
37274--- a/drivers/pci/pcie/aspm.c
37275+++ b/drivers/pci/pcie/aspm.c
37276@@ -27,9 +27,9 @@
37277 #define MODULE_PARAM_PREFIX "pcie_aspm."
37278
37279 /* Note: those are not register definitions */
37280-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
37281-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
37282-#define ASPM_STATE_L1 (4) /* L1 state */
37283+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
37284+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
37285+#define ASPM_STATE_L1 (4U) /* L1 state */
37286 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
37287 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
37288
37289diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
37290index ec909af..e7517f3 100644
37291--- a/drivers/pci/probe.c
37292+++ b/drivers/pci/probe.c
37293@@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
37294 struct pci_bus_region region;
37295 bool bar_too_big = false, bar_disabled = false;
37296
37297- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
37298+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
37299
37300 /* No printks while decoding is disabled! */
37301 if (!dev->mmio_always_on) {
37302diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
37303index 9b8505c..f00870a 100644
37304--- a/drivers/pci/proc.c
37305+++ b/drivers/pci/proc.c
37306@@ -465,7 +465,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
37307 static int __init pci_proc_init(void)
37308 {
37309 struct pci_dev *dev = NULL;
37310+
37311+#ifdef CONFIG_GRKERNSEC_PROC_ADD
37312+#ifdef CONFIG_GRKERNSEC_PROC_USER
37313+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
37314+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
37315+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
37316+#endif
37317+#else
37318 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
37319+#endif
37320 proc_create("devices", 0, proc_bus_pci_dir,
37321 &proc_bus_pci_dev_operations);
37322 proc_initialized = 1;
37323diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
37324index 75dd651..2af4c9a 100644
37325--- a/drivers/platform/x86/thinkpad_acpi.c
37326+++ b/drivers/platform/x86/thinkpad_acpi.c
37327@@ -2097,7 +2097,7 @@ static int hotkey_mask_get(void)
37328 return 0;
37329 }
37330
37331-void static hotkey_mask_warn_incomplete_mask(void)
37332+static void hotkey_mask_warn_incomplete_mask(void)
37333 {
37334 /* log only what the user can fix... */
37335 const u32 wantedmask = hotkey_driver_mask &
37336@@ -2328,11 +2328,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
37337 }
37338 }
37339
37340-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
37341- struct tp_nvram_state *newn,
37342- const u32 event_mask)
37343-{
37344-
37345 #define TPACPI_COMPARE_KEY(__scancode, __member) \
37346 do { \
37347 if ((event_mask & (1 << __scancode)) && \
37348@@ -2346,36 +2341,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
37349 tpacpi_hotkey_send_key(__scancode); \
37350 } while (0)
37351
37352- void issue_volchange(const unsigned int oldvol,
37353- const unsigned int newvol)
37354- {
37355- unsigned int i = oldvol;
37356+static void issue_volchange(const unsigned int oldvol,
37357+ const unsigned int newvol,
37358+ const u32 event_mask)
37359+{
37360+ unsigned int i = oldvol;
37361
37362- while (i > newvol) {
37363- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
37364- i--;
37365- }
37366- while (i < newvol) {
37367- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
37368- i++;
37369- }
37370+ while (i > newvol) {
37371+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
37372+ i--;
37373 }
37374+ while (i < newvol) {
37375+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
37376+ i++;
37377+ }
37378+}
37379
37380- void issue_brightnesschange(const unsigned int oldbrt,
37381- const unsigned int newbrt)
37382- {
37383- unsigned int i = oldbrt;
37384+static void issue_brightnesschange(const unsigned int oldbrt,
37385+ const unsigned int newbrt,
37386+ const u32 event_mask)
37387+{
37388+ unsigned int i = oldbrt;
37389
37390- while (i > newbrt) {
37391- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
37392- i--;
37393- }
37394- while (i < newbrt) {
37395- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
37396- i++;
37397- }
37398+ while (i > newbrt) {
37399+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
37400+ i--;
37401+ }
37402+ while (i < newbrt) {
37403+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
37404+ i++;
37405 }
37406+}
37407
37408+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
37409+ struct tp_nvram_state *newn,
37410+ const u32 event_mask)
37411+{
37412 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
37413 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
37414 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
37415@@ -2409,7 +2410,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
37416 oldn->volume_level != newn->volume_level) {
37417 /* recently muted, or repeated mute keypress, or
37418 * multiple presses ending in mute */
37419- issue_volchange(oldn->volume_level, newn->volume_level);
37420+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
37421 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
37422 }
37423 } else {
37424@@ -2419,7 +2420,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
37425 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
37426 }
37427 if (oldn->volume_level != newn->volume_level) {
37428- issue_volchange(oldn->volume_level, newn->volume_level);
37429+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
37430 } else if (oldn->volume_toggle != newn->volume_toggle) {
37431 /* repeated vol up/down keypress at end of scale ? */
37432 if (newn->volume_level == 0)
37433@@ -2432,7 +2433,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
37434 /* handle brightness */
37435 if (oldn->brightness_level != newn->brightness_level) {
37436 issue_brightnesschange(oldn->brightness_level,
37437- newn->brightness_level);
37438+ newn->brightness_level,
37439+ event_mask);
37440 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
37441 /* repeated key presses that didn't change state */
37442 if (newn->brightness_level == 0)
37443@@ -2441,10 +2443,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
37444 && !tp_features.bright_unkfw)
37445 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
37446 }
37447+}
37448
37449 #undef TPACPI_COMPARE_KEY
37450 #undef TPACPI_MAY_SEND_KEY
37451-}
37452
37453 /*
37454 * Polling driver
37455diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
37456index 769d265..a3a05ca 100644
37457--- a/drivers/pnp/pnpbios/bioscalls.c
37458+++ b/drivers/pnp/pnpbios/bioscalls.c
37459@@ -58,7 +58,7 @@ do { \
37460 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
37461 } while(0)
37462
37463-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
37464+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
37465 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
37466
37467 /*
37468@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
37469
37470 cpu = get_cpu();
37471 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
37472+
37473+ pax_open_kernel();
37474 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
37475+ pax_close_kernel();
37476
37477 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
37478 spin_lock_irqsave(&pnp_bios_lock, flags);
37479@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
37480 :"memory");
37481 spin_unlock_irqrestore(&pnp_bios_lock, flags);
37482
37483+ pax_open_kernel();
37484 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
37485+ pax_close_kernel();
37486+
37487 put_cpu();
37488
37489 /* If we get here and this is set then the PnP BIOS faulted on us. */
37490@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
37491 return status;
37492 }
37493
37494-void pnpbios_calls_init(union pnp_bios_install_struct *header)
37495+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
37496 {
37497 int i;
37498
37499@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
37500 pnp_bios_callpoint.offset = header->fields.pm16offset;
37501 pnp_bios_callpoint.segment = PNP_CS16;
37502
37503+ pax_open_kernel();
37504+
37505 for_each_possible_cpu(i) {
37506 struct desc_struct *gdt = get_cpu_gdt_table(i);
37507 if (!gdt)
37508@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
37509 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
37510 (unsigned long)__va(header->fields.pm16dseg));
37511 }
37512+
37513+ pax_close_kernel();
37514 }
37515diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
37516index b0ecacb..7c9da2e 100644
37517--- a/drivers/pnp/resource.c
37518+++ b/drivers/pnp/resource.c
37519@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
37520 return 1;
37521
37522 /* check if the resource is valid */
37523- if (*irq < 0 || *irq > 15)
37524+ if (*irq > 15)
37525 return 0;
37526
37527 /* check if the resource is reserved */
37528@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
37529 return 1;
37530
37531 /* check if the resource is valid */
37532- if (*dma < 0 || *dma == 4 || *dma > 7)
37533+ if (*dma == 4 || *dma > 7)
37534 return 0;
37535
37536 /* check if the resource is reserved */
37537diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
37538index 5860d4d..d90d268 100644
37539--- a/drivers/power/bq27x00_battery.c
37540+++ b/drivers/power/bq27x00_battery.c
37541@@ -80,7 +80,7 @@
37542 struct bq27x00_device_info;
37543 struct bq27x00_access_methods {
37544 int (*read)(struct bq27x00_device_info *di, u8 reg, bool single);
37545-};
37546+} __no_const;
37547
37548 enum bq27x00_chip { BQ27000, BQ27500, BQ27425};
37549
37550diff --git a/drivers/power/da9030_battery.c b/drivers/power/da9030_battery.c
37551index 94762e6..d35ff48 100644
37552--- a/drivers/power/da9030_battery.c
37553+++ b/drivers/power/da9030_battery.c
37554@@ -110,7 +110,7 @@ struct da9030_charger {
37555 int mV;
37556 bool is_on;
37557
37558- struct notifier_block nb;
37559+ notifier_block_no_const nb;
37560
37561 /* platform callbacks for battery low and critical events */
37562 void (*battery_low)(void);
37563diff --git a/drivers/power/da9052-battery.c b/drivers/power/da9052-battery.c
37564index d9d034d..3c9a5e1 100644
37565--- a/drivers/power/da9052-battery.c
37566+++ b/drivers/power/da9052-battery.c
37567@@ -170,7 +170,7 @@ static u32 const vc_tbl[3][68][2] = {
37568 struct da9052_battery {
37569 struct da9052 *da9052;
37570 struct power_supply psy;
37571- struct notifier_block nb;
37572+ notifier_block_no_const nb;
37573 int charger_type;
37574 int status;
37575 int health;
37576diff --git a/drivers/power/isp1704_charger.c b/drivers/power/isp1704_charger.c
37577index 1229119..f53b75d 100644
37578--- a/drivers/power/isp1704_charger.c
37579+++ b/drivers/power/isp1704_charger.c
37580@@ -57,7 +57,7 @@ struct isp1704_charger {
37581 struct device *dev;
37582 struct power_supply psy;
37583 struct usb_phy *phy;
37584- struct notifier_block nb;
37585+ notifier_block_no_const nb;
37586 struct work_struct work;
37587
37588 /* properties */
37589diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
37590index 7df7c5f..bd48c47 100644
37591--- a/drivers/power/pda_power.c
37592+++ b/drivers/power/pda_power.c
37593@@ -37,7 +37,11 @@ static int polling;
37594
37595 #ifdef CONFIG_USB_OTG_UTILS
37596 static struct usb_phy *transceiver;
37597-static struct notifier_block otg_nb;
37598+static int otg_handle_notification(struct notifier_block *nb,
37599+ unsigned long event, void *unused);
37600+static struct notifier_block otg_nb = {
37601+ .notifier_call = otg_handle_notification
37602+};
37603 #endif
37604
37605 static struct regulator *ac_draw;
37606@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
37607
37608 #ifdef CONFIG_USB_OTG_UTILS
37609 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
37610- otg_nb.notifier_call = otg_handle_notification;
37611 ret = usb_register_notifier(transceiver, &otg_nb);
37612 if (ret) {
37613 dev_err(dev, "failure to register otg notifier\n");
37614diff --git a/drivers/power/twl4030_charger.c b/drivers/power/twl4030_charger.c
37615index f9e70cf..2a21d8b 100644
37616--- a/drivers/power/twl4030_charger.c
37617+++ b/drivers/power/twl4030_charger.c
37618@@ -84,7 +84,7 @@ struct twl4030_bci {
37619 struct power_supply ac;
37620 struct power_supply usb;
37621 struct usb_phy *transceiver;
37622- struct notifier_block usb_nb;
37623+ notifier_block_no_const usb_nb;
37624 struct work_struct work;
37625 int irq_chg;
37626 int irq_bci;
37627diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
37628index 8d53174..04c65de 100644
37629--- a/drivers/regulator/max8660.c
37630+++ b/drivers/regulator/max8660.c
37631@@ -333,8 +333,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
37632 max8660->shadow_regs[MAX8660_OVER1] = 5;
37633 } else {
37634 /* Otherwise devices can be toggled via software */
37635- max8660_dcdc_ops.enable = max8660_dcdc_enable;
37636- max8660_dcdc_ops.disable = max8660_dcdc_disable;
37637+ pax_open_kernel();
37638+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
37639+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
37640+ pax_close_kernel();
37641 }
37642
37643 /*
37644diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
37645index 1fa6381..f58834e 100644
37646--- a/drivers/regulator/mc13892-regulator.c
37647+++ b/drivers/regulator/mc13892-regulator.c
37648@@ -540,10 +540,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
37649 }
37650 mc13xxx_unlock(mc13892);
37651
37652- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
37653+ pax_open_kernel();
37654+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
37655 = mc13892_vcam_set_mode;
37656- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
37657+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
37658 = mc13892_vcam_get_mode;
37659+ pax_close_kernel();
37660
37661 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
37662 ARRAY_SIZE(mc13892_regulators));
37663diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
37664index cace6d3..f623fda 100644
37665--- a/drivers/rtc/rtc-dev.c
37666+++ b/drivers/rtc/rtc-dev.c
37667@@ -14,6 +14,7 @@
37668 #include <linux/module.h>
37669 #include <linux/rtc.h>
37670 #include <linux/sched.h>
37671+#include <linux/grsecurity.h>
37672 #include "rtc-core.h"
37673
37674 static dev_t rtc_devt;
37675@@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
37676 if (copy_from_user(&tm, uarg, sizeof(tm)))
37677 return -EFAULT;
37678
37679+ gr_log_timechange();
37680+
37681 return rtc_set_time(rtc, &tm);
37682
37683 case RTC_PIE_ON:
37684diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
37685index 9e933a8..4f969f7 100644
37686--- a/drivers/scsi/aacraid/aacraid.h
37687+++ b/drivers/scsi/aacraid/aacraid.h
37688@@ -503,7 +503,7 @@ struct adapter_ops
37689 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
37690 /* Administrative operations */
37691 int (*adapter_comm)(struct aac_dev * dev, int comm);
37692-};
37693+} __no_const;
37694
37695 /*
37696 * Define which interrupt handler needs to be installed
37697diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
37698index 4ad7e36..d004679 100644
37699--- a/drivers/scsi/bfa/bfa.h
37700+++ b/drivers/scsi/bfa/bfa.h
37701@@ -196,7 +196,7 @@ struct bfa_hwif_s {
37702 u32 *end);
37703 int cpe_vec_q0;
37704 int rme_vec_q0;
37705-};
37706+} __no_const;
37707 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
37708
37709 struct bfa_faa_cbfn_s {
37710diff --git a/drivers/scsi/bfa/bfa_fcpim.c b/drivers/scsi/bfa/bfa_fcpim.c
37711index 27b5609..e08d9c4 100644
37712--- a/drivers/scsi/bfa/bfa_fcpim.c
37713+++ b/drivers/scsi/bfa/bfa_fcpim.c
37714@@ -3731,7 +3731,7 @@ bfa_fcp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
37715
37716 bfa_iotag_attach(fcp);
37717
37718- fcp->itn_arr = (struct bfa_itn_s *) bfa_mem_kva_curp(fcp);
37719+ fcp->itn_arr = (bfa_itn_s_no_const *) bfa_mem_kva_curp(fcp);
37720 bfa_mem_kva_curp(fcp) = (u8 *)fcp->itn_arr +
37721 (fcp->num_itns * sizeof(struct bfa_itn_s));
37722 memset(fcp->itn_arr, 0,
37723@@ -3799,7 +3799,7 @@ bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
37724 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m))
37725 {
37726 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
37727- struct bfa_itn_s *itn;
37728+ bfa_itn_s_no_const *itn;
37729
37730 itn = BFA_ITN_FROM_TAG(fcp, rport->rport_tag);
37731 itn->isr = isr;
37732diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
37733index e693af6..4faba24 100644
37734--- a/drivers/scsi/bfa/bfa_fcpim.h
37735+++ b/drivers/scsi/bfa/bfa_fcpim.h
37736@@ -37,6 +37,7 @@ struct bfa_iotag_s {
37737 struct bfa_itn_s {
37738 bfa_isr_func_t isr;
37739 };
37740+typedef struct bfa_itn_s __no_const bfa_itn_s_no_const;
37741
37742 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
37743 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
37744@@ -149,7 +150,7 @@ struct bfa_fcp_mod_s {
37745 struct list_head iotag_tio_free_q; /* free IO resources */
37746 struct list_head iotag_unused_q; /* unused IO resources*/
37747 struct bfa_iotag_s *iotag_arr;
37748- struct bfa_itn_s *itn_arr;
37749+ bfa_itn_s_no_const *itn_arr;
37750 int max_ioim_reqs;
37751 int num_ioim_reqs;
37752 int num_fwtio_reqs;
37753diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
37754index 23a90e7..9cf04ee 100644
37755--- a/drivers/scsi/bfa/bfa_ioc.h
37756+++ b/drivers/scsi/bfa/bfa_ioc.h
37757@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
37758 bfa_ioc_disable_cbfn_t disable_cbfn;
37759 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
37760 bfa_ioc_reset_cbfn_t reset_cbfn;
37761-};
37762+} __no_const;
37763
37764 /*
37765 * IOC event notification mechanism.
37766@@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
37767 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
37768 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
37769 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
37770-};
37771+} __no_const;
37772
37773 /*
37774 * Queue element to wait for room in request queue. FIFO order is
37775diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
37776index 593085a..47aa999 100644
37777--- a/drivers/scsi/hosts.c
37778+++ b/drivers/scsi/hosts.c
37779@@ -42,7 +42,7 @@
37780 #include "scsi_logging.h"
37781
37782
37783-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
37784+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
37785
37786
37787 static void scsi_host_cls_release(struct device *dev)
37788@@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
37789 * subtract one because we increment first then return, but we need to
37790 * know what the next host number was before increment
37791 */
37792- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
37793+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
37794 shost->dma_channel = 0xff;
37795
37796 /* These three are default values which can be overridden */
37797diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
37798index 4217e49..9c77e3e 100644
37799--- a/drivers/scsi/hpsa.c
37800+++ b/drivers/scsi/hpsa.c
37801@@ -554,7 +554,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
37802 unsigned long flags;
37803
37804 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
37805- return h->access.command_completed(h, q);
37806+ return h->access->command_completed(h, q);
37807
37808 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
37809 a = rq->head[rq->current_entry];
37810@@ -3374,7 +3374,7 @@ static void start_io(struct ctlr_info *h)
37811 while (!list_empty(&h->reqQ)) {
37812 c = list_entry(h->reqQ.next, struct CommandList, list);
37813 /* can't do anything if fifo is full */
37814- if ((h->access.fifo_full(h))) {
37815+ if ((h->access->fifo_full(h))) {
37816 dev_warn(&h->pdev->dev, "fifo full\n");
37817 break;
37818 }
37819@@ -3396,7 +3396,7 @@ static void start_io(struct ctlr_info *h)
37820
37821 /* Tell the controller execute command */
37822 spin_unlock_irqrestore(&h->lock, flags);
37823- h->access.submit_command(h, c);
37824+ h->access->submit_command(h, c);
37825 spin_lock_irqsave(&h->lock, flags);
37826 }
37827 spin_unlock_irqrestore(&h->lock, flags);
37828@@ -3404,17 +3404,17 @@ static void start_io(struct ctlr_info *h)
37829
37830 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
37831 {
37832- return h->access.command_completed(h, q);
37833+ return h->access->command_completed(h, q);
37834 }
37835
37836 static inline bool interrupt_pending(struct ctlr_info *h)
37837 {
37838- return h->access.intr_pending(h);
37839+ return h->access->intr_pending(h);
37840 }
37841
37842 static inline long interrupt_not_for_us(struct ctlr_info *h)
37843 {
37844- return (h->access.intr_pending(h) == 0) ||
37845+ return (h->access->intr_pending(h) == 0) ||
37846 (h->interrupts_enabled == 0);
37847 }
37848
37849@@ -4318,7 +4318,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
37850 if (prod_index < 0)
37851 return -ENODEV;
37852 h->product_name = products[prod_index].product_name;
37853- h->access = *(products[prod_index].access);
37854+ h->access = products[prod_index].access;
37855
37856 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
37857 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
37858@@ -4600,7 +4600,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
37859
37860 assert_spin_locked(&lockup_detector_lock);
37861 remove_ctlr_from_lockup_detector_list(h);
37862- h->access.set_intr_mask(h, HPSA_INTR_OFF);
37863+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
37864 spin_lock_irqsave(&h->lock, flags);
37865 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
37866 spin_unlock_irqrestore(&h->lock, flags);
37867@@ -4778,7 +4778,7 @@ reinit_after_soft_reset:
37868 }
37869
37870 /* make sure the board interrupts are off */
37871- h->access.set_intr_mask(h, HPSA_INTR_OFF);
37872+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
37873
37874 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
37875 goto clean2;
37876@@ -4812,7 +4812,7 @@ reinit_after_soft_reset:
37877 * fake ones to scoop up any residual completions.
37878 */
37879 spin_lock_irqsave(&h->lock, flags);
37880- h->access.set_intr_mask(h, HPSA_INTR_OFF);
37881+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
37882 spin_unlock_irqrestore(&h->lock, flags);
37883 free_irqs(h);
37884 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
37885@@ -4831,9 +4831,9 @@ reinit_after_soft_reset:
37886 dev_info(&h->pdev->dev, "Board READY.\n");
37887 dev_info(&h->pdev->dev,
37888 "Waiting for stale completions to drain.\n");
37889- h->access.set_intr_mask(h, HPSA_INTR_ON);
37890+ h->access->set_intr_mask(h, HPSA_INTR_ON);
37891 msleep(10000);
37892- h->access.set_intr_mask(h, HPSA_INTR_OFF);
37893+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
37894
37895 rc = controller_reset_failed(h->cfgtable);
37896 if (rc)
37897@@ -4854,7 +4854,7 @@ reinit_after_soft_reset:
37898 }
37899
37900 /* Turn the interrupts on so we can service requests */
37901- h->access.set_intr_mask(h, HPSA_INTR_ON);
37902+ h->access->set_intr_mask(h, HPSA_INTR_ON);
37903
37904 hpsa_hba_inquiry(h);
37905 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
37906@@ -4906,7 +4906,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
37907 * To write all data in the battery backed cache to disks
37908 */
37909 hpsa_flush_cache(h);
37910- h->access.set_intr_mask(h, HPSA_INTR_OFF);
37911+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
37912 hpsa_free_irqs_and_disable_msix(h);
37913 }
37914
37915@@ -5075,7 +5075,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
37916 return;
37917 }
37918 /* Change the access methods to the performant access methods */
37919- h->access = SA5_performant_access;
37920+ h->access = &SA5_performant_access;
37921 h->transMethod = CFGTBL_Trans_Performant;
37922 }
37923
37924diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
37925index 9816479..c5d4e97 100644
37926--- a/drivers/scsi/hpsa.h
37927+++ b/drivers/scsi/hpsa.h
37928@@ -79,7 +79,7 @@ struct ctlr_info {
37929 unsigned int msix_vector;
37930 unsigned int msi_vector;
37931 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
37932- struct access_method access;
37933+ struct access_method *access;
37934
37935 /* queue and queue Info */
37936 struct list_head reqQ;
37937diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
37938index f2df059..a3a9930 100644
37939--- a/drivers/scsi/ips.h
37940+++ b/drivers/scsi/ips.h
37941@@ -1027,7 +1027,7 @@ typedef struct {
37942 int (*intr)(struct ips_ha *);
37943 void (*enableint)(struct ips_ha *);
37944 uint32_t (*statupd)(struct ips_ha *);
37945-} ips_hw_func_t;
37946+} __no_const ips_hw_func_t;
37947
37948 typedef struct ips_ha {
37949 uint8_t ha_id[IPS_MAX_CHANNELS+1];
37950diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
37951index c772d8d..35c362c 100644
37952--- a/drivers/scsi/libfc/fc_exch.c
37953+++ b/drivers/scsi/libfc/fc_exch.c
37954@@ -100,12 +100,12 @@ struct fc_exch_mgr {
37955 u16 pool_max_index;
37956
37957 struct {
37958- atomic_t no_free_exch;
37959- atomic_t no_free_exch_xid;
37960- atomic_t xid_not_found;
37961- atomic_t xid_busy;
37962- atomic_t seq_not_found;
37963- atomic_t non_bls_resp;
37964+ atomic_unchecked_t no_free_exch;
37965+ atomic_unchecked_t no_free_exch_xid;
37966+ atomic_unchecked_t xid_not_found;
37967+ atomic_unchecked_t xid_busy;
37968+ atomic_unchecked_t seq_not_found;
37969+ atomic_unchecked_t non_bls_resp;
37970 } stats;
37971 };
37972
37973@@ -725,7 +725,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
37974 /* allocate memory for exchange */
37975 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
37976 if (!ep) {
37977- atomic_inc(&mp->stats.no_free_exch);
37978+ atomic_inc_unchecked(&mp->stats.no_free_exch);
37979 goto out;
37980 }
37981 memset(ep, 0, sizeof(*ep));
37982@@ -786,7 +786,7 @@ out:
37983 return ep;
37984 err:
37985 spin_unlock_bh(&pool->lock);
37986- atomic_inc(&mp->stats.no_free_exch_xid);
37987+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
37988 mempool_free(ep, mp->ep_pool);
37989 return NULL;
37990 }
37991@@ -929,7 +929,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
37992 xid = ntohs(fh->fh_ox_id); /* we originated exch */
37993 ep = fc_exch_find(mp, xid);
37994 if (!ep) {
37995- atomic_inc(&mp->stats.xid_not_found);
37996+ atomic_inc_unchecked(&mp->stats.xid_not_found);
37997 reject = FC_RJT_OX_ID;
37998 goto out;
37999 }
38000@@ -959,7 +959,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
38001 ep = fc_exch_find(mp, xid);
38002 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
38003 if (ep) {
38004- atomic_inc(&mp->stats.xid_busy);
38005+ atomic_inc_unchecked(&mp->stats.xid_busy);
38006 reject = FC_RJT_RX_ID;
38007 goto rel;
38008 }
38009@@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
38010 }
38011 xid = ep->xid; /* get our XID */
38012 } else if (!ep) {
38013- atomic_inc(&mp->stats.xid_not_found);
38014+ atomic_inc_unchecked(&mp->stats.xid_not_found);
38015 reject = FC_RJT_RX_ID; /* XID not found */
38016 goto out;
38017 }
38018@@ -987,7 +987,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
38019 } else {
38020 sp = &ep->seq;
38021 if (sp->id != fh->fh_seq_id) {
38022- atomic_inc(&mp->stats.seq_not_found);
38023+ atomic_inc_unchecked(&mp->stats.seq_not_found);
38024 if (f_ctl & FC_FC_END_SEQ) {
38025 /*
38026 * Update sequence_id based on incoming last
38027@@ -1437,22 +1437,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
38028
38029 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
38030 if (!ep) {
38031- atomic_inc(&mp->stats.xid_not_found);
38032+ atomic_inc_unchecked(&mp->stats.xid_not_found);
38033 goto out;
38034 }
38035 if (ep->esb_stat & ESB_ST_COMPLETE) {
38036- atomic_inc(&mp->stats.xid_not_found);
38037+ atomic_inc_unchecked(&mp->stats.xid_not_found);
38038 goto rel;
38039 }
38040 if (ep->rxid == FC_XID_UNKNOWN)
38041 ep->rxid = ntohs(fh->fh_rx_id);
38042 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
38043- atomic_inc(&mp->stats.xid_not_found);
38044+ atomic_inc_unchecked(&mp->stats.xid_not_found);
38045 goto rel;
38046 }
38047 if (ep->did != ntoh24(fh->fh_s_id) &&
38048 ep->did != FC_FID_FLOGI) {
38049- atomic_inc(&mp->stats.xid_not_found);
38050+ atomic_inc_unchecked(&mp->stats.xid_not_found);
38051 goto rel;
38052 }
38053 sof = fr_sof(fp);
38054@@ -1461,7 +1461,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
38055 sp->ssb_stat |= SSB_ST_RESP;
38056 sp->id = fh->fh_seq_id;
38057 } else if (sp->id != fh->fh_seq_id) {
38058- atomic_inc(&mp->stats.seq_not_found);
38059+ atomic_inc_unchecked(&mp->stats.seq_not_found);
38060 goto rel;
38061 }
38062
38063@@ -1525,9 +1525,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
38064 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
38065
38066 if (!sp)
38067- atomic_inc(&mp->stats.xid_not_found);
38068+ atomic_inc_unchecked(&mp->stats.xid_not_found);
38069 else
38070- atomic_inc(&mp->stats.non_bls_resp);
38071+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
38072
38073 fc_frame_free(fp);
38074 }
38075@@ -2174,13 +2174,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
38076
38077 list_for_each_entry(ema, &lport->ema_list, ema_list) {
38078 mp = ema->mp;
38079- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
38080+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
38081 st->fc_no_free_exch_xid +=
38082- atomic_read(&mp->stats.no_free_exch_xid);
38083- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
38084- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
38085- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
38086- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
38087+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
38088+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
38089+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
38090+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
38091+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
38092 }
38093 }
38094 EXPORT_SYMBOL(fc_exch_update_stats);
38095diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
38096index bdb81cd..d3c7c2c 100644
38097--- a/drivers/scsi/libsas/sas_ata.c
38098+++ b/drivers/scsi/libsas/sas_ata.c
38099@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
38100 .postreset = ata_std_postreset,
38101 .error_handler = ata_std_error_handler,
38102 .post_internal_cmd = sas_ata_post_internal,
38103- .qc_defer = ata_std_qc_defer,
38104+ .qc_defer = ata_std_qc_defer,
38105 .qc_prep = ata_noop_qc_prep,
38106 .qc_issue = sas_ata_qc_issue,
38107 .qc_fill_rtf = sas_ata_qc_fill_rtf,
38108diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
38109index 69b5993..1ac9dce 100644
38110--- a/drivers/scsi/lpfc/lpfc.h
38111+++ b/drivers/scsi/lpfc/lpfc.h
38112@@ -424,7 +424,7 @@ struct lpfc_vport {
38113 struct dentry *debug_nodelist;
38114 struct dentry *vport_debugfs_root;
38115 struct lpfc_debugfs_trc *disc_trc;
38116- atomic_t disc_trc_cnt;
38117+ atomic_unchecked_t disc_trc_cnt;
38118 #endif
38119 uint8_t stat_data_enabled;
38120 uint8_t stat_data_blocked;
38121@@ -840,8 +840,8 @@ struct lpfc_hba {
38122 struct timer_list fabric_block_timer;
38123 unsigned long bit_flags;
38124 #define FABRIC_COMANDS_BLOCKED 0
38125- atomic_t num_rsrc_err;
38126- atomic_t num_cmd_success;
38127+ atomic_unchecked_t num_rsrc_err;
38128+ atomic_unchecked_t num_cmd_success;
38129 unsigned long last_rsrc_error_time;
38130 unsigned long last_ramp_down_time;
38131 unsigned long last_ramp_up_time;
38132@@ -877,7 +877,7 @@ struct lpfc_hba {
38133
38134 struct dentry *debug_slow_ring_trc;
38135 struct lpfc_debugfs_trc *slow_ring_trc;
38136- atomic_t slow_ring_trc_cnt;
38137+ atomic_unchecked_t slow_ring_trc_cnt;
38138 /* iDiag debugfs sub-directory */
38139 struct dentry *idiag_root;
38140 struct dentry *idiag_pci_cfg;
38141diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
38142index f63f5ff..de29189 100644
38143--- a/drivers/scsi/lpfc/lpfc_debugfs.c
38144+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
38145@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
38146
38147 #include <linux/debugfs.h>
38148
38149-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
38150+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
38151 static unsigned long lpfc_debugfs_start_time = 0L;
38152
38153 /* iDiag */
38154@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
38155 lpfc_debugfs_enable = 0;
38156
38157 len = 0;
38158- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
38159+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
38160 (lpfc_debugfs_max_disc_trc - 1);
38161 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
38162 dtp = vport->disc_trc + i;
38163@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
38164 lpfc_debugfs_enable = 0;
38165
38166 len = 0;
38167- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
38168+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
38169 (lpfc_debugfs_max_slow_ring_trc - 1);
38170 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
38171 dtp = phba->slow_ring_trc + i;
38172@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
38173 !vport || !vport->disc_trc)
38174 return;
38175
38176- index = atomic_inc_return(&vport->disc_trc_cnt) &
38177+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
38178 (lpfc_debugfs_max_disc_trc - 1);
38179 dtp = vport->disc_trc + index;
38180 dtp->fmt = fmt;
38181 dtp->data1 = data1;
38182 dtp->data2 = data2;
38183 dtp->data3 = data3;
38184- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
38185+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
38186 dtp->jif = jiffies;
38187 #endif
38188 return;
38189@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
38190 !phba || !phba->slow_ring_trc)
38191 return;
38192
38193- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
38194+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
38195 (lpfc_debugfs_max_slow_ring_trc - 1);
38196 dtp = phba->slow_ring_trc + index;
38197 dtp->fmt = fmt;
38198 dtp->data1 = data1;
38199 dtp->data2 = data2;
38200 dtp->data3 = data3;
38201- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
38202+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
38203 dtp->jif = jiffies;
38204 #endif
38205 return;
38206@@ -4182,7 +4182,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
38207 "slow_ring buffer\n");
38208 goto debug_failed;
38209 }
38210- atomic_set(&phba->slow_ring_trc_cnt, 0);
38211+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
38212 memset(phba->slow_ring_trc, 0,
38213 (sizeof(struct lpfc_debugfs_trc) *
38214 lpfc_debugfs_max_slow_ring_trc));
38215@@ -4228,7 +4228,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
38216 "buffer\n");
38217 goto debug_failed;
38218 }
38219- atomic_set(&vport->disc_trc_cnt, 0);
38220+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
38221
38222 snprintf(name, sizeof(name), "discovery_trace");
38223 vport->debug_disc_trc =
38224diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
38225index 7dc4218..3436f08 100644
38226--- a/drivers/scsi/lpfc/lpfc_init.c
38227+++ b/drivers/scsi/lpfc/lpfc_init.c
38228@@ -10589,8 +10589,10 @@ lpfc_init(void)
38229 "misc_register returned with status %d", error);
38230
38231 if (lpfc_enable_npiv) {
38232- lpfc_transport_functions.vport_create = lpfc_vport_create;
38233- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
38234+ pax_open_kernel();
38235+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
38236+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
38237+ pax_close_kernel();
38238 }
38239 lpfc_transport_template =
38240 fc_attach_transport(&lpfc_transport_functions);
38241diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
38242index 7f45ac9..cf62eda 100644
38243--- a/drivers/scsi/lpfc/lpfc_scsi.c
38244+++ b/drivers/scsi/lpfc/lpfc_scsi.c
38245@@ -305,7 +305,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
38246 uint32_t evt_posted;
38247
38248 spin_lock_irqsave(&phba->hbalock, flags);
38249- atomic_inc(&phba->num_rsrc_err);
38250+ atomic_inc_unchecked(&phba->num_rsrc_err);
38251 phba->last_rsrc_error_time = jiffies;
38252
38253 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
38254@@ -346,7 +346,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
38255 unsigned long flags;
38256 struct lpfc_hba *phba = vport->phba;
38257 uint32_t evt_posted;
38258- atomic_inc(&phba->num_cmd_success);
38259+ atomic_inc_unchecked(&phba->num_cmd_success);
38260
38261 if (vport->cfg_lun_queue_depth <= queue_depth)
38262 return;
38263@@ -390,8 +390,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
38264 unsigned long num_rsrc_err, num_cmd_success;
38265 int i;
38266
38267- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
38268- num_cmd_success = atomic_read(&phba->num_cmd_success);
38269+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
38270+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
38271
38272 /*
38273 * The error and success command counters are global per
38274@@ -419,8 +419,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
38275 }
38276 }
38277 lpfc_destroy_vport_work_array(phba, vports);
38278- atomic_set(&phba->num_rsrc_err, 0);
38279- atomic_set(&phba->num_cmd_success, 0);
38280+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
38281+ atomic_set_unchecked(&phba->num_cmd_success, 0);
38282 }
38283
38284 /**
38285@@ -454,8 +454,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
38286 }
38287 }
38288 lpfc_destroy_vport_work_array(phba, vports);
38289- atomic_set(&phba->num_rsrc_err, 0);
38290- atomic_set(&phba->num_cmd_success, 0);
38291+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
38292+ atomic_set_unchecked(&phba->num_cmd_success, 0);
38293 }
38294
38295 /**
38296diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
38297index af763ea..41904f7 100644
38298--- a/drivers/scsi/pmcraid.c
38299+++ b/drivers/scsi/pmcraid.c
38300@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
38301 res->scsi_dev = scsi_dev;
38302 scsi_dev->hostdata = res;
38303 res->change_detected = 0;
38304- atomic_set(&res->read_failures, 0);
38305- atomic_set(&res->write_failures, 0);
38306+ atomic_set_unchecked(&res->read_failures, 0);
38307+ atomic_set_unchecked(&res->write_failures, 0);
38308 rc = 0;
38309 }
38310 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
38311@@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
38312
38313 /* If this was a SCSI read/write command keep count of errors */
38314 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
38315- atomic_inc(&res->read_failures);
38316+ atomic_inc_unchecked(&res->read_failures);
38317 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
38318- atomic_inc(&res->write_failures);
38319+ atomic_inc_unchecked(&res->write_failures);
38320
38321 if (!RES_IS_GSCSI(res->cfg_entry) &&
38322 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
38323@@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
38324 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
38325 * hrrq_id assigned here in queuecommand
38326 */
38327- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
38328+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
38329 pinstance->num_hrrq;
38330 cmd->cmd_done = pmcraid_io_done;
38331
38332@@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
38333 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
38334 * hrrq_id assigned here in queuecommand
38335 */
38336- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
38337+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
38338 pinstance->num_hrrq;
38339
38340 if (request_size) {
38341@@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
38342
38343 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
38344 /* add resources only after host is added into system */
38345- if (!atomic_read(&pinstance->expose_resources))
38346+ if (!atomic_read_unchecked(&pinstance->expose_resources))
38347 return;
38348
38349 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
38350@@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
38351 init_waitqueue_head(&pinstance->reset_wait_q);
38352
38353 atomic_set(&pinstance->outstanding_cmds, 0);
38354- atomic_set(&pinstance->last_message_id, 0);
38355- atomic_set(&pinstance->expose_resources, 0);
38356+ atomic_set_unchecked(&pinstance->last_message_id, 0);
38357+ atomic_set_unchecked(&pinstance->expose_resources, 0);
38358
38359 INIT_LIST_HEAD(&pinstance->free_res_q);
38360 INIT_LIST_HEAD(&pinstance->used_res_q);
38361@@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
38362 /* Schedule worker thread to handle CCN and take care of adding and
38363 * removing devices to OS
38364 */
38365- atomic_set(&pinstance->expose_resources, 1);
38366+ atomic_set_unchecked(&pinstance->expose_resources, 1);
38367 schedule_work(&pinstance->worker_q);
38368 return rc;
38369
38370diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
38371index e1d150f..6c6df44 100644
38372--- a/drivers/scsi/pmcraid.h
38373+++ b/drivers/scsi/pmcraid.h
38374@@ -748,7 +748,7 @@ struct pmcraid_instance {
38375 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
38376
38377 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
38378- atomic_t last_message_id;
38379+ atomic_unchecked_t last_message_id;
38380
38381 /* configuration table */
38382 struct pmcraid_config_table *cfg_table;
38383@@ -777,7 +777,7 @@ struct pmcraid_instance {
38384 atomic_t outstanding_cmds;
38385
38386 /* should add/delete resources to mid-layer now ?*/
38387- atomic_t expose_resources;
38388+ atomic_unchecked_t expose_resources;
38389
38390
38391
38392@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
38393 struct pmcraid_config_table_entry_ext cfg_entry_ext;
38394 };
38395 struct scsi_device *scsi_dev; /* Link scsi_device structure */
38396- atomic_t read_failures; /* count of failed READ commands */
38397- atomic_t write_failures; /* count of failed WRITE commands */
38398+ atomic_unchecked_t read_failures; /* count of failed READ commands */
38399+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
38400
38401 /* To indicate add/delete/modify during CCN */
38402 u8 change_detected;
38403diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
38404index 1c28215..86991a1 100644
38405--- a/drivers/scsi/qla2xxx/qla_attr.c
38406+++ b/drivers/scsi/qla2xxx/qla_attr.c
38407@@ -1970,7 +1970,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
38408 return 0;
38409 }
38410
38411-struct fc_function_template qla2xxx_transport_functions = {
38412+fc_function_template_no_const qla2xxx_transport_functions = {
38413
38414 .show_host_node_name = 1,
38415 .show_host_port_name = 1,
38416@@ -2017,7 +2017,7 @@ struct fc_function_template qla2xxx_transport_functions = {
38417 .bsg_timeout = qla24xx_bsg_timeout,
38418 };
38419
38420-struct fc_function_template qla2xxx_transport_vport_functions = {
38421+fc_function_template_no_const qla2xxx_transport_vport_functions = {
38422
38423 .show_host_node_name = 1,
38424 .show_host_port_name = 1,
38425diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
38426index a9725bf..18eeb73 100644
38427--- a/drivers/scsi/qla2xxx/qla_def.h
38428+++ b/drivers/scsi/qla2xxx/qla_def.h
38429@@ -2385,7 +2385,7 @@ struct isp_operations {
38430 int (*start_scsi) (srb_t *);
38431 int (*abort_isp) (struct scsi_qla_host *);
38432 int (*iospace_config)(struct qla_hw_data*);
38433-};
38434+} __no_const;
38435
38436 /* MSI-X Support *************************************************************/
38437
38438diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
38439index 6acb397..d86e3e0 100644
38440--- a/drivers/scsi/qla2xxx/qla_gbl.h
38441+++ b/drivers/scsi/qla2xxx/qla_gbl.h
38442@@ -515,8 +515,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
38443 struct device_attribute;
38444 extern struct device_attribute *qla2x00_host_attrs[];
38445 struct fc_function_template;
38446-extern struct fc_function_template qla2xxx_transport_functions;
38447-extern struct fc_function_template qla2xxx_transport_vport_functions;
38448+extern fc_function_template_no_const qla2xxx_transport_functions;
38449+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
38450 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
38451 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
38452 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
38453diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
38454index 329d553..f20d31d 100644
38455--- a/drivers/scsi/qla4xxx/ql4_def.h
38456+++ b/drivers/scsi/qla4xxx/ql4_def.h
38457@@ -273,7 +273,7 @@ struct ddb_entry {
38458 * (4000 only) */
38459 atomic_t relogin_timer; /* Max Time to wait for
38460 * relogin to complete */
38461- atomic_t relogin_retry_count; /* Num of times relogin has been
38462+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
38463 * retried */
38464 uint32_t default_time2wait; /* Default Min time between
38465 * relogins (+aens) */
38466diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
38467index fbc546e..c7d1b48 100644
38468--- a/drivers/scsi/qla4xxx/ql4_os.c
38469+++ b/drivers/scsi/qla4xxx/ql4_os.c
38470@@ -2621,12 +2621,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
38471 */
38472 if (!iscsi_is_session_online(cls_sess)) {
38473 /* Reset retry relogin timer */
38474- atomic_inc(&ddb_entry->relogin_retry_count);
38475+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
38476 DEBUG2(ql4_printk(KERN_INFO, ha,
38477 "%s: index[%d] relogin timed out-retrying"
38478 " relogin (%d), retry (%d)\n", __func__,
38479 ddb_entry->fw_ddb_index,
38480- atomic_read(&ddb_entry->relogin_retry_count),
38481+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
38482 ddb_entry->default_time2wait + 4));
38483 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
38484 atomic_set(&ddb_entry->retry_relogin_timer,
38485@@ -4738,7 +4738,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
38486
38487 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
38488 atomic_set(&ddb_entry->relogin_timer, 0);
38489- atomic_set(&ddb_entry->relogin_retry_count, 0);
38490+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
38491 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
38492 ddb_entry->default_relogin_timeout =
38493 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
38494diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
38495index 2c0d0ec..4e8681a 100644
38496--- a/drivers/scsi/scsi.c
38497+++ b/drivers/scsi/scsi.c
38498@@ -661,7 +661,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
38499 unsigned long timeout;
38500 int rtn = 0;
38501
38502- atomic_inc(&cmd->device->iorequest_cnt);
38503+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
38504
38505 /* check if the device is still usable */
38506 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
38507diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
38508index 9032e91..7a805d0 100644
38509--- a/drivers/scsi/scsi_lib.c
38510+++ b/drivers/scsi/scsi_lib.c
38511@@ -1454,7 +1454,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
38512 shost = sdev->host;
38513 scsi_init_cmd_errh(cmd);
38514 cmd->result = DID_NO_CONNECT << 16;
38515- atomic_inc(&cmd->device->iorequest_cnt);
38516+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
38517
38518 /*
38519 * SCSI request completion path will do scsi_device_unbusy(),
38520@@ -1480,9 +1480,9 @@ static void scsi_softirq_done(struct request *rq)
38521
38522 INIT_LIST_HEAD(&cmd->eh_entry);
38523
38524- atomic_inc(&cmd->device->iodone_cnt);
38525+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
38526 if (cmd->result)
38527- atomic_inc(&cmd->device->ioerr_cnt);
38528+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
38529
38530 disposition = scsi_decide_disposition(cmd);
38531 if (disposition != SUCCESS &&
38532diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
38533index ce5224c..8c6d071 100644
38534--- a/drivers/scsi/scsi_sysfs.c
38535+++ b/drivers/scsi/scsi_sysfs.c
38536@@ -661,7 +661,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
38537 char *buf) \
38538 { \
38539 struct scsi_device *sdev = to_scsi_device(dev); \
38540- unsigned long long count = atomic_read(&sdev->field); \
38541+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
38542 return snprintf(buf, 20, "0x%llx\n", count); \
38543 } \
38544 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
38545diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
38546index 84a1fdf..693b0d6 100644
38547--- a/drivers/scsi/scsi_tgt_lib.c
38548+++ b/drivers/scsi/scsi_tgt_lib.c
38549@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
38550 int err;
38551
38552 dprintk("%lx %u\n", uaddr, len);
38553- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
38554+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
38555 if (err) {
38556 /*
38557 * TODO: need to fixup sg_tablesize, max_segment_size,
38558diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
38559index e894ca7..de9d7660 100644
38560--- a/drivers/scsi/scsi_transport_fc.c
38561+++ b/drivers/scsi/scsi_transport_fc.c
38562@@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
38563 * Netlink Infrastructure
38564 */
38565
38566-static atomic_t fc_event_seq;
38567+static atomic_unchecked_t fc_event_seq;
38568
38569 /**
38570 * fc_get_event_number - Obtain the next sequential FC event number
38571@@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
38572 u32
38573 fc_get_event_number(void)
38574 {
38575- return atomic_add_return(1, &fc_event_seq);
38576+ return atomic_add_return_unchecked(1, &fc_event_seq);
38577 }
38578 EXPORT_SYMBOL(fc_get_event_number);
38579
38580@@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
38581 {
38582 int error;
38583
38584- atomic_set(&fc_event_seq, 0);
38585+ atomic_set_unchecked(&fc_event_seq, 0);
38586
38587 error = transport_class_register(&fc_host_class);
38588 if (error)
38589@@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
38590 char *cp;
38591
38592 *val = simple_strtoul(buf, &cp, 0);
38593- if ((*cp && (*cp != '\n')) || (*val < 0))
38594+ if (*cp && (*cp != '\n'))
38595 return -EINVAL;
38596 /*
38597 * Check for overflow; dev_loss_tmo is u32
38598diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
38599index 31969f2..2b348f0 100644
38600--- a/drivers/scsi/scsi_transport_iscsi.c
38601+++ b/drivers/scsi/scsi_transport_iscsi.c
38602@@ -79,7 +79,7 @@ struct iscsi_internal {
38603 struct transport_container session_cont;
38604 };
38605
38606-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
38607+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
38608 static struct workqueue_struct *iscsi_eh_timer_workq;
38609
38610 static DEFINE_IDA(iscsi_sess_ida);
38611@@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
38612 int err;
38613
38614 ihost = shost->shost_data;
38615- session->sid = atomic_add_return(1, &iscsi_session_nr);
38616+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
38617
38618 if (target_id == ISCSI_MAX_TARGET) {
38619 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
38620@@ -2943,7 +2943,7 @@ static __init int iscsi_transport_init(void)
38621 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
38622 ISCSI_TRANSPORT_VERSION);
38623
38624- atomic_set(&iscsi_session_nr, 0);
38625+ atomic_set_unchecked(&iscsi_session_nr, 0);
38626
38627 err = class_register(&iscsi_transport_class);
38628 if (err)
38629diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
38630index 21a045e..ec89e03 100644
38631--- a/drivers/scsi/scsi_transport_srp.c
38632+++ b/drivers/scsi/scsi_transport_srp.c
38633@@ -33,7 +33,7 @@
38634 #include "scsi_transport_srp_internal.h"
38635
38636 struct srp_host_attrs {
38637- atomic_t next_port_id;
38638+ atomic_unchecked_t next_port_id;
38639 };
38640 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
38641
38642@@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
38643 struct Scsi_Host *shost = dev_to_shost(dev);
38644 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
38645
38646- atomic_set(&srp_host->next_port_id, 0);
38647+ atomic_set_unchecked(&srp_host->next_port_id, 0);
38648 return 0;
38649 }
38650
38651@@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
38652 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
38653 rport->roles = ids->roles;
38654
38655- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
38656+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
38657 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
38658
38659 transport_setup_device(&rport->dev);
38660diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
38661index 352bc77..c049b14 100644
38662--- a/drivers/scsi/sd.c
38663+++ b/drivers/scsi/sd.c
38664@@ -2899,7 +2899,7 @@ static int sd_probe(struct device *dev)
38665 sdkp->disk = gd;
38666 sdkp->index = index;
38667 atomic_set(&sdkp->openers, 0);
38668- atomic_set(&sdkp->device->ioerr_cnt, 0);
38669+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
38670
38671 if (!sdp->request_queue->rq_timeout) {
38672 if (sdp->type != TYPE_MOD)
38673diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
38674index be2c9a6..275525c 100644
38675--- a/drivers/scsi/sg.c
38676+++ b/drivers/scsi/sg.c
38677@@ -1101,7 +1101,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
38678 sdp->disk->disk_name,
38679 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
38680 NULL,
38681- (char *)arg);
38682+ (char __user *)arg);
38683 case BLKTRACESTART:
38684 return blk_trace_startstop(sdp->device->request_queue, 1);
38685 case BLKTRACESTOP:
38686diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
38687index 84c2861..ece0a31 100644
38688--- a/drivers/spi/spi.c
38689+++ b/drivers/spi/spi.c
38690@@ -1453,7 +1453,7 @@ int spi_bus_unlock(struct spi_master *master)
38691 EXPORT_SYMBOL_GPL(spi_bus_unlock);
38692
38693 /* portable code must never pass more than 32 bytes */
38694-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
38695+#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
38696
38697 static u8 *buf;
38698
38699diff --git a/drivers/staging/csr/sdio_mmc.c b/drivers/staging/csr/sdio_mmc.c
38700index af3e40b..29de4f5 100644
38701--- a/drivers/staging/csr/sdio_mmc.c
38702+++ b/drivers/staging/csr/sdio_mmc.c
38703@@ -898,7 +898,7 @@ struct uf_sdio_mmc_pm_notifier
38704 struct list_head list;
38705
38706 CsrSdioFunction *sdio_ctx;
38707- struct notifier_block pm_notifier;
38708+ notifier_block_no_const pm_notifier;
38709 };
38710
38711 /* PM notifier list head */
38712diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
38713index 34afc16..ffe44dd 100644
38714--- a/drivers/staging/octeon/ethernet-rx.c
38715+++ b/drivers/staging/octeon/ethernet-rx.c
38716@@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
38717 /* Increment RX stats for virtual ports */
38718 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
38719 #ifdef CONFIG_64BIT
38720- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
38721- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
38722+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
38723+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
38724 #else
38725- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
38726- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
38727+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
38728+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
38729 #endif
38730 }
38731 netif_receive_skb(skb);
38732@@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
38733 dev->name);
38734 */
38735 #ifdef CONFIG_64BIT
38736- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
38737+ atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
38738 #else
38739- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
38740+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
38741 #endif
38742 dev_kfree_skb_irq(skb);
38743 }
38744diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
38745index 683bedc..86dba9a 100644
38746--- a/drivers/staging/octeon/ethernet.c
38747+++ b/drivers/staging/octeon/ethernet.c
38748@@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
38749 * since the RX tasklet also increments it.
38750 */
38751 #ifdef CONFIG_64BIT
38752- atomic64_add(rx_status.dropped_packets,
38753- (atomic64_t *)&priv->stats.rx_dropped);
38754+ atomic64_add_unchecked(rx_status.dropped_packets,
38755+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
38756 #else
38757- atomic_add(rx_status.dropped_packets,
38758- (atomic_t *)&priv->stats.rx_dropped);
38759+ atomic_add_unchecked(rx_status.dropped_packets,
38760+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
38761 #endif
38762 }
38763
38764diff --git a/drivers/staging/ramster/tmem.c b/drivers/staging/ramster/tmem.c
38765index a2b7e03..aaf3630 100644
38766--- a/drivers/staging/ramster/tmem.c
38767+++ b/drivers/staging/ramster/tmem.c
38768@@ -50,25 +50,25 @@
38769 * A tmem host implementation must use this function to register callbacks
38770 * for memory allocation.
38771 */
38772-static struct tmem_hostops tmem_hostops;
38773+static struct tmem_hostops *tmem_hostops;
38774
38775 static void tmem_objnode_tree_init(void);
38776
38777 void tmem_register_hostops(struct tmem_hostops *m)
38778 {
38779 tmem_objnode_tree_init();
38780- tmem_hostops = *m;
38781+ tmem_hostops = m;
38782 }
38783
38784 /*
38785 * A tmem host implementation must use this function to register
38786 * callbacks for a page-accessible memory (PAM) implementation.
38787 */
38788-static struct tmem_pamops tmem_pamops;
38789+static struct tmem_pamops *tmem_pamops;
38790
38791 void tmem_register_pamops(struct tmem_pamops *m)
38792 {
38793- tmem_pamops = *m;
38794+ tmem_pamops = m;
38795 }
38796
38797 /*
38798@@ -174,7 +174,7 @@ static void tmem_obj_init(struct tmem_obj *obj, struct tmem_hashbucket *hb,
38799 obj->pampd_count = 0;
38800 #ifdef CONFIG_RAMSTER
38801 if (tmem_pamops.new_obj != NULL)
38802- (*tmem_pamops.new_obj)(obj);
38803+ (tmem_pamops->new_obj)(obj);
38804 #endif
38805 SET_SENTINEL(obj, OBJ);
38806
38807@@ -210,7 +210,7 @@ static void tmem_pool_flush(struct tmem_pool *pool, bool destroy)
38808 rbnode = rb_next(rbnode);
38809 tmem_pampd_destroy_all_in_obj(obj, true);
38810 tmem_obj_free(obj, hb);
38811- (*tmem_hostops.obj_free)(obj, pool);
38812+ (tmem_hostops->obj_free)(obj, pool);
38813 }
38814 spin_unlock(&hb->lock);
38815 }
38816@@ -261,7 +261,7 @@ static struct tmem_objnode *tmem_objnode_alloc(struct tmem_obj *obj)
38817 ASSERT_SENTINEL(obj, OBJ);
38818 BUG_ON(obj->pool == NULL);
38819 ASSERT_SENTINEL(obj->pool, POOL);
38820- objnode = (*tmem_hostops.objnode_alloc)(obj->pool);
38821+ objnode = (tmem_hostops->objnode_alloc)(obj->pool);
38822 if (unlikely(objnode == NULL))
38823 goto out;
38824 objnode->obj = obj;
38825@@ -290,7 +290,7 @@ static void tmem_objnode_free(struct tmem_objnode *objnode)
38826 ASSERT_SENTINEL(pool, POOL);
38827 objnode->obj->objnode_count--;
38828 objnode->obj = NULL;
38829- (*tmem_hostops.objnode_free)(objnode, pool);
38830+ (tmem_hostops->objnode_free)(objnode, pool);
38831 }
38832
38833 /*
38834@@ -348,7 +348,7 @@ static void *tmem_pampd_replace_in_obj(struct tmem_obj *obj, uint32_t index,
38835 void *old_pampd = *(void **)slot;
38836 *(void **)slot = new_pampd;
38837 if (!no_free)
38838- (*tmem_pamops.free)(old_pampd, obj->pool,
38839+ (tmem_pamops->free)(old_pampd, obj->pool,
38840 NULL, 0, false);
38841 ret = new_pampd;
38842 }
38843@@ -505,7 +505,7 @@ static void tmem_objnode_node_destroy(struct tmem_obj *obj,
38844 if (objnode->slots[i]) {
38845 if (ht == 1) {
38846 obj->pampd_count--;
38847- (*tmem_pamops.free)(objnode->slots[i],
38848+ (tmem_pamops->free)(objnode->slots[i],
38849 obj->pool, NULL, 0, true);
38850 objnode->slots[i] = NULL;
38851 continue;
38852@@ -524,7 +524,7 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
38853 return;
38854 if (obj->objnode_tree_height == 0) {
38855 obj->pampd_count--;
38856- (*tmem_pamops.free)(obj->objnode_tree_root,
38857+ (tmem_pamops->free)(obj->objnode_tree_root,
38858 obj->pool, NULL, 0, true);
38859 } else {
38860 tmem_objnode_node_destroy(obj, obj->objnode_tree_root,
38861@@ -535,7 +535,7 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
38862 obj->objnode_tree_root = NULL;
38863 #ifdef CONFIG_RAMSTER
38864 if (tmem_pamops.free_obj != NULL)
38865- (*tmem_pamops.free_obj)(obj->pool, obj, pool_destroy);
38866+ (tmem_pamops->free_obj)(obj->pool, obj, pool_destroy);
38867 #endif
38868 }
38869
38870@@ -574,7 +574,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
38871 /* if found, is a dup put, flush the old one */
38872 pampd_del = tmem_pampd_delete_from_obj(obj, index);
38873 BUG_ON(pampd_del != pampd);
38874- (*tmem_pamops.free)(pampd, pool, oidp, index, true);
38875+ (tmem_pamops->free)(pampd, pool, oidp, index, true);
38876 if (obj->pampd_count == 0) {
38877 objnew = obj;
38878 objfound = NULL;
38879@@ -582,7 +582,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
38880 pampd = NULL;
38881 }
38882 } else {
38883- obj = objnew = (*tmem_hostops.obj_alloc)(pool);
38884+ obj = objnew = (tmem_hostops->obj_alloc)(pool);
38885 if (unlikely(obj == NULL)) {
38886 ret = -ENOMEM;
38887 goto out;
38888@@ -597,16 +597,16 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
38889 if (unlikely(ret == -ENOMEM))
38890 /* may have partially built objnode tree ("stump") */
38891 goto delete_and_free;
38892- (*tmem_pamops.create_finish)(pampd, is_ephemeral(pool));
38893+ (tmem_pamops->create_finish)(pampd, is_ephemeral(pool));
38894 goto out;
38895
38896 delete_and_free:
38897 (void)tmem_pampd_delete_from_obj(obj, index);
38898 if (pampd)
38899- (*tmem_pamops.free)(pampd, pool, NULL, 0, true);
38900+ (tmem_pamops->free)(pampd, pool, NULL, 0, true);
38901 if (objnew) {
38902 tmem_obj_free(objnew, hb);
38903- (*tmem_hostops.obj_free)(objnew, pool);
38904+ (tmem_hostops->obj_free)(objnew, pool);
38905 }
38906 out:
38907 spin_unlock(&hb->lock);
38908@@ -651,7 +651,7 @@ void tmem_localify_finish(struct tmem_obj *obj, uint32_t index,
38909 if (pampd != NULL) {
38910 BUG_ON(obj == NULL);
38911 (void)tmem_pampd_replace_in_obj(obj, index, pampd, 1);
38912- (*tmem_pamops.create_finish)(pampd, is_ephemeral(obj->pool));
38913+ (tmem_pamops->create_finish)(pampd, is_ephemeral(obj->pool));
38914 } else if (delete) {
38915 BUG_ON(obj == NULL);
38916 (void)tmem_pampd_delete_from_obj(obj, index);
38917@@ -671,7 +671,7 @@ static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
38918 int ret = 0;
38919
38920 if (!is_ephemeral(pool))
38921- new_pampd = (*tmem_pamops.repatriate_preload)(
38922+ new_pampd = (tmem_pamops->repatriate_preload)(
38923 old_pampd, pool, oidp, index, &intransit);
38924 if (intransit)
38925 ret = -EAGAIN;
38926@@ -680,7 +680,7 @@ static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
38927 /* must release the hb->lock else repatriate can't sleep */
38928 spin_unlock(&hb->lock);
38929 if (!intransit)
38930- ret = (*tmem_pamops.repatriate)(old_pampd, new_pampd, pool,
38931+ ret = (tmem_pamops->repatriate)(old_pampd, new_pampd, pool,
38932 oidp, index, free, data);
38933 if (ret == -EAGAIN) {
38934 /* rare I think, but should cond_resched()??? */
38935@@ -714,7 +714,7 @@ int tmem_replace(struct tmem_pool *pool, struct tmem_oid *oidp,
38936 new_pampd = tmem_pampd_replace_in_obj(obj, index, new_pampd, 0);
38937 /* if we bug here, pamops wasn't properly set up for ramster */
38938 BUG_ON(tmem_pamops.replace_in_obj == NULL);
38939- ret = (*tmem_pamops.replace_in_obj)(new_pampd, obj);
38940+ ret = (tmem_pamops->replace_in_obj)(new_pampd, obj);
38941 out:
38942 spin_unlock(&hb->lock);
38943 return ret;
38944@@ -776,15 +776,15 @@ int tmem_get(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
38945 if (free) {
38946 if (obj->pampd_count == 0) {
38947 tmem_obj_free(obj, hb);
38948- (*tmem_hostops.obj_free)(obj, pool);
38949+ (tmem_hostops->obj_free)(obj, pool);
38950 obj = NULL;
38951 }
38952 }
38953 if (free)
38954- ret = (*tmem_pamops.get_data_and_free)(
38955+ ret = (tmem_pamops->get_data_and_free)(
38956 data, sizep, raw, pampd, pool, oidp, index);
38957 else
38958- ret = (*tmem_pamops.get_data)(
38959+ ret = (tmem_pamops->get_data)(
38960 data, sizep, raw, pampd, pool, oidp, index);
38961 if (ret < 0)
38962 goto out;
38963@@ -816,10 +816,10 @@ int tmem_flush_page(struct tmem_pool *pool,
38964 pampd = tmem_pampd_delete_from_obj(obj, index);
38965 if (pampd == NULL)
38966 goto out;
38967- (*tmem_pamops.free)(pampd, pool, oidp, index, true);
38968+ (tmem_pamops->free)(pampd, pool, oidp, index, true);
38969 if (obj->pampd_count == 0) {
38970 tmem_obj_free(obj, hb);
38971- (*tmem_hostops.obj_free)(obj, pool);
38972+ (tmem_hostops->obj_free)(obj, pool);
38973 }
38974 ret = 0;
38975
38976@@ -844,7 +844,7 @@ int tmem_flush_object(struct tmem_pool *pool, struct tmem_oid *oidp)
38977 goto out;
38978 tmem_pampd_destroy_all_in_obj(obj, false);
38979 tmem_obj_free(obj, hb);
38980- (*tmem_hostops.obj_free)(obj, pool);
38981+ (tmem_hostops->obj_free)(obj, pool);
38982 ret = 0;
38983
38984 out:
38985diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
38986index dc23395..cf7e9b1 100644
38987--- a/drivers/staging/rtl8712/rtl871x_io.h
38988+++ b/drivers/staging/rtl8712/rtl871x_io.h
38989@@ -108,7 +108,7 @@ struct _io_ops {
38990 u8 *pmem);
38991 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
38992 u8 *pmem);
38993-};
38994+} __no_const;
38995
38996 struct io_req {
38997 struct list_head list;
38998diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
38999index 180c963..1f18377 100644
39000--- a/drivers/staging/sbe-2t3e3/netdev.c
39001+++ b/drivers/staging/sbe-2t3e3/netdev.c
39002@@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
39003 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
39004
39005 if (rlen)
39006- if (copy_to_user(data, &resp, rlen))
39007+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
39008 return -EFAULT;
39009
39010 return 0;
39011diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
39012index 5d89c0f..9261317 100644
39013--- a/drivers/staging/usbip/usbip_common.h
39014+++ b/drivers/staging/usbip/usbip_common.h
39015@@ -289,7 +289,7 @@ struct usbip_device {
39016 void (*shutdown)(struct usbip_device *);
39017 void (*reset)(struct usbip_device *);
39018 void (*unusable)(struct usbip_device *);
39019- } eh_ops;
39020+ } __no_const eh_ops;
39021 };
39022
39023 #define kthread_get_run(threadfn, data, namefmt, ...) \
39024diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
39025index c66b8b3..a4a035b 100644
39026--- a/drivers/staging/usbip/vhci.h
39027+++ b/drivers/staging/usbip/vhci.h
39028@@ -83,7 +83,7 @@ struct vhci_hcd {
39029 unsigned resuming:1;
39030 unsigned long re_timeout;
39031
39032- atomic_t seqnum;
39033+ atomic_unchecked_t seqnum;
39034
39035 /*
39036 * NOTE:
39037diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
39038index 620d1be..1cd6711 100644
39039--- a/drivers/staging/usbip/vhci_hcd.c
39040+++ b/drivers/staging/usbip/vhci_hcd.c
39041@@ -471,7 +471,7 @@ static void vhci_tx_urb(struct urb *urb)
39042 return;
39043 }
39044
39045- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
39046+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
39047 if (priv->seqnum == 0xffff)
39048 dev_info(&urb->dev->dev, "seqnum max\n");
39049
39050@@ -723,7 +723,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
39051 return -ENOMEM;
39052 }
39053
39054- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
39055+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
39056 if (unlink->seqnum == 0xffff)
39057 pr_info("seqnum max\n");
39058
39059@@ -924,7 +924,7 @@ static int vhci_start(struct usb_hcd *hcd)
39060 vdev->rhport = rhport;
39061 }
39062
39063- atomic_set(&vhci->seqnum, 0);
39064+ atomic_set_unchecked(&vhci->seqnum, 0);
39065 spin_lock_init(&vhci->lock);
39066
39067 hcd->power_budget = 0; /* no limit */
39068diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
39069index f0eaf04..5a82e06 100644
39070--- a/drivers/staging/usbip/vhci_rx.c
39071+++ b/drivers/staging/usbip/vhci_rx.c
39072@@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
39073 if (!urb) {
39074 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
39075 pr_info("max seqnum %d\n",
39076- atomic_read(&the_controller->seqnum));
39077+ atomic_read_unchecked(&the_controller->seqnum));
39078 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
39079 return;
39080 }
39081diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
39082index 67b1b88..6392fe9 100644
39083--- a/drivers/staging/vt6655/hostap.c
39084+++ b/drivers/staging/vt6655/hostap.c
39085@@ -73,14 +73,13 @@ static int msglevel =MSG_LEVEL_INFO;
39086 *
39087 */
39088
39089+static net_device_ops_no_const apdev_netdev_ops;
39090+
39091 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
39092 {
39093 PSDevice apdev_priv;
39094 struct net_device *dev = pDevice->dev;
39095 int ret;
39096- const struct net_device_ops apdev_netdev_ops = {
39097- .ndo_start_xmit = pDevice->tx_80211,
39098- };
39099
39100 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
39101
39102@@ -92,6 +91,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
39103 *apdev_priv = *pDevice;
39104 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
39105
39106+ /* only half broken now */
39107+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
39108 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
39109
39110 pDevice->apdev->type = ARPHRD_IEEE80211;
39111diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
39112index 0a73d40..6fda560 100644
39113--- a/drivers/staging/vt6656/hostap.c
39114+++ b/drivers/staging/vt6656/hostap.c
39115@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
39116 *
39117 */
39118
39119+static net_device_ops_no_const apdev_netdev_ops;
39120+
39121 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
39122 {
39123 PSDevice apdev_priv;
39124 struct net_device *dev = pDevice->dev;
39125 int ret;
39126- const struct net_device_ops apdev_netdev_ops = {
39127- .ndo_start_xmit = pDevice->tx_80211,
39128- };
39129
39130 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
39131
39132@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
39133 *apdev_priv = *pDevice;
39134 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
39135
39136+ /* only half broken now */
39137+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
39138 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
39139
39140 pDevice->apdev->type = ARPHRD_IEEE80211;
39141diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
39142index f180c3d..4b9ecfc 100644
39143--- a/drivers/staging/wlan-ng/hfa384x_usb.c
39144+++ b/drivers/staging/wlan-ng/hfa384x_usb.c
39145@@ -204,7 +204,7 @@ static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
39146
39147 struct usbctlx_completor {
39148 int (*complete) (struct usbctlx_completor *);
39149-};
39150+} __no_const;
39151
39152 static int
39153 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
39154diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
39155index 56c8e60..1920c63 100644
39156--- a/drivers/staging/zcache/tmem.c
39157+++ b/drivers/staging/zcache/tmem.c
39158@@ -39,7 +39,7 @@
39159 * A tmem host implementation must use this function to register callbacks
39160 * for memory allocation.
39161 */
39162-static struct tmem_hostops tmem_hostops;
39163+static tmem_hostops_no_const tmem_hostops;
39164
39165 static void tmem_objnode_tree_init(void);
39166
39167@@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
39168 * A tmem host implementation must use this function to register
39169 * callbacks for a page-accessible memory (PAM) implementation
39170 */
39171-static struct tmem_pamops tmem_pamops;
39172+static tmem_pamops_no_const tmem_pamops;
39173
39174 void tmem_register_pamops(struct tmem_pamops *m)
39175 {
39176diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
39177index 0d4aa82..f7832d4 100644
39178--- a/drivers/staging/zcache/tmem.h
39179+++ b/drivers/staging/zcache/tmem.h
39180@@ -180,6 +180,7 @@ struct tmem_pamops {
39181 void (*new_obj)(struct tmem_obj *);
39182 int (*replace_in_obj)(void *, struct tmem_obj *);
39183 };
39184+typedef struct tmem_pamops __no_const tmem_pamops_no_const;
39185 extern void tmem_register_pamops(struct tmem_pamops *m);
39186
39187 /* memory allocation methods provided by the host implementation */
39188@@ -189,6 +190,7 @@ struct tmem_hostops {
39189 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
39190 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
39191 };
39192+typedef struct tmem_hostops __no_const tmem_hostops_no_const;
39193 extern void tmem_register_hostops(struct tmem_hostops *m);
39194
39195 /* core tmem accessor functions */
39196diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
39197index dcecbfb..4fad7d5 100644
39198--- a/drivers/target/target_core_transport.c
39199+++ b/drivers/target/target_core_transport.c
39200@@ -1087,7 +1087,7 @@ struct se_device *transport_add_device_to_core_hba(
39201 spin_lock_init(&dev->se_port_lock);
39202 spin_lock_init(&dev->se_tmr_lock);
39203 spin_lock_init(&dev->qf_cmd_lock);
39204- atomic_set(&dev->dev_ordered_id, 0);
39205+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
39206
39207 se_dev_set_default_attribs(dev, dev_limits);
39208
39209@@ -1277,7 +1277,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
39210 * Used to determine when ORDERED commands should go from
39211 * Dormant to Active status.
39212 */
39213- cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
39214+ cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
39215 smp_mb__after_atomic_inc();
39216 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
39217 cmd->se_ordered_id, cmd->sam_task_attr,
39218diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
39219index 0a6a0bc..5501b06 100644
39220--- a/drivers/tty/cyclades.c
39221+++ b/drivers/tty/cyclades.c
39222@@ -1589,10 +1589,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
39223 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
39224 info->port.count);
39225 #endif
39226- info->port.count++;
39227+ atomic_inc(&info->port.count);
39228 #ifdef CY_DEBUG_COUNT
39229 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
39230- current->pid, info->port.count);
39231+ current->pid, atomic_read(&info->port.count));
39232 #endif
39233
39234 /*
39235@@ -3989,7 +3989,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
39236 for (j = 0; j < cy_card[i].nports; j++) {
39237 info = &cy_card[i].ports[j];
39238
39239- if (info->port.count) {
39240+ if (atomic_read(&info->port.count)) {
39241 /* XXX is the ldisc num worth this? */
39242 struct tty_struct *tty;
39243 struct tty_ldisc *ld;
39244diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
39245index 13ee53b..418d164 100644
39246--- a/drivers/tty/hvc/hvc_console.c
39247+++ b/drivers/tty/hvc/hvc_console.c
39248@@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
39249
39250 spin_lock_irqsave(&hp->port.lock, flags);
39251 /* Check and then increment for fast path open. */
39252- if (hp->port.count++ > 0) {
39253+ if (atomic_inc_return(&hp->port.count) > 1) {
39254 spin_unlock_irqrestore(&hp->port.lock, flags);
39255 hvc_kick();
39256 return 0;
39257@@ -388,7 +388,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
39258
39259 spin_lock_irqsave(&hp->port.lock, flags);
39260
39261- if (--hp->port.count == 0) {
39262+ if (atomic_dec_return(&hp->port.count) == 0) {
39263 spin_unlock_irqrestore(&hp->port.lock, flags);
39264 /* We are done with the tty pointer now. */
39265 tty_port_tty_set(&hp->port, NULL);
39266@@ -406,9 +406,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
39267 */
39268 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
39269 } else {
39270- if (hp->port.count < 0)
39271+ if (atomic_read(&hp->port.count) < 0)
39272 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
39273- hp->vtermno, hp->port.count);
39274+ hp->vtermno, atomic_read(&hp->port.count));
39275 spin_unlock_irqrestore(&hp->port.lock, flags);
39276 }
39277 }
39278@@ -438,12 +438,12 @@ static void hvc_hangup(struct tty_struct *tty)
39279 * open->hangup case this can be called after the final close so prevent
39280 * that from happening for now.
39281 */
39282- if (hp->port.count <= 0) {
39283+ if (atomic_read(&hp->port.count) <= 0) {
39284 spin_unlock_irqrestore(&hp->port.lock, flags);
39285 return;
39286 }
39287
39288- hp->port.count = 0;
39289+ atomic_set(&hp->port.count, 0);
39290 spin_unlock_irqrestore(&hp->port.lock, flags);
39291 tty_port_tty_set(&hp->port, NULL);
39292
39293@@ -491,7 +491,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
39294 return -EPIPE;
39295
39296 /* FIXME what's this (unprotected) check for? */
39297- if (hp->port.count <= 0)
39298+ if (atomic_read(&hp->port.count) <= 0)
39299 return -EIO;
39300
39301 spin_lock_irqsave(&hp->lock, flags);
39302diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
39303index cab5c7a..4cc66ea 100644
39304--- a/drivers/tty/hvc/hvcs.c
39305+++ b/drivers/tty/hvc/hvcs.c
39306@@ -83,6 +83,7 @@
39307 #include <asm/hvcserver.h>
39308 #include <asm/uaccess.h>
39309 #include <asm/vio.h>
39310+#include <asm/local.h>
39311
39312 /*
39313 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
39314@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
39315
39316 spin_lock_irqsave(&hvcsd->lock, flags);
39317
39318- if (hvcsd->port.count > 0) {
39319+ if (atomic_read(&hvcsd->port.count) > 0) {
39320 spin_unlock_irqrestore(&hvcsd->lock, flags);
39321 printk(KERN_INFO "HVCS: vterm state unchanged. "
39322 "The hvcs device node is still in use.\n");
39323@@ -1132,7 +1133,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
39324 }
39325 }
39326
39327- hvcsd->port.count = 0;
39328+ atomic_set(&hvcsd->port.count, 0);
39329 hvcsd->port.tty = tty;
39330 tty->driver_data = hvcsd;
39331
39332@@ -1185,7 +1186,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
39333 unsigned long flags;
39334
39335 spin_lock_irqsave(&hvcsd->lock, flags);
39336- hvcsd->port.count++;
39337+ atomic_inc(&hvcsd->port.count);
39338 hvcsd->todo_mask |= HVCS_SCHED_READ;
39339 spin_unlock_irqrestore(&hvcsd->lock, flags);
39340
39341@@ -1221,7 +1222,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
39342 hvcsd = tty->driver_data;
39343
39344 spin_lock_irqsave(&hvcsd->lock, flags);
39345- if (--hvcsd->port.count == 0) {
39346+ if (atomic_dec_and_test(&hvcsd->port.count)) {
39347
39348 vio_disable_interrupts(hvcsd->vdev);
39349
39350@@ -1246,10 +1247,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
39351
39352 free_irq(irq, hvcsd);
39353 return;
39354- } else if (hvcsd->port.count < 0) {
39355+ } else if (atomic_read(&hvcsd->port.count) < 0) {
39356 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
39357 " is missmanaged.\n",
39358- hvcsd->vdev->unit_address, hvcsd->port.count);
39359+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
39360 }
39361
39362 spin_unlock_irqrestore(&hvcsd->lock, flags);
39363@@ -1271,7 +1272,7 @@ static void hvcs_hangup(struct tty_struct * tty)
39364
39365 spin_lock_irqsave(&hvcsd->lock, flags);
39366 /* Preserve this so that we know how many kref refs to put */
39367- temp_open_count = hvcsd->port.count;
39368+ temp_open_count = atomic_read(&hvcsd->port.count);
39369
39370 /*
39371 * Don't kref put inside the spinlock because the destruction
39372@@ -1286,7 +1287,7 @@ static void hvcs_hangup(struct tty_struct * tty)
39373 tty->driver_data = NULL;
39374 hvcsd->port.tty = NULL;
39375
39376- hvcsd->port.count = 0;
39377+ atomic_set(&hvcsd->port.count, 0);
39378
39379 /* This will drop any buffered data on the floor which is OK in a hangup
39380 * scenario. */
39381@@ -1357,7 +1358,7 @@ static int hvcs_write(struct tty_struct *tty,
39382 * the middle of a write operation? This is a crummy place to do this
39383 * but we want to keep it all in the spinlock.
39384 */
39385- if (hvcsd->port.count <= 0) {
39386+ if (atomic_read(&hvcsd->port.count) <= 0) {
39387 spin_unlock_irqrestore(&hvcsd->lock, flags);
39388 return -ENODEV;
39389 }
39390@@ -1431,7 +1432,7 @@ static int hvcs_write_room(struct tty_struct *tty)
39391 {
39392 struct hvcs_struct *hvcsd = tty->driver_data;
39393
39394- if (!hvcsd || hvcsd->port.count <= 0)
39395+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
39396 return 0;
39397
39398 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
39399diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
39400index 160f0ad..588b853 100644
39401--- a/drivers/tty/ipwireless/tty.c
39402+++ b/drivers/tty/ipwireless/tty.c
39403@@ -29,6 +29,7 @@
39404 #include <linux/tty_driver.h>
39405 #include <linux/tty_flip.h>
39406 #include <linux/uaccess.h>
39407+#include <asm/local.h>
39408
39409 #include "tty.h"
39410 #include "network.h"
39411@@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
39412 mutex_unlock(&tty->ipw_tty_mutex);
39413 return -ENODEV;
39414 }
39415- if (tty->port.count == 0)
39416+ if (atomic_read(&tty->port.count) == 0)
39417 tty->tx_bytes_queued = 0;
39418
39419- tty->port.count++;
39420+ atomic_inc(&tty->port.count);
39421
39422 tty->port.tty = linux_tty;
39423 linux_tty->driver_data = tty;
39424@@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
39425
39426 static void do_ipw_close(struct ipw_tty *tty)
39427 {
39428- tty->port.count--;
39429-
39430- if (tty->port.count == 0) {
39431+ if (atomic_dec_return(&tty->port.count) == 0) {
39432 struct tty_struct *linux_tty = tty->port.tty;
39433
39434 if (linux_tty != NULL) {
39435@@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
39436 return;
39437
39438 mutex_lock(&tty->ipw_tty_mutex);
39439- if (tty->port.count == 0) {
39440+ if (atomic_read(&tty->port.count) == 0) {
39441 mutex_unlock(&tty->ipw_tty_mutex);
39442 return;
39443 }
39444@@ -170,7 +169,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
39445 return;
39446 }
39447
39448- if (!tty->port.count) {
39449+ if (!atomic_read(&tty->port.count)) {
39450 mutex_unlock(&tty->ipw_tty_mutex);
39451 return;
39452 }
39453@@ -212,7 +211,7 @@ static int ipw_write(struct tty_struct *linux_tty,
39454 return -ENODEV;
39455
39456 mutex_lock(&tty->ipw_tty_mutex);
39457- if (!tty->port.count) {
39458+ if (!atomic_read(&tty->port.count)) {
39459 mutex_unlock(&tty->ipw_tty_mutex);
39460 return -EINVAL;
39461 }
39462@@ -252,7 +251,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
39463 if (!tty)
39464 return -ENODEV;
39465
39466- if (!tty->port.count)
39467+ if (!atomic_read(&tty->port.count))
39468 return -EINVAL;
39469
39470 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
39471@@ -294,7 +293,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
39472 if (!tty)
39473 return 0;
39474
39475- if (!tty->port.count)
39476+ if (!atomic_read(&tty->port.count))
39477 return 0;
39478
39479 return tty->tx_bytes_queued;
39480@@ -375,7 +374,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
39481 if (!tty)
39482 return -ENODEV;
39483
39484- if (!tty->port.count)
39485+ if (!atomic_read(&tty->port.count))
39486 return -EINVAL;
39487
39488 return get_control_lines(tty);
39489@@ -391,7 +390,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
39490 if (!tty)
39491 return -ENODEV;
39492
39493- if (!tty->port.count)
39494+ if (!atomic_read(&tty->port.count))
39495 return -EINVAL;
39496
39497 return set_control_lines(tty, set, clear);
39498@@ -405,7 +404,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
39499 if (!tty)
39500 return -ENODEV;
39501
39502- if (!tty->port.count)
39503+ if (!atomic_read(&tty->port.count))
39504 return -EINVAL;
39505
39506 /* FIXME: Exactly how is the tty object locked here .. */
39507@@ -561,7 +560,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
39508 * are gone */
39509 mutex_lock(&ttyj->ipw_tty_mutex);
39510 }
39511- while (ttyj->port.count)
39512+ while (atomic_read(&ttyj->port.count))
39513 do_ipw_close(ttyj);
39514 ipwireless_disassociate_network_ttys(network,
39515 ttyj->channel_idx);
39516diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
39517index 56e616b..9d9f10a 100644
39518--- a/drivers/tty/moxa.c
39519+++ b/drivers/tty/moxa.c
39520@@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
39521 }
39522
39523 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
39524- ch->port.count++;
39525+ atomic_inc(&ch->port.count);
39526 tty->driver_data = ch;
39527 tty_port_tty_set(&ch->port, tty);
39528 mutex_lock(&ch->port.mutex);
39529diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
39530index 1e8e8ce..a9efc93 100644
39531--- a/drivers/tty/n_gsm.c
39532+++ b/drivers/tty/n_gsm.c
39533@@ -1638,7 +1638,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
39534 kref_init(&dlci->ref);
39535 mutex_init(&dlci->mutex);
39536 dlci->fifo = &dlci->_fifo;
39537- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
39538+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
39539 kfree(dlci);
39540 return NULL;
39541 }
39542@@ -2925,7 +2925,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
39543 struct gsm_dlci *dlci = tty->driver_data;
39544 struct tty_port *port = &dlci->port;
39545
39546- port->count++;
39547+ atomic_inc(&port->count);
39548 dlci_get(dlci);
39549 dlci_get(dlci->gsm->dlci[0]);
39550 mux_get(dlci->gsm);
39551diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
39552index 8c0b7b4..e88f052 100644
39553--- a/drivers/tty/n_tty.c
39554+++ b/drivers/tty/n_tty.c
39555@@ -2142,6 +2142,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
39556 {
39557 *ops = tty_ldisc_N_TTY;
39558 ops->owner = NULL;
39559- ops->refcount = ops->flags = 0;
39560+ atomic_set(&ops->refcount, 0);
39561+ ops->flags = 0;
39562 }
39563 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
39564diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
39565index a82b399..331a220 100644
39566--- a/drivers/tty/pty.c
39567+++ b/drivers/tty/pty.c
39568@@ -728,8 +728,10 @@ static void __init unix98_pty_init(void)
39569 panic("Couldn't register Unix98 pts driver");
39570
39571 /* Now create the /dev/ptmx special device */
39572+ pax_open_kernel();
39573 tty_default_fops(&ptmx_fops);
39574- ptmx_fops.open = ptmx_open;
39575+ *(void **)&ptmx_fops.open = ptmx_open;
39576+ pax_close_kernel();
39577
39578 cdev_init(&ptmx_cdev, &ptmx_fops);
39579 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
39580diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
39581index 9700d34..df7520c 100644
39582--- a/drivers/tty/rocket.c
39583+++ b/drivers/tty/rocket.c
39584@@ -924,7 +924,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
39585 tty->driver_data = info;
39586 tty_port_tty_set(port, tty);
39587
39588- if (port->count++ == 0) {
39589+ if (atomic_inc_return(&port->count) == 1) {
39590 atomic_inc(&rp_num_ports_open);
39591
39592 #ifdef ROCKET_DEBUG_OPEN
39593@@ -933,7 +933,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
39594 #endif
39595 }
39596 #ifdef ROCKET_DEBUG_OPEN
39597- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
39598+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
39599 #endif
39600
39601 /*
39602@@ -1528,7 +1528,7 @@ static void rp_hangup(struct tty_struct *tty)
39603 spin_unlock_irqrestore(&info->port.lock, flags);
39604 return;
39605 }
39606- if (info->port.count)
39607+ if (atomic_read(&info->port.count))
39608 atomic_dec(&rp_num_ports_open);
39609 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
39610 spin_unlock_irqrestore(&info->port.lock, flags);
39611diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
39612index 1002054..dd644a8 100644
39613--- a/drivers/tty/serial/kgdboc.c
39614+++ b/drivers/tty/serial/kgdboc.c
39615@@ -24,8 +24,9 @@
39616 #define MAX_CONFIG_LEN 40
39617
39618 static struct kgdb_io kgdboc_io_ops;
39619+static struct kgdb_io kgdboc_io_ops_console;
39620
39621-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
39622+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
39623 static int configured = -1;
39624
39625 static char config[MAX_CONFIG_LEN];
39626@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
39627 kgdboc_unregister_kbd();
39628 if (configured == 1)
39629 kgdb_unregister_io_module(&kgdboc_io_ops);
39630+ else if (configured == 2)
39631+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
39632 }
39633
39634 static int configure_kgdboc(void)
39635@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
39636 int err;
39637 char *cptr = config;
39638 struct console *cons;
39639+ int is_console = 0;
39640
39641 err = kgdboc_option_setup(config);
39642 if (err || !strlen(config) || isspace(config[0]))
39643 goto noconfig;
39644
39645 err = -ENODEV;
39646- kgdboc_io_ops.is_console = 0;
39647 kgdb_tty_driver = NULL;
39648
39649 kgdboc_use_kms = 0;
39650@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
39651 int idx;
39652 if (cons->device && cons->device(cons, &idx) == p &&
39653 idx == tty_line) {
39654- kgdboc_io_ops.is_console = 1;
39655+ is_console = 1;
39656 break;
39657 }
39658 cons = cons->next;
39659@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
39660 kgdb_tty_line = tty_line;
39661
39662 do_register:
39663- err = kgdb_register_io_module(&kgdboc_io_ops);
39664+ if (is_console) {
39665+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
39666+ configured = 2;
39667+ } else {
39668+ err = kgdb_register_io_module(&kgdboc_io_ops);
39669+ configured = 1;
39670+ }
39671 if (err)
39672 goto noconfig;
39673
39674@@ -205,8 +214,6 @@ do_register:
39675 if (err)
39676 goto nmi_con_failed;
39677
39678- configured = 1;
39679-
39680 return 0;
39681
39682 nmi_con_failed:
39683@@ -223,7 +230,7 @@ noconfig:
39684 static int __init init_kgdboc(void)
39685 {
39686 /* Already configured? */
39687- if (configured == 1)
39688+ if (configured >= 1)
39689 return 0;
39690
39691 return configure_kgdboc();
39692@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
39693 if (config[len - 1] == '\n')
39694 config[len - 1] = '\0';
39695
39696- if (configured == 1)
39697+ if (configured >= 1)
39698 cleanup_kgdboc();
39699
39700 /* Go and configure with the new params. */
39701@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
39702 .post_exception = kgdboc_post_exp_handler,
39703 };
39704
39705+static struct kgdb_io kgdboc_io_ops_console = {
39706+ .name = "kgdboc",
39707+ .read_char = kgdboc_get_char,
39708+ .write_char = kgdboc_put_char,
39709+ .pre_exception = kgdboc_pre_exp_handler,
39710+ .post_exception = kgdboc_post_exp_handler,
39711+ .is_console = 1
39712+};
39713+
39714 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
39715 /* This is only available if kgdboc is a built in for early debugging */
39716 static int __init kgdboc_early_init(char *opt)
39717diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
39718index 7f04717..0f3794f 100644
39719--- a/drivers/tty/serial/samsung.c
39720+++ b/drivers/tty/serial/samsung.c
39721@@ -445,11 +445,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
39722 }
39723 }
39724
39725+static int s3c64xx_serial_startup(struct uart_port *port);
39726 static int s3c24xx_serial_startup(struct uart_port *port)
39727 {
39728 struct s3c24xx_uart_port *ourport = to_ourport(port);
39729 int ret;
39730
39731+ /* Startup sequence is different for s3c64xx and higher SoC's */
39732+ if (s3c24xx_serial_has_interrupt_mask(port))
39733+ return s3c64xx_serial_startup(port);
39734+
39735 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
39736 port->mapbase, port->membase);
39737
39738@@ -1115,10 +1120,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
39739 /* setup info for port */
39740 port->dev = &platdev->dev;
39741
39742- /* Startup sequence is different for s3c64xx and higher SoC's */
39743- if (s3c24xx_serial_has_interrupt_mask(port))
39744- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
39745-
39746 port->uartclk = 1;
39747
39748 if (cfg->uart_flags & UPF_CONS_FLOW) {
39749diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
39750index 0fcfd98..8244fce 100644
39751--- a/drivers/tty/serial/serial_core.c
39752+++ b/drivers/tty/serial/serial_core.c
39753@@ -1408,7 +1408,7 @@ static void uart_hangup(struct tty_struct *tty)
39754 uart_flush_buffer(tty);
39755 uart_shutdown(tty, state);
39756 spin_lock_irqsave(&port->lock, flags);
39757- port->count = 0;
39758+ atomic_set(&port->count, 0);
39759 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
39760 spin_unlock_irqrestore(&port->lock, flags);
39761 tty_port_tty_set(port, NULL);
39762@@ -1504,7 +1504,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
39763 goto end;
39764 }
39765
39766- port->count++;
39767+ atomic_inc(&port->count);
39768 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
39769 retval = -ENXIO;
39770 goto err_dec_count;
39771@@ -1531,7 +1531,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
39772 /*
39773 * Make sure the device is in D0 state.
39774 */
39775- if (port->count == 1)
39776+ if (atomic_read(&port->count) == 1)
39777 uart_change_pm(state, 0);
39778
39779 /*
39780@@ -1549,7 +1549,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
39781 end:
39782 return retval;
39783 err_dec_count:
39784- port->count--;
39785+ atomic_inc(&port->count);
39786 mutex_unlock(&port->mutex);
39787 goto end;
39788 }
39789diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
39790index 70e3a52..5742052 100644
39791--- a/drivers/tty/synclink.c
39792+++ b/drivers/tty/synclink.c
39793@@ -3095,7 +3095,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
39794
39795 if (debug_level >= DEBUG_LEVEL_INFO)
39796 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
39797- __FILE__,__LINE__, info->device_name, info->port.count);
39798+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
39799
39800 if (tty_port_close_start(&info->port, tty, filp) == 0)
39801 goto cleanup;
39802@@ -3113,7 +3113,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
39803 cleanup:
39804 if (debug_level >= DEBUG_LEVEL_INFO)
39805 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
39806- tty->driver->name, info->port.count);
39807+ tty->driver->name, atomic_read(&info->port.count));
39808
39809 } /* end of mgsl_close() */
39810
39811@@ -3212,8 +3212,8 @@ static void mgsl_hangup(struct tty_struct *tty)
39812
39813 mgsl_flush_buffer(tty);
39814 shutdown(info);
39815-
39816- info->port.count = 0;
39817+
39818+ atomic_set(&info->port.count, 0);
39819 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
39820 info->port.tty = NULL;
39821
39822@@ -3302,12 +3302,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
39823
39824 if (debug_level >= DEBUG_LEVEL_INFO)
39825 printk("%s(%d):block_til_ready before block on %s count=%d\n",
39826- __FILE__,__LINE__, tty->driver->name, port->count );
39827+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
39828
39829 spin_lock_irqsave(&info->irq_spinlock, flags);
39830 if (!tty_hung_up_p(filp)) {
39831 extra_count = true;
39832- port->count--;
39833+ atomic_dec(&port->count);
39834 }
39835 spin_unlock_irqrestore(&info->irq_spinlock, flags);
39836 port->blocked_open++;
39837@@ -3336,7 +3336,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
39838
39839 if (debug_level >= DEBUG_LEVEL_INFO)
39840 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
39841- __FILE__,__LINE__, tty->driver->name, port->count );
39842+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
39843
39844 tty_unlock(tty);
39845 schedule();
39846@@ -3348,12 +3348,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
39847
39848 /* FIXME: Racy on hangup during close wait */
39849 if (extra_count)
39850- port->count++;
39851+ atomic_inc(&port->count);
39852 port->blocked_open--;
39853
39854 if (debug_level >= DEBUG_LEVEL_INFO)
39855 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
39856- __FILE__,__LINE__, tty->driver->name, port->count );
39857+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
39858
39859 if (!retval)
39860 port->flags |= ASYNC_NORMAL_ACTIVE;
39861@@ -3405,7 +3405,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
39862
39863 if (debug_level >= DEBUG_LEVEL_INFO)
39864 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
39865- __FILE__,__LINE__,tty->driver->name, info->port.count);
39866+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
39867
39868 /* If port is closing, signal caller to try again */
39869 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
39870@@ -3424,10 +3424,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
39871 spin_unlock_irqrestore(&info->netlock, flags);
39872 goto cleanup;
39873 }
39874- info->port.count++;
39875+ atomic_inc(&info->port.count);
39876 spin_unlock_irqrestore(&info->netlock, flags);
39877
39878- if (info->port.count == 1) {
39879+ if (atomic_read(&info->port.count) == 1) {
39880 /* 1st open on this device, init hardware */
39881 retval = startup(info);
39882 if (retval < 0)
39883@@ -3451,8 +3451,8 @@ cleanup:
39884 if (retval) {
39885 if (tty->count == 1)
39886 info->port.tty = NULL; /* tty layer will release tty struct */
39887- if(info->port.count)
39888- info->port.count--;
39889+ if (atomic_read(&info->port.count))
39890+ atomic_dec(&info->port.count);
39891 }
39892
39893 return retval;
39894@@ -7661,7 +7661,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
39895 unsigned short new_crctype;
39896
39897 /* return error if TTY interface open */
39898- if (info->port.count)
39899+ if (atomic_read(&info->port.count))
39900 return -EBUSY;
39901
39902 switch (encoding)
39903@@ -7756,7 +7756,7 @@ static int hdlcdev_open(struct net_device *dev)
39904
39905 /* arbitrate between network and tty opens */
39906 spin_lock_irqsave(&info->netlock, flags);
39907- if (info->port.count != 0 || info->netcount != 0) {
39908+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
39909 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
39910 spin_unlock_irqrestore(&info->netlock, flags);
39911 return -EBUSY;
39912@@ -7842,7 +7842,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
39913 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
39914
39915 /* return error if TTY interface open */
39916- if (info->port.count)
39917+ if (atomic_read(&info->port.count))
39918 return -EBUSY;
39919
39920 if (cmd != SIOCWANDEV)
39921diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
39922index b38e954..ce45b38 100644
39923--- a/drivers/tty/synclink_gt.c
39924+++ b/drivers/tty/synclink_gt.c
39925@@ -671,7 +671,7 @@ static int open(struct tty_struct *tty, struct file *filp)
39926 tty->driver_data = info;
39927 info->port.tty = tty;
39928
39929- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
39930+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
39931
39932 /* If port is closing, signal caller to try again */
39933 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
39934@@ -692,10 +692,10 @@ static int open(struct tty_struct *tty, struct file *filp)
39935 mutex_unlock(&info->port.mutex);
39936 goto cleanup;
39937 }
39938- info->port.count++;
39939+ atomic_inc(&info->port.count);
39940 spin_unlock_irqrestore(&info->netlock, flags);
39941
39942- if (info->port.count == 1) {
39943+ if (atomic_read(&info->port.count) == 1) {
39944 /* 1st open on this device, init hardware */
39945 retval = startup(info);
39946 if (retval < 0) {
39947@@ -716,8 +716,8 @@ cleanup:
39948 if (retval) {
39949 if (tty->count == 1)
39950 info->port.tty = NULL; /* tty layer will release tty struct */
39951- if(info->port.count)
39952- info->port.count--;
39953+ if(atomic_read(&info->port.count))
39954+ atomic_dec(&info->port.count);
39955 }
39956
39957 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
39958@@ -730,7 +730,7 @@ static void close(struct tty_struct *tty, struct file *filp)
39959
39960 if (sanity_check(info, tty->name, "close"))
39961 return;
39962- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
39963+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
39964
39965 if (tty_port_close_start(&info->port, tty, filp) == 0)
39966 goto cleanup;
39967@@ -747,7 +747,7 @@ static void close(struct tty_struct *tty, struct file *filp)
39968 tty_port_close_end(&info->port, tty);
39969 info->port.tty = NULL;
39970 cleanup:
39971- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
39972+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
39973 }
39974
39975 static void hangup(struct tty_struct *tty)
39976@@ -765,7 +765,7 @@ static void hangup(struct tty_struct *tty)
39977 shutdown(info);
39978
39979 spin_lock_irqsave(&info->port.lock, flags);
39980- info->port.count = 0;
39981+ atomic_set(&info->port.count, 0);
39982 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
39983 info->port.tty = NULL;
39984 spin_unlock_irqrestore(&info->port.lock, flags);
39985@@ -1450,7 +1450,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
39986 unsigned short new_crctype;
39987
39988 /* return error if TTY interface open */
39989- if (info->port.count)
39990+ if (atomic_read(&info->port.count))
39991 return -EBUSY;
39992
39993 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
39994@@ -1545,7 +1545,7 @@ static int hdlcdev_open(struct net_device *dev)
39995
39996 /* arbitrate between network and tty opens */
39997 spin_lock_irqsave(&info->netlock, flags);
39998- if (info->port.count != 0 || info->netcount != 0) {
39999+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
40000 DBGINFO(("%s hdlc_open busy\n", dev->name));
40001 spin_unlock_irqrestore(&info->netlock, flags);
40002 return -EBUSY;
40003@@ -1630,7 +1630,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
40004 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
40005
40006 /* return error if TTY interface open */
40007- if (info->port.count)
40008+ if (atomic_read(&info->port.count))
40009 return -EBUSY;
40010
40011 if (cmd != SIOCWANDEV)
40012@@ -2419,7 +2419,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
40013 if (port == NULL)
40014 continue;
40015 spin_lock(&port->lock);
40016- if ((port->port.count || port->netcount) &&
40017+ if ((atomic_read(&port->port.count) || port->netcount) &&
40018 port->pending_bh && !port->bh_running &&
40019 !port->bh_requested) {
40020 DBGISR(("%s bh queued\n", port->device_name));
40021@@ -3308,7 +3308,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
40022 spin_lock_irqsave(&info->lock, flags);
40023 if (!tty_hung_up_p(filp)) {
40024 extra_count = true;
40025- port->count--;
40026+ atomic_dec(&port->count);
40027 }
40028 spin_unlock_irqrestore(&info->lock, flags);
40029 port->blocked_open++;
40030@@ -3345,7 +3345,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
40031 remove_wait_queue(&port->open_wait, &wait);
40032
40033 if (extra_count)
40034- port->count++;
40035+ atomic_inc(&port->count);
40036 port->blocked_open--;
40037
40038 if (!retval)
40039diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
40040index f17d9f3..27a041b 100644
40041--- a/drivers/tty/synclinkmp.c
40042+++ b/drivers/tty/synclinkmp.c
40043@@ -751,7 +751,7 @@ static int open(struct tty_struct *tty, struct file *filp)
40044
40045 if (debug_level >= DEBUG_LEVEL_INFO)
40046 printk("%s(%d):%s open(), old ref count = %d\n",
40047- __FILE__,__LINE__,tty->driver->name, info->port.count);
40048+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
40049
40050 /* If port is closing, signal caller to try again */
40051 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
40052@@ -770,10 +770,10 @@ static int open(struct tty_struct *tty, struct file *filp)
40053 spin_unlock_irqrestore(&info->netlock, flags);
40054 goto cleanup;
40055 }
40056- info->port.count++;
40057+ atomic_inc(&info->port.count);
40058 spin_unlock_irqrestore(&info->netlock, flags);
40059
40060- if (info->port.count == 1) {
40061+ if (atomic_read(&info->port.count) == 1) {
40062 /* 1st open on this device, init hardware */
40063 retval = startup(info);
40064 if (retval < 0)
40065@@ -797,8 +797,8 @@ cleanup:
40066 if (retval) {
40067 if (tty->count == 1)
40068 info->port.tty = NULL; /* tty layer will release tty struct */
40069- if(info->port.count)
40070- info->port.count--;
40071+ if(atomic_read(&info->port.count))
40072+ atomic_dec(&info->port.count);
40073 }
40074
40075 return retval;
40076@@ -816,7 +816,7 @@ static void close(struct tty_struct *tty, struct file *filp)
40077
40078 if (debug_level >= DEBUG_LEVEL_INFO)
40079 printk("%s(%d):%s close() entry, count=%d\n",
40080- __FILE__,__LINE__, info->device_name, info->port.count);
40081+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
40082
40083 if (tty_port_close_start(&info->port, tty, filp) == 0)
40084 goto cleanup;
40085@@ -835,7 +835,7 @@ static void close(struct tty_struct *tty, struct file *filp)
40086 cleanup:
40087 if (debug_level >= DEBUG_LEVEL_INFO)
40088 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
40089- tty->driver->name, info->port.count);
40090+ tty->driver->name, atomic_read(&info->port.count));
40091 }
40092
40093 /* Called by tty_hangup() when a hangup is signaled.
40094@@ -858,7 +858,7 @@ static void hangup(struct tty_struct *tty)
40095 shutdown(info);
40096
40097 spin_lock_irqsave(&info->port.lock, flags);
40098- info->port.count = 0;
40099+ atomic_set(&info->port.count, 0);
40100 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
40101 info->port.tty = NULL;
40102 spin_unlock_irqrestore(&info->port.lock, flags);
40103@@ -1566,7 +1566,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
40104 unsigned short new_crctype;
40105
40106 /* return error if TTY interface open */
40107- if (info->port.count)
40108+ if (atomic_read(&info->port.count))
40109 return -EBUSY;
40110
40111 switch (encoding)
40112@@ -1661,7 +1661,7 @@ static int hdlcdev_open(struct net_device *dev)
40113
40114 /* arbitrate between network and tty opens */
40115 spin_lock_irqsave(&info->netlock, flags);
40116- if (info->port.count != 0 || info->netcount != 0) {
40117+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
40118 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
40119 spin_unlock_irqrestore(&info->netlock, flags);
40120 return -EBUSY;
40121@@ -1747,7 +1747,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
40122 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
40123
40124 /* return error if TTY interface open */
40125- if (info->port.count)
40126+ if (atomic_read(&info->port.count))
40127 return -EBUSY;
40128
40129 if (cmd != SIOCWANDEV)
40130@@ -2632,7 +2632,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
40131 * do not request bottom half processing if the
40132 * device is not open in a normal mode.
40133 */
40134- if ( port && (port->port.count || port->netcount) &&
40135+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
40136 port->pending_bh && !port->bh_running &&
40137 !port->bh_requested ) {
40138 if ( debug_level >= DEBUG_LEVEL_ISR )
40139@@ -3330,12 +3330,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
40140
40141 if (debug_level >= DEBUG_LEVEL_INFO)
40142 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
40143- __FILE__,__LINE__, tty->driver->name, port->count );
40144+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
40145
40146 spin_lock_irqsave(&info->lock, flags);
40147 if (!tty_hung_up_p(filp)) {
40148 extra_count = true;
40149- port->count--;
40150+ atomic_dec(&port->count);
40151 }
40152 spin_unlock_irqrestore(&info->lock, flags);
40153 port->blocked_open++;
40154@@ -3364,7 +3364,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
40155
40156 if (debug_level >= DEBUG_LEVEL_INFO)
40157 printk("%s(%d):%s block_til_ready() count=%d\n",
40158- __FILE__,__LINE__, tty->driver->name, port->count );
40159+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
40160
40161 tty_unlock(tty);
40162 schedule();
40163@@ -3375,12 +3375,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
40164 remove_wait_queue(&port->open_wait, &wait);
40165
40166 if (extra_count)
40167- port->count++;
40168+ atomic_inc(&port->count);
40169 port->blocked_open--;
40170
40171 if (debug_level >= DEBUG_LEVEL_INFO)
40172 printk("%s(%d):%s block_til_ready() after, count=%d\n",
40173- __FILE__,__LINE__, tty->driver->name, port->count );
40174+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
40175
40176 if (!retval)
40177 port->flags |= ASYNC_NORMAL_ACTIVE;
40178diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
40179index 16ee6ce..bfcac57 100644
40180--- a/drivers/tty/sysrq.c
40181+++ b/drivers/tty/sysrq.c
40182@@ -866,7 +866,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
40183 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
40184 size_t count, loff_t *ppos)
40185 {
40186- if (count) {
40187+ if (count && capable(CAP_SYS_ADMIN)) {
40188 char c;
40189
40190 if (get_user(c, buf))
40191diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
40192index 2ea176b..2877bc8 100644
40193--- a/drivers/tty/tty_io.c
40194+++ b/drivers/tty/tty_io.c
40195@@ -3395,7 +3395,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
40196
40197 void tty_default_fops(struct file_operations *fops)
40198 {
40199- *fops = tty_fops;
40200+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
40201 }
40202
40203 /*
40204diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
40205index 0f2a2c5..471e228 100644
40206--- a/drivers/tty/tty_ldisc.c
40207+++ b/drivers/tty/tty_ldisc.c
40208@@ -56,7 +56,7 @@ static void put_ldisc(struct tty_ldisc *ld)
40209 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
40210 struct tty_ldisc_ops *ldo = ld->ops;
40211
40212- ldo->refcount--;
40213+ atomic_dec(&ldo->refcount);
40214 module_put(ldo->owner);
40215 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
40216
40217@@ -91,7 +91,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
40218 spin_lock_irqsave(&tty_ldisc_lock, flags);
40219 tty_ldiscs[disc] = new_ldisc;
40220 new_ldisc->num = disc;
40221- new_ldisc->refcount = 0;
40222+ atomic_set(&new_ldisc->refcount, 0);
40223 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
40224
40225 return ret;
40226@@ -119,7 +119,7 @@ int tty_unregister_ldisc(int disc)
40227 return -EINVAL;
40228
40229 spin_lock_irqsave(&tty_ldisc_lock, flags);
40230- if (tty_ldiscs[disc]->refcount)
40231+ if (atomic_read(&tty_ldiscs[disc]->refcount))
40232 ret = -EBUSY;
40233 else
40234 tty_ldiscs[disc] = NULL;
40235@@ -140,7 +140,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
40236 if (ldops) {
40237 ret = ERR_PTR(-EAGAIN);
40238 if (try_module_get(ldops->owner)) {
40239- ldops->refcount++;
40240+ atomic_inc(&ldops->refcount);
40241 ret = ldops;
40242 }
40243 }
40244@@ -153,7 +153,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
40245 unsigned long flags;
40246
40247 spin_lock_irqsave(&tty_ldisc_lock, flags);
40248- ldops->refcount--;
40249+ atomic_dec(&ldops->refcount);
40250 module_put(ldops->owner);
40251 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
40252 }
40253diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
40254index d7bdd8d..feaef30 100644
40255--- a/drivers/tty/tty_port.c
40256+++ b/drivers/tty/tty_port.c
40257@@ -202,7 +202,7 @@ void tty_port_hangup(struct tty_port *port)
40258 unsigned long flags;
40259
40260 spin_lock_irqsave(&port->lock, flags);
40261- port->count = 0;
40262+ atomic_set(&port->count, 0);
40263 port->flags &= ~ASYNC_NORMAL_ACTIVE;
40264 if (port->tty) {
40265 set_bit(TTY_IO_ERROR, &port->tty->flags);
40266@@ -328,7 +328,7 @@ int tty_port_block_til_ready(struct tty_port *port,
40267 /* The port lock protects the port counts */
40268 spin_lock_irqsave(&port->lock, flags);
40269 if (!tty_hung_up_p(filp))
40270- port->count--;
40271+ atomic_dec(&port->count);
40272 port->blocked_open++;
40273 spin_unlock_irqrestore(&port->lock, flags);
40274
40275@@ -370,7 +370,7 @@ int tty_port_block_til_ready(struct tty_port *port,
40276 we must not mess that up further */
40277 spin_lock_irqsave(&port->lock, flags);
40278 if (!tty_hung_up_p(filp))
40279- port->count++;
40280+ atomic_inc(&port->count);
40281 port->blocked_open--;
40282 if (retval == 0)
40283 port->flags |= ASYNC_NORMAL_ACTIVE;
40284@@ -390,19 +390,19 @@ int tty_port_close_start(struct tty_port *port,
40285 return 0;
40286 }
40287
40288- if (tty->count == 1 && port->count != 1) {
40289+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
40290 printk(KERN_WARNING
40291 "tty_port_close_start: tty->count = 1 port count = %d.\n",
40292- port->count);
40293- port->count = 1;
40294+ atomic_read(&port->count));
40295+ atomic_set(&port->count, 1);
40296 }
40297- if (--port->count < 0) {
40298+ if (atomic_dec_return(&port->count) < 0) {
40299 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
40300- port->count);
40301- port->count = 0;
40302+ atomic_read(&port->count));
40303+ atomic_set(&port->count, 0);
40304 }
40305
40306- if (port->count) {
40307+ if (atomic_read(&port->count)) {
40308 spin_unlock_irqrestore(&port->lock, flags);
40309 if (port->ops->drop)
40310 port->ops->drop(port);
40311@@ -500,7 +500,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
40312 {
40313 spin_lock_irq(&port->lock);
40314 if (!tty_hung_up_p(filp))
40315- ++port->count;
40316+ atomic_inc(&port->count);
40317 spin_unlock_irq(&port->lock);
40318 tty_port_tty_set(port, tty);
40319
40320diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
40321index 681765b..d3ccdf2 100644
40322--- a/drivers/tty/vt/keyboard.c
40323+++ b/drivers/tty/vt/keyboard.c
40324@@ -660,6 +660,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
40325 kbd->kbdmode == VC_OFF) &&
40326 value != KVAL(K_SAK))
40327 return; /* SAK is allowed even in raw mode */
40328+
40329+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
40330+ {
40331+ void *func = fn_handler[value];
40332+ if (func == fn_show_state || func == fn_show_ptregs ||
40333+ func == fn_show_mem)
40334+ return;
40335+ }
40336+#endif
40337+
40338 fn_handler[value](vc);
40339 }
40340
40341@@ -1808,9 +1818,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
40342 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
40343 return -EFAULT;
40344
40345- if (!capable(CAP_SYS_TTY_CONFIG))
40346- perm = 0;
40347-
40348 switch (cmd) {
40349 case KDGKBENT:
40350 /* Ensure another thread doesn't free it under us */
40351@@ -1825,6 +1832,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
40352 spin_unlock_irqrestore(&kbd_event_lock, flags);
40353 return put_user(val, &user_kbe->kb_value);
40354 case KDSKBENT:
40355+ if (!capable(CAP_SYS_TTY_CONFIG))
40356+ perm = 0;
40357+
40358 if (!perm)
40359 return -EPERM;
40360 if (!i && v == K_NOSUCHMAP) {
40361@@ -1915,9 +1925,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
40362 int i, j, k;
40363 int ret;
40364
40365- if (!capable(CAP_SYS_TTY_CONFIG))
40366- perm = 0;
40367-
40368 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
40369 if (!kbs) {
40370 ret = -ENOMEM;
40371@@ -1951,6 +1958,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
40372 kfree(kbs);
40373 return ((p && *p) ? -EOVERFLOW : 0);
40374 case KDSKBSENT:
40375+ if (!capable(CAP_SYS_TTY_CONFIG))
40376+ perm = 0;
40377+
40378 if (!perm) {
40379 ret = -EPERM;
40380 goto reterr;
40381diff --git a/drivers/tty/vt/vc_screen.c b/drivers/tty/vt/vc_screen.c
40382index fa7268a..cb08d48 100644
40383--- a/drivers/tty/vt/vc_screen.c
40384+++ b/drivers/tty/vt/vc_screen.c
40385@@ -51,7 +51,7 @@
40386 #define CON_BUF_SIZE (CONFIG_BASE_SMALL ? 256 : PAGE_SIZE)
40387
40388 struct vcs_poll_data {
40389- struct notifier_block notifier;
40390+ notifier_block_no_const notifier;
40391 unsigned int cons_num;
40392 bool seen_last_update;
40393 wait_queue_head_t waitq;
40394diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
40395index 5110f36..8dc0a74 100644
40396--- a/drivers/uio/uio.c
40397+++ b/drivers/uio/uio.c
40398@@ -25,6 +25,7 @@
40399 #include <linux/kobject.h>
40400 #include <linux/cdev.h>
40401 #include <linux/uio_driver.h>
40402+#include <asm/local.h>
40403
40404 #define UIO_MAX_DEVICES (1U << MINORBITS)
40405
40406@@ -32,10 +33,10 @@ struct uio_device {
40407 struct module *owner;
40408 struct device *dev;
40409 int minor;
40410- atomic_t event;
40411+ atomic_unchecked_t event;
40412 struct fasync_struct *async_queue;
40413 wait_queue_head_t wait;
40414- int vma_count;
40415+ local_t vma_count;
40416 struct uio_info *info;
40417 struct kobject *map_dir;
40418 struct kobject *portio_dir;
40419@@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
40420 struct device_attribute *attr, char *buf)
40421 {
40422 struct uio_device *idev = dev_get_drvdata(dev);
40423- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
40424+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
40425 }
40426
40427 static struct device_attribute uio_class_attributes[] = {
40428@@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
40429 {
40430 struct uio_device *idev = info->uio_dev;
40431
40432- atomic_inc(&idev->event);
40433+ atomic_inc_unchecked(&idev->event);
40434 wake_up_interruptible(&idev->wait);
40435 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
40436 }
40437@@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
40438 }
40439
40440 listener->dev = idev;
40441- listener->event_count = atomic_read(&idev->event);
40442+ listener->event_count = atomic_read_unchecked(&idev->event);
40443 filep->private_data = listener;
40444
40445 if (idev->info->open) {
40446@@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
40447 return -EIO;
40448
40449 poll_wait(filep, &idev->wait, wait);
40450- if (listener->event_count != atomic_read(&idev->event))
40451+ if (listener->event_count != atomic_read_unchecked(&idev->event))
40452 return POLLIN | POLLRDNORM;
40453 return 0;
40454 }
40455@@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
40456 do {
40457 set_current_state(TASK_INTERRUPTIBLE);
40458
40459- event_count = atomic_read(&idev->event);
40460+ event_count = atomic_read_unchecked(&idev->event);
40461 if (event_count != listener->event_count) {
40462 if (copy_to_user(buf, &event_count, count))
40463 retval = -EFAULT;
40464@@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
40465 static void uio_vma_open(struct vm_area_struct *vma)
40466 {
40467 struct uio_device *idev = vma->vm_private_data;
40468- idev->vma_count++;
40469+ local_inc(&idev->vma_count);
40470 }
40471
40472 static void uio_vma_close(struct vm_area_struct *vma)
40473 {
40474 struct uio_device *idev = vma->vm_private_data;
40475- idev->vma_count--;
40476+ local_dec(&idev->vma_count);
40477 }
40478
40479 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
40480@@ -819,7 +820,7 @@ int __uio_register_device(struct module *owner,
40481 idev->owner = owner;
40482 idev->info = info;
40483 init_waitqueue_head(&idev->wait);
40484- atomic_set(&idev->event, 0);
40485+ atomic_set_unchecked(&idev->event, 0);
40486
40487 ret = uio_get_minor(idev);
40488 if (ret)
40489diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
40490index b7eb86a..36d28af 100644
40491--- a/drivers/usb/atm/cxacru.c
40492+++ b/drivers/usb/atm/cxacru.c
40493@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
40494 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
40495 if (ret < 2)
40496 return -EINVAL;
40497- if (index < 0 || index > 0x7f)
40498+ if (index > 0x7f)
40499 return -EINVAL;
40500 pos += tmp;
40501
40502diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
40503index 35f10bf..6a38a0b 100644
40504--- a/drivers/usb/atm/usbatm.c
40505+++ b/drivers/usb/atm/usbatm.c
40506@@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
40507 if (printk_ratelimit())
40508 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
40509 __func__, vpi, vci);
40510- atomic_inc(&vcc->stats->rx_err);
40511+ atomic_inc_unchecked(&vcc->stats->rx_err);
40512 return;
40513 }
40514
40515@@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
40516 if (length > ATM_MAX_AAL5_PDU) {
40517 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
40518 __func__, length, vcc);
40519- atomic_inc(&vcc->stats->rx_err);
40520+ atomic_inc_unchecked(&vcc->stats->rx_err);
40521 goto out;
40522 }
40523
40524@@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
40525 if (sarb->len < pdu_length) {
40526 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
40527 __func__, pdu_length, sarb->len, vcc);
40528- atomic_inc(&vcc->stats->rx_err);
40529+ atomic_inc_unchecked(&vcc->stats->rx_err);
40530 goto out;
40531 }
40532
40533 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
40534 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
40535 __func__, vcc);
40536- atomic_inc(&vcc->stats->rx_err);
40537+ atomic_inc_unchecked(&vcc->stats->rx_err);
40538 goto out;
40539 }
40540
40541@@ -389,7 +389,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
40542 if (printk_ratelimit())
40543 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
40544 __func__, length);
40545- atomic_inc(&vcc->stats->rx_drop);
40546+ atomic_inc_unchecked(&vcc->stats->rx_drop);
40547 goto out;
40548 }
40549
40550@@ -417,7 +417,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
40551
40552 vcc->push(vcc, skb);
40553
40554- atomic_inc(&vcc->stats->rx);
40555+ atomic_inc_unchecked(&vcc->stats->rx);
40556 out:
40557 skb_trim(sarb, 0);
40558 }
40559@@ -623,7 +623,7 @@ static void usbatm_tx_process(unsigned long data)
40560 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
40561
40562 usbatm_pop(vcc, skb);
40563- atomic_inc(&vcc->stats->tx);
40564+ atomic_inc_unchecked(&vcc->stats->tx);
40565
40566 skb = skb_dequeue(&instance->sndqueue);
40567 }
40568@@ -779,11 +779,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
40569 if (!left--)
40570 return sprintf(page,
40571 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
40572- atomic_read(&atm_dev->stats.aal5.tx),
40573- atomic_read(&atm_dev->stats.aal5.tx_err),
40574- atomic_read(&atm_dev->stats.aal5.rx),
40575- atomic_read(&atm_dev->stats.aal5.rx_err),
40576- atomic_read(&atm_dev->stats.aal5.rx_drop));
40577+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
40578+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
40579+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
40580+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
40581+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
40582
40583 if (!left--) {
40584 if (instance->disconnected)
40585diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
40586index f460de3..95ba1f6 100644
40587--- a/drivers/usb/core/devices.c
40588+++ b/drivers/usb/core/devices.c
40589@@ -126,7 +126,7 @@ static const char format_endpt[] =
40590 * time it gets called.
40591 */
40592 static struct device_connect_event {
40593- atomic_t count;
40594+ atomic_unchecked_t count;
40595 wait_queue_head_t wait;
40596 } device_event = {
40597 .count = ATOMIC_INIT(1),
40598@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
40599
40600 void usbfs_conn_disc_event(void)
40601 {
40602- atomic_add(2, &device_event.count);
40603+ atomic_add_unchecked(2, &device_event.count);
40604 wake_up(&device_event.wait);
40605 }
40606
40607@@ -647,7 +647,7 @@ static unsigned int usb_device_poll(struct file *file,
40608
40609 poll_wait(file, &device_event.wait, wait);
40610
40611- event_count = atomic_read(&device_event.count);
40612+ event_count = atomic_read_unchecked(&device_event.count);
40613 if (file->f_version != event_count) {
40614 file->f_version = event_count;
40615 return POLLIN | POLLRDNORM;
40616diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
40617index f034716..aed0368 100644
40618--- a/drivers/usb/core/hcd.c
40619+++ b/drivers/usb/core/hcd.c
40620@@ -1478,7 +1478,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
40621 */
40622 usb_get_urb(urb);
40623 atomic_inc(&urb->use_count);
40624- atomic_inc(&urb->dev->urbnum);
40625+ atomic_inc_unchecked(&urb->dev->urbnum);
40626 usbmon_urb_submit(&hcd->self, urb);
40627
40628 /* NOTE requirements on root-hub callers (usbfs and the hub
40629@@ -1505,7 +1505,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
40630 urb->hcpriv = NULL;
40631 INIT_LIST_HEAD(&urb->urb_list);
40632 atomic_dec(&urb->use_count);
40633- atomic_dec(&urb->dev->urbnum);
40634+ atomic_dec_unchecked(&urb->dev->urbnum);
40635 if (atomic_read(&urb->reject))
40636 wake_up(&usb_kill_urb_queue);
40637 usb_put_urb(urb);
40638diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
40639index 818e4a0..0fc9589 100644
40640--- a/drivers/usb/core/sysfs.c
40641+++ b/drivers/usb/core/sysfs.c
40642@@ -226,7 +226,7 @@ show_urbnum(struct device *dev, struct device_attribute *attr, char *buf)
40643 struct usb_device *udev;
40644
40645 udev = to_usb_device(dev);
40646- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
40647+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
40648 }
40649 static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL);
40650
40651diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
40652index cd8fb44..17fbe0c 100644
40653--- a/drivers/usb/core/usb.c
40654+++ b/drivers/usb/core/usb.c
40655@@ -397,7 +397,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
40656 set_dev_node(&dev->dev, dev_to_node(bus->controller));
40657 dev->state = USB_STATE_ATTACHED;
40658 dev->lpm_disable_count = 1;
40659- atomic_set(&dev->urbnum, 0);
40660+ atomic_set_unchecked(&dev->urbnum, 0);
40661
40662 INIT_LIST_HEAD(&dev->ep0.urb_list);
40663 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
40664diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
40665index 4bfa78a..902bfbd 100644
40666--- a/drivers/usb/early/ehci-dbgp.c
40667+++ b/drivers/usb/early/ehci-dbgp.c
40668@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
40669
40670 #ifdef CONFIG_KGDB
40671 static struct kgdb_io kgdbdbgp_io_ops;
40672-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
40673+static struct kgdb_io kgdbdbgp_io_ops_console;
40674+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
40675 #else
40676 #define dbgp_kgdb_mode (0)
40677 #endif
40678@@ -1047,6 +1048,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
40679 .write_char = kgdbdbgp_write_char,
40680 };
40681
40682+static struct kgdb_io kgdbdbgp_io_ops_console = {
40683+ .name = "kgdbdbgp",
40684+ .read_char = kgdbdbgp_read_char,
40685+ .write_char = kgdbdbgp_write_char,
40686+ .is_console = 1
40687+};
40688+
40689 static int kgdbdbgp_wait_time;
40690
40691 static int __init kgdbdbgp_parse_config(char *str)
40692@@ -1062,8 +1070,10 @@ static int __init kgdbdbgp_parse_config(char *str)
40693 ptr++;
40694 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
40695 }
40696- kgdb_register_io_module(&kgdbdbgp_io_ops);
40697- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
40698+ if (early_dbgp_console.index != -1)
40699+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
40700+ else
40701+ kgdb_register_io_module(&kgdbdbgp_io_ops);
40702
40703 return 0;
40704 }
40705diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
40706index f173952..83d6ec0 100644
40707--- a/drivers/usb/gadget/u_serial.c
40708+++ b/drivers/usb/gadget/u_serial.c
40709@@ -735,9 +735,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
40710 spin_lock_irq(&port->port_lock);
40711
40712 /* already open? Great. */
40713- if (port->port.count) {
40714+ if (atomic_read(&port->port.count)) {
40715 status = 0;
40716- port->port.count++;
40717+ atomic_inc(&port->port.count);
40718
40719 /* currently opening/closing? wait ... */
40720 } else if (port->openclose) {
40721@@ -796,7 +796,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
40722 tty->driver_data = port;
40723 port->port.tty = tty;
40724
40725- port->port.count = 1;
40726+ atomic_set(&port->port.count, 1);
40727 port->openclose = false;
40728
40729 /* if connected, start the I/O stream */
40730@@ -838,11 +838,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
40731
40732 spin_lock_irq(&port->port_lock);
40733
40734- if (port->port.count != 1) {
40735- if (port->port.count == 0)
40736+ if (atomic_read(&port->port.count) != 1) {
40737+ if (atomic_read(&port->port.count) == 0)
40738 WARN_ON(1);
40739 else
40740- --port->port.count;
40741+ atomic_dec(&port->port.count);
40742 goto exit;
40743 }
40744
40745@@ -852,7 +852,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
40746 * and sleep if necessary
40747 */
40748 port->openclose = true;
40749- port->port.count = 0;
40750+ atomic_set(&port->port.count, 0);
40751
40752 gser = port->port_usb;
40753 if (gser && gser->disconnect)
40754@@ -1157,7 +1157,7 @@ static int gs_closed(struct gs_port *port)
40755 int cond;
40756
40757 spin_lock_irq(&port->port_lock);
40758- cond = (port->port.count == 0) && !port->openclose;
40759+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
40760 spin_unlock_irq(&port->port_lock);
40761 return cond;
40762 }
40763@@ -1270,7 +1270,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
40764 /* if it's already open, start I/O ... and notify the serial
40765 * protocol about open/close status (connect/disconnect).
40766 */
40767- if (port->port.count) {
40768+ if (atomic_read(&port->port.count)) {
40769 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
40770 gs_start_io(port);
40771 if (gser->connect)
40772@@ -1317,7 +1317,7 @@ void gserial_disconnect(struct gserial *gser)
40773
40774 port->port_usb = NULL;
40775 gser->ioport = NULL;
40776- if (port->port.count > 0 || port->openclose) {
40777+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
40778 wake_up_interruptible(&port->drain_wait);
40779 if (port->port.tty)
40780 tty_hangup(port->port.tty);
40781@@ -1333,7 +1333,7 @@ void gserial_disconnect(struct gserial *gser)
40782
40783 /* finally, free any unused/unusable I/O buffers */
40784 spin_lock_irqsave(&port->port_lock, flags);
40785- if (port->port.count == 0 && !port->openclose)
40786+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
40787 gs_buf_free(&port->port_write_buf);
40788 gs_free_requests(gser->out, &port->read_pool, NULL);
40789 gs_free_requests(gser->out, &port->read_queue, NULL);
40790diff --git a/drivers/usb/musb/musb_dma.h b/drivers/usb/musb/musb_dma.h
40791index 24d3921..0c652ed 100644
40792--- a/drivers/usb/musb/musb_dma.h
40793+++ b/drivers/usb/musb/musb_dma.h
40794@@ -172,7 +172,7 @@ struct dma_controller {
40795 int (*is_compatible)(struct dma_channel *channel,
40796 u16 maxpacket,
40797 void *buf, u32 length);
40798-};
40799+} __no_const;
40800
40801 /* called after channel_program(), may indicate a fault */
40802 extern void musb_dma_completion(struct musb *musb, u8 epnum, u8 transmit);
40803diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
40804index 5f3bcd3..bfca43f 100644
40805--- a/drivers/usb/serial/console.c
40806+++ b/drivers/usb/serial/console.c
40807@@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
40808
40809 info->port = port;
40810
40811- ++port->port.count;
40812+ atomic_inc(&port->port.count);
40813 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
40814 if (serial->type->set_termios) {
40815 /*
40816@@ -174,7 +174,7 @@ static int usb_console_setup(struct console *co, char *options)
40817 }
40818 /* Now that any required fake tty operations are completed restore
40819 * the tty port count */
40820- --port->port.count;
40821+ atomic_dec(&port->port.count);
40822 /* The console is special in terms of closing the device so
40823 * indicate this port is now acting as a system console. */
40824 port->port.console = 1;
40825@@ -187,7 +187,7 @@ static int usb_console_setup(struct console *co, char *options)
40826 free_tty:
40827 kfree(tty);
40828 reset_open_count:
40829- port->port.count = 0;
40830+ atomic_set(&port->port.count, 0);
40831 usb_autopm_put_interface(serial->interface);
40832 error_get_interface:
40833 usb_serial_put(serial);
40834diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
40835index d6bea3e..60b250e 100644
40836--- a/drivers/usb/wusbcore/wa-hc.h
40837+++ b/drivers/usb/wusbcore/wa-hc.h
40838@@ -192,7 +192,7 @@ struct wahc {
40839 struct list_head xfer_delayed_list;
40840 spinlock_t xfer_list_lock;
40841 struct work_struct xfer_work;
40842- atomic_t xfer_id_count;
40843+ atomic_unchecked_t xfer_id_count;
40844 };
40845
40846
40847@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
40848 INIT_LIST_HEAD(&wa->xfer_delayed_list);
40849 spin_lock_init(&wa->xfer_list_lock);
40850 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
40851- atomic_set(&wa->xfer_id_count, 1);
40852+ atomic_set_unchecked(&wa->xfer_id_count, 1);
40853 }
40854
40855 /**
40856diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
40857index 57c01ab..8a05959 100644
40858--- a/drivers/usb/wusbcore/wa-xfer.c
40859+++ b/drivers/usb/wusbcore/wa-xfer.c
40860@@ -296,7 +296,7 @@ out:
40861 */
40862 static void wa_xfer_id_init(struct wa_xfer *xfer)
40863 {
40864- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
40865+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
40866 }
40867
40868 /*
40869diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
40870index 56097c6..4f38643 100644
40871--- a/drivers/vfio/vfio.c
40872+++ b/drivers/vfio/vfio.c
40873@@ -71,7 +71,7 @@ struct vfio_group {
40874 struct list_head device_list;
40875 struct mutex device_lock;
40876 struct device *dev;
40877- struct notifier_block nb;
40878+ notifier_block_no_const nb;
40879 struct list_head vfio_next;
40880 struct list_head container_next;
40881 };
40882diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
40883index dedaf81..b0f11ab 100644
40884--- a/drivers/vhost/vhost.c
40885+++ b/drivers/vhost/vhost.c
40886@@ -634,7 +634,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
40887 return 0;
40888 }
40889
40890-static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
40891+static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
40892 {
40893 struct file *eventfp, *filep = NULL;
40894 bool pollstart = false, pollstop = false;
40895diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
40896index 0fefa84..7a9d581 100644
40897--- a/drivers/video/aty/aty128fb.c
40898+++ b/drivers/video/aty/aty128fb.c
40899@@ -149,7 +149,7 @@ enum {
40900 };
40901
40902 /* Must match above enum */
40903-static char * const r128_family[] __devinitconst = {
40904+static const char * const r128_family[] __devinitconst = {
40905 "AGP",
40906 "PCI",
40907 "PRO AGP",
40908diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
40909index 5c3960d..15cf8fc 100644
40910--- a/drivers/video/fbcmap.c
40911+++ b/drivers/video/fbcmap.c
40912@@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
40913 rc = -ENODEV;
40914 goto out;
40915 }
40916- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
40917- !info->fbops->fb_setcmap)) {
40918+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
40919 rc = -EINVAL;
40920 goto out1;
40921 }
40922diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
40923index 3ff0105..7589d98 100644
40924--- a/drivers/video/fbmem.c
40925+++ b/drivers/video/fbmem.c
40926@@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
40927 image->dx += image->width + 8;
40928 }
40929 } else if (rotate == FB_ROTATE_UD) {
40930- for (x = 0; x < num && image->dx >= 0; x++) {
40931+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
40932 info->fbops->fb_imageblit(info, image);
40933 image->dx -= image->width + 8;
40934 }
40935@@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
40936 image->dy += image->height + 8;
40937 }
40938 } else if (rotate == FB_ROTATE_CCW) {
40939- for (x = 0; x < num && image->dy >= 0; x++) {
40940+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
40941 info->fbops->fb_imageblit(info, image);
40942 image->dy -= image->height + 8;
40943 }
40944@@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
40945 return -EFAULT;
40946 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
40947 return -EINVAL;
40948- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
40949+ if (con2fb.framebuffer >= FB_MAX)
40950 return -EINVAL;
40951 if (!registered_fb[con2fb.framebuffer])
40952 request_module("fb%d", con2fb.framebuffer);
40953diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
40954index 7672d2e..b56437f 100644
40955--- a/drivers/video/i810/i810_accel.c
40956+++ b/drivers/video/i810/i810_accel.c
40957@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
40958 }
40959 }
40960 printk("ringbuffer lockup!!!\n");
40961+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
40962 i810_report_error(mmio);
40963 par->dev_flags |= LOCKUP;
40964 info->pixmap.scan_align = 1;
40965diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
40966index 3c14e43..eafa544 100644
40967--- a/drivers/video/logo/logo_linux_clut224.ppm
40968+++ b/drivers/video/logo/logo_linux_clut224.ppm
40969@@ -1,1604 +1,1123 @@
40970 P3
40971-# Standard 224-color Linux logo
40972 80 80
40973 255
40974- 0 0 0 0 0 0 0 0 0 0 0 0
40975- 0 0 0 0 0 0 0 0 0 0 0 0
40976- 0 0 0 0 0 0 0 0 0 0 0 0
40977- 0 0 0 0 0 0 0 0 0 0 0 0
40978- 0 0 0 0 0 0 0 0 0 0 0 0
40979- 0 0 0 0 0 0 0 0 0 0 0 0
40980- 0 0 0 0 0 0 0 0 0 0 0 0
40981- 0 0 0 0 0 0 0 0 0 0 0 0
40982- 0 0 0 0 0 0 0 0 0 0 0 0
40983- 6 6 6 6 6 6 10 10 10 10 10 10
40984- 10 10 10 6 6 6 6 6 6 6 6 6
40985- 0 0 0 0 0 0 0 0 0 0 0 0
40986- 0 0 0 0 0 0 0 0 0 0 0 0
40987- 0 0 0 0 0 0 0 0 0 0 0 0
40988- 0 0 0 0 0 0 0 0 0 0 0 0
40989- 0 0 0 0 0 0 0 0 0 0 0 0
40990- 0 0 0 0 0 0 0 0 0 0 0 0
40991- 0 0 0 0 0 0 0 0 0 0 0 0
40992- 0 0 0 0 0 0 0 0 0 0 0 0
40993- 0 0 0 0 0 0 0 0 0 0 0 0
40994- 0 0 0 0 0 0 0 0 0 0 0 0
40995- 0 0 0 0 0 0 0 0 0 0 0 0
40996- 0 0 0 0 0 0 0 0 0 0 0 0
40997- 0 0 0 0 0 0 0 0 0 0 0 0
40998- 0 0 0 0 0 0 0 0 0 0 0 0
40999- 0 0 0 0 0 0 0 0 0 0 0 0
41000- 0 0 0 0 0 0 0 0 0 0 0 0
41001- 0 0 0 0 0 0 0 0 0 0 0 0
41002- 0 0 0 6 6 6 10 10 10 14 14 14
41003- 22 22 22 26 26 26 30 30 30 34 34 34
41004- 30 30 30 30 30 30 26 26 26 18 18 18
41005- 14 14 14 10 10 10 6 6 6 0 0 0
41006- 0 0 0 0 0 0 0 0 0 0 0 0
41007- 0 0 0 0 0 0 0 0 0 0 0 0
41008- 0 0 0 0 0 0 0 0 0 0 0 0
41009- 0 0 0 0 0 0 0 0 0 0 0 0
41010- 0 0 0 0 0 0 0 0 0 0 0 0
41011- 0 0 0 0 0 0 0 0 0 0 0 0
41012- 0 0 0 0 0 0 0 0 0 0 0 0
41013- 0 0 0 0 0 0 0 0 0 0 0 0
41014- 0 0 0 0 0 0 0 0 0 0 0 0
41015- 0 0 0 0 0 1 0 0 1 0 0 0
41016- 0 0 0 0 0 0 0 0 0 0 0 0
41017- 0 0 0 0 0 0 0 0 0 0 0 0
41018- 0 0 0 0 0 0 0 0 0 0 0 0
41019- 0 0 0 0 0 0 0 0 0 0 0 0
41020- 0 0 0 0 0 0 0 0 0 0 0 0
41021- 0 0 0 0 0 0 0 0 0 0 0 0
41022- 6 6 6 14 14 14 26 26 26 42 42 42
41023- 54 54 54 66 66 66 78 78 78 78 78 78
41024- 78 78 78 74 74 74 66 66 66 54 54 54
41025- 42 42 42 26 26 26 18 18 18 10 10 10
41026- 6 6 6 0 0 0 0 0 0 0 0 0
41027- 0 0 0 0 0 0 0 0 0 0 0 0
41028- 0 0 0 0 0 0 0 0 0 0 0 0
41029- 0 0 0 0 0 0 0 0 0 0 0 0
41030- 0 0 0 0 0 0 0 0 0 0 0 0
41031- 0 0 0 0 0 0 0 0 0 0 0 0
41032- 0 0 0 0 0 0 0 0 0 0 0 0
41033- 0 0 0 0 0 0 0 0 0 0 0 0
41034- 0 0 0 0 0 0 0 0 0 0 0 0
41035- 0 0 1 0 0 0 0 0 0 0 0 0
41036- 0 0 0 0 0 0 0 0 0 0 0 0
41037- 0 0 0 0 0 0 0 0 0 0 0 0
41038- 0 0 0 0 0 0 0 0 0 0 0 0
41039- 0 0 0 0 0 0 0 0 0 0 0 0
41040- 0 0 0 0 0 0 0 0 0 0 0 0
41041- 0 0 0 0 0 0 0 0 0 10 10 10
41042- 22 22 22 42 42 42 66 66 66 86 86 86
41043- 66 66 66 38 38 38 38 38 38 22 22 22
41044- 26 26 26 34 34 34 54 54 54 66 66 66
41045- 86 86 86 70 70 70 46 46 46 26 26 26
41046- 14 14 14 6 6 6 0 0 0 0 0 0
41047- 0 0 0 0 0 0 0 0 0 0 0 0
41048- 0 0 0 0 0 0 0 0 0 0 0 0
41049- 0 0 0 0 0 0 0 0 0 0 0 0
41050- 0 0 0 0 0 0 0 0 0 0 0 0
41051- 0 0 0 0 0 0 0 0 0 0 0 0
41052- 0 0 0 0 0 0 0 0 0 0 0 0
41053- 0 0 0 0 0 0 0 0 0 0 0 0
41054- 0 0 0 0 0 0 0 0 0 0 0 0
41055- 0 0 1 0 0 1 0 0 1 0 0 0
41056- 0 0 0 0 0 0 0 0 0 0 0 0
41057- 0 0 0 0 0 0 0 0 0 0 0 0
41058- 0 0 0 0 0 0 0 0 0 0 0 0
41059- 0 0 0 0 0 0 0 0 0 0 0 0
41060- 0 0 0 0 0 0 0 0 0 0 0 0
41061- 0 0 0 0 0 0 10 10 10 26 26 26
41062- 50 50 50 82 82 82 58 58 58 6 6 6
41063- 2 2 6 2 2 6 2 2 6 2 2 6
41064- 2 2 6 2 2 6 2 2 6 2 2 6
41065- 6 6 6 54 54 54 86 86 86 66 66 66
41066- 38 38 38 18 18 18 6 6 6 0 0 0
41067- 0 0 0 0 0 0 0 0 0 0 0 0
41068- 0 0 0 0 0 0 0 0 0 0 0 0
41069- 0 0 0 0 0 0 0 0 0 0 0 0
41070- 0 0 0 0 0 0 0 0 0 0 0 0
41071- 0 0 0 0 0 0 0 0 0 0 0 0
41072- 0 0 0 0 0 0 0 0 0 0 0 0
41073- 0 0 0 0 0 0 0 0 0 0 0 0
41074- 0 0 0 0 0 0 0 0 0 0 0 0
41075- 0 0 0 0 0 0 0 0 0 0 0 0
41076- 0 0 0 0 0 0 0 0 0 0 0 0
41077- 0 0 0 0 0 0 0 0 0 0 0 0
41078- 0 0 0 0 0 0 0 0 0 0 0 0
41079- 0 0 0 0 0 0 0 0 0 0 0 0
41080- 0 0 0 0 0 0 0 0 0 0 0 0
41081- 0 0 0 6 6 6 22 22 22 50 50 50
41082- 78 78 78 34 34 34 2 2 6 2 2 6
41083- 2 2 6 2 2 6 2 2 6 2 2 6
41084- 2 2 6 2 2 6 2 2 6 2 2 6
41085- 2 2 6 2 2 6 6 6 6 70 70 70
41086- 78 78 78 46 46 46 22 22 22 6 6 6
41087- 0 0 0 0 0 0 0 0 0 0 0 0
41088- 0 0 0 0 0 0 0 0 0 0 0 0
41089- 0 0 0 0 0 0 0 0 0 0 0 0
41090- 0 0 0 0 0 0 0 0 0 0 0 0
41091- 0 0 0 0 0 0 0 0 0 0 0 0
41092- 0 0 0 0 0 0 0 0 0 0 0 0
41093- 0 0 0 0 0 0 0 0 0 0 0 0
41094- 0 0 0 0 0 0 0 0 0 0 0 0
41095- 0 0 1 0 0 1 0 0 1 0 0 0
41096- 0 0 0 0 0 0 0 0 0 0 0 0
41097- 0 0 0 0 0 0 0 0 0 0 0 0
41098- 0 0 0 0 0 0 0 0 0 0 0 0
41099- 0 0 0 0 0 0 0 0 0 0 0 0
41100- 0 0 0 0 0 0 0 0 0 0 0 0
41101- 6 6 6 18 18 18 42 42 42 82 82 82
41102- 26 26 26 2 2 6 2 2 6 2 2 6
41103- 2 2 6 2 2 6 2 2 6 2 2 6
41104- 2 2 6 2 2 6 2 2 6 14 14 14
41105- 46 46 46 34 34 34 6 6 6 2 2 6
41106- 42 42 42 78 78 78 42 42 42 18 18 18
41107- 6 6 6 0 0 0 0 0 0 0 0 0
41108- 0 0 0 0 0 0 0 0 0 0 0 0
41109- 0 0 0 0 0 0 0 0 0 0 0 0
41110- 0 0 0 0 0 0 0 0 0 0 0 0
41111- 0 0 0 0 0 0 0 0 0 0 0 0
41112- 0 0 0 0 0 0 0 0 0 0 0 0
41113- 0 0 0 0 0 0 0 0 0 0 0 0
41114- 0 0 0 0 0 0 0 0 0 0 0 0
41115- 0 0 1 0 0 0 0 0 1 0 0 0
41116- 0 0 0 0 0 0 0 0 0 0 0 0
41117- 0 0 0 0 0 0 0 0 0 0 0 0
41118- 0 0 0 0 0 0 0 0 0 0 0 0
41119- 0 0 0 0 0 0 0 0 0 0 0 0
41120- 0 0 0 0 0 0 0 0 0 0 0 0
41121- 10 10 10 30 30 30 66 66 66 58 58 58
41122- 2 2 6 2 2 6 2 2 6 2 2 6
41123- 2 2 6 2 2 6 2 2 6 2 2 6
41124- 2 2 6 2 2 6 2 2 6 26 26 26
41125- 86 86 86 101 101 101 46 46 46 10 10 10
41126- 2 2 6 58 58 58 70 70 70 34 34 34
41127- 10 10 10 0 0 0 0 0 0 0 0 0
41128- 0 0 0 0 0 0 0 0 0 0 0 0
41129- 0 0 0 0 0 0 0 0 0 0 0 0
41130- 0 0 0 0 0 0 0 0 0 0 0 0
41131- 0 0 0 0 0 0 0 0 0 0 0 0
41132- 0 0 0 0 0 0 0 0 0 0 0 0
41133- 0 0 0 0 0 0 0 0 0 0 0 0
41134- 0 0 0 0 0 0 0 0 0 0 0 0
41135- 0 0 1 0 0 1 0 0 1 0 0 0
41136- 0 0 0 0 0 0 0 0 0 0 0 0
41137- 0 0 0 0 0 0 0 0 0 0 0 0
41138- 0 0 0 0 0 0 0 0 0 0 0 0
41139- 0 0 0 0 0 0 0 0 0 0 0 0
41140- 0 0 0 0 0 0 0 0 0 0 0 0
41141- 14 14 14 42 42 42 86 86 86 10 10 10
41142- 2 2 6 2 2 6 2 2 6 2 2 6
41143- 2 2 6 2 2 6 2 2 6 2 2 6
41144- 2 2 6 2 2 6 2 2 6 30 30 30
41145- 94 94 94 94 94 94 58 58 58 26 26 26
41146- 2 2 6 6 6 6 78 78 78 54 54 54
41147- 22 22 22 6 6 6 0 0 0 0 0 0
41148- 0 0 0 0 0 0 0 0 0 0 0 0
41149- 0 0 0 0 0 0 0 0 0 0 0 0
41150- 0 0 0 0 0 0 0 0 0 0 0 0
41151- 0 0 0 0 0 0 0 0 0 0 0 0
41152- 0 0 0 0 0 0 0 0 0 0 0 0
41153- 0 0 0 0 0 0 0 0 0 0 0 0
41154- 0 0 0 0 0 0 0 0 0 0 0 0
41155- 0 0 0 0 0 0 0 0 0 0 0 0
41156- 0 0 0 0 0 0 0 0 0 0 0 0
41157- 0 0 0 0 0 0 0 0 0 0 0 0
41158- 0 0 0 0 0 0 0 0 0 0 0 0
41159- 0 0 0 0 0 0 0 0 0 0 0 0
41160- 0 0 0 0 0 0 0 0 0 6 6 6
41161- 22 22 22 62 62 62 62 62 62 2 2 6
41162- 2 2 6 2 2 6 2 2 6 2 2 6
41163- 2 2 6 2 2 6 2 2 6 2 2 6
41164- 2 2 6 2 2 6 2 2 6 26 26 26
41165- 54 54 54 38 38 38 18 18 18 10 10 10
41166- 2 2 6 2 2 6 34 34 34 82 82 82
41167- 38 38 38 14 14 14 0 0 0 0 0 0
41168- 0 0 0 0 0 0 0 0 0 0 0 0
41169- 0 0 0 0 0 0 0 0 0 0 0 0
41170- 0 0 0 0 0 0 0 0 0 0 0 0
41171- 0 0 0 0 0 0 0 0 0 0 0 0
41172- 0 0 0 0 0 0 0 0 0 0 0 0
41173- 0 0 0 0 0 0 0 0 0 0 0 0
41174- 0 0 0 0 0 0 0 0 0 0 0 0
41175- 0 0 0 0 0 1 0 0 1 0 0 0
41176- 0 0 0 0 0 0 0 0 0 0 0 0
41177- 0 0 0 0 0 0 0 0 0 0 0 0
41178- 0 0 0 0 0 0 0 0 0 0 0 0
41179- 0 0 0 0 0 0 0 0 0 0 0 0
41180- 0 0 0 0 0 0 0 0 0 6 6 6
41181- 30 30 30 78 78 78 30 30 30 2 2 6
41182- 2 2 6 2 2 6 2 2 6 2 2 6
41183- 2 2 6 2 2 6 2 2 6 2 2 6
41184- 2 2 6 2 2 6 2 2 6 10 10 10
41185- 10 10 10 2 2 6 2 2 6 2 2 6
41186- 2 2 6 2 2 6 2 2 6 78 78 78
41187- 50 50 50 18 18 18 6 6 6 0 0 0
41188- 0 0 0 0 0 0 0 0 0 0 0 0
41189- 0 0 0 0 0 0 0 0 0 0 0 0
41190- 0 0 0 0 0 0 0 0 0 0 0 0
41191- 0 0 0 0 0 0 0 0 0 0 0 0
41192- 0 0 0 0 0 0 0 0 0 0 0 0
41193- 0 0 0 0 0 0 0 0 0 0 0 0
41194- 0 0 0 0 0 0 0 0 0 0 0 0
41195- 0 0 1 0 0 0 0 0 0 0 0 0
41196- 0 0 0 0 0 0 0 0 0 0 0 0
41197- 0 0 0 0 0 0 0 0 0 0 0 0
41198- 0 0 0 0 0 0 0 0 0 0 0 0
41199- 0 0 0 0 0 0 0 0 0 0 0 0
41200- 0 0 0 0 0 0 0 0 0 10 10 10
41201- 38 38 38 86 86 86 14 14 14 2 2 6
41202- 2 2 6 2 2 6 2 2 6 2 2 6
41203- 2 2 6 2 2 6 2 2 6 2 2 6
41204- 2 2 6 2 2 6 2 2 6 2 2 6
41205- 2 2 6 2 2 6 2 2 6 2 2 6
41206- 2 2 6 2 2 6 2 2 6 54 54 54
41207- 66 66 66 26 26 26 6 6 6 0 0 0
41208- 0 0 0 0 0 0 0 0 0 0 0 0
41209- 0 0 0 0 0 0 0 0 0 0 0 0
41210- 0 0 0 0 0 0 0 0 0 0 0 0
41211- 0 0 0 0 0 0 0 0 0 0 0 0
41212- 0 0 0 0 0 0 0 0 0 0 0 0
41213- 0 0 0 0 0 0 0 0 0 0 0 0
41214- 0 0 0 0 0 0 0 0 0 0 0 0
41215- 0 0 0 0 0 1 0 0 1 0 0 0
41216- 0 0 0 0 0 0 0 0 0 0 0 0
41217- 0 0 0 0 0 0 0 0 0 0 0 0
41218- 0 0 0 0 0 0 0 0 0 0 0 0
41219- 0 0 0 0 0 0 0 0 0 0 0 0
41220- 0 0 0 0 0 0 0 0 0 14 14 14
41221- 42 42 42 82 82 82 2 2 6 2 2 6
41222- 2 2 6 6 6 6 10 10 10 2 2 6
41223- 2 2 6 2 2 6 2 2 6 2 2 6
41224- 2 2 6 2 2 6 2 2 6 6 6 6
41225- 14 14 14 10 10 10 2 2 6 2 2 6
41226- 2 2 6 2 2 6 2 2 6 18 18 18
41227- 82 82 82 34 34 34 10 10 10 0 0 0
41228- 0 0 0 0 0 0 0 0 0 0 0 0
41229- 0 0 0 0 0 0 0 0 0 0 0 0
41230- 0 0 0 0 0 0 0 0 0 0 0 0
41231- 0 0 0 0 0 0 0 0 0 0 0 0
41232- 0 0 0 0 0 0 0 0 0 0 0 0
41233- 0 0 0 0 0 0 0 0 0 0 0 0
41234- 0 0 0 0 0 0 0 0 0 0 0 0
41235- 0 0 1 0 0 0 0 0 0 0 0 0
41236- 0 0 0 0 0 0 0 0 0 0 0 0
41237- 0 0 0 0 0 0 0 0 0 0 0 0
41238- 0 0 0 0 0 0 0 0 0 0 0 0
41239- 0 0 0 0 0 0 0 0 0 0 0 0
41240- 0 0 0 0 0 0 0 0 0 14 14 14
41241- 46 46 46 86 86 86 2 2 6 2 2 6
41242- 6 6 6 6 6 6 22 22 22 34 34 34
41243- 6 6 6 2 2 6 2 2 6 2 2 6
41244- 2 2 6 2 2 6 18 18 18 34 34 34
41245- 10 10 10 50 50 50 22 22 22 2 2 6
41246- 2 2 6 2 2 6 2 2 6 10 10 10
41247- 86 86 86 42 42 42 14 14 14 0 0 0
41248- 0 0 0 0 0 0 0 0 0 0 0 0
41249- 0 0 0 0 0 0 0 0 0 0 0 0
41250- 0 0 0 0 0 0 0 0 0 0 0 0
41251- 0 0 0 0 0 0 0 0 0 0 0 0
41252- 0 0 0 0 0 0 0 0 0 0 0 0
41253- 0 0 0 0 0 0 0 0 0 0 0 0
41254- 0 0 0 0 0 0 0 0 0 0 0 0
41255- 0 0 1 0 0 1 0 0 1 0 0 0
41256- 0 0 0 0 0 0 0 0 0 0 0 0
41257- 0 0 0 0 0 0 0 0 0 0 0 0
41258- 0 0 0 0 0 0 0 0 0 0 0 0
41259- 0 0 0 0 0 0 0 0 0 0 0 0
41260- 0 0 0 0 0 0 0 0 0 14 14 14
41261- 46 46 46 86 86 86 2 2 6 2 2 6
41262- 38 38 38 116 116 116 94 94 94 22 22 22
41263- 22 22 22 2 2 6 2 2 6 2 2 6
41264- 14 14 14 86 86 86 138 138 138 162 162 162
41265-154 154 154 38 38 38 26 26 26 6 6 6
41266- 2 2 6 2 2 6 2 2 6 2 2 6
41267- 86 86 86 46 46 46 14 14 14 0 0 0
41268- 0 0 0 0 0 0 0 0 0 0 0 0
41269- 0 0 0 0 0 0 0 0 0 0 0 0
41270- 0 0 0 0 0 0 0 0 0 0 0 0
41271- 0 0 0 0 0 0 0 0 0 0 0 0
41272- 0 0 0 0 0 0 0 0 0 0 0 0
41273- 0 0 0 0 0 0 0 0 0 0 0 0
41274- 0 0 0 0 0 0 0 0 0 0 0 0
41275- 0 0 0 0 0 0 0 0 0 0 0 0
41276- 0 0 0 0 0 0 0 0 0 0 0 0
41277- 0 0 0 0 0 0 0 0 0 0 0 0
41278- 0 0 0 0 0 0 0 0 0 0 0 0
41279- 0 0 0 0 0 0 0 0 0 0 0 0
41280- 0 0 0 0 0 0 0 0 0 14 14 14
41281- 46 46 46 86 86 86 2 2 6 14 14 14
41282-134 134 134 198 198 198 195 195 195 116 116 116
41283- 10 10 10 2 2 6 2 2 6 6 6 6
41284-101 98 89 187 187 187 210 210 210 218 218 218
41285-214 214 214 134 134 134 14 14 14 6 6 6
41286- 2 2 6 2 2 6 2 2 6 2 2 6
41287- 86 86 86 50 50 50 18 18 18 6 6 6
41288- 0 0 0 0 0 0 0 0 0 0 0 0
41289- 0 0 0 0 0 0 0 0 0 0 0 0
41290- 0 0 0 0 0 0 0 0 0 0 0 0
41291- 0 0 0 0 0 0 0 0 0 0 0 0
41292- 0 0 0 0 0 0 0 0 0 0 0 0
41293- 0 0 0 0 0 0 0 0 0 0 0 0
41294- 0 0 0 0 0 0 0 0 1 0 0 0
41295- 0 0 1 0 0 1 0 0 1 0 0 0
41296- 0 0 0 0 0 0 0 0 0 0 0 0
41297- 0 0 0 0 0 0 0 0 0 0 0 0
41298- 0 0 0 0 0 0 0 0 0 0 0 0
41299- 0 0 0 0 0 0 0 0 0 0 0 0
41300- 0 0 0 0 0 0 0 0 0 14 14 14
41301- 46 46 46 86 86 86 2 2 6 54 54 54
41302-218 218 218 195 195 195 226 226 226 246 246 246
41303- 58 58 58 2 2 6 2 2 6 30 30 30
41304-210 210 210 253 253 253 174 174 174 123 123 123
41305-221 221 221 234 234 234 74 74 74 2 2 6
41306- 2 2 6 2 2 6 2 2 6 2 2 6
41307- 70 70 70 58 58 58 22 22 22 6 6 6
41308- 0 0 0 0 0 0 0 0 0 0 0 0
41309- 0 0 0 0 0 0 0 0 0 0 0 0
41310- 0 0 0 0 0 0 0 0 0 0 0 0
41311- 0 0 0 0 0 0 0 0 0 0 0 0
41312- 0 0 0 0 0 0 0 0 0 0 0 0
41313- 0 0 0 0 0 0 0 0 0 0 0 0
41314- 0 0 0 0 0 0 0 0 0 0 0 0
41315- 0 0 0 0 0 0 0 0 0 0 0 0
41316- 0 0 0 0 0 0 0 0 0 0 0 0
41317- 0 0 0 0 0 0 0 0 0 0 0 0
41318- 0 0 0 0 0 0 0 0 0 0 0 0
41319- 0 0 0 0 0 0 0 0 0 0 0 0
41320- 0 0 0 0 0 0 0 0 0 14 14 14
41321- 46 46 46 82 82 82 2 2 6 106 106 106
41322-170 170 170 26 26 26 86 86 86 226 226 226
41323-123 123 123 10 10 10 14 14 14 46 46 46
41324-231 231 231 190 190 190 6 6 6 70 70 70
41325- 90 90 90 238 238 238 158 158 158 2 2 6
41326- 2 2 6 2 2 6 2 2 6 2 2 6
41327- 70 70 70 58 58 58 22 22 22 6 6 6
41328- 0 0 0 0 0 0 0 0 0 0 0 0
41329- 0 0 0 0 0 0 0 0 0 0 0 0
41330- 0 0 0 0 0 0 0 0 0 0 0 0
41331- 0 0 0 0 0 0 0 0 0 0 0 0
41332- 0 0 0 0 0 0 0 0 0 0 0 0
41333- 0 0 0 0 0 0 0 0 0 0 0 0
41334- 0 0 0 0 0 0 0 0 1 0 0 0
41335- 0 0 1 0 0 1 0 0 1 0 0 0
41336- 0 0 0 0 0 0 0 0 0 0 0 0
41337- 0 0 0 0 0 0 0 0 0 0 0 0
41338- 0 0 0 0 0 0 0 0 0 0 0 0
41339- 0 0 0 0 0 0 0 0 0 0 0 0
41340- 0 0 0 0 0 0 0 0 0 14 14 14
41341- 42 42 42 86 86 86 6 6 6 116 116 116
41342-106 106 106 6 6 6 70 70 70 149 149 149
41343-128 128 128 18 18 18 38 38 38 54 54 54
41344-221 221 221 106 106 106 2 2 6 14 14 14
41345- 46 46 46 190 190 190 198 198 198 2 2 6
41346- 2 2 6 2 2 6 2 2 6 2 2 6
41347- 74 74 74 62 62 62 22 22 22 6 6 6
41348- 0 0 0 0 0 0 0 0 0 0 0 0
41349- 0 0 0 0 0 0 0 0 0 0 0 0
41350- 0 0 0 0 0 0 0 0 0 0 0 0
41351- 0 0 0 0 0 0 0 0 0 0 0 0
41352- 0 0 0 0 0 0 0 0 0 0 0 0
41353- 0 0 0 0 0 0 0 0 0 0 0 0
41354- 0 0 0 0 0 0 0 0 1 0 0 0
41355- 0 0 1 0 0 0 0 0 1 0 0 0
41356- 0 0 0 0 0 0 0 0 0 0 0 0
41357- 0 0 0 0 0 0 0 0 0 0 0 0
41358- 0 0 0 0 0 0 0 0 0 0 0 0
41359- 0 0 0 0 0 0 0 0 0 0 0 0
41360- 0 0 0 0 0 0 0 0 0 14 14 14
41361- 42 42 42 94 94 94 14 14 14 101 101 101
41362-128 128 128 2 2 6 18 18 18 116 116 116
41363-118 98 46 121 92 8 121 92 8 98 78 10
41364-162 162 162 106 106 106 2 2 6 2 2 6
41365- 2 2 6 195 195 195 195 195 195 6 6 6
41366- 2 2 6 2 2 6 2 2 6 2 2 6
41367- 74 74 74 62 62 62 22 22 22 6 6 6
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 1 0 0 1
41375- 0 0 1 0 0 0 0 0 1 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 10 10 10
41381- 38 38 38 90 90 90 14 14 14 58 58 58
41382-210 210 210 26 26 26 54 38 6 154 114 10
41383-226 170 11 236 186 11 225 175 15 184 144 12
41384-215 174 15 175 146 61 37 26 9 2 2 6
41385- 70 70 70 246 246 246 138 138 138 2 2 6
41386- 2 2 6 2 2 6 2 2 6 2 2 6
41387- 70 70 70 66 66 66 26 26 26 6 6 6
41388- 0 0 0 0 0 0 0 0 0 0 0 0
41389- 0 0 0 0 0 0 0 0 0 0 0 0
41390- 0 0 0 0 0 0 0 0 0 0 0 0
41391- 0 0 0 0 0 0 0 0 0 0 0 0
41392- 0 0 0 0 0 0 0 0 0 0 0 0
41393- 0 0 0 0 0 0 0 0 0 0 0 0
41394- 0 0 0 0 0 0 0 0 0 0 0 0
41395- 0 0 0 0 0 0 0 0 0 0 0 0
41396- 0 0 0 0 0 0 0 0 0 0 0 0
41397- 0 0 0 0 0 0 0 0 0 0 0 0
41398- 0 0 0 0 0 0 0 0 0 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 10 10 10
41401- 38 38 38 86 86 86 14 14 14 10 10 10
41402-195 195 195 188 164 115 192 133 9 225 175 15
41403-239 182 13 234 190 10 232 195 16 232 200 30
41404-245 207 45 241 208 19 232 195 16 184 144 12
41405-218 194 134 211 206 186 42 42 42 2 2 6
41406- 2 2 6 2 2 6 2 2 6 2 2 6
41407- 50 50 50 74 74 74 30 30 30 6 6 6
41408- 0 0 0 0 0 0 0 0 0 0 0 0
41409- 0 0 0 0 0 0 0 0 0 0 0 0
41410- 0 0 0 0 0 0 0 0 0 0 0 0
41411- 0 0 0 0 0 0 0 0 0 0 0 0
41412- 0 0 0 0 0 0 0 0 0 0 0 0
41413- 0 0 0 0 0 0 0 0 0 0 0 0
41414- 0 0 0 0 0 0 0 0 0 0 0 0
41415- 0 0 0 0 0 0 0 0 0 0 0 0
41416- 0 0 0 0 0 0 0 0 0 0 0 0
41417- 0 0 0 0 0 0 0 0 0 0 0 0
41418- 0 0 0 0 0 0 0 0 0 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 10 10 10
41421- 34 34 34 86 86 86 14 14 14 2 2 6
41422-121 87 25 192 133 9 219 162 10 239 182 13
41423-236 186 11 232 195 16 241 208 19 244 214 54
41424-246 218 60 246 218 38 246 215 20 241 208 19
41425-241 208 19 226 184 13 121 87 25 2 2 6
41426- 2 2 6 2 2 6 2 2 6 2 2 6
41427- 50 50 50 82 82 82 34 34 34 10 10 10
41428- 0 0 0 0 0 0 0 0 0 0 0 0
41429- 0 0 0 0 0 0 0 0 0 0 0 0
41430- 0 0 0 0 0 0 0 0 0 0 0 0
41431- 0 0 0 0 0 0 0 0 0 0 0 0
41432- 0 0 0 0 0 0 0 0 0 0 0 0
41433- 0 0 0 0 0 0 0 0 0 0 0 0
41434- 0 0 0 0 0 0 0 0 0 0 0 0
41435- 0 0 0 0 0 0 0 0 0 0 0 0
41436- 0 0 0 0 0 0 0 0 0 0 0 0
41437- 0 0 0 0 0 0 0 0 0 0 0 0
41438- 0 0 0 0 0 0 0 0 0 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 10 10 10
41441- 34 34 34 82 82 82 30 30 30 61 42 6
41442-180 123 7 206 145 10 230 174 11 239 182 13
41443-234 190 10 238 202 15 241 208 19 246 218 74
41444-246 218 38 246 215 20 246 215 20 246 215 20
41445-226 184 13 215 174 15 184 144 12 6 6 6
41446- 2 2 6 2 2 6 2 2 6 2 2 6
41447- 26 26 26 94 94 94 42 42 42 14 14 14
41448- 0 0 0 0 0 0 0 0 0 0 0 0
41449- 0 0 0 0 0 0 0 0 0 0 0 0
41450- 0 0 0 0 0 0 0 0 0 0 0 0
41451- 0 0 0 0 0 0 0 0 0 0 0 0
41452- 0 0 0 0 0 0 0 0 0 0 0 0
41453- 0 0 0 0 0 0 0 0 0 0 0 0
41454- 0 0 0 0 0 0 0 0 0 0 0 0
41455- 0 0 0 0 0 0 0 0 0 0 0 0
41456- 0 0 0 0 0 0 0 0 0 0 0 0
41457- 0 0 0 0 0 0 0 0 0 0 0 0
41458- 0 0 0 0 0 0 0 0 0 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 10 10 10
41461- 30 30 30 78 78 78 50 50 50 104 69 6
41462-192 133 9 216 158 10 236 178 12 236 186 11
41463-232 195 16 241 208 19 244 214 54 245 215 43
41464-246 215 20 246 215 20 241 208 19 198 155 10
41465-200 144 11 216 158 10 156 118 10 2 2 6
41466- 2 2 6 2 2 6 2 2 6 2 2 6
41467- 6 6 6 90 90 90 54 54 54 18 18 18
41468- 6 6 6 0 0 0 0 0 0 0 0 0
41469- 0 0 0 0 0 0 0 0 0 0 0 0
41470- 0 0 0 0 0 0 0 0 0 0 0 0
41471- 0 0 0 0 0 0 0 0 0 0 0 0
41472- 0 0 0 0 0 0 0 0 0 0 0 0
41473- 0 0 0 0 0 0 0 0 0 0 0 0
41474- 0 0 0 0 0 0 0 0 0 0 0 0
41475- 0 0 0 0 0 0 0 0 0 0 0 0
41476- 0 0 0 0 0 0 0 0 0 0 0 0
41477- 0 0 0 0 0 0 0 0 0 0 0 0
41478- 0 0 0 0 0 0 0 0 0 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 10 10 10
41481- 30 30 30 78 78 78 46 46 46 22 22 22
41482-137 92 6 210 162 10 239 182 13 238 190 10
41483-238 202 15 241 208 19 246 215 20 246 215 20
41484-241 208 19 203 166 17 185 133 11 210 150 10
41485-216 158 10 210 150 10 102 78 10 2 2 6
41486- 6 6 6 54 54 54 14 14 14 2 2 6
41487- 2 2 6 62 62 62 74 74 74 30 30 30
41488- 10 10 10 0 0 0 0 0 0 0 0 0
41489- 0 0 0 0 0 0 0 0 0 0 0 0
41490- 0 0 0 0 0 0 0 0 0 0 0 0
41491- 0 0 0 0 0 0 0 0 0 0 0 0
41492- 0 0 0 0 0 0 0 0 0 0 0 0
41493- 0 0 0 0 0 0 0 0 0 0 0 0
41494- 0 0 0 0 0 0 0 0 0 0 0 0
41495- 0 0 0 0 0 0 0 0 0 0 0 0
41496- 0 0 0 0 0 0 0 0 0 0 0 0
41497- 0 0 0 0 0 0 0 0 0 0 0 0
41498- 0 0 0 0 0 0 0 0 0 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 10 10 10
41501- 34 34 34 78 78 78 50 50 50 6 6 6
41502- 94 70 30 139 102 15 190 146 13 226 184 13
41503-232 200 30 232 195 16 215 174 15 190 146 13
41504-168 122 10 192 133 9 210 150 10 213 154 11
41505-202 150 34 182 157 106 101 98 89 2 2 6
41506- 2 2 6 78 78 78 116 116 116 58 58 58
41507- 2 2 6 22 22 22 90 90 90 46 46 46
41508- 18 18 18 6 6 6 0 0 0 0 0 0
41509- 0 0 0 0 0 0 0 0 0 0 0 0
41510- 0 0 0 0 0 0 0 0 0 0 0 0
41511- 0 0 0 0 0 0 0 0 0 0 0 0
41512- 0 0 0 0 0 0 0 0 0 0 0 0
41513- 0 0 0 0 0 0 0 0 0 0 0 0
41514- 0 0 0 0 0 0 0 0 0 0 0 0
41515- 0 0 0 0 0 0 0 0 0 0 0 0
41516- 0 0 0 0 0 0 0 0 0 0 0 0
41517- 0 0 0 0 0 0 0 0 0 0 0 0
41518- 0 0 0 0 0 0 0 0 0 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 10 10 10
41521- 38 38 38 86 86 86 50 50 50 6 6 6
41522-128 128 128 174 154 114 156 107 11 168 122 10
41523-198 155 10 184 144 12 197 138 11 200 144 11
41524-206 145 10 206 145 10 197 138 11 188 164 115
41525-195 195 195 198 198 198 174 174 174 14 14 14
41526- 2 2 6 22 22 22 116 116 116 116 116 116
41527- 22 22 22 2 2 6 74 74 74 70 70 70
41528- 30 30 30 10 10 10 0 0 0 0 0 0
41529- 0 0 0 0 0 0 0 0 0 0 0 0
41530- 0 0 0 0 0 0 0 0 0 0 0 0
41531- 0 0 0 0 0 0 0 0 0 0 0 0
41532- 0 0 0 0 0 0 0 0 0 0 0 0
41533- 0 0 0 0 0 0 0 0 0 0 0 0
41534- 0 0 0 0 0 0 0 0 0 0 0 0
41535- 0 0 0 0 0 0 0 0 0 0 0 0
41536- 0 0 0 0 0 0 0 0 0 0 0 0
41537- 0 0 0 0 0 0 0 0 0 0 0 0
41538- 0 0 0 0 0 0 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 6 6 6 18 18 18
41541- 50 50 50 101 101 101 26 26 26 10 10 10
41542-138 138 138 190 190 190 174 154 114 156 107 11
41543-197 138 11 200 144 11 197 138 11 192 133 9
41544-180 123 7 190 142 34 190 178 144 187 187 187
41545-202 202 202 221 221 221 214 214 214 66 66 66
41546- 2 2 6 2 2 6 50 50 50 62 62 62
41547- 6 6 6 2 2 6 10 10 10 90 90 90
41548- 50 50 50 18 18 18 6 6 6 0 0 0
41549- 0 0 0 0 0 0 0 0 0 0 0 0
41550- 0 0 0 0 0 0 0 0 0 0 0 0
41551- 0 0 0 0 0 0 0 0 0 0 0 0
41552- 0 0 0 0 0 0 0 0 0 0 0 0
41553- 0 0 0 0 0 0 0 0 0 0 0 0
41554- 0 0 0 0 0 0 0 0 0 0 0 0
41555- 0 0 0 0 0 0 0 0 0 0 0 0
41556- 0 0 0 0 0 0 0 0 0 0 0 0
41557- 0 0 0 0 0 0 0 0 0 0 0 0
41558- 0 0 0 0 0 0 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 10 10 10 34 34 34
41561- 74 74 74 74 74 74 2 2 6 6 6 6
41562-144 144 144 198 198 198 190 190 190 178 166 146
41563-154 121 60 156 107 11 156 107 11 168 124 44
41564-174 154 114 187 187 187 190 190 190 210 210 210
41565-246 246 246 253 253 253 253 253 253 182 182 182
41566- 6 6 6 2 2 6 2 2 6 2 2 6
41567- 2 2 6 2 2 6 2 2 6 62 62 62
41568- 74 74 74 34 34 34 14 14 14 0 0 0
41569- 0 0 0 0 0 0 0 0 0 0 0 0
41570- 0 0 0 0 0 0 0 0 0 0 0 0
41571- 0 0 0 0 0 0 0 0 0 0 0 0
41572- 0 0 0 0 0 0 0 0 0 0 0 0
41573- 0 0 0 0 0 0 0 0 0 0 0 0
41574- 0 0 0 0 0 0 0 0 0 0 0 0
41575- 0 0 0 0 0 0 0 0 0 0 0 0
41576- 0 0 0 0 0 0 0 0 0 0 0 0
41577- 0 0 0 0 0 0 0 0 0 0 0 0
41578- 0 0 0 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 10 10 10 22 22 22 54 54 54
41581- 94 94 94 18 18 18 2 2 6 46 46 46
41582-234 234 234 221 221 221 190 190 190 190 190 190
41583-190 190 190 187 187 187 187 187 187 190 190 190
41584-190 190 190 195 195 195 214 214 214 242 242 242
41585-253 253 253 253 253 253 253 253 253 253 253 253
41586- 82 82 82 2 2 6 2 2 6 2 2 6
41587- 2 2 6 2 2 6 2 2 6 14 14 14
41588- 86 86 86 54 54 54 22 22 22 6 6 6
41589- 0 0 0 0 0 0 0 0 0 0 0 0
41590- 0 0 0 0 0 0 0 0 0 0 0 0
41591- 0 0 0 0 0 0 0 0 0 0 0 0
41592- 0 0 0 0 0 0 0 0 0 0 0 0
41593- 0 0 0 0 0 0 0 0 0 0 0 0
41594- 0 0 0 0 0 0 0 0 0 0 0 0
41595- 0 0 0 0 0 0 0 0 0 0 0 0
41596- 0 0 0 0 0 0 0 0 0 0 0 0
41597- 0 0 0 0 0 0 0 0 0 0 0 0
41598- 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- 6 6 6 18 18 18 46 46 46 90 90 90
41601- 46 46 46 18 18 18 6 6 6 182 182 182
41602-253 253 253 246 246 246 206 206 206 190 190 190
41603-190 190 190 190 190 190 190 190 190 190 190 190
41604-206 206 206 231 231 231 250 250 250 253 253 253
41605-253 253 253 253 253 253 253 253 253 253 253 253
41606-202 202 202 14 14 14 2 2 6 2 2 6
41607- 2 2 6 2 2 6 2 2 6 2 2 6
41608- 42 42 42 86 86 86 42 42 42 18 18 18
41609- 6 6 6 0 0 0 0 0 0 0 0 0
41610- 0 0 0 0 0 0 0 0 0 0 0 0
41611- 0 0 0 0 0 0 0 0 0 0 0 0
41612- 0 0 0 0 0 0 0 0 0 0 0 0
41613- 0 0 0 0 0 0 0 0 0 0 0 0
41614- 0 0 0 0 0 0 0 0 0 0 0 0
41615- 0 0 0 0 0 0 0 0 0 0 0 0
41616- 0 0 0 0 0 0 0 0 0 0 0 0
41617- 0 0 0 0 0 0 0 0 0 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 6 6 6
41620- 14 14 14 38 38 38 74 74 74 66 66 66
41621- 2 2 6 6 6 6 90 90 90 250 250 250
41622-253 253 253 253 253 253 238 238 238 198 198 198
41623-190 190 190 190 190 190 195 195 195 221 221 221
41624-246 246 246 253 253 253 253 253 253 253 253 253
41625-253 253 253 253 253 253 253 253 253 253 253 253
41626-253 253 253 82 82 82 2 2 6 2 2 6
41627- 2 2 6 2 2 6 2 2 6 2 2 6
41628- 2 2 6 78 78 78 70 70 70 34 34 34
41629- 14 14 14 6 6 6 0 0 0 0 0 0
41630- 0 0 0 0 0 0 0 0 0 0 0 0
41631- 0 0 0 0 0 0 0 0 0 0 0 0
41632- 0 0 0 0 0 0 0 0 0 0 0 0
41633- 0 0 0 0 0 0 0 0 0 0 0 0
41634- 0 0 0 0 0 0 0 0 0 0 0 0
41635- 0 0 0 0 0 0 0 0 0 0 0 0
41636- 0 0 0 0 0 0 0 0 0 0 0 0
41637- 0 0 0 0 0 0 0 0 0 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 14 14 14
41640- 34 34 34 66 66 66 78 78 78 6 6 6
41641- 2 2 6 18 18 18 218 218 218 253 253 253
41642-253 253 253 253 253 253 253 253 253 246 246 246
41643-226 226 226 231 231 231 246 246 246 253 253 253
41644-253 253 253 253 253 253 253 253 253 253 253 253
41645-253 253 253 253 253 253 253 253 253 253 253 253
41646-253 253 253 178 178 178 2 2 6 2 2 6
41647- 2 2 6 2 2 6 2 2 6 2 2 6
41648- 2 2 6 18 18 18 90 90 90 62 62 62
41649- 30 30 30 10 10 10 0 0 0 0 0 0
41650- 0 0 0 0 0 0 0 0 0 0 0 0
41651- 0 0 0 0 0 0 0 0 0 0 0 0
41652- 0 0 0 0 0 0 0 0 0 0 0 0
41653- 0 0 0 0 0 0 0 0 0 0 0 0
41654- 0 0 0 0 0 0 0 0 0 0 0 0
41655- 0 0 0 0 0 0 0 0 0 0 0 0
41656- 0 0 0 0 0 0 0 0 0 0 0 0
41657- 0 0 0 0 0 0 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 10 10 10 26 26 26
41660- 58 58 58 90 90 90 18 18 18 2 2 6
41661- 2 2 6 110 110 110 253 253 253 253 253 253
41662-253 253 253 253 253 253 253 253 253 253 253 253
41663-250 250 250 253 253 253 253 253 253 253 253 253
41664-253 253 253 253 253 253 253 253 253 253 253 253
41665-253 253 253 253 253 253 253 253 253 253 253 253
41666-253 253 253 231 231 231 18 18 18 2 2 6
41667- 2 2 6 2 2 6 2 2 6 2 2 6
41668- 2 2 6 2 2 6 18 18 18 94 94 94
41669- 54 54 54 26 26 26 10 10 10 0 0 0
41670- 0 0 0 0 0 0 0 0 0 0 0 0
41671- 0 0 0 0 0 0 0 0 0 0 0 0
41672- 0 0 0 0 0 0 0 0 0 0 0 0
41673- 0 0 0 0 0 0 0 0 0 0 0 0
41674- 0 0 0 0 0 0 0 0 0 0 0 0
41675- 0 0 0 0 0 0 0 0 0 0 0 0
41676- 0 0 0 0 0 0 0 0 0 0 0 0
41677- 0 0 0 0 0 0 0 0 0 0 0 0
41678- 0 0 0 0 0 0 0 0 0 0 0 0
41679- 0 0 0 6 6 6 22 22 22 50 50 50
41680- 90 90 90 26 26 26 2 2 6 2 2 6
41681- 14 14 14 195 195 195 250 250 250 253 253 253
41682-253 253 253 253 253 253 253 253 253 253 253 253
41683-253 253 253 253 253 253 253 253 253 253 253 253
41684-253 253 253 253 253 253 253 253 253 253 253 253
41685-253 253 253 253 253 253 253 253 253 253 253 253
41686-250 250 250 242 242 242 54 54 54 2 2 6
41687- 2 2 6 2 2 6 2 2 6 2 2 6
41688- 2 2 6 2 2 6 2 2 6 38 38 38
41689- 86 86 86 50 50 50 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- 6 6 6 14 14 14 38 38 38 82 82 82
41700- 34 34 34 2 2 6 2 2 6 2 2 6
41701- 42 42 42 195 195 195 246 246 246 253 253 253
41702-253 253 253 253 253 253 253 253 253 250 250 250
41703-242 242 242 242 242 242 250 250 250 253 253 253
41704-253 253 253 253 253 253 253 253 253 253 253 253
41705-253 253 253 250 250 250 246 246 246 238 238 238
41706-226 226 226 231 231 231 101 101 101 6 6 6
41707- 2 2 6 2 2 6 2 2 6 2 2 6
41708- 2 2 6 2 2 6 2 2 6 2 2 6
41709- 38 38 38 82 82 82 42 42 42 14 14 14
41710- 6 6 6 0 0 0 0 0 0 0 0 0
41711- 0 0 0 0 0 0 0 0 0 0 0 0
41712- 0 0 0 0 0 0 0 0 0 0 0 0
41713- 0 0 0 0 0 0 0 0 0 0 0 0
41714- 0 0 0 0 0 0 0 0 0 0 0 0
41715- 0 0 0 0 0 0 0 0 0 0 0 0
41716- 0 0 0 0 0 0 0 0 0 0 0 0
41717- 0 0 0 0 0 0 0 0 0 0 0 0
41718- 0 0 0 0 0 0 0 0 0 0 0 0
41719- 10 10 10 26 26 26 62 62 62 66 66 66
41720- 2 2 6 2 2 6 2 2 6 6 6 6
41721- 70 70 70 170 170 170 206 206 206 234 234 234
41722-246 246 246 250 250 250 250 250 250 238 238 238
41723-226 226 226 231 231 231 238 238 238 250 250 250
41724-250 250 250 250 250 250 246 246 246 231 231 231
41725-214 214 214 206 206 206 202 202 202 202 202 202
41726-198 198 198 202 202 202 182 182 182 18 18 18
41727- 2 2 6 2 2 6 2 2 6 2 2 6
41728- 2 2 6 2 2 6 2 2 6 2 2 6
41729- 2 2 6 62 62 62 66 66 66 30 30 30
41730- 10 10 10 0 0 0 0 0 0 0 0 0
41731- 0 0 0 0 0 0 0 0 0 0 0 0
41732- 0 0 0 0 0 0 0 0 0 0 0 0
41733- 0 0 0 0 0 0 0 0 0 0 0 0
41734- 0 0 0 0 0 0 0 0 0 0 0 0
41735- 0 0 0 0 0 0 0 0 0 0 0 0
41736- 0 0 0 0 0 0 0 0 0 0 0 0
41737- 0 0 0 0 0 0 0 0 0 0 0 0
41738- 0 0 0 0 0 0 0 0 0 0 0 0
41739- 14 14 14 42 42 42 82 82 82 18 18 18
41740- 2 2 6 2 2 6 2 2 6 10 10 10
41741- 94 94 94 182 182 182 218 218 218 242 242 242
41742-250 250 250 253 253 253 253 253 253 250 250 250
41743-234 234 234 253 253 253 253 253 253 253 253 253
41744-253 253 253 253 253 253 253 253 253 246 246 246
41745-238 238 238 226 226 226 210 210 210 202 202 202
41746-195 195 195 195 195 195 210 210 210 158 158 158
41747- 6 6 6 14 14 14 50 50 50 14 14 14
41748- 2 2 6 2 2 6 2 2 6 2 2 6
41749- 2 2 6 6 6 6 86 86 86 46 46 46
41750- 18 18 18 6 6 6 0 0 0 0 0 0
41751- 0 0 0 0 0 0 0 0 0 0 0 0
41752- 0 0 0 0 0 0 0 0 0 0 0 0
41753- 0 0 0 0 0 0 0 0 0 0 0 0
41754- 0 0 0 0 0 0 0 0 0 0 0 0
41755- 0 0 0 0 0 0 0 0 0 0 0 0
41756- 0 0 0 0 0 0 0 0 0 0 0 0
41757- 0 0 0 0 0 0 0 0 0 0 0 0
41758- 0 0 0 0 0 0 0 0 0 6 6 6
41759- 22 22 22 54 54 54 70 70 70 2 2 6
41760- 2 2 6 10 10 10 2 2 6 22 22 22
41761-166 166 166 231 231 231 250 250 250 253 253 253
41762-253 253 253 253 253 253 253 253 253 250 250 250
41763-242 242 242 253 253 253 253 253 253 253 253 253
41764-253 253 253 253 253 253 253 253 253 253 253 253
41765-253 253 253 253 253 253 253 253 253 246 246 246
41766-231 231 231 206 206 206 198 198 198 226 226 226
41767- 94 94 94 2 2 6 6 6 6 38 38 38
41768- 30 30 30 2 2 6 2 2 6 2 2 6
41769- 2 2 6 2 2 6 62 62 62 66 66 66
41770- 26 26 26 10 10 10 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 10 10 10
41779- 30 30 30 74 74 74 50 50 50 2 2 6
41780- 26 26 26 26 26 26 2 2 6 106 106 106
41781-238 238 238 253 253 253 253 253 253 253 253 253
41782-253 253 253 253 253 253 253 253 253 253 253 253
41783-253 253 253 253 253 253 253 253 253 253 253 253
41784-253 253 253 253 253 253 253 253 253 253 253 253
41785-253 253 253 253 253 253 253 253 253 253 253 253
41786-253 253 253 246 246 246 218 218 218 202 202 202
41787-210 210 210 14 14 14 2 2 6 2 2 6
41788- 30 30 30 22 22 22 2 2 6 2 2 6
41789- 2 2 6 2 2 6 18 18 18 86 86 86
41790- 42 42 42 14 14 14 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 14 14 14
41799- 42 42 42 90 90 90 22 22 22 2 2 6
41800- 42 42 42 2 2 6 18 18 18 218 218 218
41801-253 253 253 253 253 253 253 253 253 253 253 253
41802-253 253 253 253 253 253 253 253 253 253 253 253
41803-253 253 253 253 253 253 253 253 253 253 253 253
41804-253 253 253 253 253 253 253 253 253 253 253 253
41805-253 253 253 253 253 253 253 253 253 253 253 253
41806-253 253 253 253 253 253 250 250 250 221 221 221
41807-218 218 218 101 101 101 2 2 6 14 14 14
41808- 18 18 18 38 38 38 10 10 10 2 2 6
41809- 2 2 6 2 2 6 2 2 6 78 78 78
41810- 58 58 58 22 22 22 6 6 6 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 6 6 6 18 18 18
41819- 54 54 54 82 82 82 2 2 6 26 26 26
41820- 22 22 22 2 2 6 123 123 123 253 253 253
41821-253 253 253 253 253 253 253 253 253 253 253 253
41822-253 253 253 253 253 253 253 253 253 253 253 253
41823-253 253 253 253 253 253 253 253 253 253 253 253
41824-253 253 253 253 253 253 253 253 253 253 253 253
41825-253 253 253 253 253 253 253 253 253 253 253 253
41826-253 253 253 253 253 253 253 253 253 250 250 250
41827-238 238 238 198 198 198 6 6 6 38 38 38
41828- 58 58 58 26 26 26 38 38 38 2 2 6
41829- 2 2 6 2 2 6 2 2 6 46 46 46
41830- 78 78 78 30 30 30 10 10 10 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 10 10 10 30 30 30
41839- 74 74 74 58 58 58 2 2 6 42 42 42
41840- 2 2 6 22 22 22 231 231 231 253 253 253
41841-253 253 253 253 253 253 253 253 253 253 253 253
41842-253 253 253 253 253 253 253 253 253 250 250 250
41843-253 253 253 253 253 253 253 253 253 253 253 253
41844-253 253 253 253 253 253 253 253 253 253 253 253
41845-253 253 253 253 253 253 253 253 253 253 253 253
41846-253 253 253 253 253 253 253 253 253 253 253 253
41847-253 253 253 246 246 246 46 46 46 38 38 38
41848- 42 42 42 14 14 14 38 38 38 14 14 14
41849- 2 2 6 2 2 6 2 2 6 6 6 6
41850- 86 86 86 46 46 46 14 14 14 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 6 6 6 14 14 14 42 42 42
41859- 90 90 90 18 18 18 18 18 18 26 26 26
41860- 2 2 6 116 116 116 253 253 253 253 253 253
41861-253 253 253 253 253 253 253 253 253 253 253 253
41862-253 253 253 253 253 253 250 250 250 238 238 238
41863-253 253 253 253 253 253 253 253 253 253 253 253
41864-253 253 253 253 253 253 253 253 253 253 253 253
41865-253 253 253 253 253 253 253 253 253 253 253 253
41866-253 253 253 253 253 253 253 253 253 253 253 253
41867-253 253 253 253 253 253 94 94 94 6 6 6
41868- 2 2 6 2 2 6 10 10 10 34 34 34
41869- 2 2 6 2 2 6 2 2 6 2 2 6
41870- 74 74 74 58 58 58 22 22 22 6 6 6
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 10 10 10 26 26 26 66 66 66
41879- 82 82 82 2 2 6 38 38 38 6 6 6
41880- 14 14 14 210 210 210 253 253 253 253 253 253
41881-253 253 253 253 253 253 253 253 253 253 253 253
41882-253 253 253 253 253 253 246 246 246 242 242 242
41883-253 253 253 253 253 253 253 253 253 253 253 253
41884-253 253 253 253 253 253 253 253 253 253 253 253
41885-253 253 253 253 253 253 253 253 253 253 253 253
41886-253 253 253 253 253 253 253 253 253 253 253 253
41887-253 253 253 253 253 253 144 144 144 2 2 6
41888- 2 2 6 2 2 6 2 2 6 46 46 46
41889- 2 2 6 2 2 6 2 2 6 2 2 6
41890- 42 42 42 74 74 74 30 30 30 10 10 10
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- 6 6 6 14 14 14 42 42 42 90 90 90
41899- 26 26 26 6 6 6 42 42 42 2 2 6
41900- 74 74 74 250 250 250 253 253 253 253 253 253
41901-253 253 253 253 253 253 253 253 253 253 253 253
41902-253 253 253 253 253 253 242 242 242 242 242 242
41903-253 253 253 253 253 253 253 253 253 253 253 253
41904-253 253 253 253 253 253 253 253 253 253 253 253
41905-253 253 253 253 253 253 253 253 253 253 253 253
41906-253 253 253 253 253 253 253 253 253 253 253 253
41907-253 253 253 253 253 253 182 182 182 2 2 6
41908- 2 2 6 2 2 6 2 2 6 46 46 46
41909- 2 2 6 2 2 6 2 2 6 2 2 6
41910- 10 10 10 86 86 86 38 38 38 10 10 10
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- 10 10 10 26 26 26 66 66 66 82 82 82
41919- 2 2 6 22 22 22 18 18 18 2 2 6
41920-149 149 149 253 253 253 253 253 253 253 253 253
41921-253 253 253 253 253 253 253 253 253 253 253 253
41922-253 253 253 253 253 253 234 234 234 242 242 242
41923-253 253 253 253 253 253 253 253 253 253 253 253
41924-253 253 253 253 253 253 253 253 253 253 253 253
41925-253 253 253 253 253 253 253 253 253 253 253 253
41926-253 253 253 253 253 253 253 253 253 253 253 253
41927-253 253 253 253 253 253 206 206 206 2 2 6
41928- 2 2 6 2 2 6 2 2 6 38 38 38
41929- 2 2 6 2 2 6 2 2 6 2 2 6
41930- 6 6 6 86 86 86 46 46 46 14 14 14
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 6 6 6
41938- 18 18 18 46 46 46 86 86 86 18 18 18
41939- 2 2 6 34 34 34 10 10 10 6 6 6
41940-210 210 210 253 253 253 253 253 253 253 253 253
41941-253 253 253 253 253 253 253 253 253 253 253 253
41942-253 253 253 253 253 253 234 234 234 242 242 242
41943-253 253 253 253 253 253 253 253 253 253 253 253
41944-253 253 253 253 253 253 253 253 253 253 253 253
41945-253 253 253 253 253 253 253 253 253 253 253 253
41946-253 253 253 253 253 253 253 253 253 253 253 253
41947-253 253 253 253 253 253 221 221 221 6 6 6
41948- 2 2 6 2 2 6 6 6 6 30 30 30
41949- 2 2 6 2 2 6 2 2 6 2 2 6
41950- 2 2 6 82 82 82 54 54 54 18 18 18
41951- 6 6 6 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 10 10 10
41958- 26 26 26 66 66 66 62 62 62 2 2 6
41959- 2 2 6 38 38 38 10 10 10 26 26 26
41960-238 238 238 253 253 253 253 253 253 253 253 253
41961-253 253 253 253 253 253 253 253 253 253 253 253
41962-253 253 253 253 253 253 231 231 231 238 238 238
41963-253 253 253 253 253 253 253 253 253 253 253 253
41964-253 253 253 253 253 253 253 253 253 253 253 253
41965-253 253 253 253 253 253 253 253 253 253 253 253
41966-253 253 253 253 253 253 253 253 253 253 253 253
41967-253 253 253 253 253 253 231 231 231 6 6 6
41968- 2 2 6 2 2 6 10 10 10 30 30 30
41969- 2 2 6 2 2 6 2 2 6 2 2 6
41970- 2 2 6 66 66 66 58 58 58 22 22 22
41971- 6 6 6 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 10 10 10
41978- 38 38 38 78 78 78 6 6 6 2 2 6
41979- 2 2 6 46 46 46 14 14 14 42 42 42
41980-246 246 246 253 253 253 253 253 253 253 253 253
41981-253 253 253 253 253 253 253 253 253 253 253 253
41982-253 253 253 253 253 253 231 231 231 242 242 242
41983-253 253 253 253 253 253 253 253 253 253 253 253
41984-253 253 253 253 253 253 253 253 253 253 253 253
41985-253 253 253 253 253 253 253 253 253 253 253 253
41986-253 253 253 253 253 253 253 253 253 253 253 253
41987-253 253 253 253 253 253 234 234 234 10 10 10
41988- 2 2 6 2 2 6 22 22 22 14 14 14
41989- 2 2 6 2 2 6 2 2 6 2 2 6
41990- 2 2 6 66 66 66 62 62 62 22 22 22
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 6 6 6 18 18 18
41998- 50 50 50 74 74 74 2 2 6 2 2 6
41999- 14 14 14 70 70 70 34 34 34 62 62 62
42000-250 250 250 253 253 253 253 253 253 253 253 253
42001-253 253 253 253 253 253 253 253 253 253 253 253
42002-253 253 253 253 253 253 231 231 231 246 246 246
42003-253 253 253 253 253 253 253 253 253 253 253 253
42004-253 253 253 253 253 253 253 253 253 253 253 253
42005-253 253 253 253 253 253 253 253 253 253 253 253
42006-253 253 253 253 253 253 253 253 253 253 253 253
42007-253 253 253 253 253 253 234 234 234 14 14 14
42008- 2 2 6 2 2 6 30 30 30 2 2 6
42009- 2 2 6 2 2 6 2 2 6 2 2 6
42010- 2 2 6 66 66 66 62 62 62 22 22 22
42011- 6 6 6 0 0 0 0 0 0 0 0 0
42012- 0 0 0 0 0 0 0 0 0 0 0 0
42013- 0 0 0 0 0 0 0 0 0 0 0 0
42014- 0 0 0 0 0 0 0 0 0 0 0 0
42015- 0 0 0 0 0 0 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 6 6 6 18 18 18
42018- 54 54 54 62 62 62 2 2 6 2 2 6
42019- 2 2 6 30 30 30 46 46 46 70 70 70
42020-250 250 250 253 253 253 253 253 253 253 253 253
42021-253 253 253 253 253 253 253 253 253 253 253 253
42022-253 253 253 253 253 253 231 231 231 246 246 246
42023-253 253 253 253 253 253 253 253 253 253 253 253
42024-253 253 253 253 253 253 253 253 253 253 253 253
42025-253 253 253 253 253 253 253 253 253 253 253 253
42026-253 253 253 253 253 253 253 253 253 253 253 253
42027-253 253 253 253 253 253 226 226 226 10 10 10
42028- 2 2 6 6 6 6 30 30 30 2 2 6
42029- 2 2 6 2 2 6 2 2 6 2 2 6
42030- 2 2 6 66 66 66 58 58 58 22 22 22
42031- 6 6 6 0 0 0 0 0 0 0 0 0
42032- 0 0 0 0 0 0 0 0 0 0 0 0
42033- 0 0 0 0 0 0 0 0 0 0 0 0
42034- 0 0 0 0 0 0 0 0 0 0 0 0
42035- 0 0 0 0 0 0 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 6 6 6 22 22 22
42038- 58 58 58 62 62 62 2 2 6 2 2 6
42039- 2 2 6 2 2 6 30 30 30 78 78 78
42040-250 250 250 253 253 253 253 253 253 253 253 253
42041-253 253 253 253 253 253 253 253 253 253 253 253
42042-253 253 253 253 253 253 231 231 231 246 246 246
42043-253 253 253 253 253 253 253 253 253 253 253 253
42044-253 253 253 253 253 253 253 253 253 253 253 253
42045-253 253 253 253 253 253 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 206 206 206 2 2 6
42048- 22 22 22 34 34 34 18 14 6 22 22 22
42049- 26 26 26 18 18 18 6 6 6 2 2 6
42050- 2 2 6 82 82 82 54 54 54 18 18 18
42051- 6 6 6 0 0 0 0 0 0 0 0 0
42052- 0 0 0 0 0 0 0 0 0 0 0 0
42053- 0 0 0 0 0 0 0 0 0 0 0 0
42054- 0 0 0 0 0 0 0 0 0 0 0 0
42055- 0 0 0 0 0 0 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 6 6 6 26 26 26
42058- 62 62 62 106 106 106 74 54 14 185 133 11
42059-210 162 10 121 92 8 6 6 6 62 62 62
42060-238 238 238 253 253 253 253 253 253 253 253 253
42061-253 253 253 253 253 253 253 253 253 253 253 253
42062-253 253 253 253 253 253 231 231 231 246 246 246
42063-253 253 253 253 253 253 253 253 253 253 253 253
42064-253 253 253 253 253 253 253 253 253 253 253 253
42065-253 253 253 253 253 253 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 158 158 158 18 18 18
42068- 14 14 14 2 2 6 2 2 6 2 2 6
42069- 6 6 6 18 18 18 66 66 66 38 38 38
42070- 6 6 6 94 94 94 50 50 50 18 18 18
42071- 6 6 6 0 0 0 0 0 0 0 0 0
42072- 0 0 0 0 0 0 0 0 0 0 0 0
42073- 0 0 0 0 0 0 0 0 0 0 0 0
42074- 0 0 0 0 0 0 0 0 0 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 6 6 6
42077- 10 10 10 10 10 10 18 18 18 38 38 38
42078- 78 78 78 142 134 106 216 158 10 242 186 14
42079-246 190 14 246 190 14 156 118 10 10 10 10
42080- 90 90 90 238 238 238 253 253 253 253 253 253
42081-253 253 253 253 253 253 253 253 253 253 253 253
42082-253 253 253 253 253 253 231 231 231 250 250 250
42083-253 253 253 253 253 253 253 253 253 253 253 253
42084-253 253 253 253 253 253 253 253 253 253 253 253
42085-253 253 253 253 253 253 253 253 253 253 253 253
42086-253 253 253 253 253 253 253 253 253 246 230 190
42087-238 204 91 238 204 91 181 142 44 37 26 9
42088- 2 2 6 2 2 6 2 2 6 2 2 6
42089- 2 2 6 2 2 6 38 38 38 46 46 46
42090- 26 26 26 106 106 106 54 54 54 18 18 18
42091- 6 6 6 0 0 0 0 0 0 0 0 0
42092- 0 0 0 0 0 0 0 0 0 0 0 0
42093- 0 0 0 0 0 0 0 0 0 0 0 0
42094- 0 0 0 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 6 6 6 14 14 14 22 22 22
42097- 30 30 30 38 38 38 50 50 50 70 70 70
42098-106 106 106 190 142 34 226 170 11 242 186 14
42099-246 190 14 246 190 14 246 190 14 154 114 10
42100- 6 6 6 74 74 74 226 226 226 253 253 253
42101-253 253 253 253 253 253 253 253 253 253 253 253
42102-253 253 253 253 253 253 231 231 231 250 250 250
42103-253 253 253 253 253 253 253 253 253 253 253 253
42104-253 253 253 253 253 253 253 253 253 253 253 253
42105-253 253 253 253 253 253 253 253 253 253 253 253
42106-253 253 253 253 253 253 253 253 253 228 184 62
42107-241 196 14 241 208 19 232 195 16 38 30 10
42108- 2 2 6 2 2 6 2 2 6 2 2 6
42109- 2 2 6 6 6 6 30 30 30 26 26 26
42110-203 166 17 154 142 90 66 66 66 26 26 26
42111- 6 6 6 0 0 0 0 0 0 0 0 0
42112- 0 0 0 0 0 0 0 0 0 0 0 0
42113- 0 0 0 0 0 0 0 0 0 0 0 0
42114- 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- 6 6 6 18 18 18 38 38 38 58 58 58
42117- 78 78 78 86 86 86 101 101 101 123 123 123
42118-175 146 61 210 150 10 234 174 13 246 186 14
42119-246 190 14 246 190 14 246 190 14 238 190 10
42120-102 78 10 2 2 6 46 46 46 198 198 198
42121-253 253 253 253 253 253 253 253 253 253 253 253
42122-253 253 253 253 253 253 234 234 234 242 242 242
42123-253 253 253 253 253 253 253 253 253 253 253 253
42124-253 253 253 253 253 253 253 253 253 253 253 253
42125-253 253 253 253 253 253 253 253 253 253 253 253
42126-253 253 253 253 253 253 253 253 253 224 178 62
42127-242 186 14 241 196 14 210 166 10 22 18 6
42128- 2 2 6 2 2 6 2 2 6 2 2 6
42129- 2 2 6 2 2 6 6 6 6 121 92 8
42130-238 202 15 232 195 16 82 82 82 34 34 34
42131- 10 10 10 0 0 0 0 0 0 0 0 0
42132- 0 0 0 0 0 0 0 0 0 0 0 0
42133- 0 0 0 0 0 0 0 0 0 0 0 0
42134- 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- 14 14 14 38 38 38 70 70 70 154 122 46
42137-190 142 34 200 144 11 197 138 11 197 138 11
42138-213 154 11 226 170 11 242 186 14 246 190 14
42139-246 190 14 246 190 14 246 190 14 246 190 14
42140-225 175 15 46 32 6 2 2 6 22 22 22
42141-158 158 158 250 250 250 253 253 253 253 253 253
42142-253 253 253 253 253 253 253 253 253 253 253 253
42143-253 253 253 253 253 253 253 253 253 253 253 253
42144-253 253 253 253 253 253 253 253 253 253 253 253
42145-253 253 253 253 253 253 253 253 253 253 253 253
42146-253 253 253 250 250 250 242 242 242 224 178 62
42147-239 182 13 236 186 11 213 154 11 46 32 6
42148- 2 2 6 2 2 6 2 2 6 2 2 6
42149- 2 2 6 2 2 6 61 42 6 225 175 15
42150-238 190 10 236 186 11 112 100 78 42 42 42
42151- 14 14 14 0 0 0 0 0 0 0 0 0
42152- 0 0 0 0 0 0 0 0 0 0 0 0
42153- 0 0 0 0 0 0 0 0 0 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 6 6 6
42156- 22 22 22 54 54 54 154 122 46 213 154 11
42157-226 170 11 230 174 11 226 170 11 226 170 11
42158-236 178 12 242 186 14 246 190 14 246 190 14
42159-246 190 14 246 190 14 246 190 14 246 190 14
42160-241 196 14 184 144 12 10 10 10 2 2 6
42161- 6 6 6 116 116 116 242 242 242 253 253 253
42162-253 253 253 253 253 253 253 253 253 253 253 253
42163-253 253 253 253 253 253 253 253 253 253 253 253
42164-253 253 253 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 231 231 231 198 198 198 214 170 54
42167-236 178 12 236 178 12 210 150 10 137 92 6
42168- 18 14 6 2 2 6 2 2 6 2 2 6
42169- 6 6 6 70 47 6 200 144 11 236 178 12
42170-239 182 13 239 182 13 124 112 88 58 58 58
42171- 22 22 22 6 6 6 0 0 0 0 0 0
42172- 0 0 0 0 0 0 0 0 0 0 0 0
42173- 0 0 0 0 0 0 0 0 0 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 10 10 10
42176- 30 30 30 70 70 70 180 133 36 226 170 11
42177-239 182 13 242 186 14 242 186 14 246 186 14
42178-246 190 14 246 190 14 246 190 14 246 190 14
42179-246 190 14 246 190 14 246 190 14 246 190 14
42180-246 190 14 232 195 16 98 70 6 2 2 6
42181- 2 2 6 2 2 6 66 66 66 221 221 221
42182-253 253 253 253 253 253 253 253 253 253 253 253
42183-253 253 253 253 253 253 253 253 253 253 253 253
42184-253 253 253 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 206 206 206 198 198 198 214 166 58
42187-230 174 11 230 174 11 216 158 10 192 133 9
42188-163 110 8 116 81 8 102 78 10 116 81 8
42189-167 114 7 197 138 11 226 170 11 239 182 13
42190-242 186 14 242 186 14 162 146 94 78 78 78
42191- 34 34 34 14 14 14 6 6 6 0 0 0
42192- 0 0 0 0 0 0 0 0 0 0 0 0
42193- 0 0 0 0 0 0 0 0 0 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 6 6 6
42196- 30 30 30 78 78 78 190 142 34 226 170 11
42197-239 182 13 246 190 14 246 190 14 246 190 14
42198-246 190 14 246 190 14 246 190 14 246 190 14
42199-246 190 14 246 190 14 246 190 14 246 190 14
42200-246 190 14 241 196 14 203 166 17 22 18 6
42201- 2 2 6 2 2 6 2 2 6 38 38 38
42202-218 218 218 253 253 253 253 253 253 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-250 250 250 206 206 206 198 198 198 202 162 69
42207-226 170 11 236 178 12 224 166 10 210 150 10
42208-200 144 11 197 138 11 192 133 9 197 138 11
42209-210 150 10 226 170 11 242 186 14 246 190 14
42210-246 190 14 246 186 14 225 175 15 124 112 88
42211- 62 62 62 30 30 30 14 14 14 6 6 6
42212- 0 0 0 0 0 0 0 0 0 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 10 10 10
42216- 30 30 30 78 78 78 174 135 50 224 166 10
42217-239 182 13 246 190 14 246 190 14 246 190 14
42218-246 190 14 246 190 14 246 190 14 246 190 14
42219-246 190 14 246 190 14 246 190 14 246 190 14
42220-246 190 14 246 190 14 241 196 14 139 102 15
42221- 2 2 6 2 2 6 2 2 6 2 2 6
42222- 78 78 78 250 250 250 253 253 253 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 253 253 253
42225-253 253 253 253 253 253 253 253 253 253 253 253
42226-250 250 250 214 214 214 198 198 198 190 150 46
42227-219 162 10 236 178 12 234 174 13 224 166 10
42228-216 158 10 213 154 11 213 154 11 216 158 10
42229-226 170 11 239 182 13 246 190 14 246 190 14
42230-246 190 14 246 190 14 242 186 14 206 162 42
42231-101 101 101 58 58 58 30 30 30 14 14 14
42232- 6 6 6 0 0 0 0 0 0 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 10 10 10
42236- 30 30 30 74 74 74 174 135 50 216 158 10
42237-236 178 12 246 190 14 246 190 14 246 190 14
42238-246 190 14 246 190 14 246 190 14 246 190 14
42239-246 190 14 246 190 14 246 190 14 246 190 14
42240-246 190 14 246 190 14 241 196 14 226 184 13
42241- 61 42 6 2 2 6 2 2 6 2 2 6
42242- 22 22 22 238 238 238 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 253 253 253 253 253 253
42245-253 253 253 253 253 253 253 253 253 253 253 253
42246-253 253 253 226 226 226 187 187 187 180 133 36
42247-216 158 10 236 178 12 239 182 13 236 178 12
42248-230 174 11 226 170 11 226 170 11 230 174 11
42249-236 178 12 242 186 14 246 190 14 246 190 14
42250-246 190 14 246 190 14 246 186 14 239 182 13
42251-206 162 42 106 106 106 66 66 66 34 34 34
42252- 14 14 14 6 6 6 0 0 0 0 0 0
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 6 6 6
42256- 26 26 26 70 70 70 163 133 67 213 154 11
42257-236 178 12 246 190 14 246 190 14 246 190 14
42258-246 190 14 246 190 14 246 190 14 246 190 14
42259-246 190 14 246 190 14 246 190 14 246 190 14
42260-246 190 14 246 190 14 246 190 14 241 196 14
42261-190 146 13 18 14 6 2 2 6 2 2 6
42262- 46 46 46 246 246 246 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 253 253 253 253 253 253
42265-253 253 253 253 253 253 253 253 253 253 253 253
42266-253 253 253 221 221 221 86 86 86 156 107 11
42267-216 158 10 236 178 12 242 186 14 246 186 14
42268-242 186 14 239 182 13 239 182 13 242 186 14
42269-242 186 14 246 186 14 246 190 14 246 190 14
42270-246 190 14 246 190 14 246 190 14 246 190 14
42271-242 186 14 225 175 15 142 122 72 66 66 66
42272- 30 30 30 10 10 10 0 0 0 0 0 0
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 6 6 6
42276- 26 26 26 70 70 70 163 133 67 210 150 10
42277-236 178 12 246 190 14 246 190 14 246 190 14
42278-246 190 14 246 190 14 246 190 14 246 190 14
42279-246 190 14 246 190 14 246 190 14 246 190 14
42280-246 190 14 246 190 14 246 190 14 246 190 14
42281-232 195 16 121 92 8 34 34 34 106 106 106
42282-221 221 221 253 253 253 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 253 253 253 253 253 253
42285-253 253 253 253 253 253 253 253 253 253 253 253
42286-242 242 242 82 82 82 18 14 6 163 110 8
42287-216 158 10 236 178 12 242 186 14 246 190 14
42288-246 190 14 246 190 14 246 190 14 246 190 14
42289-246 190 14 246 190 14 246 190 14 246 190 14
42290-246 190 14 246 190 14 246 190 14 246 190 14
42291-246 190 14 246 190 14 242 186 14 163 133 67
42292- 46 46 46 18 18 18 6 6 6 0 0 0
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 10 10 10
42296- 30 30 30 78 78 78 163 133 67 210 150 10
42297-236 178 12 246 186 14 246 190 14 246 190 14
42298-246 190 14 246 190 14 246 190 14 246 190 14
42299-246 190 14 246 190 14 246 190 14 246 190 14
42300-246 190 14 246 190 14 246 190 14 246 190 14
42301-241 196 14 215 174 15 190 178 144 253 253 253
42302-253 253 253 253 253 253 253 253 253 253 253 253
42303-253 253 253 253 253 253 253 253 253 253 253 253
42304-253 253 253 253 253 253 253 253 253 253 253 253
42305-253 253 253 253 253 253 253 253 253 218 218 218
42306- 58 58 58 2 2 6 22 18 6 167 114 7
42307-216 158 10 236 178 12 246 186 14 246 190 14
42308-246 190 14 246 190 14 246 190 14 246 190 14
42309-246 190 14 246 190 14 246 190 14 246 190 14
42310-246 190 14 246 190 14 246 190 14 246 190 14
42311-246 190 14 246 186 14 242 186 14 190 150 46
42312- 54 54 54 22 22 22 6 6 6 0 0 0
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 14 14 14
42316- 38 38 38 86 86 86 180 133 36 213 154 11
42317-236 178 12 246 186 14 246 190 14 246 190 14
42318-246 190 14 246 190 14 246 190 14 246 190 14
42319-246 190 14 246 190 14 246 190 14 246 190 14
42320-246 190 14 246 190 14 246 190 14 246 190 14
42321-246 190 14 232 195 16 190 146 13 214 214 214
42322-253 253 253 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 253 253 253 253 253 253
42325-253 253 253 250 250 250 170 170 170 26 26 26
42326- 2 2 6 2 2 6 37 26 9 163 110 8
42327-219 162 10 239 182 13 246 186 14 246 190 14
42328-246 190 14 246 190 14 246 190 14 246 190 14
42329-246 190 14 246 190 14 246 190 14 246 190 14
42330-246 190 14 246 190 14 246 190 14 246 190 14
42331-246 186 14 236 178 12 224 166 10 142 122 72
42332- 46 46 46 18 18 18 6 6 6 0 0 0
42333- 0 0 0 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 6 6 6 18 18 18
42336- 50 50 50 109 106 95 192 133 9 224 166 10
42337-242 186 14 246 190 14 246 190 14 246 190 14
42338-246 190 14 246 190 14 246 190 14 246 190 14
42339-246 190 14 246 190 14 246 190 14 246 190 14
42340-246 190 14 246 190 14 246 190 14 246 190 14
42341-242 186 14 226 184 13 210 162 10 142 110 46
42342-226 226 226 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 253 253 253 253 253 253
42345-198 198 198 66 66 66 2 2 6 2 2 6
42346- 2 2 6 2 2 6 50 34 6 156 107 11
42347-219 162 10 239 182 13 246 186 14 246 190 14
42348-246 190 14 246 190 14 246 190 14 246 190 14
42349-246 190 14 246 190 14 246 190 14 246 190 14
42350-246 190 14 246 190 14 246 190 14 242 186 14
42351-234 174 13 213 154 11 154 122 46 66 66 66
42352- 30 30 30 10 10 10 0 0 0 0 0 0
42353- 0 0 0 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 6 6 6 22 22 22
42356- 58 58 58 154 121 60 206 145 10 234 174 13
42357-242 186 14 246 186 14 246 190 14 246 190 14
42358-246 190 14 246 190 14 246 190 14 246 190 14
42359-246 190 14 246 190 14 246 190 14 246 190 14
42360-246 190 14 246 190 14 246 190 14 246 190 14
42361-246 186 14 236 178 12 210 162 10 163 110 8
42362- 61 42 6 138 138 138 218 218 218 250 250 250
42363-253 253 253 253 253 253 253 253 253 250 250 250
42364-242 242 242 210 210 210 144 144 144 66 66 66
42365- 6 6 6 2 2 6 2 2 6 2 2 6
42366- 2 2 6 2 2 6 61 42 6 163 110 8
42367-216 158 10 236 178 12 246 190 14 246 190 14
42368-246 190 14 246 190 14 246 190 14 246 190 14
42369-246 190 14 246 190 14 246 190 14 246 190 14
42370-246 190 14 239 182 13 230 174 11 216 158 10
42371-190 142 34 124 112 88 70 70 70 38 38 38
42372- 18 18 18 6 6 6 0 0 0 0 0 0
42373- 0 0 0 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 6 6 6 22 22 22
42376- 62 62 62 168 124 44 206 145 10 224 166 10
42377-236 178 12 239 182 13 242 186 14 242 186 14
42378-246 186 14 246 190 14 246 190 14 246 190 14
42379-246 190 14 246 190 14 246 190 14 246 190 14
42380-246 190 14 246 190 14 246 190 14 246 190 14
42381-246 190 14 236 178 12 216 158 10 175 118 6
42382- 80 54 7 2 2 6 6 6 6 30 30 30
42383- 54 54 54 62 62 62 50 50 50 38 38 38
42384- 14 14 14 2 2 6 2 2 6 2 2 6
42385- 2 2 6 2 2 6 2 2 6 2 2 6
42386- 2 2 6 6 6 6 80 54 7 167 114 7
42387-213 154 11 236 178 12 246 190 14 246 190 14
42388-246 190 14 246 190 14 246 190 14 246 190 14
42389-246 190 14 242 186 14 239 182 13 239 182 13
42390-230 174 11 210 150 10 174 135 50 124 112 88
42391- 82 82 82 54 54 54 34 34 34 18 18 18
42392- 6 6 6 0 0 0 0 0 0 0 0 0
42393- 0 0 0 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 6 6 6 18 18 18
42396- 50 50 50 158 118 36 192 133 9 200 144 11
42397-216 158 10 219 162 10 224 166 10 226 170 11
42398-230 174 11 236 178 12 239 182 13 239 182 13
42399-242 186 14 246 186 14 246 190 14 246 190 14
42400-246 190 14 246 190 14 246 190 14 246 190 14
42401-246 186 14 230 174 11 210 150 10 163 110 8
42402-104 69 6 10 10 10 2 2 6 2 2 6
42403- 2 2 6 2 2 6 2 2 6 2 2 6
42404- 2 2 6 2 2 6 2 2 6 2 2 6
42405- 2 2 6 2 2 6 2 2 6 2 2 6
42406- 2 2 6 6 6 6 91 60 6 167 114 7
42407-206 145 10 230 174 11 242 186 14 246 190 14
42408-246 190 14 246 190 14 246 186 14 242 186 14
42409-239 182 13 230 174 11 224 166 10 213 154 11
42410-180 133 36 124 112 88 86 86 86 58 58 58
42411- 38 38 38 22 22 22 10 10 10 6 6 6
42412- 0 0 0 0 0 0 0 0 0 0 0 0
42413- 0 0 0 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 14 14 14
42416- 34 34 34 70 70 70 138 110 50 158 118 36
42417-167 114 7 180 123 7 192 133 9 197 138 11
42418-200 144 11 206 145 10 213 154 11 219 162 10
42419-224 166 10 230 174 11 239 182 13 242 186 14
42420-246 186 14 246 186 14 246 186 14 246 186 14
42421-239 182 13 216 158 10 185 133 11 152 99 6
42422-104 69 6 18 14 6 2 2 6 2 2 6
42423- 2 2 6 2 2 6 2 2 6 2 2 6
42424- 2 2 6 2 2 6 2 2 6 2 2 6
42425- 2 2 6 2 2 6 2 2 6 2 2 6
42426- 2 2 6 6 6 6 80 54 7 152 99 6
42427-192 133 9 219 162 10 236 178 12 239 182 13
42428-246 186 14 242 186 14 239 182 13 236 178 12
42429-224 166 10 206 145 10 192 133 9 154 121 60
42430- 94 94 94 62 62 62 42 42 42 22 22 22
42431- 14 14 14 6 6 6 0 0 0 0 0 0
42432- 0 0 0 0 0 0 0 0 0 0 0 0
42433- 0 0 0 0 0 0 0 0 0 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 6 6 6
42436- 18 18 18 34 34 34 58 58 58 78 78 78
42437-101 98 89 124 112 88 142 110 46 156 107 11
42438-163 110 8 167 114 7 175 118 6 180 123 7
42439-185 133 11 197 138 11 210 150 10 219 162 10
42440-226 170 11 236 178 12 236 178 12 234 174 13
42441-219 162 10 197 138 11 163 110 8 130 83 6
42442- 91 60 6 10 10 10 2 2 6 2 2 6
42443- 18 18 18 38 38 38 38 38 38 38 38 38
42444- 38 38 38 38 38 38 38 38 38 38 38 38
42445- 38 38 38 38 38 38 26 26 26 2 2 6
42446- 2 2 6 6 6 6 70 47 6 137 92 6
42447-175 118 6 200 144 11 219 162 10 230 174 11
42448-234 174 13 230 174 11 219 162 10 210 150 10
42449-192 133 9 163 110 8 124 112 88 82 82 82
42450- 50 50 50 30 30 30 14 14 14 6 6 6
42451- 0 0 0 0 0 0 0 0 0 0 0 0
42452- 0 0 0 0 0 0 0 0 0 0 0 0
42453- 0 0 0 0 0 0 0 0 0 0 0 0
42454- 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- 6 6 6 14 14 14 22 22 22 34 34 34
42457- 42 42 42 58 58 58 74 74 74 86 86 86
42458-101 98 89 122 102 70 130 98 46 121 87 25
42459-137 92 6 152 99 6 163 110 8 180 123 7
42460-185 133 11 197 138 11 206 145 10 200 144 11
42461-180 123 7 156 107 11 130 83 6 104 69 6
42462- 50 34 6 54 54 54 110 110 110 101 98 89
42463- 86 86 86 82 82 82 78 78 78 78 78 78
42464- 78 78 78 78 78 78 78 78 78 78 78 78
42465- 78 78 78 82 82 82 86 86 86 94 94 94
42466-106 106 106 101 101 101 86 66 34 124 80 6
42467-156 107 11 180 123 7 192 133 9 200 144 11
42468-206 145 10 200 144 11 192 133 9 175 118 6
42469-139 102 15 109 106 95 70 70 70 42 42 42
42470- 22 22 22 10 10 10 0 0 0 0 0 0
42471- 0 0 0 0 0 0 0 0 0 0 0 0
42472- 0 0 0 0 0 0 0 0 0 0 0 0
42473- 0 0 0 0 0 0 0 0 0 0 0 0
42474- 0 0 0 0 0 0 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 6 6 6 10 10 10
42477- 14 14 14 22 22 22 30 30 30 38 38 38
42478- 50 50 50 62 62 62 74 74 74 90 90 90
42479-101 98 89 112 100 78 121 87 25 124 80 6
42480-137 92 6 152 99 6 152 99 6 152 99 6
42481-138 86 6 124 80 6 98 70 6 86 66 30
42482-101 98 89 82 82 82 58 58 58 46 46 46
42483- 38 38 38 34 34 34 34 34 34 34 34 34
42484- 34 34 34 34 34 34 34 34 34 34 34 34
42485- 34 34 34 34 34 34 38 38 38 42 42 42
42486- 54 54 54 82 82 82 94 86 76 91 60 6
42487-134 86 6 156 107 11 167 114 7 175 118 6
42488-175 118 6 167 114 7 152 99 6 121 87 25
42489-101 98 89 62 62 62 34 34 34 18 18 18
42490- 6 6 6 0 0 0 0 0 0 0 0 0
42491- 0 0 0 0 0 0 0 0 0 0 0 0
42492- 0 0 0 0 0 0 0 0 0 0 0 0
42493- 0 0 0 0 0 0 0 0 0 0 0 0
42494- 0 0 0 0 0 0 0 0 0 0 0 0
42495- 0 0 0 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 6 6 6 6 6 6 10 10 10
42498- 18 18 18 22 22 22 30 30 30 42 42 42
42499- 50 50 50 66 66 66 86 86 86 101 98 89
42500-106 86 58 98 70 6 104 69 6 104 69 6
42501-104 69 6 91 60 6 82 62 34 90 90 90
42502- 62 62 62 38 38 38 22 22 22 14 14 14
42503- 10 10 10 10 10 10 10 10 10 10 10 10
42504- 10 10 10 10 10 10 6 6 6 10 10 10
42505- 10 10 10 10 10 10 10 10 10 14 14 14
42506- 22 22 22 42 42 42 70 70 70 89 81 66
42507- 80 54 7 104 69 6 124 80 6 137 92 6
42508-134 86 6 116 81 8 100 82 52 86 86 86
42509- 58 58 58 30 30 30 14 14 14 6 6 6
42510- 0 0 0 0 0 0 0 0 0 0 0 0
42511- 0 0 0 0 0 0 0 0 0 0 0 0
42512- 0 0 0 0 0 0 0 0 0 0 0 0
42513- 0 0 0 0 0 0 0 0 0 0 0 0
42514- 0 0 0 0 0 0 0 0 0 0 0 0
42515- 0 0 0 0 0 0 0 0 0 0 0 0
42516- 0 0 0 0 0 0 0 0 0 0 0 0
42517- 0 0 0 0 0 0 0 0 0 0 0 0
42518- 0 0 0 6 6 6 10 10 10 14 14 14
42519- 18 18 18 26 26 26 38 38 38 54 54 54
42520- 70 70 70 86 86 86 94 86 76 89 81 66
42521- 89 81 66 86 86 86 74 74 74 50 50 50
42522- 30 30 30 14 14 14 6 6 6 0 0 0
42523- 0 0 0 0 0 0 0 0 0 0 0 0
42524- 0 0 0 0 0 0 0 0 0 0 0 0
42525- 0 0 0 0 0 0 0 0 0 0 0 0
42526- 6 6 6 18 18 18 34 34 34 58 58 58
42527- 82 82 82 89 81 66 89 81 66 89 81 66
42528- 94 86 66 94 86 76 74 74 74 50 50 50
42529- 26 26 26 14 14 14 6 6 6 0 0 0
42530- 0 0 0 0 0 0 0 0 0 0 0 0
42531- 0 0 0 0 0 0 0 0 0 0 0 0
42532- 0 0 0 0 0 0 0 0 0 0 0 0
42533- 0 0 0 0 0 0 0 0 0 0 0 0
42534- 0 0 0 0 0 0 0 0 0 0 0 0
42535- 0 0 0 0 0 0 0 0 0 0 0 0
42536- 0 0 0 0 0 0 0 0 0 0 0 0
42537- 0 0 0 0 0 0 0 0 0 0 0 0
42538- 0 0 0 0 0 0 0 0 0 0 0 0
42539- 6 6 6 6 6 6 14 14 14 18 18 18
42540- 30 30 30 38 38 38 46 46 46 54 54 54
42541- 50 50 50 42 42 42 30 30 30 18 18 18
42542- 10 10 10 0 0 0 0 0 0 0 0 0
42543- 0 0 0 0 0 0 0 0 0 0 0 0
42544- 0 0 0 0 0 0 0 0 0 0 0 0
42545- 0 0 0 0 0 0 0 0 0 0 0 0
42546- 0 0 0 6 6 6 14 14 14 26 26 26
42547- 38 38 38 50 50 50 58 58 58 58 58 58
42548- 54 54 54 42 42 42 30 30 30 18 18 18
42549- 10 10 10 0 0 0 0 0 0 0 0 0
42550- 0 0 0 0 0 0 0 0 0 0 0 0
42551- 0 0 0 0 0 0 0 0 0 0 0 0
42552- 0 0 0 0 0 0 0 0 0 0 0 0
42553- 0 0 0 0 0 0 0 0 0 0 0 0
42554- 0 0 0 0 0 0 0 0 0 0 0 0
42555- 0 0 0 0 0 0 0 0 0 0 0 0
42556- 0 0 0 0 0 0 0 0 0 0 0 0
42557- 0 0 0 0 0 0 0 0 0 0 0 0
42558- 0 0 0 0 0 0 0 0 0 0 0 0
42559- 0 0 0 0 0 0 0 0 0 6 6 6
42560- 6 6 6 10 10 10 14 14 14 18 18 18
42561- 18 18 18 14 14 14 10 10 10 6 6 6
42562- 0 0 0 0 0 0 0 0 0 0 0 0
42563- 0 0 0 0 0 0 0 0 0 0 0 0
42564- 0 0 0 0 0 0 0 0 0 0 0 0
42565- 0 0 0 0 0 0 0 0 0 0 0 0
42566- 0 0 0 0 0 0 0 0 0 6 6 6
42567- 14 14 14 18 18 18 22 22 22 22 22 22
42568- 18 18 18 14 14 14 10 10 10 6 6 6
42569- 0 0 0 0 0 0 0 0 0 0 0 0
42570- 0 0 0 0 0 0 0 0 0 0 0 0
42571- 0 0 0 0 0 0 0 0 0 0 0 0
42572- 0 0 0 0 0 0 0 0 0 0 0 0
42573- 0 0 0 0 0 0 0 0 0 0 0 0
42574+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42575+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42576+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42577+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42578+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42579+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42580+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42581+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42582+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42583+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42584+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42585+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42586+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42587+4 4 4 4 4 4
42588+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42589+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42590+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42591+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42592+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42593+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42594+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42595+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42596+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42597+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42598+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42599+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42600+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42601+4 4 4 4 4 4
42602+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42603+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42604+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42605+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42606+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42607+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42608+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42609+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42610+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42611+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42612+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42613+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42614+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42615+4 4 4 4 4 4
42616+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42617+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42618+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42619+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42620+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42621+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42622+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42623+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42624+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42625+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42626+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42627+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42628+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42629+4 4 4 4 4 4
42630+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42631+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42632+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42633+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42634+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42635+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42636+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42637+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42638+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42639+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42640+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42641+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42642+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42643+4 4 4 4 4 4
42644+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42645+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42646+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42647+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42648+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42649+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42650+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42651+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42652+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42653+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42654+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42655+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42656+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42657+4 4 4 4 4 4
42658+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42659+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42660+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42661+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42662+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
42663+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
42664+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42665+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42666+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42667+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
42668+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
42669+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
42670+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42671+4 4 4 4 4 4
42672+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42673+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42674+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42675+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42676+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
42677+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
42678+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42679+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42680+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42681+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
42682+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
42683+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
42684+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42685+4 4 4 4 4 4
42686+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42687+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42688+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42689+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42690+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
42691+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
42692+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
42693+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42694+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42695+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
42696+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
42697+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
42698+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
42699+4 4 4 4 4 4
42700+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42701+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42702+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42703+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
42704+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
42705+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
42706+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
42707+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42708+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
42709+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
42710+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
42711+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
42712+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
42713+4 4 4 4 4 4
42714+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42715+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42716+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42717+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
42718+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
42719+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
42720+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
42721+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42722+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
42723+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
42724+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
42725+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
42726+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
42727+4 4 4 4 4 4
42728+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42729+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42730+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
42731+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
42732+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
42733+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
42734+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
42735+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
42736+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
42737+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
42738+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
42739+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
42740+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
42741+4 4 4 4 4 4
42742+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42743+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42744+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
42745+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
42746+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
42747+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
42748+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
42749+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
42750+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
42751+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
42752+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
42753+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
42754+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
42755+4 4 4 4 4 4
42756+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42757+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42758+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
42759+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
42760+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
42761+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
42762+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
42763+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
42764+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
42765+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
42766+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
42767+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
42768+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
42769+4 4 4 4 4 4
42770+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42771+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42772+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
42773+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
42774+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
42775+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
42776+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
42777+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
42778+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
42779+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
42780+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
42781+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
42782+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
42783+4 4 4 4 4 4
42784+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42785+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42786+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
42787+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
42788+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
42789+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
42790+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
42791+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
42792+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
42793+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
42794+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
42795+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
42796+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
42797+4 4 4 4 4 4
42798+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42799+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
42800+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
42801+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
42802+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
42803+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
42804+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
42805+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
42806+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
42807+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
42808+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
42809+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
42810+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
42811+4 4 4 4 4 4
42812+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42813+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
42814+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
42815+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
42816+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
42817+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
42818+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
42819+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
42820+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
42821+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
42822+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
42823+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
42824+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
42825+0 0 0 4 4 4
42826+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
42827+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
42828+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
42829+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
42830+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
42831+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
42832+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
42833+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
42834+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
42835+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
42836+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
42837+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
42838+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
42839+2 0 0 0 0 0
42840+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
42841+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
42842+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
42843+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
42844+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
42845+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
42846+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
42847+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
42848+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
42849+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
42850+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
42851+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
42852+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
42853+37 38 37 0 0 0
42854+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
42855+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
42856+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
42857+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
42858+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
42859+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
42860+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
42861+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
42862+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
42863+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
42864+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
42865+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
42866+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
42867+85 115 134 4 0 0
42868+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
42869+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
42870+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
42871+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
42872+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
42873+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
42874+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
42875+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
42876+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
42877+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
42878+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
42879+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
42880+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
42881+60 73 81 4 0 0
42882+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
42883+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
42884+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
42885+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
42886+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
42887+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
42888+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
42889+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
42890+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
42891+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
42892+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
42893+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
42894+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
42895+16 19 21 4 0 0
42896+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
42897+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
42898+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
42899+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
42900+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
42901+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
42902+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
42903+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
42904+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
42905+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
42906+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
42907+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
42908+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
42909+4 0 0 4 3 3
42910+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
42911+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
42912+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
42913+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
42914+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
42915+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
42916+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
42917+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
42918+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
42919+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
42920+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
42921+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
42922+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
42923+3 2 2 4 4 4
42924+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
42925+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
42926+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
42927+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
42928+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
42929+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
42930+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
42931+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
42932+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
42933+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
42934+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
42935+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
42936+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
42937+4 4 4 4 4 4
42938+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
42939+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
42940+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
42941+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
42942+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
42943+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
42944+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
42945+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
42946+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
42947+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
42948+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
42949+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
42950+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
42951+4 4 4 4 4 4
42952+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
42953+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
42954+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
42955+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
42956+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
42957+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
42958+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
42959+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
42960+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
42961+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
42962+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
42963+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
42964+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
42965+5 5 5 5 5 5
42966+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
42967+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
42968+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
42969+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
42970+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
42971+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
42972+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
42973+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
42974+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
42975+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
42976+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
42977+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
42978+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
42979+5 5 5 4 4 4
42980+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
42981+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
42982+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
42983+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
42984+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
42985+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
42986+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
42987+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
42988+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
42989+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
42990+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
42991+4 0 0 4 0 0 5 5 5 5 5 5 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
42994+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
42995+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
42996+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
42997+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
42998+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
42999+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
43000+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
43001+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
43002+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
43003+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
43004+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
43005+3 3 3 5 5 5 6 6 6 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
43008+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
43009+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
43010+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
43011+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
43012+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
43013+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
43014+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
43015+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
43016+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
43017+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
43018+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 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
43022+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
43023+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
43024+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
43025+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
43026+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
43027+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
43028+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
43029+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
43030+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
43031+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
43032+6 6 6 4 0 0 4 0 0 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
43036+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
43037+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
43038+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
43039+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
43040+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
43041+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
43042+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
43043+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
43044+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
43045+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
43046+4 0 0 4 3 3 5 5 5 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
43050+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
43051+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
43052+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
43053+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
43054+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
43055+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
43056+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
43057+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
43058+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
43059+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
43060+6 6 6 4 0 0 6 6 6 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
43064+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
43065+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
43066+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
43067+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
43068+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
43069+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
43070+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
43071+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
43072+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
43073+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
43074+4 0 0 3 2 2 5 5 5 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
43078+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
43079+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
43080+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
43081+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
43082+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
43083+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
43084+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
43085+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
43086+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
43087+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
43088+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 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 4 4 4 4 4 4
43091+4 4 4 4 4 4
43092+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
43093+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
43094+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
43095+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
43096+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
43097+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
43098+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
43099+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
43100+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
43101+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
43102+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43103+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43104+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43105+4 4 4 4 4 4
43106+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
43107+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
43108+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
43109+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
43110+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
43111+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
43112+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
43113+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
43114+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
43115+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
43116+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43117+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43118+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43119+4 4 4 4 4 4
43120+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
43121+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
43122+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
43123+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
43124+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
43125+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
43126+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
43127+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
43128+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
43129+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43130+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43131+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43132+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43133+4 4 4 4 4 4
43134+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
43135+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
43136+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
43137+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
43138+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
43139+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
43140+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
43141+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
43142+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
43143+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43144+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43145+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43146+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43147+4 4 4 4 4 4
43148+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
43149+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
43150+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
43151+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
43152+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
43153+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
43154+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
43155+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
43156+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
43157+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43158+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43159+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43160+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43161+4 4 4 4 4 4
43162+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
43163+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
43164+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
43165+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
43166+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
43167+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
43168+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
43169+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
43170+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
43171+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43172+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43173+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43174+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43175+4 4 4 4 4 4
43176+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
43177+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
43178+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
43179+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
43180+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
43181+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
43182+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
43183+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
43184+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
43185+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43186+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43187+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43188+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43189+4 4 4 4 4 4
43190+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
43191+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
43192+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
43193+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
43194+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
43195+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
43196+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
43197+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
43198+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
43199+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43200+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43201+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43202+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43203+4 4 4 4 4 4
43204+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
43205+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
43206+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
43207+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
43208+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
43209+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
43210+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
43211+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
43212+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
43213+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43214+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43215+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43216+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43217+4 4 4 4 4 4
43218+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
43219+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
43220+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
43221+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
43222+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
43223+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
43224+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
43225+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
43226+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
43227+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43228+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43229+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43230+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43231+4 4 4 4 4 4
43232+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
43233+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
43234+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
43235+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
43236+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
43237+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
43238+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
43239+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
43240+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
43241+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43242+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43243+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43244+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43245+4 4 4 4 4 4
43246+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
43247+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
43248+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
43249+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
43250+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
43251+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
43252+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
43253+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
43254+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
43255+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43256+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43257+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43258+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43259+4 4 4 4 4 4
43260+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
43261+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
43262+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
43263+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
43264+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
43265+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
43266+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
43267+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
43268+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
43269+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43270+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43271+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43272+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43273+4 4 4 4 4 4
43274+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
43275+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
43276+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
43277+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
43278+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
43279+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
43280+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
43281+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
43282+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
43283+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43284+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43285+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43286+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43287+4 4 4 4 4 4
43288+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
43289+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
43290+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
43291+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
43292+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
43293+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
43294+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
43295+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
43296+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
43297+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43298+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43299+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43300+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43301+4 4 4 4 4 4
43302+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
43303+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
43304+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
43305+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
43306+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
43307+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
43308+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
43309+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
43310+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
43311+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43312+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43313+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43314+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43315+4 4 4 4 4 4
43316+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
43317+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
43318+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
43319+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
43320+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
43321+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
43322+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
43323+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
43324+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
43325+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43326+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43327+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43328+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43329+4 4 4 4 4 4
43330+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
43331+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
43332+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
43333+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
43334+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
43335+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
43336+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
43337+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
43338+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
43339+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
43340+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43341+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43342+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43343+4 4 4 4 4 4
43344+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
43345+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
43346+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
43347+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
43348+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
43349+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
43350+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
43351+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
43352+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
43353+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
43354+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43355+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43356+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43357+4 4 4 4 4 4
43358+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
43359+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
43360+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
43361+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
43362+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
43363+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
43364+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43365+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
43366+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
43367+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
43368+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
43369+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43370+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43371+4 4 4 4 4 4
43372+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
43373+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
43374+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
43375+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
43376+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
43377+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
43378+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
43379+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
43380+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
43381+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
43382+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43383+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43384+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43385+4 4 4 4 4 4
43386+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
43387+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
43388+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
43389+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
43390+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
43391+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
43392+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
43393+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
43394+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
43395+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
43396+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43397+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43398+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43399+4 4 4 4 4 4
43400+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
43401+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
43402+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
43403+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
43404+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
43405+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
43406+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
43407+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
43408+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
43409+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
43410+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43411+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43412+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43413+4 4 4 4 4 4
43414+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
43415+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
43416+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
43417+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
43418+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
43419+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
43420+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
43421+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
43422+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
43423+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
43424+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43425+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43426+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43427+4 4 4 4 4 4
43428+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
43429+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
43430+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
43431+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
43432+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
43433+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
43434+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
43435+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
43436+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
43437+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
43438+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43439+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43440+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43441+4 4 4 4 4 4
43442+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
43443+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
43444+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
43445+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
43446+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
43447+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
43448+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
43449+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
43450+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
43451+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43452+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43453+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43454+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43455+4 4 4 4 4 4
43456+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
43457+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
43458+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
43459+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
43460+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
43461+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
43462+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
43463+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
43464+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
43465+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43466+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43467+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43468+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43469+4 4 4 4 4 4
43470+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
43471+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
43472+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
43473+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
43474+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
43475+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
43476+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
43477+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
43478+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43479+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43480+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43481+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43482+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43483+4 4 4 4 4 4
43484+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
43485+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
43486+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
43487+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
43488+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
43489+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
43490+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
43491+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
43492+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43493+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43494+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43495+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43496+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43497+4 4 4 4 4 4
43498+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
43499+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
43500+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
43501+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
43502+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
43503+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
43504+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
43505+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
43506+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43507+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43508+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43509+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43510+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43511+4 4 4 4 4 4
43512+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
43513+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
43514+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
43515+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
43516+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
43517+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
43518+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
43519+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
43520+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43521+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43522+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43523+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43524+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43525+4 4 4 4 4 4
43526+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43527+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
43528+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
43529+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
43530+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
43531+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
43532+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
43533+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
43534+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43535+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43536+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43537+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43538+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43539+4 4 4 4 4 4
43540+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43541+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
43542+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
43543+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
43544+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
43545+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
43546+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
43547+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
43548+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43549+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43550+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43551+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43552+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43553+4 4 4 4 4 4
43554+4 4 4 4 4 4 4 4 4 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 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
43557+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
43558+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
43559+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
43560+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
43561+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
43562+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43563+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43564+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43565+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43566+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43567+4 4 4 4 4 4
43568+4 4 4 4 4 4 4 4 4 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 5 5 5
43571+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
43572+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
43573+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
43574+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
43575+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43576+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43577+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43578+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43579+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43580+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43581+4 4 4 4 4 4
43582+4 4 4 4 4 4 4 4 4 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 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
43586+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
43587+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
43588+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
43589+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43590+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43591+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43592+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43593+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43594+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43595+4 4 4 4 4 4
43596+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43597+4 4 4 4 4 4 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 5 5 5 4 3 3 5 5 5 6 6 6
43600+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
43601+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
43602+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
43603+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43604+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43605+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43606+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43607+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43608+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43609+4 4 4 4 4 4
43610+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43611+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43612+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43613+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
43614+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
43615+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
43616+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
43617+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43618+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43619+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43620+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43621+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43622+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43623+4 4 4 4 4 4
43624+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43625+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43626+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43627+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
43628+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
43629+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
43630+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43631+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43632+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43633+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43634+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43635+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43636+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43637+4 4 4 4 4 4
43638+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43639+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43640+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43641+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43642+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
43643+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
43644+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
43645+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43646+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43647+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43648+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43649+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43650+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43651+4 4 4 4 4 4
43652+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43653+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43654+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43655+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43656+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
43657+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
43658+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43659+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43660+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43661+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43662+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43663+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43664+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43665+4 4 4 4 4 4
43666+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43667+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43668+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43669+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43670+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
43671+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
43672+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43673+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43674+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43675+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43676+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43677+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43678+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43679+4 4 4 4 4 4
43680+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43681+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43682+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43683+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43684+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
43685+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
43686+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43687+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43688+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43689+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43690+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43691+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43692+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43693+4 4 4 4 4 4
43694diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
43695index 86d449e..af6a7f7 100644
43696--- a/drivers/video/udlfb.c
43697+++ b/drivers/video/udlfb.c
43698@@ -619,11 +619,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
43699 dlfb_urb_completion(urb);
43700
43701 error:
43702- atomic_add(bytes_sent, &dev->bytes_sent);
43703- atomic_add(bytes_identical, &dev->bytes_identical);
43704- atomic_add(width*height*2, &dev->bytes_rendered);
43705+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
43706+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
43707+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
43708 end_cycles = get_cycles();
43709- atomic_add(((unsigned int) ((end_cycles - start_cycles)
43710+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
43711 >> 10)), /* Kcycles */
43712 &dev->cpu_kcycles_used);
43713
43714@@ -744,11 +744,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
43715 dlfb_urb_completion(urb);
43716
43717 error:
43718- atomic_add(bytes_sent, &dev->bytes_sent);
43719- atomic_add(bytes_identical, &dev->bytes_identical);
43720- atomic_add(bytes_rendered, &dev->bytes_rendered);
43721+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
43722+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
43723+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
43724 end_cycles = get_cycles();
43725- atomic_add(((unsigned int) ((end_cycles - start_cycles)
43726+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
43727 >> 10)), /* Kcycles */
43728 &dev->cpu_kcycles_used);
43729 }
43730@@ -1372,7 +1372,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
43731 struct fb_info *fb_info = dev_get_drvdata(fbdev);
43732 struct dlfb_data *dev = fb_info->par;
43733 return snprintf(buf, PAGE_SIZE, "%u\n",
43734- atomic_read(&dev->bytes_rendered));
43735+ atomic_read_unchecked(&dev->bytes_rendered));
43736 }
43737
43738 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
43739@@ -1380,7 +1380,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
43740 struct fb_info *fb_info = dev_get_drvdata(fbdev);
43741 struct dlfb_data *dev = fb_info->par;
43742 return snprintf(buf, PAGE_SIZE, "%u\n",
43743- atomic_read(&dev->bytes_identical));
43744+ atomic_read_unchecked(&dev->bytes_identical));
43745 }
43746
43747 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
43748@@ -1388,7 +1388,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
43749 struct fb_info *fb_info = dev_get_drvdata(fbdev);
43750 struct dlfb_data *dev = fb_info->par;
43751 return snprintf(buf, PAGE_SIZE, "%u\n",
43752- atomic_read(&dev->bytes_sent));
43753+ atomic_read_unchecked(&dev->bytes_sent));
43754 }
43755
43756 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
43757@@ -1396,7 +1396,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
43758 struct fb_info *fb_info = dev_get_drvdata(fbdev);
43759 struct dlfb_data *dev = fb_info->par;
43760 return snprintf(buf, PAGE_SIZE, "%u\n",
43761- atomic_read(&dev->cpu_kcycles_used));
43762+ atomic_read_unchecked(&dev->cpu_kcycles_used));
43763 }
43764
43765 static ssize_t edid_show(
43766@@ -1456,10 +1456,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
43767 struct fb_info *fb_info = dev_get_drvdata(fbdev);
43768 struct dlfb_data *dev = fb_info->par;
43769
43770- atomic_set(&dev->bytes_rendered, 0);
43771- atomic_set(&dev->bytes_identical, 0);
43772- atomic_set(&dev->bytes_sent, 0);
43773- atomic_set(&dev->cpu_kcycles_used, 0);
43774+ atomic_set_unchecked(&dev->bytes_rendered, 0);
43775+ atomic_set_unchecked(&dev->bytes_identical, 0);
43776+ atomic_set_unchecked(&dev->bytes_sent, 0);
43777+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
43778
43779 return count;
43780 }
43781diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
43782index 2f8f82d..191de37 100644
43783--- a/drivers/video/uvesafb.c
43784+++ b/drivers/video/uvesafb.c
43785@@ -19,6 +19,7 @@
43786 #include <linux/io.h>
43787 #include <linux/mutex.h>
43788 #include <linux/slab.h>
43789+#include <linux/moduleloader.h>
43790 #include <video/edid.h>
43791 #include <video/uvesafb.h>
43792 #ifdef CONFIG_X86
43793@@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
43794 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
43795 par->pmi_setpal = par->ypan = 0;
43796 } else {
43797+
43798+#ifdef CONFIG_PAX_KERNEXEC
43799+#ifdef CONFIG_MODULES
43800+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
43801+#endif
43802+ if (!par->pmi_code) {
43803+ par->pmi_setpal = par->ypan = 0;
43804+ return 0;
43805+ }
43806+#endif
43807+
43808 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
43809 + task->t.regs.edi);
43810+
43811+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
43812+ pax_open_kernel();
43813+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
43814+ pax_close_kernel();
43815+
43816+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
43817+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
43818+#else
43819 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
43820 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
43821+#endif
43822+
43823 printk(KERN_INFO "uvesafb: protected mode interface info at "
43824 "%04x:%04x\n",
43825 (u16)task->t.regs.es, (u16)task->t.regs.edi);
43826@@ -818,13 +841,14 @@ static int __devinit uvesafb_vbe_init(struct fb_info *info)
43827 par->ypan = ypan;
43828
43829 if (par->pmi_setpal || par->ypan) {
43830+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
43831 if (__supported_pte_mask & _PAGE_NX) {
43832 par->pmi_setpal = par->ypan = 0;
43833 printk(KERN_WARNING "uvesafb: NX protection is actively."
43834 "We have better not to use the PMI.\n");
43835- } else {
43836+ } else
43837+#endif
43838 uvesafb_vbe_getpmi(task, par);
43839- }
43840 }
43841 #else
43842 /* The protected mode interface is not available on non-x86. */
43843@@ -1838,6 +1862,11 @@ out:
43844 if (par->vbe_modes)
43845 kfree(par->vbe_modes);
43846
43847+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
43848+ if (par->pmi_code)
43849+ module_free_exec(NULL, par->pmi_code);
43850+#endif
43851+
43852 framebuffer_release(info);
43853 return err;
43854 }
43855@@ -1864,6 +1893,12 @@ static int uvesafb_remove(struct platform_device *dev)
43856 kfree(par->vbe_state_orig);
43857 if (par->vbe_state_saved)
43858 kfree(par->vbe_state_saved);
43859+
43860+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
43861+ if (par->pmi_code)
43862+ module_free_exec(NULL, par->pmi_code);
43863+#endif
43864+
43865 }
43866
43867 framebuffer_release(info);
43868diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
43869index 501b340..86bd4cf 100644
43870--- a/drivers/video/vesafb.c
43871+++ b/drivers/video/vesafb.c
43872@@ -9,6 +9,7 @@
43873 */
43874
43875 #include <linux/module.h>
43876+#include <linux/moduleloader.h>
43877 #include <linux/kernel.h>
43878 #include <linux/errno.h>
43879 #include <linux/string.h>
43880@@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
43881 static int vram_total __initdata; /* Set total amount of memory */
43882 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
43883 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
43884-static void (*pmi_start)(void) __read_mostly;
43885-static void (*pmi_pal) (void) __read_mostly;
43886+static void (*pmi_start)(void) __read_only;
43887+static void (*pmi_pal) (void) __read_only;
43888 static int depth __read_mostly;
43889 static int vga_compat __read_mostly;
43890 /* --------------------------------------------------------------------- */
43891@@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
43892 unsigned int size_vmode;
43893 unsigned int size_remap;
43894 unsigned int size_total;
43895+ void *pmi_code = NULL;
43896
43897 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
43898 return -ENODEV;
43899@@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
43900 size_remap = size_total;
43901 vesafb_fix.smem_len = size_remap;
43902
43903-#ifndef __i386__
43904- screen_info.vesapm_seg = 0;
43905-#endif
43906-
43907 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
43908 printk(KERN_WARNING
43909 "vesafb: cannot reserve video memory at 0x%lx\n",
43910@@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
43911 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
43912 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
43913
43914+#ifdef __i386__
43915+
43916+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
43917+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
43918+ if (!pmi_code)
43919+#elif !defined(CONFIG_PAX_KERNEXEC)
43920+ if (0)
43921+#endif
43922+
43923+#endif
43924+ screen_info.vesapm_seg = 0;
43925+
43926 if (screen_info.vesapm_seg) {
43927- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
43928- screen_info.vesapm_seg,screen_info.vesapm_off);
43929+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
43930+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
43931 }
43932
43933 if (screen_info.vesapm_seg < 0xc000)
43934@@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
43935
43936 if (ypan || pmi_setpal) {
43937 unsigned short *pmi_base;
43938+
43939 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
43940- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
43941- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
43942+
43943+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
43944+ pax_open_kernel();
43945+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
43946+#else
43947+ pmi_code = pmi_base;
43948+#endif
43949+
43950+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
43951+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
43952+
43953+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
43954+ pmi_start = ktva_ktla(pmi_start);
43955+ pmi_pal = ktva_ktla(pmi_pal);
43956+ pax_close_kernel();
43957+#endif
43958+
43959 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
43960 if (pmi_base[3]) {
43961 printk(KERN_INFO "vesafb: pmi: ports = ");
43962@@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
43963 info->node, info->fix.id);
43964 return 0;
43965 err:
43966+
43967+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
43968+ module_free_exec(NULL, pmi_code);
43969+#endif
43970+
43971 if (info->screen_base)
43972 iounmap(info->screen_base);
43973 framebuffer_release(info);
43974diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
43975index 88714ae..16c2e11 100644
43976--- a/drivers/video/via/via_clock.h
43977+++ b/drivers/video/via/via_clock.h
43978@@ -56,7 +56,7 @@ struct via_clock {
43979
43980 void (*set_engine_pll_state)(u8 state);
43981 void (*set_engine_pll)(struct via_pll_config config);
43982-};
43983+} __no_const;
43984
43985
43986 static inline u32 get_pll_internal_frequency(u32 ref_freq,
43987diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
43988index 6b1b7e1..b2fa4d5 100644
43989--- a/drivers/virtio/virtio_mmio.c
43990+++ b/drivers/virtio/virtio_mmio.c
43991@@ -530,7 +530,7 @@ static int vm_cmdline_set(const char *device,
43992
43993 resources[0].end = memparse(device, &str) - 1;
43994
43995- processed = sscanf(str, "@%lli:%u%n:%d%n",
43996+ processed = sscanf(str, "@%lli:%llu%n:%d%n",
43997 &base, &resources[1].start, &consumed,
43998 &vm_cmdline_id, &consumed);
43999
44000diff --git a/drivers/xen/xen-pciback/conf_space.h b/drivers/xen/xen-pciback/conf_space.h
44001index e56c934..fc22f4b 100644
44002--- a/drivers/xen/xen-pciback/conf_space.h
44003+++ b/drivers/xen/xen-pciback/conf_space.h
44004@@ -44,15 +44,15 @@ struct config_field {
44005 struct {
44006 conf_dword_write write;
44007 conf_dword_read read;
44008- } dw;
44009+ } __no_const dw;
44010 struct {
44011 conf_word_write write;
44012 conf_word_read read;
44013- } w;
44014+ } __no_const w;
44015 struct {
44016 conf_byte_write write;
44017 conf_byte_read read;
44018- } b;
44019+ } __no_const b;
44020 } u;
44021 struct list_head list;
44022 };
44023diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
44024index fef20db..d28b1ab 100644
44025--- a/drivers/xen/xenfs/xenstored.c
44026+++ b/drivers/xen/xenfs/xenstored.c
44027@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
44028 static int xsd_kva_open(struct inode *inode, struct file *file)
44029 {
44030 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
44031+#ifdef CONFIG_GRKERNSEC_HIDESYM
44032+ NULL);
44033+#else
44034 xen_store_interface);
44035+#endif
44036+
44037 if (!file->private_data)
44038 return -ENOMEM;
44039 return 0;
44040diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
44041index 890bed5..17ae73e 100644
44042--- a/fs/9p/vfs_inode.c
44043+++ b/fs/9p/vfs_inode.c
44044@@ -1329,7 +1329,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
44045 void
44046 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
44047 {
44048- char *s = nd_get_link(nd);
44049+ const char *s = nd_get_link(nd);
44050
44051 p9_debug(P9_DEBUG_VFS, " %s %s\n",
44052 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
44053diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
44054index 0efd152..b5802ad 100644
44055--- a/fs/Kconfig.binfmt
44056+++ b/fs/Kconfig.binfmt
44057@@ -89,7 +89,7 @@ config HAVE_AOUT
44058
44059 config BINFMT_AOUT
44060 tristate "Kernel support for a.out and ECOFF binaries"
44061- depends on HAVE_AOUT
44062+ depends on HAVE_AOUT && BROKEN
44063 ---help---
44064 A.out (Assembler.OUTput) is a set of formats for libraries and
44065 executables used in the earliest versions of UNIX. Linux used
44066diff --git a/fs/aio.c b/fs/aio.c
44067index 71f613c..9d01f1f 100644
44068--- a/fs/aio.c
44069+++ b/fs/aio.c
44070@@ -111,7 +111,7 @@ static int aio_setup_ring(struct kioctx *ctx)
44071 size += sizeof(struct io_event) * nr_events;
44072 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
44073
44074- if (nr_pages < 0)
44075+ if (nr_pages <= 0)
44076 return -EINVAL;
44077
44078 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
44079@@ -1373,18 +1373,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
44080 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
44081 {
44082 ssize_t ret;
44083+ struct iovec iovstack;
44084
44085 #ifdef CONFIG_COMPAT
44086 if (compat)
44087 ret = compat_rw_copy_check_uvector(type,
44088 (struct compat_iovec __user *)kiocb->ki_buf,
44089- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
44090+ kiocb->ki_nbytes, 1, &iovstack,
44091 &kiocb->ki_iovec);
44092 else
44093 #endif
44094 ret = rw_copy_check_uvector(type,
44095 (struct iovec __user *)kiocb->ki_buf,
44096- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
44097+ kiocb->ki_nbytes, 1, &iovstack,
44098 &kiocb->ki_iovec);
44099 if (ret < 0)
44100 goto out;
44101@@ -1393,6 +1394,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
44102 if (ret < 0)
44103 goto out;
44104
44105+ if (kiocb->ki_iovec == &iovstack) {
44106+ kiocb->ki_inline_vec = iovstack;
44107+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
44108+ }
44109 kiocb->ki_nr_segs = kiocb->ki_nbytes;
44110 kiocb->ki_cur_seg = 0;
44111 /* ki_nbytes/left now reflect bytes instead of segs */
44112diff --git a/fs/attr.c b/fs/attr.c
44113index cce7df5..eaa2731 100644
44114--- a/fs/attr.c
44115+++ b/fs/attr.c
44116@@ -100,6 +100,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
44117 unsigned long limit;
44118
44119 limit = rlimit(RLIMIT_FSIZE);
44120+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
44121 if (limit != RLIM_INFINITY && offset > limit)
44122 goto out_sig;
44123 if (offset > inode->i_sb->s_maxbytes)
44124diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
44125index dce436e..55e670d 100644
44126--- a/fs/autofs4/waitq.c
44127+++ b/fs/autofs4/waitq.c
44128@@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
44129 {
44130 unsigned long sigpipe, flags;
44131 mm_segment_t fs;
44132- const char *data = (const char *)addr;
44133+ const char __user *data = (const char __force_user *)addr;
44134 ssize_t wr = 0;
44135
44136 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
44137@@ -347,6 +347,10 @@ static int validate_request(struct autofs_wait_queue **wait,
44138 return 1;
44139 }
44140
44141+#ifdef CONFIG_GRKERNSEC_HIDESYM
44142+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
44143+#endif
44144+
44145 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
44146 enum autofs_notify notify)
44147 {
44148@@ -380,7 +384,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
44149
44150 /* If this is a direct mount request create a dummy name */
44151 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
44152+#ifdef CONFIG_GRKERNSEC_HIDESYM
44153+ /* this name does get written to userland via autofs4_write() */
44154+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
44155+#else
44156 qstr.len = sprintf(name, "%p", dentry);
44157+#endif
44158 else {
44159 qstr.len = autofs4_getpath(sbi, dentry, &name);
44160 if (!qstr.len) {
44161diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
44162index 2b3bda8..6a2d4be 100644
44163--- a/fs/befs/linuxvfs.c
44164+++ b/fs/befs/linuxvfs.c
44165@@ -510,7 +510,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
44166 {
44167 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
44168 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
44169- char *link = nd_get_link(nd);
44170+ const char *link = nd_get_link(nd);
44171 if (!IS_ERR(link))
44172 kfree(link);
44173 }
44174diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
44175index 0e7a6f8..332b1ca 100644
44176--- a/fs/binfmt_aout.c
44177+++ b/fs/binfmt_aout.c
44178@@ -16,6 +16,7 @@
44179 #include <linux/string.h>
44180 #include <linux/fs.h>
44181 #include <linux/file.h>
44182+#include <linux/security.h>
44183 #include <linux/stat.h>
44184 #include <linux/fcntl.h>
44185 #include <linux/ptrace.h>
44186@@ -59,6 +60,8 @@ static int aout_core_dump(struct coredump_params *cprm)
44187 #endif
44188 # define START_STACK(u) ((void __user *)u.start_stack)
44189
44190+ memset(&dump, 0, sizeof(dump));
44191+
44192 fs = get_fs();
44193 set_fs(KERNEL_DS);
44194 has_dumped = 1;
44195@@ -70,10 +73,12 @@ static int aout_core_dump(struct coredump_params *cprm)
44196
44197 /* If the size of the dump file exceeds the rlimit, then see what would happen
44198 if we wrote the stack, but not the data area. */
44199+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
44200 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
44201 dump.u_dsize = 0;
44202
44203 /* Make sure we have enough room to write the stack and data areas. */
44204+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
44205 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
44206 dump.u_ssize = 0;
44207
44208@@ -233,6 +238,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
44209 rlim = rlimit(RLIMIT_DATA);
44210 if (rlim >= RLIM_INFINITY)
44211 rlim = ~0;
44212+
44213+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
44214 if (ex.a_data + ex.a_bss > rlim)
44215 return -ENOMEM;
44216
44217@@ -267,6 +274,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
44218
44219 install_exec_creds(bprm);
44220
44221+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
44222+ current->mm->pax_flags = 0UL;
44223+#endif
44224+
44225+#ifdef CONFIG_PAX_PAGEEXEC
44226+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
44227+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
44228+
44229+#ifdef CONFIG_PAX_EMUTRAMP
44230+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
44231+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
44232+#endif
44233+
44234+#ifdef CONFIG_PAX_MPROTECT
44235+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
44236+ current->mm->pax_flags |= MF_PAX_MPROTECT;
44237+#endif
44238+
44239+ }
44240+#endif
44241+
44242 if (N_MAGIC(ex) == OMAGIC) {
44243 unsigned long text_addr, map_size;
44244 loff_t pos;
44245@@ -332,7 +360,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
44246 }
44247
44248 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
44249- PROT_READ | PROT_WRITE | PROT_EXEC,
44250+ PROT_READ | PROT_WRITE,
44251 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
44252 fd_offset + ex.a_text);
44253 if (error != N_DATADDR(ex)) {
44254diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
44255index fbd9f60..d4edac0 100644
44256--- a/fs/binfmt_elf.c
44257+++ b/fs/binfmt_elf.c
44258@@ -33,6 +33,7 @@
44259 #include <linux/elf.h>
44260 #include <linux/utsname.h>
44261 #include <linux/coredump.h>
44262+#include <linux/xattr.h>
44263 #include <asm/uaccess.h>
44264 #include <asm/param.h>
44265 #include <asm/page.h>
44266@@ -59,6 +60,10 @@ static int elf_core_dump(struct coredump_params *cprm);
44267 #define elf_core_dump NULL
44268 #endif
44269
44270+#ifdef CONFIG_PAX_MPROTECT
44271+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
44272+#endif
44273+
44274 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
44275 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
44276 #else
44277@@ -78,6 +83,11 @@ static struct linux_binfmt elf_format = {
44278 .load_binary = load_elf_binary,
44279 .load_shlib = load_elf_library,
44280 .core_dump = elf_core_dump,
44281+
44282+#ifdef CONFIG_PAX_MPROTECT
44283+ .handle_mprotect= elf_handle_mprotect,
44284+#endif
44285+
44286 .min_coredump = ELF_EXEC_PAGESIZE,
44287 };
44288
44289@@ -85,6 +95,8 @@ static struct linux_binfmt elf_format = {
44290
44291 static int set_brk(unsigned long start, unsigned long end)
44292 {
44293+ unsigned long e = end;
44294+
44295 start = ELF_PAGEALIGN(start);
44296 end = ELF_PAGEALIGN(end);
44297 if (end > start) {
44298@@ -93,7 +105,7 @@ static int set_brk(unsigned long start, unsigned long end)
44299 if (BAD_ADDR(addr))
44300 return addr;
44301 }
44302- current->mm->start_brk = current->mm->brk = end;
44303+ current->mm->start_brk = current->mm->brk = e;
44304 return 0;
44305 }
44306
44307@@ -154,12 +166,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
44308 elf_addr_t __user *u_rand_bytes;
44309 const char *k_platform = ELF_PLATFORM;
44310 const char *k_base_platform = ELF_BASE_PLATFORM;
44311- unsigned char k_rand_bytes[16];
44312+ u32 k_rand_bytes[4];
44313 int items;
44314 elf_addr_t *elf_info;
44315 int ei_index = 0;
44316 const struct cred *cred = current_cred();
44317 struct vm_area_struct *vma;
44318+ unsigned long saved_auxv[AT_VECTOR_SIZE];
44319
44320 /*
44321 * In some cases (e.g. Hyper-Threading), we want to avoid L1
44322@@ -201,8 +214,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
44323 * Generate 16 random bytes for userspace PRNG seeding.
44324 */
44325 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
44326- u_rand_bytes = (elf_addr_t __user *)
44327- STACK_ALLOC(p, sizeof(k_rand_bytes));
44328+ srandom32(k_rand_bytes[0] ^ random32());
44329+ srandom32(k_rand_bytes[1] ^ random32());
44330+ srandom32(k_rand_bytes[2] ^ random32());
44331+ srandom32(k_rand_bytes[3] ^ random32());
44332+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
44333+ u_rand_bytes = (elf_addr_t __user *) p;
44334 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
44335 return -EFAULT;
44336
44337@@ -314,9 +331,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
44338 return -EFAULT;
44339 current->mm->env_end = p;
44340
44341+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
44342+
44343 /* Put the elf_info on the stack in the right place. */
44344 sp = (elf_addr_t __user *)envp + 1;
44345- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
44346+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
44347 return -EFAULT;
44348 return 0;
44349 }
44350@@ -380,15 +399,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
44351 an ELF header */
44352
44353 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
44354- struct file *interpreter, unsigned long *interp_map_addr,
44355- unsigned long no_base)
44356+ struct file *interpreter, unsigned long no_base)
44357 {
44358 struct elf_phdr *elf_phdata;
44359 struct elf_phdr *eppnt;
44360- unsigned long load_addr = 0;
44361+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
44362 int load_addr_set = 0;
44363 unsigned long last_bss = 0, elf_bss = 0;
44364- unsigned long error = ~0UL;
44365+ unsigned long error = -EINVAL;
44366 unsigned long total_size;
44367 int retval, i, size;
44368
44369@@ -434,6 +452,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
44370 goto out_close;
44371 }
44372
44373+#ifdef CONFIG_PAX_SEGMEXEC
44374+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
44375+ pax_task_size = SEGMEXEC_TASK_SIZE;
44376+#endif
44377+
44378 eppnt = elf_phdata;
44379 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
44380 if (eppnt->p_type == PT_LOAD) {
44381@@ -457,8 +480,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
44382 map_addr = elf_map(interpreter, load_addr + vaddr,
44383 eppnt, elf_prot, elf_type, total_size);
44384 total_size = 0;
44385- if (!*interp_map_addr)
44386- *interp_map_addr = map_addr;
44387 error = map_addr;
44388 if (BAD_ADDR(map_addr))
44389 goto out_close;
44390@@ -477,8 +498,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
44391 k = load_addr + eppnt->p_vaddr;
44392 if (BAD_ADDR(k) ||
44393 eppnt->p_filesz > eppnt->p_memsz ||
44394- eppnt->p_memsz > TASK_SIZE ||
44395- TASK_SIZE - eppnt->p_memsz < k) {
44396+ eppnt->p_memsz > pax_task_size ||
44397+ pax_task_size - eppnt->p_memsz < k) {
44398 error = -ENOMEM;
44399 goto out_close;
44400 }
44401@@ -530,6 +551,315 @@ out:
44402 return error;
44403 }
44404
44405+#ifdef CONFIG_PAX_PT_PAX_FLAGS
44406+#ifdef CONFIG_PAX_SOFTMODE
44407+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
44408+{
44409+ unsigned long pax_flags = 0UL;
44410+
44411+#ifdef CONFIG_PAX_PAGEEXEC
44412+ if (elf_phdata->p_flags & PF_PAGEEXEC)
44413+ pax_flags |= MF_PAX_PAGEEXEC;
44414+#endif
44415+
44416+#ifdef CONFIG_PAX_SEGMEXEC
44417+ if (elf_phdata->p_flags & PF_SEGMEXEC)
44418+ pax_flags |= MF_PAX_SEGMEXEC;
44419+#endif
44420+
44421+#ifdef CONFIG_PAX_EMUTRAMP
44422+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
44423+ pax_flags |= MF_PAX_EMUTRAMP;
44424+#endif
44425+
44426+#ifdef CONFIG_PAX_MPROTECT
44427+ if (elf_phdata->p_flags & PF_MPROTECT)
44428+ pax_flags |= MF_PAX_MPROTECT;
44429+#endif
44430+
44431+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
44432+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
44433+ pax_flags |= MF_PAX_RANDMMAP;
44434+#endif
44435+
44436+ return pax_flags;
44437+}
44438+#endif
44439+
44440+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
44441+{
44442+ unsigned long pax_flags = 0UL;
44443+
44444+#ifdef CONFIG_PAX_PAGEEXEC
44445+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
44446+ pax_flags |= MF_PAX_PAGEEXEC;
44447+#endif
44448+
44449+#ifdef CONFIG_PAX_SEGMEXEC
44450+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
44451+ pax_flags |= MF_PAX_SEGMEXEC;
44452+#endif
44453+
44454+#ifdef CONFIG_PAX_EMUTRAMP
44455+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
44456+ pax_flags |= MF_PAX_EMUTRAMP;
44457+#endif
44458+
44459+#ifdef CONFIG_PAX_MPROTECT
44460+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
44461+ pax_flags |= MF_PAX_MPROTECT;
44462+#endif
44463+
44464+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
44465+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
44466+ pax_flags |= MF_PAX_RANDMMAP;
44467+#endif
44468+
44469+ return pax_flags;
44470+}
44471+#endif
44472+
44473+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
44474+#ifdef CONFIG_PAX_SOFTMODE
44475+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
44476+{
44477+ unsigned long pax_flags = 0UL;
44478+
44479+#ifdef CONFIG_PAX_PAGEEXEC
44480+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
44481+ pax_flags |= MF_PAX_PAGEEXEC;
44482+#endif
44483+
44484+#ifdef CONFIG_PAX_SEGMEXEC
44485+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
44486+ pax_flags |= MF_PAX_SEGMEXEC;
44487+#endif
44488+
44489+#ifdef CONFIG_PAX_EMUTRAMP
44490+ if (pax_flags_softmode & MF_PAX_EMUTRAMP)
44491+ pax_flags |= MF_PAX_EMUTRAMP;
44492+#endif
44493+
44494+#ifdef CONFIG_PAX_MPROTECT
44495+ if (pax_flags_softmode & MF_PAX_MPROTECT)
44496+ pax_flags |= MF_PAX_MPROTECT;
44497+#endif
44498+
44499+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
44500+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
44501+ pax_flags |= MF_PAX_RANDMMAP;
44502+#endif
44503+
44504+ return pax_flags;
44505+}
44506+#endif
44507+
44508+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
44509+{
44510+ unsigned long pax_flags = 0UL;
44511+
44512+#ifdef CONFIG_PAX_PAGEEXEC
44513+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
44514+ pax_flags |= MF_PAX_PAGEEXEC;
44515+#endif
44516+
44517+#ifdef CONFIG_PAX_SEGMEXEC
44518+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
44519+ pax_flags |= MF_PAX_SEGMEXEC;
44520+#endif
44521+
44522+#ifdef CONFIG_PAX_EMUTRAMP
44523+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
44524+ pax_flags |= MF_PAX_EMUTRAMP;
44525+#endif
44526+
44527+#ifdef CONFIG_PAX_MPROTECT
44528+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
44529+ pax_flags |= MF_PAX_MPROTECT;
44530+#endif
44531+
44532+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
44533+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
44534+ pax_flags |= MF_PAX_RANDMMAP;
44535+#endif
44536+
44537+ return pax_flags;
44538+}
44539+#endif
44540+
44541+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
44542+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
44543+{
44544+ unsigned long pax_flags = 0UL;
44545+
44546+#ifdef CONFIG_PAX_EI_PAX
44547+
44548+#ifdef CONFIG_PAX_PAGEEXEC
44549+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
44550+ pax_flags |= MF_PAX_PAGEEXEC;
44551+#endif
44552+
44553+#ifdef CONFIG_PAX_SEGMEXEC
44554+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
44555+ pax_flags |= MF_PAX_SEGMEXEC;
44556+#endif
44557+
44558+#ifdef CONFIG_PAX_EMUTRAMP
44559+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
44560+ pax_flags |= MF_PAX_EMUTRAMP;
44561+#endif
44562+
44563+#ifdef CONFIG_PAX_MPROTECT
44564+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
44565+ pax_flags |= MF_PAX_MPROTECT;
44566+#endif
44567+
44568+#ifdef CONFIG_PAX_ASLR
44569+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
44570+ pax_flags |= MF_PAX_RANDMMAP;
44571+#endif
44572+
44573+#else
44574+
44575+#ifdef CONFIG_PAX_PAGEEXEC
44576+ pax_flags |= MF_PAX_PAGEEXEC;
44577+#endif
44578+
44579+#ifdef CONFIG_PAX_SEGMEXEC
44580+ pax_flags |= MF_PAX_SEGMEXEC;
44581+#endif
44582+
44583+#ifdef CONFIG_PAX_MPROTECT
44584+ pax_flags |= MF_PAX_MPROTECT;
44585+#endif
44586+
44587+#ifdef CONFIG_PAX_RANDMMAP
44588+ if (randomize_va_space)
44589+ pax_flags |= MF_PAX_RANDMMAP;
44590+#endif
44591+
44592+#endif
44593+
44594+ return pax_flags;
44595+}
44596+
44597+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
44598+{
44599+
44600+#ifdef CONFIG_PAX_PT_PAX_FLAGS
44601+ unsigned long i;
44602+
44603+ for (i = 0UL; i < elf_ex->e_phnum; i++)
44604+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
44605+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
44606+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
44607+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
44608+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
44609+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
44610+ return ~0UL;
44611+
44612+#ifdef CONFIG_PAX_SOFTMODE
44613+ if (pax_softmode)
44614+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
44615+ else
44616+#endif
44617+
44618+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
44619+ break;
44620+ }
44621+#endif
44622+
44623+ return ~0UL;
44624+}
44625+
44626+static unsigned long pax_parse_xattr_pax(struct file * const file)
44627+{
44628+
44629+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
44630+ ssize_t xattr_size, i;
44631+ unsigned char xattr_value[5];
44632+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
44633+
44634+ xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
44635+ if (xattr_size <= 0 || xattr_size > 5)
44636+ return ~0UL;
44637+
44638+ for (i = 0; i < xattr_size; i++)
44639+ switch (xattr_value[i]) {
44640+ default:
44641+ return ~0UL;
44642+
44643+#define parse_flag(option1, option2, flag) \
44644+ case option1: \
44645+ if (pax_flags_hardmode & MF_PAX_##flag) \
44646+ return ~0UL; \
44647+ pax_flags_hardmode |= MF_PAX_##flag; \
44648+ break; \
44649+ case option2: \
44650+ if (pax_flags_softmode & MF_PAX_##flag) \
44651+ return ~0UL; \
44652+ pax_flags_softmode |= MF_PAX_##flag; \
44653+ break;
44654+
44655+ parse_flag('p', 'P', PAGEEXEC);
44656+ parse_flag('e', 'E', EMUTRAMP);
44657+ parse_flag('m', 'M', MPROTECT);
44658+ parse_flag('r', 'R', RANDMMAP);
44659+ parse_flag('s', 'S', SEGMEXEC);
44660+
44661+#undef parse_flag
44662+ }
44663+
44664+ if (pax_flags_hardmode & pax_flags_softmode)
44665+ return ~0UL;
44666+
44667+#ifdef CONFIG_PAX_SOFTMODE
44668+ if (pax_softmode)
44669+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
44670+ else
44671+#endif
44672+
44673+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
44674+#else
44675+ return ~0UL;
44676+#endif
44677+
44678+}
44679+
44680+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
44681+{
44682+ unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
44683+
44684+ pax_flags = pax_parse_ei_pax(elf_ex);
44685+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
44686+ xattr_pax_flags = pax_parse_xattr_pax(file);
44687+
44688+ if (pt_pax_flags == ~0UL)
44689+ pt_pax_flags = xattr_pax_flags;
44690+ else if (xattr_pax_flags == ~0UL)
44691+ xattr_pax_flags = pt_pax_flags;
44692+ if (pt_pax_flags != xattr_pax_flags)
44693+ return -EINVAL;
44694+ if (pt_pax_flags != ~0UL)
44695+ pax_flags = pt_pax_flags;
44696+
44697+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
44698+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
44699+ if ((__supported_pte_mask & _PAGE_NX))
44700+ pax_flags &= ~MF_PAX_SEGMEXEC;
44701+ else
44702+ pax_flags &= ~MF_PAX_PAGEEXEC;
44703+ }
44704+#endif
44705+
44706+ if (0 > pax_check_flags(&pax_flags))
44707+ return -EINVAL;
44708+
44709+ current->mm->pax_flags = pax_flags;
44710+ return 0;
44711+}
44712+#endif
44713+
44714 /*
44715 * These are the functions used to load ELF style executables and shared
44716 * libraries. There is no binary dependent code anywhere else.
44717@@ -546,6 +876,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
44718 {
44719 unsigned int random_variable = 0;
44720
44721+#ifdef CONFIG_PAX_RANDUSTACK
44722+ if (randomize_va_space)
44723+ return stack_top - current->mm->delta_stack;
44724+#endif
44725+
44726 if ((current->flags & PF_RANDOMIZE) &&
44727 !(current->personality & ADDR_NO_RANDOMIZE)) {
44728 random_variable = get_random_int() & STACK_RND_MASK;
44729@@ -564,7 +899,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
44730 unsigned long load_addr = 0, load_bias = 0;
44731 int load_addr_set = 0;
44732 char * elf_interpreter = NULL;
44733- unsigned long error;
44734+ unsigned long error = 0;
44735 struct elf_phdr *elf_ppnt, *elf_phdata;
44736 unsigned long elf_bss, elf_brk;
44737 int retval, i;
44738@@ -574,11 +909,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
44739 unsigned long start_code, end_code, start_data, end_data;
44740 unsigned long reloc_func_desc __maybe_unused = 0;
44741 int executable_stack = EXSTACK_DEFAULT;
44742- unsigned long def_flags = 0;
44743 struct {
44744 struct elfhdr elf_ex;
44745 struct elfhdr interp_elf_ex;
44746 } *loc;
44747+ unsigned long pax_task_size = TASK_SIZE;
44748
44749 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
44750 if (!loc) {
44751@@ -714,11 +1049,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
44752 goto out_free_dentry;
44753
44754 /* OK, This is the point of no return */
44755- current->mm->def_flags = def_flags;
44756+
44757+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
44758+ current->mm->pax_flags = 0UL;
44759+#endif
44760+
44761+#ifdef CONFIG_PAX_DLRESOLVE
44762+ current->mm->call_dl_resolve = 0UL;
44763+#endif
44764+
44765+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
44766+ current->mm->call_syscall = 0UL;
44767+#endif
44768+
44769+#ifdef CONFIG_PAX_ASLR
44770+ current->mm->delta_mmap = 0UL;
44771+ current->mm->delta_stack = 0UL;
44772+#endif
44773+
44774+ current->mm->def_flags = 0;
44775+
44776+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
44777+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
44778+ send_sig(SIGKILL, current, 0);
44779+ goto out_free_dentry;
44780+ }
44781+#endif
44782+
44783+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
44784+ pax_set_initial_flags(bprm);
44785+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
44786+ if (pax_set_initial_flags_func)
44787+ (pax_set_initial_flags_func)(bprm);
44788+#endif
44789+
44790+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
44791+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
44792+ current->mm->context.user_cs_limit = PAGE_SIZE;
44793+ current->mm->def_flags |= VM_PAGEEXEC;
44794+ }
44795+#endif
44796+
44797+#ifdef CONFIG_PAX_SEGMEXEC
44798+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
44799+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
44800+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
44801+ pax_task_size = SEGMEXEC_TASK_SIZE;
44802+ current->mm->def_flags |= VM_NOHUGEPAGE;
44803+ }
44804+#endif
44805+
44806+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
44807+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
44808+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
44809+ put_cpu();
44810+ }
44811+#endif
44812
44813 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
44814 may depend on the personality. */
44815 SET_PERSONALITY(loc->elf_ex);
44816+
44817+#ifdef CONFIG_PAX_ASLR
44818+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
44819+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
44820+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
44821+ }
44822+#endif
44823+
44824+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
44825+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
44826+ executable_stack = EXSTACK_DISABLE_X;
44827+ current->personality &= ~READ_IMPLIES_EXEC;
44828+ } else
44829+#endif
44830+
44831 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
44832 current->personality |= READ_IMPLIES_EXEC;
44833
44834@@ -809,6 +1214,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
44835 #else
44836 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
44837 #endif
44838+
44839+#ifdef CONFIG_PAX_RANDMMAP
44840+ /* PaX: randomize base address at the default exe base if requested */
44841+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
44842+#ifdef CONFIG_SPARC64
44843+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
44844+#else
44845+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
44846+#endif
44847+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
44848+ elf_flags |= MAP_FIXED;
44849+ }
44850+#endif
44851+
44852 }
44853
44854 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
44855@@ -841,9 +1260,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
44856 * allowed task size. Note that p_filesz must always be
44857 * <= p_memsz so it is only necessary to check p_memsz.
44858 */
44859- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
44860- elf_ppnt->p_memsz > TASK_SIZE ||
44861- TASK_SIZE - elf_ppnt->p_memsz < k) {
44862+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
44863+ elf_ppnt->p_memsz > pax_task_size ||
44864+ pax_task_size - elf_ppnt->p_memsz < k) {
44865 /* set_brk can never work. Avoid overflows. */
44866 send_sig(SIGKILL, current, 0);
44867 retval = -EINVAL;
44868@@ -882,17 +1301,44 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
44869 goto out_free_dentry;
44870 }
44871 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
44872- send_sig(SIGSEGV, current, 0);
44873- retval = -EFAULT; /* Nobody gets to see this, but.. */
44874- goto out_free_dentry;
44875+ /*
44876+ * This bss-zeroing can fail if the ELF
44877+ * file specifies odd protections. So
44878+ * we don't check the return value
44879+ */
44880 }
44881
44882+#ifdef CONFIG_PAX_RANDMMAP
44883+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
44884+ unsigned long start, size;
44885+
44886+ start = ELF_PAGEALIGN(elf_brk);
44887+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
44888+ down_read(&current->mm->mmap_sem);
44889+ retval = -ENOMEM;
44890+ if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
44891+ unsigned long prot = PROT_NONE;
44892+
44893+ up_read(&current->mm->mmap_sem);
44894+ current->mm->brk_gap = PAGE_ALIGN(size) >> PAGE_SHIFT;
44895+// if (current->personality & ADDR_NO_RANDOMIZE)
44896+// prot = PROT_READ;
44897+ start = vm_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
44898+ retval = IS_ERR_VALUE(start) ? start : 0;
44899+ } else
44900+ up_read(&current->mm->mmap_sem);
44901+ if (retval == 0)
44902+ retval = set_brk(start + size, start + size + PAGE_SIZE);
44903+ if (retval < 0) {
44904+ send_sig(SIGKILL, current, 0);
44905+ goto out_free_dentry;
44906+ }
44907+ }
44908+#endif
44909+
44910 if (elf_interpreter) {
44911- unsigned long interp_map_addr = 0;
44912-
44913 elf_entry = load_elf_interp(&loc->interp_elf_ex,
44914 interpreter,
44915- &interp_map_addr,
44916 load_bias);
44917 if (!IS_ERR((void *)elf_entry)) {
44918 /*
44919@@ -1114,7 +1560,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
44920 * Decide what to dump of a segment, part, all or none.
44921 */
44922 static unsigned long vma_dump_size(struct vm_area_struct *vma,
44923- unsigned long mm_flags)
44924+ unsigned long mm_flags, long signr)
44925 {
44926 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
44927
44928@@ -1151,7 +1597,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
44929 if (vma->vm_file == NULL)
44930 return 0;
44931
44932- if (FILTER(MAPPED_PRIVATE))
44933+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
44934 goto whole;
44935
44936 /*
44937@@ -1373,9 +1819,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
44938 {
44939 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
44940 int i = 0;
44941- do
44942+ do {
44943 i += 2;
44944- while (auxv[i - 2] != AT_NULL);
44945+ } while (auxv[i - 2] != AT_NULL);
44946 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
44947 }
44948
44949@@ -2003,14 +2449,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
44950 }
44951
44952 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
44953- unsigned long mm_flags)
44954+ struct coredump_params *cprm)
44955 {
44956 struct vm_area_struct *vma;
44957 size_t size = 0;
44958
44959 for (vma = first_vma(current, gate_vma); vma != NULL;
44960 vma = next_vma(vma, gate_vma))
44961- size += vma_dump_size(vma, mm_flags);
44962+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
44963 return size;
44964 }
44965
44966@@ -2104,7 +2550,7 @@ static int elf_core_dump(struct coredump_params *cprm)
44967
44968 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
44969
44970- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
44971+ offset += elf_core_vma_data_size(gate_vma, cprm);
44972 offset += elf_core_extra_data_size();
44973 e_shoff = offset;
44974
44975@@ -2118,10 +2564,12 @@ static int elf_core_dump(struct coredump_params *cprm)
44976 offset = dataoff;
44977
44978 size += sizeof(*elf);
44979+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
44980 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
44981 goto end_coredump;
44982
44983 size += sizeof(*phdr4note);
44984+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
44985 if (size > cprm->limit
44986 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
44987 goto end_coredump;
44988@@ -2135,7 +2583,7 @@ static int elf_core_dump(struct coredump_params *cprm)
44989 phdr.p_offset = offset;
44990 phdr.p_vaddr = vma->vm_start;
44991 phdr.p_paddr = 0;
44992- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
44993+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
44994 phdr.p_memsz = vma->vm_end - vma->vm_start;
44995 offset += phdr.p_filesz;
44996 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
44997@@ -2146,6 +2594,7 @@ static int elf_core_dump(struct coredump_params *cprm)
44998 phdr.p_align = ELF_EXEC_PAGESIZE;
44999
45000 size += sizeof(phdr);
45001+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
45002 if (size > cprm->limit
45003 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
45004 goto end_coredump;
45005@@ -2170,7 +2619,7 @@ static int elf_core_dump(struct coredump_params *cprm)
45006 unsigned long addr;
45007 unsigned long end;
45008
45009- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
45010+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
45011
45012 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
45013 struct page *page;
45014@@ -2179,6 +2628,7 @@ static int elf_core_dump(struct coredump_params *cprm)
45015 page = get_dump_page(addr);
45016 if (page) {
45017 void *kaddr = kmap(page);
45018+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
45019 stop = ((size += PAGE_SIZE) > cprm->limit) ||
45020 !dump_write(cprm->file, kaddr,
45021 PAGE_SIZE);
45022@@ -2196,6 +2646,7 @@ static int elf_core_dump(struct coredump_params *cprm)
45023
45024 if (e_phnum == PN_XNUM) {
45025 size += sizeof(*shdr4extnum);
45026+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
45027 if (size > cprm->limit
45028 || !dump_write(cprm->file, shdr4extnum,
45029 sizeof(*shdr4extnum)))
45030@@ -2216,6 +2667,97 @@ out:
45031
45032 #endif /* CONFIG_ELF_CORE */
45033
45034+#ifdef CONFIG_PAX_MPROTECT
45035+/* PaX: non-PIC ELF libraries need relocations on their executable segments
45036+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
45037+ * we'll remove VM_MAYWRITE for good on RELRO segments.
45038+ *
45039+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
45040+ * basis because we want to allow the common case and not the special ones.
45041+ */
45042+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
45043+{
45044+ struct elfhdr elf_h;
45045+ struct elf_phdr elf_p;
45046+ unsigned long i;
45047+ unsigned long oldflags;
45048+ bool is_textrel_rw, is_textrel_rx, is_relro;
45049+
45050+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
45051+ return;
45052+
45053+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
45054+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
45055+
45056+#ifdef CONFIG_PAX_ELFRELOCS
45057+ /* possible TEXTREL */
45058+ is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
45059+ 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);
45060+#else
45061+ is_textrel_rw = false;
45062+ is_textrel_rx = false;
45063+#endif
45064+
45065+ /* possible RELRO */
45066+ is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
45067+
45068+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
45069+ return;
45070+
45071+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
45072+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
45073+
45074+#ifdef CONFIG_PAX_ETEXECRELOCS
45075+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
45076+#else
45077+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
45078+#endif
45079+
45080+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
45081+ !elf_check_arch(&elf_h) ||
45082+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
45083+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
45084+ return;
45085+
45086+ for (i = 0UL; i < elf_h.e_phnum; i++) {
45087+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
45088+ return;
45089+ switch (elf_p.p_type) {
45090+ case PT_DYNAMIC:
45091+ if (!is_textrel_rw && !is_textrel_rx)
45092+ continue;
45093+ i = 0UL;
45094+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
45095+ elf_dyn dyn;
45096+
45097+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
45098+ return;
45099+ if (dyn.d_tag == DT_NULL)
45100+ return;
45101+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
45102+ gr_log_textrel(vma);
45103+ if (is_textrel_rw)
45104+ vma->vm_flags |= VM_MAYWRITE;
45105+ else
45106+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
45107+ vma->vm_flags &= ~VM_MAYWRITE;
45108+ return;
45109+ }
45110+ i++;
45111+ }
45112+ return;
45113+
45114+ case PT_GNU_RELRO:
45115+ if (!is_relro)
45116+ continue;
45117+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
45118+ vma->vm_flags &= ~VM_MAYWRITE;
45119+ return;
45120+ }
45121+ }
45122+}
45123+#endif
45124+
45125 static int __init init_elf_binfmt(void)
45126 {
45127 register_binfmt(&elf_format);
45128diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
45129index e280352..7b2f231 100644
45130--- a/fs/binfmt_flat.c
45131+++ b/fs/binfmt_flat.c
45132@@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
45133 realdatastart = (unsigned long) -ENOMEM;
45134 printk("Unable to allocate RAM for process data, errno %d\n",
45135 (int)-realdatastart);
45136+ down_write(&current->mm->mmap_sem);
45137 vm_munmap(textpos, text_len);
45138+ up_write(&current->mm->mmap_sem);
45139 ret = realdatastart;
45140 goto err;
45141 }
45142@@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
45143 }
45144 if (IS_ERR_VALUE(result)) {
45145 printk("Unable to read data+bss, errno %d\n", (int)-result);
45146+ down_write(&current->mm->mmap_sem);
45147 vm_munmap(textpos, text_len);
45148 vm_munmap(realdatastart, len);
45149+ up_write(&current->mm->mmap_sem);
45150 ret = result;
45151 goto err;
45152 }
45153@@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
45154 }
45155 if (IS_ERR_VALUE(result)) {
45156 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
45157+ down_write(&current->mm->mmap_sem);
45158 vm_munmap(textpos, text_len + data_len + extra +
45159 MAX_SHARED_LIBS * sizeof(unsigned long));
45160+ up_write(&current->mm->mmap_sem);
45161 ret = result;
45162 goto err;
45163 }
45164diff --git a/fs/bio.c b/fs/bio.c
45165index b96fc6c..431d628 100644
45166--- a/fs/bio.c
45167+++ b/fs/bio.c
45168@@ -818,7 +818,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
45169 /*
45170 * Overflow, abort
45171 */
45172- if (end < start)
45173+ if (end < start || end - start > INT_MAX - nr_pages)
45174 return ERR_PTR(-EINVAL);
45175
45176 nr_pages += end - start;
45177@@ -952,7 +952,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
45178 /*
45179 * Overflow, abort
45180 */
45181- if (end < start)
45182+ if (end < start || end - start > INT_MAX - nr_pages)
45183 return ERR_PTR(-EINVAL);
45184
45185 nr_pages += end - start;
45186@@ -1214,7 +1214,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
45187 const int read = bio_data_dir(bio) == READ;
45188 struct bio_map_data *bmd = bio->bi_private;
45189 int i;
45190- char *p = bmd->sgvecs[0].iov_base;
45191+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
45192
45193 __bio_for_each_segment(bvec, bio, i, 0) {
45194 char *addr = page_address(bvec->bv_page);
45195diff --git a/fs/block_dev.c b/fs/block_dev.c
45196index ab3a456..7da538b 100644
45197--- a/fs/block_dev.c
45198+++ b/fs/block_dev.c
45199@@ -651,7 +651,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
45200 else if (bdev->bd_contains == bdev)
45201 return true; /* is a whole device which isn't held */
45202
45203- else if (whole->bd_holder == bd_may_claim)
45204+ else if (whole->bd_holder == (void *)bd_may_claim)
45205 return true; /* is a partition of a device that is being partitioned */
45206 else if (whole->bd_holder != NULL)
45207 return false; /* is a partition of a held device */
45208diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
45209index 5a3e45d..ad19cc3 100644
45210--- a/fs/btrfs/check-integrity.c
45211+++ b/fs/btrfs/check-integrity.c
45212@@ -156,7 +156,7 @@ struct btrfsic_block {
45213 union {
45214 bio_end_io_t *bio;
45215 bh_end_io_t *bh;
45216- } orig_bio_bh_end_io;
45217+ } __no_const orig_bio_bh_end_io;
45218 int submit_bio_bh_rw;
45219 u64 flush_gen; /* only valid if !never_written */
45220 };
45221diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
45222index cdfb4c4..da736d4 100644
45223--- a/fs/btrfs/ctree.c
45224+++ b/fs/btrfs/ctree.c
45225@@ -1035,9 +1035,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
45226 free_extent_buffer(buf);
45227 add_root_to_dirty_list(root);
45228 } else {
45229- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
45230- parent_start = parent->start;
45231- else
45232+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
45233+ if (parent)
45234+ parent_start = parent->start;
45235+ else
45236+ parent_start = 0;
45237+ } else
45238 parent_start = 0;
45239
45240 WARN_ON(trans->transid != btrfs_header_generation(parent));
45241diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
45242index 95542a1..95a8727 100644
45243--- a/fs/btrfs/inode.c
45244+++ b/fs/btrfs/inode.c
45245@@ -7243,7 +7243,7 @@ fail:
45246 return -ENOMEM;
45247 }
45248
45249-static int btrfs_getattr(struct vfsmount *mnt,
45250+int btrfs_getattr(struct vfsmount *mnt,
45251 struct dentry *dentry, struct kstat *stat)
45252 {
45253 struct inode *inode = dentry->d_inode;
45254@@ -7257,6 +7257,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
45255 return 0;
45256 }
45257
45258+EXPORT_SYMBOL(btrfs_getattr);
45259+
45260+dev_t get_btrfs_dev_from_inode(struct inode *inode)
45261+{
45262+ return BTRFS_I(inode)->root->anon_dev;
45263+}
45264+EXPORT_SYMBOL(get_btrfs_dev_from_inode);
45265+
45266 /*
45267 * If a file is moved, it will inherit the cow and compression flags of the new
45268 * directory.
45269diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
45270index 8fcf9a5..a200000 100644
45271--- a/fs/btrfs/ioctl.c
45272+++ b/fs/btrfs/ioctl.c
45273@@ -2965,9 +2965,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
45274 for (i = 0; i < num_types; i++) {
45275 struct btrfs_space_info *tmp;
45276
45277+ /* Don't copy in more than we allocated */
45278 if (!slot_count)
45279 break;
45280
45281+ slot_count--;
45282+
45283 info = NULL;
45284 rcu_read_lock();
45285 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
45286@@ -2989,10 +2992,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
45287 memcpy(dest, &space, sizeof(space));
45288 dest++;
45289 space_args.total_spaces++;
45290- slot_count--;
45291 }
45292- if (!slot_count)
45293- break;
45294 }
45295 up_read(&info->groups_sem);
45296 }
45297diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
45298index 776f0aa..3aad281 100644
45299--- a/fs/btrfs/relocation.c
45300+++ b/fs/btrfs/relocation.c
45301@@ -1269,7 +1269,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
45302 }
45303 spin_unlock(&rc->reloc_root_tree.lock);
45304
45305- BUG_ON((struct btrfs_root *)node->data != root);
45306+ BUG_ON(!node || (struct btrfs_root *)node->data != root);
45307
45308 if (!del) {
45309 spin_lock(&rc->reloc_root_tree.lock);
45310diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
45311index 622f469..e8d2d55 100644
45312--- a/fs/cachefiles/bind.c
45313+++ b/fs/cachefiles/bind.c
45314@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
45315 args);
45316
45317 /* start by checking things over */
45318- ASSERT(cache->fstop_percent >= 0 &&
45319- cache->fstop_percent < cache->fcull_percent &&
45320+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
45321 cache->fcull_percent < cache->frun_percent &&
45322 cache->frun_percent < 100);
45323
45324- ASSERT(cache->bstop_percent >= 0 &&
45325- cache->bstop_percent < cache->bcull_percent &&
45326+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
45327 cache->bcull_percent < cache->brun_percent &&
45328 cache->brun_percent < 100);
45329
45330diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
45331index 0a1467b..6a53245 100644
45332--- a/fs/cachefiles/daemon.c
45333+++ b/fs/cachefiles/daemon.c
45334@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
45335 if (n > buflen)
45336 return -EMSGSIZE;
45337
45338- if (copy_to_user(_buffer, buffer, n) != 0)
45339+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
45340 return -EFAULT;
45341
45342 return n;
45343@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
45344 if (test_bit(CACHEFILES_DEAD, &cache->flags))
45345 return -EIO;
45346
45347- if (datalen < 0 || datalen > PAGE_SIZE - 1)
45348+ if (datalen > PAGE_SIZE - 1)
45349 return -EOPNOTSUPP;
45350
45351 /* drag the command string into the kernel so we can parse it */
45352@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
45353 if (args[0] != '%' || args[1] != '\0')
45354 return -EINVAL;
45355
45356- if (fstop < 0 || fstop >= cache->fcull_percent)
45357+ if (fstop >= cache->fcull_percent)
45358 return cachefiles_daemon_range_error(cache, args);
45359
45360 cache->fstop_percent = fstop;
45361@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
45362 if (args[0] != '%' || args[1] != '\0')
45363 return -EINVAL;
45364
45365- if (bstop < 0 || bstop >= cache->bcull_percent)
45366+ if (bstop >= cache->bcull_percent)
45367 return cachefiles_daemon_range_error(cache, args);
45368
45369 cache->bstop_percent = bstop;
45370diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
45371index bd6bc1b..b627b53 100644
45372--- a/fs/cachefiles/internal.h
45373+++ b/fs/cachefiles/internal.h
45374@@ -57,7 +57,7 @@ struct cachefiles_cache {
45375 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
45376 struct rb_root active_nodes; /* active nodes (can't be culled) */
45377 rwlock_t active_lock; /* lock for active_nodes */
45378- atomic_t gravecounter; /* graveyard uniquifier */
45379+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
45380 unsigned frun_percent; /* when to stop culling (% files) */
45381 unsigned fcull_percent; /* when to start culling (% files) */
45382 unsigned fstop_percent; /* when to stop allocating (% files) */
45383@@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
45384 * proc.c
45385 */
45386 #ifdef CONFIG_CACHEFILES_HISTOGRAM
45387-extern atomic_t cachefiles_lookup_histogram[HZ];
45388-extern atomic_t cachefiles_mkdir_histogram[HZ];
45389-extern atomic_t cachefiles_create_histogram[HZ];
45390+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
45391+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
45392+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
45393
45394 extern int __init cachefiles_proc_init(void);
45395 extern void cachefiles_proc_cleanup(void);
45396 static inline
45397-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
45398+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
45399 {
45400 unsigned long jif = jiffies - start_jif;
45401 if (jif >= HZ)
45402 jif = HZ - 1;
45403- atomic_inc(&histogram[jif]);
45404+ atomic_inc_unchecked(&histogram[jif]);
45405 }
45406
45407 #else
45408diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
45409index b0b5f7c..039bb26 100644
45410--- a/fs/cachefiles/namei.c
45411+++ b/fs/cachefiles/namei.c
45412@@ -318,7 +318,7 @@ try_again:
45413 /* first step is to make up a grave dentry in the graveyard */
45414 sprintf(nbuffer, "%08x%08x",
45415 (uint32_t) get_seconds(),
45416- (uint32_t) atomic_inc_return(&cache->gravecounter));
45417+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
45418
45419 /* do the multiway lock magic */
45420 trap = lock_rename(cache->graveyard, dir);
45421diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
45422index eccd339..4c1d995 100644
45423--- a/fs/cachefiles/proc.c
45424+++ b/fs/cachefiles/proc.c
45425@@ -14,9 +14,9 @@
45426 #include <linux/seq_file.h>
45427 #include "internal.h"
45428
45429-atomic_t cachefiles_lookup_histogram[HZ];
45430-atomic_t cachefiles_mkdir_histogram[HZ];
45431-atomic_t cachefiles_create_histogram[HZ];
45432+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
45433+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
45434+atomic_unchecked_t cachefiles_create_histogram[HZ];
45435
45436 /*
45437 * display the latency histogram
45438@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
45439 return 0;
45440 default:
45441 index = (unsigned long) v - 3;
45442- x = atomic_read(&cachefiles_lookup_histogram[index]);
45443- y = atomic_read(&cachefiles_mkdir_histogram[index]);
45444- z = atomic_read(&cachefiles_create_histogram[index]);
45445+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
45446+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
45447+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
45448 if (x == 0 && y == 0 && z == 0)
45449 return 0;
45450
45451diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
45452index c994691..2a1537f 100644
45453--- a/fs/cachefiles/rdwr.c
45454+++ b/fs/cachefiles/rdwr.c
45455@@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
45456 old_fs = get_fs();
45457 set_fs(KERNEL_DS);
45458 ret = file->f_op->write(
45459- file, (const void __user *) data, len, &pos);
45460+ file, (const void __force_user *) data, len, &pos);
45461 set_fs(old_fs);
45462 kunmap(page);
45463 if (ret != len)
45464diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
45465index e5b7731..b9c59fb 100644
45466--- a/fs/ceph/dir.c
45467+++ b/fs/ceph/dir.c
45468@@ -243,7 +243,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
45469 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
45470 struct ceph_mds_client *mdsc = fsc->mdsc;
45471 unsigned frag = fpos_frag(filp->f_pos);
45472- int off = fpos_off(filp->f_pos);
45473+ unsigned int off = fpos_off(filp->f_pos);
45474 int err;
45475 u32 ftype;
45476 struct ceph_mds_reply_info_parsed *rinfo;
45477diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
45478index d9ea6ed..1e6c8ac 100644
45479--- a/fs/cifs/cifs_debug.c
45480+++ b/fs/cifs/cifs_debug.c
45481@@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
45482
45483 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
45484 #ifdef CONFIG_CIFS_STATS2
45485- atomic_set(&totBufAllocCount, 0);
45486- atomic_set(&totSmBufAllocCount, 0);
45487+ atomic_set_unchecked(&totBufAllocCount, 0);
45488+ atomic_set_unchecked(&totSmBufAllocCount, 0);
45489 #endif /* CONFIG_CIFS_STATS2 */
45490 spin_lock(&cifs_tcp_ses_lock);
45491 list_for_each(tmp1, &cifs_tcp_ses_list) {
45492@@ -281,7 +281,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
45493 tcon = list_entry(tmp3,
45494 struct cifs_tcon,
45495 tcon_list);
45496- atomic_set(&tcon->num_smbs_sent, 0);
45497+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
45498 if (server->ops->clear_stats)
45499 server->ops->clear_stats(tcon);
45500 }
45501@@ -313,8 +313,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
45502 smBufAllocCount.counter, cifs_min_small);
45503 #ifdef CONFIG_CIFS_STATS2
45504 seq_printf(m, "Total Large %d Small %d Allocations\n",
45505- atomic_read(&totBufAllocCount),
45506- atomic_read(&totSmBufAllocCount));
45507+ atomic_read_unchecked(&totBufAllocCount),
45508+ atomic_read_unchecked(&totSmBufAllocCount));
45509 #endif /* CONFIG_CIFS_STATS2 */
45510
45511 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
45512@@ -343,7 +343,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
45513 if (tcon->need_reconnect)
45514 seq_puts(m, "\tDISCONNECTED ");
45515 seq_printf(m, "\nSMBs: %d",
45516- atomic_read(&tcon->num_smbs_sent));
45517+ atomic_read_unchecked(&tcon->num_smbs_sent));
45518 if (server->ops->print_stats)
45519 server->ops->print_stats(m, tcon);
45520 }
45521diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
45522index e7931cc..76a1ab9 100644
45523--- a/fs/cifs/cifsfs.c
45524+++ b/fs/cifs/cifsfs.c
45525@@ -999,7 +999,7 @@ cifs_init_request_bufs(void)
45526 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
45527 cifs_req_cachep = kmem_cache_create("cifs_request",
45528 CIFSMaxBufSize + max_hdr_size, 0,
45529- SLAB_HWCACHE_ALIGN, NULL);
45530+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
45531 if (cifs_req_cachep == NULL)
45532 return -ENOMEM;
45533
45534@@ -1026,7 +1026,7 @@ cifs_init_request_bufs(void)
45535 efficient to alloc 1 per page off the slab compared to 17K (5page)
45536 alloc of large cifs buffers even when page debugging is on */
45537 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
45538- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
45539+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
45540 NULL);
45541 if (cifs_sm_req_cachep == NULL) {
45542 mempool_destroy(cifs_req_poolp);
45543@@ -1111,8 +1111,8 @@ init_cifs(void)
45544 atomic_set(&bufAllocCount, 0);
45545 atomic_set(&smBufAllocCount, 0);
45546 #ifdef CONFIG_CIFS_STATS2
45547- atomic_set(&totBufAllocCount, 0);
45548- atomic_set(&totSmBufAllocCount, 0);
45549+ atomic_set_unchecked(&totBufAllocCount, 0);
45550+ atomic_set_unchecked(&totSmBufAllocCount, 0);
45551 #endif /* CONFIG_CIFS_STATS2 */
45552
45553 atomic_set(&midCount, 0);
45554diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
45555index f5af252..489b5f2 100644
45556--- a/fs/cifs/cifsglob.h
45557+++ b/fs/cifs/cifsglob.h
45558@@ -751,35 +751,35 @@ struct cifs_tcon {
45559 __u16 Flags; /* optional support bits */
45560 enum statusEnum tidStatus;
45561 #ifdef CONFIG_CIFS_STATS
45562- atomic_t num_smbs_sent;
45563+ atomic_unchecked_t num_smbs_sent;
45564 union {
45565 struct {
45566- atomic_t num_writes;
45567- atomic_t num_reads;
45568- atomic_t num_flushes;
45569- atomic_t num_oplock_brks;
45570- atomic_t num_opens;
45571- atomic_t num_closes;
45572- atomic_t num_deletes;
45573- atomic_t num_mkdirs;
45574- atomic_t num_posixopens;
45575- atomic_t num_posixmkdirs;
45576- atomic_t num_rmdirs;
45577- atomic_t num_renames;
45578- atomic_t num_t2renames;
45579- atomic_t num_ffirst;
45580- atomic_t num_fnext;
45581- atomic_t num_fclose;
45582- atomic_t num_hardlinks;
45583- atomic_t num_symlinks;
45584- atomic_t num_locks;
45585- atomic_t num_acl_get;
45586- atomic_t num_acl_set;
45587+ atomic_unchecked_t num_writes;
45588+ atomic_unchecked_t num_reads;
45589+ atomic_unchecked_t num_flushes;
45590+ atomic_unchecked_t num_oplock_brks;
45591+ atomic_unchecked_t num_opens;
45592+ atomic_unchecked_t num_closes;
45593+ atomic_unchecked_t num_deletes;
45594+ atomic_unchecked_t num_mkdirs;
45595+ atomic_unchecked_t num_posixopens;
45596+ atomic_unchecked_t num_posixmkdirs;
45597+ atomic_unchecked_t num_rmdirs;
45598+ atomic_unchecked_t num_renames;
45599+ atomic_unchecked_t num_t2renames;
45600+ atomic_unchecked_t num_ffirst;
45601+ atomic_unchecked_t num_fnext;
45602+ atomic_unchecked_t num_fclose;
45603+ atomic_unchecked_t num_hardlinks;
45604+ atomic_unchecked_t num_symlinks;
45605+ atomic_unchecked_t num_locks;
45606+ atomic_unchecked_t num_acl_get;
45607+ atomic_unchecked_t num_acl_set;
45608 } cifs_stats;
45609 #ifdef CONFIG_CIFS_SMB2
45610 struct {
45611- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
45612- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
45613+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
45614+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
45615 } smb2_stats;
45616 #endif /* CONFIG_CIFS_SMB2 */
45617 } stats;
45618@@ -1094,7 +1094,7 @@ build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb,
45619 }
45620
45621 #ifdef CONFIG_CIFS_STATS
45622-#define cifs_stats_inc atomic_inc
45623+#define cifs_stats_inc atomic_inc_unchecked
45624
45625 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
45626 unsigned int bytes)
45627@@ -1459,8 +1459,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
45628 /* Various Debug counters */
45629 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
45630 #ifdef CONFIG_CIFS_STATS2
45631-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
45632-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
45633+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
45634+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
45635 #endif
45636 GLOBAL_EXTERN atomic_t smBufAllocCount;
45637 GLOBAL_EXTERN atomic_t midCount;
45638diff --git a/fs/cifs/link.c b/fs/cifs/link.c
45639index 51dc2fb..1e12a33 100644
45640--- a/fs/cifs/link.c
45641+++ b/fs/cifs/link.c
45642@@ -616,7 +616,7 @@ symlink_exit:
45643
45644 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
45645 {
45646- char *p = nd_get_link(nd);
45647+ const char *p = nd_get_link(nd);
45648 if (!IS_ERR(p))
45649 kfree(p);
45650 }
45651diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
45652index 3a00c0d..42d901c 100644
45653--- a/fs/cifs/misc.c
45654+++ b/fs/cifs/misc.c
45655@@ -169,7 +169,7 @@ cifs_buf_get(void)
45656 memset(ret_buf, 0, buf_size + 3);
45657 atomic_inc(&bufAllocCount);
45658 #ifdef CONFIG_CIFS_STATS2
45659- atomic_inc(&totBufAllocCount);
45660+ atomic_inc_unchecked(&totBufAllocCount);
45661 #endif /* CONFIG_CIFS_STATS2 */
45662 }
45663
45664@@ -204,7 +204,7 @@ cifs_small_buf_get(void)
45665 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
45666 atomic_inc(&smBufAllocCount);
45667 #ifdef CONFIG_CIFS_STATS2
45668- atomic_inc(&totSmBufAllocCount);
45669+ atomic_inc_unchecked(&totSmBufAllocCount);
45670 #endif /* CONFIG_CIFS_STATS2 */
45671
45672 }
45673diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
45674index 34cea27..3fbdf6f 100644
45675--- a/fs/cifs/smb1ops.c
45676+++ b/fs/cifs/smb1ops.c
45677@@ -610,27 +610,27 @@ static void
45678 cifs_clear_stats(struct cifs_tcon *tcon)
45679 {
45680 #ifdef CONFIG_CIFS_STATS
45681- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
45682- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
45683- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
45684- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
45685- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
45686- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
45687- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
45688- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
45689- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
45690- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
45691- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
45692- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
45693- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
45694- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
45695- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
45696- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
45697- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
45698- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
45699- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
45700- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
45701- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
45702+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
45703+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
45704+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
45705+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
45706+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
45707+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
45708+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
45709+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
45710+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
45711+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
45712+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
45713+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
45714+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
45715+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
45716+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
45717+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
45718+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
45719+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
45720+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
45721+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
45722+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
45723 #endif
45724 }
45725
45726@@ -639,36 +639,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
45727 {
45728 #ifdef CONFIG_CIFS_STATS
45729 seq_printf(m, " Oplocks breaks: %d",
45730- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
45731+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
45732 seq_printf(m, "\nReads: %d Bytes: %llu",
45733- atomic_read(&tcon->stats.cifs_stats.num_reads),
45734+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
45735 (long long)(tcon->bytes_read));
45736 seq_printf(m, "\nWrites: %d Bytes: %llu",
45737- atomic_read(&tcon->stats.cifs_stats.num_writes),
45738+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
45739 (long long)(tcon->bytes_written));
45740 seq_printf(m, "\nFlushes: %d",
45741- atomic_read(&tcon->stats.cifs_stats.num_flushes));
45742+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
45743 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
45744- atomic_read(&tcon->stats.cifs_stats.num_locks),
45745- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
45746- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
45747+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
45748+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
45749+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
45750 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
45751- atomic_read(&tcon->stats.cifs_stats.num_opens),
45752- atomic_read(&tcon->stats.cifs_stats.num_closes),
45753- atomic_read(&tcon->stats.cifs_stats.num_deletes));
45754+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
45755+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
45756+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
45757 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
45758- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
45759- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
45760+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
45761+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
45762 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
45763- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
45764- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
45765+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
45766+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
45767 seq_printf(m, "\nRenames: %d T2 Renames %d",
45768- atomic_read(&tcon->stats.cifs_stats.num_renames),
45769- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
45770+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
45771+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
45772 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
45773- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
45774- atomic_read(&tcon->stats.cifs_stats.num_fnext),
45775- atomic_read(&tcon->stats.cifs_stats.num_fclose));
45776+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
45777+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
45778+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
45779 #endif
45780 }
45781
45782diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
45783index 4d9dbe0..0af4601 100644
45784--- a/fs/cifs/smb2ops.c
45785+++ b/fs/cifs/smb2ops.c
45786@@ -291,8 +291,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
45787 #ifdef CONFIG_CIFS_STATS
45788 int i;
45789 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
45790- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
45791- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
45792+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
45793+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
45794 }
45795 #endif
45796 }
45797@@ -301,66 +301,66 @@ static void
45798 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
45799 {
45800 #ifdef CONFIG_CIFS_STATS
45801- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
45802- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
45803+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
45804+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
45805 seq_printf(m, "\nNegotiates: %d sent %d failed",
45806- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
45807- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
45808+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
45809+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
45810 seq_printf(m, "\nSessionSetups: %d sent %d failed",
45811- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
45812- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
45813+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
45814+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
45815 #define SMB2LOGOFF 0x0002 /* trivial request/resp */
45816 seq_printf(m, "\nLogoffs: %d sent %d failed",
45817- atomic_read(&sent[SMB2_LOGOFF_HE]),
45818- atomic_read(&failed[SMB2_LOGOFF_HE]));
45819+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
45820+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
45821 seq_printf(m, "\nTreeConnects: %d sent %d failed",
45822- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
45823- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
45824+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
45825+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
45826 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
45827- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
45828- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
45829+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
45830+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
45831 seq_printf(m, "\nCreates: %d sent %d failed",
45832- atomic_read(&sent[SMB2_CREATE_HE]),
45833- atomic_read(&failed[SMB2_CREATE_HE]));
45834+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
45835+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
45836 seq_printf(m, "\nCloses: %d sent %d failed",
45837- atomic_read(&sent[SMB2_CLOSE_HE]),
45838- atomic_read(&failed[SMB2_CLOSE_HE]));
45839+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
45840+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
45841 seq_printf(m, "\nFlushes: %d sent %d failed",
45842- atomic_read(&sent[SMB2_FLUSH_HE]),
45843- atomic_read(&failed[SMB2_FLUSH_HE]));
45844+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
45845+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
45846 seq_printf(m, "\nReads: %d sent %d failed",
45847- atomic_read(&sent[SMB2_READ_HE]),
45848- atomic_read(&failed[SMB2_READ_HE]));
45849+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
45850+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
45851 seq_printf(m, "\nWrites: %d sent %d failed",
45852- atomic_read(&sent[SMB2_WRITE_HE]),
45853- atomic_read(&failed[SMB2_WRITE_HE]));
45854+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
45855+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
45856 seq_printf(m, "\nLocks: %d sent %d failed",
45857- atomic_read(&sent[SMB2_LOCK_HE]),
45858- atomic_read(&failed[SMB2_LOCK_HE]));
45859+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
45860+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
45861 seq_printf(m, "\nIOCTLs: %d sent %d failed",
45862- atomic_read(&sent[SMB2_IOCTL_HE]),
45863- atomic_read(&failed[SMB2_IOCTL_HE]));
45864+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
45865+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
45866 seq_printf(m, "\nCancels: %d sent %d failed",
45867- atomic_read(&sent[SMB2_CANCEL_HE]),
45868- atomic_read(&failed[SMB2_CANCEL_HE]));
45869+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
45870+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
45871 seq_printf(m, "\nEchos: %d sent %d failed",
45872- atomic_read(&sent[SMB2_ECHO_HE]),
45873- atomic_read(&failed[SMB2_ECHO_HE]));
45874+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
45875+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
45876 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
45877- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
45878- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
45879+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
45880+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
45881 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
45882- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
45883- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
45884+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
45885+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
45886 seq_printf(m, "\nQueryInfos: %d sent %d failed",
45887- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
45888- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
45889+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
45890+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
45891 seq_printf(m, "\nSetInfos: %d sent %d failed",
45892- atomic_read(&sent[SMB2_SET_INFO_HE]),
45893- atomic_read(&failed[SMB2_SET_INFO_HE]));
45894+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
45895+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
45896 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
45897- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
45898- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
45899+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
45900+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
45901 #endif
45902 }
45903
45904diff --git a/fs/coda/cache.c b/fs/coda/cache.c
45905index 958ae0e..505c9d0 100644
45906--- a/fs/coda/cache.c
45907+++ b/fs/coda/cache.c
45908@@ -24,7 +24,7 @@
45909 #include "coda_linux.h"
45910 #include "coda_cache.h"
45911
45912-static atomic_t permission_epoch = ATOMIC_INIT(0);
45913+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
45914
45915 /* replace or extend an acl cache hit */
45916 void coda_cache_enter(struct inode *inode, int mask)
45917@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
45918 struct coda_inode_info *cii = ITOC(inode);
45919
45920 spin_lock(&cii->c_lock);
45921- cii->c_cached_epoch = atomic_read(&permission_epoch);
45922+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
45923 if (cii->c_uid != current_fsuid()) {
45924 cii->c_uid = current_fsuid();
45925 cii->c_cached_perm = mask;
45926@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
45927 {
45928 struct coda_inode_info *cii = ITOC(inode);
45929 spin_lock(&cii->c_lock);
45930- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
45931+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
45932 spin_unlock(&cii->c_lock);
45933 }
45934
45935 /* remove all acl caches */
45936 void coda_cache_clear_all(struct super_block *sb)
45937 {
45938- atomic_inc(&permission_epoch);
45939+ atomic_inc_unchecked(&permission_epoch);
45940 }
45941
45942
45943@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
45944 spin_lock(&cii->c_lock);
45945 hit = (mask & cii->c_cached_perm) == mask &&
45946 cii->c_uid == current_fsuid() &&
45947- cii->c_cached_epoch == atomic_read(&permission_epoch);
45948+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
45949 spin_unlock(&cii->c_lock);
45950
45951 return hit;
45952diff --git a/fs/compat.c b/fs/compat.c
45953index 015e1e1..5ce8e54 100644
45954--- a/fs/compat.c
45955+++ b/fs/compat.c
45956@@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
45957
45958 set_fs(KERNEL_DS);
45959 /* The __user pointer cast is valid because of the set_fs() */
45960- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
45961+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
45962 set_fs(oldfs);
45963 /* truncating is ok because it's a user address */
45964 if (!ret)
45965@@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
45966 goto out;
45967
45968 ret = -EINVAL;
45969- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
45970+ if (nr_segs > UIO_MAXIOV)
45971 goto out;
45972 if (nr_segs > fast_segs) {
45973 ret = -ENOMEM;
45974@@ -831,6 +831,7 @@ struct compat_old_linux_dirent {
45975
45976 struct compat_readdir_callback {
45977 struct compat_old_linux_dirent __user *dirent;
45978+ struct file * file;
45979 int result;
45980 };
45981
45982@@ -848,6 +849,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
45983 buf->result = -EOVERFLOW;
45984 return -EOVERFLOW;
45985 }
45986+
45987+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
45988+ return 0;
45989+
45990 buf->result++;
45991 dirent = buf->dirent;
45992 if (!access_ok(VERIFY_WRITE, dirent,
45993@@ -878,6 +883,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
45994
45995 buf.result = 0;
45996 buf.dirent = dirent;
45997+ buf.file = f.file;
45998
45999 error = vfs_readdir(f.file, compat_fillonedir, &buf);
46000 if (buf.result)
46001@@ -897,6 +903,7 @@ struct compat_linux_dirent {
46002 struct compat_getdents_callback {
46003 struct compat_linux_dirent __user *current_dir;
46004 struct compat_linux_dirent __user *previous;
46005+ struct file * file;
46006 int count;
46007 int error;
46008 };
46009@@ -918,6 +925,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
46010 buf->error = -EOVERFLOW;
46011 return -EOVERFLOW;
46012 }
46013+
46014+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
46015+ return 0;
46016+
46017 dirent = buf->previous;
46018 if (dirent) {
46019 if (__put_user(offset, &dirent->d_off))
46020@@ -963,6 +974,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
46021 buf.previous = NULL;
46022 buf.count = count;
46023 buf.error = 0;
46024+ buf.file = f.file;
46025
46026 error = vfs_readdir(f.file, compat_filldir, &buf);
46027 if (error >= 0)
46028@@ -983,6 +995,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
46029 struct compat_getdents_callback64 {
46030 struct linux_dirent64 __user *current_dir;
46031 struct linux_dirent64 __user *previous;
46032+ struct file * file;
46033 int count;
46034 int error;
46035 };
46036@@ -999,6 +1012,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
46037 buf->error = -EINVAL; /* only used if we fail.. */
46038 if (reclen > buf->count)
46039 return -EINVAL;
46040+
46041+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
46042+ return 0;
46043+
46044 dirent = buf->previous;
46045
46046 if (dirent) {
46047@@ -1048,13 +1065,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
46048 buf.previous = NULL;
46049 buf.count = count;
46050 buf.error = 0;
46051+ buf.file = f.file;
46052
46053 error = vfs_readdir(f.file, compat_filldir64, &buf);
46054 if (error >= 0)
46055 error = buf.error;
46056 lastdirent = buf.previous;
46057 if (lastdirent) {
46058- typeof(lastdirent->d_off) d_off = f.file->f_pos;
46059+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
46060 if (__put_user_unaligned(d_off, &lastdirent->d_off))
46061 error = -EFAULT;
46062 else
46063diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
46064index a81147e..20bf2b5 100644
46065--- a/fs/compat_binfmt_elf.c
46066+++ b/fs/compat_binfmt_elf.c
46067@@ -30,11 +30,13 @@
46068 #undef elf_phdr
46069 #undef elf_shdr
46070 #undef elf_note
46071+#undef elf_dyn
46072 #undef elf_addr_t
46073 #define elfhdr elf32_hdr
46074 #define elf_phdr elf32_phdr
46075 #define elf_shdr elf32_shdr
46076 #define elf_note elf32_note
46077+#define elf_dyn Elf32_Dyn
46078 #define elf_addr_t Elf32_Addr
46079
46080 /*
46081diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
46082index 4c6285f..b7a2411 100644
46083--- a/fs/compat_ioctl.c
46084+++ b/fs/compat_ioctl.c
46085@@ -623,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
46086 return -EFAULT;
46087 if (__get_user(udata, &ss32->iomem_base))
46088 return -EFAULT;
46089- ss.iomem_base = compat_ptr(udata);
46090+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
46091 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
46092 __get_user(ss.port_high, &ss32->port_high))
46093 return -EFAULT;
46094@@ -798,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
46095 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
46096 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
46097 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
46098- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
46099+ copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
46100 return -EFAULT;
46101
46102 return ioctl_preallocate(file, p);
46103@@ -1617,8 +1617,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
46104 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
46105 {
46106 unsigned int a, b;
46107- a = *(unsigned int *)p;
46108- b = *(unsigned int *)q;
46109+ a = *(const unsigned int *)p;
46110+ b = *(const unsigned int *)q;
46111 if (a > b)
46112 return 1;
46113 if (a < b)
46114diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
46115index 7414ae2..d98ad6d 100644
46116--- a/fs/configfs/dir.c
46117+++ b/fs/configfs/dir.c
46118@@ -1564,7 +1564,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
46119 }
46120 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
46121 struct configfs_dirent *next;
46122- const char * name;
46123+ const unsigned char * name;
46124+ char d_name[sizeof(next->s_dentry->d_iname)];
46125 int len;
46126 struct inode *inode = NULL;
46127
46128@@ -1574,7 +1575,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
46129 continue;
46130
46131 name = configfs_get_name(next);
46132- len = strlen(name);
46133+ if (next->s_dentry && name == next->s_dentry->d_iname) {
46134+ len = next->s_dentry->d_name.len;
46135+ memcpy(d_name, name, len);
46136+ name = d_name;
46137+ } else
46138+ len = strlen(name);
46139
46140 /*
46141 * We'll have a dentry and an inode for
46142diff --git a/fs/coredump.c b/fs/coredump.c
46143index ce47379..68c8e43 100644
46144--- a/fs/coredump.c
46145+++ b/fs/coredump.c
46146@@ -52,7 +52,7 @@ struct core_name {
46147 char *corename;
46148 int used, size;
46149 };
46150-static atomic_t call_count = ATOMIC_INIT(1);
46151+static atomic_unchecked_t call_count = ATOMIC_INIT(1);
46152
46153 /* The maximal length of core_pattern is also specified in sysctl.c */
46154
46155@@ -60,7 +60,7 @@ static int expand_corename(struct core_name *cn)
46156 {
46157 char *old_corename = cn->corename;
46158
46159- cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
46160+ cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
46161 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
46162
46163 if (!cn->corename) {
46164@@ -157,7 +157,7 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm)
46165 int pid_in_pattern = 0;
46166 int err = 0;
46167
46168- cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
46169+ cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
46170 cn->corename = kmalloc(cn->size, GFP_KERNEL);
46171 cn->used = 0;
46172
46173@@ -414,17 +414,17 @@ static void wait_for_dump_helpers(struct file *file)
46174 pipe = file->f_path.dentry->d_inode->i_pipe;
46175
46176 pipe_lock(pipe);
46177- pipe->readers++;
46178- pipe->writers--;
46179+ atomic_inc(&pipe->readers);
46180+ atomic_dec(&pipe->writers);
46181
46182- while ((pipe->readers > 1) && (!signal_pending(current))) {
46183+ while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
46184 wake_up_interruptible_sync(&pipe->wait);
46185 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
46186 pipe_wait(pipe);
46187 }
46188
46189- pipe->readers--;
46190- pipe->writers++;
46191+ atomic_dec(&pipe->readers);
46192+ atomic_inc(&pipe->writers);
46193 pipe_unlock(pipe);
46194
46195 }
46196@@ -471,7 +471,8 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
46197 int ispipe;
46198 struct files_struct *displaced;
46199 bool need_nonrelative = false;
46200- static atomic_t core_dump_count = ATOMIC_INIT(0);
46201+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
46202+ long signr = siginfo->si_signo;
46203 struct coredump_params cprm = {
46204 .siginfo = siginfo,
46205 .regs = regs,
46206@@ -484,7 +485,10 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
46207 .mm_flags = mm->flags,
46208 };
46209
46210- audit_core_dumps(siginfo->si_signo);
46211+ audit_core_dumps(signr);
46212+
46213+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
46214+ gr_handle_brute_attach(cprm.mm_flags);
46215
46216 binfmt = mm->binfmt;
46217 if (!binfmt || !binfmt->core_dump)
46218@@ -508,7 +512,7 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
46219 need_nonrelative = true;
46220 }
46221
46222- retval = coredump_wait(siginfo->si_signo, &core_state);
46223+ retval = coredump_wait(signr, &core_state);
46224 if (retval < 0)
46225 goto fail_creds;
46226
46227@@ -556,7 +560,7 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
46228 }
46229 cprm.limit = RLIM_INFINITY;
46230
46231- dump_count = atomic_inc_return(&core_dump_count);
46232+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
46233 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
46234 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
46235 task_tgid_vnr(current), current->comm);
46236@@ -583,6 +587,8 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
46237 } else {
46238 struct inode *inode;
46239
46240+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
46241+
46242 if (cprm.limit < binfmt->min_coredump)
46243 goto fail_unlock;
46244
46245@@ -640,7 +646,7 @@ close_fail:
46246 filp_close(cprm.file, NULL);
46247 fail_dropcount:
46248 if (ispipe)
46249- atomic_dec(&core_dump_count);
46250+ atomic_dec_unchecked(&core_dump_count);
46251 fail_unlock:
46252 kfree(cn.corename);
46253 fail_corename:
46254@@ -659,7 +665,7 @@ fail:
46255 */
46256 int dump_write(struct file *file, const void *addr, int nr)
46257 {
46258- return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
46259+ return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
46260 }
46261 EXPORT_SYMBOL(dump_write);
46262
46263diff --git a/fs/dcache.c b/fs/dcache.c
46264index 3a463d0..9f345c8 100644
46265--- a/fs/dcache.c
46266+++ b/fs/dcache.c
46267@@ -3164,7 +3164,7 @@ void __init vfs_caches_init(unsigned long mempages)
46268 mempages -= reserve;
46269
46270 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
46271- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
46272+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
46273
46274 dcache_init();
46275 inode_init();
46276diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
46277index b607d92..41fda09 100644
46278--- a/fs/debugfs/inode.c
46279+++ b/fs/debugfs/inode.c
46280@@ -416,7 +416,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
46281 */
46282 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
46283 {
46284+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
46285+ return __create_file(name, S_IFDIR | S_IRWXU,
46286+#else
46287 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
46288+#endif
46289 parent, NULL, NULL);
46290 }
46291 EXPORT_SYMBOL_GPL(debugfs_create_dir);
46292diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
46293index cc7709e..7e7211f 100644
46294--- a/fs/ecryptfs/inode.c
46295+++ b/fs/ecryptfs/inode.c
46296@@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
46297 old_fs = get_fs();
46298 set_fs(get_ds());
46299 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
46300- (char __user *)lower_buf,
46301+ (char __force_user *)lower_buf,
46302 PATH_MAX);
46303 set_fs(old_fs);
46304 if (rc < 0)
46305@@ -706,7 +706,7 @@ out:
46306 static void
46307 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
46308 {
46309- char *buf = nd_get_link(nd);
46310+ const char *buf = nd_get_link(nd);
46311 if (!IS_ERR(buf)) {
46312 /* Free the char* */
46313 kfree(buf);
46314diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
46315index 412e6ed..4292d22 100644
46316--- a/fs/ecryptfs/miscdev.c
46317+++ b/fs/ecryptfs/miscdev.c
46318@@ -315,7 +315,7 @@ check_list:
46319 goto out_unlock_msg_ctx;
46320 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
46321 if (msg_ctx->msg) {
46322- if (copy_to_user(&buf[i], packet_length, packet_length_size))
46323+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
46324 goto out_unlock_msg_ctx;
46325 i += packet_length_size;
46326 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
46327diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
46328index b2a34a1..162fa69 100644
46329--- a/fs/ecryptfs/read_write.c
46330+++ b/fs/ecryptfs/read_write.c
46331@@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
46332 return -EIO;
46333 fs_save = get_fs();
46334 set_fs(get_ds());
46335- rc = vfs_write(lower_file, data, size, &offset);
46336+ rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
46337 set_fs(fs_save);
46338 mark_inode_dirty_sync(ecryptfs_inode);
46339 return rc;
46340@@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
46341 return -EIO;
46342 fs_save = get_fs();
46343 set_fs(get_ds());
46344- rc = vfs_read(lower_file, data, size, &offset);
46345+ rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
46346 set_fs(fs_save);
46347 return rc;
46348 }
46349diff --git a/fs/exec.c b/fs/exec.c
46350index 0039055..03fb669 100644
46351--- a/fs/exec.c
46352+++ b/fs/exec.c
46353@@ -55,6 +55,16 @@
46354 #include <linux/pipe_fs_i.h>
46355 #include <linux/oom.h>
46356 #include <linux/compat.h>
46357+#include <linux/random.h>
46358+#include <linux/seq_file.h>
46359+#include <linux/coredump.h>
46360+
46361+#ifdef CONFIG_PAX_REFCOUNT
46362+#include <linux/kallsyms.h>
46363+#include <linux/kdebug.h>
46364+#endif
46365+
46366+#include <trace/events/fs.h>
46367
46368 #include <asm/uaccess.h>
46369 #include <asm/mmu_context.h>
46370@@ -66,6 +76,18 @@
46371
46372 #include <trace/events/sched.h>
46373
46374+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
46375+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
46376+{
46377+ 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");
46378+}
46379+#endif
46380+
46381+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
46382+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
46383+EXPORT_SYMBOL(pax_set_initial_flags_func);
46384+#endif
46385+
46386 int suid_dumpable = 0;
46387
46388 static LIST_HEAD(formats);
46389@@ -180,18 +202,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
46390 int write)
46391 {
46392 struct page *page;
46393- int ret;
46394
46395-#ifdef CONFIG_STACK_GROWSUP
46396- if (write) {
46397- ret = expand_downwards(bprm->vma, pos);
46398- if (ret < 0)
46399- return NULL;
46400- }
46401-#endif
46402- ret = get_user_pages(current, bprm->mm, pos,
46403- 1, write, 1, &page, NULL);
46404- if (ret <= 0)
46405+ if (0 > expand_downwards(bprm->vma, pos))
46406+ return NULL;
46407+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
46408 return NULL;
46409
46410 if (write) {
46411@@ -207,6 +221,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
46412 if (size <= ARG_MAX)
46413 return page;
46414
46415+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46416+ // only allow 512KB for argv+env on suid/sgid binaries
46417+ // to prevent easy ASLR exhaustion
46418+ if (((bprm->cred->euid != current_euid()) ||
46419+ (bprm->cred->egid != current_egid())) &&
46420+ (size > (512 * 1024))) {
46421+ put_page(page);
46422+ return NULL;
46423+ }
46424+#endif
46425+
46426 /*
46427 * Limit to 1/4-th the stack size for the argv+env strings.
46428 * This ensures that:
46429@@ -266,6 +291,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
46430 vma->vm_end = STACK_TOP_MAX;
46431 vma->vm_start = vma->vm_end - PAGE_SIZE;
46432 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
46433+
46434+#ifdef CONFIG_PAX_SEGMEXEC
46435+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
46436+#endif
46437+
46438 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
46439 INIT_LIST_HEAD(&vma->anon_vma_chain);
46440
46441@@ -276,6 +306,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
46442 mm->stack_vm = mm->total_vm = 1;
46443 up_write(&mm->mmap_sem);
46444 bprm->p = vma->vm_end - sizeof(void *);
46445+
46446+#ifdef CONFIG_PAX_RANDUSTACK
46447+ if (randomize_va_space)
46448+ bprm->p ^= random32() & ~PAGE_MASK;
46449+#endif
46450+
46451 return 0;
46452 err:
46453 up_write(&mm->mmap_sem);
46454@@ -384,19 +420,7 @@ err:
46455 return err;
46456 }
46457
46458-struct user_arg_ptr {
46459-#ifdef CONFIG_COMPAT
46460- bool is_compat;
46461-#endif
46462- union {
46463- const char __user *const __user *native;
46464-#ifdef CONFIG_COMPAT
46465- const compat_uptr_t __user *compat;
46466-#endif
46467- } ptr;
46468-};
46469-
46470-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
46471+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
46472 {
46473 const char __user *native;
46474
46475@@ -405,14 +429,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
46476 compat_uptr_t compat;
46477
46478 if (get_user(compat, argv.ptr.compat + nr))
46479- return ERR_PTR(-EFAULT);
46480+ return (const char __force_user *)ERR_PTR(-EFAULT);
46481
46482 return compat_ptr(compat);
46483 }
46484 #endif
46485
46486 if (get_user(native, argv.ptr.native + nr))
46487- return ERR_PTR(-EFAULT);
46488+ return (const char __force_user *)ERR_PTR(-EFAULT);
46489
46490 return native;
46491 }
46492@@ -431,7 +455,7 @@ static int count(struct user_arg_ptr argv, int max)
46493 if (!p)
46494 break;
46495
46496- if (IS_ERR(p))
46497+ if (IS_ERR((const char __force_kernel *)p))
46498 return -EFAULT;
46499
46500 if (i++ >= max)
46501@@ -465,7 +489,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
46502
46503 ret = -EFAULT;
46504 str = get_user_arg_ptr(argv, argc);
46505- if (IS_ERR(str))
46506+ if (IS_ERR((const char __force_kernel *)str))
46507 goto out;
46508
46509 len = strnlen_user(str, MAX_ARG_STRLEN);
46510@@ -547,7 +571,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
46511 int r;
46512 mm_segment_t oldfs = get_fs();
46513 struct user_arg_ptr argv = {
46514- .ptr.native = (const char __user *const __user *)__argv,
46515+ .ptr.native = (const char __force_user *const __force_user *)__argv,
46516 };
46517
46518 set_fs(KERNEL_DS);
46519@@ -582,7 +606,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
46520 unsigned long new_end = old_end - shift;
46521 struct mmu_gather tlb;
46522
46523- BUG_ON(new_start > new_end);
46524+ if (new_start >= new_end || new_start < mmap_min_addr)
46525+ return -ENOMEM;
46526
46527 /*
46528 * ensure there are no vmas between where we want to go
46529@@ -591,6 +616,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
46530 if (vma != find_vma(mm, new_start))
46531 return -EFAULT;
46532
46533+#ifdef CONFIG_PAX_SEGMEXEC
46534+ BUG_ON(pax_find_mirror_vma(vma));
46535+#endif
46536+
46537 /*
46538 * cover the whole range: [new_start, old_end)
46539 */
46540@@ -671,10 +700,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
46541 stack_top = arch_align_stack(stack_top);
46542 stack_top = PAGE_ALIGN(stack_top);
46543
46544- if (unlikely(stack_top < mmap_min_addr) ||
46545- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
46546- return -ENOMEM;
46547-
46548 stack_shift = vma->vm_end - stack_top;
46549
46550 bprm->p -= stack_shift;
46551@@ -686,8 +711,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
46552 bprm->exec -= stack_shift;
46553
46554 down_write(&mm->mmap_sem);
46555+
46556+ /* Move stack pages down in memory. */
46557+ if (stack_shift) {
46558+ ret = shift_arg_pages(vma, stack_shift);
46559+ if (ret)
46560+ goto out_unlock;
46561+ }
46562+
46563 vm_flags = VM_STACK_FLAGS;
46564
46565+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
46566+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
46567+ vm_flags &= ~VM_EXEC;
46568+
46569+#ifdef CONFIG_PAX_MPROTECT
46570+ if (mm->pax_flags & MF_PAX_MPROTECT)
46571+ vm_flags &= ~VM_MAYEXEC;
46572+#endif
46573+
46574+ }
46575+#endif
46576+
46577 /*
46578 * Adjust stack execute permissions; explicitly enable for
46579 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
46580@@ -706,13 +751,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
46581 goto out_unlock;
46582 BUG_ON(prev != vma);
46583
46584- /* Move stack pages down in memory. */
46585- if (stack_shift) {
46586- ret = shift_arg_pages(vma, stack_shift);
46587- if (ret)
46588- goto out_unlock;
46589- }
46590-
46591 /* mprotect_fixup is overkill to remove the temporary stack flags */
46592 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
46593
46594@@ -771,6 +809,8 @@ struct file *open_exec(const char *name)
46595
46596 fsnotify_open(file);
46597
46598+ trace_open_exec(name);
46599+
46600 err = deny_write_access(file);
46601 if (err)
46602 goto exit;
46603@@ -794,7 +834,7 @@ int kernel_read(struct file *file, loff_t offset,
46604 old_fs = get_fs();
46605 set_fs(get_ds());
46606 /* The cast to a user pointer is valid due to the set_fs() */
46607- result = vfs_read(file, (void __user *)addr, count, &pos);
46608+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
46609 set_fs(old_fs);
46610 return result;
46611 }
46612@@ -1231,7 +1271,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
46613 }
46614 rcu_read_unlock();
46615
46616- if (p->fs->users > n_fs) {
46617+ if (atomic_read(&p->fs->users) > n_fs) {
46618 bprm->unsafe |= LSM_UNSAFE_SHARE;
46619 } else {
46620 res = -EAGAIN;
46621@@ -1434,6 +1474,28 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
46622
46623 EXPORT_SYMBOL(search_binary_handler);
46624
46625+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46626+static DEFINE_PER_CPU(u64, exec_counter);
46627+static int __init init_exec_counters(void)
46628+{
46629+ unsigned int cpu;
46630+
46631+ for_each_possible_cpu(cpu) {
46632+ per_cpu(exec_counter, cpu) = (u64)cpu;
46633+ }
46634+
46635+ return 0;
46636+}
46637+early_initcall(init_exec_counters);
46638+static inline void increment_exec_counter(void)
46639+{
46640+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
46641+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
46642+}
46643+#else
46644+static inline void increment_exec_counter(void) {}
46645+#endif
46646+
46647 /*
46648 * sys_execve() executes a new program.
46649 */
46650@@ -1442,6 +1504,11 @@ static int do_execve_common(const char *filename,
46651 struct user_arg_ptr envp,
46652 struct pt_regs *regs)
46653 {
46654+#ifdef CONFIG_GRKERNSEC
46655+ struct file *old_exec_file;
46656+ struct acl_subject_label *old_acl;
46657+ struct rlimit old_rlim[RLIM_NLIMITS];
46658+#endif
46659 struct linux_binprm *bprm;
46660 struct file *file;
46661 struct files_struct *displaced;
46662@@ -1449,6 +1516,8 @@ static int do_execve_common(const char *filename,
46663 int retval;
46664 const struct cred *cred = current_cred();
46665
46666+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
46667+
46668 /*
46669 * We move the actual failure in case of RLIMIT_NPROC excess from
46670 * set*uid() to execve() because too many poorly written programs
46671@@ -1489,12 +1558,27 @@ static int do_execve_common(const char *filename,
46672 if (IS_ERR(file))
46673 goto out_unmark;
46674
46675+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
46676+ retval = -EPERM;
46677+ goto out_file;
46678+ }
46679+
46680 sched_exec();
46681
46682 bprm->file = file;
46683 bprm->filename = filename;
46684 bprm->interp = filename;
46685
46686+ if (gr_process_user_ban()) {
46687+ retval = -EPERM;
46688+ goto out_file;
46689+ }
46690+
46691+ if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
46692+ retval = -EACCES;
46693+ goto out_file;
46694+ }
46695+
46696 retval = bprm_mm_init(bprm);
46697 if (retval)
46698 goto out_file;
46699@@ -1511,24 +1595,65 @@ static int do_execve_common(const char *filename,
46700 if (retval < 0)
46701 goto out;
46702
46703+#ifdef CONFIG_GRKERNSEC
46704+ old_acl = current->acl;
46705+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
46706+ old_exec_file = current->exec_file;
46707+ get_file(file);
46708+ current->exec_file = file;
46709+#endif
46710+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46711+ /* limit suid stack to 8MB
46712+ we saved the old limits above and will restore them if this exec fails
46713+ */
46714+ if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
46715+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
46716+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
46717+#endif
46718+
46719+ if (!gr_tpe_allow(file)) {
46720+ retval = -EACCES;
46721+ goto out_fail;
46722+ }
46723+
46724+ if (gr_check_crash_exec(file)) {
46725+ retval = -EACCES;
46726+ goto out_fail;
46727+ }
46728+
46729+ retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
46730+ bprm->unsafe);
46731+ if (retval < 0)
46732+ goto out_fail;
46733+
46734 retval = copy_strings_kernel(1, &bprm->filename, bprm);
46735 if (retval < 0)
46736- goto out;
46737+ goto out_fail;
46738
46739 bprm->exec = bprm->p;
46740 retval = copy_strings(bprm->envc, envp, bprm);
46741 if (retval < 0)
46742- goto out;
46743+ goto out_fail;
46744
46745 retval = copy_strings(bprm->argc, argv, bprm);
46746 if (retval < 0)
46747- goto out;
46748+ goto out_fail;
46749+
46750+ gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
46751+
46752+ gr_handle_exec_args(bprm, argv);
46753
46754 retval = search_binary_handler(bprm,regs);
46755 if (retval < 0)
46756- goto out;
46757+ goto out_fail;
46758+#ifdef CONFIG_GRKERNSEC
46759+ if (old_exec_file)
46760+ fput(old_exec_file);
46761+#endif
46762
46763 /* execve succeeded */
46764+
46765+ increment_exec_counter();
46766 current->fs->in_exec = 0;
46767 current->in_execve = 0;
46768 acct_update_integrals(current);
46769@@ -1537,6 +1662,14 @@ static int do_execve_common(const char *filename,
46770 put_files_struct(displaced);
46771 return retval;
46772
46773+out_fail:
46774+#ifdef CONFIG_GRKERNSEC
46775+ current->acl = old_acl;
46776+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
46777+ fput(current->exec_file);
46778+ current->exec_file = old_exec_file;
46779+#endif
46780+
46781 out:
46782 if (bprm->mm) {
46783 acct_arg_size(bprm, 0);
46784@@ -1712,3 +1845,253 @@ int kernel_execve(const char *filename,
46785 ret_from_kernel_execve(p);
46786 }
46787 #endif
46788+
46789+int pax_check_flags(unsigned long *flags)
46790+{
46791+ int retval = 0;
46792+
46793+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
46794+ if (*flags & MF_PAX_SEGMEXEC)
46795+ {
46796+ *flags &= ~MF_PAX_SEGMEXEC;
46797+ retval = -EINVAL;
46798+ }
46799+#endif
46800+
46801+ if ((*flags & MF_PAX_PAGEEXEC)
46802+
46803+#ifdef CONFIG_PAX_PAGEEXEC
46804+ && (*flags & MF_PAX_SEGMEXEC)
46805+#endif
46806+
46807+ )
46808+ {
46809+ *flags &= ~MF_PAX_PAGEEXEC;
46810+ retval = -EINVAL;
46811+ }
46812+
46813+ if ((*flags & MF_PAX_MPROTECT)
46814+
46815+#ifdef CONFIG_PAX_MPROTECT
46816+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
46817+#endif
46818+
46819+ )
46820+ {
46821+ *flags &= ~MF_PAX_MPROTECT;
46822+ retval = -EINVAL;
46823+ }
46824+
46825+ if ((*flags & MF_PAX_EMUTRAMP)
46826+
46827+#ifdef CONFIG_PAX_EMUTRAMP
46828+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
46829+#endif
46830+
46831+ )
46832+ {
46833+ *flags &= ~MF_PAX_EMUTRAMP;
46834+ retval = -EINVAL;
46835+ }
46836+
46837+ return retval;
46838+}
46839+
46840+EXPORT_SYMBOL(pax_check_flags);
46841+
46842+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
46843+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
46844+{
46845+ struct task_struct *tsk = current;
46846+ struct mm_struct *mm = current->mm;
46847+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
46848+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
46849+ char *path_exec = NULL;
46850+ char *path_fault = NULL;
46851+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
46852+ siginfo_t info = { };
46853+
46854+ if (buffer_exec && buffer_fault) {
46855+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
46856+
46857+ down_read(&mm->mmap_sem);
46858+ vma = mm->mmap;
46859+ while (vma && (!vma_exec || !vma_fault)) {
46860+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
46861+ vma_exec = vma;
46862+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
46863+ vma_fault = vma;
46864+ vma = vma->vm_next;
46865+ }
46866+ if (vma_exec) {
46867+ path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
46868+ if (IS_ERR(path_exec))
46869+ path_exec = "<path too long>";
46870+ else {
46871+ path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
46872+ if (path_exec) {
46873+ *path_exec = 0;
46874+ path_exec = buffer_exec;
46875+ } else
46876+ path_exec = "<path too long>";
46877+ }
46878+ }
46879+ if (vma_fault) {
46880+ start = vma_fault->vm_start;
46881+ end = vma_fault->vm_end;
46882+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
46883+ if (vma_fault->vm_file) {
46884+ path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
46885+ if (IS_ERR(path_fault))
46886+ path_fault = "<path too long>";
46887+ else {
46888+ path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
46889+ if (path_fault) {
46890+ *path_fault = 0;
46891+ path_fault = buffer_fault;
46892+ } else
46893+ path_fault = "<path too long>";
46894+ }
46895+ } else
46896+ path_fault = "<anonymous mapping>";
46897+ }
46898+ up_read(&mm->mmap_sem);
46899+ }
46900+ if (tsk->signal->curr_ip)
46901+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
46902+ else
46903+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
46904+ printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
46905+ "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
46906+ task_uid(tsk), task_euid(tsk), pc, sp);
46907+ free_page((unsigned long)buffer_exec);
46908+ free_page((unsigned long)buffer_fault);
46909+ pax_report_insns(regs, pc, sp);
46910+ info.si_signo = SIGKILL;
46911+ info.si_errno = 0;
46912+ info.si_code = SI_KERNEL;
46913+ info.si_pid = 0;
46914+ info.si_uid = 0;
46915+ do_coredump(&info, regs);
46916+}
46917+#endif
46918+
46919+#ifdef CONFIG_PAX_REFCOUNT
46920+void pax_report_refcount_overflow(struct pt_regs *regs)
46921+{
46922+ if (current->signal->curr_ip)
46923+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
46924+ &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
46925+ else
46926+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
46927+ current->comm, task_pid_nr(current), current_uid(), current_euid());
46928+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
46929+ show_regs(regs);
46930+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
46931+}
46932+#endif
46933+
46934+#ifdef CONFIG_PAX_USERCOPY
46935+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
46936+static noinline int check_stack_object(const void *obj, unsigned long len)
46937+{
46938+ const void * const stack = task_stack_page(current);
46939+ const void * const stackend = stack + THREAD_SIZE;
46940+
46941+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
46942+ const void *frame = NULL;
46943+ const void *oldframe;
46944+#endif
46945+
46946+ if (obj + len < obj)
46947+ return -1;
46948+
46949+ if (obj + len <= stack || stackend <= obj)
46950+ return 0;
46951+
46952+ if (obj < stack || stackend < obj + len)
46953+ return -1;
46954+
46955+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
46956+ oldframe = __builtin_frame_address(1);
46957+ if (oldframe)
46958+ frame = __builtin_frame_address(2);
46959+ /*
46960+ low ----------------------------------------------> high
46961+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
46962+ ^----------------^
46963+ allow copies only within here
46964+ */
46965+ while (stack <= frame && frame < stackend) {
46966+ /* if obj + len extends past the last frame, this
46967+ check won't pass and the next frame will be 0,
46968+ causing us to bail out and correctly report
46969+ the copy as invalid
46970+ */
46971+ if (obj + len <= frame)
46972+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
46973+ oldframe = frame;
46974+ frame = *(const void * const *)frame;
46975+ }
46976+ return -1;
46977+#else
46978+ return 1;
46979+#endif
46980+}
46981+
46982+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
46983+{
46984+ if (current->signal->curr_ip)
46985+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
46986+ &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
46987+ else
46988+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
46989+ to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
46990+ dump_stack();
46991+ gr_handle_kernel_exploit();
46992+ do_group_exit(SIGKILL);
46993+}
46994+#endif
46995+
46996+void check_object_size(const void *ptr, unsigned long n, bool to)
46997+{
46998+
46999+#ifdef CONFIG_PAX_USERCOPY
47000+ const char *type;
47001+
47002+ if (!n)
47003+ return;
47004+
47005+ type = check_heap_object(ptr, n);
47006+ if (!type) {
47007+ if (check_stack_object(ptr, n) != -1)
47008+ return;
47009+ type = "<process stack>";
47010+ }
47011+
47012+ pax_report_usercopy(ptr, n, to, type);
47013+#endif
47014+
47015+}
47016+EXPORT_SYMBOL(check_object_size);
47017+
47018+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
47019+void pax_track_stack(void)
47020+{
47021+ unsigned long sp = (unsigned long)&sp;
47022+ if (sp < current_thread_info()->lowest_stack &&
47023+ sp > (unsigned long)task_stack_page(current))
47024+ current_thread_info()->lowest_stack = sp;
47025+}
47026+EXPORT_SYMBOL(pax_track_stack);
47027+#endif
47028+
47029+#ifdef CONFIG_PAX_SIZE_OVERFLOW
47030+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
47031+{
47032+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
47033+ dump_stack();
47034+ do_group_exit(SIGKILL);
47035+}
47036+EXPORT_SYMBOL(report_size_overflow);
47037+#endif
47038diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
47039index 2616d0e..2ffdec9 100644
47040--- a/fs/ext2/balloc.c
47041+++ b/fs/ext2/balloc.c
47042@@ -1190,10 +1190,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
47043
47044 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
47045 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
47046- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
47047+ if (free_blocks < root_blocks + 1 &&
47048 !uid_eq(sbi->s_resuid, current_fsuid()) &&
47049 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
47050- !in_group_p (sbi->s_resgid))) {
47051+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
47052 return 0;
47053 }
47054 return 1;
47055diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
47056index 22548f5..41521d8 100644
47057--- a/fs/ext3/balloc.c
47058+++ b/fs/ext3/balloc.c
47059@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
47060
47061 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
47062 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
47063- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
47064+ if (free_blocks < root_blocks + 1 &&
47065 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
47066 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
47067- !in_group_p (sbi->s_resgid))) {
47068+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
47069 return 0;
47070 }
47071 return 1;
47072diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
47073index cf18217..8f6b9c3 100644
47074--- a/fs/ext4/balloc.c
47075+++ b/fs/ext4/balloc.c
47076@@ -498,8 +498,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
47077 /* Hm, nope. Are (enough) root reserved clusters available? */
47078 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
47079 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
47080- capable(CAP_SYS_RESOURCE) ||
47081- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
47082+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
47083+ capable_nolog(CAP_SYS_RESOURCE)) {
47084
47085 if (free_clusters >= (nclusters + dirty_clusters))
47086 return 1;
47087diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
47088index 3c20de1..6ff2460 100644
47089--- a/fs/ext4/ext4.h
47090+++ b/fs/ext4/ext4.h
47091@@ -1247,19 +1247,19 @@ struct ext4_sb_info {
47092 unsigned long s_mb_last_start;
47093
47094 /* stats for buddy allocator */
47095- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
47096- atomic_t s_bal_success; /* we found long enough chunks */
47097- atomic_t s_bal_allocated; /* in blocks */
47098- atomic_t s_bal_ex_scanned; /* total extents scanned */
47099- atomic_t s_bal_goals; /* goal hits */
47100- atomic_t s_bal_breaks; /* too long searches */
47101- atomic_t s_bal_2orders; /* 2^order hits */
47102+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
47103+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
47104+ atomic_unchecked_t s_bal_allocated; /* in blocks */
47105+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
47106+ atomic_unchecked_t s_bal_goals; /* goal hits */
47107+ atomic_unchecked_t s_bal_breaks; /* too long searches */
47108+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
47109 spinlock_t s_bal_lock;
47110 unsigned long s_mb_buddies_generated;
47111 unsigned long long s_mb_generation_time;
47112- atomic_t s_mb_lost_chunks;
47113- atomic_t s_mb_preallocated;
47114- atomic_t s_mb_discarded;
47115+ atomic_unchecked_t s_mb_lost_chunks;
47116+ atomic_unchecked_t s_mb_preallocated;
47117+ atomic_unchecked_t s_mb_discarded;
47118 atomic_t s_lock_busy;
47119
47120 /* locality groups */
47121diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c
47122index 3a100e7..c7efa88 100644
47123--- a/fs/ext4/ialloc.c
47124+++ b/fs/ext4/ialloc.c
47125@@ -762,7 +762,6 @@ got:
47126
47127 BUFFER_TRACE(block_bitmap_bh, "dirty block bitmap");
47128 err = ext4_handle_dirty_metadata(handle, NULL, block_bitmap_bh);
47129- brelse(block_bitmap_bh);
47130
47131 /* recheck and clear flag under lock if we still need to */
47132 ext4_lock_group(sb, group);
47133@@ -775,6 +774,7 @@ got:
47134 ext4_group_desc_csum_set(sb, group, gdp);
47135 }
47136 ext4_unlock_group(sb, group);
47137+ brelse(block_bitmap_bh);
47138
47139 if (err)
47140 goto fail;
47141diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
47142index b3c243b..772c318 100644
47143--- a/fs/ext4/inode.c
47144+++ b/fs/ext4/inode.c
47145@@ -1503,6 +1503,7 @@ static void ext4_da_block_invalidatepages(struct mpage_da_data *mpd)
47146
47147 index = mpd->first_page;
47148 end = mpd->next_page - 1;
47149+ pagevec_init(&pvec, 0);
47150 while (index <= end) {
47151 nr_pages = pagevec_lookup(&pvec, mapping, index, PAGEVEC_SIZE);
47152 if (nr_pages == 0)
47153diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
47154index 526e553..3f2de85 100644
47155--- a/fs/ext4/mballoc.c
47156+++ b/fs/ext4/mballoc.c
47157@@ -1747,7 +1747,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
47158 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
47159
47160 if (EXT4_SB(sb)->s_mb_stats)
47161- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
47162+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
47163
47164 break;
47165 }
47166@@ -2044,7 +2044,7 @@ repeat:
47167 ac->ac_status = AC_STATUS_CONTINUE;
47168 ac->ac_flags |= EXT4_MB_HINT_FIRST;
47169 cr = 3;
47170- atomic_inc(&sbi->s_mb_lost_chunks);
47171+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
47172 goto repeat;
47173 }
47174 }
47175@@ -2552,25 +2552,25 @@ int ext4_mb_release(struct super_block *sb)
47176 if (sbi->s_mb_stats) {
47177 ext4_msg(sb, KERN_INFO,
47178 "mballoc: %u blocks %u reqs (%u success)",
47179- atomic_read(&sbi->s_bal_allocated),
47180- atomic_read(&sbi->s_bal_reqs),
47181- atomic_read(&sbi->s_bal_success));
47182+ atomic_read_unchecked(&sbi->s_bal_allocated),
47183+ atomic_read_unchecked(&sbi->s_bal_reqs),
47184+ atomic_read_unchecked(&sbi->s_bal_success));
47185 ext4_msg(sb, KERN_INFO,
47186 "mballoc: %u extents scanned, %u goal hits, "
47187 "%u 2^N hits, %u breaks, %u lost",
47188- atomic_read(&sbi->s_bal_ex_scanned),
47189- atomic_read(&sbi->s_bal_goals),
47190- atomic_read(&sbi->s_bal_2orders),
47191- atomic_read(&sbi->s_bal_breaks),
47192- atomic_read(&sbi->s_mb_lost_chunks));
47193+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
47194+ atomic_read_unchecked(&sbi->s_bal_goals),
47195+ atomic_read_unchecked(&sbi->s_bal_2orders),
47196+ atomic_read_unchecked(&sbi->s_bal_breaks),
47197+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
47198 ext4_msg(sb, KERN_INFO,
47199 "mballoc: %lu generated and it took %Lu",
47200 sbi->s_mb_buddies_generated,
47201 sbi->s_mb_generation_time);
47202 ext4_msg(sb, KERN_INFO,
47203 "mballoc: %u preallocated, %u discarded",
47204- atomic_read(&sbi->s_mb_preallocated),
47205- atomic_read(&sbi->s_mb_discarded));
47206+ atomic_read_unchecked(&sbi->s_mb_preallocated),
47207+ atomic_read_unchecked(&sbi->s_mb_discarded));
47208 }
47209
47210 free_percpu(sbi->s_locality_groups);
47211@@ -3052,16 +3052,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
47212 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
47213
47214 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
47215- atomic_inc(&sbi->s_bal_reqs);
47216- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
47217+ atomic_inc_unchecked(&sbi->s_bal_reqs);
47218+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
47219 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
47220- atomic_inc(&sbi->s_bal_success);
47221- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
47222+ atomic_inc_unchecked(&sbi->s_bal_success);
47223+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
47224 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
47225 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
47226- atomic_inc(&sbi->s_bal_goals);
47227+ atomic_inc_unchecked(&sbi->s_bal_goals);
47228 if (ac->ac_found > sbi->s_mb_max_to_scan)
47229- atomic_inc(&sbi->s_bal_breaks);
47230+ atomic_inc_unchecked(&sbi->s_bal_breaks);
47231 }
47232
47233 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
47234@@ -3461,7 +3461,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
47235 trace_ext4_mb_new_inode_pa(ac, pa);
47236
47237 ext4_mb_use_inode_pa(ac, pa);
47238- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
47239+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
47240
47241 ei = EXT4_I(ac->ac_inode);
47242 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
47243@@ -3521,7 +3521,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
47244 trace_ext4_mb_new_group_pa(ac, pa);
47245
47246 ext4_mb_use_group_pa(ac, pa);
47247- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
47248+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
47249
47250 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
47251 lg = ac->ac_lg;
47252@@ -3610,7 +3610,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
47253 * from the bitmap and continue.
47254 */
47255 }
47256- atomic_add(free, &sbi->s_mb_discarded);
47257+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
47258
47259 return err;
47260 }
47261@@ -3628,7 +3628,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
47262 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
47263 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
47264 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
47265- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
47266+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
47267 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
47268
47269 return 0;
47270diff --git a/fs/ext4/super.c b/fs/ext4/super.c
47271index 80928f7..c3f2b1f 100644
47272--- a/fs/ext4/super.c
47273+++ b/fs/ext4/super.c
47274@@ -3202,7 +3202,6 @@ int ext4_calculate_overhead(struct super_block *sb)
47275 ext4_fsblk_t overhead = 0;
47276 char *buf = (char *) get_zeroed_page(GFP_KERNEL);
47277
47278- memset(buf, 0, PAGE_SIZE);
47279 if (!buf)
47280 return -ENOMEM;
47281
47282diff --git a/fs/fcntl.c b/fs/fcntl.c
47283index 71a600a..20d87b1 100644
47284--- a/fs/fcntl.c
47285+++ b/fs/fcntl.c
47286@@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
47287 if (err)
47288 return err;
47289
47290+ if (gr_handle_chroot_fowner(pid, type))
47291+ return -ENOENT;
47292+ if (gr_check_protected_task_fowner(pid, type))
47293+ return -EACCES;
47294+
47295 f_modown(filp, pid, type, force);
47296 return 0;
47297 }
47298diff --git a/fs/fifo.c b/fs/fifo.c
47299index cf6f434..3d7942c 100644
47300--- a/fs/fifo.c
47301+++ b/fs/fifo.c
47302@@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
47303 */
47304 filp->f_op = &read_pipefifo_fops;
47305 pipe->r_counter++;
47306- if (pipe->readers++ == 0)
47307+ if (atomic_inc_return(&pipe->readers) == 1)
47308 wake_up_partner(inode);
47309
47310- if (!pipe->writers) {
47311+ if (!atomic_read(&pipe->writers)) {
47312 if ((filp->f_flags & O_NONBLOCK)) {
47313 /* suppress POLLHUP until we have
47314 * seen a writer */
47315@@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
47316 * errno=ENXIO when there is no process reading the FIFO.
47317 */
47318 ret = -ENXIO;
47319- if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
47320+ if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
47321 goto err;
47322
47323 filp->f_op = &write_pipefifo_fops;
47324 pipe->w_counter++;
47325- if (!pipe->writers++)
47326+ if (atomic_inc_return(&pipe->writers) == 1)
47327 wake_up_partner(inode);
47328
47329- if (!pipe->readers) {
47330+ if (!atomic_read(&pipe->readers)) {
47331 if (wait_for_partner(inode, &pipe->r_counter))
47332 goto err_wr;
47333 }
47334@@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
47335 */
47336 filp->f_op = &rdwr_pipefifo_fops;
47337
47338- pipe->readers++;
47339- pipe->writers++;
47340+ atomic_inc(&pipe->readers);
47341+ atomic_inc(&pipe->writers);
47342 pipe->r_counter++;
47343 pipe->w_counter++;
47344- if (pipe->readers == 1 || pipe->writers == 1)
47345+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
47346 wake_up_partner(inode);
47347 break;
47348
47349@@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
47350 return 0;
47351
47352 err_rd:
47353- if (!--pipe->readers)
47354+ if (atomic_dec_and_test(&pipe->readers))
47355 wake_up_interruptible(&pipe->wait);
47356 ret = -ERESTARTSYS;
47357 goto err;
47358
47359 err_wr:
47360- if (!--pipe->writers)
47361+ if (atomic_dec_and_test(&pipe->writers))
47362 wake_up_interruptible(&pipe->wait);
47363 ret = -ERESTARTSYS;
47364 goto err;
47365
47366 err:
47367- if (!pipe->readers && !pipe->writers)
47368+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
47369 free_pipe_info(inode);
47370
47371 err_nocleanup:
47372diff --git a/fs/file.c b/fs/file.c
47373index eff2316..8c8930c 100644
47374--- a/fs/file.c
47375+++ b/fs/file.c
47376@@ -16,6 +16,7 @@
47377 #include <linux/slab.h>
47378 #include <linux/vmalloc.h>
47379 #include <linux/file.h>
47380+#include <linux/security.h>
47381 #include <linux/fdtable.h>
47382 #include <linux/bitops.h>
47383 #include <linux/interrupt.h>
47384@@ -898,6 +899,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
47385 if (!file)
47386 return __close_fd(files, fd);
47387
47388+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
47389 if (fd >= rlimit(RLIMIT_NOFILE))
47390 return -EBADF;
47391
47392@@ -924,6 +926,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
47393 if (unlikely(oldfd == newfd))
47394 return -EINVAL;
47395
47396+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
47397 if (newfd >= rlimit(RLIMIT_NOFILE))
47398 return -EBADF;
47399
47400@@ -979,6 +982,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
47401 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
47402 {
47403 int err;
47404+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
47405 if (from >= rlimit(RLIMIT_NOFILE))
47406 return -EINVAL;
47407 err = alloc_fd(from, flags);
47408diff --git a/fs/filesystems.c b/fs/filesystems.c
47409index da165f6..3671bdb 100644
47410--- a/fs/filesystems.c
47411+++ b/fs/filesystems.c
47412@@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
47413 int len = dot ? dot - name : strlen(name);
47414
47415 fs = __get_fs_type(name, len);
47416+
47417+#ifdef CONFIG_GRKERNSEC_MODHARDEN
47418+ if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
47419+#else
47420 if (!fs && (request_module("%.*s", len, name) == 0))
47421+#endif
47422 fs = __get_fs_type(name, len);
47423
47424 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
47425diff --git a/fs/fs_struct.c b/fs/fs_struct.c
47426index 5df4775..f656176 100644
47427--- a/fs/fs_struct.c
47428+++ b/fs/fs_struct.c
47429@@ -4,6 +4,7 @@
47430 #include <linux/path.h>
47431 #include <linux/slab.h>
47432 #include <linux/fs_struct.h>
47433+#include <linux/grsecurity.h>
47434 #include "internal.h"
47435
47436 /*
47437@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
47438 write_seqcount_begin(&fs->seq);
47439 old_root = fs->root;
47440 fs->root = *path;
47441+ gr_set_chroot_entries(current, path);
47442 write_seqcount_end(&fs->seq);
47443 spin_unlock(&fs->lock);
47444 if (old_root.dentry)
47445@@ -53,6 +55,21 @@ static inline int replace_path(struct path *p, const struct path *old, const str
47446 return 1;
47447 }
47448
47449+static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
47450+{
47451+ if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
47452+ return 0;
47453+ *p = *new;
47454+
47455+ /* This function is only called from pivot_root(). Leave our
47456+ gr_chroot_dentry and is_chrooted flags as-is, so that a
47457+ pivoted root isn't treated as a chroot
47458+ */
47459+ //gr_set_chroot_entries(task, new);
47460+
47461+ return 1;
47462+}
47463+
47464 void chroot_fs_refs(struct path *old_root, struct path *new_root)
47465 {
47466 struct task_struct *g, *p;
47467@@ -67,7 +84,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
47468 int hits = 0;
47469 spin_lock(&fs->lock);
47470 write_seqcount_begin(&fs->seq);
47471- hits += replace_path(&fs->root, old_root, new_root);
47472+ hits += replace_root_path(p, &fs->root, old_root, new_root);
47473 hits += replace_path(&fs->pwd, old_root, new_root);
47474 write_seqcount_end(&fs->seq);
47475 while (hits--) {
47476@@ -94,12 +111,15 @@ void exit_fs(struct task_struct *tsk)
47477 {
47478 struct fs_struct *fs = tsk->fs;
47479
47480+ gr_put_exec_file(tsk);
47481+
47482 if (fs) {
47483 int kill;
47484 task_lock(tsk);
47485 spin_lock(&fs->lock);
47486 tsk->fs = NULL;
47487- kill = !--fs->users;
47488+ gr_clear_chroot_entries(tsk);
47489+ kill = !atomic_dec_return(&fs->users);
47490 spin_unlock(&fs->lock);
47491 task_unlock(tsk);
47492 if (kill)
47493@@ -112,7 +132,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
47494 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
47495 /* We don't need to lock fs - think why ;-) */
47496 if (fs) {
47497- fs->users = 1;
47498+ atomic_set(&fs->users, 1);
47499 fs->in_exec = 0;
47500 spin_lock_init(&fs->lock);
47501 seqcount_init(&fs->seq);
47502@@ -121,6 +141,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
47503 spin_lock(&old->lock);
47504 fs->root = old->root;
47505 path_get(&fs->root);
47506+ /* instead of calling gr_set_chroot_entries here,
47507+ we call it from every caller of this function
47508+ */
47509 fs->pwd = old->pwd;
47510 path_get(&fs->pwd);
47511 spin_unlock(&old->lock);
47512@@ -139,8 +162,9 @@ int unshare_fs_struct(void)
47513
47514 task_lock(current);
47515 spin_lock(&fs->lock);
47516- kill = !--fs->users;
47517+ kill = !atomic_dec_return(&fs->users);
47518 current->fs = new_fs;
47519+ gr_set_chroot_entries(current, &new_fs->root);
47520 spin_unlock(&fs->lock);
47521 task_unlock(current);
47522
47523@@ -153,13 +177,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
47524
47525 int current_umask(void)
47526 {
47527- return current->fs->umask;
47528+ return current->fs->umask | gr_acl_umask();
47529 }
47530 EXPORT_SYMBOL(current_umask);
47531
47532 /* to be mentioned only in INIT_TASK */
47533 struct fs_struct init_fs = {
47534- .users = 1,
47535+ .users = ATOMIC_INIT(1),
47536 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
47537 .seq = SEQCNT_ZERO,
47538 .umask = 0022,
47539@@ -169,18 +193,21 @@ void daemonize_fs_struct(void)
47540 {
47541 struct fs_struct *fs = current->fs;
47542
47543+ gr_put_exec_file(current);
47544+
47545 if (fs) {
47546 int kill;
47547
47548 task_lock(current);
47549
47550 spin_lock(&init_fs.lock);
47551- init_fs.users++;
47552+ atomic_inc(&init_fs.users);
47553 spin_unlock(&init_fs.lock);
47554
47555 spin_lock(&fs->lock);
47556 current->fs = &init_fs;
47557- kill = !--fs->users;
47558+ gr_set_chroot_entries(current, &current->fs->root);
47559+ kill = !atomic_dec_return(&fs->users);
47560 spin_unlock(&fs->lock);
47561
47562 task_unlock(current);
47563diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
47564index 9905350..02eaec4 100644
47565--- a/fs/fscache/cookie.c
47566+++ b/fs/fscache/cookie.c
47567@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
47568 parent ? (char *) parent->def->name : "<no-parent>",
47569 def->name, netfs_data);
47570
47571- fscache_stat(&fscache_n_acquires);
47572+ fscache_stat_unchecked(&fscache_n_acquires);
47573
47574 /* if there's no parent cookie, then we don't create one here either */
47575 if (!parent) {
47576- fscache_stat(&fscache_n_acquires_null);
47577+ fscache_stat_unchecked(&fscache_n_acquires_null);
47578 _leave(" [no parent]");
47579 return NULL;
47580 }
47581@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
47582 /* allocate and initialise a cookie */
47583 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
47584 if (!cookie) {
47585- fscache_stat(&fscache_n_acquires_oom);
47586+ fscache_stat_unchecked(&fscache_n_acquires_oom);
47587 _leave(" [ENOMEM]");
47588 return NULL;
47589 }
47590@@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
47591
47592 switch (cookie->def->type) {
47593 case FSCACHE_COOKIE_TYPE_INDEX:
47594- fscache_stat(&fscache_n_cookie_index);
47595+ fscache_stat_unchecked(&fscache_n_cookie_index);
47596 break;
47597 case FSCACHE_COOKIE_TYPE_DATAFILE:
47598- fscache_stat(&fscache_n_cookie_data);
47599+ fscache_stat_unchecked(&fscache_n_cookie_data);
47600 break;
47601 default:
47602- fscache_stat(&fscache_n_cookie_special);
47603+ fscache_stat_unchecked(&fscache_n_cookie_special);
47604 break;
47605 }
47606
47607@@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
47608 if (fscache_acquire_non_index_cookie(cookie) < 0) {
47609 atomic_dec(&parent->n_children);
47610 __fscache_cookie_put(cookie);
47611- fscache_stat(&fscache_n_acquires_nobufs);
47612+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
47613 _leave(" = NULL");
47614 return NULL;
47615 }
47616 }
47617
47618- fscache_stat(&fscache_n_acquires_ok);
47619+ fscache_stat_unchecked(&fscache_n_acquires_ok);
47620 _leave(" = %p", cookie);
47621 return cookie;
47622 }
47623@@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
47624 cache = fscache_select_cache_for_object(cookie->parent);
47625 if (!cache) {
47626 up_read(&fscache_addremove_sem);
47627- fscache_stat(&fscache_n_acquires_no_cache);
47628+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
47629 _leave(" = -ENOMEDIUM [no cache]");
47630 return -ENOMEDIUM;
47631 }
47632@@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
47633 object = cache->ops->alloc_object(cache, cookie);
47634 fscache_stat_d(&fscache_n_cop_alloc_object);
47635 if (IS_ERR(object)) {
47636- fscache_stat(&fscache_n_object_no_alloc);
47637+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
47638 ret = PTR_ERR(object);
47639 goto error;
47640 }
47641
47642- fscache_stat(&fscache_n_object_alloc);
47643+ fscache_stat_unchecked(&fscache_n_object_alloc);
47644
47645 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
47646
47647@@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
47648 struct fscache_object *object;
47649 struct hlist_node *_p;
47650
47651- fscache_stat(&fscache_n_updates);
47652+ fscache_stat_unchecked(&fscache_n_updates);
47653
47654 if (!cookie) {
47655- fscache_stat(&fscache_n_updates_null);
47656+ fscache_stat_unchecked(&fscache_n_updates_null);
47657 _leave(" [no cookie]");
47658 return;
47659 }
47660@@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
47661 struct fscache_object *object;
47662 unsigned long event;
47663
47664- fscache_stat(&fscache_n_relinquishes);
47665+ fscache_stat_unchecked(&fscache_n_relinquishes);
47666 if (retire)
47667- fscache_stat(&fscache_n_relinquishes_retire);
47668+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
47669
47670 if (!cookie) {
47671- fscache_stat(&fscache_n_relinquishes_null);
47672+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
47673 _leave(" [no cookie]");
47674 return;
47675 }
47676@@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
47677
47678 /* wait for the cookie to finish being instantiated (or to fail) */
47679 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
47680- fscache_stat(&fscache_n_relinquishes_waitcrt);
47681+ fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
47682 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
47683 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
47684 }
47685diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
47686index f6aad48..88dcf26 100644
47687--- a/fs/fscache/internal.h
47688+++ b/fs/fscache/internal.h
47689@@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
47690 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
47691 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
47692
47693-extern atomic_t fscache_n_op_pend;
47694-extern atomic_t fscache_n_op_run;
47695-extern atomic_t fscache_n_op_enqueue;
47696-extern atomic_t fscache_n_op_deferred_release;
47697-extern atomic_t fscache_n_op_release;
47698-extern atomic_t fscache_n_op_gc;
47699-extern atomic_t fscache_n_op_cancelled;
47700-extern atomic_t fscache_n_op_rejected;
47701+extern atomic_unchecked_t fscache_n_op_pend;
47702+extern atomic_unchecked_t fscache_n_op_run;
47703+extern atomic_unchecked_t fscache_n_op_enqueue;
47704+extern atomic_unchecked_t fscache_n_op_deferred_release;
47705+extern atomic_unchecked_t fscache_n_op_release;
47706+extern atomic_unchecked_t fscache_n_op_gc;
47707+extern atomic_unchecked_t fscache_n_op_cancelled;
47708+extern atomic_unchecked_t fscache_n_op_rejected;
47709
47710-extern atomic_t fscache_n_attr_changed;
47711-extern atomic_t fscache_n_attr_changed_ok;
47712-extern atomic_t fscache_n_attr_changed_nobufs;
47713-extern atomic_t fscache_n_attr_changed_nomem;
47714-extern atomic_t fscache_n_attr_changed_calls;
47715+extern atomic_unchecked_t fscache_n_attr_changed;
47716+extern atomic_unchecked_t fscache_n_attr_changed_ok;
47717+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
47718+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
47719+extern atomic_unchecked_t fscache_n_attr_changed_calls;
47720
47721-extern atomic_t fscache_n_allocs;
47722-extern atomic_t fscache_n_allocs_ok;
47723-extern atomic_t fscache_n_allocs_wait;
47724-extern atomic_t fscache_n_allocs_nobufs;
47725-extern atomic_t fscache_n_allocs_intr;
47726-extern atomic_t fscache_n_allocs_object_dead;
47727-extern atomic_t fscache_n_alloc_ops;
47728-extern atomic_t fscache_n_alloc_op_waits;
47729+extern atomic_unchecked_t fscache_n_allocs;
47730+extern atomic_unchecked_t fscache_n_allocs_ok;
47731+extern atomic_unchecked_t fscache_n_allocs_wait;
47732+extern atomic_unchecked_t fscache_n_allocs_nobufs;
47733+extern atomic_unchecked_t fscache_n_allocs_intr;
47734+extern atomic_unchecked_t fscache_n_allocs_object_dead;
47735+extern atomic_unchecked_t fscache_n_alloc_ops;
47736+extern atomic_unchecked_t fscache_n_alloc_op_waits;
47737
47738-extern atomic_t fscache_n_retrievals;
47739-extern atomic_t fscache_n_retrievals_ok;
47740-extern atomic_t fscache_n_retrievals_wait;
47741-extern atomic_t fscache_n_retrievals_nodata;
47742-extern atomic_t fscache_n_retrievals_nobufs;
47743-extern atomic_t fscache_n_retrievals_intr;
47744-extern atomic_t fscache_n_retrievals_nomem;
47745-extern atomic_t fscache_n_retrievals_object_dead;
47746-extern atomic_t fscache_n_retrieval_ops;
47747-extern atomic_t fscache_n_retrieval_op_waits;
47748+extern atomic_unchecked_t fscache_n_retrievals;
47749+extern atomic_unchecked_t fscache_n_retrievals_ok;
47750+extern atomic_unchecked_t fscache_n_retrievals_wait;
47751+extern atomic_unchecked_t fscache_n_retrievals_nodata;
47752+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
47753+extern atomic_unchecked_t fscache_n_retrievals_intr;
47754+extern atomic_unchecked_t fscache_n_retrievals_nomem;
47755+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
47756+extern atomic_unchecked_t fscache_n_retrieval_ops;
47757+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
47758
47759-extern atomic_t fscache_n_stores;
47760-extern atomic_t fscache_n_stores_ok;
47761-extern atomic_t fscache_n_stores_again;
47762-extern atomic_t fscache_n_stores_nobufs;
47763-extern atomic_t fscache_n_stores_oom;
47764-extern atomic_t fscache_n_store_ops;
47765-extern atomic_t fscache_n_store_calls;
47766-extern atomic_t fscache_n_store_pages;
47767-extern atomic_t fscache_n_store_radix_deletes;
47768-extern atomic_t fscache_n_store_pages_over_limit;
47769+extern atomic_unchecked_t fscache_n_stores;
47770+extern atomic_unchecked_t fscache_n_stores_ok;
47771+extern atomic_unchecked_t fscache_n_stores_again;
47772+extern atomic_unchecked_t fscache_n_stores_nobufs;
47773+extern atomic_unchecked_t fscache_n_stores_oom;
47774+extern atomic_unchecked_t fscache_n_store_ops;
47775+extern atomic_unchecked_t fscache_n_store_calls;
47776+extern atomic_unchecked_t fscache_n_store_pages;
47777+extern atomic_unchecked_t fscache_n_store_radix_deletes;
47778+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
47779
47780-extern atomic_t fscache_n_store_vmscan_not_storing;
47781-extern atomic_t fscache_n_store_vmscan_gone;
47782-extern atomic_t fscache_n_store_vmscan_busy;
47783-extern atomic_t fscache_n_store_vmscan_cancelled;
47784+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
47785+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
47786+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
47787+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
47788
47789-extern atomic_t fscache_n_marks;
47790-extern atomic_t fscache_n_uncaches;
47791+extern atomic_unchecked_t fscache_n_marks;
47792+extern atomic_unchecked_t fscache_n_uncaches;
47793
47794-extern atomic_t fscache_n_acquires;
47795-extern atomic_t fscache_n_acquires_null;
47796-extern atomic_t fscache_n_acquires_no_cache;
47797-extern atomic_t fscache_n_acquires_ok;
47798-extern atomic_t fscache_n_acquires_nobufs;
47799-extern atomic_t fscache_n_acquires_oom;
47800+extern atomic_unchecked_t fscache_n_acquires;
47801+extern atomic_unchecked_t fscache_n_acquires_null;
47802+extern atomic_unchecked_t fscache_n_acquires_no_cache;
47803+extern atomic_unchecked_t fscache_n_acquires_ok;
47804+extern atomic_unchecked_t fscache_n_acquires_nobufs;
47805+extern atomic_unchecked_t fscache_n_acquires_oom;
47806
47807-extern atomic_t fscache_n_updates;
47808-extern atomic_t fscache_n_updates_null;
47809-extern atomic_t fscache_n_updates_run;
47810+extern atomic_unchecked_t fscache_n_updates;
47811+extern atomic_unchecked_t fscache_n_updates_null;
47812+extern atomic_unchecked_t fscache_n_updates_run;
47813
47814-extern atomic_t fscache_n_relinquishes;
47815-extern atomic_t fscache_n_relinquishes_null;
47816-extern atomic_t fscache_n_relinquishes_waitcrt;
47817-extern atomic_t fscache_n_relinquishes_retire;
47818+extern atomic_unchecked_t fscache_n_relinquishes;
47819+extern atomic_unchecked_t fscache_n_relinquishes_null;
47820+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
47821+extern atomic_unchecked_t fscache_n_relinquishes_retire;
47822
47823-extern atomic_t fscache_n_cookie_index;
47824-extern atomic_t fscache_n_cookie_data;
47825-extern atomic_t fscache_n_cookie_special;
47826+extern atomic_unchecked_t fscache_n_cookie_index;
47827+extern atomic_unchecked_t fscache_n_cookie_data;
47828+extern atomic_unchecked_t fscache_n_cookie_special;
47829
47830-extern atomic_t fscache_n_object_alloc;
47831-extern atomic_t fscache_n_object_no_alloc;
47832-extern atomic_t fscache_n_object_lookups;
47833-extern atomic_t fscache_n_object_lookups_negative;
47834-extern atomic_t fscache_n_object_lookups_positive;
47835-extern atomic_t fscache_n_object_lookups_timed_out;
47836-extern atomic_t fscache_n_object_created;
47837-extern atomic_t fscache_n_object_avail;
47838-extern atomic_t fscache_n_object_dead;
47839+extern atomic_unchecked_t fscache_n_object_alloc;
47840+extern atomic_unchecked_t fscache_n_object_no_alloc;
47841+extern atomic_unchecked_t fscache_n_object_lookups;
47842+extern atomic_unchecked_t fscache_n_object_lookups_negative;
47843+extern atomic_unchecked_t fscache_n_object_lookups_positive;
47844+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
47845+extern atomic_unchecked_t fscache_n_object_created;
47846+extern atomic_unchecked_t fscache_n_object_avail;
47847+extern atomic_unchecked_t fscache_n_object_dead;
47848
47849-extern atomic_t fscache_n_checkaux_none;
47850-extern atomic_t fscache_n_checkaux_okay;
47851-extern atomic_t fscache_n_checkaux_update;
47852-extern atomic_t fscache_n_checkaux_obsolete;
47853+extern atomic_unchecked_t fscache_n_checkaux_none;
47854+extern atomic_unchecked_t fscache_n_checkaux_okay;
47855+extern atomic_unchecked_t fscache_n_checkaux_update;
47856+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
47857
47858 extern atomic_t fscache_n_cop_alloc_object;
47859 extern atomic_t fscache_n_cop_lookup_object;
47860@@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
47861 atomic_inc(stat);
47862 }
47863
47864+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
47865+{
47866+ atomic_inc_unchecked(stat);
47867+}
47868+
47869 static inline void fscache_stat_d(atomic_t *stat)
47870 {
47871 atomic_dec(stat);
47872@@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
47873
47874 #define __fscache_stat(stat) (NULL)
47875 #define fscache_stat(stat) do {} while (0)
47876+#define fscache_stat_unchecked(stat) do {} while (0)
47877 #define fscache_stat_d(stat) do {} while (0)
47878 #endif
47879
47880diff --git a/fs/fscache/object.c b/fs/fscache/object.c
47881index b6b897c..0ffff9c 100644
47882--- a/fs/fscache/object.c
47883+++ b/fs/fscache/object.c
47884@@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
47885 /* update the object metadata on disk */
47886 case FSCACHE_OBJECT_UPDATING:
47887 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
47888- fscache_stat(&fscache_n_updates_run);
47889+ fscache_stat_unchecked(&fscache_n_updates_run);
47890 fscache_stat(&fscache_n_cop_update_object);
47891 object->cache->ops->update_object(object);
47892 fscache_stat_d(&fscache_n_cop_update_object);
47893@@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
47894 spin_lock(&object->lock);
47895 object->state = FSCACHE_OBJECT_DEAD;
47896 spin_unlock(&object->lock);
47897- fscache_stat(&fscache_n_object_dead);
47898+ fscache_stat_unchecked(&fscache_n_object_dead);
47899 goto terminal_transit;
47900
47901 /* handle the parent cache of this object being withdrawn from
47902@@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
47903 spin_lock(&object->lock);
47904 object->state = FSCACHE_OBJECT_DEAD;
47905 spin_unlock(&object->lock);
47906- fscache_stat(&fscache_n_object_dead);
47907+ fscache_stat_unchecked(&fscache_n_object_dead);
47908 goto terminal_transit;
47909
47910 /* complain about the object being woken up once it is
47911@@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
47912 parent->cookie->def->name, cookie->def->name,
47913 object->cache->tag->name);
47914
47915- fscache_stat(&fscache_n_object_lookups);
47916+ fscache_stat_unchecked(&fscache_n_object_lookups);
47917 fscache_stat(&fscache_n_cop_lookup_object);
47918 ret = object->cache->ops->lookup_object(object);
47919 fscache_stat_d(&fscache_n_cop_lookup_object);
47920@@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
47921 if (ret == -ETIMEDOUT) {
47922 /* probably stuck behind another object, so move this one to
47923 * the back of the queue */
47924- fscache_stat(&fscache_n_object_lookups_timed_out);
47925+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
47926 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
47927 }
47928
47929@@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
47930
47931 spin_lock(&object->lock);
47932 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
47933- fscache_stat(&fscache_n_object_lookups_negative);
47934+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
47935
47936 /* transit here to allow write requests to begin stacking up
47937 * and read requests to begin returning ENODATA */
47938@@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
47939 * result, in which case there may be data available */
47940 spin_lock(&object->lock);
47941 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
47942- fscache_stat(&fscache_n_object_lookups_positive);
47943+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
47944
47945 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
47946
47947@@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
47948 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
47949 } else {
47950 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
47951- fscache_stat(&fscache_n_object_created);
47952+ fscache_stat_unchecked(&fscache_n_object_created);
47953
47954 object->state = FSCACHE_OBJECT_AVAILABLE;
47955 spin_unlock(&object->lock);
47956@@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
47957 fscache_enqueue_dependents(object);
47958
47959 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
47960- fscache_stat(&fscache_n_object_avail);
47961+ fscache_stat_unchecked(&fscache_n_object_avail);
47962
47963 _leave("");
47964 }
47965@@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
47966 enum fscache_checkaux result;
47967
47968 if (!object->cookie->def->check_aux) {
47969- fscache_stat(&fscache_n_checkaux_none);
47970+ fscache_stat_unchecked(&fscache_n_checkaux_none);
47971 return FSCACHE_CHECKAUX_OKAY;
47972 }
47973
47974@@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
47975 switch (result) {
47976 /* entry okay as is */
47977 case FSCACHE_CHECKAUX_OKAY:
47978- fscache_stat(&fscache_n_checkaux_okay);
47979+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
47980 break;
47981
47982 /* entry requires update */
47983 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
47984- fscache_stat(&fscache_n_checkaux_update);
47985+ fscache_stat_unchecked(&fscache_n_checkaux_update);
47986 break;
47987
47988 /* entry requires deletion */
47989 case FSCACHE_CHECKAUX_OBSOLETE:
47990- fscache_stat(&fscache_n_checkaux_obsolete);
47991+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
47992 break;
47993
47994 default:
47995diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
47996index 30afdfa..2256596 100644
47997--- a/fs/fscache/operation.c
47998+++ b/fs/fscache/operation.c
47999@@ -17,7 +17,7 @@
48000 #include <linux/slab.h>
48001 #include "internal.h"
48002
48003-atomic_t fscache_op_debug_id;
48004+atomic_unchecked_t fscache_op_debug_id;
48005 EXPORT_SYMBOL(fscache_op_debug_id);
48006
48007 /**
48008@@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
48009 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
48010 ASSERTCMP(atomic_read(&op->usage), >, 0);
48011
48012- fscache_stat(&fscache_n_op_enqueue);
48013+ fscache_stat_unchecked(&fscache_n_op_enqueue);
48014 switch (op->flags & FSCACHE_OP_TYPE) {
48015 case FSCACHE_OP_ASYNC:
48016 _debug("queue async");
48017@@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
48018 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
48019 if (op->processor)
48020 fscache_enqueue_operation(op);
48021- fscache_stat(&fscache_n_op_run);
48022+ fscache_stat_unchecked(&fscache_n_op_run);
48023 }
48024
48025 /*
48026@@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
48027 if (object->n_ops > 1) {
48028 atomic_inc(&op->usage);
48029 list_add_tail(&op->pend_link, &object->pending_ops);
48030- fscache_stat(&fscache_n_op_pend);
48031+ fscache_stat_unchecked(&fscache_n_op_pend);
48032 } else if (!list_empty(&object->pending_ops)) {
48033 atomic_inc(&op->usage);
48034 list_add_tail(&op->pend_link, &object->pending_ops);
48035- fscache_stat(&fscache_n_op_pend);
48036+ fscache_stat_unchecked(&fscache_n_op_pend);
48037 fscache_start_operations(object);
48038 } else {
48039 ASSERTCMP(object->n_in_progress, ==, 0);
48040@@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
48041 object->n_exclusive++; /* reads and writes must wait */
48042 atomic_inc(&op->usage);
48043 list_add_tail(&op->pend_link, &object->pending_ops);
48044- fscache_stat(&fscache_n_op_pend);
48045+ fscache_stat_unchecked(&fscache_n_op_pend);
48046 ret = 0;
48047 } else {
48048 /* not allowed to submit ops in any other state */
48049@@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
48050 if (object->n_exclusive > 0) {
48051 atomic_inc(&op->usage);
48052 list_add_tail(&op->pend_link, &object->pending_ops);
48053- fscache_stat(&fscache_n_op_pend);
48054+ fscache_stat_unchecked(&fscache_n_op_pend);
48055 } else if (!list_empty(&object->pending_ops)) {
48056 atomic_inc(&op->usage);
48057 list_add_tail(&op->pend_link, &object->pending_ops);
48058- fscache_stat(&fscache_n_op_pend);
48059+ fscache_stat_unchecked(&fscache_n_op_pend);
48060 fscache_start_operations(object);
48061 } else {
48062 ASSERTCMP(object->n_exclusive, ==, 0);
48063@@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
48064 object->n_ops++;
48065 atomic_inc(&op->usage);
48066 list_add_tail(&op->pend_link, &object->pending_ops);
48067- fscache_stat(&fscache_n_op_pend);
48068+ fscache_stat_unchecked(&fscache_n_op_pend);
48069 ret = 0;
48070 } else if (object->state == FSCACHE_OBJECT_DYING ||
48071 object->state == FSCACHE_OBJECT_LC_DYING ||
48072 object->state == FSCACHE_OBJECT_WITHDRAWING) {
48073- fscache_stat(&fscache_n_op_rejected);
48074+ fscache_stat_unchecked(&fscache_n_op_rejected);
48075 ret = -ENOBUFS;
48076 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
48077 fscache_report_unexpected_submission(object, op, ostate);
48078@@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
48079
48080 ret = -EBUSY;
48081 if (!list_empty(&op->pend_link)) {
48082- fscache_stat(&fscache_n_op_cancelled);
48083+ fscache_stat_unchecked(&fscache_n_op_cancelled);
48084 list_del_init(&op->pend_link);
48085 object->n_ops--;
48086 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
48087@@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
48088 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
48089 BUG();
48090
48091- fscache_stat(&fscache_n_op_release);
48092+ fscache_stat_unchecked(&fscache_n_op_release);
48093
48094 if (op->release) {
48095 op->release(op);
48096@@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
48097 * lock, and defer it otherwise */
48098 if (!spin_trylock(&object->lock)) {
48099 _debug("defer put");
48100- fscache_stat(&fscache_n_op_deferred_release);
48101+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
48102
48103 cache = object->cache;
48104 spin_lock(&cache->op_gc_list_lock);
48105@@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
48106
48107 _debug("GC DEFERRED REL OBJ%x OP%x",
48108 object->debug_id, op->debug_id);
48109- fscache_stat(&fscache_n_op_gc);
48110+ fscache_stat_unchecked(&fscache_n_op_gc);
48111
48112 ASSERTCMP(atomic_read(&op->usage), ==, 0);
48113
48114diff --git a/fs/fscache/page.c b/fs/fscache/page.c
48115index 3f7a59b..cf196cc 100644
48116--- a/fs/fscache/page.c
48117+++ b/fs/fscache/page.c
48118@@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
48119 val = radix_tree_lookup(&cookie->stores, page->index);
48120 if (!val) {
48121 rcu_read_unlock();
48122- fscache_stat(&fscache_n_store_vmscan_not_storing);
48123+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
48124 __fscache_uncache_page(cookie, page);
48125 return true;
48126 }
48127@@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
48128 spin_unlock(&cookie->stores_lock);
48129
48130 if (xpage) {
48131- fscache_stat(&fscache_n_store_vmscan_cancelled);
48132- fscache_stat(&fscache_n_store_radix_deletes);
48133+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
48134+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
48135 ASSERTCMP(xpage, ==, page);
48136 } else {
48137- fscache_stat(&fscache_n_store_vmscan_gone);
48138+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
48139 }
48140
48141 wake_up_bit(&cookie->flags, 0);
48142@@ -107,7 +107,7 @@ page_busy:
48143 /* we might want to wait here, but that could deadlock the allocator as
48144 * the work threads writing to the cache may all end up sleeping
48145 * on memory allocation */
48146- fscache_stat(&fscache_n_store_vmscan_busy);
48147+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
48148 return false;
48149 }
48150 EXPORT_SYMBOL(__fscache_maybe_release_page);
48151@@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
48152 FSCACHE_COOKIE_STORING_TAG);
48153 if (!radix_tree_tag_get(&cookie->stores, page->index,
48154 FSCACHE_COOKIE_PENDING_TAG)) {
48155- fscache_stat(&fscache_n_store_radix_deletes);
48156+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
48157 xpage = radix_tree_delete(&cookie->stores, page->index);
48158 }
48159 spin_unlock(&cookie->stores_lock);
48160@@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
48161
48162 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
48163
48164- fscache_stat(&fscache_n_attr_changed_calls);
48165+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
48166
48167 if (fscache_object_is_active(object)) {
48168 fscache_stat(&fscache_n_cop_attr_changed);
48169@@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
48170
48171 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
48172
48173- fscache_stat(&fscache_n_attr_changed);
48174+ fscache_stat_unchecked(&fscache_n_attr_changed);
48175
48176 op = kzalloc(sizeof(*op), GFP_KERNEL);
48177 if (!op) {
48178- fscache_stat(&fscache_n_attr_changed_nomem);
48179+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
48180 _leave(" = -ENOMEM");
48181 return -ENOMEM;
48182 }
48183@@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
48184 if (fscache_submit_exclusive_op(object, op) < 0)
48185 goto nobufs;
48186 spin_unlock(&cookie->lock);
48187- fscache_stat(&fscache_n_attr_changed_ok);
48188+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
48189 fscache_put_operation(op);
48190 _leave(" = 0");
48191 return 0;
48192@@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
48193 nobufs:
48194 spin_unlock(&cookie->lock);
48195 kfree(op);
48196- fscache_stat(&fscache_n_attr_changed_nobufs);
48197+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
48198 _leave(" = %d", -ENOBUFS);
48199 return -ENOBUFS;
48200 }
48201@@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
48202 /* allocate a retrieval operation and attempt to submit it */
48203 op = kzalloc(sizeof(*op), GFP_NOIO);
48204 if (!op) {
48205- fscache_stat(&fscache_n_retrievals_nomem);
48206+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
48207 return NULL;
48208 }
48209
48210@@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
48211 return 0;
48212 }
48213
48214- fscache_stat(&fscache_n_retrievals_wait);
48215+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
48216
48217 jif = jiffies;
48218 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
48219 fscache_wait_bit_interruptible,
48220 TASK_INTERRUPTIBLE) != 0) {
48221- fscache_stat(&fscache_n_retrievals_intr);
48222+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
48223 _leave(" = -ERESTARTSYS");
48224 return -ERESTARTSYS;
48225 }
48226@@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
48227 */
48228 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
48229 struct fscache_retrieval *op,
48230- atomic_t *stat_op_waits,
48231- atomic_t *stat_object_dead)
48232+ atomic_unchecked_t *stat_op_waits,
48233+ atomic_unchecked_t *stat_object_dead)
48234 {
48235 int ret;
48236
48237@@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
48238 goto check_if_dead;
48239
48240 _debug(">>> WT");
48241- fscache_stat(stat_op_waits);
48242+ fscache_stat_unchecked(stat_op_waits);
48243 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
48244 fscache_wait_bit_interruptible,
48245 TASK_INTERRUPTIBLE) < 0) {
48246@@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
48247
48248 check_if_dead:
48249 if (unlikely(fscache_object_is_dead(object))) {
48250- fscache_stat(stat_object_dead);
48251+ fscache_stat_unchecked(stat_object_dead);
48252 return -ENOBUFS;
48253 }
48254 return 0;
48255@@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
48256
48257 _enter("%p,%p,,,", cookie, page);
48258
48259- fscache_stat(&fscache_n_retrievals);
48260+ fscache_stat_unchecked(&fscache_n_retrievals);
48261
48262 if (hlist_empty(&cookie->backing_objects))
48263 goto nobufs;
48264@@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
48265 goto nobufs_unlock;
48266 spin_unlock(&cookie->lock);
48267
48268- fscache_stat(&fscache_n_retrieval_ops);
48269+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
48270
48271 /* pin the netfs read context in case we need to do the actual netfs
48272 * read because we've encountered a cache read failure */
48273@@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
48274
48275 error:
48276 if (ret == -ENOMEM)
48277- fscache_stat(&fscache_n_retrievals_nomem);
48278+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
48279 else if (ret == -ERESTARTSYS)
48280- fscache_stat(&fscache_n_retrievals_intr);
48281+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
48282 else if (ret == -ENODATA)
48283- fscache_stat(&fscache_n_retrievals_nodata);
48284+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
48285 else if (ret < 0)
48286- fscache_stat(&fscache_n_retrievals_nobufs);
48287+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
48288 else
48289- fscache_stat(&fscache_n_retrievals_ok);
48290+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
48291
48292 fscache_put_retrieval(op);
48293 _leave(" = %d", ret);
48294@@ -429,7 +429,7 @@ nobufs_unlock:
48295 spin_unlock(&cookie->lock);
48296 kfree(op);
48297 nobufs:
48298- fscache_stat(&fscache_n_retrievals_nobufs);
48299+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
48300 _leave(" = -ENOBUFS");
48301 return -ENOBUFS;
48302 }
48303@@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
48304
48305 _enter("%p,,%d,,,", cookie, *nr_pages);
48306
48307- fscache_stat(&fscache_n_retrievals);
48308+ fscache_stat_unchecked(&fscache_n_retrievals);
48309
48310 if (hlist_empty(&cookie->backing_objects))
48311 goto nobufs;
48312@@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
48313 goto nobufs_unlock;
48314 spin_unlock(&cookie->lock);
48315
48316- fscache_stat(&fscache_n_retrieval_ops);
48317+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
48318
48319 /* pin the netfs read context in case we need to do the actual netfs
48320 * read because we've encountered a cache read failure */
48321@@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
48322
48323 error:
48324 if (ret == -ENOMEM)
48325- fscache_stat(&fscache_n_retrievals_nomem);
48326+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
48327 else if (ret == -ERESTARTSYS)
48328- fscache_stat(&fscache_n_retrievals_intr);
48329+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
48330 else if (ret == -ENODATA)
48331- fscache_stat(&fscache_n_retrievals_nodata);
48332+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
48333 else if (ret < 0)
48334- fscache_stat(&fscache_n_retrievals_nobufs);
48335+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
48336 else
48337- fscache_stat(&fscache_n_retrievals_ok);
48338+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
48339
48340 fscache_put_retrieval(op);
48341 _leave(" = %d", ret);
48342@@ -545,7 +545,7 @@ nobufs_unlock:
48343 spin_unlock(&cookie->lock);
48344 kfree(op);
48345 nobufs:
48346- fscache_stat(&fscache_n_retrievals_nobufs);
48347+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
48348 _leave(" = -ENOBUFS");
48349 return -ENOBUFS;
48350 }
48351@@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
48352
48353 _enter("%p,%p,,,", cookie, page);
48354
48355- fscache_stat(&fscache_n_allocs);
48356+ fscache_stat_unchecked(&fscache_n_allocs);
48357
48358 if (hlist_empty(&cookie->backing_objects))
48359 goto nobufs;
48360@@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
48361 goto nobufs_unlock;
48362 spin_unlock(&cookie->lock);
48363
48364- fscache_stat(&fscache_n_alloc_ops);
48365+ fscache_stat_unchecked(&fscache_n_alloc_ops);
48366
48367 ret = fscache_wait_for_retrieval_activation(
48368 object, op,
48369@@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
48370
48371 error:
48372 if (ret == -ERESTARTSYS)
48373- fscache_stat(&fscache_n_allocs_intr);
48374+ fscache_stat_unchecked(&fscache_n_allocs_intr);
48375 else if (ret < 0)
48376- fscache_stat(&fscache_n_allocs_nobufs);
48377+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
48378 else
48379- fscache_stat(&fscache_n_allocs_ok);
48380+ fscache_stat_unchecked(&fscache_n_allocs_ok);
48381
48382 fscache_put_retrieval(op);
48383 _leave(" = %d", ret);
48384@@ -625,7 +625,7 @@ nobufs_unlock:
48385 spin_unlock(&cookie->lock);
48386 kfree(op);
48387 nobufs:
48388- fscache_stat(&fscache_n_allocs_nobufs);
48389+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
48390 _leave(" = -ENOBUFS");
48391 return -ENOBUFS;
48392 }
48393@@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
48394
48395 spin_lock(&cookie->stores_lock);
48396
48397- fscache_stat(&fscache_n_store_calls);
48398+ fscache_stat_unchecked(&fscache_n_store_calls);
48399
48400 /* find a page to store */
48401 page = NULL;
48402@@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
48403 page = results[0];
48404 _debug("gang %d [%lx]", n, page->index);
48405 if (page->index > op->store_limit) {
48406- fscache_stat(&fscache_n_store_pages_over_limit);
48407+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
48408 goto superseded;
48409 }
48410
48411@@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
48412 spin_unlock(&cookie->stores_lock);
48413 spin_unlock(&object->lock);
48414
48415- fscache_stat(&fscache_n_store_pages);
48416+ fscache_stat_unchecked(&fscache_n_store_pages);
48417 fscache_stat(&fscache_n_cop_write_page);
48418 ret = object->cache->ops->write_page(op, page);
48419 fscache_stat_d(&fscache_n_cop_write_page);
48420@@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
48421 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
48422 ASSERT(PageFsCache(page));
48423
48424- fscache_stat(&fscache_n_stores);
48425+ fscache_stat_unchecked(&fscache_n_stores);
48426
48427 op = kzalloc(sizeof(*op), GFP_NOIO);
48428 if (!op)
48429@@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
48430 spin_unlock(&cookie->stores_lock);
48431 spin_unlock(&object->lock);
48432
48433- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
48434+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
48435 op->store_limit = object->store_limit;
48436
48437 if (fscache_submit_op(object, &op->op) < 0)
48438@@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
48439
48440 spin_unlock(&cookie->lock);
48441 radix_tree_preload_end();
48442- fscache_stat(&fscache_n_store_ops);
48443- fscache_stat(&fscache_n_stores_ok);
48444+ fscache_stat_unchecked(&fscache_n_store_ops);
48445+ fscache_stat_unchecked(&fscache_n_stores_ok);
48446
48447 /* the work queue now carries its own ref on the object */
48448 fscache_put_operation(&op->op);
48449@@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
48450 return 0;
48451
48452 already_queued:
48453- fscache_stat(&fscache_n_stores_again);
48454+ fscache_stat_unchecked(&fscache_n_stores_again);
48455 already_pending:
48456 spin_unlock(&cookie->stores_lock);
48457 spin_unlock(&object->lock);
48458 spin_unlock(&cookie->lock);
48459 radix_tree_preload_end();
48460 kfree(op);
48461- fscache_stat(&fscache_n_stores_ok);
48462+ fscache_stat_unchecked(&fscache_n_stores_ok);
48463 _leave(" = 0");
48464 return 0;
48465
48466@@ -851,14 +851,14 @@ nobufs:
48467 spin_unlock(&cookie->lock);
48468 radix_tree_preload_end();
48469 kfree(op);
48470- fscache_stat(&fscache_n_stores_nobufs);
48471+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
48472 _leave(" = -ENOBUFS");
48473 return -ENOBUFS;
48474
48475 nomem_free:
48476 kfree(op);
48477 nomem:
48478- fscache_stat(&fscache_n_stores_oom);
48479+ fscache_stat_unchecked(&fscache_n_stores_oom);
48480 _leave(" = -ENOMEM");
48481 return -ENOMEM;
48482 }
48483@@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
48484 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
48485 ASSERTCMP(page, !=, NULL);
48486
48487- fscache_stat(&fscache_n_uncaches);
48488+ fscache_stat_unchecked(&fscache_n_uncaches);
48489
48490 /* cache withdrawal may beat us to it */
48491 if (!PageFsCache(page))
48492@@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
48493 unsigned long loop;
48494
48495 #ifdef CONFIG_FSCACHE_STATS
48496- atomic_add(pagevec->nr, &fscache_n_marks);
48497+ atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
48498 #endif
48499
48500 for (loop = 0; loop < pagevec->nr; loop++) {
48501diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
48502index 4765190..2a067f2 100644
48503--- a/fs/fscache/stats.c
48504+++ b/fs/fscache/stats.c
48505@@ -18,95 +18,95 @@
48506 /*
48507 * operation counters
48508 */
48509-atomic_t fscache_n_op_pend;
48510-atomic_t fscache_n_op_run;
48511-atomic_t fscache_n_op_enqueue;
48512-atomic_t fscache_n_op_requeue;
48513-atomic_t fscache_n_op_deferred_release;
48514-atomic_t fscache_n_op_release;
48515-atomic_t fscache_n_op_gc;
48516-atomic_t fscache_n_op_cancelled;
48517-atomic_t fscache_n_op_rejected;
48518+atomic_unchecked_t fscache_n_op_pend;
48519+atomic_unchecked_t fscache_n_op_run;
48520+atomic_unchecked_t fscache_n_op_enqueue;
48521+atomic_unchecked_t fscache_n_op_requeue;
48522+atomic_unchecked_t fscache_n_op_deferred_release;
48523+atomic_unchecked_t fscache_n_op_release;
48524+atomic_unchecked_t fscache_n_op_gc;
48525+atomic_unchecked_t fscache_n_op_cancelled;
48526+atomic_unchecked_t fscache_n_op_rejected;
48527
48528-atomic_t fscache_n_attr_changed;
48529-atomic_t fscache_n_attr_changed_ok;
48530-atomic_t fscache_n_attr_changed_nobufs;
48531-atomic_t fscache_n_attr_changed_nomem;
48532-atomic_t fscache_n_attr_changed_calls;
48533+atomic_unchecked_t fscache_n_attr_changed;
48534+atomic_unchecked_t fscache_n_attr_changed_ok;
48535+atomic_unchecked_t fscache_n_attr_changed_nobufs;
48536+atomic_unchecked_t fscache_n_attr_changed_nomem;
48537+atomic_unchecked_t fscache_n_attr_changed_calls;
48538
48539-atomic_t fscache_n_allocs;
48540-atomic_t fscache_n_allocs_ok;
48541-atomic_t fscache_n_allocs_wait;
48542-atomic_t fscache_n_allocs_nobufs;
48543-atomic_t fscache_n_allocs_intr;
48544-atomic_t fscache_n_allocs_object_dead;
48545-atomic_t fscache_n_alloc_ops;
48546-atomic_t fscache_n_alloc_op_waits;
48547+atomic_unchecked_t fscache_n_allocs;
48548+atomic_unchecked_t fscache_n_allocs_ok;
48549+atomic_unchecked_t fscache_n_allocs_wait;
48550+atomic_unchecked_t fscache_n_allocs_nobufs;
48551+atomic_unchecked_t fscache_n_allocs_intr;
48552+atomic_unchecked_t fscache_n_allocs_object_dead;
48553+atomic_unchecked_t fscache_n_alloc_ops;
48554+atomic_unchecked_t fscache_n_alloc_op_waits;
48555
48556-atomic_t fscache_n_retrievals;
48557-atomic_t fscache_n_retrievals_ok;
48558-atomic_t fscache_n_retrievals_wait;
48559-atomic_t fscache_n_retrievals_nodata;
48560-atomic_t fscache_n_retrievals_nobufs;
48561-atomic_t fscache_n_retrievals_intr;
48562-atomic_t fscache_n_retrievals_nomem;
48563-atomic_t fscache_n_retrievals_object_dead;
48564-atomic_t fscache_n_retrieval_ops;
48565-atomic_t fscache_n_retrieval_op_waits;
48566+atomic_unchecked_t fscache_n_retrievals;
48567+atomic_unchecked_t fscache_n_retrievals_ok;
48568+atomic_unchecked_t fscache_n_retrievals_wait;
48569+atomic_unchecked_t fscache_n_retrievals_nodata;
48570+atomic_unchecked_t fscache_n_retrievals_nobufs;
48571+atomic_unchecked_t fscache_n_retrievals_intr;
48572+atomic_unchecked_t fscache_n_retrievals_nomem;
48573+atomic_unchecked_t fscache_n_retrievals_object_dead;
48574+atomic_unchecked_t fscache_n_retrieval_ops;
48575+atomic_unchecked_t fscache_n_retrieval_op_waits;
48576
48577-atomic_t fscache_n_stores;
48578-atomic_t fscache_n_stores_ok;
48579-atomic_t fscache_n_stores_again;
48580-atomic_t fscache_n_stores_nobufs;
48581-atomic_t fscache_n_stores_oom;
48582-atomic_t fscache_n_store_ops;
48583-atomic_t fscache_n_store_calls;
48584-atomic_t fscache_n_store_pages;
48585-atomic_t fscache_n_store_radix_deletes;
48586-atomic_t fscache_n_store_pages_over_limit;
48587+atomic_unchecked_t fscache_n_stores;
48588+atomic_unchecked_t fscache_n_stores_ok;
48589+atomic_unchecked_t fscache_n_stores_again;
48590+atomic_unchecked_t fscache_n_stores_nobufs;
48591+atomic_unchecked_t fscache_n_stores_oom;
48592+atomic_unchecked_t fscache_n_store_ops;
48593+atomic_unchecked_t fscache_n_store_calls;
48594+atomic_unchecked_t fscache_n_store_pages;
48595+atomic_unchecked_t fscache_n_store_radix_deletes;
48596+atomic_unchecked_t fscache_n_store_pages_over_limit;
48597
48598-atomic_t fscache_n_store_vmscan_not_storing;
48599-atomic_t fscache_n_store_vmscan_gone;
48600-atomic_t fscache_n_store_vmscan_busy;
48601-atomic_t fscache_n_store_vmscan_cancelled;
48602+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
48603+atomic_unchecked_t fscache_n_store_vmscan_gone;
48604+atomic_unchecked_t fscache_n_store_vmscan_busy;
48605+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
48606
48607-atomic_t fscache_n_marks;
48608-atomic_t fscache_n_uncaches;
48609+atomic_unchecked_t fscache_n_marks;
48610+atomic_unchecked_t fscache_n_uncaches;
48611
48612-atomic_t fscache_n_acquires;
48613-atomic_t fscache_n_acquires_null;
48614-atomic_t fscache_n_acquires_no_cache;
48615-atomic_t fscache_n_acquires_ok;
48616-atomic_t fscache_n_acquires_nobufs;
48617-atomic_t fscache_n_acquires_oom;
48618+atomic_unchecked_t fscache_n_acquires;
48619+atomic_unchecked_t fscache_n_acquires_null;
48620+atomic_unchecked_t fscache_n_acquires_no_cache;
48621+atomic_unchecked_t fscache_n_acquires_ok;
48622+atomic_unchecked_t fscache_n_acquires_nobufs;
48623+atomic_unchecked_t fscache_n_acquires_oom;
48624
48625-atomic_t fscache_n_updates;
48626-atomic_t fscache_n_updates_null;
48627-atomic_t fscache_n_updates_run;
48628+atomic_unchecked_t fscache_n_updates;
48629+atomic_unchecked_t fscache_n_updates_null;
48630+atomic_unchecked_t fscache_n_updates_run;
48631
48632-atomic_t fscache_n_relinquishes;
48633-atomic_t fscache_n_relinquishes_null;
48634-atomic_t fscache_n_relinquishes_waitcrt;
48635-atomic_t fscache_n_relinquishes_retire;
48636+atomic_unchecked_t fscache_n_relinquishes;
48637+atomic_unchecked_t fscache_n_relinquishes_null;
48638+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
48639+atomic_unchecked_t fscache_n_relinquishes_retire;
48640
48641-atomic_t fscache_n_cookie_index;
48642-atomic_t fscache_n_cookie_data;
48643-atomic_t fscache_n_cookie_special;
48644+atomic_unchecked_t fscache_n_cookie_index;
48645+atomic_unchecked_t fscache_n_cookie_data;
48646+atomic_unchecked_t fscache_n_cookie_special;
48647
48648-atomic_t fscache_n_object_alloc;
48649-atomic_t fscache_n_object_no_alloc;
48650-atomic_t fscache_n_object_lookups;
48651-atomic_t fscache_n_object_lookups_negative;
48652-atomic_t fscache_n_object_lookups_positive;
48653-atomic_t fscache_n_object_lookups_timed_out;
48654-atomic_t fscache_n_object_created;
48655-atomic_t fscache_n_object_avail;
48656-atomic_t fscache_n_object_dead;
48657+atomic_unchecked_t fscache_n_object_alloc;
48658+atomic_unchecked_t fscache_n_object_no_alloc;
48659+atomic_unchecked_t fscache_n_object_lookups;
48660+atomic_unchecked_t fscache_n_object_lookups_negative;
48661+atomic_unchecked_t fscache_n_object_lookups_positive;
48662+atomic_unchecked_t fscache_n_object_lookups_timed_out;
48663+atomic_unchecked_t fscache_n_object_created;
48664+atomic_unchecked_t fscache_n_object_avail;
48665+atomic_unchecked_t fscache_n_object_dead;
48666
48667-atomic_t fscache_n_checkaux_none;
48668-atomic_t fscache_n_checkaux_okay;
48669-atomic_t fscache_n_checkaux_update;
48670-atomic_t fscache_n_checkaux_obsolete;
48671+atomic_unchecked_t fscache_n_checkaux_none;
48672+atomic_unchecked_t fscache_n_checkaux_okay;
48673+atomic_unchecked_t fscache_n_checkaux_update;
48674+atomic_unchecked_t fscache_n_checkaux_obsolete;
48675
48676 atomic_t fscache_n_cop_alloc_object;
48677 atomic_t fscache_n_cop_lookup_object;
48678@@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
48679 seq_puts(m, "FS-Cache statistics\n");
48680
48681 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
48682- atomic_read(&fscache_n_cookie_index),
48683- atomic_read(&fscache_n_cookie_data),
48684- atomic_read(&fscache_n_cookie_special));
48685+ atomic_read_unchecked(&fscache_n_cookie_index),
48686+ atomic_read_unchecked(&fscache_n_cookie_data),
48687+ atomic_read_unchecked(&fscache_n_cookie_special));
48688
48689 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
48690- atomic_read(&fscache_n_object_alloc),
48691- atomic_read(&fscache_n_object_no_alloc),
48692- atomic_read(&fscache_n_object_avail),
48693- atomic_read(&fscache_n_object_dead));
48694+ atomic_read_unchecked(&fscache_n_object_alloc),
48695+ atomic_read_unchecked(&fscache_n_object_no_alloc),
48696+ atomic_read_unchecked(&fscache_n_object_avail),
48697+ atomic_read_unchecked(&fscache_n_object_dead));
48698 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
48699- atomic_read(&fscache_n_checkaux_none),
48700- atomic_read(&fscache_n_checkaux_okay),
48701- atomic_read(&fscache_n_checkaux_update),
48702- atomic_read(&fscache_n_checkaux_obsolete));
48703+ atomic_read_unchecked(&fscache_n_checkaux_none),
48704+ atomic_read_unchecked(&fscache_n_checkaux_okay),
48705+ atomic_read_unchecked(&fscache_n_checkaux_update),
48706+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
48707
48708 seq_printf(m, "Pages : mrk=%u unc=%u\n",
48709- atomic_read(&fscache_n_marks),
48710- atomic_read(&fscache_n_uncaches));
48711+ atomic_read_unchecked(&fscache_n_marks),
48712+ atomic_read_unchecked(&fscache_n_uncaches));
48713
48714 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
48715 " oom=%u\n",
48716- atomic_read(&fscache_n_acquires),
48717- atomic_read(&fscache_n_acquires_null),
48718- atomic_read(&fscache_n_acquires_no_cache),
48719- atomic_read(&fscache_n_acquires_ok),
48720- atomic_read(&fscache_n_acquires_nobufs),
48721- atomic_read(&fscache_n_acquires_oom));
48722+ atomic_read_unchecked(&fscache_n_acquires),
48723+ atomic_read_unchecked(&fscache_n_acquires_null),
48724+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
48725+ atomic_read_unchecked(&fscache_n_acquires_ok),
48726+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
48727+ atomic_read_unchecked(&fscache_n_acquires_oom));
48728
48729 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
48730- atomic_read(&fscache_n_object_lookups),
48731- atomic_read(&fscache_n_object_lookups_negative),
48732- atomic_read(&fscache_n_object_lookups_positive),
48733- atomic_read(&fscache_n_object_created),
48734- atomic_read(&fscache_n_object_lookups_timed_out));
48735+ atomic_read_unchecked(&fscache_n_object_lookups),
48736+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
48737+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
48738+ atomic_read_unchecked(&fscache_n_object_created),
48739+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
48740
48741 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
48742- atomic_read(&fscache_n_updates),
48743- atomic_read(&fscache_n_updates_null),
48744- atomic_read(&fscache_n_updates_run));
48745+ atomic_read_unchecked(&fscache_n_updates),
48746+ atomic_read_unchecked(&fscache_n_updates_null),
48747+ atomic_read_unchecked(&fscache_n_updates_run));
48748
48749 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
48750- atomic_read(&fscache_n_relinquishes),
48751- atomic_read(&fscache_n_relinquishes_null),
48752- atomic_read(&fscache_n_relinquishes_waitcrt),
48753- atomic_read(&fscache_n_relinquishes_retire));
48754+ atomic_read_unchecked(&fscache_n_relinquishes),
48755+ atomic_read_unchecked(&fscache_n_relinquishes_null),
48756+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
48757+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
48758
48759 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
48760- atomic_read(&fscache_n_attr_changed),
48761- atomic_read(&fscache_n_attr_changed_ok),
48762- atomic_read(&fscache_n_attr_changed_nobufs),
48763- atomic_read(&fscache_n_attr_changed_nomem),
48764- atomic_read(&fscache_n_attr_changed_calls));
48765+ atomic_read_unchecked(&fscache_n_attr_changed),
48766+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
48767+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
48768+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
48769+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
48770
48771 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
48772- atomic_read(&fscache_n_allocs),
48773- atomic_read(&fscache_n_allocs_ok),
48774- atomic_read(&fscache_n_allocs_wait),
48775- atomic_read(&fscache_n_allocs_nobufs),
48776- atomic_read(&fscache_n_allocs_intr));
48777+ atomic_read_unchecked(&fscache_n_allocs),
48778+ atomic_read_unchecked(&fscache_n_allocs_ok),
48779+ atomic_read_unchecked(&fscache_n_allocs_wait),
48780+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
48781+ atomic_read_unchecked(&fscache_n_allocs_intr));
48782 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
48783- atomic_read(&fscache_n_alloc_ops),
48784- atomic_read(&fscache_n_alloc_op_waits),
48785- atomic_read(&fscache_n_allocs_object_dead));
48786+ atomic_read_unchecked(&fscache_n_alloc_ops),
48787+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
48788+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
48789
48790 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
48791 " int=%u oom=%u\n",
48792- atomic_read(&fscache_n_retrievals),
48793- atomic_read(&fscache_n_retrievals_ok),
48794- atomic_read(&fscache_n_retrievals_wait),
48795- atomic_read(&fscache_n_retrievals_nodata),
48796- atomic_read(&fscache_n_retrievals_nobufs),
48797- atomic_read(&fscache_n_retrievals_intr),
48798- atomic_read(&fscache_n_retrievals_nomem));
48799+ atomic_read_unchecked(&fscache_n_retrievals),
48800+ atomic_read_unchecked(&fscache_n_retrievals_ok),
48801+ atomic_read_unchecked(&fscache_n_retrievals_wait),
48802+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
48803+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
48804+ atomic_read_unchecked(&fscache_n_retrievals_intr),
48805+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
48806 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
48807- atomic_read(&fscache_n_retrieval_ops),
48808- atomic_read(&fscache_n_retrieval_op_waits),
48809- atomic_read(&fscache_n_retrievals_object_dead));
48810+ atomic_read_unchecked(&fscache_n_retrieval_ops),
48811+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
48812+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
48813
48814 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
48815- atomic_read(&fscache_n_stores),
48816- atomic_read(&fscache_n_stores_ok),
48817- atomic_read(&fscache_n_stores_again),
48818- atomic_read(&fscache_n_stores_nobufs),
48819- atomic_read(&fscache_n_stores_oom));
48820+ atomic_read_unchecked(&fscache_n_stores),
48821+ atomic_read_unchecked(&fscache_n_stores_ok),
48822+ atomic_read_unchecked(&fscache_n_stores_again),
48823+ atomic_read_unchecked(&fscache_n_stores_nobufs),
48824+ atomic_read_unchecked(&fscache_n_stores_oom));
48825 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
48826- atomic_read(&fscache_n_store_ops),
48827- atomic_read(&fscache_n_store_calls),
48828- atomic_read(&fscache_n_store_pages),
48829- atomic_read(&fscache_n_store_radix_deletes),
48830- atomic_read(&fscache_n_store_pages_over_limit));
48831+ atomic_read_unchecked(&fscache_n_store_ops),
48832+ atomic_read_unchecked(&fscache_n_store_calls),
48833+ atomic_read_unchecked(&fscache_n_store_pages),
48834+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
48835+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
48836
48837 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
48838- atomic_read(&fscache_n_store_vmscan_not_storing),
48839- atomic_read(&fscache_n_store_vmscan_gone),
48840- atomic_read(&fscache_n_store_vmscan_busy),
48841- atomic_read(&fscache_n_store_vmscan_cancelled));
48842+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
48843+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
48844+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
48845+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
48846
48847 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
48848- atomic_read(&fscache_n_op_pend),
48849- atomic_read(&fscache_n_op_run),
48850- atomic_read(&fscache_n_op_enqueue),
48851- atomic_read(&fscache_n_op_cancelled),
48852- atomic_read(&fscache_n_op_rejected));
48853+ atomic_read_unchecked(&fscache_n_op_pend),
48854+ atomic_read_unchecked(&fscache_n_op_run),
48855+ atomic_read_unchecked(&fscache_n_op_enqueue),
48856+ atomic_read_unchecked(&fscache_n_op_cancelled),
48857+ atomic_read_unchecked(&fscache_n_op_rejected));
48858 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
48859- atomic_read(&fscache_n_op_deferred_release),
48860- atomic_read(&fscache_n_op_release),
48861- atomic_read(&fscache_n_op_gc));
48862+ atomic_read_unchecked(&fscache_n_op_deferred_release),
48863+ atomic_read_unchecked(&fscache_n_op_release),
48864+ atomic_read_unchecked(&fscache_n_op_gc));
48865
48866 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
48867 atomic_read(&fscache_n_cop_alloc_object),
48868diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
48869index ee8d550..7189d8c 100644
48870--- a/fs/fuse/cuse.c
48871+++ b/fs/fuse/cuse.c
48872@@ -585,10 +585,12 @@ static int __init cuse_init(void)
48873 INIT_LIST_HEAD(&cuse_conntbl[i]);
48874
48875 /* inherit and extend fuse_dev_operations */
48876- cuse_channel_fops = fuse_dev_operations;
48877- cuse_channel_fops.owner = THIS_MODULE;
48878- cuse_channel_fops.open = cuse_channel_open;
48879- cuse_channel_fops.release = cuse_channel_release;
48880+ pax_open_kernel();
48881+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
48882+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
48883+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
48884+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
48885+ pax_close_kernel();
48886
48887 cuse_class = class_create(THIS_MODULE, "cuse");
48888 if (IS_ERR(cuse_class))
48889diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
48890index 8c23fa7..0e3aac7 100644
48891--- a/fs/fuse/dev.c
48892+++ b/fs/fuse/dev.c
48893@@ -1241,7 +1241,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
48894 ret = 0;
48895 pipe_lock(pipe);
48896
48897- if (!pipe->readers) {
48898+ if (!atomic_read(&pipe->readers)) {
48899 send_sig(SIGPIPE, current, 0);
48900 if (!ret)
48901 ret = -EPIPE;
48902diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
48903index 324bc08..4fdd56e 100644
48904--- a/fs/fuse/dir.c
48905+++ b/fs/fuse/dir.c
48906@@ -1226,7 +1226,7 @@ static char *read_link(struct dentry *dentry)
48907 return link;
48908 }
48909
48910-static void free_link(char *link)
48911+static void free_link(const char *link)
48912 {
48913 if (!IS_ERR(link))
48914 free_page((unsigned long) link);
48915diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
48916index 381893c..3793318 100644
48917--- a/fs/gfs2/inode.c
48918+++ b/fs/gfs2/inode.c
48919@@ -1490,7 +1490,7 @@ out:
48920
48921 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
48922 {
48923- char *s = nd_get_link(nd);
48924+ const char *s = nd_get_link(nd);
48925 if (!IS_ERR(s))
48926 kfree(s);
48927 }
48928diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
48929index c5bc355..5a513bb 100644
48930--- a/fs/hugetlbfs/inode.c
48931+++ b/fs/hugetlbfs/inode.c
48932@@ -923,7 +923,7 @@ static struct file_system_type hugetlbfs_fs_type = {
48933 .kill_sb = kill_litter_super,
48934 };
48935
48936-static struct vfsmount *hugetlbfs_vfsmount;
48937+struct vfsmount *hugetlbfs_vfsmount;
48938
48939 static int can_do_hugetlb_shm(void)
48940 {
48941diff --git a/fs/inode.c b/fs/inode.c
48942index 64999f1..8fad608 100644
48943--- a/fs/inode.c
48944+++ b/fs/inode.c
48945@@ -880,8 +880,8 @@ unsigned int get_next_ino(void)
48946
48947 #ifdef CONFIG_SMP
48948 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
48949- static atomic_t shared_last_ino;
48950- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
48951+ static atomic_unchecked_t shared_last_ino;
48952+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
48953
48954 res = next - LAST_INO_BATCH;
48955 }
48956diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
48957index 4a6cf28..d3a29d3 100644
48958--- a/fs/jffs2/erase.c
48959+++ b/fs/jffs2/erase.c
48960@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
48961 struct jffs2_unknown_node marker = {
48962 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
48963 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
48964- .totlen = cpu_to_je32(c->cleanmarker_size)
48965+ .totlen = cpu_to_je32(c->cleanmarker_size),
48966+ .hdr_crc = cpu_to_je32(0)
48967 };
48968
48969 jffs2_prealloc_raw_node_refs(c, jeb, 1);
48970diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
48971index a6597d6..41b30ec 100644
48972--- a/fs/jffs2/wbuf.c
48973+++ b/fs/jffs2/wbuf.c
48974@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
48975 {
48976 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
48977 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
48978- .totlen = constant_cpu_to_je32(8)
48979+ .totlen = constant_cpu_to_je32(8),
48980+ .hdr_crc = constant_cpu_to_je32(0)
48981 };
48982
48983 /*
48984diff --git a/fs/jfs/super.c b/fs/jfs/super.c
48985index 1a543be..d803c40 100644
48986--- a/fs/jfs/super.c
48987+++ b/fs/jfs/super.c
48988@@ -855,7 +855,7 @@ static int __init init_jfs_fs(void)
48989
48990 jfs_inode_cachep =
48991 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
48992- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
48993+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
48994 init_once);
48995 if (jfs_inode_cachep == NULL)
48996 return -ENOMEM;
48997diff --git a/fs/libfs.c b/fs/libfs.c
48998index 7cc37ca..b3e3eec 100644
48999--- a/fs/libfs.c
49000+++ b/fs/libfs.c
49001@@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
49002
49003 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
49004 struct dentry *next;
49005+ char d_name[sizeof(next->d_iname)];
49006+ const unsigned char *name;
49007+
49008 next = list_entry(p, struct dentry, d_u.d_child);
49009 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
49010 if (!simple_positive(next)) {
49011@@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
49012
49013 spin_unlock(&next->d_lock);
49014 spin_unlock(&dentry->d_lock);
49015- if (filldir(dirent, next->d_name.name,
49016+ name = next->d_name.name;
49017+ if (name == next->d_iname) {
49018+ memcpy(d_name, name, next->d_name.len);
49019+ name = d_name;
49020+ }
49021+ if (filldir(dirent, name,
49022 next->d_name.len, filp->f_pos,
49023 next->d_inode->i_ino,
49024 dt_type(next->d_inode)) < 0)
49025diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
49026index 05d2912..760abfa 100644
49027--- a/fs/lockd/clntproc.c
49028+++ b/fs/lockd/clntproc.c
49029@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
49030 /*
49031 * Cookie counter for NLM requests
49032 */
49033-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
49034+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
49035
49036 void nlmclnt_next_cookie(struct nlm_cookie *c)
49037 {
49038- u32 cookie = atomic_inc_return(&nlm_cookie);
49039+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
49040
49041 memcpy(c->data, &cookie, 4);
49042 c->len=4;
49043diff --git a/fs/locks.c b/fs/locks.c
49044index a94e331..060bce3 100644
49045--- a/fs/locks.c
49046+++ b/fs/locks.c
49047@@ -2064,16 +2064,16 @@ void locks_remove_flock(struct file *filp)
49048 return;
49049
49050 if (filp->f_op && filp->f_op->flock) {
49051- struct file_lock fl = {
49052+ struct file_lock flock = {
49053 .fl_pid = current->tgid,
49054 .fl_file = filp,
49055 .fl_flags = FL_FLOCK,
49056 .fl_type = F_UNLCK,
49057 .fl_end = OFFSET_MAX,
49058 };
49059- filp->f_op->flock(filp, F_SETLKW, &fl);
49060- if (fl.fl_ops && fl.fl_ops->fl_release_private)
49061- fl.fl_ops->fl_release_private(&fl);
49062+ filp->f_op->flock(filp, F_SETLKW, &flock);
49063+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
49064+ flock.fl_ops->fl_release_private(&flock);
49065 }
49066
49067 lock_flocks();
49068diff --git a/fs/namei.c b/fs/namei.c
49069index 5f4cdf3..959a013 100644
49070--- a/fs/namei.c
49071+++ b/fs/namei.c
49072@@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
49073 if (ret != -EACCES)
49074 return ret;
49075
49076+#ifdef CONFIG_GRKERNSEC
49077+ /* we'll block if we have to log due to a denied capability use */
49078+ if (mask & MAY_NOT_BLOCK)
49079+ return -ECHILD;
49080+#endif
49081+
49082 if (S_ISDIR(inode->i_mode)) {
49083 /* DACs are overridable for directories */
49084- if (inode_capable(inode, CAP_DAC_OVERRIDE))
49085- return 0;
49086 if (!(mask & MAY_WRITE))
49087- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
49088+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
49089+ inode_capable(inode, CAP_DAC_READ_SEARCH))
49090 return 0;
49091+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
49092+ return 0;
49093 return -EACCES;
49094 }
49095 /*
49096+ * Searching includes executable on directories, else just read.
49097+ */
49098+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
49099+ if (mask == MAY_READ)
49100+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
49101+ inode_capable(inode, CAP_DAC_READ_SEARCH))
49102+ return 0;
49103+
49104+ /*
49105 * Read/write DACs are always overridable.
49106 * Executable DACs are overridable when there is
49107 * at least one exec bit set.
49108@@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
49109 if (inode_capable(inode, CAP_DAC_OVERRIDE))
49110 return 0;
49111
49112- /*
49113- * Searching includes executable on directories, else just read.
49114- */
49115- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
49116- if (mask == MAY_READ)
49117- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
49118- return 0;
49119-
49120 return -EACCES;
49121 }
49122
49123@@ -826,7 +834,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
49124 {
49125 struct dentry *dentry = link->dentry;
49126 int error;
49127- char *s;
49128+ const char *s;
49129
49130 BUG_ON(nd->flags & LOOKUP_RCU);
49131
49132@@ -847,6 +855,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
49133 if (error)
49134 goto out_put_nd_path;
49135
49136+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
49137+ dentry->d_inode, dentry, nd->path.mnt)) {
49138+ error = -EACCES;
49139+ goto out_put_nd_path;
49140+ }
49141+
49142 nd->last_type = LAST_BIND;
49143 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
49144 error = PTR_ERR(*p);
49145@@ -1605,6 +1619,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
49146 break;
49147 res = walk_component(nd, path, &nd->last,
49148 nd->last_type, LOOKUP_FOLLOW);
49149+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
49150+ res = -EACCES;
49151 put_link(nd, &link, cookie);
49152 } while (res > 0);
49153
49154@@ -1703,7 +1719,7 @@ EXPORT_SYMBOL(full_name_hash);
49155 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
49156 {
49157 unsigned long a, b, adata, bdata, mask, hash, len;
49158- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
49159+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
49160
49161 hash = a = 0;
49162 len = -sizeof(unsigned long);
49163@@ -1993,6 +2009,8 @@ static int path_lookupat(int dfd, const char *name,
49164 if (err)
49165 break;
49166 err = lookup_last(nd, &path);
49167+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
49168+ err = -EACCES;
49169 put_link(nd, &link, cookie);
49170 }
49171 }
49172@@ -2000,6 +2018,21 @@ static int path_lookupat(int dfd, const char *name,
49173 if (!err)
49174 err = complete_walk(nd);
49175
49176+ if (!(nd->flags & LOOKUP_PARENT)) {
49177+#ifdef CONFIG_GRKERNSEC
49178+ if (flags & LOOKUP_RCU) {
49179+ if (!err)
49180+ path_put(&nd->path);
49181+ err = -ECHILD;
49182+ } else
49183+#endif
49184+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
49185+ if (!err)
49186+ path_put(&nd->path);
49187+ err = -ENOENT;
49188+ }
49189+ }
49190+
49191 if (!err && nd->flags & LOOKUP_DIRECTORY) {
49192 if (!nd->inode->i_op->lookup) {
49193 path_put(&nd->path);
49194@@ -2027,8 +2060,17 @@ static int filename_lookup(int dfd, struct filename *name,
49195 retval = path_lookupat(dfd, name->name,
49196 flags | LOOKUP_REVAL, nd);
49197
49198- if (likely(!retval))
49199+ if (likely(!retval)) {
49200+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
49201+#ifdef CONFIG_GRKERNSEC
49202+ if (flags & LOOKUP_RCU)
49203+ return -ECHILD;
49204+#endif
49205+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
49206+ return -ENOENT;
49207+ }
49208 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
49209+ }
49210 return retval;
49211 }
49212
49213@@ -2402,6 +2444,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
49214 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
49215 return -EPERM;
49216
49217+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
49218+ return -EPERM;
49219+ if (gr_handle_rawio(inode))
49220+ return -EPERM;
49221+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
49222+ return -EACCES;
49223+
49224 return 0;
49225 }
49226
49227@@ -2623,7 +2672,7 @@ looked_up:
49228 * cleared otherwise prior to returning.
49229 */
49230 static int lookup_open(struct nameidata *nd, struct path *path,
49231- struct file *file,
49232+ struct path *link, struct file *file,
49233 const struct open_flags *op,
49234 bool got_write, int *opened)
49235 {
49236@@ -2658,6 +2707,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
49237 /* Negative dentry, just create the file */
49238 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
49239 umode_t mode = op->mode;
49240+
49241+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
49242+ error = -EACCES;
49243+ goto out_dput;
49244+ }
49245+
49246+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
49247+ error = -EACCES;
49248+ goto out_dput;
49249+ }
49250+
49251 if (!IS_POSIXACL(dir->d_inode))
49252 mode &= ~current_umask();
49253 /*
49254@@ -2679,6 +2739,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
49255 nd->flags & LOOKUP_EXCL);
49256 if (error)
49257 goto out_dput;
49258+ else
49259+ gr_handle_create(dentry, nd->path.mnt);
49260 }
49261 out_no_open:
49262 path->dentry = dentry;
49263@@ -2693,7 +2755,7 @@ out_dput:
49264 /*
49265 * Handle the last step of open()
49266 */
49267-static int do_last(struct nameidata *nd, struct path *path,
49268+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
49269 struct file *file, const struct open_flags *op,
49270 int *opened, struct filename *name)
49271 {
49272@@ -2722,16 +2784,44 @@ static int do_last(struct nameidata *nd, struct path *path,
49273 error = complete_walk(nd);
49274 if (error)
49275 return error;
49276+#ifdef CONFIG_GRKERNSEC
49277+ if (nd->flags & LOOKUP_RCU) {
49278+ error = -ECHILD;
49279+ goto out;
49280+ }
49281+#endif
49282+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
49283+ error = -ENOENT;
49284+ goto out;
49285+ }
49286 audit_inode(name, nd->path.dentry, 0);
49287 if (open_flag & O_CREAT) {
49288 error = -EISDIR;
49289 goto out;
49290 }
49291+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
49292+ error = -EACCES;
49293+ goto out;
49294+ }
49295 goto finish_open;
49296 case LAST_BIND:
49297 error = complete_walk(nd);
49298 if (error)
49299 return error;
49300+#ifdef CONFIG_GRKERNSEC
49301+ if (nd->flags & LOOKUP_RCU) {
49302+ error = -ECHILD;
49303+ goto out;
49304+ }
49305+#endif
49306+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
49307+ error = -ENOENT;
49308+ goto out;
49309+ }
49310+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
49311+ error = -EACCES;
49312+ goto out;
49313+ }
49314 audit_inode(name, dir, 0);
49315 goto finish_open;
49316 }
49317@@ -2780,7 +2870,7 @@ retry_lookup:
49318 */
49319 }
49320 mutex_lock(&dir->d_inode->i_mutex);
49321- error = lookup_open(nd, path, file, op, got_write, opened);
49322+ error = lookup_open(nd, path, link, file, op, got_write, opened);
49323 mutex_unlock(&dir->d_inode->i_mutex);
49324
49325 if (error <= 0) {
49326@@ -2804,11 +2894,28 @@ retry_lookup:
49327 goto finish_open_created;
49328 }
49329
49330+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
49331+ error = -ENOENT;
49332+ goto exit_dput;
49333+ }
49334+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
49335+ error = -EACCES;
49336+ goto exit_dput;
49337+ }
49338+
49339 /*
49340 * create/update audit record if it already exists.
49341 */
49342- if (path->dentry->d_inode)
49343+ if (path->dentry->d_inode) {
49344+ /* only check if O_CREAT is specified, all other checks need to go
49345+ into may_open */
49346+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
49347+ error = -EACCES;
49348+ goto exit_dput;
49349+ }
49350+
49351 audit_inode(name, path->dentry, 0);
49352+ }
49353
49354 /*
49355 * If atomic_open() acquired write access it is dropped now due to
49356@@ -2849,6 +2956,11 @@ finish_lookup:
49357 }
49358 }
49359 BUG_ON(inode != path->dentry->d_inode);
49360+ /* if we're resolving a symlink to another symlink */
49361+ if (link && gr_handle_symlink_owner(link, inode)) {
49362+ error = -EACCES;
49363+ goto out;
49364+ }
49365 return 1;
49366 }
49367
49368@@ -2858,7 +2970,6 @@ finish_lookup:
49369 save_parent.dentry = nd->path.dentry;
49370 save_parent.mnt = mntget(path->mnt);
49371 nd->path.dentry = path->dentry;
49372-
49373 }
49374 nd->inode = inode;
49375 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
49376@@ -2867,6 +2978,22 @@ finish_lookup:
49377 path_put(&save_parent);
49378 return error;
49379 }
49380+
49381+#ifdef CONFIG_GRKERNSEC
49382+ if (nd->flags & LOOKUP_RCU) {
49383+ error = -ECHILD;
49384+ goto out;
49385+ }
49386+#endif
49387+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
49388+ error = -ENOENT;
49389+ goto out;
49390+ }
49391+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
49392+ error = -EACCES;
49393+ goto out;
49394+ }
49395+
49396 error = -EISDIR;
49397 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
49398 goto out;
49399@@ -2965,7 +3092,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
49400 if (unlikely(error))
49401 goto out;
49402
49403- error = do_last(nd, &path, file, op, &opened, pathname);
49404+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
49405 while (unlikely(error > 0)) { /* trailing symlink */
49406 struct path link = path;
49407 void *cookie;
49408@@ -2983,7 +3110,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
49409 error = follow_link(&link, nd, &cookie);
49410 if (unlikely(error))
49411 break;
49412- error = do_last(nd, &path, file, op, &opened, pathname);
49413+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
49414 put_link(nd, &link, cookie);
49415 }
49416 out:
49417@@ -3073,8 +3200,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
49418 goto unlock;
49419
49420 error = -EEXIST;
49421- if (dentry->d_inode)
49422+ if (dentry->d_inode) {
49423+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
49424+ error = -ENOENT;
49425+ }
49426 goto fail;
49427+ }
49428 /*
49429 * Special case - lookup gave negative, but... we had foo/bar/
49430 * From the vfs_mknod() POV we just have a negative dentry -
49431@@ -3125,6 +3256,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
49432 }
49433 EXPORT_SYMBOL(user_path_create);
49434
49435+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, int is_dir)
49436+{
49437+ struct filename *tmp = getname(pathname);
49438+ struct dentry *res;
49439+ if (IS_ERR(tmp))
49440+ return ERR_CAST(tmp);
49441+ res = kern_path_create(dfd, tmp->name, path, is_dir);
49442+ if (IS_ERR(res))
49443+ putname(tmp);
49444+ else
49445+ *to = tmp;
49446+ return res;
49447+}
49448+
49449 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
49450 {
49451 int error = may_create(dir, dentry);
49452@@ -3186,6 +3331,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
49453
49454 if (!IS_POSIXACL(path.dentry->d_inode))
49455 mode &= ~current_umask();
49456+
49457+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
49458+ error = -EPERM;
49459+ goto out;
49460+ }
49461+
49462+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
49463+ error = -EACCES;
49464+ goto out;
49465+ }
49466+
49467 error = security_path_mknod(&path, dentry, mode, dev);
49468 if (error)
49469 goto out;
49470@@ -3202,6 +3358,8 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
49471 break;
49472 }
49473 out:
49474+ if (!error)
49475+ gr_handle_create(dentry, path.mnt);
49476 done_path_create(&path, dentry);
49477 return error;
49478 }
49479@@ -3248,9 +3406,18 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode)
49480
49481 if (!IS_POSIXACL(path.dentry->d_inode))
49482 mode &= ~current_umask();
49483+
49484+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
49485+ error = -EACCES;
49486+ goto out;
49487+ }
49488+
49489 error = security_path_mkdir(&path, dentry, mode);
49490 if (!error)
49491 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
49492+ if (!error)
49493+ gr_handle_create(dentry, path.mnt);
49494+out:
49495 done_path_create(&path, dentry);
49496 return error;
49497 }
49498@@ -3327,6 +3494,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
49499 struct filename *name;
49500 struct dentry *dentry;
49501 struct nameidata nd;
49502+ ino_t saved_ino = 0;
49503+ dev_t saved_dev = 0;
49504
49505 name = user_path_parent(dfd, pathname, &nd);
49506 if (IS_ERR(name))
49507@@ -3358,10 +3527,21 @@ static long do_rmdir(int dfd, const char __user *pathname)
49508 error = -ENOENT;
49509 goto exit3;
49510 }
49511+
49512+ saved_ino = dentry->d_inode->i_ino;
49513+ saved_dev = gr_get_dev_from_dentry(dentry);
49514+
49515+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
49516+ error = -EACCES;
49517+ goto exit3;
49518+ }
49519+
49520 error = security_path_rmdir(&nd.path, dentry);
49521 if (error)
49522 goto exit3;
49523 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
49524+ if (!error && (saved_dev || saved_ino))
49525+ gr_handle_delete(saved_ino, saved_dev);
49526 exit3:
49527 dput(dentry);
49528 exit2:
49529@@ -3423,6 +3603,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
49530 struct dentry *dentry;
49531 struct nameidata nd;
49532 struct inode *inode = NULL;
49533+ ino_t saved_ino = 0;
49534+ dev_t saved_dev = 0;
49535
49536 name = user_path_parent(dfd, pathname, &nd);
49537 if (IS_ERR(name))
49538@@ -3448,10 +3630,22 @@ static long do_unlinkat(int dfd, const char __user *pathname)
49539 if (!inode)
49540 goto slashes;
49541 ihold(inode);
49542+
49543+ if (inode->i_nlink <= 1) {
49544+ saved_ino = inode->i_ino;
49545+ saved_dev = gr_get_dev_from_dentry(dentry);
49546+ }
49547+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
49548+ error = -EACCES;
49549+ goto exit2;
49550+ }
49551+
49552 error = security_path_unlink(&nd.path, dentry);
49553 if (error)
49554 goto exit2;
49555 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
49556+ if (!error && (saved_ino || saved_dev))
49557+ gr_handle_delete(saved_ino, saved_dev);
49558 exit2:
49559 dput(dentry);
49560 }
49561@@ -3523,9 +3717,17 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
49562 if (IS_ERR(dentry))
49563 goto out_putname;
49564
49565+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
49566+ error = -EACCES;
49567+ goto out;
49568+ }
49569+
49570 error = security_path_symlink(&path, dentry, from->name);
49571 if (!error)
49572 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
49573+ if (!error)
49574+ gr_handle_create(dentry, path.mnt);
49575+out:
49576 done_path_create(&path, dentry);
49577 out_putname:
49578 putname(from);
49579@@ -3595,6 +3797,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
49580 {
49581 struct dentry *new_dentry;
49582 struct path old_path, new_path;
49583+ struct filename *to = NULL;
49584 int how = 0;
49585 int error;
49586
49587@@ -3618,7 +3821,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
49588 if (error)
49589 return error;
49590
49591- new_dentry = user_path_create(newdfd, newname, &new_path, 0);
49592+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
49593 error = PTR_ERR(new_dentry);
49594 if (IS_ERR(new_dentry))
49595 goto out;
49596@@ -3629,11 +3832,28 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
49597 error = may_linkat(&old_path);
49598 if (unlikely(error))
49599 goto out_dput;
49600+
49601+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
49602+ old_path.dentry->d_inode,
49603+ old_path.dentry->d_inode->i_mode, to)) {
49604+ error = -EACCES;
49605+ goto out_dput;
49606+ }
49607+
49608+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
49609+ old_path.dentry, old_path.mnt, to)) {
49610+ error = -EACCES;
49611+ goto out_dput;
49612+ }
49613+
49614 error = security_path_link(old_path.dentry, &new_path, new_dentry);
49615 if (error)
49616 goto out_dput;
49617 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
49618+ if (!error)
49619+ gr_handle_create(new_dentry, new_path.mnt);
49620 out_dput:
49621+ putname(to);
49622 done_path_create(&new_path, new_dentry);
49623 out:
49624 path_put(&old_path);
49625@@ -3873,12 +4093,21 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
49626 if (new_dentry == trap)
49627 goto exit5;
49628
49629+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
49630+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
49631+ to);
49632+ if (error)
49633+ goto exit5;
49634+
49635 error = security_path_rename(&oldnd.path, old_dentry,
49636 &newnd.path, new_dentry);
49637 if (error)
49638 goto exit5;
49639 error = vfs_rename(old_dir->d_inode, old_dentry,
49640 new_dir->d_inode, new_dentry);
49641+ if (!error)
49642+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
49643+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
49644 exit5:
49645 dput(new_dentry);
49646 exit4:
49647@@ -3903,6 +4132,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
49648
49649 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
49650 {
49651+ char tmpbuf[64];
49652+ const char *newlink;
49653 int len;
49654
49655 len = PTR_ERR(link);
49656@@ -3912,7 +4143,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
49657 len = strlen(link);
49658 if (len > (unsigned) buflen)
49659 len = buflen;
49660- if (copy_to_user(buffer, link, len))
49661+
49662+ if (len < sizeof(tmpbuf)) {
49663+ memcpy(tmpbuf, link, len);
49664+ newlink = tmpbuf;
49665+ } else
49666+ newlink = link;
49667+
49668+ if (copy_to_user(buffer, newlink, len))
49669 len = -EFAULT;
49670 out:
49671 return len;
49672diff --git a/fs/namespace.c b/fs/namespace.c
49673index 2496062..e26f6d6 100644
49674--- a/fs/namespace.c
49675+++ b/fs/namespace.c
49676@@ -1212,6 +1212,9 @@ static int do_umount(struct mount *mnt, int flags)
49677 if (!(sb->s_flags & MS_RDONLY))
49678 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
49679 up_write(&sb->s_umount);
49680+
49681+ gr_log_remount(mnt->mnt_devname, retval);
49682+
49683 return retval;
49684 }
49685
49686@@ -1231,6 +1234,9 @@ static int do_umount(struct mount *mnt, int flags)
49687 br_write_unlock(&vfsmount_lock);
49688 up_write(&namespace_sem);
49689 release_mounts(&umount_list);
49690+
49691+ gr_log_unmount(mnt->mnt_devname, retval);
49692+
49693 return retval;
49694 }
49695
49696@@ -2244,6 +2250,16 @@ long do_mount(const char *dev_name, const char *dir_name,
49697 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
49698 MS_STRICTATIME);
49699
49700+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
49701+ retval = -EPERM;
49702+ goto dput_out;
49703+ }
49704+
49705+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
49706+ retval = -EPERM;
49707+ goto dput_out;
49708+ }
49709+
49710 if (flags & MS_REMOUNT)
49711 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
49712 data_page);
49713@@ -2258,6 +2274,9 @@ long do_mount(const char *dev_name, const char *dir_name,
49714 dev_name, data_page);
49715 dput_out:
49716 path_put(&path);
49717+
49718+ gr_log_mount(dev_name, dir_name, retval);
49719+
49720 return retval;
49721 }
49722
49723@@ -2516,6 +2535,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
49724 if (error)
49725 goto out2;
49726
49727+ if (gr_handle_chroot_pivot()) {
49728+ error = -EPERM;
49729+ goto out2;
49730+ }
49731+
49732 get_fs_root(current->fs, &root);
49733 error = lock_mount(&old);
49734 if (error)
49735diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
49736index 6fa01ae..2790820 100644
49737--- a/fs/nfs/inode.c
49738+++ b/fs/nfs/inode.c
49739@@ -1029,16 +1029,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
49740 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
49741 }
49742
49743-static atomic_long_t nfs_attr_generation_counter;
49744+static atomic_long_unchecked_t nfs_attr_generation_counter;
49745
49746 static unsigned long nfs_read_attr_generation_counter(void)
49747 {
49748- return atomic_long_read(&nfs_attr_generation_counter);
49749+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
49750 }
49751
49752 unsigned long nfs_inc_attr_generation_counter(void)
49753 {
49754- return atomic_long_inc_return(&nfs_attr_generation_counter);
49755+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
49756 }
49757
49758 void nfs_fattr_init(struct nfs_fattr *fattr)
49759diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
49760index c120b48..8ac4140 100644
49761--- a/fs/nfsd/vfs.c
49762+++ b/fs/nfsd/vfs.c
49763@@ -941,7 +941,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
49764 } else {
49765 oldfs = get_fs();
49766 set_fs(KERNEL_DS);
49767- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
49768+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
49769 set_fs(oldfs);
49770 }
49771
49772@@ -1045,7 +1045,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
49773
49774 /* Write the data. */
49775 oldfs = get_fs(); set_fs(KERNEL_DS);
49776- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
49777+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
49778 set_fs(oldfs);
49779 if (host_err < 0)
49780 goto out_nfserr;
49781@@ -1581,7 +1581,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
49782 */
49783
49784 oldfs = get_fs(); set_fs(KERNEL_DS);
49785- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
49786+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
49787 set_fs(oldfs);
49788
49789 if (host_err < 0)
49790diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
49791index 6fcaeb8..9d16d04 100644
49792--- a/fs/notify/fanotify/fanotify_user.c
49793+++ b/fs/notify/fanotify/fanotify_user.c
49794@@ -250,8 +250,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
49795
49796 fd = fanotify_event_metadata.fd;
49797 ret = -EFAULT;
49798- if (copy_to_user(buf, &fanotify_event_metadata,
49799- fanotify_event_metadata.event_len))
49800+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
49801+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
49802 goto out_close_fd;
49803
49804 ret = prepare_for_access_response(group, event, fd);
49805diff --git a/fs/notify/notification.c b/fs/notify/notification.c
49806index c887b13..0fdf472 100644
49807--- a/fs/notify/notification.c
49808+++ b/fs/notify/notification.c
49809@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
49810 * get set to 0 so it will never get 'freed'
49811 */
49812 static struct fsnotify_event *q_overflow_event;
49813-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
49814+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
49815
49816 /**
49817 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
49818@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
49819 */
49820 u32 fsnotify_get_cookie(void)
49821 {
49822- return atomic_inc_return(&fsnotify_sync_cookie);
49823+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
49824 }
49825 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
49826
49827diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
49828index 99e3610..02c1068 100644
49829--- a/fs/ntfs/dir.c
49830+++ b/fs/ntfs/dir.c
49831@@ -1329,7 +1329,7 @@ find_next_index_buffer:
49832 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
49833 ~(s64)(ndir->itype.index.block_size - 1)));
49834 /* Bounds checks. */
49835- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
49836+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
49837 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
49838 "inode 0x%lx or driver bug.", vdir->i_ino);
49839 goto err_out;
49840diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
49841index 1ecf464..e1ff8bf 100644
49842--- a/fs/ntfs/file.c
49843+++ b/fs/ntfs/file.c
49844@@ -2232,6 +2232,6 @@ const struct inode_operations ntfs_file_inode_ops = {
49845 #endif /* NTFS_RW */
49846 };
49847
49848-const struct file_operations ntfs_empty_file_ops = {};
49849+const struct file_operations ntfs_empty_file_ops __read_only;
49850
49851-const struct inode_operations ntfs_empty_inode_ops = {};
49852+const struct inode_operations ntfs_empty_inode_ops __read_only;
49853diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
49854index a9f78c7..ed8a381 100644
49855--- a/fs/ocfs2/localalloc.c
49856+++ b/fs/ocfs2/localalloc.c
49857@@ -1279,7 +1279,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
49858 goto bail;
49859 }
49860
49861- atomic_inc(&osb->alloc_stats.moves);
49862+ atomic_inc_unchecked(&osb->alloc_stats.moves);
49863
49864 bail:
49865 if (handle)
49866diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
49867index d355e6e..578d905 100644
49868--- a/fs/ocfs2/ocfs2.h
49869+++ b/fs/ocfs2/ocfs2.h
49870@@ -235,11 +235,11 @@ enum ocfs2_vol_state
49871
49872 struct ocfs2_alloc_stats
49873 {
49874- atomic_t moves;
49875- atomic_t local_data;
49876- atomic_t bitmap_data;
49877- atomic_t bg_allocs;
49878- atomic_t bg_extends;
49879+ atomic_unchecked_t moves;
49880+ atomic_unchecked_t local_data;
49881+ atomic_unchecked_t bitmap_data;
49882+ atomic_unchecked_t bg_allocs;
49883+ atomic_unchecked_t bg_extends;
49884 };
49885
49886 enum ocfs2_local_alloc_state
49887diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
49888index f169da4..9112253 100644
49889--- a/fs/ocfs2/suballoc.c
49890+++ b/fs/ocfs2/suballoc.c
49891@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
49892 mlog_errno(status);
49893 goto bail;
49894 }
49895- atomic_inc(&osb->alloc_stats.bg_extends);
49896+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
49897
49898 /* You should never ask for this much metadata */
49899 BUG_ON(bits_wanted >
49900@@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
49901 mlog_errno(status);
49902 goto bail;
49903 }
49904- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
49905+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
49906
49907 *suballoc_loc = res.sr_bg_blkno;
49908 *suballoc_bit_start = res.sr_bit_offset;
49909@@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
49910 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
49911 res->sr_bits);
49912
49913- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
49914+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
49915
49916 BUG_ON(res->sr_bits != 1);
49917
49918@@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
49919 mlog_errno(status);
49920 goto bail;
49921 }
49922- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
49923+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
49924
49925 BUG_ON(res.sr_bits != 1);
49926
49927@@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
49928 cluster_start,
49929 num_clusters);
49930 if (!status)
49931- atomic_inc(&osb->alloc_stats.local_data);
49932+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
49933 } else {
49934 if (min_clusters > (osb->bitmap_cpg - 1)) {
49935 /* The only paths asking for contiguousness
49936@@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
49937 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
49938 res.sr_bg_blkno,
49939 res.sr_bit_offset);
49940- atomic_inc(&osb->alloc_stats.bitmap_data);
49941+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
49942 *num_clusters = res.sr_bits;
49943 }
49944 }
49945diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
49946index 0e91ec2..f4b3fc6 100644
49947--- a/fs/ocfs2/super.c
49948+++ b/fs/ocfs2/super.c
49949@@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
49950 "%10s => GlobalAllocs: %d LocalAllocs: %d "
49951 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
49952 "Stats",
49953- atomic_read(&osb->alloc_stats.bitmap_data),
49954- atomic_read(&osb->alloc_stats.local_data),
49955- atomic_read(&osb->alloc_stats.bg_allocs),
49956- atomic_read(&osb->alloc_stats.moves),
49957- atomic_read(&osb->alloc_stats.bg_extends));
49958+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
49959+ atomic_read_unchecked(&osb->alloc_stats.local_data),
49960+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
49961+ atomic_read_unchecked(&osb->alloc_stats.moves),
49962+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
49963
49964 out += snprintf(buf + out, len - out,
49965 "%10s => State: %u Descriptor: %llu Size: %u bits "
49966@@ -2121,11 +2121,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
49967 spin_lock_init(&osb->osb_xattr_lock);
49968 ocfs2_init_steal_slots(osb);
49969
49970- atomic_set(&osb->alloc_stats.moves, 0);
49971- atomic_set(&osb->alloc_stats.local_data, 0);
49972- atomic_set(&osb->alloc_stats.bitmap_data, 0);
49973- atomic_set(&osb->alloc_stats.bg_allocs, 0);
49974- atomic_set(&osb->alloc_stats.bg_extends, 0);
49975+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
49976+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
49977+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
49978+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
49979+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
49980
49981 /* Copy the blockcheck stats from the superblock probe */
49982 osb->osb_ecc_stats = *stats;
49983diff --git a/fs/open.c b/fs/open.c
49984index 59071f5..c6229a0 100644
49985--- a/fs/open.c
49986+++ b/fs/open.c
49987@@ -31,6 +31,8 @@
49988 #include <linux/ima.h>
49989 #include <linux/dnotify.h>
49990
49991+#define CREATE_TRACE_POINTS
49992+#include <trace/events/fs.h>
49993 #include "internal.h"
49994
49995 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
49996@@ -112,6 +114,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
49997 error = locks_verify_truncate(inode, NULL, length);
49998 if (!error)
49999 error = security_path_truncate(&path);
50000+
50001+ if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
50002+ error = -EACCES;
50003+
50004 if (!error)
50005 error = do_truncate(path.dentry, length, 0, NULL);
50006
50007@@ -362,6 +368,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
50008 if (__mnt_is_readonly(path.mnt))
50009 res = -EROFS;
50010
50011+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
50012+ res = -EACCES;
50013+
50014 out_path_release:
50015 path_put(&path);
50016 out:
50017@@ -388,6 +397,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
50018 if (error)
50019 goto dput_and_out;
50020
50021+ gr_log_chdir(path.dentry, path.mnt);
50022+
50023 set_fs_pwd(current->fs, &path);
50024
50025 dput_and_out:
50026@@ -413,6 +424,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
50027 goto out_putf;
50028
50029 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
50030+
50031+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
50032+ error = -EPERM;
50033+
50034+ if (!error)
50035+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
50036+
50037 if (!error)
50038 set_fs_pwd(current->fs, &f.file->f_path);
50039 out_putf:
50040@@ -441,7 +459,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
50041 if (error)
50042 goto dput_and_out;
50043
50044+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
50045+ goto dput_and_out;
50046+
50047 set_fs_root(current->fs, &path);
50048+
50049+ gr_handle_chroot_chdir(&path);
50050+
50051 error = 0;
50052 dput_and_out:
50053 path_put(&path);
50054@@ -459,6 +483,16 @@ static int chmod_common(struct path *path, umode_t mode)
50055 if (error)
50056 return error;
50057 mutex_lock(&inode->i_mutex);
50058+
50059+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
50060+ error = -EACCES;
50061+ goto out_unlock;
50062+ }
50063+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
50064+ error = -EACCES;
50065+ goto out_unlock;
50066+ }
50067+
50068 error = security_path_chmod(path, mode);
50069 if (error)
50070 goto out_unlock;
50071@@ -514,6 +548,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
50072 uid = make_kuid(current_user_ns(), user);
50073 gid = make_kgid(current_user_ns(), group);
50074
50075+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
50076+ return -EACCES;
50077+
50078 newattrs.ia_valid = ATTR_CTIME;
50079 if (user != (uid_t) -1) {
50080 if (!uid_valid(uid))
50081@@ -925,6 +962,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
50082 } else {
50083 fsnotify_open(f);
50084 fd_install(fd, f);
50085+ trace_do_sys_open(tmp->name, flags, mode);
50086 }
50087 }
50088 putname(tmp);
50089diff --git a/fs/pipe.c b/fs/pipe.c
50090index bd3479d..fb92c4d 100644
50091--- a/fs/pipe.c
50092+++ b/fs/pipe.c
50093@@ -438,9 +438,9 @@ redo:
50094 }
50095 if (bufs) /* More to do? */
50096 continue;
50097- if (!pipe->writers)
50098+ if (!atomic_read(&pipe->writers))
50099 break;
50100- if (!pipe->waiting_writers) {
50101+ if (!atomic_read(&pipe->waiting_writers)) {
50102 /* syscall merging: Usually we must not sleep
50103 * if O_NONBLOCK is set, or if we got some data.
50104 * But if a writer sleeps in kernel space, then
50105@@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
50106 mutex_lock(&inode->i_mutex);
50107 pipe = inode->i_pipe;
50108
50109- if (!pipe->readers) {
50110+ if (!atomic_read(&pipe->readers)) {
50111 send_sig(SIGPIPE, current, 0);
50112 ret = -EPIPE;
50113 goto out;
50114@@ -553,7 +553,7 @@ redo1:
50115 for (;;) {
50116 int bufs;
50117
50118- if (!pipe->readers) {
50119+ if (!atomic_read(&pipe->readers)) {
50120 send_sig(SIGPIPE, current, 0);
50121 if (!ret)
50122 ret = -EPIPE;
50123@@ -644,9 +644,9 @@ redo2:
50124 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
50125 do_wakeup = 0;
50126 }
50127- pipe->waiting_writers++;
50128+ atomic_inc(&pipe->waiting_writers);
50129 pipe_wait(pipe);
50130- pipe->waiting_writers--;
50131+ atomic_dec(&pipe->waiting_writers);
50132 }
50133 out:
50134 mutex_unlock(&inode->i_mutex);
50135@@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
50136 mask = 0;
50137 if (filp->f_mode & FMODE_READ) {
50138 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
50139- if (!pipe->writers && filp->f_version != pipe->w_counter)
50140+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
50141 mask |= POLLHUP;
50142 }
50143
50144@@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
50145 * Most Unices do not set POLLERR for FIFOs but on Linux they
50146 * behave exactly like pipes for poll().
50147 */
50148- if (!pipe->readers)
50149+ if (!atomic_read(&pipe->readers))
50150 mask |= POLLERR;
50151 }
50152
50153@@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
50154
50155 mutex_lock(&inode->i_mutex);
50156 pipe = inode->i_pipe;
50157- pipe->readers -= decr;
50158- pipe->writers -= decw;
50159+ atomic_sub(decr, &pipe->readers);
50160+ atomic_sub(decw, &pipe->writers);
50161
50162- if (!pipe->readers && !pipe->writers) {
50163+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
50164 free_pipe_info(inode);
50165 } else {
50166 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
50167@@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
50168
50169 if (inode->i_pipe) {
50170 ret = 0;
50171- inode->i_pipe->readers++;
50172+ atomic_inc(&inode->i_pipe->readers);
50173 }
50174
50175 mutex_unlock(&inode->i_mutex);
50176@@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
50177
50178 if (inode->i_pipe) {
50179 ret = 0;
50180- inode->i_pipe->writers++;
50181+ atomic_inc(&inode->i_pipe->writers);
50182 }
50183
50184 mutex_unlock(&inode->i_mutex);
50185@@ -868,9 +868,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
50186 if (inode->i_pipe) {
50187 ret = 0;
50188 if (filp->f_mode & FMODE_READ)
50189- inode->i_pipe->readers++;
50190+ atomic_inc(&inode->i_pipe->readers);
50191 if (filp->f_mode & FMODE_WRITE)
50192- inode->i_pipe->writers++;
50193+ atomic_inc(&inode->i_pipe->writers);
50194 }
50195
50196 mutex_unlock(&inode->i_mutex);
50197@@ -962,7 +962,7 @@ void free_pipe_info(struct inode *inode)
50198 inode->i_pipe = NULL;
50199 }
50200
50201-static struct vfsmount *pipe_mnt __read_mostly;
50202+struct vfsmount *pipe_mnt __read_mostly;
50203
50204 /*
50205 * pipefs_dname() is called from d_path().
50206@@ -992,7 +992,8 @@ static struct inode * get_pipe_inode(void)
50207 goto fail_iput;
50208 inode->i_pipe = pipe;
50209
50210- pipe->readers = pipe->writers = 1;
50211+ atomic_set(&pipe->readers, 1);
50212+ atomic_set(&pipe->writers, 1);
50213 inode->i_fop = &rdwr_pipefifo_fops;
50214
50215 /*
50216diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
50217index 15af622..0e9f4467 100644
50218--- a/fs/proc/Kconfig
50219+++ b/fs/proc/Kconfig
50220@@ -30,12 +30,12 @@ config PROC_FS
50221
50222 config PROC_KCORE
50223 bool "/proc/kcore support" if !ARM
50224- depends on PROC_FS && MMU
50225+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
50226
50227 config PROC_VMCORE
50228 bool "/proc/vmcore support"
50229- depends on PROC_FS && CRASH_DUMP
50230- default y
50231+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
50232+ default n
50233 help
50234 Exports the dump image of crashed kernel in ELF format.
50235
50236@@ -59,8 +59,8 @@ config PROC_SYSCTL
50237 limited in memory.
50238
50239 config PROC_PAGE_MONITOR
50240- default y
50241- depends on PROC_FS && MMU
50242+ default n
50243+ depends on PROC_FS && MMU && !GRKERNSEC
50244 bool "Enable /proc page monitoring" if EXPERT
50245 help
50246 Various /proc files exist to monitor process memory utilization:
50247diff --git a/fs/proc/array.c b/fs/proc/array.c
50248index c1c207c..01ce725 100644
50249--- a/fs/proc/array.c
50250+++ b/fs/proc/array.c
50251@@ -60,6 +60,7 @@
50252 #include <linux/tty.h>
50253 #include <linux/string.h>
50254 #include <linux/mman.h>
50255+#include <linux/grsecurity.h>
50256 #include <linux/proc_fs.h>
50257 #include <linux/ioport.h>
50258 #include <linux/uaccess.h>
50259@@ -346,6 +347,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
50260 seq_putc(m, '\n');
50261 }
50262
50263+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
50264+static inline void task_pax(struct seq_file *m, struct task_struct *p)
50265+{
50266+ if (p->mm)
50267+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
50268+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
50269+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
50270+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
50271+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
50272+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
50273+ else
50274+ seq_printf(m, "PaX:\t-----\n");
50275+}
50276+#endif
50277+
50278 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
50279 struct pid *pid, struct task_struct *task)
50280 {
50281@@ -363,9 +379,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
50282 task_cpus_allowed(m, task);
50283 cpuset_task_status_allowed(m, task);
50284 task_context_switch_counts(m, task);
50285+
50286+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
50287+ task_pax(m, task);
50288+#endif
50289+
50290+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
50291+ task_grsec_rbac(m, task);
50292+#endif
50293+
50294 return 0;
50295 }
50296
50297+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50298+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
50299+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
50300+ _mm->pax_flags & MF_PAX_SEGMEXEC))
50301+#endif
50302+
50303 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
50304 struct pid *pid, struct task_struct *task, int whole)
50305 {
50306@@ -387,6 +418,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
50307 char tcomm[sizeof(task->comm)];
50308 unsigned long flags;
50309
50310+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50311+ if (current->exec_id != m->exec_id) {
50312+ gr_log_badprocpid("stat");
50313+ return 0;
50314+ }
50315+#endif
50316+
50317 state = *get_task_state(task);
50318 vsize = eip = esp = 0;
50319 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
50320@@ -458,6 +496,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
50321 gtime = task->gtime;
50322 }
50323
50324+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50325+ if (PAX_RAND_FLAGS(mm)) {
50326+ eip = 0;
50327+ esp = 0;
50328+ wchan = 0;
50329+ }
50330+#endif
50331+#ifdef CONFIG_GRKERNSEC_HIDESYM
50332+ wchan = 0;
50333+ eip =0;
50334+ esp =0;
50335+#endif
50336+
50337 /* scale priority and nice values from timeslices to -20..20 */
50338 /* to make it look like a "normal" Unix priority/nice value */
50339 priority = task_prio(task);
50340@@ -494,9 +545,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
50341 seq_put_decimal_ull(m, ' ', vsize);
50342 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
50343 seq_put_decimal_ull(m, ' ', rsslim);
50344+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50345+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
50346+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
50347+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
50348+#else
50349 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
50350 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
50351 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
50352+#endif
50353 seq_put_decimal_ull(m, ' ', esp);
50354 seq_put_decimal_ull(m, ' ', eip);
50355 /* The signal information here is obsolete.
50356@@ -518,7 +575,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
50357 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
50358 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
50359
50360- if (mm && permitted) {
50361+ if (mm && permitted
50362+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50363+ && !PAX_RAND_FLAGS(mm)
50364+#endif
50365+ ) {
50366 seq_put_decimal_ull(m, ' ', mm->start_data);
50367 seq_put_decimal_ull(m, ' ', mm->end_data);
50368 seq_put_decimal_ull(m, ' ', mm->start_brk);
50369@@ -556,8 +617,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
50370 struct pid *pid, struct task_struct *task)
50371 {
50372 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
50373- struct mm_struct *mm = get_task_mm(task);
50374+ struct mm_struct *mm;
50375
50376+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50377+ if (current->exec_id != m->exec_id) {
50378+ gr_log_badprocpid("statm");
50379+ return 0;
50380+ }
50381+#endif
50382+ mm = get_task_mm(task);
50383 if (mm) {
50384 size = task_statm(mm, &shared, &text, &data, &resident);
50385 mmput(mm);
50386@@ -580,6 +648,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
50387 return 0;
50388 }
50389
50390+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
50391+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
50392+{
50393+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
50394+}
50395+#endif
50396+
50397 #ifdef CONFIG_CHECKPOINT_RESTORE
50398 static struct pid *
50399 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
50400diff --git a/fs/proc/base.c b/fs/proc/base.c
50401index 9e28356..c485b3c 100644
50402--- a/fs/proc/base.c
50403+++ b/fs/proc/base.c
50404@@ -111,6 +111,14 @@ struct pid_entry {
50405 union proc_op op;
50406 };
50407
50408+struct getdents_callback {
50409+ struct linux_dirent __user * current_dir;
50410+ struct linux_dirent __user * previous;
50411+ struct file * file;
50412+ int count;
50413+ int error;
50414+};
50415+
50416 #define NOD(NAME, MODE, IOP, FOP, OP) { \
50417 .name = (NAME), \
50418 .len = sizeof(NAME) - 1, \
50419@@ -208,6 +216,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
50420 if (!mm->arg_end)
50421 goto out_mm; /* Shh! No looking before we're done */
50422
50423+ if (gr_acl_handle_procpidmem(task))
50424+ goto out_mm;
50425+
50426 len = mm->arg_end - mm->arg_start;
50427
50428 if (len > PAGE_SIZE)
50429@@ -235,12 +246,28 @@ out:
50430 return res;
50431 }
50432
50433+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50434+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
50435+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
50436+ _mm->pax_flags & MF_PAX_SEGMEXEC))
50437+#endif
50438+
50439 static int proc_pid_auxv(struct task_struct *task, char *buffer)
50440 {
50441 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
50442 int res = PTR_ERR(mm);
50443 if (mm && !IS_ERR(mm)) {
50444 unsigned int nwords = 0;
50445+
50446+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50447+ /* allow if we're currently ptracing this task */
50448+ if (PAX_RAND_FLAGS(mm) &&
50449+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
50450+ mmput(mm);
50451+ return 0;
50452+ }
50453+#endif
50454+
50455 do {
50456 nwords += 2;
50457 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
50458@@ -254,7 +281,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
50459 }
50460
50461
50462-#ifdef CONFIG_KALLSYMS
50463+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
50464 /*
50465 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
50466 * Returns the resolved symbol. If that fails, simply return the address.
50467@@ -293,7 +320,7 @@ static void unlock_trace(struct task_struct *task)
50468 mutex_unlock(&task->signal->cred_guard_mutex);
50469 }
50470
50471-#ifdef CONFIG_STACKTRACE
50472+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
50473
50474 #define MAX_STACK_TRACE_DEPTH 64
50475
50476@@ -485,7 +512,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
50477 return count;
50478 }
50479
50480-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
50481+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
50482 static int proc_pid_syscall(struct task_struct *task, char *buffer)
50483 {
50484 long nr;
50485@@ -514,7 +541,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
50486 /************************************************************************/
50487
50488 /* permission checks */
50489-static int proc_fd_access_allowed(struct inode *inode)
50490+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
50491 {
50492 struct task_struct *task;
50493 int allowed = 0;
50494@@ -524,7 +551,10 @@ static int proc_fd_access_allowed(struct inode *inode)
50495 */
50496 task = get_proc_task(inode);
50497 if (task) {
50498- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
50499+ if (log)
50500+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
50501+ else
50502+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
50503 put_task_struct(task);
50504 }
50505 return allowed;
50506@@ -562,10 +592,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
50507 struct task_struct *task,
50508 int hide_pid_min)
50509 {
50510+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
50511+ return false;
50512+
50513+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50514+ rcu_read_lock();
50515+ {
50516+ const struct cred *tmpcred = current_cred();
50517+ const struct cred *cred = __task_cred(task);
50518+
50519+ if (!tmpcred->uid || (tmpcred->uid == cred->uid)
50520+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
50521+ || in_group_p(grsec_proc_gid)
50522+#endif
50523+ ) {
50524+ rcu_read_unlock();
50525+ return true;
50526+ }
50527+ }
50528+ rcu_read_unlock();
50529+
50530+ if (!pid->hide_pid)
50531+ return false;
50532+#endif
50533+
50534 if (pid->hide_pid < hide_pid_min)
50535 return true;
50536 if (in_group_p(pid->pid_gid))
50537 return true;
50538+
50539 return ptrace_may_access(task, PTRACE_MODE_READ);
50540 }
50541
50542@@ -583,7 +638,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
50543 put_task_struct(task);
50544
50545 if (!has_perms) {
50546+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50547+ {
50548+#else
50549 if (pid->hide_pid == 2) {
50550+#endif
50551 /*
50552 * Let's make getdents(), stat(), and open()
50553 * consistent with each other. If a process
50554@@ -681,6 +740,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
50555 if (!task)
50556 return -ESRCH;
50557
50558+ if (gr_acl_handle_procpidmem(task)) {
50559+ put_task_struct(task);
50560+ return -EPERM;
50561+ }
50562+
50563 mm = mm_access(task, mode);
50564 put_task_struct(task);
50565
50566@@ -696,6 +760,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
50567
50568 file->private_data = mm;
50569
50570+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50571+ file->f_version = current->exec_id;
50572+#endif
50573+
50574 return 0;
50575 }
50576
50577@@ -717,6 +785,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
50578 ssize_t copied;
50579 char *page;
50580
50581+#ifdef CONFIG_GRKERNSEC
50582+ if (write)
50583+ return -EPERM;
50584+#endif
50585+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50586+ if (file->f_version != current->exec_id) {
50587+ gr_log_badprocpid("mem");
50588+ return 0;
50589+ }
50590+#endif
50591+
50592 if (!mm)
50593 return 0;
50594
50595@@ -821,6 +900,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
50596 if (!mm)
50597 return 0;
50598
50599+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50600+ if (file->f_version != current->exec_id) {
50601+ gr_log_badprocpid("environ");
50602+ return 0;
50603+ }
50604+#endif
50605+
50606 page = (char *)__get_free_page(GFP_TEMPORARY);
50607 if (!page)
50608 return -ENOMEM;
50609@@ -1436,7 +1522,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
50610 int error = -EACCES;
50611
50612 /* Are we allowed to snoop on the tasks file descriptors? */
50613- if (!proc_fd_access_allowed(inode))
50614+ if (!proc_fd_access_allowed(inode, 0))
50615 goto out;
50616
50617 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
50618@@ -1480,8 +1566,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
50619 struct path path;
50620
50621 /* Are we allowed to snoop on the tasks file descriptors? */
50622- if (!proc_fd_access_allowed(inode))
50623- goto out;
50624+ /* logging this is needed for learning on chromium to work properly,
50625+ but we don't want to flood the logs from 'ps' which does a readlink
50626+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
50627+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
50628+ */
50629+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
50630+ if (!proc_fd_access_allowed(inode,0))
50631+ goto out;
50632+ } else {
50633+ if (!proc_fd_access_allowed(inode,1))
50634+ goto out;
50635+ }
50636
50637 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
50638 if (error)
50639@@ -1531,7 +1627,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
50640 rcu_read_lock();
50641 cred = __task_cred(task);
50642 inode->i_uid = cred->euid;
50643+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
50644+ inode->i_gid = grsec_proc_gid;
50645+#else
50646 inode->i_gid = cred->egid;
50647+#endif
50648 rcu_read_unlock();
50649 }
50650 security_task_to_inode(task, inode);
50651@@ -1567,10 +1667,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
50652 return -ENOENT;
50653 }
50654 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
50655+#ifdef CONFIG_GRKERNSEC_PROC_USER
50656+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
50657+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50658+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
50659+#endif
50660 task_dumpable(task)) {
50661 cred = __task_cred(task);
50662 stat->uid = cred->euid;
50663+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
50664+ stat->gid = grsec_proc_gid;
50665+#else
50666 stat->gid = cred->egid;
50667+#endif
50668 }
50669 }
50670 rcu_read_unlock();
50671@@ -1608,11 +1717,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
50672
50673 if (task) {
50674 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
50675+#ifdef CONFIG_GRKERNSEC_PROC_USER
50676+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
50677+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50678+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
50679+#endif
50680 task_dumpable(task)) {
50681 rcu_read_lock();
50682 cred = __task_cred(task);
50683 inode->i_uid = cred->euid;
50684+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
50685+ inode->i_gid = grsec_proc_gid;
50686+#else
50687 inode->i_gid = cred->egid;
50688+#endif
50689 rcu_read_unlock();
50690 } else {
50691 inode->i_uid = GLOBAL_ROOT_UID;
50692@@ -2065,6 +2183,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
50693 if (!task)
50694 goto out_no_task;
50695
50696+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
50697+ goto out;
50698+
50699 /*
50700 * Yes, it does not scale. And it should not. Don't add
50701 * new entries into /proc/<tgid>/ without very good reasons.
50702@@ -2109,6 +2230,9 @@ static int proc_pident_readdir(struct file *filp,
50703 if (!task)
50704 goto out_no_task;
50705
50706+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
50707+ goto out;
50708+
50709 ret = 0;
50710 i = filp->f_pos;
50711 switch (i) {
50712@@ -2380,7 +2504,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
50713 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
50714 void *cookie)
50715 {
50716- char *s = nd_get_link(nd);
50717+ const char *s = nd_get_link(nd);
50718 if (!IS_ERR(s))
50719 kfree(s);
50720 }
50721@@ -2662,7 +2786,7 @@ static const struct pid_entry tgid_base_stuff[] = {
50722 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
50723 #endif
50724 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
50725-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
50726+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
50727 INF("syscall", S_IRUGO, proc_pid_syscall),
50728 #endif
50729 INF("cmdline", S_IRUGO, proc_pid_cmdline),
50730@@ -2687,10 +2811,10 @@ static const struct pid_entry tgid_base_stuff[] = {
50731 #ifdef CONFIG_SECURITY
50732 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
50733 #endif
50734-#ifdef CONFIG_KALLSYMS
50735+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
50736 INF("wchan", S_IRUGO, proc_pid_wchan),
50737 #endif
50738-#ifdef CONFIG_STACKTRACE
50739+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
50740 ONE("stack", S_IRUGO, proc_pid_stack),
50741 #endif
50742 #ifdef CONFIG_SCHEDSTATS
50743@@ -2724,6 +2848,9 @@ static const struct pid_entry tgid_base_stuff[] = {
50744 #ifdef CONFIG_HARDWALL
50745 INF("hardwall", S_IRUGO, proc_pid_hardwall),
50746 #endif
50747+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
50748+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
50749+#endif
50750 #ifdef CONFIG_USER_NS
50751 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
50752 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
50753@@ -2856,7 +2983,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
50754 if (!inode)
50755 goto out;
50756
50757+#ifdef CONFIG_GRKERNSEC_PROC_USER
50758+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
50759+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50760+ inode->i_gid = grsec_proc_gid;
50761+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
50762+#else
50763 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
50764+#endif
50765 inode->i_op = &proc_tgid_base_inode_operations;
50766 inode->i_fop = &proc_tgid_base_operations;
50767 inode->i_flags|=S_IMMUTABLE;
50768@@ -2898,7 +3032,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
50769 if (!task)
50770 goto out;
50771
50772+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
50773+ goto out_put_task;
50774+
50775 result = proc_pid_instantiate(dir, dentry, task, NULL);
50776+out_put_task:
50777 put_task_struct(task);
50778 out:
50779 return result;
50780@@ -2961,6 +3099,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
50781 static int fake_filldir(void *buf, const char *name, int namelen,
50782 loff_t offset, u64 ino, unsigned d_type)
50783 {
50784+ struct getdents_callback * __buf = (struct getdents_callback *) buf;
50785+ __buf->error = -EINVAL;
50786 return 0;
50787 }
50788
50789@@ -3027,7 +3167,7 @@ static const struct pid_entry tid_base_stuff[] = {
50790 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
50791 #endif
50792 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
50793-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
50794+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
50795 INF("syscall", S_IRUGO, proc_pid_syscall),
50796 #endif
50797 INF("cmdline", S_IRUGO, proc_pid_cmdline),
50798@@ -3054,10 +3194,10 @@ static const struct pid_entry tid_base_stuff[] = {
50799 #ifdef CONFIG_SECURITY
50800 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
50801 #endif
50802-#ifdef CONFIG_KALLSYMS
50803+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
50804 INF("wchan", S_IRUGO, proc_pid_wchan),
50805 #endif
50806-#ifdef CONFIG_STACKTRACE
50807+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
50808 ONE("stack", S_IRUGO, proc_pid_stack),
50809 #endif
50810 #ifdef CONFIG_SCHEDSTATS
50811diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
50812index 82676e3..5f8518a 100644
50813--- a/fs/proc/cmdline.c
50814+++ b/fs/proc/cmdline.c
50815@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
50816
50817 static int __init proc_cmdline_init(void)
50818 {
50819+#ifdef CONFIG_GRKERNSEC_PROC_ADD
50820+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
50821+#else
50822 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
50823+#endif
50824 return 0;
50825 }
50826 module_init(proc_cmdline_init);
50827diff --git a/fs/proc/devices.c b/fs/proc/devices.c
50828index b143471..bb105e5 100644
50829--- a/fs/proc/devices.c
50830+++ b/fs/proc/devices.c
50831@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
50832
50833 static int __init proc_devices_init(void)
50834 {
50835+#ifdef CONFIG_GRKERNSEC_PROC_ADD
50836+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
50837+#else
50838 proc_create("devices", 0, NULL, &proc_devinfo_operations);
50839+#endif
50840 return 0;
50841 }
50842 module_init(proc_devices_init);
50843diff --git a/fs/proc/fd.c b/fs/proc/fd.c
50844index f28a875..c467953 100644
50845--- a/fs/proc/fd.c
50846+++ b/fs/proc/fd.c
50847@@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
50848 if (!task)
50849 return -ENOENT;
50850
50851- files = get_files_struct(task);
50852+ if (!gr_acl_handle_procpidmem(task))
50853+ files = get_files_struct(task);
50854 put_task_struct(task);
50855
50856 if (files) {
50857@@ -300,11 +301,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
50858 */
50859 int proc_fd_permission(struct inode *inode, int mask)
50860 {
50861+ struct task_struct *task;
50862 int rv = generic_permission(inode, mask);
50863- if (rv == 0)
50864- return 0;
50865+
50866 if (task_pid(current) == proc_pid(inode))
50867 rv = 0;
50868+
50869+ task = get_proc_task(inode);
50870+ if (task == NULL)
50871+ return rv;
50872+
50873+ if (gr_acl_handle_procpidmem(task))
50874+ rv = -EACCES;
50875+
50876+ put_task_struct(task);
50877+
50878 return rv;
50879 }
50880
50881diff --git a/fs/proc/inode.c b/fs/proc/inode.c
50882index 3b22bbd..895b58c 100644
50883--- a/fs/proc/inode.c
50884+++ b/fs/proc/inode.c
50885@@ -21,11 +21,17 @@
50886 #include <linux/seq_file.h>
50887 #include <linux/slab.h>
50888 #include <linux/mount.h>
50889+#include <linux/grsecurity.h>
50890
50891 #include <asm/uaccess.h>
50892
50893 #include "internal.h"
50894
50895+#ifdef CONFIG_PROC_SYSCTL
50896+extern const struct inode_operations proc_sys_inode_operations;
50897+extern const struct inode_operations proc_sys_dir_operations;
50898+#endif
50899+
50900 static void proc_evict_inode(struct inode *inode)
50901 {
50902 struct proc_dir_entry *de;
50903@@ -51,6 +57,13 @@ static void proc_evict_inode(struct inode *inode)
50904 ns_ops = PROC_I(inode)->ns_ops;
50905 if (ns_ops && ns_ops->put)
50906 ns_ops->put(PROC_I(inode)->ns);
50907+
50908+#ifdef CONFIG_PROC_SYSCTL
50909+ if (inode->i_op == &proc_sys_inode_operations ||
50910+ inode->i_op == &proc_sys_dir_operations)
50911+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
50912+#endif
50913+
50914 }
50915
50916 static struct kmem_cache * proc_inode_cachep;
50917@@ -455,7 +468,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
50918 if (de->mode) {
50919 inode->i_mode = de->mode;
50920 inode->i_uid = de->uid;
50921+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
50922+ inode->i_gid = grsec_proc_gid;
50923+#else
50924 inode->i_gid = de->gid;
50925+#endif
50926 }
50927 if (de->size)
50928 inode->i_size = de->size;
50929diff --git a/fs/proc/internal.h b/fs/proc/internal.h
50930index 43973b0..a20e704 100644
50931--- a/fs/proc/internal.h
50932+++ b/fs/proc/internal.h
50933@@ -54,6 +54,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
50934 struct pid *pid, struct task_struct *task);
50935 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
50936 struct pid *pid, struct task_struct *task);
50937+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
50938+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
50939+#endif
50940 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
50941
50942 extern const struct file_operations proc_tid_children_operations;
50943diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
50944index 86c67ee..cdca321 100644
50945--- a/fs/proc/kcore.c
50946+++ b/fs/proc/kcore.c
50947@@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
50948 * the addresses in the elf_phdr on our list.
50949 */
50950 start = kc_offset_to_vaddr(*fpos - elf_buflen);
50951- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
50952+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
50953+ if (tsz > buflen)
50954 tsz = buflen;
50955-
50956+
50957 while (buflen) {
50958 struct kcore_list *m;
50959
50960@@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
50961 kfree(elf_buf);
50962 } else {
50963 if (kern_addr_valid(start)) {
50964- unsigned long n;
50965+ char *elf_buf;
50966+ mm_segment_t oldfs;
50967
50968- n = copy_to_user(buffer, (char *)start, tsz);
50969- /*
50970- * We cannot distinguish between fault on source
50971- * and fault on destination. When this happens
50972- * we clear too and hope it will trigger the
50973- * EFAULT again.
50974- */
50975- if (n) {
50976- if (clear_user(buffer + tsz - n,
50977- n))
50978+ elf_buf = kmalloc(tsz, GFP_KERNEL);
50979+ if (!elf_buf)
50980+ return -ENOMEM;
50981+ oldfs = get_fs();
50982+ set_fs(KERNEL_DS);
50983+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
50984+ set_fs(oldfs);
50985+ if (copy_to_user(buffer, elf_buf, tsz)) {
50986+ kfree(elf_buf);
50987 return -EFAULT;
50988+ }
50989 }
50990+ set_fs(oldfs);
50991+ kfree(elf_buf);
50992 } else {
50993 if (clear_user(buffer, tsz))
50994 return -EFAULT;
50995@@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
50996
50997 static int open_kcore(struct inode *inode, struct file *filp)
50998 {
50999+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
51000+ return -EPERM;
51001+#endif
51002 if (!capable(CAP_SYS_RAWIO))
51003 return -EPERM;
51004 if (kcore_need_update)
51005diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
51006index 80e4645..53e5fcf 100644
51007--- a/fs/proc/meminfo.c
51008+++ b/fs/proc/meminfo.c
51009@@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
51010 vmi.used >> 10,
51011 vmi.largest_chunk >> 10
51012 #ifdef CONFIG_MEMORY_FAILURE
51013- ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
51014+ ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
51015 #endif
51016 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
51017 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
51018diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
51019index b1822dd..df622cb 100644
51020--- a/fs/proc/nommu.c
51021+++ b/fs/proc/nommu.c
51022@@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
51023 if (len < 1)
51024 len = 1;
51025 seq_printf(m, "%*c", len, ' ');
51026- seq_path(m, &file->f_path, "");
51027+ seq_path(m, &file->f_path, "\n\\");
51028 }
51029
51030 seq_putc(m, '\n');
51031diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
51032index fe72cd0..cb9b67d 100644
51033--- a/fs/proc/proc_net.c
51034+++ b/fs/proc/proc_net.c
51035@@ -23,6 +23,7 @@
51036 #include <linux/nsproxy.h>
51037 #include <net/net_namespace.h>
51038 #include <linux/seq_file.h>
51039+#include <linux/grsecurity.h>
51040
51041 #include "internal.h"
51042
51043@@ -105,6 +106,17 @@ static struct net *get_proc_task_net(struct inode *dir)
51044 struct task_struct *task;
51045 struct nsproxy *ns;
51046 struct net *net = NULL;
51047+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51048+ const struct cred *cred = current_cred();
51049+#endif
51050+
51051+#ifdef CONFIG_GRKERNSEC_PROC_USER
51052+ if (cred->fsuid)
51053+ return net;
51054+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51055+ if (cred->fsuid && !in_group_p(grsec_proc_gid))
51056+ return net;
51057+#endif
51058
51059 rcu_read_lock();
51060 task = pid_task(proc_pid(dir), PIDTYPE_PID);
51061diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
51062index a781bdf..6665284 100644
51063--- a/fs/proc/proc_sysctl.c
51064+++ b/fs/proc/proc_sysctl.c
51065@@ -12,11 +12,15 @@
51066 #include <linux/module.h>
51067 #include "internal.h"
51068
51069+extern int gr_handle_chroot_sysctl(const int op);
51070+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
51071+ const int op);
51072+
51073 static const struct dentry_operations proc_sys_dentry_operations;
51074 static const struct file_operations proc_sys_file_operations;
51075-static const struct inode_operations proc_sys_inode_operations;
51076+const struct inode_operations proc_sys_inode_operations;
51077 static const struct file_operations proc_sys_dir_file_operations;
51078-static const struct inode_operations proc_sys_dir_operations;
51079+const struct inode_operations proc_sys_dir_operations;
51080
51081 void proc_sys_poll_notify(struct ctl_table_poll *poll)
51082 {
51083@@ -465,6 +469,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
51084
51085 err = NULL;
51086 d_set_d_op(dentry, &proc_sys_dentry_operations);
51087+
51088+ gr_handle_proc_create(dentry, inode);
51089+
51090 d_add(dentry, inode);
51091
51092 out:
51093@@ -480,18 +487,20 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
51094 struct inode *inode = filp->f_path.dentry->d_inode;
51095 struct ctl_table_header *head = grab_header(inode);
51096 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
51097+ int op = write ? MAY_WRITE : MAY_READ;
51098 ssize_t error;
51099 size_t res;
51100
51101 if (IS_ERR(head))
51102 return PTR_ERR(head);
51103
51104+
51105 /*
51106 * At this point we know that the sysctl was not unregistered
51107 * and won't be until we finish.
51108 */
51109 error = -EPERM;
51110- if (sysctl_perm(head->root, table, write ? MAY_WRITE : MAY_READ))
51111+ if (sysctl_perm(head->root, table, op))
51112 goto out;
51113
51114 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
51115@@ -499,6 +508,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
51116 if (!table->proc_handler)
51117 goto out;
51118
51119+#ifdef CONFIG_GRKERNSEC
51120+ error = -EPERM;
51121+ if (gr_handle_chroot_sysctl(op))
51122+ goto out;
51123+ dget(filp->f_path.dentry);
51124+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
51125+ dput(filp->f_path.dentry);
51126+ goto out;
51127+ }
51128+ dput(filp->f_path.dentry);
51129+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
51130+ goto out;
51131+ if (write && !capable(CAP_SYS_ADMIN))
51132+ goto out;
51133+#endif
51134+
51135 /* careful: calling conventions are nasty here */
51136 res = count;
51137 error = table->proc_handler(table, write, buf, &res, ppos);
51138@@ -596,6 +621,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
51139 return -ENOMEM;
51140 } else {
51141 d_set_d_op(child, &proc_sys_dentry_operations);
51142+
51143+ gr_handle_proc_create(child, inode);
51144+
51145 d_add(child, inode);
51146 }
51147 } else {
51148@@ -639,6 +667,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
51149 if ((*pos)++ < file->f_pos)
51150 return 0;
51151
51152+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
51153+ return 0;
51154+
51155 if (unlikely(S_ISLNK(table->mode)))
51156 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
51157 else
51158@@ -756,6 +787,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
51159 if (IS_ERR(head))
51160 return PTR_ERR(head);
51161
51162+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
51163+ return -ENOENT;
51164+
51165 generic_fillattr(inode, stat);
51166 if (table)
51167 stat->mode = (stat->mode & S_IFMT) | table->mode;
51168@@ -778,13 +812,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
51169 .llseek = generic_file_llseek,
51170 };
51171
51172-static const struct inode_operations proc_sys_inode_operations = {
51173+const struct inode_operations proc_sys_inode_operations = {
51174 .permission = proc_sys_permission,
51175 .setattr = proc_sys_setattr,
51176 .getattr = proc_sys_getattr,
51177 };
51178
51179-static const struct inode_operations proc_sys_dir_operations = {
51180+const struct inode_operations proc_sys_dir_operations = {
51181 .lookup = proc_sys_lookup,
51182 .permission = proc_sys_permission,
51183 .setattr = proc_sys_setattr,
51184diff --git a/fs/proc/root.c b/fs/proc/root.c
51185index 9889a92..2613b48 100644
51186--- a/fs/proc/root.c
51187+++ b/fs/proc/root.c
51188@@ -187,7 +187,15 @@ void __init proc_root_init(void)
51189 #ifdef CONFIG_PROC_DEVICETREE
51190 proc_device_tree_init();
51191 #endif
51192+#ifdef CONFIG_GRKERNSEC_PROC_ADD
51193+#ifdef CONFIG_GRKERNSEC_PROC_USER
51194+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
51195+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51196+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
51197+#endif
51198+#else
51199 proc_mkdir("bus", NULL);
51200+#endif
51201 proc_sys_init();
51202 }
51203
51204diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
51205index 90c63f9..e662cfc 100644
51206--- a/fs/proc/task_mmu.c
51207+++ b/fs/proc/task_mmu.c
51208@@ -11,12 +11,19 @@
51209 #include <linux/rmap.h>
51210 #include <linux/swap.h>
51211 #include <linux/swapops.h>
51212+#include <linux/grsecurity.h>
51213
51214 #include <asm/elf.h>
51215 #include <asm/uaccess.h>
51216 #include <asm/tlbflush.h>
51217 #include "internal.h"
51218
51219+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51220+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
51221+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
51222+ _mm->pax_flags & MF_PAX_SEGMEXEC))
51223+#endif
51224+
51225 void task_mem(struct seq_file *m, struct mm_struct *mm)
51226 {
51227 unsigned long data, text, lib, swap;
51228@@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
51229 "VmExe:\t%8lu kB\n"
51230 "VmLib:\t%8lu kB\n"
51231 "VmPTE:\t%8lu kB\n"
51232- "VmSwap:\t%8lu kB\n",
51233- hiwater_vm << (PAGE_SHIFT-10),
51234+ "VmSwap:\t%8lu kB\n"
51235+
51236+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
51237+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
51238+#endif
51239+
51240+ ,hiwater_vm << (PAGE_SHIFT-10),
51241 total_vm << (PAGE_SHIFT-10),
51242 mm->locked_vm << (PAGE_SHIFT-10),
51243 mm->pinned_vm << (PAGE_SHIFT-10),
51244@@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
51245 data << (PAGE_SHIFT-10),
51246 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
51247 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
51248- swap << (PAGE_SHIFT-10));
51249+ swap << (PAGE_SHIFT-10)
51250+
51251+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
51252+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51253+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
51254+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
51255+#else
51256+ , mm->context.user_cs_base
51257+ , mm->context.user_cs_limit
51258+#endif
51259+#endif
51260+
51261+ );
51262 }
51263
51264 unsigned long task_vsize(struct mm_struct *mm)
51265@@ -277,13 +301,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
51266 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
51267 }
51268
51269- /* We don't show the stack guard page in /proc/maps */
51270+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51271+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
51272+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
51273+#else
51274 start = vma->vm_start;
51275- if (stack_guard_page_start(vma, start))
51276- start += PAGE_SIZE;
51277 end = vma->vm_end;
51278- if (stack_guard_page_end(vma, end))
51279- end -= PAGE_SIZE;
51280+#endif
51281
51282 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
51283 start,
51284@@ -292,7 +316,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
51285 flags & VM_WRITE ? 'w' : '-',
51286 flags & VM_EXEC ? 'x' : '-',
51287 flags & VM_MAYSHARE ? 's' : 'p',
51288+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51289+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
51290+#else
51291 pgoff,
51292+#endif
51293 MAJOR(dev), MINOR(dev), ino, &len);
51294
51295 /*
51296@@ -301,7 +329,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
51297 */
51298 if (file) {
51299 pad_len_spaces(m, len);
51300- seq_path(m, &file->f_path, "\n");
51301+ seq_path(m, &file->f_path, "\n\\");
51302 goto done;
51303 }
51304
51305@@ -327,8 +355,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
51306 * Thread stack in /proc/PID/task/TID/maps or
51307 * the main process stack.
51308 */
51309- if (!is_pid || (vma->vm_start <= mm->start_stack &&
51310- vma->vm_end >= mm->start_stack)) {
51311+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
51312+ (vma->vm_start <= mm->start_stack &&
51313+ vma->vm_end >= mm->start_stack)) {
51314 name = "[stack]";
51315 } else {
51316 /* Thread stack in /proc/PID/maps */
51317@@ -352,6 +381,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
51318 struct proc_maps_private *priv = m->private;
51319 struct task_struct *task = priv->task;
51320
51321+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51322+ if (current->exec_id != m->exec_id) {
51323+ gr_log_badprocpid("maps");
51324+ return 0;
51325+ }
51326+#endif
51327+
51328 show_map_vma(m, vma, is_pid);
51329
51330 if (m->count < m->size) /* vma is copied successfully */
51331@@ -538,12 +574,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
51332 .private = &mss,
51333 };
51334
51335+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51336+ if (current->exec_id != m->exec_id) {
51337+ gr_log_badprocpid("smaps");
51338+ return 0;
51339+ }
51340+#endif
51341 memset(&mss, 0, sizeof mss);
51342- mss.vma = vma;
51343- /* mmap_sem is held in m_start */
51344- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
51345- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
51346-
51347+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51348+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
51349+#endif
51350+ mss.vma = vma;
51351+ /* mmap_sem is held in m_start */
51352+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
51353+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
51354+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51355+ }
51356+#endif
51357 show_map_vma(m, vma, is_pid);
51358
51359 seq_printf(m,
51360@@ -561,7 +608,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
51361 "KernelPageSize: %8lu kB\n"
51362 "MMUPageSize: %8lu kB\n"
51363 "Locked: %8lu kB\n",
51364+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51365+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
51366+#else
51367 (vma->vm_end - vma->vm_start) >> 10,
51368+#endif
51369 mss.resident >> 10,
51370 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
51371 mss.shared_clean >> 10,
51372@@ -1211,6 +1262,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
51373 int n;
51374 char buffer[50];
51375
51376+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51377+ if (current->exec_id != m->exec_id) {
51378+ gr_log_badprocpid("numa_maps");
51379+ return 0;
51380+ }
51381+#endif
51382+
51383 if (!mm)
51384 return 0;
51385
51386@@ -1228,11 +1286,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
51387 mpol_to_str(buffer, sizeof(buffer), pol, 0);
51388 mpol_cond_put(pol);
51389
51390+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51391+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
51392+#else
51393 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
51394+#endif
51395
51396 if (file) {
51397 seq_printf(m, " file=");
51398- seq_path(m, &file->f_path, "\n\t= ");
51399+ seq_path(m, &file->f_path, "\n\t\\= ");
51400 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
51401 seq_printf(m, " heap");
51402 } else {
51403diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
51404index 1ccfa53..0848f95 100644
51405--- a/fs/proc/task_nommu.c
51406+++ b/fs/proc/task_nommu.c
51407@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
51408 else
51409 bytes += kobjsize(mm);
51410
51411- if (current->fs && current->fs->users > 1)
51412+ if (current->fs && atomic_read(&current->fs->users) > 1)
51413 sbytes += kobjsize(current->fs);
51414 else
51415 bytes += kobjsize(current->fs);
51416@@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
51417
51418 if (file) {
51419 pad_len_spaces(m, len);
51420- seq_path(m, &file->f_path, "");
51421+ seq_path(m, &file->f_path, "\n\\");
51422 } else if (mm) {
51423 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
51424
51425diff --git a/fs/pstore/ftrace.c b/fs/pstore/ftrace.c
51426index 2d57e1a..43b1280 100644
51427--- a/fs/pstore/ftrace.c
51428+++ b/fs/pstore/ftrace.c
51429@@ -28,7 +28,9 @@
51430 #include "internal.h"
51431
51432 static void notrace pstore_ftrace_call(unsigned long ip,
51433- unsigned long parent_ip)
51434+ unsigned long parent_ip,
51435+ struct ftrace_ops *op,
51436+ struct pt_regs *regs)
51437 {
51438 unsigned long flags;
51439 struct pstore_ftrace_record rec = {};
51440diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
51441index 16e8abb..2dcf914 100644
51442--- a/fs/quota/netlink.c
51443+++ b/fs/quota/netlink.c
51444@@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
51445 void quota_send_warning(struct kqid qid, dev_t dev,
51446 const char warntype)
51447 {
51448- static atomic_t seq;
51449+ static atomic_unchecked_t seq;
51450 struct sk_buff *skb;
51451 void *msg_head;
51452 int ret;
51453@@ -49,7 +49,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
51454 "VFS: Not enough memory to send quota warning.\n");
51455 return;
51456 }
51457- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
51458+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
51459 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
51460 if (!msg_head) {
51461 printk(KERN_ERR
51462diff --git a/fs/read_write.c b/fs/read_write.c
51463index d065348..8e2b43d 100644
51464--- a/fs/read_write.c
51465+++ b/fs/read_write.c
51466@@ -935,6 +935,8 @@ ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos, size_t count,
51467 if (retval > 0) {
51468 add_rchar(current, retval);
51469 add_wchar(current, retval);
51470+ fsnotify_access(in.file);
51471+ fsnotify_modify(out.file);
51472 }
51473
51474 inc_syscr(current);
51475diff --git a/fs/readdir.c b/fs/readdir.c
51476index 5e69ef5..e5d9099 100644
51477--- a/fs/readdir.c
51478+++ b/fs/readdir.c
51479@@ -17,6 +17,7 @@
51480 #include <linux/security.h>
51481 #include <linux/syscalls.h>
51482 #include <linux/unistd.h>
51483+#include <linux/namei.h>
51484
51485 #include <asm/uaccess.h>
51486
51487@@ -67,6 +68,7 @@ struct old_linux_dirent {
51488
51489 struct readdir_callback {
51490 struct old_linux_dirent __user * dirent;
51491+ struct file * file;
51492 int result;
51493 };
51494
51495@@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
51496 buf->result = -EOVERFLOW;
51497 return -EOVERFLOW;
51498 }
51499+
51500+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
51501+ return 0;
51502+
51503 buf->result++;
51504 dirent = buf->dirent;
51505 if (!access_ok(VERIFY_WRITE, dirent,
51506@@ -114,6 +120,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
51507
51508 buf.result = 0;
51509 buf.dirent = dirent;
51510+ buf.file = f.file;
51511
51512 error = vfs_readdir(f.file, fillonedir, &buf);
51513 if (buf.result)
51514@@ -139,6 +146,7 @@ struct linux_dirent {
51515 struct getdents_callback {
51516 struct linux_dirent __user * current_dir;
51517 struct linux_dirent __user * previous;
51518+ struct file * file;
51519 int count;
51520 int error;
51521 };
51522@@ -160,6 +168,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
51523 buf->error = -EOVERFLOW;
51524 return -EOVERFLOW;
51525 }
51526+
51527+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
51528+ return 0;
51529+
51530 dirent = buf->previous;
51531 if (dirent) {
51532 if (__put_user(offset, &dirent->d_off))
51533@@ -205,6 +217,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
51534 buf.previous = NULL;
51535 buf.count = count;
51536 buf.error = 0;
51537+ buf.file = f.file;
51538
51539 error = vfs_readdir(f.file, filldir, &buf);
51540 if (error >= 0)
51541@@ -223,6 +236,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
51542 struct getdents_callback64 {
51543 struct linux_dirent64 __user * current_dir;
51544 struct linux_dirent64 __user * previous;
51545+ struct file *file;
51546 int count;
51547 int error;
51548 };
51549@@ -238,6 +252,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
51550 buf->error = -EINVAL; /* only used if we fail.. */
51551 if (reclen > buf->count)
51552 return -EINVAL;
51553+
51554+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
51555+ return 0;
51556+
51557 dirent = buf->previous;
51558 if (dirent) {
51559 if (__put_user(offset, &dirent->d_off))
51560@@ -283,6 +301,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
51561
51562 buf.current_dir = dirent;
51563 buf.previous = NULL;
51564+ buf.file = f.file;
51565 buf.count = count;
51566 buf.error = 0;
51567
51568@@ -291,7 +310,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
51569 error = buf.error;
51570 lastdirent = buf.previous;
51571 if (lastdirent) {
51572- typeof(lastdirent->d_off) d_off = f.file->f_pos;
51573+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
51574 if (__put_user(d_off, &lastdirent->d_off))
51575 error = -EFAULT;
51576 else
51577diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
51578index 2b7882b..1c5ef48 100644
51579--- a/fs/reiserfs/do_balan.c
51580+++ b/fs/reiserfs/do_balan.c
51581@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
51582 return;
51583 }
51584
51585- atomic_inc(&(fs_generation(tb->tb_sb)));
51586+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
51587 do_balance_starts(tb);
51588
51589 /* balance leaf returns 0 except if combining L R and S into
51590diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
51591index e60e870..f40ac16 100644
51592--- a/fs/reiserfs/procfs.c
51593+++ b/fs/reiserfs/procfs.c
51594@@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
51595 "SMALL_TAILS " : "NO_TAILS ",
51596 replay_only(sb) ? "REPLAY_ONLY " : "",
51597 convert_reiserfs(sb) ? "CONV " : "",
51598- atomic_read(&r->s_generation_counter),
51599+ atomic_read_unchecked(&r->s_generation_counter),
51600 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
51601 SF(s_do_balance), SF(s_unneeded_left_neighbor),
51602 SF(s_good_search_by_key_reada), SF(s_bmaps),
51603diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
51604index 33215f5..c5d427a 100644
51605--- a/fs/reiserfs/reiserfs.h
51606+++ b/fs/reiserfs/reiserfs.h
51607@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
51608 /* Comment? -Hans */
51609 wait_queue_head_t s_wait;
51610 /* To be obsoleted soon by per buffer seals.. -Hans */
51611- atomic_t s_generation_counter; // increased by one every time the
51612+ atomic_unchecked_t s_generation_counter; // increased by one every time the
51613 // tree gets re-balanced
51614 unsigned long s_properties; /* File system properties. Currently holds
51615 on-disk FS format */
51616@@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
51617 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
51618
51619 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
51620-#define get_generation(s) atomic_read (&fs_generation(s))
51621+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
51622 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
51623 #define __fs_changed(gen,s) (gen != get_generation (s))
51624 #define fs_changed(gen,s) \
51625diff --git a/fs/select.c b/fs/select.c
51626index 2ef72d9..f213b17 100644
51627--- a/fs/select.c
51628+++ b/fs/select.c
51629@@ -20,6 +20,7 @@
51630 #include <linux/export.h>
51631 #include <linux/slab.h>
51632 #include <linux/poll.h>
51633+#include <linux/security.h>
51634 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
51635 #include <linux/file.h>
51636 #include <linux/fdtable.h>
51637@@ -826,6 +827,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
51638 struct poll_list *walk = head;
51639 unsigned long todo = nfds;
51640
51641+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
51642 if (nfds > rlimit(RLIMIT_NOFILE))
51643 return -EINVAL;
51644
51645diff --git a/fs/seq_file.c b/fs/seq_file.c
51646index 99dffab..884a1eb 100644
51647--- a/fs/seq_file.c
51648+++ b/fs/seq_file.c
51649@@ -10,6 +10,7 @@
51650 #include <linux/seq_file.h>
51651 #include <linux/slab.h>
51652 #include <linux/cred.h>
51653+#include <linux/sched.h>
51654
51655 #include <asm/uaccess.h>
51656 #include <asm/page.h>
51657@@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
51658 #ifdef CONFIG_USER_NS
51659 p->user_ns = file->f_cred->user_ns;
51660 #endif
51661+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51662+ p->exec_id = current->exec_id;
51663+#endif
51664
51665 /*
51666 * Wrappers around seq_open(e.g. swaps_open) need to be
51667@@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
51668 return 0;
51669 }
51670 if (!m->buf) {
51671- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
51672+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
51673 if (!m->buf)
51674 return -ENOMEM;
51675 }
51676@@ -136,7 +140,7 @@ static int traverse(struct seq_file *m, loff_t offset)
51677 Eoverflow:
51678 m->op->stop(m, p);
51679 kfree(m->buf);
51680- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
51681+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
51682 return !m->buf ? -ENOMEM : -EAGAIN;
51683 }
51684
51685@@ -191,7 +195,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
51686
51687 /* grab buffer if we didn't have one */
51688 if (!m->buf) {
51689- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
51690+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
51691 if (!m->buf)
51692 goto Enomem;
51693 }
51694@@ -232,7 +236,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
51695 goto Fill;
51696 m->op->stop(m, p);
51697 kfree(m->buf);
51698- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
51699+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
51700 if (!m->buf)
51701 goto Enomem;
51702 m->count = 0;
51703@@ -581,7 +585,7 @@ static void single_stop(struct seq_file *p, void *v)
51704 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
51705 void *data)
51706 {
51707- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
51708+ seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
51709 int res = -ENOMEM;
51710
51711 if (op) {
51712diff --git a/fs/splice.c b/fs/splice.c
51713index 13e5b47..2262998 100644
51714--- a/fs/splice.c
51715+++ b/fs/splice.c
51716@@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
51717 pipe_lock(pipe);
51718
51719 for (;;) {
51720- if (!pipe->readers) {
51721+ if (!atomic_read(&pipe->readers)) {
51722 send_sig(SIGPIPE, current, 0);
51723 if (!ret)
51724 ret = -EPIPE;
51725@@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
51726 do_wakeup = 0;
51727 }
51728
51729- pipe->waiting_writers++;
51730+ atomic_inc(&pipe->waiting_writers);
51731 pipe_wait(pipe);
51732- pipe->waiting_writers--;
51733+ atomic_dec(&pipe->waiting_writers);
51734 }
51735
51736 pipe_unlock(pipe);
51737@@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
51738 old_fs = get_fs();
51739 set_fs(get_ds());
51740 /* The cast to a user pointer is valid due to the set_fs() */
51741- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
51742+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
51743 set_fs(old_fs);
51744
51745 return res;
51746@@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
51747 old_fs = get_fs();
51748 set_fs(get_ds());
51749 /* The cast to a user pointer is valid due to the set_fs() */
51750- res = vfs_write(file, (const char __user *)buf, count, &pos);
51751+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
51752 set_fs(old_fs);
51753
51754 return res;
51755@@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
51756 goto err;
51757
51758 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
51759- vec[i].iov_base = (void __user *) page_address(page);
51760+ vec[i].iov_base = (void __force_user *) page_address(page);
51761 vec[i].iov_len = this_len;
51762 spd.pages[i] = page;
51763 spd.nr_pages++;
51764@@ -849,10 +849,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
51765 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
51766 {
51767 while (!pipe->nrbufs) {
51768- if (!pipe->writers)
51769+ if (!atomic_read(&pipe->writers))
51770 return 0;
51771
51772- if (!pipe->waiting_writers && sd->num_spliced)
51773+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
51774 return 0;
51775
51776 if (sd->flags & SPLICE_F_NONBLOCK)
51777@@ -1190,7 +1190,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
51778 * out of the pipe right after the splice_to_pipe(). So set
51779 * PIPE_READERS appropriately.
51780 */
51781- pipe->readers = 1;
51782+ atomic_set(&pipe->readers, 1);
51783
51784 current->splice_pipe = pipe;
51785 }
51786@@ -1739,9 +1739,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
51787 ret = -ERESTARTSYS;
51788 break;
51789 }
51790- if (!pipe->writers)
51791+ if (!atomic_read(&pipe->writers))
51792 break;
51793- if (!pipe->waiting_writers) {
51794+ if (!atomic_read(&pipe->waiting_writers)) {
51795 if (flags & SPLICE_F_NONBLOCK) {
51796 ret = -EAGAIN;
51797 break;
51798@@ -1773,7 +1773,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
51799 pipe_lock(pipe);
51800
51801 while (pipe->nrbufs >= pipe->buffers) {
51802- if (!pipe->readers) {
51803+ if (!atomic_read(&pipe->readers)) {
51804 send_sig(SIGPIPE, current, 0);
51805 ret = -EPIPE;
51806 break;
51807@@ -1786,9 +1786,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
51808 ret = -ERESTARTSYS;
51809 break;
51810 }
51811- pipe->waiting_writers++;
51812+ atomic_inc(&pipe->waiting_writers);
51813 pipe_wait(pipe);
51814- pipe->waiting_writers--;
51815+ atomic_dec(&pipe->waiting_writers);
51816 }
51817
51818 pipe_unlock(pipe);
51819@@ -1824,14 +1824,14 @@ retry:
51820 pipe_double_lock(ipipe, opipe);
51821
51822 do {
51823- if (!opipe->readers) {
51824+ if (!atomic_read(&opipe->readers)) {
51825 send_sig(SIGPIPE, current, 0);
51826 if (!ret)
51827 ret = -EPIPE;
51828 break;
51829 }
51830
51831- if (!ipipe->nrbufs && !ipipe->writers)
51832+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
51833 break;
51834
51835 /*
51836@@ -1928,7 +1928,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
51837 pipe_double_lock(ipipe, opipe);
51838
51839 do {
51840- if (!opipe->readers) {
51841+ if (!atomic_read(&opipe->readers)) {
51842 send_sig(SIGPIPE, current, 0);
51843 if (!ret)
51844 ret = -EPIPE;
51845@@ -1973,7 +1973,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
51846 * return EAGAIN if we have the potential of some data in the
51847 * future, otherwise just return 0
51848 */
51849- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
51850+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
51851 ret = -EAGAIN;
51852
51853 pipe_unlock(ipipe);
51854diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
51855index 2fbdff6..5530a61 100644
51856--- a/fs/sysfs/dir.c
51857+++ b/fs/sysfs/dir.c
51858@@ -685,6 +685,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
51859 struct sysfs_dirent *sd;
51860 int rc;
51861
51862+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
51863+ const char *parent_name = parent_sd->s_name;
51864+
51865+ mode = S_IFDIR | S_IRWXU;
51866+
51867+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
51868+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
51869+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
51870+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
51871+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
51872+#endif
51873+
51874 /* allocate */
51875 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
51876 if (!sd)
51877diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
51878index 00012e3..8392349 100644
51879--- a/fs/sysfs/file.c
51880+++ b/fs/sysfs/file.c
51881@@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
51882
51883 struct sysfs_open_dirent {
51884 atomic_t refcnt;
51885- atomic_t event;
51886+ atomic_unchecked_t event;
51887 wait_queue_head_t poll;
51888 struct list_head buffers; /* goes through sysfs_buffer.list */
51889 };
51890@@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
51891 if (!sysfs_get_active(attr_sd))
51892 return -ENODEV;
51893
51894- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
51895+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
51896 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
51897
51898 sysfs_put_active(attr_sd);
51899@@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
51900 return -ENOMEM;
51901
51902 atomic_set(&new_od->refcnt, 0);
51903- atomic_set(&new_od->event, 1);
51904+ atomic_set_unchecked(&new_od->event, 1);
51905 init_waitqueue_head(&new_od->poll);
51906 INIT_LIST_HEAD(&new_od->buffers);
51907 goto retry;
51908@@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
51909
51910 sysfs_put_active(attr_sd);
51911
51912- if (buffer->event != atomic_read(&od->event))
51913+ if (buffer->event != atomic_read_unchecked(&od->event))
51914 goto trigger;
51915
51916 return DEFAULT_POLLMASK;
51917@@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
51918
51919 od = sd->s_attr.open;
51920 if (od) {
51921- atomic_inc(&od->event);
51922+ atomic_inc_unchecked(&od->event);
51923 wake_up_interruptible(&od->poll);
51924 }
51925
51926diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
51927index 3c9eb56..9dea5be 100644
51928--- a/fs/sysfs/symlink.c
51929+++ b/fs/sysfs/symlink.c
51930@@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
51931
51932 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
51933 {
51934- char *page = nd_get_link(nd);
51935+ const char *page = nd_get_link(nd);
51936 if (!IS_ERR(page))
51937 free_page((unsigned long)page);
51938 }
51939diff --git a/fs/udf/misc.c b/fs/udf/misc.c
51940index c175b4d..8f36a16 100644
51941--- a/fs/udf/misc.c
51942+++ b/fs/udf/misc.c
51943@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
51944
51945 u8 udf_tag_checksum(const struct tag *t)
51946 {
51947- u8 *data = (u8 *)t;
51948+ const u8 *data = (const u8 *)t;
51949 u8 checksum = 0;
51950 int i;
51951 for (i = 0; i < sizeof(struct tag); ++i)
51952diff --git a/fs/utimes.c b/fs/utimes.c
51953index bb0696a..552054b 100644
51954--- a/fs/utimes.c
51955+++ b/fs/utimes.c
51956@@ -1,6 +1,7 @@
51957 #include <linux/compiler.h>
51958 #include <linux/file.h>
51959 #include <linux/fs.h>
51960+#include <linux/security.h>
51961 #include <linux/linkage.h>
51962 #include <linux/mount.h>
51963 #include <linux/namei.h>
51964@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
51965 goto mnt_drop_write_and_out;
51966 }
51967 }
51968+
51969+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
51970+ error = -EACCES;
51971+ goto mnt_drop_write_and_out;
51972+ }
51973+
51974 mutex_lock(&inode->i_mutex);
51975 error = notify_change(path->dentry, &newattrs);
51976 mutex_unlock(&inode->i_mutex);
51977diff --git a/fs/xattr.c b/fs/xattr.c
51978index e21c119..21dfc7c 100644
51979--- a/fs/xattr.c
51980+++ b/fs/xattr.c
51981@@ -319,7 +319,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
51982 * Extended attribute SET operations
51983 */
51984 static long
51985-setxattr(struct dentry *d, const char __user *name, const void __user *value,
51986+setxattr(struct path *path, const char __user *name, const void __user *value,
51987 size_t size, int flags)
51988 {
51989 int error;
51990@@ -355,7 +355,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
51991 posix_acl_fix_xattr_from_user(kvalue, size);
51992 }
51993
51994- error = vfs_setxattr(d, kname, kvalue, size, flags);
51995+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
51996+ error = -EACCES;
51997+ goto out;
51998+ }
51999+
52000+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
52001 out:
52002 if (vvalue)
52003 vfree(vvalue);
52004@@ -376,7 +381,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
52005 return error;
52006 error = mnt_want_write(path.mnt);
52007 if (!error) {
52008- error = setxattr(path.dentry, name, value, size, flags);
52009+ error = setxattr(&path, name, value, size, flags);
52010 mnt_drop_write(path.mnt);
52011 }
52012 path_put(&path);
52013@@ -395,7 +400,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
52014 return error;
52015 error = mnt_want_write(path.mnt);
52016 if (!error) {
52017- error = setxattr(path.dentry, name, value, size, flags);
52018+ error = setxattr(&path, name, value, size, flags);
52019 mnt_drop_write(path.mnt);
52020 }
52021 path_put(&path);
52022@@ -406,16 +411,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
52023 const void __user *,value, size_t, size, int, flags)
52024 {
52025 struct fd f = fdget(fd);
52026- struct dentry *dentry;
52027 int error = -EBADF;
52028
52029 if (!f.file)
52030 return error;
52031- dentry = f.file->f_path.dentry;
52032- audit_inode(NULL, dentry, 0);
52033+ audit_inode(NULL, f.file->f_path.dentry, 0);
52034 error = mnt_want_write_file(f.file);
52035 if (!error) {
52036- error = setxattr(dentry, name, value, size, flags);
52037+ error = setxattr(&f.file->f_path, name, value, size, flags);
52038 mnt_drop_write_file(f.file);
52039 }
52040 fdput(f);
52041diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
52042index 9fbea87..6b19972 100644
52043--- a/fs/xattr_acl.c
52044+++ b/fs/xattr_acl.c
52045@@ -76,8 +76,8 @@ struct posix_acl *
52046 posix_acl_from_xattr(struct user_namespace *user_ns,
52047 const void *value, size_t size)
52048 {
52049- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
52050- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
52051+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
52052+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
52053 int count;
52054 struct posix_acl *acl;
52055 struct posix_acl_entry *acl_e;
52056diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
52057index 83d0cf3..2ef526b 100644
52058--- a/fs/xfs/xfs_bmap.c
52059+++ b/fs/xfs/xfs_bmap.c
52060@@ -189,7 +189,7 @@ xfs_bmap_validate_ret(
52061 int nmap,
52062 int ret_nmap);
52063 #else
52064-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
52065+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
52066 #endif /* DEBUG */
52067
52068 STATIC int
52069diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
52070index 1b9fc3e..e1bdde0 100644
52071--- a/fs/xfs/xfs_dir2_sf.c
52072+++ b/fs/xfs/xfs_dir2_sf.c
52073@@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
52074 }
52075
52076 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
52077- if (filldir(dirent, (char *)sfep->name, sfep->namelen,
52078+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
52079+ char name[sfep->namelen];
52080+ memcpy(name, sfep->name, sfep->namelen);
52081+ if (filldir(dirent, name, sfep->namelen,
52082+ off & 0x7fffffff, ino, DT_UNKNOWN)) {
52083+ *offset = off & 0x7fffffff;
52084+ return 0;
52085+ }
52086+ } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
52087 off & 0x7fffffff, ino, DT_UNKNOWN)) {
52088 *offset = off & 0x7fffffff;
52089 return 0;
52090diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
52091index c1df3c6..f987db6 100644
52092--- a/fs/xfs/xfs_ioctl.c
52093+++ b/fs/xfs/xfs_ioctl.c
52094@@ -126,7 +126,7 @@ xfs_find_handle(
52095 }
52096
52097 error = -EFAULT;
52098- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
52099+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
52100 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
52101 goto out_put;
52102
52103diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
52104index 4e00cf0..3374374 100644
52105--- a/fs/xfs/xfs_iops.c
52106+++ b/fs/xfs/xfs_iops.c
52107@@ -394,7 +394,7 @@ xfs_vn_put_link(
52108 struct nameidata *nd,
52109 void *p)
52110 {
52111- char *s = nd_get_link(nd);
52112+ const char *s = nd_get_link(nd);
52113
52114 if (!IS_ERR(s))
52115 kfree(s);
52116diff --git a/fs/xfs/xfs_mount.h b/fs/xfs/xfs_mount.h
52117index deee09e..1c74028 100644
52118--- a/fs/xfs/xfs_mount.h
52119+++ b/fs/xfs/xfs_mount.h
52120@@ -193,7 +193,7 @@ typedef struct xfs_mount {
52121 #ifdef HAVE_PERCPU_SB
52122 xfs_icsb_cnts_t __percpu *m_sb_cnts; /* per-cpu superblock counters */
52123 unsigned long m_icsb_counters; /* disabled per-cpu counters */
52124- struct notifier_block m_icsb_notifier; /* hotplug cpu notifier */
52125+ notifier_block_no_const m_icsb_notifier; /* hotplug cpu notifier */
52126 struct mutex m_icsb_mutex; /* balancer sync lock */
52127 #endif
52128 struct xfs_mru_cache *m_filestream; /* per-mount filestream data */
52129diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
52130new file mode 100644
52131index 0000000..3900064
52132--- /dev/null
52133+++ b/grsecurity/Kconfig
52134@@ -0,0 +1,964 @@
52135+#
52136+# grecurity configuration
52137+#
52138+menu "Memory Protections"
52139+depends on GRKERNSEC
52140+
52141+config GRKERNSEC_KMEM
52142+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
52143+ default y if GRKERNSEC_CONFIG_AUTO
52144+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
52145+ help
52146+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
52147+ be written to or read from to modify or leak the contents of the running
52148+ kernel. /dev/port will also not be allowed to be opened. If you have module
52149+ support disabled, enabling this will close up four ways that are
52150+ currently used to insert malicious code into the running kernel.
52151+ Even with all these features enabled, we still highly recommend that
52152+ you use the RBAC system, as it is still possible for an attacker to
52153+ modify the running kernel through privileged I/O granted by ioperm/iopl.
52154+ If you are not using XFree86, you may be able to stop this additional
52155+ case by enabling the 'Disable privileged I/O' option. Though nothing
52156+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
52157+ but only to video memory, which is the only writing we allow in this
52158+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
52159+ not be allowed to mprotect it with PROT_WRITE later.
52160+ It is highly recommended that you say Y here if you meet all the
52161+ conditions above.
52162+
52163+config GRKERNSEC_VM86
52164+ bool "Restrict VM86 mode"
52165+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
52166+ depends on X86_32
52167+
52168+ help
52169+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
52170+ make use of a special execution mode on 32bit x86 processors called
52171+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
52172+ video cards and will still work with this option enabled. The purpose
52173+ of the option is to prevent exploitation of emulation errors in
52174+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
52175+ Nearly all users should be able to enable this option.
52176+
52177+config GRKERNSEC_IO
52178+ bool "Disable privileged I/O"
52179+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
52180+ depends on X86
52181+ select RTC_CLASS
52182+ select RTC_INTF_DEV
52183+ select RTC_DRV_CMOS
52184+
52185+ help
52186+ If you say Y here, all ioperm and iopl calls will return an error.
52187+ Ioperm and iopl can be used to modify the running kernel.
52188+ Unfortunately, some programs need this access to operate properly,
52189+ the most notable of which are XFree86 and hwclock. hwclock can be
52190+ remedied by having RTC support in the kernel, so real-time
52191+ clock support is enabled if this option is enabled, to ensure
52192+ that hwclock operates correctly. XFree86 still will not
52193+ operate correctly with this option enabled, so DO NOT CHOOSE Y
52194+ IF YOU USE XFree86. If you use XFree86 and you still want to
52195+ protect your kernel against modification, use the RBAC system.
52196+
52197+config GRKERNSEC_JIT_HARDEN
52198+ bool "Harden BPF JIT against spray attacks"
52199+ default y if GRKERNSEC_CONFIG_AUTO
52200+ depends on BPF_JIT
52201+ help
52202+ If you say Y here, the native code generated by the kernel's Berkeley
52203+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
52204+ attacks that attempt to fit attacker-beneficial instructions in
52205+ 32bit immediate fields of JIT-generated native instructions. The
52206+ attacker will generally aim to cause an unintended instruction sequence
52207+ of JIT-generated native code to execute by jumping into the middle of
52208+ a generated instruction. This feature effectively randomizes the 32bit
52209+ immediate constants present in the generated code to thwart such attacks.
52210+
52211+ If you're using KERNEXEC, it's recommended that you enable this option
52212+ to supplement the hardening of the kernel.
52213+
52214+config GRKERNSEC_PROC_MEMMAP
52215+ bool "Harden ASLR against information leaks and entropy reduction"
52216+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
52217+ depends on PAX_NOEXEC || PAX_ASLR
52218+ help
52219+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
52220+ give no information about the addresses of its mappings if
52221+ PaX features that rely on random addresses are enabled on the task.
52222+ In addition to sanitizing this information and disabling other
52223+ dangerous sources of information, this option causes reads of sensitive
52224+ /proc/<pid> entries where the file descriptor was opened in a different
52225+ task than the one performing the read. Such attempts are logged.
52226+ This option also limits argv/env strings for suid/sgid binaries
52227+ to 512KB to prevent a complete exhaustion of the stack entropy provided
52228+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
52229+ binaries to prevent alternative mmap layouts from being abused.
52230+
52231+ If you use PaX it is essential that you say Y here as it closes up
52232+ several holes that make full ASLR useless locally.
52233+
52234+config GRKERNSEC_BRUTE
52235+ bool "Deter exploit bruteforcing"
52236+ default y if GRKERNSEC_CONFIG_AUTO
52237+ help
52238+ If you say Y here, attempts to bruteforce exploits against forking
52239+ daemons such as apache or sshd, as well as against suid/sgid binaries
52240+ will be deterred. When a child of a forking daemon is killed by PaX
52241+ or crashes due to an illegal instruction or other suspicious signal,
52242+ the parent process will be delayed 30 seconds upon every subsequent
52243+ fork until the administrator is able to assess the situation and
52244+ restart the daemon.
52245+ In the suid/sgid case, the attempt is logged, the user has all their
52246+ processes terminated, and they are prevented from executing any further
52247+ processes for 15 minutes.
52248+ It is recommended that you also enable signal logging in the auditing
52249+ section so that logs are generated when a process triggers a suspicious
52250+ signal.
52251+ If the sysctl option is enabled, a sysctl option with name
52252+ "deter_bruteforce" is created.
52253+
52254+
52255+config GRKERNSEC_MODHARDEN
52256+ bool "Harden module auto-loading"
52257+ default y if GRKERNSEC_CONFIG_AUTO
52258+ depends on MODULES
52259+ help
52260+ If you say Y here, module auto-loading in response to use of some
52261+ feature implemented by an unloaded module will be restricted to
52262+ root users. Enabling this option helps defend against attacks
52263+ by unprivileged users who abuse the auto-loading behavior to
52264+ cause a vulnerable module to load that is then exploited.
52265+
52266+ If this option prevents a legitimate use of auto-loading for a
52267+ non-root user, the administrator can execute modprobe manually
52268+ with the exact name of the module mentioned in the alert log.
52269+ Alternatively, the administrator can add the module to the list
52270+ of modules loaded at boot by modifying init scripts.
52271+
52272+ Modification of init scripts will most likely be needed on
52273+ Ubuntu servers with encrypted home directory support enabled,
52274+ as the first non-root user logging in will cause the ecb(aes),
52275+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
52276+
52277+config GRKERNSEC_HIDESYM
52278+ bool "Hide kernel symbols"
52279+ default y if GRKERNSEC_CONFIG_AUTO
52280+ select PAX_USERCOPY_SLABS
52281+ help
52282+ If you say Y here, getting information on loaded modules, and
52283+ displaying all kernel symbols through a syscall will be restricted
52284+ to users with CAP_SYS_MODULE. For software compatibility reasons,
52285+ /proc/kallsyms will be restricted to the root user. The RBAC
52286+ system can hide that entry even from root.
52287+
52288+ This option also prevents leaking of kernel addresses through
52289+ several /proc entries.
52290+
52291+ Note that this option is only effective provided the following
52292+ conditions are met:
52293+ 1) The kernel using grsecurity is not precompiled by some distribution
52294+ 2) You have also enabled GRKERNSEC_DMESG
52295+ 3) You are using the RBAC system and hiding other files such as your
52296+ kernel image and System.map. Alternatively, enabling this option
52297+ causes the permissions on /boot, /lib/modules, and the kernel
52298+ source directory to change at compile time to prevent
52299+ reading by non-root users.
52300+ If the above conditions are met, this option will aid in providing a
52301+ useful protection against local kernel exploitation of overflows
52302+ and arbitrary read/write vulnerabilities.
52303+
52304+config GRKERNSEC_KERN_LOCKOUT
52305+ bool "Active kernel exploit response"
52306+ default y if GRKERNSEC_CONFIG_AUTO
52307+ depends on X86 || ARM || PPC || SPARC
52308+ help
52309+ If you say Y here, when a PaX alert is triggered due to suspicious
52310+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
52311+ or an OOPS occurs due to bad memory accesses, instead of just
52312+ terminating the offending process (and potentially allowing
52313+ a subsequent exploit from the same user), we will take one of two
52314+ actions:
52315+ If the user was root, we will panic the system
52316+ If the user was non-root, we will log the attempt, terminate
52317+ all processes owned by the user, then prevent them from creating
52318+ any new processes until the system is restarted
52319+ This deters repeated kernel exploitation/bruteforcing attempts
52320+ and is useful for later forensics.
52321+
52322+endmenu
52323+menu "Role Based Access Control Options"
52324+depends on GRKERNSEC
52325+
52326+config GRKERNSEC_RBAC_DEBUG
52327+ bool
52328+
52329+config GRKERNSEC_NO_RBAC
52330+ bool "Disable RBAC system"
52331+ help
52332+ If you say Y here, the /dev/grsec device will be removed from the kernel,
52333+ preventing the RBAC system from being enabled. You should only say Y
52334+ here if you have no intention of using the RBAC system, so as to prevent
52335+ an attacker with root access from misusing the RBAC system to hide files
52336+ and processes when loadable module support and /dev/[k]mem have been
52337+ locked down.
52338+
52339+config GRKERNSEC_ACL_HIDEKERN
52340+ bool "Hide kernel processes"
52341+ help
52342+ If you say Y here, all kernel threads will be hidden to all
52343+ processes but those whose subject has the "view hidden processes"
52344+ flag.
52345+
52346+config GRKERNSEC_ACL_MAXTRIES
52347+ int "Maximum tries before password lockout"
52348+ default 3
52349+ help
52350+ This option enforces the maximum number of times a user can attempt
52351+ to authorize themselves with the grsecurity RBAC system before being
52352+ denied the ability to attempt authorization again for a specified time.
52353+ The lower the number, the harder it will be to brute-force a password.
52354+
52355+config GRKERNSEC_ACL_TIMEOUT
52356+ int "Time to wait after max password tries, in seconds"
52357+ default 30
52358+ help
52359+ This option specifies the time the user must wait after attempting to
52360+ authorize to the RBAC system with the maximum number of invalid
52361+ passwords. The higher the number, the harder it will be to brute-force
52362+ a password.
52363+
52364+endmenu
52365+menu "Filesystem Protections"
52366+depends on GRKERNSEC
52367+
52368+config GRKERNSEC_PROC
52369+ bool "Proc restrictions"
52370+ default y if GRKERNSEC_CONFIG_AUTO
52371+ help
52372+ If you say Y here, the permissions of the /proc filesystem
52373+ will be altered to enhance system security and privacy. You MUST
52374+ choose either a user only restriction or a user and group restriction.
52375+ Depending upon the option you choose, you can either restrict users to
52376+ see only the processes they themselves run, or choose a group that can
52377+ view all processes and files normally restricted to root if you choose
52378+ the "restrict to user only" option. NOTE: If you're running identd or
52379+ ntpd as a non-root user, you will have to run it as the group you
52380+ specify here.
52381+
52382+config GRKERNSEC_PROC_USER
52383+ bool "Restrict /proc to user only"
52384+ depends on GRKERNSEC_PROC
52385+ help
52386+ If you say Y here, non-root users will only be able to view their own
52387+ processes, and restricts them from viewing network-related information,
52388+ and viewing kernel symbol and module information.
52389+
52390+config GRKERNSEC_PROC_USERGROUP
52391+ bool "Allow special group"
52392+ default y if GRKERNSEC_CONFIG_AUTO
52393+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
52394+ help
52395+ If you say Y here, you will be able to select a group that will be
52396+ able to view all processes and network-related information. If you've
52397+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
52398+ remain hidden. This option is useful if you want to run identd as
52399+ a non-root user. The group you select may also be chosen at boot time
52400+ via "grsec_proc_gid=" on the kernel commandline.
52401+
52402+config GRKERNSEC_PROC_GID
52403+ int "GID for special group"
52404+ depends on GRKERNSEC_PROC_USERGROUP
52405+ default 1001
52406+
52407+config GRKERNSEC_PROC_ADD
52408+ bool "Additional restrictions"
52409+ default y if GRKERNSEC_CONFIG_AUTO
52410+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
52411+ help
52412+ If you say Y here, additional restrictions will be placed on
52413+ /proc that keep normal users from viewing device information and
52414+ slabinfo information that could be useful for exploits.
52415+
52416+config GRKERNSEC_LINK
52417+ bool "Linking restrictions"
52418+ default y if GRKERNSEC_CONFIG_AUTO
52419+ help
52420+ If you say Y here, /tmp race exploits will be prevented, since users
52421+ will no longer be able to follow symlinks owned by other users in
52422+ world-writable +t directories (e.g. /tmp), unless the owner of the
52423+ symlink is the owner of the directory. users will also not be
52424+ able to hardlink to files they do not own. If the sysctl option is
52425+ enabled, a sysctl option with name "linking_restrictions" is created.
52426+
52427+config GRKERNSEC_SYMLINKOWN
52428+ bool "Kernel-enforced SymlinksIfOwnerMatch"
52429+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
52430+ help
52431+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
52432+ that prevents it from being used as a security feature. As Apache
52433+ verifies the symlink by performing a stat() against the target of
52434+ the symlink before it is followed, an attacker can setup a symlink
52435+ to point to a same-owned file, then replace the symlink with one
52436+ that targets another user's file just after Apache "validates" the
52437+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
52438+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
52439+ will be in place for the group you specify. If the sysctl option
52440+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
52441+ created.
52442+
52443+config GRKERNSEC_SYMLINKOWN_GID
52444+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
52445+ depends on GRKERNSEC_SYMLINKOWN
52446+ default 1006
52447+ help
52448+ Setting this GID determines what group kernel-enforced
52449+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
52450+ is enabled, a sysctl option with name "symlinkown_gid" is created.
52451+
52452+config GRKERNSEC_FIFO
52453+ bool "FIFO restrictions"
52454+ default y if GRKERNSEC_CONFIG_AUTO
52455+ help
52456+ If you say Y here, users will not be able to write to FIFOs they don't
52457+ own in world-writable +t directories (e.g. /tmp), unless the owner of
52458+ the FIFO is the same owner of the directory it's held in. If the sysctl
52459+ option is enabled, a sysctl option with name "fifo_restrictions" is
52460+ created.
52461+
52462+config GRKERNSEC_SYSFS_RESTRICT
52463+ bool "Sysfs/debugfs restriction"
52464+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
52465+ depends on SYSFS
52466+ help
52467+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
52468+ any filesystem normally mounted under it (e.g. debugfs) will be
52469+ mostly accessible only by root. These filesystems generally provide access
52470+ to hardware and debug information that isn't appropriate for unprivileged
52471+ users of the system. Sysfs and debugfs have also become a large source
52472+ of new vulnerabilities, ranging from infoleaks to local compromise.
52473+ There has been very little oversight with an eye toward security involved
52474+ in adding new exporters of information to these filesystems, so their
52475+ use is discouraged.
52476+ For reasons of compatibility, a few directories have been whitelisted
52477+ for access by non-root users:
52478+ /sys/fs/selinux
52479+ /sys/fs/fuse
52480+ /sys/devices/system/cpu
52481+
52482+config GRKERNSEC_ROFS
52483+ bool "Runtime read-only mount protection"
52484+ help
52485+ If you say Y here, a sysctl option with name "romount_protect" will
52486+ be created. By setting this option to 1 at runtime, filesystems
52487+ will be protected in the following ways:
52488+ * No new writable mounts will be allowed
52489+ * Existing read-only mounts won't be able to be remounted read/write
52490+ * Write operations will be denied on all block devices
52491+ This option acts independently of grsec_lock: once it is set to 1,
52492+ it cannot be turned off. Therefore, please be mindful of the resulting
52493+ behavior if this option is enabled in an init script on a read-only
52494+ filesystem. This feature is mainly intended for secure embedded systems.
52495+
52496+config GRKERNSEC_CHROOT
52497+ bool "Chroot jail restrictions"
52498+ default y if GRKERNSEC_CONFIG_AUTO
52499+ help
52500+ If you say Y here, you will be able to choose several options that will
52501+ make breaking out of a chrooted jail much more difficult. If you
52502+ encounter no software incompatibilities with the following options, it
52503+ is recommended that you enable each one.
52504+
52505+config GRKERNSEC_CHROOT_MOUNT
52506+ bool "Deny mounts"
52507+ default y if GRKERNSEC_CONFIG_AUTO
52508+ depends on GRKERNSEC_CHROOT
52509+ help
52510+ If you say Y here, processes inside a chroot will not be able to
52511+ mount or remount filesystems. If the sysctl option is enabled, a
52512+ sysctl option with name "chroot_deny_mount" is created.
52513+
52514+config GRKERNSEC_CHROOT_DOUBLE
52515+ bool "Deny double-chroots"
52516+ default y if GRKERNSEC_CONFIG_AUTO
52517+ depends on GRKERNSEC_CHROOT
52518+ help
52519+ If you say Y here, processes inside a chroot will not be able to chroot
52520+ again outside the chroot. This is a widely used method of breaking
52521+ out of a chroot jail and should not be allowed. If the sysctl
52522+ option is enabled, a sysctl option with name
52523+ "chroot_deny_chroot" is created.
52524+
52525+config GRKERNSEC_CHROOT_PIVOT
52526+ bool "Deny pivot_root in chroot"
52527+ default y if GRKERNSEC_CONFIG_AUTO
52528+ depends on GRKERNSEC_CHROOT
52529+ help
52530+ If you say Y here, processes inside a chroot will not be able to use
52531+ a function called pivot_root() that was introduced in Linux 2.3.41. It
52532+ works similar to chroot in that it changes the root filesystem. This
52533+ function could be misused in a chrooted process to attempt to break out
52534+ of the chroot, and therefore should not be allowed. If the sysctl
52535+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
52536+ created.
52537+
52538+config GRKERNSEC_CHROOT_CHDIR
52539+ bool "Enforce chdir(\"/\") on all chroots"
52540+ default y if GRKERNSEC_CONFIG_AUTO
52541+ depends on GRKERNSEC_CHROOT
52542+ help
52543+ If you say Y here, the current working directory of all newly-chrooted
52544+ applications will be set to the the root directory of the chroot.
52545+ The man page on chroot(2) states:
52546+ Note that this call does not change the current working
52547+ directory, so that `.' can be outside the tree rooted at
52548+ `/'. In particular, the super-user can escape from a
52549+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
52550+
52551+ It is recommended that you say Y here, since it's not known to break
52552+ any software. If the sysctl option is enabled, a sysctl option with
52553+ name "chroot_enforce_chdir" is created.
52554+
52555+config GRKERNSEC_CHROOT_CHMOD
52556+ bool "Deny (f)chmod +s"
52557+ default y if GRKERNSEC_CONFIG_AUTO
52558+ depends on GRKERNSEC_CHROOT
52559+ help
52560+ If you say Y here, processes inside a chroot will not be able to chmod
52561+ or fchmod files to make them have suid or sgid bits. This protects
52562+ against another published method of breaking a chroot. If the sysctl
52563+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
52564+ created.
52565+
52566+config GRKERNSEC_CHROOT_FCHDIR
52567+ bool "Deny fchdir out of chroot"
52568+ default y if GRKERNSEC_CONFIG_AUTO
52569+ depends on GRKERNSEC_CHROOT
52570+ help
52571+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
52572+ to a file descriptor of the chrooting process that points to a directory
52573+ outside the filesystem will be stopped. If the sysctl option
52574+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
52575+
52576+config GRKERNSEC_CHROOT_MKNOD
52577+ bool "Deny mknod"
52578+ default y if GRKERNSEC_CONFIG_AUTO
52579+ depends on GRKERNSEC_CHROOT
52580+ help
52581+ If you say Y here, processes inside a chroot will not be allowed to
52582+ mknod. The problem with using mknod inside a chroot is that it
52583+ would allow an attacker to create a device entry that is the same
52584+ as one on the physical root of your system, which could range from
52585+ anything from the console device to a device for your harddrive (which
52586+ they could then use to wipe the drive or steal data). It is recommended
52587+ that you say Y here, unless you run into software incompatibilities.
52588+ If the sysctl option is enabled, a sysctl option with name
52589+ "chroot_deny_mknod" is created.
52590+
52591+config GRKERNSEC_CHROOT_SHMAT
52592+ bool "Deny shmat() out of chroot"
52593+ default y if GRKERNSEC_CONFIG_AUTO
52594+ depends on GRKERNSEC_CHROOT
52595+ help
52596+ If you say Y here, processes inside a chroot will not be able to attach
52597+ to shared memory segments that were created outside of the chroot jail.
52598+ It is recommended that you say Y here. If the sysctl option is enabled,
52599+ a sysctl option with name "chroot_deny_shmat" is created.
52600+
52601+config GRKERNSEC_CHROOT_UNIX
52602+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
52603+ default y if GRKERNSEC_CONFIG_AUTO
52604+ depends on GRKERNSEC_CHROOT
52605+ help
52606+ If you say Y here, processes inside a chroot will not be able to
52607+ connect to abstract (meaning not belonging to a filesystem) Unix
52608+ domain sockets that were bound outside of a chroot. It is recommended
52609+ that you say Y here. If the sysctl option is enabled, a sysctl option
52610+ with name "chroot_deny_unix" is created.
52611+
52612+config GRKERNSEC_CHROOT_FINDTASK
52613+ bool "Protect outside processes"
52614+ default y if GRKERNSEC_CONFIG_AUTO
52615+ depends on GRKERNSEC_CHROOT
52616+ help
52617+ If you say Y here, processes inside a chroot will not be able to
52618+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
52619+ getsid, or view any process outside of the chroot. If the sysctl
52620+ option is enabled, a sysctl option with name "chroot_findtask" is
52621+ created.
52622+
52623+config GRKERNSEC_CHROOT_NICE
52624+ bool "Restrict priority changes"
52625+ default y if GRKERNSEC_CONFIG_AUTO
52626+ depends on GRKERNSEC_CHROOT
52627+ help
52628+ If you say Y here, processes inside a chroot will not be able to raise
52629+ the priority of processes in the chroot, or alter the priority of
52630+ processes outside the chroot. This provides more security than simply
52631+ removing CAP_SYS_NICE from the process' capability set. If the
52632+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
52633+ is created.
52634+
52635+config GRKERNSEC_CHROOT_SYSCTL
52636+ bool "Deny sysctl writes"
52637+ default y if GRKERNSEC_CONFIG_AUTO
52638+ depends on GRKERNSEC_CHROOT
52639+ help
52640+ If you say Y here, an attacker in a chroot will not be able to
52641+ write to sysctl entries, either by sysctl(2) or through a /proc
52642+ interface. It is strongly recommended that you say Y here. If the
52643+ sysctl option is enabled, a sysctl option with name
52644+ "chroot_deny_sysctl" is created.
52645+
52646+config GRKERNSEC_CHROOT_CAPS
52647+ bool "Capability restrictions"
52648+ default y if GRKERNSEC_CONFIG_AUTO
52649+ depends on GRKERNSEC_CHROOT
52650+ help
52651+ If you say Y here, the capabilities on all processes within a
52652+ chroot jail will be lowered to stop module insertion, raw i/o,
52653+ system and net admin tasks, rebooting the system, modifying immutable
52654+ files, modifying IPC owned by another, and changing the system time.
52655+ This is left an option because it can break some apps. Disable this
52656+ if your chrooted apps are having problems performing those kinds of
52657+ tasks. If the sysctl option is enabled, a sysctl option with
52658+ name "chroot_caps" is created.
52659+
52660+endmenu
52661+menu "Kernel Auditing"
52662+depends on GRKERNSEC
52663+
52664+config GRKERNSEC_AUDIT_GROUP
52665+ bool "Single group for auditing"
52666+ help
52667+ If you say Y here, the exec, chdir, and (un)mount logging features
52668+ will only operate on a group you specify. This option is recommended
52669+ if you only want to watch certain users instead of having a large
52670+ amount of logs from the entire system. If the sysctl option is enabled,
52671+ a sysctl option with name "audit_group" is created.
52672+
52673+config GRKERNSEC_AUDIT_GID
52674+ int "GID for auditing"
52675+ depends on GRKERNSEC_AUDIT_GROUP
52676+ default 1007
52677+
52678+config GRKERNSEC_EXECLOG
52679+ bool "Exec logging"
52680+ help
52681+ If you say Y here, all execve() calls will be logged (since the
52682+ other exec*() calls are frontends to execve(), all execution
52683+ will be logged). Useful for shell-servers that like to keep track
52684+ of their users. If the sysctl option is enabled, a sysctl option with
52685+ name "exec_logging" is created.
52686+ WARNING: This option when enabled will produce a LOT of logs, especially
52687+ on an active system.
52688+
52689+config GRKERNSEC_RESLOG
52690+ bool "Resource logging"
52691+ default y if GRKERNSEC_CONFIG_AUTO
52692+ help
52693+ If you say Y here, all attempts to overstep resource limits will
52694+ be logged with the resource name, the requested size, and the current
52695+ limit. It is highly recommended that you say Y here. If the sysctl
52696+ option is enabled, a sysctl option with name "resource_logging" is
52697+ created. If the RBAC system is enabled, the sysctl value is ignored.
52698+
52699+config GRKERNSEC_CHROOT_EXECLOG
52700+ bool "Log execs within chroot"
52701+ help
52702+ If you say Y here, all executions inside a chroot jail will be logged
52703+ to syslog. This can cause a large amount of logs if certain
52704+ applications (eg. djb's daemontools) are installed on the system, and
52705+ is therefore left as an option. If the sysctl option is enabled, a
52706+ sysctl option with name "chroot_execlog" is created.
52707+
52708+config GRKERNSEC_AUDIT_PTRACE
52709+ bool "Ptrace logging"
52710+ help
52711+ If you say Y here, all attempts to attach to a process via ptrace
52712+ will be logged. If the sysctl option is enabled, a sysctl option
52713+ with name "audit_ptrace" is created.
52714+
52715+config GRKERNSEC_AUDIT_CHDIR
52716+ bool "Chdir logging"
52717+ help
52718+ If you say Y here, all chdir() calls will be logged. If the sysctl
52719+ option is enabled, a sysctl option with name "audit_chdir" is created.
52720+
52721+config GRKERNSEC_AUDIT_MOUNT
52722+ bool "(Un)Mount logging"
52723+ help
52724+ If you say Y here, all mounts and unmounts will be logged. If the
52725+ sysctl option is enabled, a sysctl option with name "audit_mount" is
52726+ created.
52727+
52728+config GRKERNSEC_SIGNAL
52729+ bool "Signal logging"
52730+ default y if GRKERNSEC_CONFIG_AUTO
52731+ help
52732+ If you say Y here, certain important signals will be logged, such as
52733+ SIGSEGV, which will as a result inform you of when a error in a program
52734+ occurred, which in some cases could mean a possible exploit attempt.
52735+ If the sysctl option is enabled, a sysctl option with name
52736+ "signal_logging" is created.
52737+
52738+config GRKERNSEC_FORKFAIL
52739+ bool "Fork failure logging"
52740+ help
52741+ If you say Y here, all failed fork() attempts will be logged.
52742+ This could suggest a fork bomb, or someone attempting to overstep
52743+ their process limit. If the sysctl option is enabled, a sysctl option
52744+ with name "forkfail_logging" is created.
52745+
52746+config GRKERNSEC_TIME
52747+ bool "Time change logging"
52748+ default y if GRKERNSEC_CONFIG_AUTO
52749+ help
52750+ If you say Y here, any changes of the system clock will be logged.
52751+ If the sysctl option is enabled, a sysctl option with name
52752+ "timechange_logging" is created.
52753+
52754+config GRKERNSEC_PROC_IPADDR
52755+ bool "/proc/<pid>/ipaddr support"
52756+ default y if GRKERNSEC_CONFIG_AUTO
52757+ help
52758+ If you say Y here, a new entry will be added to each /proc/<pid>
52759+ directory that contains the IP address of the person using the task.
52760+ The IP is carried across local TCP and AF_UNIX stream sockets.
52761+ This information can be useful for IDS/IPSes to perform remote response
52762+ to a local attack. The entry is readable by only the owner of the
52763+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
52764+ the RBAC system), and thus does not create privacy concerns.
52765+
52766+config GRKERNSEC_RWXMAP_LOG
52767+ bool 'Denied RWX mmap/mprotect logging'
52768+ default y if GRKERNSEC_CONFIG_AUTO
52769+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
52770+ help
52771+ If you say Y here, calls to mmap() and mprotect() with explicit
52772+ usage of PROT_WRITE and PROT_EXEC together will be logged when
52773+ denied by the PAX_MPROTECT feature. If the sysctl option is
52774+ enabled, a sysctl option with name "rwxmap_logging" is created.
52775+
52776+config GRKERNSEC_AUDIT_TEXTREL
52777+ bool 'ELF text relocations logging (READ HELP)'
52778+ depends on PAX_MPROTECT
52779+ help
52780+ If you say Y here, text relocations will be logged with the filename
52781+ of the offending library or binary. The purpose of the feature is
52782+ to help Linux distribution developers get rid of libraries and
52783+ binaries that need text relocations which hinder the future progress
52784+ of PaX. Only Linux distribution developers should say Y here, and
52785+ never on a production machine, as this option creates an information
52786+ leak that could aid an attacker in defeating the randomization of
52787+ a single memory region. If the sysctl option is enabled, a sysctl
52788+ option with name "audit_textrel" is created.
52789+
52790+endmenu
52791+
52792+menu "Executable Protections"
52793+depends on GRKERNSEC
52794+
52795+config GRKERNSEC_DMESG
52796+ bool "Dmesg(8) restriction"
52797+ default y if GRKERNSEC_CONFIG_AUTO
52798+ help
52799+ If you say Y here, non-root users will not be able to use dmesg(8)
52800+ to view the contents of the kernel's circular log buffer.
52801+ The kernel's log buffer often contains kernel addresses and other
52802+ identifying information useful to an attacker in fingerprinting a
52803+ system for a targeted exploit.
52804+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
52805+ created.
52806+
52807+config GRKERNSEC_HARDEN_PTRACE
52808+ bool "Deter ptrace-based process snooping"
52809+ default y if GRKERNSEC_CONFIG_AUTO
52810+ help
52811+ If you say Y here, TTY sniffers and other malicious monitoring
52812+ programs implemented through ptrace will be defeated. If you
52813+ have been using the RBAC system, this option has already been
52814+ enabled for several years for all users, with the ability to make
52815+ fine-grained exceptions.
52816+
52817+ This option only affects the ability of non-root users to ptrace
52818+ processes that are not a descendent of the ptracing process.
52819+ This means that strace ./binary and gdb ./binary will still work,
52820+ but attaching to arbitrary processes will not. If the sysctl
52821+ option is enabled, a sysctl option with name "harden_ptrace" is
52822+ created.
52823+
52824+config GRKERNSEC_PTRACE_READEXEC
52825+ bool "Require read access to ptrace sensitive binaries"
52826+ default y if GRKERNSEC_CONFIG_AUTO
52827+ help
52828+ If you say Y here, unprivileged users will not be able to ptrace unreadable
52829+ binaries. This option is useful in environments that
52830+ remove the read bits (e.g. file mode 4711) from suid binaries to
52831+ prevent infoleaking of their contents. This option adds
52832+ consistency to the use of that file mode, as the binary could normally
52833+ be read out when run without privileges while ptracing.
52834+
52835+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
52836+ is created.
52837+
52838+config GRKERNSEC_SETXID
52839+ bool "Enforce consistent multithreaded privileges"
52840+ default y if GRKERNSEC_CONFIG_AUTO
52841+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
52842+ help
52843+ If you say Y here, a change from a root uid to a non-root uid
52844+ in a multithreaded application will cause the resulting uids,
52845+ gids, supplementary groups, and capabilities in that thread
52846+ to be propagated to the other threads of the process. In most
52847+ cases this is unnecessary, as glibc will emulate this behavior
52848+ on behalf of the application. Other libcs do not act in the
52849+ same way, allowing the other threads of the process to continue
52850+ running with root privileges. If the sysctl option is enabled,
52851+ a sysctl option with name "consistent_setxid" is created.
52852+
52853+config GRKERNSEC_TPE
52854+ bool "Trusted Path Execution (TPE)"
52855+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
52856+ help
52857+ If you say Y here, you will be able to choose a gid to add to the
52858+ supplementary groups of users you want to mark as "untrusted."
52859+ These users will not be able to execute any files that are not in
52860+ root-owned directories writable only by root. If the sysctl option
52861+ is enabled, a sysctl option with name "tpe" is created.
52862+
52863+config GRKERNSEC_TPE_ALL
52864+ bool "Partially restrict all non-root users"
52865+ depends on GRKERNSEC_TPE
52866+ help
52867+ If you say Y here, all non-root users will be covered under
52868+ a weaker TPE restriction. This is separate from, and in addition to,
52869+ the main TPE options that you have selected elsewhere. Thus, if a
52870+ "trusted" GID is chosen, this restriction applies to even that GID.
52871+ Under this restriction, all non-root users will only be allowed to
52872+ execute files in directories they own that are not group or
52873+ world-writable, or in directories owned by root and writable only by
52874+ root. If the sysctl option is enabled, a sysctl option with name
52875+ "tpe_restrict_all" is created.
52876+
52877+config GRKERNSEC_TPE_INVERT
52878+ bool "Invert GID option"
52879+ depends on GRKERNSEC_TPE
52880+ help
52881+ If you say Y here, the group you specify in the TPE configuration will
52882+ decide what group TPE restrictions will be *disabled* for. This
52883+ option is useful if you want TPE restrictions to be applied to most
52884+ users on the system. If the sysctl option is enabled, a sysctl option
52885+ with name "tpe_invert" is created. Unlike other sysctl options, this
52886+ entry will default to on for backward-compatibility.
52887+
52888+config GRKERNSEC_TPE_GID
52889+ int
52890+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
52891+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
52892+
52893+config GRKERNSEC_TPE_UNTRUSTED_GID
52894+ int "GID for TPE-untrusted users"
52895+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
52896+ default 1005
52897+ help
52898+ Setting this GID determines what group TPE restrictions will be
52899+ *enabled* for. If the sysctl option is enabled, a sysctl option
52900+ with name "tpe_gid" is created.
52901+
52902+config GRKERNSEC_TPE_TRUSTED_GID
52903+ int "GID for TPE-trusted users"
52904+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
52905+ default 1005
52906+ help
52907+ Setting this GID determines what group TPE restrictions will be
52908+ *disabled* for. If the sysctl option is enabled, a sysctl option
52909+ with name "tpe_gid" is created.
52910+
52911+endmenu
52912+menu "Network Protections"
52913+depends on GRKERNSEC
52914+
52915+config GRKERNSEC_RANDNET
52916+ bool "Larger entropy pools"
52917+ default y if GRKERNSEC_CONFIG_AUTO
52918+ help
52919+ If you say Y here, the entropy pools used for many features of Linux
52920+ and grsecurity will be doubled in size. Since several grsecurity
52921+ features use additional randomness, it is recommended that you say Y
52922+ here. Saying Y here has a similar effect as modifying
52923+ /proc/sys/kernel/random/poolsize.
52924+
52925+config GRKERNSEC_BLACKHOLE
52926+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
52927+ default y if GRKERNSEC_CONFIG_AUTO
52928+ depends on NET
52929+ help
52930+ If you say Y here, neither TCP resets nor ICMP
52931+ destination-unreachable packets will be sent in response to packets
52932+ sent to ports for which no associated listening process exists.
52933+ This feature supports both IPV4 and IPV6 and exempts the
52934+ loopback interface from blackholing. Enabling this feature
52935+ makes a host more resilient to DoS attacks and reduces network
52936+ visibility against scanners.
52937+
52938+ The blackhole feature as-implemented is equivalent to the FreeBSD
52939+ blackhole feature, as it prevents RST responses to all packets, not
52940+ just SYNs. Under most application behavior this causes no
52941+ problems, but applications (like haproxy) may not close certain
52942+ connections in a way that cleanly terminates them on the remote
52943+ end, leaving the remote host in LAST_ACK state. Because of this
52944+ side-effect and to prevent intentional LAST_ACK DoSes, this
52945+ feature also adds automatic mitigation against such attacks.
52946+ The mitigation drastically reduces the amount of time a socket
52947+ can spend in LAST_ACK state. If you're using haproxy and not
52948+ all servers it connects to have this option enabled, consider
52949+ disabling this feature on the haproxy host.
52950+
52951+ If the sysctl option is enabled, two sysctl options with names
52952+ "ip_blackhole" and "lastack_retries" will be created.
52953+ While "ip_blackhole" takes the standard zero/non-zero on/off
52954+ toggle, "lastack_retries" uses the same kinds of values as
52955+ "tcp_retries1" and "tcp_retries2". The default value of 4
52956+ prevents a socket from lasting more than 45 seconds in LAST_ACK
52957+ state.
52958+
52959+config GRKERNSEC_SOCKET
52960+ bool "Socket restrictions"
52961+ depends on NET
52962+ help
52963+ If you say Y here, you will be able to choose from several options.
52964+ If you assign a GID on your system and add it to the supplementary
52965+ groups of users you want to restrict socket access to, this patch
52966+ will perform up to three things, based on the option(s) you choose.
52967+
52968+config GRKERNSEC_SOCKET_ALL
52969+ bool "Deny any sockets to group"
52970+ depends on GRKERNSEC_SOCKET
52971+ help
52972+ If you say Y here, you will be able to choose a GID of whose users will
52973+ be unable to connect to other hosts from your machine or run server
52974+ applications from your machine. If the sysctl option is enabled, a
52975+ sysctl option with name "socket_all" is created.
52976+
52977+config GRKERNSEC_SOCKET_ALL_GID
52978+ int "GID to deny all sockets for"
52979+ depends on GRKERNSEC_SOCKET_ALL
52980+ default 1004
52981+ help
52982+ Here you can choose the GID to disable socket access for. Remember to
52983+ add the users you want socket access disabled for to the GID
52984+ specified here. If the sysctl option is enabled, a sysctl option
52985+ with name "socket_all_gid" is created.
52986+
52987+config GRKERNSEC_SOCKET_CLIENT
52988+ bool "Deny client sockets to group"
52989+ depends on GRKERNSEC_SOCKET
52990+ help
52991+ If you say Y here, you will be able to choose a GID of whose users will
52992+ be unable to connect to other hosts from your machine, but will be
52993+ able to run servers. If this option is enabled, all users in the group
52994+ you specify will have to use passive mode when initiating ftp transfers
52995+ from the shell on your machine. If the sysctl option is enabled, a
52996+ sysctl option with name "socket_client" is created.
52997+
52998+config GRKERNSEC_SOCKET_CLIENT_GID
52999+ int "GID to deny client sockets for"
53000+ depends on GRKERNSEC_SOCKET_CLIENT
53001+ default 1003
53002+ help
53003+ Here you can choose the GID to disable client socket access for.
53004+ Remember to add the users you want client socket access disabled for to
53005+ the GID specified here. If the sysctl option is enabled, a sysctl
53006+ option with name "socket_client_gid" is created.
53007+
53008+config GRKERNSEC_SOCKET_SERVER
53009+ bool "Deny server sockets to group"
53010+ depends on GRKERNSEC_SOCKET
53011+ help
53012+ If you say Y here, you will be able to choose a GID of whose users will
53013+ be unable to run server applications from your machine. If the sysctl
53014+ option is enabled, a sysctl option with name "socket_server" is created.
53015+
53016+config GRKERNSEC_SOCKET_SERVER_GID
53017+ int "GID to deny server sockets for"
53018+ depends on GRKERNSEC_SOCKET_SERVER
53019+ default 1002
53020+ help
53021+ Here you can choose the GID to disable server socket access for.
53022+ Remember to add the users you want server socket access disabled for to
53023+ the GID specified here. If the sysctl option is enabled, a sysctl
53024+ option with name "socket_server_gid" is created.
53025+
53026+endmenu
53027+menu "Sysctl Support"
53028+depends on GRKERNSEC && SYSCTL
53029+
53030+config GRKERNSEC_SYSCTL
53031+ bool "Sysctl support"
53032+ default y if GRKERNSEC_CONFIG_AUTO
53033+ help
53034+ If you say Y here, you will be able to change the options that
53035+ grsecurity runs with at bootup, without having to recompile your
53036+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
53037+ to enable (1) or disable (0) various features. All the sysctl entries
53038+ are mutable until the "grsec_lock" entry is set to a non-zero value.
53039+ All features enabled in the kernel configuration are disabled at boot
53040+ if you do not say Y to the "Turn on features by default" option.
53041+ All options should be set at startup, and the grsec_lock entry should
53042+ be set to a non-zero value after all the options are set.
53043+ *THIS IS EXTREMELY IMPORTANT*
53044+
53045+config GRKERNSEC_SYSCTL_DISTRO
53046+ bool "Extra sysctl support for distro makers (READ HELP)"
53047+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
53048+ help
53049+ If you say Y here, additional sysctl options will be created
53050+ for features that affect processes running as root. Therefore,
53051+ it is critical when using this option that the grsec_lock entry be
53052+ enabled after boot. Only distros with prebuilt kernel packages
53053+ with this option enabled that can ensure grsec_lock is enabled
53054+ after boot should use this option.
53055+ *Failure to set grsec_lock after boot makes all grsec features
53056+ this option covers useless*
53057+
53058+ Currently this option creates the following sysctl entries:
53059+ "Disable Privileged I/O": "disable_priv_io"
53060+
53061+config GRKERNSEC_SYSCTL_ON
53062+ bool "Turn on features by default"
53063+ default y if GRKERNSEC_CONFIG_AUTO
53064+ depends on GRKERNSEC_SYSCTL
53065+ help
53066+ If you say Y here, instead of having all features enabled in the
53067+ kernel configuration disabled at boot time, the features will be
53068+ enabled at boot time. It is recommended you say Y here unless
53069+ there is some reason you would want all sysctl-tunable features to
53070+ be disabled by default. As mentioned elsewhere, it is important
53071+ to enable the grsec_lock entry once you have finished modifying
53072+ the sysctl entries.
53073+
53074+endmenu
53075+menu "Logging Options"
53076+depends on GRKERNSEC
53077+
53078+config GRKERNSEC_FLOODTIME
53079+ int "Seconds in between log messages (minimum)"
53080+ default 10
53081+ help
53082+ This option allows you to enforce the number of seconds between
53083+ grsecurity log messages. The default should be suitable for most
53084+ people, however, if you choose to change it, choose a value small enough
53085+ to allow informative logs to be produced, but large enough to
53086+ prevent flooding.
53087+
53088+config GRKERNSEC_FLOODBURST
53089+ int "Number of messages in a burst (maximum)"
53090+ default 6
53091+ help
53092+ This option allows you to choose the maximum number of messages allowed
53093+ within the flood time interval you chose in a separate option. The
53094+ default should be suitable for most people, however if you find that
53095+ many of your logs are being interpreted as flooding, you may want to
53096+ raise this value.
53097+
53098+endmenu
53099diff --git a/grsecurity/Makefile b/grsecurity/Makefile
53100new file mode 100644
53101index 0000000..1b9afa9
53102--- /dev/null
53103+++ b/grsecurity/Makefile
53104@@ -0,0 +1,38 @@
53105+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
53106+# during 2001-2009 it has been completely redesigned by Brad Spengler
53107+# into an RBAC system
53108+#
53109+# All code in this directory and various hooks inserted throughout the kernel
53110+# are copyright Brad Spengler - Open Source Security, Inc., and released
53111+# under the GPL v2 or higher
53112+
53113+KBUILD_CFLAGS += -Werror
53114+
53115+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
53116+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
53117+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
53118+
53119+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
53120+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
53121+ gracl_learn.o grsec_log.o
53122+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
53123+
53124+ifdef CONFIG_NET
53125+obj-y += grsec_sock.o
53126+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
53127+endif
53128+
53129+ifndef CONFIG_GRKERNSEC
53130+obj-y += grsec_disabled.o
53131+endif
53132+
53133+ifdef CONFIG_GRKERNSEC_HIDESYM
53134+extra-y := grsec_hidesym.o
53135+$(obj)/grsec_hidesym.o:
53136+ @-chmod -f 500 /boot
53137+ @-chmod -f 500 /lib/modules
53138+ @-chmod -f 500 /lib64/modules
53139+ @-chmod -f 500 /lib32/modules
53140+ @-chmod -f 700 .
53141+ @echo ' grsec: protected kernel image paths'
53142+endif
53143diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
53144new file mode 100644
53145index 0000000..78353bd
53146--- /dev/null
53147+++ b/grsecurity/gracl.c
53148@@ -0,0 +1,4039 @@
53149+#include <linux/kernel.h>
53150+#include <linux/module.h>
53151+#include <linux/sched.h>
53152+#include <linux/mm.h>
53153+#include <linux/file.h>
53154+#include <linux/fs.h>
53155+#include <linux/namei.h>
53156+#include <linux/mount.h>
53157+#include <linux/tty.h>
53158+#include <linux/proc_fs.h>
53159+#include <linux/lglock.h>
53160+#include <linux/slab.h>
53161+#include <linux/vmalloc.h>
53162+#include <linux/types.h>
53163+#include <linux/sysctl.h>
53164+#include <linux/netdevice.h>
53165+#include <linux/ptrace.h>
53166+#include <linux/gracl.h>
53167+#include <linux/gralloc.h>
53168+#include <linux/security.h>
53169+#include <linux/grinternal.h>
53170+#include <linux/pid_namespace.h>
53171+#include <linux/stop_machine.h>
53172+#include <linux/fdtable.h>
53173+#include <linux/percpu.h>
53174+#include <linux/lglock.h>
53175+#include "../fs/mount.h"
53176+
53177+#include <asm/uaccess.h>
53178+#include <asm/errno.h>
53179+#include <asm/mman.h>
53180+
53181+extern struct lglock vfsmount_lock;
53182+
53183+static struct acl_role_db acl_role_set;
53184+static struct name_db name_set;
53185+static struct inodev_db inodev_set;
53186+
53187+/* for keeping track of userspace pointers used for subjects, so we
53188+ can share references in the kernel as well
53189+*/
53190+
53191+static struct path real_root;
53192+
53193+static struct acl_subj_map_db subj_map_set;
53194+
53195+static struct acl_role_label *default_role;
53196+
53197+static struct acl_role_label *role_list;
53198+
53199+static u16 acl_sp_role_value;
53200+
53201+extern char *gr_shared_page[4];
53202+static DEFINE_MUTEX(gr_dev_mutex);
53203+DEFINE_RWLOCK(gr_inode_lock);
53204+
53205+struct gr_arg *gr_usermode;
53206+
53207+static unsigned int gr_status __read_only = GR_STATUS_INIT;
53208+
53209+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
53210+extern void gr_clear_learn_entries(void);
53211+
53212+#ifdef CONFIG_GRKERNSEC_RESLOG
53213+extern void gr_log_resource(const struct task_struct *task,
53214+ const int res, const unsigned long wanted, const int gt);
53215+#endif
53216+
53217+unsigned char *gr_system_salt;
53218+unsigned char *gr_system_sum;
53219+
53220+static struct sprole_pw **acl_special_roles = NULL;
53221+static __u16 num_sprole_pws = 0;
53222+
53223+static struct acl_role_label *kernel_role = NULL;
53224+
53225+static unsigned int gr_auth_attempts = 0;
53226+static unsigned long gr_auth_expires = 0UL;
53227+
53228+#ifdef CONFIG_NET
53229+extern struct vfsmount *sock_mnt;
53230+#endif
53231+
53232+extern struct vfsmount *pipe_mnt;
53233+extern struct vfsmount *shm_mnt;
53234+#ifdef CONFIG_HUGETLBFS
53235+extern struct vfsmount *hugetlbfs_vfsmount;
53236+#endif
53237+
53238+static struct acl_object_label *fakefs_obj_rw;
53239+static struct acl_object_label *fakefs_obj_rwx;
53240+
53241+extern int gr_init_uidset(void);
53242+extern void gr_free_uidset(void);
53243+extern void gr_remove_uid(uid_t uid);
53244+extern int gr_find_uid(uid_t uid);
53245+
53246+__inline__ int
53247+gr_acl_is_enabled(void)
53248+{
53249+ return (gr_status & GR_READY);
53250+}
53251+
53252+#ifdef CONFIG_BTRFS_FS
53253+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
53254+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
53255+#endif
53256+
53257+static inline dev_t __get_dev(const struct dentry *dentry)
53258+{
53259+#ifdef CONFIG_BTRFS_FS
53260+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
53261+ return get_btrfs_dev_from_inode(dentry->d_inode);
53262+ else
53263+#endif
53264+ return dentry->d_inode->i_sb->s_dev;
53265+}
53266+
53267+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
53268+{
53269+ return __get_dev(dentry);
53270+}
53271+
53272+static char gr_task_roletype_to_char(struct task_struct *task)
53273+{
53274+ switch (task->role->roletype &
53275+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
53276+ GR_ROLE_SPECIAL)) {
53277+ case GR_ROLE_DEFAULT:
53278+ return 'D';
53279+ case GR_ROLE_USER:
53280+ return 'U';
53281+ case GR_ROLE_GROUP:
53282+ return 'G';
53283+ case GR_ROLE_SPECIAL:
53284+ return 'S';
53285+ }
53286+
53287+ return 'X';
53288+}
53289+
53290+char gr_roletype_to_char(void)
53291+{
53292+ return gr_task_roletype_to_char(current);
53293+}
53294+
53295+__inline__ int
53296+gr_acl_tpe_check(void)
53297+{
53298+ if (unlikely(!(gr_status & GR_READY)))
53299+ return 0;
53300+ if (current->role->roletype & GR_ROLE_TPE)
53301+ return 1;
53302+ else
53303+ return 0;
53304+}
53305+
53306+int
53307+gr_handle_rawio(const struct inode *inode)
53308+{
53309+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
53310+ if (inode && S_ISBLK(inode->i_mode) &&
53311+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
53312+ !capable(CAP_SYS_RAWIO))
53313+ return 1;
53314+#endif
53315+ return 0;
53316+}
53317+
53318+static int
53319+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
53320+{
53321+ if (likely(lena != lenb))
53322+ return 0;
53323+
53324+ return !memcmp(a, b, lena);
53325+}
53326+
53327+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
53328+{
53329+ *buflen -= namelen;
53330+ if (*buflen < 0)
53331+ return -ENAMETOOLONG;
53332+ *buffer -= namelen;
53333+ memcpy(*buffer, str, namelen);
53334+ return 0;
53335+}
53336+
53337+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
53338+{
53339+ return prepend(buffer, buflen, name->name, name->len);
53340+}
53341+
53342+static int prepend_path(const struct path *path, struct path *root,
53343+ char **buffer, int *buflen)
53344+{
53345+ struct dentry *dentry = path->dentry;
53346+ struct vfsmount *vfsmnt = path->mnt;
53347+ struct mount *mnt = real_mount(vfsmnt);
53348+ bool slash = false;
53349+ int error = 0;
53350+
53351+ while (dentry != root->dentry || vfsmnt != root->mnt) {
53352+ struct dentry * parent;
53353+
53354+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
53355+ /* Global root? */
53356+ if (!mnt_has_parent(mnt)) {
53357+ goto out;
53358+ }
53359+ dentry = mnt->mnt_mountpoint;
53360+ mnt = mnt->mnt_parent;
53361+ vfsmnt = &mnt->mnt;
53362+ continue;
53363+ }
53364+ parent = dentry->d_parent;
53365+ prefetch(parent);
53366+ spin_lock(&dentry->d_lock);
53367+ error = prepend_name(buffer, buflen, &dentry->d_name);
53368+ spin_unlock(&dentry->d_lock);
53369+ if (!error)
53370+ error = prepend(buffer, buflen, "/", 1);
53371+ if (error)
53372+ break;
53373+
53374+ slash = true;
53375+ dentry = parent;
53376+ }
53377+
53378+out:
53379+ if (!error && !slash)
53380+ error = prepend(buffer, buflen, "/", 1);
53381+
53382+ return error;
53383+}
53384+
53385+/* this must be called with vfsmount_lock and rename_lock held */
53386+
53387+static char *__our_d_path(const struct path *path, struct path *root,
53388+ char *buf, int buflen)
53389+{
53390+ char *res = buf + buflen;
53391+ int error;
53392+
53393+ prepend(&res, &buflen, "\0", 1);
53394+ error = prepend_path(path, root, &res, &buflen);
53395+ if (error)
53396+ return ERR_PTR(error);
53397+
53398+ return res;
53399+}
53400+
53401+static char *
53402+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
53403+{
53404+ char *retval;
53405+
53406+ retval = __our_d_path(path, root, buf, buflen);
53407+ if (unlikely(IS_ERR(retval)))
53408+ retval = strcpy(buf, "<path too long>");
53409+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
53410+ retval[1] = '\0';
53411+
53412+ return retval;
53413+}
53414+
53415+static char *
53416+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
53417+ char *buf, int buflen)
53418+{
53419+ struct path path;
53420+ char *res;
53421+
53422+ path.dentry = (struct dentry *)dentry;
53423+ path.mnt = (struct vfsmount *)vfsmnt;
53424+
53425+ /* we can use real_root.dentry, real_root.mnt, because this is only called
53426+ by the RBAC system */
53427+ res = gen_full_path(&path, &real_root, buf, buflen);
53428+
53429+ return res;
53430+}
53431+
53432+static char *
53433+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
53434+ char *buf, int buflen)
53435+{
53436+ char *res;
53437+ struct path path;
53438+ struct path root;
53439+ struct task_struct *reaper = init_pid_ns.child_reaper;
53440+
53441+ path.dentry = (struct dentry *)dentry;
53442+ path.mnt = (struct vfsmount *)vfsmnt;
53443+
53444+ /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
53445+ get_fs_root(reaper->fs, &root);
53446+
53447+ write_seqlock(&rename_lock);
53448+ br_read_lock(&vfsmount_lock);
53449+ res = gen_full_path(&path, &root, buf, buflen);
53450+ br_read_unlock(&vfsmount_lock);
53451+ write_sequnlock(&rename_lock);
53452+
53453+ path_put(&root);
53454+ return res;
53455+}
53456+
53457+static char *
53458+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
53459+{
53460+ char *ret;
53461+ write_seqlock(&rename_lock);
53462+ br_read_lock(&vfsmount_lock);
53463+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
53464+ PAGE_SIZE);
53465+ br_read_unlock(&vfsmount_lock);
53466+ write_sequnlock(&rename_lock);
53467+ return ret;
53468+}
53469+
53470+static char *
53471+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
53472+{
53473+ char *ret;
53474+ char *buf;
53475+ int buflen;
53476+
53477+ write_seqlock(&rename_lock);
53478+ br_read_lock(&vfsmount_lock);
53479+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
53480+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
53481+ buflen = (int)(ret - buf);
53482+ if (buflen >= 5)
53483+ prepend(&ret, &buflen, "/proc", 5);
53484+ else
53485+ ret = strcpy(buf, "<path too long>");
53486+ br_read_unlock(&vfsmount_lock);
53487+ write_sequnlock(&rename_lock);
53488+ return ret;
53489+}
53490+
53491+char *
53492+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
53493+{
53494+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
53495+ PAGE_SIZE);
53496+}
53497+
53498+char *
53499+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
53500+{
53501+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
53502+ PAGE_SIZE);
53503+}
53504+
53505+char *
53506+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
53507+{
53508+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
53509+ PAGE_SIZE);
53510+}
53511+
53512+char *
53513+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
53514+{
53515+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
53516+ PAGE_SIZE);
53517+}
53518+
53519+char *
53520+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
53521+{
53522+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
53523+ PAGE_SIZE);
53524+}
53525+
53526+__inline__ __u32
53527+to_gr_audit(const __u32 reqmode)
53528+{
53529+ /* masks off auditable permission flags, then shifts them to create
53530+ auditing flags, and adds the special case of append auditing if
53531+ we're requesting write */
53532+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
53533+}
53534+
53535+struct acl_subject_label *
53536+lookup_subject_map(const struct acl_subject_label *userp)
53537+{
53538+ unsigned int index = gr_shash(userp, subj_map_set.s_size);
53539+ struct subject_map *match;
53540+
53541+ match = subj_map_set.s_hash[index];
53542+
53543+ while (match && match->user != userp)
53544+ match = match->next;
53545+
53546+ if (match != NULL)
53547+ return match->kernel;
53548+ else
53549+ return NULL;
53550+}
53551+
53552+static void
53553+insert_subj_map_entry(struct subject_map *subjmap)
53554+{
53555+ unsigned int index = gr_shash(subjmap->user, subj_map_set.s_size);
53556+ struct subject_map **curr;
53557+
53558+ subjmap->prev = NULL;
53559+
53560+ curr = &subj_map_set.s_hash[index];
53561+ if (*curr != NULL)
53562+ (*curr)->prev = subjmap;
53563+
53564+ subjmap->next = *curr;
53565+ *curr = subjmap;
53566+
53567+ return;
53568+}
53569+
53570+static struct acl_role_label *
53571+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
53572+ const gid_t gid)
53573+{
53574+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
53575+ struct acl_role_label *match;
53576+ struct role_allowed_ip *ipp;
53577+ unsigned int x;
53578+ u32 curr_ip = task->signal->curr_ip;
53579+
53580+ task->signal->saved_ip = curr_ip;
53581+
53582+ match = acl_role_set.r_hash[index];
53583+
53584+ while (match) {
53585+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
53586+ for (x = 0; x < match->domain_child_num; x++) {
53587+ if (match->domain_children[x] == uid)
53588+ goto found;
53589+ }
53590+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
53591+ break;
53592+ match = match->next;
53593+ }
53594+found:
53595+ if (match == NULL) {
53596+ try_group:
53597+ index = gr_rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
53598+ match = acl_role_set.r_hash[index];
53599+
53600+ while (match) {
53601+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
53602+ for (x = 0; x < match->domain_child_num; x++) {
53603+ if (match->domain_children[x] == gid)
53604+ goto found2;
53605+ }
53606+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
53607+ break;
53608+ match = match->next;
53609+ }
53610+found2:
53611+ if (match == NULL)
53612+ match = default_role;
53613+ if (match->allowed_ips == NULL)
53614+ return match;
53615+ else {
53616+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
53617+ if (likely
53618+ ((ntohl(curr_ip) & ipp->netmask) ==
53619+ (ntohl(ipp->addr) & ipp->netmask)))
53620+ return match;
53621+ }
53622+ match = default_role;
53623+ }
53624+ } else if (match->allowed_ips == NULL) {
53625+ return match;
53626+ } else {
53627+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
53628+ if (likely
53629+ ((ntohl(curr_ip) & ipp->netmask) ==
53630+ (ntohl(ipp->addr) & ipp->netmask)))
53631+ return match;
53632+ }
53633+ goto try_group;
53634+ }
53635+
53636+ return match;
53637+}
53638+
53639+struct acl_subject_label *
53640+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
53641+ const struct acl_role_label *role)
53642+{
53643+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
53644+ struct acl_subject_label *match;
53645+
53646+ match = role->subj_hash[index];
53647+
53648+ while (match && (match->inode != ino || match->device != dev ||
53649+ (match->mode & GR_DELETED))) {
53650+ match = match->next;
53651+ }
53652+
53653+ if (match && !(match->mode & GR_DELETED))
53654+ return match;
53655+ else
53656+ return NULL;
53657+}
53658+
53659+struct acl_subject_label *
53660+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
53661+ const struct acl_role_label *role)
53662+{
53663+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
53664+ struct acl_subject_label *match;
53665+
53666+ match = role->subj_hash[index];
53667+
53668+ while (match && (match->inode != ino || match->device != dev ||
53669+ !(match->mode & GR_DELETED))) {
53670+ match = match->next;
53671+ }
53672+
53673+ if (match && (match->mode & GR_DELETED))
53674+ return match;
53675+ else
53676+ return NULL;
53677+}
53678+
53679+static struct acl_object_label *
53680+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
53681+ const struct acl_subject_label *subj)
53682+{
53683+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
53684+ struct acl_object_label *match;
53685+
53686+ match = subj->obj_hash[index];
53687+
53688+ while (match && (match->inode != ino || match->device != dev ||
53689+ (match->mode & GR_DELETED))) {
53690+ match = match->next;
53691+ }
53692+
53693+ if (match && !(match->mode & GR_DELETED))
53694+ return match;
53695+ else
53696+ return NULL;
53697+}
53698+
53699+static struct acl_object_label *
53700+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
53701+ const struct acl_subject_label *subj)
53702+{
53703+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
53704+ struct acl_object_label *match;
53705+
53706+ match = subj->obj_hash[index];
53707+
53708+ while (match && (match->inode != ino || match->device != dev ||
53709+ !(match->mode & GR_DELETED))) {
53710+ match = match->next;
53711+ }
53712+
53713+ if (match && (match->mode & GR_DELETED))
53714+ return match;
53715+
53716+ match = subj->obj_hash[index];
53717+
53718+ while (match && (match->inode != ino || match->device != dev ||
53719+ (match->mode & GR_DELETED))) {
53720+ match = match->next;
53721+ }
53722+
53723+ if (match && !(match->mode & GR_DELETED))
53724+ return match;
53725+ else
53726+ return NULL;
53727+}
53728+
53729+static struct name_entry *
53730+lookup_name_entry(const char *name)
53731+{
53732+ unsigned int len = strlen(name);
53733+ unsigned int key = full_name_hash(name, len);
53734+ unsigned int index = key % name_set.n_size;
53735+ struct name_entry *match;
53736+
53737+ match = name_set.n_hash[index];
53738+
53739+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
53740+ match = match->next;
53741+
53742+ return match;
53743+}
53744+
53745+static struct name_entry *
53746+lookup_name_entry_create(const char *name)
53747+{
53748+ unsigned int len = strlen(name);
53749+ unsigned int key = full_name_hash(name, len);
53750+ unsigned int index = key % name_set.n_size;
53751+ struct name_entry *match;
53752+
53753+ match = name_set.n_hash[index];
53754+
53755+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
53756+ !match->deleted))
53757+ match = match->next;
53758+
53759+ if (match && match->deleted)
53760+ return match;
53761+
53762+ match = name_set.n_hash[index];
53763+
53764+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
53765+ match->deleted))
53766+ match = match->next;
53767+
53768+ if (match && !match->deleted)
53769+ return match;
53770+ else
53771+ return NULL;
53772+}
53773+
53774+static struct inodev_entry *
53775+lookup_inodev_entry(const ino_t ino, const dev_t dev)
53776+{
53777+ unsigned int index = gr_fhash(ino, dev, inodev_set.i_size);
53778+ struct inodev_entry *match;
53779+
53780+ match = inodev_set.i_hash[index];
53781+
53782+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
53783+ match = match->next;
53784+
53785+ return match;
53786+}
53787+
53788+static void
53789+insert_inodev_entry(struct inodev_entry *entry)
53790+{
53791+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
53792+ inodev_set.i_size);
53793+ struct inodev_entry **curr;
53794+
53795+ entry->prev = NULL;
53796+
53797+ curr = &inodev_set.i_hash[index];
53798+ if (*curr != NULL)
53799+ (*curr)->prev = entry;
53800+
53801+ entry->next = *curr;
53802+ *curr = entry;
53803+
53804+ return;
53805+}
53806+
53807+static void
53808+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
53809+{
53810+ unsigned int index =
53811+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
53812+ struct acl_role_label **curr;
53813+ struct acl_role_label *tmp, *tmp2;
53814+
53815+ curr = &acl_role_set.r_hash[index];
53816+
53817+ /* simple case, slot is empty, just set it to our role */
53818+ if (*curr == NULL) {
53819+ *curr = role;
53820+ } else {
53821+ /* example:
53822+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
53823+ 2 -> 3
53824+ */
53825+ /* first check to see if we can already be reached via this slot */
53826+ tmp = *curr;
53827+ while (tmp && tmp != role)
53828+ tmp = tmp->next;
53829+ if (tmp == role) {
53830+ /* we don't need to add ourselves to this slot's chain */
53831+ return;
53832+ }
53833+ /* we need to add ourselves to this chain, two cases */
53834+ if (role->next == NULL) {
53835+ /* simple case, append the current chain to our role */
53836+ role->next = *curr;
53837+ *curr = role;
53838+ } else {
53839+ /* 1 -> 2 -> 3 -> 4
53840+ 2 -> 3 -> 4
53841+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
53842+ */
53843+ /* trickier case: walk our role's chain until we find
53844+ the role for the start of the current slot's chain */
53845+ tmp = role;
53846+ tmp2 = *curr;
53847+ while (tmp->next && tmp->next != tmp2)
53848+ tmp = tmp->next;
53849+ if (tmp->next == tmp2) {
53850+ /* from example above, we found 3, so just
53851+ replace this slot's chain with ours */
53852+ *curr = role;
53853+ } else {
53854+ /* we didn't find a subset of our role's chain
53855+ in the current slot's chain, so append their
53856+ chain to ours, and set us as the first role in
53857+ the slot's chain
53858+
53859+ we could fold this case with the case above,
53860+ but making it explicit for clarity
53861+ */
53862+ tmp->next = tmp2;
53863+ *curr = role;
53864+ }
53865+ }
53866+ }
53867+
53868+ return;
53869+}
53870+
53871+static void
53872+insert_acl_role_label(struct acl_role_label *role)
53873+{
53874+ int i;
53875+
53876+ if (role_list == NULL) {
53877+ role_list = role;
53878+ role->prev = NULL;
53879+ } else {
53880+ role->prev = role_list;
53881+ role_list = role;
53882+ }
53883+
53884+ /* used for hash chains */
53885+ role->next = NULL;
53886+
53887+ if (role->roletype & GR_ROLE_DOMAIN) {
53888+ for (i = 0; i < role->domain_child_num; i++)
53889+ __insert_acl_role_label(role, role->domain_children[i]);
53890+ } else
53891+ __insert_acl_role_label(role, role->uidgid);
53892+}
53893+
53894+static int
53895+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
53896+{
53897+ struct name_entry **curr, *nentry;
53898+ struct inodev_entry *ientry;
53899+ unsigned int len = strlen(name);
53900+ unsigned int key = full_name_hash(name, len);
53901+ unsigned int index = key % name_set.n_size;
53902+
53903+ curr = &name_set.n_hash[index];
53904+
53905+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
53906+ curr = &((*curr)->next);
53907+
53908+ if (*curr != NULL)
53909+ return 1;
53910+
53911+ nentry = acl_alloc(sizeof (struct name_entry));
53912+ if (nentry == NULL)
53913+ return 0;
53914+ ientry = acl_alloc(sizeof (struct inodev_entry));
53915+ if (ientry == NULL)
53916+ return 0;
53917+ ientry->nentry = nentry;
53918+
53919+ nentry->key = key;
53920+ nentry->name = name;
53921+ nentry->inode = inode;
53922+ nentry->device = device;
53923+ nentry->len = len;
53924+ nentry->deleted = deleted;
53925+
53926+ nentry->prev = NULL;
53927+ curr = &name_set.n_hash[index];
53928+ if (*curr != NULL)
53929+ (*curr)->prev = nentry;
53930+ nentry->next = *curr;
53931+ *curr = nentry;
53932+
53933+ /* insert us into the table searchable by inode/dev */
53934+ insert_inodev_entry(ientry);
53935+
53936+ return 1;
53937+}
53938+
53939+static void
53940+insert_acl_obj_label(struct acl_object_label *obj,
53941+ struct acl_subject_label *subj)
53942+{
53943+ unsigned int index =
53944+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
53945+ struct acl_object_label **curr;
53946+
53947+
53948+ obj->prev = NULL;
53949+
53950+ curr = &subj->obj_hash[index];
53951+ if (*curr != NULL)
53952+ (*curr)->prev = obj;
53953+
53954+ obj->next = *curr;
53955+ *curr = obj;
53956+
53957+ return;
53958+}
53959+
53960+static void
53961+insert_acl_subj_label(struct acl_subject_label *obj,
53962+ struct acl_role_label *role)
53963+{
53964+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
53965+ struct acl_subject_label **curr;
53966+
53967+ obj->prev = NULL;
53968+
53969+ curr = &role->subj_hash[index];
53970+ if (*curr != NULL)
53971+ (*curr)->prev = obj;
53972+
53973+ obj->next = *curr;
53974+ *curr = obj;
53975+
53976+ return;
53977+}
53978+
53979+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
53980+
53981+static void *
53982+create_table(__u32 * len, int elementsize)
53983+{
53984+ unsigned int table_sizes[] = {
53985+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
53986+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
53987+ 4194301, 8388593, 16777213, 33554393, 67108859
53988+ };
53989+ void *newtable = NULL;
53990+ unsigned int pwr = 0;
53991+
53992+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
53993+ table_sizes[pwr] <= *len)
53994+ pwr++;
53995+
53996+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
53997+ return newtable;
53998+
53999+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
54000+ newtable =
54001+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
54002+ else
54003+ newtable = vmalloc(table_sizes[pwr] * elementsize);
54004+
54005+ *len = table_sizes[pwr];
54006+
54007+ return newtable;
54008+}
54009+
54010+static int
54011+init_variables(const struct gr_arg *arg)
54012+{
54013+ struct task_struct *reaper = init_pid_ns.child_reaper;
54014+ unsigned int stacksize;
54015+
54016+ subj_map_set.s_size = arg->role_db.num_subjects;
54017+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
54018+ name_set.n_size = arg->role_db.num_objects;
54019+ inodev_set.i_size = arg->role_db.num_objects;
54020+
54021+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
54022+ !name_set.n_size || !inodev_set.i_size)
54023+ return 1;
54024+
54025+ if (!gr_init_uidset())
54026+ return 1;
54027+
54028+ /* set up the stack that holds allocation info */
54029+
54030+ stacksize = arg->role_db.num_pointers + 5;
54031+
54032+ if (!acl_alloc_stack_init(stacksize))
54033+ return 1;
54034+
54035+ /* grab reference for the real root dentry and vfsmount */
54036+ get_fs_root(reaper->fs, &real_root);
54037+
54038+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54039+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
54040+#endif
54041+
54042+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
54043+ if (fakefs_obj_rw == NULL)
54044+ return 1;
54045+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
54046+
54047+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
54048+ if (fakefs_obj_rwx == NULL)
54049+ return 1;
54050+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
54051+
54052+ subj_map_set.s_hash =
54053+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
54054+ acl_role_set.r_hash =
54055+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
54056+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
54057+ inodev_set.i_hash =
54058+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
54059+
54060+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
54061+ !name_set.n_hash || !inodev_set.i_hash)
54062+ return 1;
54063+
54064+ memset(subj_map_set.s_hash, 0,
54065+ sizeof(struct subject_map *) * subj_map_set.s_size);
54066+ memset(acl_role_set.r_hash, 0,
54067+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
54068+ memset(name_set.n_hash, 0,
54069+ sizeof (struct name_entry *) * name_set.n_size);
54070+ memset(inodev_set.i_hash, 0,
54071+ sizeof (struct inodev_entry *) * inodev_set.i_size);
54072+
54073+ return 0;
54074+}
54075+
54076+/* free information not needed after startup
54077+ currently contains user->kernel pointer mappings for subjects
54078+*/
54079+
54080+static void
54081+free_init_variables(void)
54082+{
54083+ __u32 i;
54084+
54085+ if (subj_map_set.s_hash) {
54086+ for (i = 0; i < subj_map_set.s_size; i++) {
54087+ if (subj_map_set.s_hash[i]) {
54088+ kfree(subj_map_set.s_hash[i]);
54089+ subj_map_set.s_hash[i] = NULL;
54090+ }
54091+ }
54092+
54093+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
54094+ PAGE_SIZE)
54095+ kfree(subj_map_set.s_hash);
54096+ else
54097+ vfree(subj_map_set.s_hash);
54098+ }
54099+
54100+ return;
54101+}
54102+
54103+static void
54104+free_variables(void)
54105+{
54106+ struct acl_subject_label *s;
54107+ struct acl_role_label *r;
54108+ struct task_struct *task, *task2;
54109+ unsigned int x;
54110+
54111+ gr_clear_learn_entries();
54112+
54113+ read_lock(&tasklist_lock);
54114+ do_each_thread(task2, task) {
54115+ task->acl_sp_role = 0;
54116+ task->acl_role_id = 0;
54117+ task->acl = NULL;
54118+ task->role = NULL;
54119+ } while_each_thread(task2, task);
54120+ read_unlock(&tasklist_lock);
54121+
54122+ /* release the reference to the real root dentry and vfsmount */
54123+ path_put(&real_root);
54124+ memset(&real_root, 0, sizeof(real_root));
54125+
54126+ /* free all object hash tables */
54127+
54128+ FOR_EACH_ROLE_START(r)
54129+ if (r->subj_hash == NULL)
54130+ goto next_role;
54131+ FOR_EACH_SUBJECT_START(r, s, x)
54132+ if (s->obj_hash == NULL)
54133+ break;
54134+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
54135+ kfree(s->obj_hash);
54136+ else
54137+ vfree(s->obj_hash);
54138+ FOR_EACH_SUBJECT_END(s, x)
54139+ FOR_EACH_NESTED_SUBJECT_START(r, s)
54140+ if (s->obj_hash == NULL)
54141+ break;
54142+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
54143+ kfree(s->obj_hash);
54144+ else
54145+ vfree(s->obj_hash);
54146+ FOR_EACH_NESTED_SUBJECT_END(s)
54147+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
54148+ kfree(r->subj_hash);
54149+ else
54150+ vfree(r->subj_hash);
54151+ r->subj_hash = NULL;
54152+next_role:
54153+ FOR_EACH_ROLE_END(r)
54154+
54155+ acl_free_all();
54156+
54157+ if (acl_role_set.r_hash) {
54158+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
54159+ PAGE_SIZE)
54160+ kfree(acl_role_set.r_hash);
54161+ else
54162+ vfree(acl_role_set.r_hash);
54163+ }
54164+ if (name_set.n_hash) {
54165+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
54166+ PAGE_SIZE)
54167+ kfree(name_set.n_hash);
54168+ else
54169+ vfree(name_set.n_hash);
54170+ }
54171+
54172+ if (inodev_set.i_hash) {
54173+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
54174+ PAGE_SIZE)
54175+ kfree(inodev_set.i_hash);
54176+ else
54177+ vfree(inodev_set.i_hash);
54178+ }
54179+
54180+ gr_free_uidset();
54181+
54182+ memset(&name_set, 0, sizeof (struct name_db));
54183+ memset(&inodev_set, 0, sizeof (struct inodev_db));
54184+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
54185+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
54186+
54187+ default_role = NULL;
54188+ kernel_role = NULL;
54189+ role_list = NULL;
54190+
54191+ return;
54192+}
54193+
54194+static __u32
54195+count_user_objs(struct acl_object_label *userp)
54196+{
54197+ struct acl_object_label o_tmp;
54198+ __u32 num = 0;
54199+
54200+ while (userp) {
54201+ if (copy_from_user(&o_tmp, userp,
54202+ sizeof (struct acl_object_label)))
54203+ break;
54204+
54205+ userp = o_tmp.prev;
54206+ num++;
54207+ }
54208+
54209+ return num;
54210+}
54211+
54212+static struct acl_subject_label *
54213+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
54214+
54215+static int
54216+copy_user_glob(struct acl_object_label *obj)
54217+{
54218+ struct acl_object_label *g_tmp, **guser;
54219+ unsigned int len;
54220+ char *tmp;
54221+
54222+ if (obj->globbed == NULL)
54223+ return 0;
54224+
54225+ guser = &obj->globbed;
54226+ while (*guser) {
54227+ g_tmp = (struct acl_object_label *)
54228+ acl_alloc(sizeof (struct acl_object_label));
54229+ if (g_tmp == NULL)
54230+ return -ENOMEM;
54231+
54232+ if (copy_from_user(g_tmp, *guser,
54233+ sizeof (struct acl_object_label)))
54234+ return -EFAULT;
54235+
54236+ len = strnlen_user(g_tmp->filename, PATH_MAX);
54237+
54238+ if (!len || len >= PATH_MAX)
54239+ return -EINVAL;
54240+
54241+ if ((tmp = (char *) acl_alloc(len)) == NULL)
54242+ return -ENOMEM;
54243+
54244+ if (copy_from_user(tmp, g_tmp->filename, len))
54245+ return -EFAULT;
54246+ tmp[len-1] = '\0';
54247+ g_tmp->filename = tmp;
54248+
54249+ *guser = g_tmp;
54250+ guser = &(g_tmp->next);
54251+ }
54252+
54253+ return 0;
54254+}
54255+
54256+static int
54257+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
54258+ struct acl_role_label *role)
54259+{
54260+ struct acl_object_label *o_tmp;
54261+ unsigned int len;
54262+ int ret;
54263+ char *tmp;
54264+
54265+ while (userp) {
54266+ if ((o_tmp = (struct acl_object_label *)
54267+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
54268+ return -ENOMEM;
54269+
54270+ if (copy_from_user(o_tmp, userp,
54271+ sizeof (struct acl_object_label)))
54272+ return -EFAULT;
54273+
54274+ userp = o_tmp->prev;
54275+
54276+ len = strnlen_user(o_tmp->filename, PATH_MAX);
54277+
54278+ if (!len || len >= PATH_MAX)
54279+ return -EINVAL;
54280+
54281+ if ((tmp = (char *) acl_alloc(len)) == NULL)
54282+ return -ENOMEM;
54283+
54284+ if (copy_from_user(tmp, o_tmp->filename, len))
54285+ return -EFAULT;
54286+ tmp[len-1] = '\0';
54287+ o_tmp->filename = tmp;
54288+
54289+ insert_acl_obj_label(o_tmp, subj);
54290+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
54291+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
54292+ return -ENOMEM;
54293+
54294+ ret = copy_user_glob(o_tmp);
54295+ if (ret)
54296+ return ret;
54297+
54298+ if (o_tmp->nested) {
54299+ int already_copied;
54300+
54301+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
54302+ if (IS_ERR(o_tmp->nested))
54303+ return PTR_ERR(o_tmp->nested);
54304+
54305+ /* insert into nested subject list if we haven't copied this one yet
54306+ to prevent duplicate entries */
54307+ if (!already_copied) {
54308+ o_tmp->nested->next = role->hash->first;
54309+ role->hash->first = o_tmp->nested;
54310+ }
54311+ }
54312+ }
54313+
54314+ return 0;
54315+}
54316+
54317+static __u32
54318+count_user_subjs(struct acl_subject_label *userp)
54319+{
54320+ struct acl_subject_label s_tmp;
54321+ __u32 num = 0;
54322+
54323+ while (userp) {
54324+ if (copy_from_user(&s_tmp, userp,
54325+ sizeof (struct acl_subject_label)))
54326+ break;
54327+
54328+ userp = s_tmp.prev;
54329+ }
54330+
54331+ return num;
54332+}
54333+
54334+static int
54335+copy_user_allowedips(struct acl_role_label *rolep)
54336+{
54337+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
54338+
54339+ ruserip = rolep->allowed_ips;
54340+
54341+ while (ruserip) {
54342+ rlast = rtmp;
54343+
54344+ if ((rtmp = (struct role_allowed_ip *)
54345+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
54346+ return -ENOMEM;
54347+
54348+ if (copy_from_user(rtmp, ruserip,
54349+ sizeof (struct role_allowed_ip)))
54350+ return -EFAULT;
54351+
54352+ ruserip = rtmp->prev;
54353+
54354+ if (!rlast) {
54355+ rtmp->prev = NULL;
54356+ rolep->allowed_ips = rtmp;
54357+ } else {
54358+ rlast->next = rtmp;
54359+ rtmp->prev = rlast;
54360+ }
54361+
54362+ if (!ruserip)
54363+ rtmp->next = NULL;
54364+ }
54365+
54366+ return 0;
54367+}
54368+
54369+static int
54370+copy_user_transitions(struct acl_role_label *rolep)
54371+{
54372+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
54373+
54374+ unsigned int len;
54375+ char *tmp;
54376+
54377+ rusertp = rolep->transitions;
54378+
54379+ while (rusertp) {
54380+ rlast = rtmp;
54381+
54382+ if ((rtmp = (struct role_transition *)
54383+ acl_alloc(sizeof (struct role_transition))) == NULL)
54384+ return -ENOMEM;
54385+
54386+ if (copy_from_user(rtmp, rusertp,
54387+ sizeof (struct role_transition)))
54388+ return -EFAULT;
54389+
54390+ rusertp = rtmp->prev;
54391+
54392+ len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
54393+
54394+ if (!len || len >= GR_SPROLE_LEN)
54395+ return -EINVAL;
54396+
54397+ if ((tmp = (char *) acl_alloc(len)) == NULL)
54398+ return -ENOMEM;
54399+
54400+ if (copy_from_user(tmp, rtmp->rolename, len))
54401+ return -EFAULT;
54402+ tmp[len-1] = '\0';
54403+ rtmp->rolename = tmp;
54404+
54405+ if (!rlast) {
54406+ rtmp->prev = NULL;
54407+ rolep->transitions = rtmp;
54408+ } else {
54409+ rlast->next = rtmp;
54410+ rtmp->prev = rlast;
54411+ }
54412+
54413+ if (!rusertp)
54414+ rtmp->next = NULL;
54415+ }
54416+
54417+ return 0;
54418+}
54419+
54420+static struct acl_subject_label *
54421+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
54422+{
54423+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
54424+ unsigned int len;
54425+ char *tmp;
54426+ __u32 num_objs;
54427+ struct acl_ip_label **i_tmp, *i_utmp2;
54428+ struct gr_hash_struct ghash;
54429+ struct subject_map *subjmap;
54430+ unsigned int i_num;
54431+ int err;
54432+
54433+ if (already_copied != NULL)
54434+ *already_copied = 0;
54435+
54436+ s_tmp = lookup_subject_map(userp);
54437+
54438+ /* we've already copied this subject into the kernel, just return
54439+ the reference to it, and don't copy it over again
54440+ */
54441+ if (s_tmp) {
54442+ if (already_copied != NULL)
54443+ *already_copied = 1;
54444+ return(s_tmp);
54445+ }
54446+
54447+ if ((s_tmp = (struct acl_subject_label *)
54448+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
54449+ return ERR_PTR(-ENOMEM);
54450+
54451+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
54452+ if (subjmap == NULL)
54453+ return ERR_PTR(-ENOMEM);
54454+
54455+ subjmap->user = userp;
54456+ subjmap->kernel = s_tmp;
54457+ insert_subj_map_entry(subjmap);
54458+
54459+ if (copy_from_user(s_tmp, userp,
54460+ sizeof (struct acl_subject_label)))
54461+ return ERR_PTR(-EFAULT);
54462+
54463+ len = strnlen_user(s_tmp->filename, PATH_MAX);
54464+
54465+ if (!len || len >= PATH_MAX)
54466+ return ERR_PTR(-EINVAL);
54467+
54468+ if ((tmp = (char *) acl_alloc(len)) == NULL)
54469+ return ERR_PTR(-ENOMEM);
54470+
54471+ if (copy_from_user(tmp, s_tmp->filename, len))
54472+ return ERR_PTR(-EFAULT);
54473+ tmp[len-1] = '\0';
54474+ s_tmp->filename = tmp;
54475+
54476+ if (!strcmp(s_tmp->filename, "/"))
54477+ role->root_label = s_tmp;
54478+
54479+ if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
54480+ return ERR_PTR(-EFAULT);
54481+
54482+ /* copy user and group transition tables */
54483+
54484+ if (s_tmp->user_trans_num) {
54485+ uid_t *uidlist;
54486+
54487+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
54488+ if (uidlist == NULL)
54489+ return ERR_PTR(-ENOMEM);
54490+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
54491+ return ERR_PTR(-EFAULT);
54492+
54493+ s_tmp->user_transitions = uidlist;
54494+ }
54495+
54496+ if (s_tmp->group_trans_num) {
54497+ gid_t *gidlist;
54498+
54499+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
54500+ if (gidlist == NULL)
54501+ return ERR_PTR(-ENOMEM);
54502+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
54503+ return ERR_PTR(-EFAULT);
54504+
54505+ s_tmp->group_transitions = gidlist;
54506+ }
54507+
54508+ /* set up object hash table */
54509+ num_objs = count_user_objs(ghash.first);
54510+
54511+ s_tmp->obj_hash_size = num_objs;
54512+ s_tmp->obj_hash =
54513+ (struct acl_object_label **)
54514+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
54515+
54516+ if (!s_tmp->obj_hash)
54517+ return ERR_PTR(-ENOMEM);
54518+
54519+ memset(s_tmp->obj_hash, 0,
54520+ s_tmp->obj_hash_size *
54521+ sizeof (struct acl_object_label *));
54522+
54523+ /* add in objects */
54524+ err = copy_user_objs(ghash.first, s_tmp, role);
54525+
54526+ if (err)
54527+ return ERR_PTR(err);
54528+
54529+ /* set pointer for parent subject */
54530+ if (s_tmp->parent_subject) {
54531+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
54532+
54533+ if (IS_ERR(s_tmp2))
54534+ return s_tmp2;
54535+
54536+ s_tmp->parent_subject = s_tmp2;
54537+ }
54538+
54539+ /* add in ip acls */
54540+
54541+ if (!s_tmp->ip_num) {
54542+ s_tmp->ips = NULL;
54543+ goto insert;
54544+ }
54545+
54546+ i_tmp =
54547+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
54548+ sizeof (struct acl_ip_label *));
54549+
54550+ if (!i_tmp)
54551+ return ERR_PTR(-ENOMEM);
54552+
54553+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
54554+ *(i_tmp + i_num) =
54555+ (struct acl_ip_label *)
54556+ acl_alloc(sizeof (struct acl_ip_label));
54557+ if (!*(i_tmp + i_num))
54558+ return ERR_PTR(-ENOMEM);
54559+
54560+ if (copy_from_user
54561+ (&i_utmp2, s_tmp->ips + i_num,
54562+ sizeof (struct acl_ip_label *)))
54563+ return ERR_PTR(-EFAULT);
54564+
54565+ if (copy_from_user
54566+ (*(i_tmp + i_num), i_utmp2,
54567+ sizeof (struct acl_ip_label)))
54568+ return ERR_PTR(-EFAULT);
54569+
54570+ if ((*(i_tmp + i_num))->iface == NULL)
54571+ continue;
54572+
54573+ len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
54574+ if (!len || len >= IFNAMSIZ)
54575+ return ERR_PTR(-EINVAL);
54576+ tmp = acl_alloc(len);
54577+ if (tmp == NULL)
54578+ return ERR_PTR(-ENOMEM);
54579+ if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
54580+ return ERR_PTR(-EFAULT);
54581+ (*(i_tmp + i_num))->iface = tmp;
54582+ }
54583+
54584+ s_tmp->ips = i_tmp;
54585+
54586+insert:
54587+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
54588+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
54589+ return ERR_PTR(-ENOMEM);
54590+
54591+ return s_tmp;
54592+}
54593+
54594+static int
54595+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
54596+{
54597+ struct acl_subject_label s_pre;
54598+ struct acl_subject_label * ret;
54599+ int err;
54600+
54601+ while (userp) {
54602+ if (copy_from_user(&s_pre, userp,
54603+ sizeof (struct acl_subject_label)))
54604+ return -EFAULT;
54605+
54606+ ret = do_copy_user_subj(userp, role, NULL);
54607+
54608+ err = PTR_ERR(ret);
54609+ if (IS_ERR(ret))
54610+ return err;
54611+
54612+ insert_acl_subj_label(ret, role);
54613+
54614+ userp = s_pre.prev;
54615+ }
54616+
54617+ return 0;
54618+}
54619+
54620+static int
54621+copy_user_acl(struct gr_arg *arg)
54622+{
54623+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
54624+ struct acl_subject_label *subj_list;
54625+ struct sprole_pw *sptmp;
54626+ struct gr_hash_struct *ghash;
54627+ uid_t *domainlist;
54628+ unsigned int r_num;
54629+ unsigned int len;
54630+ char *tmp;
54631+ int err = 0;
54632+ __u16 i;
54633+ __u32 num_subjs;
54634+
54635+ /* we need a default and kernel role */
54636+ if (arg->role_db.num_roles < 2)
54637+ return -EINVAL;
54638+
54639+ /* copy special role authentication info from userspace */
54640+
54641+ num_sprole_pws = arg->num_sprole_pws;
54642+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
54643+
54644+ if (!acl_special_roles && num_sprole_pws)
54645+ return -ENOMEM;
54646+
54647+ for (i = 0; i < num_sprole_pws; i++) {
54648+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
54649+ if (!sptmp)
54650+ return -ENOMEM;
54651+ if (copy_from_user(sptmp, arg->sprole_pws + i,
54652+ sizeof (struct sprole_pw)))
54653+ return -EFAULT;
54654+
54655+ len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
54656+
54657+ if (!len || len >= GR_SPROLE_LEN)
54658+ return -EINVAL;
54659+
54660+ if ((tmp = (char *) acl_alloc(len)) == NULL)
54661+ return -ENOMEM;
54662+
54663+ if (copy_from_user(tmp, sptmp->rolename, len))
54664+ return -EFAULT;
54665+
54666+ tmp[len-1] = '\0';
54667+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54668+ printk(KERN_ALERT "Copying special role %s\n", tmp);
54669+#endif
54670+ sptmp->rolename = tmp;
54671+ acl_special_roles[i] = sptmp;
54672+ }
54673+
54674+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
54675+
54676+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
54677+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
54678+
54679+ if (!r_tmp)
54680+ return -ENOMEM;
54681+
54682+ if (copy_from_user(&r_utmp2, r_utmp + r_num,
54683+ sizeof (struct acl_role_label *)))
54684+ return -EFAULT;
54685+
54686+ if (copy_from_user(r_tmp, r_utmp2,
54687+ sizeof (struct acl_role_label)))
54688+ return -EFAULT;
54689+
54690+ len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
54691+
54692+ if (!len || len >= PATH_MAX)
54693+ return -EINVAL;
54694+
54695+ if ((tmp = (char *) acl_alloc(len)) == NULL)
54696+ return -ENOMEM;
54697+
54698+ if (copy_from_user(tmp, r_tmp->rolename, len))
54699+ return -EFAULT;
54700+
54701+ tmp[len-1] = '\0';
54702+ r_tmp->rolename = tmp;
54703+
54704+ if (!strcmp(r_tmp->rolename, "default")
54705+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
54706+ default_role = r_tmp;
54707+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
54708+ kernel_role = r_tmp;
54709+ }
54710+
54711+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
54712+ return -ENOMEM;
54713+
54714+ if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
54715+ return -EFAULT;
54716+
54717+ r_tmp->hash = ghash;
54718+
54719+ num_subjs = count_user_subjs(r_tmp->hash->first);
54720+
54721+ r_tmp->subj_hash_size = num_subjs;
54722+ r_tmp->subj_hash =
54723+ (struct acl_subject_label **)
54724+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
54725+
54726+ if (!r_tmp->subj_hash)
54727+ return -ENOMEM;
54728+
54729+ err = copy_user_allowedips(r_tmp);
54730+ if (err)
54731+ return err;
54732+
54733+ /* copy domain info */
54734+ if (r_tmp->domain_children != NULL) {
54735+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
54736+ if (domainlist == NULL)
54737+ return -ENOMEM;
54738+
54739+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
54740+ return -EFAULT;
54741+
54742+ r_tmp->domain_children = domainlist;
54743+ }
54744+
54745+ err = copy_user_transitions(r_tmp);
54746+ if (err)
54747+ return err;
54748+
54749+ memset(r_tmp->subj_hash, 0,
54750+ r_tmp->subj_hash_size *
54751+ sizeof (struct acl_subject_label *));
54752+
54753+ /* acquire the list of subjects, then NULL out
54754+ the list prior to parsing the subjects for this role,
54755+ as during this parsing the list is replaced with a list
54756+ of *nested* subjects for the role
54757+ */
54758+ subj_list = r_tmp->hash->first;
54759+
54760+ /* set nested subject list to null */
54761+ r_tmp->hash->first = NULL;
54762+
54763+ err = copy_user_subjs(subj_list, r_tmp);
54764+
54765+ if (err)
54766+ return err;
54767+
54768+ insert_acl_role_label(r_tmp);
54769+ }
54770+
54771+ if (default_role == NULL || kernel_role == NULL)
54772+ return -EINVAL;
54773+
54774+ return err;
54775+}
54776+
54777+static int
54778+gracl_init(struct gr_arg *args)
54779+{
54780+ int error = 0;
54781+
54782+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
54783+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
54784+
54785+ if (init_variables(args)) {
54786+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
54787+ error = -ENOMEM;
54788+ free_variables();
54789+ goto out;
54790+ }
54791+
54792+ error = copy_user_acl(args);
54793+ free_init_variables();
54794+ if (error) {
54795+ free_variables();
54796+ goto out;
54797+ }
54798+
54799+ if ((error = gr_set_acls(0))) {
54800+ free_variables();
54801+ goto out;
54802+ }
54803+
54804+ pax_open_kernel();
54805+ gr_status |= GR_READY;
54806+ pax_close_kernel();
54807+
54808+ out:
54809+ return error;
54810+}
54811+
54812+/* derived from glibc fnmatch() 0: match, 1: no match*/
54813+
54814+static int
54815+glob_match(const char *p, const char *n)
54816+{
54817+ char c;
54818+
54819+ while ((c = *p++) != '\0') {
54820+ switch (c) {
54821+ case '?':
54822+ if (*n == '\0')
54823+ return 1;
54824+ else if (*n == '/')
54825+ return 1;
54826+ break;
54827+ case '\\':
54828+ if (*n != c)
54829+ return 1;
54830+ break;
54831+ case '*':
54832+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
54833+ if (*n == '/')
54834+ return 1;
54835+ else if (c == '?') {
54836+ if (*n == '\0')
54837+ return 1;
54838+ else
54839+ ++n;
54840+ }
54841+ }
54842+ if (c == '\0') {
54843+ return 0;
54844+ } else {
54845+ const char *endp;
54846+
54847+ if ((endp = strchr(n, '/')) == NULL)
54848+ endp = n + strlen(n);
54849+
54850+ if (c == '[') {
54851+ for (--p; n < endp; ++n)
54852+ if (!glob_match(p, n))
54853+ return 0;
54854+ } else if (c == '/') {
54855+ while (*n != '\0' && *n != '/')
54856+ ++n;
54857+ if (*n == '/' && !glob_match(p, n + 1))
54858+ return 0;
54859+ } else {
54860+ for (--p; n < endp; ++n)
54861+ if (*n == c && !glob_match(p, n))
54862+ return 0;
54863+ }
54864+
54865+ return 1;
54866+ }
54867+ case '[':
54868+ {
54869+ int not;
54870+ char cold;
54871+
54872+ if (*n == '\0' || *n == '/')
54873+ return 1;
54874+
54875+ not = (*p == '!' || *p == '^');
54876+ if (not)
54877+ ++p;
54878+
54879+ c = *p++;
54880+ for (;;) {
54881+ unsigned char fn = (unsigned char)*n;
54882+
54883+ if (c == '\0')
54884+ return 1;
54885+ else {
54886+ if (c == fn)
54887+ goto matched;
54888+ cold = c;
54889+ c = *p++;
54890+
54891+ if (c == '-' && *p != ']') {
54892+ unsigned char cend = *p++;
54893+
54894+ if (cend == '\0')
54895+ return 1;
54896+
54897+ if (cold <= fn && fn <= cend)
54898+ goto matched;
54899+
54900+ c = *p++;
54901+ }
54902+ }
54903+
54904+ if (c == ']')
54905+ break;
54906+ }
54907+ if (!not)
54908+ return 1;
54909+ break;
54910+ matched:
54911+ while (c != ']') {
54912+ if (c == '\0')
54913+ return 1;
54914+
54915+ c = *p++;
54916+ }
54917+ if (not)
54918+ return 1;
54919+ }
54920+ break;
54921+ default:
54922+ if (c != *n)
54923+ return 1;
54924+ }
54925+
54926+ ++n;
54927+ }
54928+
54929+ if (*n == '\0')
54930+ return 0;
54931+
54932+ if (*n == '/')
54933+ return 0;
54934+
54935+ return 1;
54936+}
54937+
54938+static struct acl_object_label *
54939+chk_glob_label(struct acl_object_label *globbed,
54940+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
54941+{
54942+ struct acl_object_label *tmp;
54943+
54944+ if (*path == NULL)
54945+ *path = gr_to_filename_nolock(dentry, mnt);
54946+
54947+ tmp = globbed;
54948+
54949+ while (tmp) {
54950+ if (!glob_match(tmp->filename, *path))
54951+ return tmp;
54952+ tmp = tmp->next;
54953+ }
54954+
54955+ return NULL;
54956+}
54957+
54958+static struct acl_object_label *
54959+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
54960+ const ino_t curr_ino, const dev_t curr_dev,
54961+ const struct acl_subject_label *subj, char **path, const int checkglob)
54962+{
54963+ struct acl_subject_label *tmpsubj;
54964+ struct acl_object_label *retval;
54965+ struct acl_object_label *retval2;
54966+
54967+ tmpsubj = (struct acl_subject_label *) subj;
54968+ read_lock(&gr_inode_lock);
54969+ do {
54970+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
54971+ if (retval) {
54972+ if (checkglob && retval->globbed) {
54973+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
54974+ if (retval2)
54975+ retval = retval2;
54976+ }
54977+ break;
54978+ }
54979+ } while ((tmpsubj = tmpsubj->parent_subject));
54980+ read_unlock(&gr_inode_lock);
54981+
54982+ return retval;
54983+}
54984+
54985+static __inline__ struct acl_object_label *
54986+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
54987+ struct dentry *curr_dentry,
54988+ const struct acl_subject_label *subj, char **path, const int checkglob)
54989+{
54990+ int newglob = checkglob;
54991+ ino_t inode;
54992+ dev_t device;
54993+
54994+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
54995+ as we don't want a / * rule to match instead of the / object
54996+ don't do this for create lookups that call this function though, since they're looking up
54997+ on the parent and thus need globbing checks on all paths
54998+ */
54999+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
55000+ newglob = GR_NO_GLOB;
55001+
55002+ spin_lock(&curr_dentry->d_lock);
55003+ inode = curr_dentry->d_inode->i_ino;
55004+ device = __get_dev(curr_dentry);
55005+ spin_unlock(&curr_dentry->d_lock);
55006+
55007+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
55008+}
55009+
55010+static struct acl_object_label *
55011+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
55012+ const struct acl_subject_label *subj, char *path, const int checkglob)
55013+{
55014+ struct dentry *dentry = (struct dentry *) l_dentry;
55015+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
55016+ struct mount *real_mnt = real_mount(mnt);
55017+ struct acl_object_label *retval;
55018+ struct dentry *parent;
55019+
55020+ write_seqlock(&rename_lock);
55021+ br_read_lock(&vfsmount_lock);
55022+
55023+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
55024+#ifdef CONFIG_NET
55025+ mnt == sock_mnt ||
55026+#endif
55027+#ifdef CONFIG_HUGETLBFS
55028+ (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
55029+#endif
55030+ /* ignore Eric Biederman */
55031+ IS_PRIVATE(l_dentry->d_inode))) {
55032+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
55033+ goto out;
55034+ }
55035+
55036+ for (;;) {
55037+ if (dentry == real_root.dentry && mnt == real_root.mnt)
55038+ break;
55039+
55040+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
55041+ if (!mnt_has_parent(real_mnt))
55042+ break;
55043+
55044+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
55045+ if (retval != NULL)
55046+ goto out;
55047+
55048+ dentry = real_mnt->mnt_mountpoint;
55049+ real_mnt = real_mnt->mnt_parent;
55050+ mnt = &real_mnt->mnt;
55051+ continue;
55052+ }
55053+
55054+ parent = dentry->d_parent;
55055+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
55056+ if (retval != NULL)
55057+ goto out;
55058+
55059+ dentry = parent;
55060+ }
55061+
55062+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
55063+
55064+ /* real_root is pinned so we don't have to hold a reference */
55065+ if (retval == NULL)
55066+ retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
55067+out:
55068+ br_read_unlock(&vfsmount_lock);
55069+ write_sequnlock(&rename_lock);
55070+
55071+ BUG_ON(retval == NULL);
55072+
55073+ return retval;
55074+}
55075+
55076+static __inline__ struct acl_object_label *
55077+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
55078+ const struct acl_subject_label *subj)
55079+{
55080+ char *path = NULL;
55081+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
55082+}
55083+
55084+static __inline__ struct acl_object_label *
55085+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
55086+ const struct acl_subject_label *subj)
55087+{
55088+ char *path = NULL;
55089+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
55090+}
55091+
55092+static __inline__ struct acl_object_label *
55093+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
55094+ const struct acl_subject_label *subj, char *path)
55095+{
55096+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
55097+}
55098+
55099+static struct acl_subject_label *
55100+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
55101+ const struct acl_role_label *role)
55102+{
55103+ struct dentry *dentry = (struct dentry *) l_dentry;
55104+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
55105+ struct mount *real_mnt = real_mount(mnt);
55106+ struct acl_subject_label *retval;
55107+ struct dentry *parent;
55108+
55109+ write_seqlock(&rename_lock);
55110+ br_read_lock(&vfsmount_lock);
55111+
55112+ for (;;) {
55113+ if (dentry == real_root.dentry && mnt == real_root.mnt)
55114+ break;
55115+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
55116+ if (!mnt_has_parent(real_mnt))
55117+ break;
55118+
55119+ spin_lock(&dentry->d_lock);
55120+ read_lock(&gr_inode_lock);
55121+ retval =
55122+ lookup_acl_subj_label(dentry->d_inode->i_ino,
55123+ __get_dev(dentry), role);
55124+ read_unlock(&gr_inode_lock);
55125+ spin_unlock(&dentry->d_lock);
55126+ if (retval != NULL)
55127+ goto out;
55128+
55129+ dentry = real_mnt->mnt_mountpoint;
55130+ real_mnt = real_mnt->mnt_parent;
55131+ mnt = &real_mnt->mnt;
55132+ continue;
55133+ }
55134+
55135+ spin_lock(&dentry->d_lock);
55136+ read_lock(&gr_inode_lock);
55137+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
55138+ __get_dev(dentry), role);
55139+ read_unlock(&gr_inode_lock);
55140+ parent = dentry->d_parent;
55141+ spin_unlock(&dentry->d_lock);
55142+
55143+ if (retval != NULL)
55144+ goto out;
55145+
55146+ dentry = parent;
55147+ }
55148+
55149+ spin_lock(&dentry->d_lock);
55150+ read_lock(&gr_inode_lock);
55151+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
55152+ __get_dev(dentry), role);
55153+ read_unlock(&gr_inode_lock);
55154+ spin_unlock(&dentry->d_lock);
55155+
55156+ if (unlikely(retval == NULL)) {
55157+ /* real_root is pinned, we don't need to hold a reference */
55158+ read_lock(&gr_inode_lock);
55159+ retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
55160+ __get_dev(real_root.dentry), role);
55161+ read_unlock(&gr_inode_lock);
55162+ }
55163+out:
55164+ br_read_unlock(&vfsmount_lock);
55165+ write_sequnlock(&rename_lock);
55166+
55167+ BUG_ON(retval == NULL);
55168+
55169+ return retval;
55170+}
55171+
55172+static void
55173+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
55174+{
55175+ struct task_struct *task = current;
55176+ const struct cred *cred = current_cred();
55177+
55178+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
55179+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
55180+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
55181+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
55182+
55183+ return;
55184+}
55185+
55186+static void
55187+gr_log_learn_id_change(const char type, const unsigned int real,
55188+ const unsigned int effective, const unsigned int fs)
55189+{
55190+ struct task_struct *task = current;
55191+ const struct cred *cred = current_cred();
55192+
55193+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
55194+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
55195+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
55196+ type, real, effective, fs, &task->signal->saved_ip);
55197+
55198+ return;
55199+}
55200+
55201+__u32
55202+gr_search_file(const struct dentry * dentry, const __u32 mode,
55203+ const struct vfsmount * mnt)
55204+{
55205+ __u32 retval = mode;
55206+ struct acl_subject_label *curracl;
55207+ struct acl_object_label *currobj;
55208+
55209+ if (unlikely(!(gr_status & GR_READY)))
55210+ return (mode & ~GR_AUDITS);
55211+
55212+ curracl = current->acl;
55213+
55214+ currobj = chk_obj_label(dentry, mnt, curracl);
55215+ retval = currobj->mode & mode;
55216+
55217+ /* if we're opening a specified transfer file for writing
55218+ (e.g. /dev/initctl), then transfer our role to init
55219+ */
55220+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
55221+ current->role->roletype & GR_ROLE_PERSIST)) {
55222+ struct task_struct *task = init_pid_ns.child_reaper;
55223+
55224+ if (task->role != current->role) {
55225+ task->acl_sp_role = 0;
55226+ task->acl_role_id = current->acl_role_id;
55227+ task->role = current->role;
55228+ rcu_read_lock();
55229+ read_lock(&grsec_exec_file_lock);
55230+ gr_apply_subject_to_task(task);
55231+ read_unlock(&grsec_exec_file_lock);
55232+ rcu_read_unlock();
55233+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
55234+ }
55235+ }
55236+
55237+ if (unlikely
55238+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
55239+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
55240+ __u32 new_mode = mode;
55241+
55242+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
55243+
55244+ retval = new_mode;
55245+
55246+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
55247+ new_mode |= GR_INHERIT;
55248+
55249+ if (!(mode & GR_NOLEARN))
55250+ gr_log_learn(dentry, mnt, new_mode);
55251+ }
55252+
55253+ return retval;
55254+}
55255+
55256+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
55257+ const struct dentry *parent,
55258+ const struct vfsmount *mnt)
55259+{
55260+ struct name_entry *match;
55261+ struct acl_object_label *matchpo;
55262+ struct acl_subject_label *curracl;
55263+ char *path;
55264+
55265+ if (unlikely(!(gr_status & GR_READY)))
55266+ return NULL;
55267+
55268+ preempt_disable();
55269+ path = gr_to_filename_rbac(new_dentry, mnt);
55270+ match = lookup_name_entry_create(path);
55271+
55272+ curracl = current->acl;
55273+
55274+ if (match) {
55275+ read_lock(&gr_inode_lock);
55276+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
55277+ read_unlock(&gr_inode_lock);
55278+
55279+ if (matchpo) {
55280+ preempt_enable();
55281+ return matchpo;
55282+ }
55283+ }
55284+
55285+ // lookup parent
55286+
55287+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
55288+
55289+ preempt_enable();
55290+ return matchpo;
55291+}
55292+
55293+__u32
55294+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
55295+ const struct vfsmount * mnt, const __u32 mode)
55296+{
55297+ struct acl_object_label *matchpo;
55298+ __u32 retval;
55299+
55300+ if (unlikely(!(gr_status & GR_READY)))
55301+ return (mode & ~GR_AUDITS);
55302+
55303+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
55304+
55305+ retval = matchpo->mode & mode;
55306+
55307+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
55308+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
55309+ __u32 new_mode = mode;
55310+
55311+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
55312+
55313+ gr_log_learn(new_dentry, mnt, new_mode);
55314+ return new_mode;
55315+ }
55316+
55317+ return retval;
55318+}
55319+
55320+__u32
55321+gr_check_link(const struct dentry * new_dentry,
55322+ const struct dentry * parent_dentry,
55323+ const struct vfsmount * parent_mnt,
55324+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
55325+{
55326+ struct acl_object_label *obj;
55327+ __u32 oldmode, newmode;
55328+ __u32 needmode;
55329+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
55330+ GR_DELETE | GR_INHERIT;
55331+
55332+ if (unlikely(!(gr_status & GR_READY)))
55333+ return (GR_CREATE | GR_LINK);
55334+
55335+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
55336+ oldmode = obj->mode;
55337+
55338+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
55339+ newmode = obj->mode;
55340+
55341+ needmode = newmode & checkmodes;
55342+
55343+ // old name for hardlink must have at least the permissions of the new name
55344+ if ((oldmode & needmode) != needmode)
55345+ goto bad;
55346+
55347+ // if old name had restrictions/auditing, make sure the new name does as well
55348+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
55349+
55350+ // don't allow hardlinking of suid/sgid/fcapped files without permission
55351+ if (is_privileged_binary(old_dentry))
55352+ needmode |= GR_SETID;
55353+
55354+ if ((newmode & needmode) != needmode)
55355+ goto bad;
55356+
55357+ // enforce minimum permissions
55358+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
55359+ return newmode;
55360+bad:
55361+ needmode = oldmode;
55362+ if (is_privileged_binary(old_dentry))
55363+ needmode |= GR_SETID;
55364+
55365+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
55366+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
55367+ return (GR_CREATE | GR_LINK);
55368+ } else if (newmode & GR_SUPPRESS)
55369+ return GR_SUPPRESS;
55370+ else
55371+ return 0;
55372+}
55373+
55374+int
55375+gr_check_hidden_task(const struct task_struct *task)
55376+{
55377+ if (unlikely(!(gr_status & GR_READY)))
55378+ return 0;
55379+
55380+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
55381+ return 1;
55382+
55383+ return 0;
55384+}
55385+
55386+int
55387+gr_check_protected_task(const struct task_struct *task)
55388+{
55389+ if (unlikely(!(gr_status & GR_READY) || !task))
55390+ return 0;
55391+
55392+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
55393+ task->acl != current->acl)
55394+ return 1;
55395+
55396+ return 0;
55397+}
55398+
55399+int
55400+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
55401+{
55402+ struct task_struct *p;
55403+ int ret = 0;
55404+
55405+ if (unlikely(!(gr_status & GR_READY) || !pid))
55406+ return ret;
55407+
55408+ read_lock(&tasklist_lock);
55409+ do_each_pid_task(pid, type, p) {
55410+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
55411+ p->acl != current->acl) {
55412+ ret = 1;
55413+ goto out;
55414+ }
55415+ } while_each_pid_task(pid, type, p);
55416+out:
55417+ read_unlock(&tasklist_lock);
55418+
55419+ return ret;
55420+}
55421+
55422+void
55423+gr_copy_label(struct task_struct *tsk)
55424+{
55425+ tsk->signal->used_accept = 0;
55426+ tsk->acl_sp_role = 0;
55427+ tsk->acl_role_id = current->acl_role_id;
55428+ tsk->acl = current->acl;
55429+ tsk->role = current->role;
55430+ tsk->signal->curr_ip = current->signal->curr_ip;
55431+ tsk->signal->saved_ip = current->signal->saved_ip;
55432+ if (current->exec_file)
55433+ get_file(current->exec_file);
55434+ tsk->exec_file = current->exec_file;
55435+ tsk->is_writable = current->is_writable;
55436+ if (unlikely(current->signal->used_accept)) {
55437+ current->signal->curr_ip = 0;
55438+ current->signal->saved_ip = 0;
55439+ }
55440+
55441+ return;
55442+}
55443+
55444+static void
55445+gr_set_proc_res(struct task_struct *task)
55446+{
55447+ struct acl_subject_label *proc;
55448+ unsigned short i;
55449+
55450+ proc = task->acl;
55451+
55452+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
55453+ return;
55454+
55455+ for (i = 0; i < RLIM_NLIMITS; i++) {
55456+ if (!(proc->resmask & (1 << i)))
55457+ continue;
55458+
55459+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
55460+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
55461+ }
55462+
55463+ return;
55464+}
55465+
55466+extern int __gr_process_user_ban(struct user_struct *user);
55467+
55468+int
55469+gr_check_user_change(int real, int effective, int fs)
55470+{
55471+ unsigned int i;
55472+ __u16 num;
55473+ uid_t *uidlist;
55474+ int curuid;
55475+ int realok = 0;
55476+ int effectiveok = 0;
55477+ int fsok = 0;
55478+
55479+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
55480+ struct user_struct *user;
55481+
55482+ if (real == -1)
55483+ goto skipit;
55484+
55485+ user = find_user(real);
55486+ if (user == NULL)
55487+ goto skipit;
55488+
55489+ if (__gr_process_user_ban(user)) {
55490+ /* for find_user */
55491+ free_uid(user);
55492+ return 1;
55493+ }
55494+
55495+ /* for find_user */
55496+ free_uid(user);
55497+
55498+skipit:
55499+#endif
55500+
55501+ if (unlikely(!(gr_status & GR_READY)))
55502+ return 0;
55503+
55504+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
55505+ gr_log_learn_id_change('u', real, effective, fs);
55506+
55507+ num = current->acl->user_trans_num;
55508+ uidlist = current->acl->user_transitions;
55509+
55510+ if (uidlist == NULL)
55511+ return 0;
55512+
55513+ if (real == -1)
55514+ realok = 1;
55515+ if (effective == -1)
55516+ effectiveok = 1;
55517+ if (fs == -1)
55518+ fsok = 1;
55519+
55520+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
55521+ for (i = 0; i < num; i++) {
55522+ curuid = (int)uidlist[i];
55523+ if (real == curuid)
55524+ realok = 1;
55525+ if (effective == curuid)
55526+ effectiveok = 1;
55527+ if (fs == curuid)
55528+ fsok = 1;
55529+ }
55530+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
55531+ for (i = 0; i < num; i++) {
55532+ curuid = (int)uidlist[i];
55533+ if (real == curuid)
55534+ break;
55535+ if (effective == curuid)
55536+ break;
55537+ if (fs == curuid)
55538+ break;
55539+ }
55540+ /* not in deny list */
55541+ if (i == num) {
55542+ realok = 1;
55543+ effectiveok = 1;
55544+ fsok = 1;
55545+ }
55546+ }
55547+
55548+ if (realok && effectiveok && fsok)
55549+ return 0;
55550+ else {
55551+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
55552+ return 1;
55553+ }
55554+}
55555+
55556+int
55557+gr_check_group_change(int real, int effective, int fs)
55558+{
55559+ unsigned int i;
55560+ __u16 num;
55561+ gid_t *gidlist;
55562+ int curgid;
55563+ int realok = 0;
55564+ int effectiveok = 0;
55565+ int fsok = 0;
55566+
55567+ if (unlikely(!(gr_status & GR_READY)))
55568+ return 0;
55569+
55570+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
55571+ gr_log_learn_id_change('g', real, effective, fs);
55572+
55573+ num = current->acl->group_trans_num;
55574+ gidlist = current->acl->group_transitions;
55575+
55576+ if (gidlist == NULL)
55577+ return 0;
55578+
55579+ if (real == -1)
55580+ realok = 1;
55581+ if (effective == -1)
55582+ effectiveok = 1;
55583+ if (fs == -1)
55584+ fsok = 1;
55585+
55586+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
55587+ for (i = 0; i < num; i++) {
55588+ curgid = (int)gidlist[i];
55589+ if (real == curgid)
55590+ realok = 1;
55591+ if (effective == curgid)
55592+ effectiveok = 1;
55593+ if (fs == curgid)
55594+ fsok = 1;
55595+ }
55596+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
55597+ for (i = 0; i < num; i++) {
55598+ curgid = (int)gidlist[i];
55599+ if (real == curgid)
55600+ break;
55601+ if (effective == curgid)
55602+ break;
55603+ if (fs == curgid)
55604+ break;
55605+ }
55606+ /* not in deny list */
55607+ if (i == num) {
55608+ realok = 1;
55609+ effectiveok = 1;
55610+ fsok = 1;
55611+ }
55612+ }
55613+
55614+ if (realok && effectiveok && fsok)
55615+ return 0;
55616+ else {
55617+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
55618+ return 1;
55619+ }
55620+}
55621+
55622+extern int gr_acl_is_capable(const int cap);
55623+
55624+void
55625+gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
55626+{
55627+ struct acl_role_label *role = task->role;
55628+ struct acl_subject_label *subj = NULL;
55629+ struct acl_object_label *obj;
55630+ struct file *filp;
55631+
55632+ if (unlikely(!(gr_status & GR_READY)))
55633+ return;
55634+
55635+ filp = task->exec_file;
55636+
55637+ /* kernel process, we'll give them the kernel role */
55638+ if (unlikely(!filp)) {
55639+ task->role = kernel_role;
55640+ task->acl = kernel_role->root_label;
55641+ return;
55642+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
55643+ role = lookup_acl_role_label(task, uid, gid);
55644+
55645+ /* don't change the role if we're not a privileged process */
55646+ if (role && task->role != role &&
55647+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
55648+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
55649+ return;
55650+
55651+ /* perform subject lookup in possibly new role
55652+ we can use this result below in the case where role == task->role
55653+ */
55654+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
55655+
55656+ /* if we changed uid/gid, but result in the same role
55657+ and are using inheritance, don't lose the inherited subject
55658+ if current subject is other than what normal lookup
55659+ would result in, we arrived via inheritance, don't
55660+ lose subject
55661+ */
55662+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
55663+ (subj == task->acl)))
55664+ task->acl = subj;
55665+
55666+ task->role = role;
55667+
55668+ task->is_writable = 0;
55669+
55670+ /* ignore additional mmap checks for processes that are writable
55671+ by the default ACL */
55672+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
55673+ if (unlikely(obj->mode & GR_WRITE))
55674+ task->is_writable = 1;
55675+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
55676+ if (unlikely(obj->mode & GR_WRITE))
55677+ task->is_writable = 1;
55678+
55679+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
55680+ printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
55681+#endif
55682+
55683+ gr_set_proc_res(task);
55684+
55685+ return;
55686+}
55687+
55688+int
55689+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
55690+ const int unsafe_flags)
55691+{
55692+ struct task_struct *task = current;
55693+ struct acl_subject_label *newacl;
55694+ struct acl_object_label *obj;
55695+ __u32 retmode;
55696+
55697+ if (unlikely(!(gr_status & GR_READY)))
55698+ return 0;
55699+
55700+ newacl = chk_subj_label(dentry, mnt, task->role);
55701+
55702+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
55703+ did an exec
55704+ */
55705+ rcu_read_lock();
55706+ read_lock(&tasklist_lock);
55707+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
55708+ (task->parent->acl->mode & GR_POVERRIDE))) {
55709+ read_unlock(&tasklist_lock);
55710+ rcu_read_unlock();
55711+ goto skip_check;
55712+ }
55713+ read_unlock(&tasklist_lock);
55714+ rcu_read_unlock();
55715+
55716+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
55717+ !(task->role->roletype & GR_ROLE_GOD) &&
55718+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
55719+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
55720+ if (unsafe_flags & LSM_UNSAFE_SHARE)
55721+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
55722+ else
55723+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
55724+ return -EACCES;
55725+ }
55726+
55727+skip_check:
55728+
55729+ obj = chk_obj_label(dentry, mnt, task->acl);
55730+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
55731+
55732+ if (!(task->acl->mode & GR_INHERITLEARN) &&
55733+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
55734+ if (obj->nested)
55735+ task->acl = obj->nested;
55736+ else
55737+ task->acl = newacl;
55738+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
55739+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
55740+
55741+ task->is_writable = 0;
55742+
55743+ /* ignore additional mmap checks for processes that are writable
55744+ by the default ACL */
55745+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
55746+ if (unlikely(obj->mode & GR_WRITE))
55747+ task->is_writable = 1;
55748+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
55749+ if (unlikely(obj->mode & GR_WRITE))
55750+ task->is_writable = 1;
55751+
55752+ gr_set_proc_res(task);
55753+
55754+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
55755+ printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
55756+#endif
55757+ return 0;
55758+}
55759+
55760+/* always called with valid inodev ptr */
55761+static void
55762+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
55763+{
55764+ struct acl_object_label *matchpo;
55765+ struct acl_subject_label *matchps;
55766+ struct acl_subject_label *subj;
55767+ struct acl_role_label *role;
55768+ unsigned int x;
55769+
55770+ FOR_EACH_ROLE_START(role)
55771+ FOR_EACH_SUBJECT_START(role, subj, x)
55772+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
55773+ matchpo->mode |= GR_DELETED;
55774+ FOR_EACH_SUBJECT_END(subj,x)
55775+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
55776+ /* nested subjects aren't in the role's subj_hash table */
55777+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
55778+ matchpo->mode |= GR_DELETED;
55779+ FOR_EACH_NESTED_SUBJECT_END(subj)
55780+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
55781+ matchps->mode |= GR_DELETED;
55782+ FOR_EACH_ROLE_END(role)
55783+
55784+ inodev->nentry->deleted = 1;
55785+
55786+ return;
55787+}
55788+
55789+void
55790+gr_handle_delete(const ino_t ino, const dev_t dev)
55791+{
55792+ struct inodev_entry *inodev;
55793+
55794+ if (unlikely(!(gr_status & GR_READY)))
55795+ return;
55796+
55797+ write_lock(&gr_inode_lock);
55798+ inodev = lookup_inodev_entry(ino, dev);
55799+ if (inodev != NULL)
55800+ do_handle_delete(inodev, ino, dev);
55801+ write_unlock(&gr_inode_lock);
55802+
55803+ return;
55804+}
55805+
55806+static void
55807+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
55808+ const ino_t newinode, const dev_t newdevice,
55809+ struct acl_subject_label *subj)
55810+{
55811+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
55812+ struct acl_object_label *match;
55813+
55814+ match = subj->obj_hash[index];
55815+
55816+ while (match && (match->inode != oldinode ||
55817+ match->device != olddevice ||
55818+ !(match->mode & GR_DELETED)))
55819+ match = match->next;
55820+
55821+ if (match && (match->inode == oldinode)
55822+ && (match->device == olddevice)
55823+ && (match->mode & GR_DELETED)) {
55824+ if (match->prev == NULL) {
55825+ subj->obj_hash[index] = match->next;
55826+ if (match->next != NULL)
55827+ match->next->prev = NULL;
55828+ } else {
55829+ match->prev->next = match->next;
55830+ if (match->next != NULL)
55831+ match->next->prev = match->prev;
55832+ }
55833+ match->prev = NULL;
55834+ match->next = NULL;
55835+ match->inode = newinode;
55836+ match->device = newdevice;
55837+ match->mode &= ~GR_DELETED;
55838+
55839+ insert_acl_obj_label(match, subj);
55840+ }
55841+
55842+ return;
55843+}
55844+
55845+static void
55846+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
55847+ const ino_t newinode, const dev_t newdevice,
55848+ struct acl_role_label *role)
55849+{
55850+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
55851+ struct acl_subject_label *match;
55852+
55853+ match = role->subj_hash[index];
55854+
55855+ while (match && (match->inode != oldinode ||
55856+ match->device != olddevice ||
55857+ !(match->mode & GR_DELETED)))
55858+ match = match->next;
55859+
55860+ if (match && (match->inode == oldinode)
55861+ && (match->device == olddevice)
55862+ && (match->mode & GR_DELETED)) {
55863+ if (match->prev == NULL) {
55864+ role->subj_hash[index] = match->next;
55865+ if (match->next != NULL)
55866+ match->next->prev = NULL;
55867+ } else {
55868+ match->prev->next = match->next;
55869+ if (match->next != NULL)
55870+ match->next->prev = match->prev;
55871+ }
55872+ match->prev = NULL;
55873+ match->next = NULL;
55874+ match->inode = newinode;
55875+ match->device = newdevice;
55876+ match->mode &= ~GR_DELETED;
55877+
55878+ insert_acl_subj_label(match, role);
55879+ }
55880+
55881+ return;
55882+}
55883+
55884+static void
55885+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
55886+ const ino_t newinode, const dev_t newdevice)
55887+{
55888+ unsigned int index = gr_fhash(oldinode, olddevice, inodev_set.i_size);
55889+ struct inodev_entry *match;
55890+
55891+ match = inodev_set.i_hash[index];
55892+
55893+ while (match && (match->nentry->inode != oldinode ||
55894+ match->nentry->device != olddevice || !match->nentry->deleted))
55895+ match = match->next;
55896+
55897+ if (match && (match->nentry->inode == oldinode)
55898+ && (match->nentry->device == olddevice) &&
55899+ match->nentry->deleted) {
55900+ if (match->prev == NULL) {
55901+ inodev_set.i_hash[index] = match->next;
55902+ if (match->next != NULL)
55903+ match->next->prev = NULL;
55904+ } else {
55905+ match->prev->next = match->next;
55906+ if (match->next != NULL)
55907+ match->next->prev = match->prev;
55908+ }
55909+ match->prev = NULL;
55910+ match->next = NULL;
55911+ match->nentry->inode = newinode;
55912+ match->nentry->device = newdevice;
55913+ match->nentry->deleted = 0;
55914+
55915+ insert_inodev_entry(match);
55916+ }
55917+
55918+ return;
55919+}
55920+
55921+static void
55922+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
55923+{
55924+ struct acl_subject_label *subj;
55925+ struct acl_role_label *role;
55926+ unsigned int x;
55927+
55928+ FOR_EACH_ROLE_START(role)
55929+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
55930+
55931+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
55932+ if ((subj->inode == ino) && (subj->device == dev)) {
55933+ subj->inode = ino;
55934+ subj->device = dev;
55935+ }
55936+ /* nested subjects aren't in the role's subj_hash table */
55937+ update_acl_obj_label(matchn->inode, matchn->device,
55938+ ino, dev, subj);
55939+ FOR_EACH_NESTED_SUBJECT_END(subj)
55940+ FOR_EACH_SUBJECT_START(role, subj, x)
55941+ update_acl_obj_label(matchn->inode, matchn->device,
55942+ ino, dev, subj);
55943+ FOR_EACH_SUBJECT_END(subj,x)
55944+ FOR_EACH_ROLE_END(role)
55945+
55946+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
55947+
55948+ return;
55949+}
55950+
55951+static void
55952+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
55953+ const struct vfsmount *mnt)
55954+{
55955+ ino_t ino = dentry->d_inode->i_ino;
55956+ dev_t dev = __get_dev(dentry);
55957+
55958+ __do_handle_create(matchn, ino, dev);
55959+
55960+ return;
55961+}
55962+
55963+void
55964+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
55965+{
55966+ struct name_entry *matchn;
55967+
55968+ if (unlikely(!(gr_status & GR_READY)))
55969+ return;
55970+
55971+ preempt_disable();
55972+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
55973+
55974+ if (unlikely((unsigned long)matchn)) {
55975+ write_lock(&gr_inode_lock);
55976+ do_handle_create(matchn, dentry, mnt);
55977+ write_unlock(&gr_inode_lock);
55978+ }
55979+ preempt_enable();
55980+
55981+ return;
55982+}
55983+
55984+void
55985+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
55986+{
55987+ struct name_entry *matchn;
55988+
55989+ if (unlikely(!(gr_status & GR_READY)))
55990+ return;
55991+
55992+ preempt_disable();
55993+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
55994+
55995+ if (unlikely((unsigned long)matchn)) {
55996+ write_lock(&gr_inode_lock);
55997+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
55998+ write_unlock(&gr_inode_lock);
55999+ }
56000+ preempt_enable();
56001+
56002+ return;
56003+}
56004+
56005+void
56006+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
56007+ struct dentry *old_dentry,
56008+ struct dentry *new_dentry,
56009+ struct vfsmount *mnt, const __u8 replace)
56010+{
56011+ struct name_entry *matchn;
56012+ struct inodev_entry *inodev;
56013+ struct inode *inode = new_dentry->d_inode;
56014+ ino_t old_ino = old_dentry->d_inode->i_ino;
56015+ dev_t old_dev = __get_dev(old_dentry);
56016+
56017+ /* vfs_rename swaps the name and parent link for old_dentry and
56018+ new_dentry
56019+ at this point, old_dentry has the new name, parent link, and inode
56020+ for the renamed file
56021+ if a file is being replaced by a rename, new_dentry has the inode
56022+ and name for the replaced file
56023+ */
56024+
56025+ if (unlikely(!(gr_status & GR_READY)))
56026+ return;
56027+
56028+ preempt_disable();
56029+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
56030+
56031+ /* we wouldn't have to check d_inode if it weren't for
56032+ NFS silly-renaming
56033+ */
56034+
56035+ write_lock(&gr_inode_lock);
56036+ if (unlikely(replace && inode)) {
56037+ ino_t new_ino = inode->i_ino;
56038+ dev_t new_dev = __get_dev(new_dentry);
56039+
56040+ inodev = lookup_inodev_entry(new_ino, new_dev);
56041+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
56042+ do_handle_delete(inodev, new_ino, new_dev);
56043+ }
56044+
56045+ inodev = lookup_inodev_entry(old_ino, old_dev);
56046+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
56047+ do_handle_delete(inodev, old_ino, old_dev);
56048+
56049+ if (unlikely((unsigned long)matchn))
56050+ do_handle_create(matchn, old_dentry, mnt);
56051+
56052+ write_unlock(&gr_inode_lock);
56053+ preempt_enable();
56054+
56055+ return;
56056+}
56057+
56058+static int
56059+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
56060+ unsigned char **sum)
56061+{
56062+ struct acl_role_label *r;
56063+ struct role_allowed_ip *ipp;
56064+ struct role_transition *trans;
56065+ unsigned int i;
56066+ int found = 0;
56067+ u32 curr_ip = current->signal->curr_ip;
56068+
56069+ current->signal->saved_ip = curr_ip;
56070+
56071+ /* check transition table */
56072+
56073+ for (trans = current->role->transitions; trans; trans = trans->next) {
56074+ if (!strcmp(rolename, trans->rolename)) {
56075+ found = 1;
56076+ break;
56077+ }
56078+ }
56079+
56080+ if (!found)
56081+ return 0;
56082+
56083+ /* handle special roles that do not require authentication
56084+ and check ip */
56085+
56086+ FOR_EACH_ROLE_START(r)
56087+ if (!strcmp(rolename, r->rolename) &&
56088+ (r->roletype & GR_ROLE_SPECIAL)) {
56089+ found = 0;
56090+ if (r->allowed_ips != NULL) {
56091+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
56092+ if ((ntohl(curr_ip) & ipp->netmask) ==
56093+ (ntohl(ipp->addr) & ipp->netmask))
56094+ found = 1;
56095+ }
56096+ } else
56097+ found = 2;
56098+ if (!found)
56099+ return 0;
56100+
56101+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
56102+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
56103+ *salt = NULL;
56104+ *sum = NULL;
56105+ return 1;
56106+ }
56107+ }
56108+ FOR_EACH_ROLE_END(r)
56109+
56110+ for (i = 0; i < num_sprole_pws; i++) {
56111+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
56112+ *salt = acl_special_roles[i]->salt;
56113+ *sum = acl_special_roles[i]->sum;
56114+ return 1;
56115+ }
56116+ }
56117+
56118+ return 0;
56119+}
56120+
56121+static void
56122+assign_special_role(char *rolename)
56123+{
56124+ struct acl_object_label *obj;
56125+ struct acl_role_label *r;
56126+ struct acl_role_label *assigned = NULL;
56127+ struct task_struct *tsk;
56128+ struct file *filp;
56129+
56130+ FOR_EACH_ROLE_START(r)
56131+ if (!strcmp(rolename, r->rolename) &&
56132+ (r->roletype & GR_ROLE_SPECIAL)) {
56133+ assigned = r;
56134+ break;
56135+ }
56136+ FOR_EACH_ROLE_END(r)
56137+
56138+ if (!assigned)
56139+ return;
56140+
56141+ read_lock(&tasklist_lock);
56142+ read_lock(&grsec_exec_file_lock);
56143+
56144+ tsk = current->real_parent;
56145+ if (tsk == NULL)
56146+ goto out_unlock;
56147+
56148+ filp = tsk->exec_file;
56149+ if (filp == NULL)
56150+ goto out_unlock;
56151+
56152+ tsk->is_writable = 0;
56153+
56154+ tsk->acl_sp_role = 1;
56155+ tsk->acl_role_id = ++acl_sp_role_value;
56156+ tsk->role = assigned;
56157+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
56158+
56159+ /* ignore additional mmap checks for processes that are writable
56160+ by the default ACL */
56161+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
56162+ if (unlikely(obj->mode & GR_WRITE))
56163+ tsk->is_writable = 1;
56164+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
56165+ if (unlikely(obj->mode & GR_WRITE))
56166+ tsk->is_writable = 1;
56167+
56168+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
56169+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
56170+#endif
56171+
56172+out_unlock:
56173+ read_unlock(&grsec_exec_file_lock);
56174+ read_unlock(&tasklist_lock);
56175+ return;
56176+}
56177+
56178+int gr_check_secure_terminal(struct task_struct *task)
56179+{
56180+ struct task_struct *p, *p2, *p3;
56181+ struct files_struct *files;
56182+ struct fdtable *fdt;
56183+ struct file *our_file = NULL, *file;
56184+ int i;
56185+
56186+ if (task->signal->tty == NULL)
56187+ return 1;
56188+
56189+ files = get_files_struct(task);
56190+ if (files != NULL) {
56191+ rcu_read_lock();
56192+ fdt = files_fdtable(files);
56193+ for (i=0; i < fdt->max_fds; i++) {
56194+ file = fcheck_files(files, i);
56195+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
56196+ get_file(file);
56197+ our_file = file;
56198+ }
56199+ }
56200+ rcu_read_unlock();
56201+ put_files_struct(files);
56202+ }
56203+
56204+ if (our_file == NULL)
56205+ return 1;
56206+
56207+ read_lock(&tasklist_lock);
56208+ do_each_thread(p2, p) {
56209+ files = get_files_struct(p);
56210+ if (files == NULL ||
56211+ (p->signal && p->signal->tty == task->signal->tty)) {
56212+ if (files != NULL)
56213+ put_files_struct(files);
56214+ continue;
56215+ }
56216+ rcu_read_lock();
56217+ fdt = files_fdtable(files);
56218+ for (i=0; i < fdt->max_fds; i++) {
56219+ file = fcheck_files(files, i);
56220+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
56221+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
56222+ p3 = task;
56223+ while (p3->pid > 0) {
56224+ if (p3 == p)
56225+ break;
56226+ p3 = p3->real_parent;
56227+ }
56228+ if (p3 == p)
56229+ break;
56230+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
56231+ gr_handle_alertkill(p);
56232+ rcu_read_unlock();
56233+ put_files_struct(files);
56234+ read_unlock(&tasklist_lock);
56235+ fput(our_file);
56236+ return 0;
56237+ }
56238+ }
56239+ rcu_read_unlock();
56240+ put_files_struct(files);
56241+ } while_each_thread(p2, p);
56242+ read_unlock(&tasklist_lock);
56243+
56244+ fput(our_file);
56245+ return 1;
56246+}
56247+
56248+static int gr_rbac_disable(void *unused)
56249+{
56250+ pax_open_kernel();
56251+ gr_status &= ~GR_READY;
56252+ pax_close_kernel();
56253+
56254+ return 0;
56255+}
56256+
56257+ssize_t
56258+write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
56259+{
56260+ struct gr_arg_wrapper uwrap;
56261+ unsigned char *sprole_salt = NULL;
56262+ unsigned char *sprole_sum = NULL;
56263+ int error = sizeof (struct gr_arg_wrapper);
56264+ int error2 = 0;
56265+
56266+ mutex_lock(&gr_dev_mutex);
56267+
56268+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
56269+ error = -EPERM;
56270+ goto out;
56271+ }
56272+
56273+ if (count != sizeof (struct gr_arg_wrapper)) {
56274+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
56275+ error = -EINVAL;
56276+ goto out;
56277+ }
56278+
56279+
56280+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
56281+ gr_auth_expires = 0;
56282+ gr_auth_attempts = 0;
56283+ }
56284+
56285+ if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
56286+ error = -EFAULT;
56287+ goto out;
56288+ }
56289+
56290+ if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
56291+ error = -EINVAL;
56292+ goto out;
56293+ }
56294+
56295+ if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
56296+ error = -EFAULT;
56297+ goto out;
56298+ }
56299+
56300+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
56301+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
56302+ time_after(gr_auth_expires, get_seconds())) {
56303+ error = -EBUSY;
56304+ goto out;
56305+ }
56306+
56307+ /* if non-root trying to do anything other than use a special role,
56308+ do not attempt authentication, do not count towards authentication
56309+ locking
56310+ */
56311+
56312+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
56313+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
56314+ !uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
56315+ error = -EPERM;
56316+ goto out;
56317+ }
56318+
56319+ /* ensure pw and special role name are null terminated */
56320+
56321+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
56322+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
56323+
56324+ /* Okay.
56325+ * We have our enough of the argument structure..(we have yet
56326+ * to copy_from_user the tables themselves) . Copy the tables
56327+ * only if we need them, i.e. for loading operations. */
56328+
56329+ switch (gr_usermode->mode) {
56330+ case GR_STATUS:
56331+ if (gr_status & GR_READY) {
56332+ error = 1;
56333+ if (!gr_check_secure_terminal(current))
56334+ error = 3;
56335+ } else
56336+ error = 2;
56337+ goto out;
56338+ case GR_SHUTDOWN:
56339+ if ((gr_status & GR_READY)
56340+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
56341+ stop_machine(gr_rbac_disable, NULL, NULL);
56342+ free_variables();
56343+ memset(gr_usermode, 0, sizeof (struct gr_arg));
56344+ memset(gr_system_salt, 0, GR_SALT_LEN);
56345+ memset(gr_system_sum, 0, GR_SHA_LEN);
56346+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
56347+ } else if (gr_status & GR_READY) {
56348+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
56349+ error = -EPERM;
56350+ } else {
56351+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
56352+ error = -EAGAIN;
56353+ }
56354+ break;
56355+ case GR_ENABLE:
56356+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
56357+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
56358+ else {
56359+ if (gr_status & GR_READY)
56360+ error = -EAGAIN;
56361+ else
56362+ error = error2;
56363+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
56364+ }
56365+ break;
56366+ case GR_RELOAD:
56367+ if (!(gr_status & GR_READY)) {
56368+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
56369+ error = -EAGAIN;
56370+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
56371+ stop_machine(gr_rbac_disable, NULL, NULL);
56372+ free_variables();
56373+ error2 = gracl_init(gr_usermode);
56374+ if (!error2)
56375+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
56376+ else {
56377+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
56378+ error = error2;
56379+ }
56380+ } else {
56381+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
56382+ error = -EPERM;
56383+ }
56384+ break;
56385+ case GR_SEGVMOD:
56386+ if (unlikely(!(gr_status & GR_READY))) {
56387+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
56388+ error = -EAGAIN;
56389+ break;
56390+ }
56391+
56392+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
56393+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
56394+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
56395+ struct acl_subject_label *segvacl;
56396+ segvacl =
56397+ lookup_acl_subj_label(gr_usermode->segv_inode,
56398+ gr_usermode->segv_device,
56399+ current->role);
56400+ if (segvacl) {
56401+ segvacl->crashes = 0;
56402+ segvacl->expires = 0;
56403+ }
56404+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
56405+ gr_remove_uid(gr_usermode->segv_uid);
56406+ }
56407+ } else {
56408+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
56409+ error = -EPERM;
56410+ }
56411+ break;
56412+ case GR_SPROLE:
56413+ case GR_SPROLEPAM:
56414+ if (unlikely(!(gr_status & GR_READY))) {
56415+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
56416+ error = -EAGAIN;
56417+ break;
56418+ }
56419+
56420+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
56421+ current->role->expires = 0;
56422+ current->role->auth_attempts = 0;
56423+ }
56424+
56425+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
56426+ time_after(current->role->expires, get_seconds())) {
56427+ error = -EBUSY;
56428+ goto out;
56429+ }
56430+
56431+ if (lookup_special_role_auth
56432+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
56433+ && ((!sprole_salt && !sprole_sum)
56434+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
56435+ char *p = "";
56436+ assign_special_role(gr_usermode->sp_role);
56437+ read_lock(&tasklist_lock);
56438+ if (current->real_parent)
56439+ p = current->real_parent->role->rolename;
56440+ read_unlock(&tasklist_lock);
56441+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
56442+ p, acl_sp_role_value);
56443+ } else {
56444+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
56445+ error = -EPERM;
56446+ if(!(current->role->auth_attempts++))
56447+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
56448+
56449+ goto out;
56450+ }
56451+ break;
56452+ case GR_UNSPROLE:
56453+ if (unlikely(!(gr_status & GR_READY))) {
56454+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
56455+ error = -EAGAIN;
56456+ break;
56457+ }
56458+
56459+ if (current->role->roletype & GR_ROLE_SPECIAL) {
56460+ char *p = "";
56461+ int i = 0;
56462+
56463+ read_lock(&tasklist_lock);
56464+ if (current->real_parent) {
56465+ p = current->real_parent->role->rolename;
56466+ i = current->real_parent->acl_role_id;
56467+ }
56468+ read_unlock(&tasklist_lock);
56469+
56470+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
56471+ gr_set_acls(1);
56472+ } else {
56473+ error = -EPERM;
56474+ goto out;
56475+ }
56476+ break;
56477+ default:
56478+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
56479+ error = -EINVAL;
56480+ break;
56481+ }
56482+
56483+ if (error != -EPERM)
56484+ goto out;
56485+
56486+ if(!(gr_auth_attempts++))
56487+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
56488+
56489+ out:
56490+ mutex_unlock(&gr_dev_mutex);
56491+ return error;
56492+}
56493+
56494+/* must be called with
56495+ rcu_read_lock();
56496+ read_lock(&tasklist_lock);
56497+ read_lock(&grsec_exec_file_lock);
56498+*/
56499+int gr_apply_subject_to_task(struct task_struct *task)
56500+{
56501+ struct acl_object_label *obj;
56502+ char *tmpname;
56503+ struct acl_subject_label *tmpsubj;
56504+ struct file *filp;
56505+ struct name_entry *nmatch;
56506+
56507+ filp = task->exec_file;
56508+ if (filp == NULL)
56509+ return 0;
56510+
56511+ /* the following is to apply the correct subject
56512+ on binaries running when the RBAC system
56513+ is enabled, when the binaries have been
56514+ replaced or deleted since their execution
56515+ -----
56516+ when the RBAC system starts, the inode/dev
56517+ from exec_file will be one the RBAC system
56518+ is unaware of. It only knows the inode/dev
56519+ of the present file on disk, or the absence
56520+ of it.
56521+ */
56522+ preempt_disable();
56523+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
56524+
56525+ nmatch = lookup_name_entry(tmpname);
56526+ preempt_enable();
56527+ tmpsubj = NULL;
56528+ if (nmatch) {
56529+ if (nmatch->deleted)
56530+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
56531+ else
56532+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
56533+ if (tmpsubj != NULL)
56534+ task->acl = tmpsubj;
56535+ }
56536+ if (tmpsubj == NULL)
56537+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
56538+ task->role);
56539+ if (task->acl) {
56540+ task->is_writable = 0;
56541+ /* ignore additional mmap checks for processes that are writable
56542+ by the default ACL */
56543+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
56544+ if (unlikely(obj->mode & GR_WRITE))
56545+ task->is_writable = 1;
56546+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
56547+ if (unlikely(obj->mode & GR_WRITE))
56548+ task->is_writable = 1;
56549+
56550+ gr_set_proc_res(task);
56551+
56552+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
56553+ printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
56554+#endif
56555+ } else {
56556+ return 1;
56557+ }
56558+
56559+ return 0;
56560+}
56561+
56562+int
56563+gr_set_acls(const int type)
56564+{
56565+ struct task_struct *task, *task2;
56566+ struct acl_role_label *role = current->role;
56567+ __u16 acl_role_id = current->acl_role_id;
56568+ const struct cred *cred;
56569+ int ret;
56570+
56571+ rcu_read_lock();
56572+ read_lock(&tasklist_lock);
56573+ read_lock(&grsec_exec_file_lock);
56574+ do_each_thread(task2, task) {
56575+ /* check to see if we're called from the exit handler,
56576+ if so, only replace ACLs that have inherited the admin
56577+ ACL */
56578+
56579+ if (type && (task->role != role ||
56580+ task->acl_role_id != acl_role_id))
56581+ continue;
56582+
56583+ task->acl_role_id = 0;
56584+ task->acl_sp_role = 0;
56585+
56586+ if (task->exec_file) {
56587+ cred = __task_cred(task);
56588+ task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
56589+ ret = gr_apply_subject_to_task(task);
56590+ if (ret) {
56591+ read_unlock(&grsec_exec_file_lock);
56592+ read_unlock(&tasklist_lock);
56593+ rcu_read_unlock();
56594+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
56595+ return ret;
56596+ }
56597+ } else {
56598+ // it's a kernel process
56599+ task->role = kernel_role;
56600+ task->acl = kernel_role->root_label;
56601+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
56602+ task->acl->mode &= ~GR_PROCFIND;
56603+#endif
56604+ }
56605+ } while_each_thread(task2, task);
56606+ read_unlock(&grsec_exec_file_lock);
56607+ read_unlock(&tasklist_lock);
56608+ rcu_read_unlock();
56609+
56610+ return 0;
56611+}
56612+
56613+void
56614+gr_learn_resource(const struct task_struct *task,
56615+ const int res, const unsigned long wanted, const int gt)
56616+{
56617+ struct acl_subject_label *acl;
56618+ const struct cred *cred;
56619+
56620+ if (unlikely((gr_status & GR_READY) &&
56621+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
56622+ goto skip_reslog;
56623+
56624+#ifdef CONFIG_GRKERNSEC_RESLOG
56625+ gr_log_resource(task, res, wanted, gt);
56626+#endif
56627+ skip_reslog:
56628+
56629+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
56630+ return;
56631+
56632+ acl = task->acl;
56633+
56634+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
56635+ !(acl->resmask & (1 << (unsigned short) res))))
56636+ return;
56637+
56638+ if (wanted >= acl->res[res].rlim_cur) {
56639+ unsigned long res_add;
56640+
56641+ res_add = wanted;
56642+ switch (res) {
56643+ case RLIMIT_CPU:
56644+ res_add += GR_RLIM_CPU_BUMP;
56645+ break;
56646+ case RLIMIT_FSIZE:
56647+ res_add += GR_RLIM_FSIZE_BUMP;
56648+ break;
56649+ case RLIMIT_DATA:
56650+ res_add += GR_RLIM_DATA_BUMP;
56651+ break;
56652+ case RLIMIT_STACK:
56653+ res_add += GR_RLIM_STACK_BUMP;
56654+ break;
56655+ case RLIMIT_CORE:
56656+ res_add += GR_RLIM_CORE_BUMP;
56657+ break;
56658+ case RLIMIT_RSS:
56659+ res_add += GR_RLIM_RSS_BUMP;
56660+ break;
56661+ case RLIMIT_NPROC:
56662+ res_add += GR_RLIM_NPROC_BUMP;
56663+ break;
56664+ case RLIMIT_NOFILE:
56665+ res_add += GR_RLIM_NOFILE_BUMP;
56666+ break;
56667+ case RLIMIT_MEMLOCK:
56668+ res_add += GR_RLIM_MEMLOCK_BUMP;
56669+ break;
56670+ case RLIMIT_AS:
56671+ res_add += GR_RLIM_AS_BUMP;
56672+ break;
56673+ case RLIMIT_LOCKS:
56674+ res_add += GR_RLIM_LOCKS_BUMP;
56675+ break;
56676+ case RLIMIT_SIGPENDING:
56677+ res_add += GR_RLIM_SIGPENDING_BUMP;
56678+ break;
56679+ case RLIMIT_MSGQUEUE:
56680+ res_add += GR_RLIM_MSGQUEUE_BUMP;
56681+ break;
56682+ case RLIMIT_NICE:
56683+ res_add += GR_RLIM_NICE_BUMP;
56684+ break;
56685+ case RLIMIT_RTPRIO:
56686+ res_add += GR_RLIM_RTPRIO_BUMP;
56687+ break;
56688+ case RLIMIT_RTTIME:
56689+ res_add += GR_RLIM_RTTIME_BUMP;
56690+ break;
56691+ }
56692+
56693+ acl->res[res].rlim_cur = res_add;
56694+
56695+ if (wanted > acl->res[res].rlim_max)
56696+ acl->res[res].rlim_max = res_add;
56697+
56698+ /* only log the subject filename, since resource logging is supported for
56699+ single-subject learning only */
56700+ rcu_read_lock();
56701+ cred = __task_cred(task);
56702+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
56703+ task->role->roletype, cred->uid, cred->gid, acl->filename,
56704+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
56705+ "", (unsigned long) res, &task->signal->saved_ip);
56706+ rcu_read_unlock();
56707+ }
56708+
56709+ return;
56710+}
56711+
56712+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
56713+void
56714+pax_set_initial_flags(struct linux_binprm *bprm)
56715+{
56716+ struct task_struct *task = current;
56717+ struct acl_subject_label *proc;
56718+ unsigned long flags;
56719+
56720+ if (unlikely(!(gr_status & GR_READY)))
56721+ return;
56722+
56723+ flags = pax_get_flags(task);
56724+
56725+ proc = task->acl;
56726+
56727+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
56728+ flags &= ~MF_PAX_PAGEEXEC;
56729+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
56730+ flags &= ~MF_PAX_SEGMEXEC;
56731+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
56732+ flags &= ~MF_PAX_RANDMMAP;
56733+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
56734+ flags &= ~MF_PAX_EMUTRAMP;
56735+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
56736+ flags &= ~MF_PAX_MPROTECT;
56737+
56738+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
56739+ flags |= MF_PAX_PAGEEXEC;
56740+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
56741+ flags |= MF_PAX_SEGMEXEC;
56742+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
56743+ flags |= MF_PAX_RANDMMAP;
56744+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
56745+ flags |= MF_PAX_EMUTRAMP;
56746+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
56747+ flags |= MF_PAX_MPROTECT;
56748+
56749+ pax_set_flags(task, flags);
56750+
56751+ return;
56752+}
56753+#endif
56754+
56755+int
56756+gr_handle_proc_ptrace(struct task_struct *task)
56757+{
56758+ struct file *filp;
56759+ struct task_struct *tmp = task;
56760+ struct task_struct *curtemp = current;
56761+ __u32 retmode;
56762+
56763+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
56764+ if (unlikely(!(gr_status & GR_READY)))
56765+ return 0;
56766+#endif
56767+
56768+ read_lock(&tasklist_lock);
56769+ read_lock(&grsec_exec_file_lock);
56770+ filp = task->exec_file;
56771+
56772+ while (tmp->pid > 0) {
56773+ if (tmp == curtemp)
56774+ break;
56775+ tmp = tmp->real_parent;
56776+ }
56777+
56778+ if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
56779+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
56780+ read_unlock(&grsec_exec_file_lock);
56781+ read_unlock(&tasklist_lock);
56782+ return 1;
56783+ }
56784+
56785+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
56786+ if (!(gr_status & GR_READY)) {
56787+ read_unlock(&grsec_exec_file_lock);
56788+ read_unlock(&tasklist_lock);
56789+ return 0;
56790+ }
56791+#endif
56792+
56793+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
56794+ read_unlock(&grsec_exec_file_lock);
56795+ read_unlock(&tasklist_lock);
56796+
56797+ if (retmode & GR_NOPTRACE)
56798+ return 1;
56799+
56800+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
56801+ && (current->acl != task->acl || (current->acl != current->role->root_label
56802+ && current->pid != task->pid)))
56803+ return 1;
56804+
56805+ return 0;
56806+}
56807+
56808+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
56809+{
56810+ if (unlikely(!(gr_status & GR_READY)))
56811+ return;
56812+
56813+ if (!(current->role->roletype & GR_ROLE_GOD))
56814+ return;
56815+
56816+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
56817+ p->role->rolename, gr_task_roletype_to_char(p),
56818+ p->acl->filename);
56819+}
56820+
56821+int
56822+gr_handle_ptrace(struct task_struct *task, const long request)
56823+{
56824+ struct task_struct *tmp = task;
56825+ struct task_struct *curtemp = current;
56826+ __u32 retmode;
56827+
56828+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
56829+ if (unlikely(!(gr_status & GR_READY)))
56830+ return 0;
56831+#endif
56832+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
56833+ read_lock(&tasklist_lock);
56834+ while (tmp->pid > 0) {
56835+ if (tmp == curtemp)
56836+ break;
56837+ tmp = tmp->real_parent;
56838+ }
56839+
56840+ if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
56841+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
56842+ read_unlock(&tasklist_lock);
56843+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
56844+ return 1;
56845+ }
56846+ read_unlock(&tasklist_lock);
56847+ }
56848+
56849+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
56850+ if (!(gr_status & GR_READY))
56851+ return 0;
56852+#endif
56853+
56854+ read_lock(&grsec_exec_file_lock);
56855+ if (unlikely(!task->exec_file)) {
56856+ read_unlock(&grsec_exec_file_lock);
56857+ return 0;
56858+ }
56859+
56860+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
56861+ read_unlock(&grsec_exec_file_lock);
56862+
56863+ if (retmode & GR_NOPTRACE) {
56864+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
56865+ return 1;
56866+ }
56867+
56868+ if (retmode & GR_PTRACERD) {
56869+ switch (request) {
56870+ case PTRACE_SEIZE:
56871+ case PTRACE_POKETEXT:
56872+ case PTRACE_POKEDATA:
56873+ case PTRACE_POKEUSR:
56874+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
56875+ case PTRACE_SETREGS:
56876+ case PTRACE_SETFPREGS:
56877+#endif
56878+#ifdef CONFIG_X86
56879+ case PTRACE_SETFPXREGS:
56880+#endif
56881+#ifdef CONFIG_ALTIVEC
56882+ case PTRACE_SETVRREGS:
56883+#endif
56884+ return 1;
56885+ default:
56886+ return 0;
56887+ }
56888+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
56889+ !(current->role->roletype & GR_ROLE_GOD) &&
56890+ (current->acl != task->acl)) {
56891+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
56892+ return 1;
56893+ }
56894+
56895+ return 0;
56896+}
56897+
56898+static int is_writable_mmap(const struct file *filp)
56899+{
56900+ struct task_struct *task = current;
56901+ struct acl_object_label *obj, *obj2;
56902+
56903+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
56904+ !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))) {
56905+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
56906+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
56907+ task->role->root_label);
56908+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
56909+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
56910+ return 1;
56911+ }
56912+ }
56913+ return 0;
56914+}
56915+
56916+int
56917+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
56918+{
56919+ __u32 mode;
56920+
56921+ if (unlikely(!file || !(prot & PROT_EXEC)))
56922+ return 1;
56923+
56924+ if (is_writable_mmap(file))
56925+ return 0;
56926+
56927+ mode =
56928+ gr_search_file(file->f_path.dentry,
56929+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
56930+ file->f_path.mnt);
56931+
56932+ if (!gr_tpe_allow(file))
56933+ return 0;
56934+
56935+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
56936+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
56937+ return 0;
56938+ } else if (unlikely(!(mode & GR_EXEC))) {
56939+ return 0;
56940+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
56941+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
56942+ return 1;
56943+ }
56944+
56945+ return 1;
56946+}
56947+
56948+int
56949+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
56950+{
56951+ __u32 mode;
56952+
56953+ if (unlikely(!file || !(prot & PROT_EXEC)))
56954+ return 1;
56955+
56956+ if (is_writable_mmap(file))
56957+ return 0;
56958+
56959+ mode =
56960+ gr_search_file(file->f_path.dentry,
56961+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
56962+ file->f_path.mnt);
56963+
56964+ if (!gr_tpe_allow(file))
56965+ return 0;
56966+
56967+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
56968+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
56969+ return 0;
56970+ } else if (unlikely(!(mode & GR_EXEC))) {
56971+ return 0;
56972+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
56973+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
56974+ return 1;
56975+ }
56976+
56977+ return 1;
56978+}
56979+
56980+void
56981+gr_acl_handle_psacct(struct task_struct *task, const long code)
56982+{
56983+ unsigned long runtime;
56984+ unsigned long cputime;
56985+ unsigned int wday, cday;
56986+ __u8 whr, chr;
56987+ __u8 wmin, cmin;
56988+ __u8 wsec, csec;
56989+ struct timespec timeval;
56990+
56991+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
56992+ !(task->acl->mode & GR_PROCACCT)))
56993+ return;
56994+
56995+ do_posix_clock_monotonic_gettime(&timeval);
56996+ runtime = timeval.tv_sec - task->start_time.tv_sec;
56997+ wday = runtime / (3600 * 24);
56998+ runtime -= wday * (3600 * 24);
56999+ whr = runtime / 3600;
57000+ runtime -= whr * 3600;
57001+ wmin = runtime / 60;
57002+ runtime -= wmin * 60;
57003+ wsec = runtime;
57004+
57005+ cputime = (task->utime + task->stime) / HZ;
57006+ cday = cputime / (3600 * 24);
57007+ cputime -= cday * (3600 * 24);
57008+ chr = cputime / 3600;
57009+ cputime -= chr * 3600;
57010+ cmin = cputime / 60;
57011+ cputime -= cmin * 60;
57012+ csec = cputime;
57013+
57014+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
57015+
57016+ return;
57017+}
57018+
57019+void gr_set_kernel_label(struct task_struct *task)
57020+{
57021+ if (gr_status & GR_READY) {
57022+ task->role = kernel_role;
57023+ task->acl = kernel_role->root_label;
57024+ }
57025+ return;
57026+}
57027+
57028+#ifdef CONFIG_TASKSTATS
57029+int gr_is_taskstats_denied(int pid)
57030+{
57031+ struct task_struct *task;
57032+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
57033+ const struct cred *cred;
57034+#endif
57035+ int ret = 0;
57036+
57037+ /* restrict taskstats viewing to un-chrooted root users
57038+ who have the 'view' subject flag if the RBAC system is enabled
57039+ */
57040+
57041+ rcu_read_lock();
57042+ read_lock(&tasklist_lock);
57043+ task = find_task_by_vpid(pid);
57044+ if (task) {
57045+#ifdef CONFIG_GRKERNSEC_CHROOT
57046+ if (proc_is_chrooted(task))
57047+ ret = -EACCES;
57048+#endif
57049+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
57050+ cred = __task_cred(task);
57051+#ifdef CONFIG_GRKERNSEC_PROC_USER
57052+ if (!uid_eq(cred->uid, GLOBAL_ROOT_UID))
57053+ ret = -EACCES;
57054+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
57055+ if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && !groups_search(cred->group_info, grsec_proc_gid))
57056+ ret = -EACCES;
57057+#endif
57058+#endif
57059+ if (gr_status & GR_READY) {
57060+ if (!(task->acl->mode & GR_VIEW))
57061+ ret = -EACCES;
57062+ }
57063+ } else
57064+ ret = -ENOENT;
57065+
57066+ read_unlock(&tasklist_lock);
57067+ rcu_read_unlock();
57068+
57069+ return ret;
57070+}
57071+#endif
57072+
57073+/* AUXV entries are filled via a descendant of search_binary_handler
57074+ after we've already applied the subject for the target
57075+*/
57076+int gr_acl_enable_at_secure(void)
57077+{
57078+ if (unlikely(!(gr_status & GR_READY)))
57079+ return 0;
57080+
57081+ if (current->acl->mode & GR_ATSECURE)
57082+ return 1;
57083+
57084+ return 0;
57085+}
57086+
57087+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
57088+{
57089+ struct task_struct *task = current;
57090+ struct dentry *dentry = file->f_path.dentry;
57091+ struct vfsmount *mnt = file->f_path.mnt;
57092+ struct acl_object_label *obj, *tmp;
57093+ struct acl_subject_label *subj;
57094+ unsigned int bufsize;
57095+ int is_not_root;
57096+ char *path;
57097+ dev_t dev = __get_dev(dentry);
57098+
57099+ if (unlikely(!(gr_status & GR_READY)))
57100+ return 1;
57101+
57102+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
57103+ return 1;
57104+
57105+ /* ignore Eric Biederman */
57106+ if (IS_PRIVATE(dentry->d_inode))
57107+ return 1;
57108+
57109+ subj = task->acl;
57110+ read_lock(&gr_inode_lock);
57111+ do {
57112+ obj = lookup_acl_obj_label(ino, dev, subj);
57113+ if (obj != NULL) {
57114+ read_unlock(&gr_inode_lock);
57115+ return (obj->mode & GR_FIND) ? 1 : 0;
57116+ }
57117+ } while ((subj = subj->parent_subject));
57118+ read_unlock(&gr_inode_lock);
57119+
57120+ /* this is purely an optimization since we're looking for an object
57121+ for the directory we're doing a readdir on
57122+ if it's possible for any globbed object to match the entry we're
57123+ filling into the directory, then the object we find here will be
57124+ an anchor point with attached globbed objects
57125+ */
57126+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
57127+ if (obj->globbed == NULL)
57128+ return (obj->mode & GR_FIND) ? 1 : 0;
57129+
57130+ is_not_root = ((obj->filename[0] == '/') &&
57131+ (obj->filename[1] == '\0')) ? 0 : 1;
57132+ bufsize = PAGE_SIZE - namelen - is_not_root;
57133+
57134+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
57135+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
57136+ return 1;
57137+
57138+ preempt_disable();
57139+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
57140+ bufsize);
57141+
57142+ bufsize = strlen(path);
57143+
57144+ /* if base is "/", don't append an additional slash */
57145+ if (is_not_root)
57146+ *(path + bufsize) = '/';
57147+ memcpy(path + bufsize + is_not_root, name, namelen);
57148+ *(path + bufsize + namelen + is_not_root) = '\0';
57149+
57150+ tmp = obj->globbed;
57151+ while (tmp) {
57152+ if (!glob_match(tmp->filename, path)) {
57153+ preempt_enable();
57154+ return (tmp->mode & GR_FIND) ? 1 : 0;
57155+ }
57156+ tmp = tmp->next;
57157+ }
57158+ preempt_enable();
57159+ return (obj->mode & GR_FIND) ? 1 : 0;
57160+}
57161+
57162+void gr_put_exec_file(struct task_struct *task)
57163+{
57164+ struct file *filp;
57165+
57166+ write_lock(&grsec_exec_file_lock);
57167+ filp = task->exec_file;
57168+ task->exec_file = NULL;
57169+ write_unlock(&grsec_exec_file_lock);
57170+
57171+ if (filp)
57172+ fput(filp);
57173+
57174+ return;
57175+}
57176+
57177+
57178+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
57179+EXPORT_SYMBOL(gr_acl_is_enabled);
57180+#endif
57181+EXPORT_SYMBOL(gr_learn_resource);
57182+EXPORT_SYMBOL(gr_set_kernel_label);
57183+#ifdef CONFIG_SECURITY
57184+EXPORT_SYMBOL(gr_check_user_change);
57185+EXPORT_SYMBOL(gr_check_group_change);
57186+#endif
57187+
57188diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
57189new file mode 100644
57190index 0000000..34fefda
57191--- /dev/null
57192+++ b/grsecurity/gracl_alloc.c
57193@@ -0,0 +1,105 @@
57194+#include <linux/kernel.h>
57195+#include <linux/mm.h>
57196+#include <linux/slab.h>
57197+#include <linux/vmalloc.h>
57198+#include <linux/gracl.h>
57199+#include <linux/grsecurity.h>
57200+
57201+static unsigned long alloc_stack_next = 1;
57202+static unsigned long alloc_stack_size = 1;
57203+static void **alloc_stack;
57204+
57205+static __inline__ int
57206+alloc_pop(void)
57207+{
57208+ if (alloc_stack_next == 1)
57209+ return 0;
57210+
57211+ kfree(alloc_stack[alloc_stack_next - 2]);
57212+
57213+ alloc_stack_next--;
57214+
57215+ return 1;
57216+}
57217+
57218+static __inline__ int
57219+alloc_push(void *buf)
57220+{
57221+ if (alloc_stack_next >= alloc_stack_size)
57222+ return 1;
57223+
57224+ alloc_stack[alloc_stack_next - 1] = buf;
57225+
57226+ alloc_stack_next++;
57227+
57228+ return 0;
57229+}
57230+
57231+void *
57232+acl_alloc(unsigned long len)
57233+{
57234+ void *ret = NULL;
57235+
57236+ if (!len || len > PAGE_SIZE)
57237+ goto out;
57238+
57239+ ret = kmalloc(len, GFP_KERNEL);
57240+
57241+ if (ret) {
57242+ if (alloc_push(ret)) {
57243+ kfree(ret);
57244+ ret = NULL;
57245+ }
57246+ }
57247+
57248+out:
57249+ return ret;
57250+}
57251+
57252+void *
57253+acl_alloc_num(unsigned long num, unsigned long len)
57254+{
57255+ if (!len || (num > (PAGE_SIZE / len)))
57256+ return NULL;
57257+
57258+ return acl_alloc(num * len);
57259+}
57260+
57261+void
57262+acl_free_all(void)
57263+{
57264+ if (gr_acl_is_enabled() || !alloc_stack)
57265+ return;
57266+
57267+ while (alloc_pop()) ;
57268+
57269+ if (alloc_stack) {
57270+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
57271+ kfree(alloc_stack);
57272+ else
57273+ vfree(alloc_stack);
57274+ }
57275+
57276+ alloc_stack = NULL;
57277+ alloc_stack_size = 1;
57278+ alloc_stack_next = 1;
57279+
57280+ return;
57281+}
57282+
57283+int
57284+acl_alloc_stack_init(unsigned long size)
57285+{
57286+ if ((size * sizeof (void *)) <= PAGE_SIZE)
57287+ alloc_stack =
57288+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
57289+ else
57290+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
57291+
57292+ alloc_stack_size = size;
57293+
57294+ if (!alloc_stack)
57295+ return 0;
57296+ else
57297+ return 1;
57298+}
57299diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
57300new file mode 100644
57301index 0000000..6d21049
57302--- /dev/null
57303+++ b/grsecurity/gracl_cap.c
57304@@ -0,0 +1,110 @@
57305+#include <linux/kernel.h>
57306+#include <linux/module.h>
57307+#include <linux/sched.h>
57308+#include <linux/gracl.h>
57309+#include <linux/grsecurity.h>
57310+#include <linux/grinternal.h>
57311+
57312+extern const char *captab_log[];
57313+extern int captab_log_entries;
57314+
57315+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
57316+{
57317+ struct acl_subject_label *curracl;
57318+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
57319+ kernel_cap_t cap_audit = __cap_empty_set;
57320+
57321+ if (!gr_acl_is_enabled())
57322+ return 1;
57323+
57324+ curracl = task->acl;
57325+
57326+ cap_drop = curracl->cap_lower;
57327+ cap_mask = curracl->cap_mask;
57328+ cap_audit = curracl->cap_invert_audit;
57329+
57330+ while ((curracl = curracl->parent_subject)) {
57331+ /* if the cap isn't specified in the current computed mask but is specified in the
57332+ current level subject, and is lowered in the current level subject, then add
57333+ it to the set of dropped capabilities
57334+ otherwise, add the current level subject's mask to the current computed mask
57335+ */
57336+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
57337+ cap_raise(cap_mask, cap);
57338+ if (cap_raised(curracl->cap_lower, cap))
57339+ cap_raise(cap_drop, cap);
57340+ if (cap_raised(curracl->cap_invert_audit, cap))
57341+ cap_raise(cap_audit, cap);
57342+ }
57343+ }
57344+
57345+ if (!cap_raised(cap_drop, cap)) {
57346+ if (cap_raised(cap_audit, cap))
57347+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
57348+ return 1;
57349+ }
57350+
57351+ curracl = task->acl;
57352+
57353+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
57354+ && cap_raised(cred->cap_effective, cap)) {
57355+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
57356+ task->role->roletype, cred->uid,
57357+ cred->gid, task->exec_file ?
57358+ gr_to_filename(task->exec_file->f_path.dentry,
57359+ task->exec_file->f_path.mnt) : curracl->filename,
57360+ curracl->filename, 0UL,
57361+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
57362+ return 1;
57363+ }
57364+
57365+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
57366+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
57367+
57368+ return 0;
57369+}
57370+
57371+int
57372+gr_acl_is_capable(const int cap)
57373+{
57374+ return gr_task_acl_is_capable(current, current_cred(), cap);
57375+}
57376+
57377+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
57378+{
57379+ struct acl_subject_label *curracl;
57380+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
57381+
57382+ if (!gr_acl_is_enabled())
57383+ return 1;
57384+
57385+ curracl = task->acl;
57386+
57387+ cap_drop = curracl->cap_lower;
57388+ cap_mask = curracl->cap_mask;
57389+
57390+ while ((curracl = curracl->parent_subject)) {
57391+ /* if the cap isn't specified in the current computed mask but is specified in the
57392+ current level subject, and is lowered in the current level subject, then add
57393+ it to the set of dropped capabilities
57394+ otherwise, add the current level subject's mask to the current computed mask
57395+ */
57396+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
57397+ cap_raise(cap_mask, cap);
57398+ if (cap_raised(curracl->cap_lower, cap))
57399+ cap_raise(cap_drop, cap);
57400+ }
57401+ }
57402+
57403+ if (!cap_raised(cap_drop, cap))
57404+ return 1;
57405+
57406+ return 0;
57407+}
57408+
57409+int
57410+gr_acl_is_capable_nolog(const int cap)
57411+{
57412+ return gr_task_acl_is_capable_nolog(current, cap);
57413+}
57414+
57415diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
57416new file mode 100644
57417index 0000000..decb035
57418--- /dev/null
57419+++ b/grsecurity/gracl_fs.c
57420@@ -0,0 +1,437 @@
57421+#include <linux/kernel.h>
57422+#include <linux/sched.h>
57423+#include <linux/types.h>
57424+#include <linux/fs.h>
57425+#include <linux/file.h>
57426+#include <linux/stat.h>
57427+#include <linux/grsecurity.h>
57428+#include <linux/grinternal.h>
57429+#include <linux/gracl.h>
57430+
57431+umode_t
57432+gr_acl_umask(void)
57433+{
57434+ if (unlikely(!gr_acl_is_enabled()))
57435+ return 0;
57436+
57437+ return current->role->umask;
57438+}
57439+
57440+__u32
57441+gr_acl_handle_hidden_file(const struct dentry * dentry,
57442+ const struct vfsmount * mnt)
57443+{
57444+ __u32 mode;
57445+
57446+ if (unlikely(!dentry->d_inode))
57447+ return GR_FIND;
57448+
57449+ mode =
57450+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
57451+
57452+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
57453+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
57454+ return mode;
57455+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
57456+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
57457+ return 0;
57458+ } else if (unlikely(!(mode & GR_FIND)))
57459+ return 0;
57460+
57461+ return GR_FIND;
57462+}
57463+
57464+__u32
57465+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
57466+ int acc_mode)
57467+{
57468+ __u32 reqmode = GR_FIND;
57469+ __u32 mode;
57470+
57471+ if (unlikely(!dentry->d_inode))
57472+ return reqmode;
57473+
57474+ if (acc_mode & MAY_APPEND)
57475+ reqmode |= GR_APPEND;
57476+ else if (acc_mode & MAY_WRITE)
57477+ reqmode |= GR_WRITE;
57478+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
57479+ reqmode |= GR_READ;
57480+
57481+ mode =
57482+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
57483+ mnt);
57484+
57485+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
57486+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
57487+ reqmode & GR_READ ? " reading" : "",
57488+ reqmode & GR_WRITE ? " writing" : reqmode &
57489+ GR_APPEND ? " appending" : "");
57490+ return reqmode;
57491+ } else
57492+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
57493+ {
57494+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
57495+ reqmode & GR_READ ? " reading" : "",
57496+ reqmode & GR_WRITE ? " writing" : reqmode &
57497+ GR_APPEND ? " appending" : "");
57498+ return 0;
57499+ } else if (unlikely((mode & reqmode) != reqmode))
57500+ return 0;
57501+
57502+ return reqmode;
57503+}
57504+
57505+__u32
57506+gr_acl_handle_creat(const struct dentry * dentry,
57507+ const struct dentry * p_dentry,
57508+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
57509+ const int imode)
57510+{
57511+ __u32 reqmode = GR_WRITE | GR_CREATE;
57512+ __u32 mode;
57513+
57514+ if (acc_mode & MAY_APPEND)
57515+ reqmode |= GR_APPEND;
57516+ // if a directory was required or the directory already exists, then
57517+ // don't count this open as a read
57518+ if ((acc_mode & MAY_READ) &&
57519+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
57520+ reqmode |= GR_READ;
57521+ if ((open_flags & O_CREAT) &&
57522+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
57523+ reqmode |= GR_SETID;
57524+
57525+ mode =
57526+ gr_check_create(dentry, p_dentry, p_mnt,
57527+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
57528+
57529+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
57530+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
57531+ reqmode & GR_READ ? " reading" : "",
57532+ reqmode & GR_WRITE ? " writing" : reqmode &
57533+ GR_APPEND ? " appending" : "");
57534+ return reqmode;
57535+ } else
57536+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
57537+ {
57538+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
57539+ reqmode & GR_READ ? " reading" : "",
57540+ reqmode & GR_WRITE ? " writing" : reqmode &
57541+ GR_APPEND ? " appending" : "");
57542+ return 0;
57543+ } else if (unlikely((mode & reqmode) != reqmode))
57544+ return 0;
57545+
57546+ return reqmode;
57547+}
57548+
57549+__u32
57550+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
57551+ const int fmode)
57552+{
57553+ __u32 mode, reqmode = GR_FIND;
57554+
57555+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
57556+ reqmode |= GR_EXEC;
57557+ if (fmode & S_IWOTH)
57558+ reqmode |= GR_WRITE;
57559+ if (fmode & S_IROTH)
57560+ reqmode |= GR_READ;
57561+
57562+ mode =
57563+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
57564+ mnt);
57565+
57566+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
57567+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
57568+ reqmode & GR_READ ? " reading" : "",
57569+ reqmode & GR_WRITE ? " writing" : "",
57570+ reqmode & GR_EXEC ? " executing" : "");
57571+ return reqmode;
57572+ } else
57573+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
57574+ {
57575+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
57576+ reqmode & GR_READ ? " reading" : "",
57577+ reqmode & GR_WRITE ? " writing" : "",
57578+ reqmode & GR_EXEC ? " executing" : "");
57579+ return 0;
57580+ } else if (unlikely((mode & reqmode) != reqmode))
57581+ return 0;
57582+
57583+ return reqmode;
57584+}
57585+
57586+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
57587+{
57588+ __u32 mode;
57589+
57590+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
57591+
57592+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
57593+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
57594+ return mode;
57595+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
57596+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
57597+ return 0;
57598+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
57599+ return 0;
57600+
57601+ return (reqmode);
57602+}
57603+
57604+__u32
57605+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
57606+{
57607+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
57608+}
57609+
57610+__u32
57611+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
57612+{
57613+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
57614+}
57615+
57616+__u32
57617+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
57618+{
57619+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
57620+}
57621+
57622+__u32
57623+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
57624+{
57625+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
57626+}
57627+
57628+__u32
57629+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
57630+ umode_t *modeptr)
57631+{
57632+ umode_t mode;
57633+
57634+ *modeptr &= ~gr_acl_umask();
57635+ mode = *modeptr;
57636+
57637+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
57638+ return 1;
57639+
57640+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
57641+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
57642+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
57643+ GR_CHMOD_ACL_MSG);
57644+ } else {
57645+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
57646+ }
57647+}
57648+
57649+__u32
57650+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
57651+{
57652+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
57653+}
57654+
57655+__u32
57656+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
57657+{
57658+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
57659+}
57660+
57661+__u32
57662+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
57663+{
57664+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
57665+}
57666+
57667+__u32
57668+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
57669+{
57670+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
57671+ GR_UNIXCONNECT_ACL_MSG);
57672+}
57673+
57674+/* hardlinks require at minimum create and link permission,
57675+ any additional privilege required is based on the
57676+ privilege of the file being linked to
57677+*/
57678+__u32
57679+gr_acl_handle_link(const struct dentry * new_dentry,
57680+ const struct dentry * parent_dentry,
57681+ const struct vfsmount * parent_mnt,
57682+ const struct dentry * old_dentry,
57683+ const struct vfsmount * old_mnt, const struct filename *to)
57684+{
57685+ __u32 mode;
57686+ __u32 needmode = GR_CREATE | GR_LINK;
57687+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
57688+
57689+ mode =
57690+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
57691+ old_mnt);
57692+
57693+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
57694+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
57695+ return mode;
57696+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
57697+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
57698+ return 0;
57699+ } else if (unlikely((mode & needmode) != needmode))
57700+ return 0;
57701+
57702+ return 1;
57703+}
57704+
57705+__u32
57706+gr_acl_handle_symlink(const struct dentry * new_dentry,
57707+ const struct dentry * parent_dentry,
57708+ const struct vfsmount * parent_mnt, const struct filename *from)
57709+{
57710+ __u32 needmode = GR_WRITE | GR_CREATE;
57711+ __u32 mode;
57712+
57713+ mode =
57714+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
57715+ GR_CREATE | GR_AUDIT_CREATE |
57716+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
57717+
57718+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
57719+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
57720+ return mode;
57721+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
57722+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
57723+ return 0;
57724+ } else if (unlikely((mode & needmode) != needmode))
57725+ return 0;
57726+
57727+ return (GR_WRITE | GR_CREATE);
57728+}
57729+
57730+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)
57731+{
57732+ __u32 mode;
57733+
57734+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
57735+
57736+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
57737+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
57738+ return mode;
57739+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
57740+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
57741+ return 0;
57742+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
57743+ return 0;
57744+
57745+ return (reqmode);
57746+}
57747+
57748+__u32
57749+gr_acl_handle_mknod(const struct dentry * new_dentry,
57750+ const struct dentry * parent_dentry,
57751+ const struct vfsmount * parent_mnt,
57752+ const int mode)
57753+{
57754+ __u32 reqmode = GR_WRITE | GR_CREATE;
57755+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
57756+ reqmode |= GR_SETID;
57757+
57758+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
57759+ reqmode, GR_MKNOD_ACL_MSG);
57760+}
57761+
57762+__u32
57763+gr_acl_handle_mkdir(const struct dentry *new_dentry,
57764+ const struct dentry *parent_dentry,
57765+ const struct vfsmount *parent_mnt)
57766+{
57767+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
57768+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
57769+}
57770+
57771+#define RENAME_CHECK_SUCCESS(old, new) \
57772+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
57773+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
57774+
57775+int
57776+gr_acl_handle_rename(struct dentry *new_dentry,
57777+ struct dentry *parent_dentry,
57778+ const struct vfsmount *parent_mnt,
57779+ struct dentry *old_dentry,
57780+ struct inode *old_parent_inode,
57781+ struct vfsmount *old_mnt, const struct filename *newname)
57782+{
57783+ __u32 comp1, comp2;
57784+ int error = 0;
57785+
57786+ if (unlikely(!gr_acl_is_enabled()))
57787+ return 0;
57788+
57789+ if (!new_dentry->d_inode) {
57790+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
57791+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
57792+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
57793+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
57794+ GR_DELETE | GR_AUDIT_DELETE |
57795+ GR_AUDIT_READ | GR_AUDIT_WRITE |
57796+ GR_SUPPRESS, old_mnt);
57797+ } else {
57798+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
57799+ GR_CREATE | GR_DELETE |
57800+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
57801+ GR_AUDIT_READ | GR_AUDIT_WRITE |
57802+ GR_SUPPRESS, parent_mnt);
57803+ comp2 =
57804+ gr_search_file(old_dentry,
57805+ GR_READ | GR_WRITE | GR_AUDIT_READ |
57806+ GR_DELETE | GR_AUDIT_DELETE |
57807+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
57808+ }
57809+
57810+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
57811+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
57812+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
57813+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
57814+ && !(comp2 & GR_SUPPRESS)) {
57815+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
57816+ error = -EACCES;
57817+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
57818+ error = -EACCES;
57819+
57820+ return error;
57821+}
57822+
57823+void
57824+gr_acl_handle_exit(void)
57825+{
57826+ u16 id;
57827+ char *rolename;
57828+ struct file *exec_file;
57829+
57830+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
57831+ !(current->role->roletype & GR_ROLE_PERSIST))) {
57832+ id = current->acl_role_id;
57833+ rolename = current->role->rolename;
57834+ gr_set_acls(1);
57835+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
57836+ }
57837+
57838+ write_lock(&grsec_exec_file_lock);
57839+ exec_file = current->exec_file;
57840+ current->exec_file = NULL;
57841+ write_unlock(&grsec_exec_file_lock);
57842+
57843+ if (exec_file)
57844+ fput(exec_file);
57845+}
57846+
57847+int
57848+gr_acl_handle_procpidmem(const struct task_struct *task)
57849+{
57850+ if (unlikely(!gr_acl_is_enabled()))
57851+ return 0;
57852+
57853+ if (task != current && task->acl->mode & GR_PROTPROCFD)
57854+ return -EACCES;
57855+
57856+ return 0;
57857+}
57858diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
57859new file mode 100644
57860index 0000000..58800a7
57861--- /dev/null
57862+++ b/grsecurity/gracl_ip.c
57863@@ -0,0 +1,384 @@
57864+#include <linux/kernel.h>
57865+#include <asm/uaccess.h>
57866+#include <asm/errno.h>
57867+#include <net/sock.h>
57868+#include <linux/file.h>
57869+#include <linux/fs.h>
57870+#include <linux/net.h>
57871+#include <linux/in.h>
57872+#include <linux/skbuff.h>
57873+#include <linux/ip.h>
57874+#include <linux/udp.h>
57875+#include <linux/types.h>
57876+#include <linux/sched.h>
57877+#include <linux/netdevice.h>
57878+#include <linux/inetdevice.h>
57879+#include <linux/gracl.h>
57880+#include <linux/grsecurity.h>
57881+#include <linux/grinternal.h>
57882+
57883+#define GR_BIND 0x01
57884+#define GR_CONNECT 0x02
57885+#define GR_INVERT 0x04
57886+#define GR_BINDOVERRIDE 0x08
57887+#define GR_CONNECTOVERRIDE 0x10
57888+#define GR_SOCK_FAMILY 0x20
57889+
57890+static const char * gr_protocols[IPPROTO_MAX] = {
57891+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
57892+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
57893+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
57894+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
57895+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
57896+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
57897+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
57898+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
57899+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
57900+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
57901+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
57902+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
57903+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
57904+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
57905+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
57906+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
57907+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
57908+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
57909+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
57910+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
57911+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
57912+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
57913+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
57914+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
57915+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
57916+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
57917+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
57918+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
57919+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
57920+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
57921+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
57922+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
57923+ };
57924+
57925+static const char * gr_socktypes[SOCK_MAX] = {
57926+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
57927+ "unknown:7", "unknown:8", "unknown:9", "packet"
57928+ };
57929+
57930+static const char * gr_sockfamilies[AF_MAX+1] = {
57931+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
57932+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
57933+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
57934+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
57935+ };
57936+
57937+const char *
57938+gr_proto_to_name(unsigned char proto)
57939+{
57940+ return gr_protocols[proto];
57941+}
57942+
57943+const char *
57944+gr_socktype_to_name(unsigned char type)
57945+{
57946+ return gr_socktypes[type];
57947+}
57948+
57949+const char *
57950+gr_sockfamily_to_name(unsigned char family)
57951+{
57952+ return gr_sockfamilies[family];
57953+}
57954+
57955+int
57956+gr_search_socket(const int domain, const int type, const int protocol)
57957+{
57958+ struct acl_subject_label *curr;
57959+ const struct cred *cred = current_cred();
57960+
57961+ if (unlikely(!gr_acl_is_enabled()))
57962+ goto exit;
57963+
57964+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
57965+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
57966+ goto exit; // let the kernel handle it
57967+
57968+ curr = current->acl;
57969+
57970+ if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
57971+ /* the family is allowed, if this is PF_INET allow it only if
57972+ the extra sock type/protocol checks pass */
57973+ if (domain == PF_INET)
57974+ goto inet_check;
57975+ goto exit;
57976+ } else {
57977+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
57978+ __u32 fakeip = 0;
57979+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
57980+ current->role->roletype, cred->uid,
57981+ cred->gid, current->exec_file ?
57982+ gr_to_filename(current->exec_file->f_path.dentry,
57983+ current->exec_file->f_path.mnt) :
57984+ curr->filename, curr->filename,
57985+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
57986+ &current->signal->saved_ip);
57987+ goto exit;
57988+ }
57989+ goto exit_fail;
57990+ }
57991+
57992+inet_check:
57993+ /* the rest of this checking is for IPv4 only */
57994+ if (!curr->ips)
57995+ goto exit;
57996+
57997+ if ((curr->ip_type & (1 << type)) &&
57998+ (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
57999+ goto exit;
58000+
58001+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
58002+ /* we don't place acls on raw sockets , and sometimes
58003+ dgram/ip sockets are opened for ioctl and not
58004+ bind/connect, so we'll fake a bind learn log */
58005+ if (type == SOCK_RAW || type == SOCK_PACKET) {
58006+ __u32 fakeip = 0;
58007+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
58008+ current->role->roletype, cred->uid,
58009+ cred->gid, current->exec_file ?
58010+ gr_to_filename(current->exec_file->f_path.dentry,
58011+ current->exec_file->f_path.mnt) :
58012+ curr->filename, curr->filename,
58013+ &fakeip, 0, type,
58014+ protocol, GR_CONNECT, &current->signal->saved_ip);
58015+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
58016+ __u32 fakeip = 0;
58017+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
58018+ current->role->roletype, cred->uid,
58019+ cred->gid, current->exec_file ?
58020+ gr_to_filename(current->exec_file->f_path.dentry,
58021+ current->exec_file->f_path.mnt) :
58022+ curr->filename, curr->filename,
58023+ &fakeip, 0, type,
58024+ protocol, GR_BIND, &current->signal->saved_ip);
58025+ }
58026+ /* we'll log when they use connect or bind */
58027+ goto exit;
58028+ }
58029+
58030+exit_fail:
58031+ if (domain == PF_INET)
58032+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
58033+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
58034+ else
58035+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
58036+ gr_socktype_to_name(type), protocol);
58037+
58038+ return 0;
58039+exit:
58040+ return 1;
58041+}
58042+
58043+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)
58044+{
58045+ if ((ip->mode & mode) &&
58046+ (ip_port >= ip->low) &&
58047+ (ip_port <= ip->high) &&
58048+ ((ntohl(ip_addr) & our_netmask) ==
58049+ (ntohl(our_addr) & our_netmask))
58050+ && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
58051+ && (ip->type & (1 << type))) {
58052+ if (ip->mode & GR_INVERT)
58053+ return 2; // specifically denied
58054+ else
58055+ return 1; // allowed
58056+ }
58057+
58058+ return 0; // not specifically allowed, may continue parsing
58059+}
58060+
58061+static int
58062+gr_search_connectbind(const int full_mode, struct sock *sk,
58063+ struct sockaddr_in *addr, const int type)
58064+{
58065+ char iface[IFNAMSIZ] = {0};
58066+ struct acl_subject_label *curr;
58067+ struct acl_ip_label *ip;
58068+ struct inet_sock *isk;
58069+ struct net_device *dev;
58070+ struct in_device *idev;
58071+ unsigned long i;
58072+ int ret;
58073+ int mode = full_mode & (GR_BIND | GR_CONNECT);
58074+ __u32 ip_addr = 0;
58075+ __u32 our_addr;
58076+ __u32 our_netmask;
58077+ char *p;
58078+ __u16 ip_port = 0;
58079+ const struct cred *cred = current_cred();
58080+
58081+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
58082+ return 0;
58083+
58084+ curr = current->acl;
58085+ isk = inet_sk(sk);
58086+
58087+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
58088+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
58089+ addr->sin_addr.s_addr = curr->inaddr_any_override;
58090+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
58091+ struct sockaddr_in saddr;
58092+ int err;
58093+
58094+ saddr.sin_family = AF_INET;
58095+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
58096+ saddr.sin_port = isk->inet_sport;
58097+
58098+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
58099+ if (err)
58100+ return err;
58101+
58102+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
58103+ if (err)
58104+ return err;
58105+ }
58106+
58107+ if (!curr->ips)
58108+ return 0;
58109+
58110+ ip_addr = addr->sin_addr.s_addr;
58111+ ip_port = ntohs(addr->sin_port);
58112+
58113+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
58114+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
58115+ current->role->roletype, cred->uid,
58116+ cred->gid, current->exec_file ?
58117+ gr_to_filename(current->exec_file->f_path.dentry,
58118+ current->exec_file->f_path.mnt) :
58119+ curr->filename, curr->filename,
58120+ &ip_addr, ip_port, type,
58121+ sk->sk_protocol, mode, &current->signal->saved_ip);
58122+ return 0;
58123+ }
58124+
58125+ for (i = 0; i < curr->ip_num; i++) {
58126+ ip = *(curr->ips + i);
58127+ if (ip->iface != NULL) {
58128+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
58129+ p = strchr(iface, ':');
58130+ if (p != NULL)
58131+ *p = '\0';
58132+ dev = dev_get_by_name(sock_net(sk), iface);
58133+ if (dev == NULL)
58134+ continue;
58135+ idev = in_dev_get(dev);
58136+ if (idev == NULL) {
58137+ dev_put(dev);
58138+ continue;
58139+ }
58140+ rcu_read_lock();
58141+ for_ifa(idev) {
58142+ if (!strcmp(ip->iface, ifa->ifa_label)) {
58143+ our_addr = ifa->ifa_address;
58144+ our_netmask = 0xffffffff;
58145+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
58146+ if (ret == 1) {
58147+ rcu_read_unlock();
58148+ in_dev_put(idev);
58149+ dev_put(dev);
58150+ return 0;
58151+ } else if (ret == 2) {
58152+ rcu_read_unlock();
58153+ in_dev_put(idev);
58154+ dev_put(dev);
58155+ goto denied;
58156+ }
58157+ }
58158+ } endfor_ifa(idev);
58159+ rcu_read_unlock();
58160+ in_dev_put(idev);
58161+ dev_put(dev);
58162+ } else {
58163+ our_addr = ip->addr;
58164+ our_netmask = ip->netmask;
58165+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
58166+ if (ret == 1)
58167+ return 0;
58168+ else if (ret == 2)
58169+ goto denied;
58170+ }
58171+ }
58172+
58173+denied:
58174+ if (mode == GR_BIND)
58175+ 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));
58176+ else if (mode == GR_CONNECT)
58177+ 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));
58178+
58179+ return -EACCES;
58180+}
58181+
58182+int
58183+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
58184+{
58185+ /* always allow disconnection of dgram sockets with connect */
58186+ if (addr->sin_family == AF_UNSPEC)
58187+ return 0;
58188+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
58189+}
58190+
58191+int
58192+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
58193+{
58194+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
58195+}
58196+
58197+int gr_search_listen(struct socket *sock)
58198+{
58199+ struct sock *sk = sock->sk;
58200+ struct sockaddr_in addr;
58201+
58202+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
58203+ addr.sin_port = inet_sk(sk)->inet_sport;
58204+
58205+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
58206+}
58207+
58208+int gr_search_accept(struct socket *sock)
58209+{
58210+ struct sock *sk = sock->sk;
58211+ struct sockaddr_in addr;
58212+
58213+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
58214+ addr.sin_port = inet_sk(sk)->inet_sport;
58215+
58216+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
58217+}
58218+
58219+int
58220+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
58221+{
58222+ if (addr)
58223+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
58224+ else {
58225+ struct sockaddr_in sin;
58226+ const struct inet_sock *inet = inet_sk(sk);
58227+
58228+ sin.sin_addr.s_addr = inet->inet_daddr;
58229+ sin.sin_port = inet->inet_dport;
58230+
58231+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
58232+ }
58233+}
58234+
58235+int
58236+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
58237+{
58238+ struct sockaddr_in sin;
58239+
58240+ if (unlikely(skb->len < sizeof (struct udphdr)))
58241+ return 0; // skip this packet
58242+
58243+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
58244+ sin.sin_port = udp_hdr(skb)->source;
58245+
58246+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
58247+}
58248diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
58249new file mode 100644
58250index 0000000..25f54ef
58251--- /dev/null
58252+++ b/grsecurity/gracl_learn.c
58253@@ -0,0 +1,207 @@
58254+#include <linux/kernel.h>
58255+#include <linux/mm.h>
58256+#include <linux/sched.h>
58257+#include <linux/poll.h>
58258+#include <linux/string.h>
58259+#include <linux/file.h>
58260+#include <linux/types.h>
58261+#include <linux/vmalloc.h>
58262+#include <linux/grinternal.h>
58263+
58264+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
58265+ size_t count, loff_t *ppos);
58266+extern int gr_acl_is_enabled(void);
58267+
58268+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
58269+static int gr_learn_attached;
58270+
58271+/* use a 512k buffer */
58272+#define LEARN_BUFFER_SIZE (512 * 1024)
58273+
58274+static DEFINE_SPINLOCK(gr_learn_lock);
58275+static DEFINE_MUTEX(gr_learn_user_mutex);
58276+
58277+/* we need to maintain two buffers, so that the kernel context of grlearn
58278+ uses a semaphore around the userspace copying, and the other kernel contexts
58279+ use a spinlock when copying into the buffer, since they cannot sleep
58280+*/
58281+static char *learn_buffer;
58282+static char *learn_buffer_user;
58283+static int learn_buffer_len;
58284+static int learn_buffer_user_len;
58285+
58286+static ssize_t
58287+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
58288+{
58289+ DECLARE_WAITQUEUE(wait, current);
58290+ ssize_t retval = 0;
58291+
58292+ add_wait_queue(&learn_wait, &wait);
58293+ set_current_state(TASK_INTERRUPTIBLE);
58294+ do {
58295+ mutex_lock(&gr_learn_user_mutex);
58296+ spin_lock(&gr_learn_lock);
58297+ if (learn_buffer_len)
58298+ break;
58299+ spin_unlock(&gr_learn_lock);
58300+ mutex_unlock(&gr_learn_user_mutex);
58301+ if (file->f_flags & O_NONBLOCK) {
58302+ retval = -EAGAIN;
58303+ goto out;
58304+ }
58305+ if (signal_pending(current)) {
58306+ retval = -ERESTARTSYS;
58307+ goto out;
58308+ }
58309+
58310+ schedule();
58311+ } while (1);
58312+
58313+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
58314+ learn_buffer_user_len = learn_buffer_len;
58315+ retval = learn_buffer_len;
58316+ learn_buffer_len = 0;
58317+
58318+ spin_unlock(&gr_learn_lock);
58319+
58320+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
58321+ retval = -EFAULT;
58322+
58323+ mutex_unlock(&gr_learn_user_mutex);
58324+out:
58325+ set_current_state(TASK_RUNNING);
58326+ remove_wait_queue(&learn_wait, &wait);
58327+ return retval;
58328+}
58329+
58330+static unsigned int
58331+poll_learn(struct file * file, poll_table * wait)
58332+{
58333+ poll_wait(file, &learn_wait, wait);
58334+
58335+ if (learn_buffer_len)
58336+ return (POLLIN | POLLRDNORM);
58337+
58338+ return 0;
58339+}
58340+
58341+void
58342+gr_clear_learn_entries(void)
58343+{
58344+ char *tmp;
58345+
58346+ mutex_lock(&gr_learn_user_mutex);
58347+ spin_lock(&gr_learn_lock);
58348+ tmp = learn_buffer;
58349+ learn_buffer = NULL;
58350+ spin_unlock(&gr_learn_lock);
58351+ if (tmp)
58352+ vfree(tmp);
58353+ if (learn_buffer_user != NULL) {
58354+ vfree(learn_buffer_user);
58355+ learn_buffer_user = NULL;
58356+ }
58357+ learn_buffer_len = 0;
58358+ mutex_unlock(&gr_learn_user_mutex);
58359+
58360+ return;
58361+}
58362+
58363+void
58364+gr_add_learn_entry(const char *fmt, ...)
58365+{
58366+ va_list args;
58367+ unsigned int len;
58368+
58369+ if (!gr_learn_attached)
58370+ return;
58371+
58372+ spin_lock(&gr_learn_lock);
58373+
58374+ /* leave a gap at the end so we know when it's "full" but don't have to
58375+ compute the exact length of the string we're trying to append
58376+ */
58377+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
58378+ spin_unlock(&gr_learn_lock);
58379+ wake_up_interruptible(&learn_wait);
58380+ return;
58381+ }
58382+ if (learn_buffer == NULL) {
58383+ spin_unlock(&gr_learn_lock);
58384+ return;
58385+ }
58386+
58387+ va_start(args, fmt);
58388+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
58389+ va_end(args);
58390+
58391+ learn_buffer_len += len + 1;
58392+
58393+ spin_unlock(&gr_learn_lock);
58394+ wake_up_interruptible(&learn_wait);
58395+
58396+ return;
58397+}
58398+
58399+static int
58400+open_learn(struct inode *inode, struct file *file)
58401+{
58402+ if (file->f_mode & FMODE_READ && gr_learn_attached)
58403+ return -EBUSY;
58404+ if (file->f_mode & FMODE_READ) {
58405+ int retval = 0;
58406+ mutex_lock(&gr_learn_user_mutex);
58407+ if (learn_buffer == NULL)
58408+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
58409+ if (learn_buffer_user == NULL)
58410+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
58411+ if (learn_buffer == NULL) {
58412+ retval = -ENOMEM;
58413+ goto out_error;
58414+ }
58415+ if (learn_buffer_user == NULL) {
58416+ retval = -ENOMEM;
58417+ goto out_error;
58418+ }
58419+ learn_buffer_len = 0;
58420+ learn_buffer_user_len = 0;
58421+ gr_learn_attached = 1;
58422+out_error:
58423+ mutex_unlock(&gr_learn_user_mutex);
58424+ return retval;
58425+ }
58426+ return 0;
58427+}
58428+
58429+static int
58430+close_learn(struct inode *inode, struct file *file)
58431+{
58432+ if (file->f_mode & FMODE_READ) {
58433+ char *tmp = NULL;
58434+ mutex_lock(&gr_learn_user_mutex);
58435+ spin_lock(&gr_learn_lock);
58436+ tmp = learn_buffer;
58437+ learn_buffer = NULL;
58438+ spin_unlock(&gr_learn_lock);
58439+ if (tmp)
58440+ vfree(tmp);
58441+ if (learn_buffer_user != NULL) {
58442+ vfree(learn_buffer_user);
58443+ learn_buffer_user = NULL;
58444+ }
58445+ learn_buffer_len = 0;
58446+ learn_buffer_user_len = 0;
58447+ gr_learn_attached = 0;
58448+ mutex_unlock(&gr_learn_user_mutex);
58449+ }
58450+
58451+ return 0;
58452+}
58453+
58454+const struct file_operations grsec_fops = {
58455+ .read = read_learn,
58456+ .write = write_grsec_handler,
58457+ .open = open_learn,
58458+ .release = close_learn,
58459+ .poll = poll_learn,
58460+};
58461diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
58462new file mode 100644
58463index 0000000..39645c9
58464--- /dev/null
58465+++ b/grsecurity/gracl_res.c
58466@@ -0,0 +1,68 @@
58467+#include <linux/kernel.h>
58468+#include <linux/sched.h>
58469+#include <linux/gracl.h>
58470+#include <linux/grinternal.h>
58471+
58472+static const char *restab_log[] = {
58473+ [RLIMIT_CPU] = "RLIMIT_CPU",
58474+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
58475+ [RLIMIT_DATA] = "RLIMIT_DATA",
58476+ [RLIMIT_STACK] = "RLIMIT_STACK",
58477+ [RLIMIT_CORE] = "RLIMIT_CORE",
58478+ [RLIMIT_RSS] = "RLIMIT_RSS",
58479+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
58480+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
58481+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
58482+ [RLIMIT_AS] = "RLIMIT_AS",
58483+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
58484+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
58485+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
58486+ [RLIMIT_NICE] = "RLIMIT_NICE",
58487+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
58488+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
58489+ [GR_CRASH_RES] = "RLIMIT_CRASH"
58490+};
58491+
58492+void
58493+gr_log_resource(const struct task_struct *task,
58494+ const int res, const unsigned long wanted, const int gt)
58495+{
58496+ const struct cred *cred;
58497+ unsigned long rlim;
58498+
58499+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
58500+ return;
58501+
58502+ // not yet supported resource
58503+ if (unlikely(!restab_log[res]))
58504+ return;
58505+
58506+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
58507+ rlim = task_rlimit_max(task, res);
58508+ else
58509+ rlim = task_rlimit(task, res);
58510+
58511+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
58512+ return;
58513+
58514+ rcu_read_lock();
58515+ cred = __task_cred(task);
58516+
58517+ if (res == RLIMIT_NPROC &&
58518+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
58519+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
58520+ goto out_rcu_unlock;
58521+ else if (res == RLIMIT_MEMLOCK &&
58522+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
58523+ goto out_rcu_unlock;
58524+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
58525+ goto out_rcu_unlock;
58526+ rcu_read_unlock();
58527+
58528+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
58529+
58530+ return;
58531+out_rcu_unlock:
58532+ rcu_read_unlock();
58533+ return;
58534+}
58535diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
58536new file mode 100644
58537index 0000000..25197e9
58538--- /dev/null
58539+++ b/grsecurity/gracl_segv.c
58540@@ -0,0 +1,299 @@
58541+#include <linux/kernel.h>
58542+#include <linux/mm.h>
58543+#include <asm/uaccess.h>
58544+#include <asm/errno.h>
58545+#include <asm/mman.h>
58546+#include <net/sock.h>
58547+#include <linux/file.h>
58548+#include <linux/fs.h>
58549+#include <linux/net.h>
58550+#include <linux/in.h>
58551+#include <linux/slab.h>
58552+#include <linux/types.h>
58553+#include <linux/sched.h>
58554+#include <linux/timer.h>
58555+#include <linux/gracl.h>
58556+#include <linux/grsecurity.h>
58557+#include <linux/grinternal.h>
58558+
58559+static struct crash_uid *uid_set;
58560+static unsigned short uid_used;
58561+static DEFINE_SPINLOCK(gr_uid_lock);
58562+extern rwlock_t gr_inode_lock;
58563+extern struct acl_subject_label *
58564+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
58565+ struct acl_role_label *role);
58566+
58567+#ifdef CONFIG_BTRFS_FS
58568+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
58569+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
58570+#endif
58571+
58572+static inline dev_t __get_dev(const struct dentry *dentry)
58573+{
58574+#ifdef CONFIG_BTRFS_FS
58575+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
58576+ return get_btrfs_dev_from_inode(dentry->d_inode);
58577+ else
58578+#endif
58579+ return dentry->d_inode->i_sb->s_dev;
58580+}
58581+
58582+int
58583+gr_init_uidset(void)
58584+{
58585+ uid_set =
58586+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
58587+ uid_used = 0;
58588+
58589+ return uid_set ? 1 : 0;
58590+}
58591+
58592+void
58593+gr_free_uidset(void)
58594+{
58595+ if (uid_set)
58596+ kfree(uid_set);
58597+
58598+ return;
58599+}
58600+
58601+int
58602+gr_find_uid(const uid_t uid)
58603+{
58604+ struct crash_uid *tmp = uid_set;
58605+ uid_t buid;
58606+ int low = 0, high = uid_used - 1, mid;
58607+
58608+ while (high >= low) {
58609+ mid = (low + high) >> 1;
58610+ buid = tmp[mid].uid;
58611+ if (buid == uid)
58612+ return mid;
58613+ if (buid > uid)
58614+ high = mid - 1;
58615+ if (buid < uid)
58616+ low = mid + 1;
58617+ }
58618+
58619+ return -1;
58620+}
58621+
58622+static __inline__ void
58623+gr_insertsort(void)
58624+{
58625+ unsigned short i, j;
58626+ struct crash_uid index;
58627+
58628+ for (i = 1; i < uid_used; i++) {
58629+ index = uid_set[i];
58630+ j = i;
58631+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
58632+ uid_set[j] = uid_set[j - 1];
58633+ j--;
58634+ }
58635+ uid_set[j] = index;
58636+ }
58637+
58638+ return;
58639+}
58640+
58641+static __inline__ void
58642+gr_insert_uid(const uid_t uid, const unsigned long expires)
58643+{
58644+ int loc;
58645+
58646+ if (uid_used == GR_UIDTABLE_MAX)
58647+ return;
58648+
58649+ loc = gr_find_uid(uid);
58650+
58651+ if (loc >= 0) {
58652+ uid_set[loc].expires = expires;
58653+ return;
58654+ }
58655+
58656+ uid_set[uid_used].uid = uid;
58657+ uid_set[uid_used].expires = expires;
58658+ uid_used++;
58659+
58660+ gr_insertsort();
58661+
58662+ return;
58663+}
58664+
58665+void
58666+gr_remove_uid(const unsigned short loc)
58667+{
58668+ unsigned short i;
58669+
58670+ for (i = loc + 1; i < uid_used; i++)
58671+ uid_set[i - 1] = uid_set[i];
58672+
58673+ uid_used--;
58674+
58675+ return;
58676+}
58677+
58678+int
58679+gr_check_crash_uid(const uid_t uid)
58680+{
58681+ int loc;
58682+ int ret = 0;
58683+
58684+ if (unlikely(!gr_acl_is_enabled()))
58685+ return 0;
58686+
58687+ spin_lock(&gr_uid_lock);
58688+ loc = gr_find_uid(uid);
58689+
58690+ if (loc < 0)
58691+ goto out_unlock;
58692+
58693+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
58694+ gr_remove_uid(loc);
58695+ else
58696+ ret = 1;
58697+
58698+out_unlock:
58699+ spin_unlock(&gr_uid_lock);
58700+ return ret;
58701+}
58702+
58703+static __inline__ int
58704+proc_is_setxid(const struct cred *cred)
58705+{
58706+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
58707+ !uid_eq(cred->uid, cred->fsuid))
58708+ return 1;
58709+ if (!uid_eq(cred->gid, cred->egid) || !uid_eq(cred->gid, cred->sgid) ||
58710+ !uid_eq(cred->gid, cred->fsgid))
58711+ return 1;
58712+
58713+ return 0;
58714+}
58715+
58716+extern int gr_fake_force_sig(int sig, struct task_struct *t);
58717+
58718+void
58719+gr_handle_crash(struct task_struct *task, const int sig)
58720+{
58721+ struct acl_subject_label *curr;
58722+ struct task_struct *tsk, *tsk2;
58723+ const struct cred *cred;
58724+ const struct cred *cred2;
58725+
58726+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
58727+ return;
58728+
58729+ if (unlikely(!gr_acl_is_enabled()))
58730+ return;
58731+
58732+ curr = task->acl;
58733+
58734+ if (!(curr->resmask & (1 << GR_CRASH_RES)))
58735+ return;
58736+
58737+ if (time_before_eq(curr->expires, get_seconds())) {
58738+ curr->expires = 0;
58739+ curr->crashes = 0;
58740+ }
58741+
58742+ curr->crashes++;
58743+
58744+ if (!curr->expires)
58745+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
58746+
58747+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
58748+ time_after(curr->expires, get_seconds())) {
58749+ rcu_read_lock();
58750+ cred = __task_cred(task);
58751+ if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && proc_is_setxid(cred)) {
58752+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
58753+ spin_lock(&gr_uid_lock);
58754+ gr_insert_uid(cred->uid, curr->expires);
58755+ spin_unlock(&gr_uid_lock);
58756+ curr->expires = 0;
58757+ curr->crashes = 0;
58758+ read_lock(&tasklist_lock);
58759+ do_each_thread(tsk2, tsk) {
58760+ cred2 = __task_cred(tsk);
58761+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
58762+ gr_fake_force_sig(SIGKILL, tsk);
58763+ } while_each_thread(tsk2, tsk);
58764+ read_unlock(&tasklist_lock);
58765+ } else {
58766+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
58767+ read_lock(&tasklist_lock);
58768+ read_lock(&grsec_exec_file_lock);
58769+ do_each_thread(tsk2, tsk) {
58770+ if (likely(tsk != task)) {
58771+ // if this thread has the same subject as the one that triggered
58772+ // RES_CRASH and it's the same binary, kill it
58773+ if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
58774+ gr_fake_force_sig(SIGKILL, tsk);
58775+ }
58776+ } while_each_thread(tsk2, tsk);
58777+ read_unlock(&grsec_exec_file_lock);
58778+ read_unlock(&tasklist_lock);
58779+ }
58780+ rcu_read_unlock();
58781+ }
58782+
58783+ return;
58784+}
58785+
58786+int
58787+gr_check_crash_exec(const struct file *filp)
58788+{
58789+ struct acl_subject_label *curr;
58790+
58791+ if (unlikely(!gr_acl_is_enabled()))
58792+ return 0;
58793+
58794+ read_lock(&gr_inode_lock);
58795+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
58796+ __get_dev(filp->f_path.dentry),
58797+ current->role);
58798+ read_unlock(&gr_inode_lock);
58799+
58800+ if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
58801+ (!curr->crashes && !curr->expires))
58802+ return 0;
58803+
58804+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
58805+ time_after(curr->expires, get_seconds()))
58806+ return 1;
58807+ else if (time_before_eq(curr->expires, get_seconds())) {
58808+ curr->crashes = 0;
58809+ curr->expires = 0;
58810+ }
58811+
58812+ return 0;
58813+}
58814+
58815+void
58816+gr_handle_alertkill(struct task_struct *task)
58817+{
58818+ struct acl_subject_label *curracl;
58819+ __u32 curr_ip;
58820+ struct task_struct *p, *p2;
58821+
58822+ if (unlikely(!gr_acl_is_enabled()))
58823+ return;
58824+
58825+ curracl = task->acl;
58826+ curr_ip = task->signal->curr_ip;
58827+
58828+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
58829+ read_lock(&tasklist_lock);
58830+ do_each_thread(p2, p) {
58831+ if (p->signal->curr_ip == curr_ip)
58832+ gr_fake_force_sig(SIGKILL, p);
58833+ } while_each_thread(p2, p);
58834+ read_unlock(&tasklist_lock);
58835+ } else if (curracl->mode & GR_KILLPROC)
58836+ gr_fake_force_sig(SIGKILL, task);
58837+
58838+ return;
58839+}
58840diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
58841new file mode 100644
58842index 0000000..9d83a69
58843--- /dev/null
58844+++ b/grsecurity/gracl_shm.c
58845@@ -0,0 +1,40 @@
58846+#include <linux/kernel.h>
58847+#include <linux/mm.h>
58848+#include <linux/sched.h>
58849+#include <linux/file.h>
58850+#include <linux/ipc.h>
58851+#include <linux/gracl.h>
58852+#include <linux/grsecurity.h>
58853+#include <linux/grinternal.h>
58854+
58855+int
58856+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
58857+ const time_t shm_createtime, const uid_t cuid, const int shmid)
58858+{
58859+ struct task_struct *task;
58860+
58861+ if (!gr_acl_is_enabled())
58862+ return 1;
58863+
58864+ rcu_read_lock();
58865+ read_lock(&tasklist_lock);
58866+
58867+ task = find_task_by_vpid(shm_cprid);
58868+
58869+ if (unlikely(!task))
58870+ task = find_task_by_vpid(shm_lapid);
58871+
58872+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
58873+ (task->pid == shm_lapid)) &&
58874+ (task->acl->mode & GR_PROTSHM) &&
58875+ (task->acl != current->acl))) {
58876+ read_unlock(&tasklist_lock);
58877+ rcu_read_unlock();
58878+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
58879+ return 0;
58880+ }
58881+ read_unlock(&tasklist_lock);
58882+ rcu_read_unlock();
58883+
58884+ return 1;
58885+}
58886diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
58887new file mode 100644
58888index 0000000..bc0be01
58889--- /dev/null
58890+++ b/grsecurity/grsec_chdir.c
58891@@ -0,0 +1,19 @@
58892+#include <linux/kernel.h>
58893+#include <linux/sched.h>
58894+#include <linux/fs.h>
58895+#include <linux/file.h>
58896+#include <linux/grsecurity.h>
58897+#include <linux/grinternal.h>
58898+
58899+void
58900+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
58901+{
58902+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
58903+ if ((grsec_enable_chdir && grsec_enable_group &&
58904+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
58905+ !grsec_enable_group)) {
58906+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
58907+ }
58908+#endif
58909+ return;
58910+}
58911diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
58912new file mode 100644
58913index 0000000..9807ee2
58914--- /dev/null
58915+++ b/grsecurity/grsec_chroot.c
58916@@ -0,0 +1,368 @@
58917+#include <linux/kernel.h>
58918+#include <linux/module.h>
58919+#include <linux/sched.h>
58920+#include <linux/file.h>
58921+#include <linux/fs.h>
58922+#include <linux/mount.h>
58923+#include <linux/types.h>
58924+#include "../fs/mount.h"
58925+#include <linux/grsecurity.h>
58926+#include <linux/grinternal.h>
58927+
58928+void gr_set_chroot_entries(struct task_struct *task, struct path *path)
58929+{
58930+#ifdef CONFIG_GRKERNSEC
58931+ if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
58932+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
58933+ task->gr_is_chrooted = 1;
58934+ else
58935+ task->gr_is_chrooted = 0;
58936+
58937+ task->gr_chroot_dentry = path->dentry;
58938+#endif
58939+ return;
58940+}
58941+
58942+void gr_clear_chroot_entries(struct task_struct *task)
58943+{
58944+#ifdef CONFIG_GRKERNSEC
58945+ task->gr_is_chrooted = 0;
58946+ task->gr_chroot_dentry = NULL;
58947+#endif
58948+ return;
58949+}
58950+
58951+int
58952+gr_handle_chroot_unix(const pid_t pid)
58953+{
58954+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
58955+ struct task_struct *p;
58956+
58957+ if (unlikely(!grsec_enable_chroot_unix))
58958+ return 1;
58959+
58960+ if (likely(!proc_is_chrooted(current)))
58961+ return 1;
58962+
58963+ rcu_read_lock();
58964+ read_lock(&tasklist_lock);
58965+ p = find_task_by_vpid_unrestricted(pid);
58966+ if (unlikely(p && !have_same_root(current, p))) {
58967+ read_unlock(&tasklist_lock);
58968+ rcu_read_unlock();
58969+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
58970+ return 0;
58971+ }
58972+ read_unlock(&tasklist_lock);
58973+ rcu_read_unlock();
58974+#endif
58975+ return 1;
58976+}
58977+
58978+int
58979+gr_handle_chroot_nice(void)
58980+{
58981+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
58982+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
58983+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
58984+ return -EPERM;
58985+ }
58986+#endif
58987+ return 0;
58988+}
58989+
58990+int
58991+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
58992+{
58993+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
58994+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
58995+ && proc_is_chrooted(current)) {
58996+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
58997+ return -EACCES;
58998+ }
58999+#endif
59000+ return 0;
59001+}
59002+
59003+int
59004+gr_handle_chroot_rawio(const struct inode *inode)
59005+{
59006+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59007+ if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
59008+ inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
59009+ return 1;
59010+#endif
59011+ return 0;
59012+}
59013+
59014+int
59015+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
59016+{
59017+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
59018+ struct task_struct *p;
59019+ int ret = 0;
59020+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
59021+ return ret;
59022+
59023+ read_lock(&tasklist_lock);
59024+ do_each_pid_task(pid, type, p) {
59025+ if (!have_same_root(current, p)) {
59026+ ret = 1;
59027+ goto out;
59028+ }
59029+ } while_each_pid_task(pid, type, p);
59030+out:
59031+ read_unlock(&tasklist_lock);
59032+ return ret;
59033+#endif
59034+ return 0;
59035+}
59036+
59037+int
59038+gr_pid_is_chrooted(struct task_struct *p)
59039+{
59040+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
59041+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
59042+ return 0;
59043+
59044+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
59045+ !have_same_root(current, p)) {
59046+ return 1;
59047+ }
59048+#endif
59049+ return 0;
59050+}
59051+
59052+EXPORT_SYMBOL(gr_pid_is_chrooted);
59053+
59054+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
59055+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
59056+{
59057+ struct path path, currentroot;
59058+ int ret = 0;
59059+
59060+ path.dentry = (struct dentry *)u_dentry;
59061+ path.mnt = (struct vfsmount *)u_mnt;
59062+ get_fs_root(current->fs, &currentroot);
59063+ if (path_is_under(&path, &currentroot))
59064+ ret = 1;
59065+ path_put(&currentroot);
59066+
59067+ return ret;
59068+}
59069+#endif
59070+
59071+int
59072+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
59073+{
59074+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
59075+ if (!grsec_enable_chroot_fchdir)
59076+ return 1;
59077+
59078+ if (!proc_is_chrooted(current))
59079+ return 1;
59080+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
59081+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
59082+ return 0;
59083+ }
59084+#endif
59085+ return 1;
59086+}
59087+
59088+int
59089+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
59090+ const time_t shm_createtime)
59091+{
59092+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
59093+ struct task_struct *p;
59094+ time_t starttime;
59095+
59096+ if (unlikely(!grsec_enable_chroot_shmat))
59097+ return 1;
59098+
59099+ if (likely(!proc_is_chrooted(current)))
59100+ return 1;
59101+
59102+ rcu_read_lock();
59103+ read_lock(&tasklist_lock);
59104+
59105+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
59106+ starttime = p->start_time.tv_sec;
59107+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
59108+ if (have_same_root(current, p)) {
59109+ goto allow;
59110+ } else {
59111+ read_unlock(&tasklist_lock);
59112+ rcu_read_unlock();
59113+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
59114+ return 0;
59115+ }
59116+ }
59117+ /* creator exited, pid reuse, fall through to next check */
59118+ }
59119+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
59120+ if (unlikely(!have_same_root(current, p))) {
59121+ read_unlock(&tasklist_lock);
59122+ rcu_read_unlock();
59123+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
59124+ return 0;
59125+ }
59126+ }
59127+
59128+allow:
59129+ read_unlock(&tasklist_lock);
59130+ rcu_read_unlock();
59131+#endif
59132+ return 1;
59133+}
59134+
59135+void
59136+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
59137+{
59138+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
59139+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
59140+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
59141+#endif
59142+ return;
59143+}
59144+
59145+int
59146+gr_handle_chroot_mknod(const struct dentry *dentry,
59147+ const struct vfsmount *mnt, const int mode)
59148+{
59149+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
59150+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
59151+ proc_is_chrooted(current)) {
59152+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
59153+ return -EPERM;
59154+ }
59155+#endif
59156+ return 0;
59157+}
59158+
59159+int
59160+gr_handle_chroot_mount(const struct dentry *dentry,
59161+ const struct vfsmount *mnt, const char *dev_name)
59162+{
59163+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
59164+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
59165+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
59166+ return -EPERM;
59167+ }
59168+#endif
59169+ return 0;
59170+}
59171+
59172+int
59173+gr_handle_chroot_pivot(void)
59174+{
59175+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
59176+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
59177+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
59178+ return -EPERM;
59179+ }
59180+#endif
59181+ return 0;
59182+}
59183+
59184+int
59185+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
59186+{
59187+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
59188+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
59189+ !gr_is_outside_chroot(dentry, mnt)) {
59190+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
59191+ return -EPERM;
59192+ }
59193+#endif
59194+ return 0;
59195+}
59196+
59197+extern const char *captab_log[];
59198+extern int captab_log_entries;
59199+
59200+int
59201+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
59202+{
59203+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59204+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
59205+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
59206+ if (cap_raised(chroot_caps, cap)) {
59207+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
59208+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
59209+ }
59210+ return 0;
59211+ }
59212+ }
59213+#endif
59214+ return 1;
59215+}
59216+
59217+int
59218+gr_chroot_is_capable(const int cap)
59219+{
59220+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59221+ return gr_task_chroot_is_capable(current, current_cred(), cap);
59222+#endif
59223+ return 1;
59224+}
59225+
59226+int
59227+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
59228+{
59229+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59230+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
59231+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
59232+ if (cap_raised(chroot_caps, cap)) {
59233+ return 0;
59234+ }
59235+ }
59236+#endif
59237+ return 1;
59238+}
59239+
59240+int
59241+gr_chroot_is_capable_nolog(const int cap)
59242+{
59243+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59244+ return gr_task_chroot_is_capable_nolog(current, cap);
59245+#endif
59246+ return 1;
59247+}
59248+
59249+int
59250+gr_handle_chroot_sysctl(const int op)
59251+{
59252+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
59253+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
59254+ proc_is_chrooted(current))
59255+ return -EACCES;
59256+#endif
59257+ return 0;
59258+}
59259+
59260+void
59261+gr_handle_chroot_chdir(struct path *path)
59262+{
59263+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
59264+ if (grsec_enable_chroot_chdir)
59265+ set_fs_pwd(current->fs, path);
59266+#endif
59267+ return;
59268+}
59269+
59270+int
59271+gr_handle_chroot_chmod(const struct dentry *dentry,
59272+ const struct vfsmount *mnt, const int mode)
59273+{
59274+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
59275+ /* allow chmod +s on directories, but not files */
59276+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
59277+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
59278+ proc_is_chrooted(current)) {
59279+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
59280+ return -EPERM;
59281+ }
59282+#endif
59283+ return 0;
59284+}
59285diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
59286new file mode 100644
59287index 0000000..7de2055
59288--- /dev/null
59289+++ b/grsecurity/grsec_disabled.c
59290@@ -0,0 +1,442 @@
59291+#include <linux/kernel.h>
59292+#include <linux/module.h>
59293+#include <linux/sched.h>
59294+#include <linux/file.h>
59295+#include <linux/fs.h>
59296+#include <linux/kdev_t.h>
59297+#include <linux/net.h>
59298+#include <linux/in.h>
59299+#include <linux/ip.h>
59300+#include <linux/skbuff.h>
59301+#include <linux/sysctl.h>
59302+
59303+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
59304+void
59305+pax_set_initial_flags(struct linux_binprm *bprm)
59306+{
59307+ return;
59308+}
59309+#endif
59310+
59311+#ifdef CONFIG_SYSCTL
59312+__u32
59313+gr_handle_sysctl(const struct ctl_table * table, const int op)
59314+{
59315+ return 0;
59316+}
59317+#endif
59318+
59319+#ifdef CONFIG_TASKSTATS
59320+int gr_is_taskstats_denied(int pid)
59321+{
59322+ return 0;
59323+}
59324+#endif
59325+
59326+int
59327+gr_acl_is_enabled(void)
59328+{
59329+ return 0;
59330+}
59331+
59332+void
59333+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
59334+{
59335+ return;
59336+}
59337+
59338+int
59339+gr_handle_rawio(const struct inode *inode)
59340+{
59341+ return 0;
59342+}
59343+
59344+void
59345+gr_acl_handle_psacct(struct task_struct *task, const long code)
59346+{
59347+ return;
59348+}
59349+
59350+int
59351+gr_handle_ptrace(struct task_struct *task, const long request)
59352+{
59353+ return 0;
59354+}
59355+
59356+int
59357+gr_handle_proc_ptrace(struct task_struct *task)
59358+{
59359+ return 0;
59360+}
59361+
59362+void
59363+gr_learn_resource(const struct task_struct *task,
59364+ const int res, const unsigned long wanted, const int gt)
59365+{
59366+ return;
59367+}
59368+
59369+int
59370+gr_set_acls(const int type)
59371+{
59372+ return 0;
59373+}
59374+
59375+int
59376+gr_check_hidden_task(const struct task_struct *tsk)
59377+{
59378+ return 0;
59379+}
59380+
59381+int
59382+gr_check_protected_task(const struct task_struct *task)
59383+{
59384+ return 0;
59385+}
59386+
59387+int
59388+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
59389+{
59390+ return 0;
59391+}
59392+
59393+void
59394+gr_copy_label(struct task_struct *tsk)
59395+{
59396+ return;
59397+}
59398+
59399+void
59400+gr_set_pax_flags(struct task_struct *task)
59401+{
59402+ return;
59403+}
59404+
59405+int
59406+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
59407+ const int unsafe_share)
59408+{
59409+ return 0;
59410+}
59411+
59412+void
59413+gr_handle_delete(const ino_t ino, const dev_t dev)
59414+{
59415+ return;
59416+}
59417+
59418+void
59419+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
59420+{
59421+ return;
59422+}
59423+
59424+void
59425+gr_handle_crash(struct task_struct *task, const int sig)
59426+{
59427+ return;
59428+}
59429+
59430+int
59431+gr_check_crash_exec(const struct file *filp)
59432+{
59433+ return 0;
59434+}
59435+
59436+int
59437+gr_check_crash_uid(const uid_t uid)
59438+{
59439+ return 0;
59440+}
59441+
59442+void
59443+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
59444+ struct dentry *old_dentry,
59445+ struct dentry *new_dentry,
59446+ struct vfsmount *mnt, const __u8 replace)
59447+{
59448+ return;
59449+}
59450+
59451+int
59452+gr_search_socket(const int family, const int type, const int protocol)
59453+{
59454+ return 1;
59455+}
59456+
59457+int
59458+gr_search_connectbind(const int mode, const struct socket *sock,
59459+ const struct sockaddr_in *addr)
59460+{
59461+ return 0;
59462+}
59463+
59464+void
59465+gr_handle_alertkill(struct task_struct *task)
59466+{
59467+ return;
59468+}
59469+
59470+__u32
59471+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
59472+{
59473+ return 1;
59474+}
59475+
59476+__u32
59477+gr_acl_handle_hidden_file(const struct dentry * dentry,
59478+ const struct vfsmount * mnt)
59479+{
59480+ return 1;
59481+}
59482+
59483+__u32
59484+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
59485+ int acc_mode)
59486+{
59487+ return 1;
59488+}
59489+
59490+__u32
59491+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
59492+{
59493+ return 1;
59494+}
59495+
59496+__u32
59497+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
59498+{
59499+ return 1;
59500+}
59501+
59502+int
59503+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
59504+ unsigned int *vm_flags)
59505+{
59506+ return 1;
59507+}
59508+
59509+__u32
59510+gr_acl_handle_truncate(const struct dentry * dentry,
59511+ const struct vfsmount * mnt)
59512+{
59513+ return 1;
59514+}
59515+
59516+__u32
59517+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
59518+{
59519+ return 1;
59520+}
59521+
59522+__u32
59523+gr_acl_handle_access(const struct dentry * dentry,
59524+ const struct vfsmount * mnt, const int fmode)
59525+{
59526+ return 1;
59527+}
59528+
59529+__u32
59530+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
59531+ umode_t *mode)
59532+{
59533+ return 1;
59534+}
59535+
59536+__u32
59537+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
59538+{
59539+ return 1;
59540+}
59541+
59542+__u32
59543+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
59544+{
59545+ return 1;
59546+}
59547+
59548+void
59549+grsecurity_init(void)
59550+{
59551+ return;
59552+}
59553+
59554+umode_t gr_acl_umask(void)
59555+{
59556+ return 0;
59557+}
59558+
59559+__u32
59560+gr_acl_handle_mknod(const struct dentry * new_dentry,
59561+ const struct dentry * parent_dentry,
59562+ const struct vfsmount * parent_mnt,
59563+ const int mode)
59564+{
59565+ return 1;
59566+}
59567+
59568+__u32
59569+gr_acl_handle_mkdir(const struct dentry * new_dentry,
59570+ const struct dentry * parent_dentry,
59571+ const struct vfsmount * parent_mnt)
59572+{
59573+ return 1;
59574+}
59575+
59576+__u32
59577+gr_acl_handle_symlink(const struct dentry * new_dentry,
59578+ const struct dentry * parent_dentry,
59579+ const struct vfsmount * parent_mnt, const struct filename *from)
59580+{
59581+ return 1;
59582+}
59583+
59584+__u32
59585+gr_acl_handle_link(const struct dentry * new_dentry,
59586+ const struct dentry * parent_dentry,
59587+ const struct vfsmount * parent_mnt,
59588+ const struct dentry * old_dentry,
59589+ const struct vfsmount * old_mnt, const struct filename *to)
59590+{
59591+ return 1;
59592+}
59593+
59594+int
59595+gr_acl_handle_rename(const struct dentry *new_dentry,
59596+ const struct dentry *parent_dentry,
59597+ const struct vfsmount *parent_mnt,
59598+ const struct dentry *old_dentry,
59599+ const struct inode *old_parent_inode,
59600+ const struct vfsmount *old_mnt, const struct filename *newname)
59601+{
59602+ return 0;
59603+}
59604+
59605+int
59606+gr_acl_handle_filldir(const struct file *file, const char *name,
59607+ const int namelen, const ino_t ino)
59608+{
59609+ return 1;
59610+}
59611+
59612+int
59613+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
59614+ const time_t shm_createtime, const uid_t cuid, const int shmid)
59615+{
59616+ return 1;
59617+}
59618+
59619+int
59620+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
59621+{
59622+ return 0;
59623+}
59624+
59625+int
59626+gr_search_accept(const struct socket *sock)
59627+{
59628+ return 0;
59629+}
59630+
59631+int
59632+gr_search_listen(const struct socket *sock)
59633+{
59634+ return 0;
59635+}
59636+
59637+int
59638+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
59639+{
59640+ return 0;
59641+}
59642+
59643+__u32
59644+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
59645+{
59646+ return 1;
59647+}
59648+
59649+__u32
59650+gr_acl_handle_creat(const struct dentry * dentry,
59651+ const struct dentry * p_dentry,
59652+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
59653+ const int imode)
59654+{
59655+ return 1;
59656+}
59657+
59658+void
59659+gr_acl_handle_exit(void)
59660+{
59661+ return;
59662+}
59663+
59664+int
59665+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
59666+{
59667+ return 1;
59668+}
59669+
59670+void
59671+gr_set_role_label(const uid_t uid, const gid_t gid)
59672+{
59673+ return;
59674+}
59675+
59676+int
59677+gr_acl_handle_procpidmem(const struct task_struct *task)
59678+{
59679+ return 0;
59680+}
59681+
59682+int
59683+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
59684+{
59685+ return 0;
59686+}
59687+
59688+int
59689+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
59690+{
59691+ return 0;
59692+}
59693+
59694+void
59695+gr_set_kernel_label(struct task_struct *task)
59696+{
59697+ return;
59698+}
59699+
59700+int
59701+gr_check_user_change(int real, int effective, int fs)
59702+{
59703+ return 0;
59704+}
59705+
59706+int
59707+gr_check_group_change(int real, int effective, int fs)
59708+{
59709+ return 0;
59710+}
59711+
59712+int gr_acl_enable_at_secure(void)
59713+{
59714+ return 0;
59715+}
59716+
59717+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
59718+{
59719+ return dentry->d_inode->i_sb->s_dev;
59720+}
59721+
59722+void gr_put_exec_file(struct task_struct *task)
59723+{
59724+ return;
59725+}
59726+
59727+EXPORT_SYMBOL(gr_learn_resource);
59728+EXPORT_SYMBOL(gr_set_kernel_label);
59729+#ifdef CONFIG_SECURITY
59730+EXPORT_SYMBOL(gr_check_user_change);
59731+EXPORT_SYMBOL(gr_check_group_change);
59732+#endif
59733diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
59734new file mode 100644
59735index 0000000..abfa971
59736--- /dev/null
59737+++ b/grsecurity/grsec_exec.c
59738@@ -0,0 +1,174 @@
59739+#include <linux/kernel.h>
59740+#include <linux/sched.h>
59741+#include <linux/file.h>
59742+#include <linux/binfmts.h>
59743+#include <linux/fs.h>
59744+#include <linux/types.h>
59745+#include <linux/grdefs.h>
59746+#include <linux/grsecurity.h>
59747+#include <linux/grinternal.h>
59748+#include <linux/capability.h>
59749+#include <linux/module.h>
59750+
59751+#include <asm/uaccess.h>
59752+
59753+#ifdef CONFIG_GRKERNSEC_EXECLOG
59754+static char gr_exec_arg_buf[132];
59755+static DEFINE_MUTEX(gr_exec_arg_mutex);
59756+#endif
59757+
59758+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
59759+
59760+void
59761+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
59762+{
59763+#ifdef CONFIG_GRKERNSEC_EXECLOG
59764+ char *grarg = gr_exec_arg_buf;
59765+ unsigned int i, x, execlen = 0;
59766+ char c;
59767+
59768+ if (!((grsec_enable_execlog && grsec_enable_group &&
59769+ in_group_p(grsec_audit_gid))
59770+ || (grsec_enable_execlog && !grsec_enable_group)))
59771+ return;
59772+
59773+ mutex_lock(&gr_exec_arg_mutex);
59774+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
59775+
59776+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
59777+ const char __user *p;
59778+ unsigned int len;
59779+
59780+ p = get_user_arg_ptr(argv, i);
59781+ if (IS_ERR(p))
59782+ goto log;
59783+
59784+ len = strnlen_user(p, 128 - execlen);
59785+ if (len > 128 - execlen)
59786+ len = 128 - execlen;
59787+ else if (len > 0)
59788+ len--;
59789+ if (copy_from_user(grarg + execlen, p, len))
59790+ goto log;
59791+
59792+ /* rewrite unprintable characters */
59793+ for (x = 0; x < len; x++) {
59794+ c = *(grarg + execlen + x);
59795+ if (c < 32 || c > 126)
59796+ *(grarg + execlen + x) = ' ';
59797+ }
59798+
59799+ execlen += len;
59800+ *(grarg + execlen) = ' ';
59801+ *(grarg + execlen + 1) = '\0';
59802+ execlen++;
59803+ }
59804+
59805+ log:
59806+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
59807+ bprm->file->f_path.mnt, grarg);
59808+ mutex_unlock(&gr_exec_arg_mutex);
59809+#endif
59810+ return;
59811+}
59812+
59813+#ifdef CONFIG_GRKERNSEC
59814+extern int gr_acl_is_capable(const int cap);
59815+extern int gr_acl_is_capable_nolog(const int cap);
59816+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
59817+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
59818+extern int gr_chroot_is_capable(const int cap);
59819+extern int gr_chroot_is_capable_nolog(const int cap);
59820+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
59821+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
59822+#endif
59823+
59824+const char *captab_log[] = {
59825+ "CAP_CHOWN",
59826+ "CAP_DAC_OVERRIDE",
59827+ "CAP_DAC_READ_SEARCH",
59828+ "CAP_FOWNER",
59829+ "CAP_FSETID",
59830+ "CAP_KILL",
59831+ "CAP_SETGID",
59832+ "CAP_SETUID",
59833+ "CAP_SETPCAP",
59834+ "CAP_LINUX_IMMUTABLE",
59835+ "CAP_NET_BIND_SERVICE",
59836+ "CAP_NET_BROADCAST",
59837+ "CAP_NET_ADMIN",
59838+ "CAP_NET_RAW",
59839+ "CAP_IPC_LOCK",
59840+ "CAP_IPC_OWNER",
59841+ "CAP_SYS_MODULE",
59842+ "CAP_SYS_RAWIO",
59843+ "CAP_SYS_CHROOT",
59844+ "CAP_SYS_PTRACE",
59845+ "CAP_SYS_PACCT",
59846+ "CAP_SYS_ADMIN",
59847+ "CAP_SYS_BOOT",
59848+ "CAP_SYS_NICE",
59849+ "CAP_SYS_RESOURCE",
59850+ "CAP_SYS_TIME",
59851+ "CAP_SYS_TTY_CONFIG",
59852+ "CAP_MKNOD",
59853+ "CAP_LEASE",
59854+ "CAP_AUDIT_WRITE",
59855+ "CAP_AUDIT_CONTROL",
59856+ "CAP_SETFCAP",
59857+ "CAP_MAC_OVERRIDE",
59858+ "CAP_MAC_ADMIN",
59859+ "CAP_SYSLOG",
59860+ "CAP_WAKE_ALARM"
59861+};
59862+
59863+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
59864+
59865+int gr_is_capable(const int cap)
59866+{
59867+#ifdef CONFIG_GRKERNSEC
59868+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
59869+ return 1;
59870+ return 0;
59871+#else
59872+ return 1;
59873+#endif
59874+}
59875+
59876+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
59877+{
59878+#ifdef CONFIG_GRKERNSEC
59879+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
59880+ return 1;
59881+ return 0;
59882+#else
59883+ return 1;
59884+#endif
59885+}
59886+
59887+int gr_is_capable_nolog(const int cap)
59888+{
59889+#ifdef CONFIG_GRKERNSEC
59890+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
59891+ return 1;
59892+ return 0;
59893+#else
59894+ return 1;
59895+#endif
59896+}
59897+
59898+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
59899+{
59900+#ifdef CONFIG_GRKERNSEC
59901+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
59902+ return 1;
59903+ return 0;
59904+#else
59905+ return 1;
59906+#endif
59907+}
59908+
59909+EXPORT_SYMBOL(gr_is_capable);
59910+EXPORT_SYMBOL(gr_is_capable_nolog);
59911+EXPORT_SYMBOL(gr_task_is_capable);
59912+EXPORT_SYMBOL(gr_task_is_capable_nolog);
59913diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
59914new file mode 100644
59915index 0000000..d3ee748
59916--- /dev/null
59917+++ b/grsecurity/grsec_fifo.c
59918@@ -0,0 +1,24 @@
59919+#include <linux/kernel.h>
59920+#include <linux/sched.h>
59921+#include <linux/fs.h>
59922+#include <linux/file.h>
59923+#include <linux/grinternal.h>
59924+
59925+int
59926+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
59927+ const struct dentry *dir, const int flag, const int acc_mode)
59928+{
59929+#ifdef CONFIG_GRKERNSEC_FIFO
59930+ const struct cred *cred = current_cred();
59931+
59932+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
59933+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
59934+ (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
59935+ (cred->fsuid != dentry->d_inode->i_uid)) {
59936+ if (!inode_permission(dentry->d_inode, acc_mode))
59937+ gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
59938+ return -EACCES;
59939+ }
59940+#endif
59941+ return 0;
59942+}
59943diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
59944new file mode 100644
59945index 0000000..8ca18bf
59946--- /dev/null
59947+++ b/grsecurity/grsec_fork.c
59948@@ -0,0 +1,23 @@
59949+#include <linux/kernel.h>
59950+#include <linux/sched.h>
59951+#include <linux/grsecurity.h>
59952+#include <linux/grinternal.h>
59953+#include <linux/errno.h>
59954+
59955+void
59956+gr_log_forkfail(const int retval)
59957+{
59958+#ifdef CONFIG_GRKERNSEC_FORKFAIL
59959+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
59960+ switch (retval) {
59961+ case -EAGAIN:
59962+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
59963+ break;
59964+ case -ENOMEM:
59965+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
59966+ break;
59967+ }
59968+ }
59969+#endif
59970+ return;
59971+}
59972diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
59973new file mode 100644
59974index 0000000..05a6015
59975--- /dev/null
59976+++ b/grsecurity/grsec_init.c
59977@@ -0,0 +1,283 @@
59978+#include <linux/kernel.h>
59979+#include <linux/sched.h>
59980+#include <linux/mm.h>
59981+#include <linux/gracl.h>
59982+#include <linux/slab.h>
59983+#include <linux/vmalloc.h>
59984+#include <linux/percpu.h>
59985+#include <linux/module.h>
59986+
59987+int grsec_enable_ptrace_readexec;
59988+int grsec_enable_setxid;
59989+int grsec_enable_symlinkown;
59990+int grsec_symlinkown_gid;
59991+int grsec_enable_brute;
59992+int grsec_enable_link;
59993+int grsec_enable_dmesg;
59994+int grsec_enable_harden_ptrace;
59995+int grsec_enable_fifo;
59996+int grsec_enable_execlog;
59997+int grsec_enable_signal;
59998+int grsec_enable_forkfail;
59999+int grsec_enable_audit_ptrace;
60000+int grsec_enable_time;
60001+int grsec_enable_audit_textrel;
60002+int grsec_enable_group;
60003+int grsec_audit_gid;
60004+int grsec_enable_chdir;
60005+int grsec_enable_mount;
60006+int grsec_enable_rofs;
60007+int grsec_enable_chroot_findtask;
60008+int grsec_enable_chroot_mount;
60009+int grsec_enable_chroot_shmat;
60010+int grsec_enable_chroot_fchdir;
60011+int grsec_enable_chroot_double;
60012+int grsec_enable_chroot_pivot;
60013+int grsec_enable_chroot_chdir;
60014+int grsec_enable_chroot_chmod;
60015+int grsec_enable_chroot_mknod;
60016+int grsec_enable_chroot_nice;
60017+int grsec_enable_chroot_execlog;
60018+int grsec_enable_chroot_caps;
60019+int grsec_enable_chroot_sysctl;
60020+int grsec_enable_chroot_unix;
60021+int grsec_enable_tpe;
60022+int grsec_tpe_gid;
60023+int grsec_enable_blackhole;
60024+#ifdef CONFIG_IPV6_MODULE
60025+EXPORT_SYMBOL(grsec_enable_blackhole);
60026+#endif
60027+int grsec_lastack_retries;
60028+int grsec_enable_tpe_all;
60029+int grsec_enable_tpe_invert;
60030+int grsec_enable_socket_all;
60031+int grsec_socket_all_gid;
60032+int grsec_enable_socket_client;
60033+int grsec_socket_client_gid;
60034+int grsec_enable_socket_server;
60035+int grsec_socket_server_gid;
60036+int grsec_resource_logging;
60037+int grsec_disable_privio;
60038+int grsec_enable_log_rwxmaps;
60039+int grsec_lock;
60040+
60041+DEFINE_SPINLOCK(grsec_alert_lock);
60042+unsigned long grsec_alert_wtime = 0;
60043+unsigned long grsec_alert_fyet = 0;
60044+
60045+DEFINE_SPINLOCK(grsec_audit_lock);
60046+
60047+DEFINE_RWLOCK(grsec_exec_file_lock);
60048+
60049+char *gr_shared_page[4];
60050+
60051+char *gr_alert_log_fmt;
60052+char *gr_audit_log_fmt;
60053+char *gr_alert_log_buf;
60054+char *gr_audit_log_buf;
60055+
60056+extern struct gr_arg *gr_usermode;
60057+extern unsigned char *gr_system_salt;
60058+extern unsigned char *gr_system_sum;
60059+
60060+void __init
60061+grsecurity_init(void)
60062+{
60063+ int j;
60064+ /* create the per-cpu shared pages */
60065+
60066+#ifdef CONFIG_X86
60067+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
60068+#endif
60069+
60070+ for (j = 0; j < 4; j++) {
60071+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
60072+ if (gr_shared_page[j] == NULL) {
60073+ panic("Unable to allocate grsecurity shared page");
60074+ return;
60075+ }
60076+ }
60077+
60078+ /* allocate log buffers */
60079+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
60080+ if (!gr_alert_log_fmt) {
60081+ panic("Unable to allocate grsecurity alert log format buffer");
60082+ return;
60083+ }
60084+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
60085+ if (!gr_audit_log_fmt) {
60086+ panic("Unable to allocate grsecurity audit log format buffer");
60087+ return;
60088+ }
60089+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
60090+ if (!gr_alert_log_buf) {
60091+ panic("Unable to allocate grsecurity alert log buffer");
60092+ return;
60093+ }
60094+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
60095+ if (!gr_audit_log_buf) {
60096+ panic("Unable to allocate grsecurity audit log buffer");
60097+ return;
60098+ }
60099+
60100+ /* allocate memory for authentication structure */
60101+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
60102+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
60103+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
60104+
60105+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
60106+ panic("Unable to allocate grsecurity authentication structure");
60107+ return;
60108+ }
60109+
60110+
60111+#ifdef CONFIG_GRKERNSEC_IO
60112+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
60113+ grsec_disable_privio = 1;
60114+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
60115+ grsec_disable_privio = 1;
60116+#else
60117+ grsec_disable_privio = 0;
60118+#endif
60119+#endif
60120+
60121+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
60122+ /* for backward compatibility, tpe_invert always defaults to on if
60123+ enabled in the kernel
60124+ */
60125+ grsec_enable_tpe_invert = 1;
60126+#endif
60127+
60128+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
60129+#ifndef CONFIG_GRKERNSEC_SYSCTL
60130+ grsec_lock = 1;
60131+#endif
60132+
60133+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
60134+ grsec_enable_audit_textrel = 1;
60135+#endif
60136+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
60137+ grsec_enable_log_rwxmaps = 1;
60138+#endif
60139+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
60140+ grsec_enable_group = 1;
60141+ grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
60142+#endif
60143+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
60144+ grsec_enable_ptrace_readexec = 1;
60145+#endif
60146+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
60147+ grsec_enable_chdir = 1;
60148+#endif
60149+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
60150+ grsec_enable_harden_ptrace = 1;
60151+#endif
60152+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
60153+ grsec_enable_mount = 1;
60154+#endif
60155+#ifdef CONFIG_GRKERNSEC_LINK
60156+ grsec_enable_link = 1;
60157+#endif
60158+#ifdef CONFIG_GRKERNSEC_BRUTE
60159+ grsec_enable_brute = 1;
60160+#endif
60161+#ifdef CONFIG_GRKERNSEC_DMESG
60162+ grsec_enable_dmesg = 1;
60163+#endif
60164+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
60165+ grsec_enable_blackhole = 1;
60166+ grsec_lastack_retries = 4;
60167+#endif
60168+#ifdef CONFIG_GRKERNSEC_FIFO
60169+ grsec_enable_fifo = 1;
60170+#endif
60171+#ifdef CONFIG_GRKERNSEC_EXECLOG
60172+ grsec_enable_execlog = 1;
60173+#endif
60174+#ifdef CONFIG_GRKERNSEC_SETXID
60175+ grsec_enable_setxid = 1;
60176+#endif
60177+#ifdef CONFIG_GRKERNSEC_SIGNAL
60178+ grsec_enable_signal = 1;
60179+#endif
60180+#ifdef CONFIG_GRKERNSEC_FORKFAIL
60181+ grsec_enable_forkfail = 1;
60182+#endif
60183+#ifdef CONFIG_GRKERNSEC_TIME
60184+ grsec_enable_time = 1;
60185+#endif
60186+#ifdef CONFIG_GRKERNSEC_RESLOG
60187+ grsec_resource_logging = 1;
60188+#endif
60189+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
60190+ grsec_enable_chroot_findtask = 1;
60191+#endif
60192+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
60193+ grsec_enable_chroot_unix = 1;
60194+#endif
60195+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
60196+ grsec_enable_chroot_mount = 1;
60197+#endif
60198+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
60199+ grsec_enable_chroot_fchdir = 1;
60200+#endif
60201+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
60202+ grsec_enable_chroot_shmat = 1;
60203+#endif
60204+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
60205+ grsec_enable_audit_ptrace = 1;
60206+#endif
60207+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
60208+ grsec_enable_chroot_double = 1;
60209+#endif
60210+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
60211+ grsec_enable_chroot_pivot = 1;
60212+#endif
60213+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
60214+ grsec_enable_chroot_chdir = 1;
60215+#endif
60216+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
60217+ grsec_enable_chroot_chmod = 1;
60218+#endif
60219+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
60220+ grsec_enable_chroot_mknod = 1;
60221+#endif
60222+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
60223+ grsec_enable_chroot_nice = 1;
60224+#endif
60225+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
60226+ grsec_enable_chroot_execlog = 1;
60227+#endif
60228+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
60229+ grsec_enable_chroot_caps = 1;
60230+#endif
60231+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
60232+ grsec_enable_chroot_sysctl = 1;
60233+#endif
60234+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
60235+ grsec_enable_symlinkown = 1;
60236+ grsec_symlinkown_gid = CONFIG_GRKERNSEC_SYMLINKOWN_GID;
60237+#endif
60238+#ifdef CONFIG_GRKERNSEC_TPE
60239+ grsec_enable_tpe = 1;
60240+ grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
60241+#ifdef CONFIG_GRKERNSEC_TPE_ALL
60242+ grsec_enable_tpe_all = 1;
60243+#endif
60244+#endif
60245+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
60246+ grsec_enable_socket_all = 1;
60247+ grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
60248+#endif
60249+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
60250+ grsec_enable_socket_client = 1;
60251+ grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
60252+#endif
60253+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
60254+ grsec_enable_socket_server = 1;
60255+ grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
60256+#endif
60257+#endif
60258+
60259+ return;
60260+}
60261diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
60262new file mode 100644
60263index 0000000..6095407
60264--- /dev/null
60265+++ b/grsecurity/grsec_link.c
60266@@ -0,0 +1,58 @@
60267+#include <linux/kernel.h>
60268+#include <linux/sched.h>
60269+#include <linux/fs.h>
60270+#include <linux/file.h>
60271+#include <linux/grinternal.h>
60272+
60273+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
60274+{
60275+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
60276+ const struct inode *link_inode = link->dentry->d_inode;
60277+
60278+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
60279+ /* ignore root-owned links, e.g. /proc/self */
60280+ !uid_eq(link_inode->i_uid, GLOBAL_ROOT_UID) && target &&
60281+ !uid_eq(link_inode->i_uid, target->i_uid)) {
60282+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
60283+ return 1;
60284+ }
60285+#endif
60286+ return 0;
60287+}
60288+
60289+int
60290+gr_handle_follow_link(const struct inode *parent,
60291+ const struct inode *inode,
60292+ const struct dentry *dentry, const struct vfsmount *mnt)
60293+{
60294+#ifdef CONFIG_GRKERNSEC_LINK
60295+ const struct cred *cred = current_cred();
60296+
60297+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
60298+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
60299+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
60300+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
60301+ return -EACCES;
60302+ }
60303+#endif
60304+ return 0;
60305+}
60306+
60307+int
60308+gr_handle_hardlink(const struct dentry *dentry,
60309+ const struct vfsmount *mnt,
60310+ struct inode *inode, const int mode, const struct filename *to)
60311+{
60312+#ifdef CONFIG_GRKERNSEC_LINK
60313+ const struct cred *cred = current_cred();
60314+
60315+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
60316+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
60317+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
60318+ !capable(CAP_FOWNER) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
60319+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
60320+ return -EPERM;
60321+ }
60322+#endif
60323+ return 0;
60324+}
60325diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
60326new file mode 100644
60327index 0000000..a45d2e9
60328--- /dev/null
60329+++ b/grsecurity/grsec_log.c
60330@@ -0,0 +1,322 @@
60331+#include <linux/kernel.h>
60332+#include <linux/sched.h>
60333+#include <linux/file.h>
60334+#include <linux/tty.h>
60335+#include <linux/fs.h>
60336+#include <linux/grinternal.h>
60337+
60338+#ifdef CONFIG_TREE_PREEMPT_RCU
60339+#define DISABLE_PREEMPT() preempt_disable()
60340+#define ENABLE_PREEMPT() preempt_enable()
60341+#else
60342+#define DISABLE_PREEMPT()
60343+#define ENABLE_PREEMPT()
60344+#endif
60345+
60346+#define BEGIN_LOCKS(x) \
60347+ DISABLE_PREEMPT(); \
60348+ rcu_read_lock(); \
60349+ read_lock(&tasklist_lock); \
60350+ read_lock(&grsec_exec_file_lock); \
60351+ if (x != GR_DO_AUDIT) \
60352+ spin_lock(&grsec_alert_lock); \
60353+ else \
60354+ spin_lock(&grsec_audit_lock)
60355+
60356+#define END_LOCKS(x) \
60357+ if (x != GR_DO_AUDIT) \
60358+ spin_unlock(&grsec_alert_lock); \
60359+ else \
60360+ spin_unlock(&grsec_audit_lock); \
60361+ read_unlock(&grsec_exec_file_lock); \
60362+ read_unlock(&tasklist_lock); \
60363+ rcu_read_unlock(); \
60364+ ENABLE_PREEMPT(); \
60365+ if (x == GR_DONT_AUDIT) \
60366+ gr_handle_alertkill(current)
60367+
60368+enum {
60369+ FLOODING,
60370+ NO_FLOODING
60371+};
60372+
60373+extern char *gr_alert_log_fmt;
60374+extern char *gr_audit_log_fmt;
60375+extern char *gr_alert_log_buf;
60376+extern char *gr_audit_log_buf;
60377+
60378+static int gr_log_start(int audit)
60379+{
60380+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
60381+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
60382+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
60383+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
60384+ unsigned long curr_secs = get_seconds();
60385+
60386+ if (audit == GR_DO_AUDIT)
60387+ goto set_fmt;
60388+
60389+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
60390+ grsec_alert_wtime = curr_secs;
60391+ grsec_alert_fyet = 0;
60392+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
60393+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
60394+ grsec_alert_fyet++;
60395+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
60396+ grsec_alert_wtime = curr_secs;
60397+ grsec_alert_fyet++;
60398+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
60399+ return FLOODING;
60400+ }
60401+ else return FLOODING;
60402+
60403+set_fmt:
60404+#endif
60405+ memset(buf, 0, PAGE_SIZE);
60406+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
60407+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
60408+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
60409+ } else if (current->signal->curr_ip) {
60410+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
60411+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
60412+ } else if (gr_acl_is_enabled()) {
60413+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
60414+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
60415+ } else {
60416+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
60417+ strcpy(buf, fmt);
60418+ }
60419+
60420+ return NO_FLOODING;
60421+}
60422+
60423+static void gr_log_middle(int audit, const char *msg, va_list ap)
60424+ __attribute__ ((format (printf, 2, 0)));
60425+
60426+static void gr_log_middle(int audit, const char *msg, va_list ap)
60427+{
60428+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
60429+ unsigned int len = strlen(buf);
60430+
60431+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
60432+
60433+ return;
60434+}
60435+
60436+static void gr_log_middle_varargs(int audit, const char *msg, ...)
60437+ __attribute__ ((format (printf, 2, 3)));
60438+
60439+static void gr_log_middle_varargs(int audit, const char *msg, ...)
60440+{
60441+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
60442+ unsigned int len = strlen(buf);
60443+ va_list ap;
60444+
60445+ va_start(ap, msg);
60446+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
60447+ va_end(ap);
60448+
60449+ return;
60450+}
60451+
60452+static void gr_log_end(int audit, int append_default)
60453+{
60454+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
60455+
60456+ if (append_default) {
60457+ unsigned int len = strlen(buf);
60458+ snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
60459+ }
60460+
60461+ printk("%s\n", buf);
60462+
60463+ return;
60464+}
60465+
60466+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
60467+{
60468+ int logtype;
60469+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
60470+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
60471+ void *voidptr = NULL;
60472+ int num1 = 0, num2 = 0;
60473+ unsigned long ulong1 = 0, ulong2 = 0;
60474+ struct dentry *dentry = NULL;
60475+ struct vfsmount *mnt = NULL;
60476+ struct file *file = NULL;
60477+ struct task_struct *task = NULL;
60478+ const struct cred *cred, *pcred;
60479+ va_list ap;
60480+
60481+ BEGIN_LOCKS(audit);
60482+ logtype = gr_log_start(audit);
60483+ if (logtype == FLOODING) {
60484+ END_LOCKS(audit);
60485+ return;
60486+ }
60487+ va_start(ap, argtypes);
60488+ switch (argtypes) {
60489+ case GR_TTYSNIFF:
60490+ task = va_arg(ap, struct task_struct *);
60491+ gr_log_middle_varargs(audit, msg, &task->signal->curr_ip, gr_task_fullpath0(task), task->comm, task->pid, gr_parent_task_fullpath0(task), task->real_parent->comm, task->real_parent->pid);
60492+ break;
60493+ case GR_SYSCTL_HIDDEN:
60494+ str1 = va_arg(ap, char *);
60495+ gr_log_middle_varargs(audit, msg, result, str1);
60496+ break;
60497+ case GR_RBAC:
60498+ dentry = va_arg(ap, struct dentry *);
60499+ mnt = va_arg(ap, struct vfsmount *);
60500+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
60501+ break;
60502+ case GR_RBAC_STR:
60503+ dentry = va_arg(ap, struct dentry *);
60504+ mnt = va_arg(ap, struct vfsmount *);
60505+ str1 = va_arg(ap, char *);
60506+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
60507+ break;
60508+ case GR_STR_RBAC:
60509+ str1 = va_arg(ap, char *);
60510+ dentry = va_arg(ap, struct dentry *);
60511+ mnt = va_arg(ap, struct vfsmount *);
60512+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
60513+ break;
60514+ case GR_RBAC_MODE2:
60515+ dentry = va_arg(ap, struct dentry *);
60516+ mnt = va_arg(ap, struct vfsmount *);
60517+ str1 = va_arg(ap, char *);
60518+ str2 = va_arg(ap, char *);
60519+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
60520+ break;
60521+ case GR_RBAC_MODE3:
60522+ dentry = va_arg(ap, struct dentry *);
60523+ mnt = va_arg(ap, struct vfsmount *);
60524+ str1 = va_arg(ap, char *);
60525+ str2 = va_arg(ap, char *);
60526+ str3 = va_arg(ap, char *);
60527+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
60528+ break;
60529+ case GR_FILENAME:
60530+ dentry = va_arg(ap, struct dentry *);
60531+ mnt = va_arg(ap, struct vfsmount *);
60532+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
60533+ break;
60534+ case GR_STR_FILENAME:
60535+ str1 = va_arg(ap, char *);
60536+ dentry = va_arg(ap, struct dentry *);
60537+ mnt = va_arg(ap, struct vfsmount *);
60538+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
60539+ break;
60540+ case GR_FILENAME_STR:
60541+ dentry = va_arg(ap, struct dentry *);
60542+ mnt = va_arg(ap, struct vfsmount *);
60543+ str1 = va_arg(ap, char *);
60544+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
60545+ break;
60546+ case GR_FILENAME_TWO_INT:
60547+ dentry = va_arg(ap, struct dentry *);
60548+ mnt = va_arg(ap, struct vfsmount *);
60549+ num1 = va_arg(ap, int);
60550+ num2 = va_arg(ap, int);
60551+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
60552+ break;
60553+ case GR_FILENAME_TWO_INT_STR:
60554+ dentry = va_arg(ap, struct dentry *);
60555+ mnt = va_arg(ap, struct vfsmount *);
60556+ num1 = va_arg(ap, int);
60557+ num2 = va_arg(ap, int);
60558+ str1 = va_arg(ap, char *);
60559+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
60560+ break;
60561+ case GR_TEXTREL:
60562+ file = va_arg(ap, struct file *);
60563+ ulong1 = va_arg(ap, unsigned long);
60564+ ulong2 = va_arg(ap, unsigned long);
60565+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
60566+ break;
60567+ case GR_PTRACE:
60568+ task = va_arg(ap, struct task_struct *);
60569+ 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);
60570+ break;
60571+ case GR_RESOURCE:
60572+ task = va_arg(ap, struct task_struct *);
60573+ cred = __task_cred(task);
60574+ pcred = __task_cred(task->real_parent);
60575+ ulong1 = va_arg(ap, unsigned long);
60576+ str1 = va_arg(ap, char *);
60577+ ulong2 = va_arg(ap, unsigned long);
60578+ gr_log_middle_varargs(audit, msg, ulong1, str1, ulong2, gr_task_fullpath(task), task->comm, task->pid, cred->uid, cred->euid, cred->gid, cred->egid, gr_parent_task_fullpath(task), task->real_parent->comm, task->real_parent->pid, pcred->uid, pcred->euid, pcred->gid, pcred->egid);
60579+ break;
60580+ case GR_CAP:
60581+ task = va_arg(ap, struct task_struct *);
60582+ cred = __task_cred(task);
60583+ pcred = __task_cred(task->real_parent);
60584+ str1 = va_arg(ap, char *);
60585+ gr_log_middle_varargs(audit, msg, str1, gr_task_fullpath(task), task->comm, task->pid, cred->uid, cred->euid, cred->gid, cred->egid, gr_parent_task_fullpath(task), task->real_parent->comm, task->real_parent->pid, pcred->uid, pcred->euid, pcred->gid, pcred->egid);
60586+ break;
60587+ case GR_SIG:
60588+ str1 = va_arg(ap, char *);
60589+ voidptr = va_arg(ap, void *);
60590+ gr_log_middle_varargs(audit, msg, str1, voidptr);
60591+ break;
60592+ case GR_SIG2:
60593+ task = va_arg(ap, struct task_struct *);
60594+ cred = __task_cred(task);
60595+ pcred = __task_cred(task->real_parent);
60596+ num1 = va_arg(ap, int);
60597+ gr_log_middle_varargs(audit, msg, num1, gr_task_fullpath0(task), task->comm, task->pid, cred->uid, cred->euid, cred->gid, cred->egid, gr_parent_task_fullpath0(task), task->real_parent->comm, task->real_parent->pid, pcred->uid, pcred->euid, pcred->gid, pcred->egid);
60598+ break;
60599+ case GR_CRASH1:
60600+ task = va_arg(ap, struct task_struct *);
60601+ cred = __task_cred(task);
60602+ pcred = __task_cred(task->real_parent);
60603+ ulong1 = va_arg(ap, unsigned long);
60604+ gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task->pid, cred->uid, cred->euid, cred->gid, cred->egid, gr_parent_task_fullpath(task), task->real_parent->comm, task->real_parent->pid, pcred->uid, pcred->euid, pcred->gid, pcred->egid, cred->uid, ulong1);
60605+ break;
60606+ case GR_CRASH2:
60607+ task = va_arg(ap, struct task_struct *);
60608+ cred = __task_cred(task);
60609+ pcred = __task_cred(task->real_parent);
60610+ ulong1 = va_arg(ap, unsigned long);
60611+ gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task->pid, cred->uid, cred->euid, cred->gid, cred->egid, gr_parent_task_fullpath(task), task->real_parent->comm, task->real_parent->pid, pcred->uid, pcred->euid, pcred->gid, pcred->egid, ulong1);
60612+ break;
60613+ case GR_RWXMAP:
60614+ file = va_arg(ap, struct file *);
60615+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
60616+ break;
60617+ case GR_PSACCT:
60618+ {
60619+ unsigned int wday, cday;
60620+ __u8 whr, chr;
60621+ __u8 wmin, cmin;
60622+ __u8 wsec, csec;
60623+ char cur_tty[64] = { 0 };
60624+ char parent_tty[64] = { 0 };
60625+
60626+ task = va_arg(ap, struct task_struct *);
60627+ wday = va_arg(ap, unsigned int);
60628+ cday = va_arg(ap, unsigned int);
60629+ whr = va_arg(ap, int);
60630+ chr = va_arg(ap, int);
60631+ wmin = va_arg(ap, int);
60632+ cmin = va_arg(ap, int);
60633+ wsec = va_arg(ap, int);
60634+ csec = va_arg(ap, int);
60635+ ulong1 = va_arg(ap, unsigned long);
60636+ cred = __task_cred(task);
60637+ pcred = __task_cred(task->real_parent);
60638+
60639+ gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task->pid, &task->signal->curr_ip, tty_name(task->signal->tty, cur_tty), cred->uid, cred->euid, cred->gid, cred->egid, wday, whr, wmin, wsec, cday, chr, cmin, csec, (task->flags & PF_SIGNALED) ? "killed by signal" : "exited", ulong1, gr_parent_task_fullpath(task), task->real_parent->comm, task->real_parent->pid, &task->real_parent->signal->curr_ip, tty_name(task->real_parent->signal->tty, parent_tty), pcred->uid, pcred->euid, pcred->gid, pcred->egid);
60640+ }
60641+ break;
60642+ default:
60643+ gr_log_middle(audit, msg, ap);
60644+ }
60645+ va_end(ap);
60646+ // these don't need DEFAULTSECARGS printed on the end
60647+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
60648+ gr_log_end(audit, 0);
60649+ else
60650+ gr_log_end(audit, 1);
60651+ END_LOCKS(audit);
60652+}
60653diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
60654new file mode 100644
60655index 0000000..f536303
60656--- /dev/null
60657+++ b/grsecurity/grsec_mem.c
60658@@ -0,0 +1,40 @@
60659+#include <linux/kernel.h>
60660+#include <linux/sched.h>
60661+#include <linux/mm.h>
60662+#include <linux/mman.h>
60663+#include <linux/grinternal.h>
60664+
60665+void
60666+gr_handle_ioperm(void)
60667+{
60668+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
60669+ return;
60670+}
60671+
60672+void
60673+gr_handle_iopl(void)
60674+{
60675+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
60676+ return;
60677+}
60678+
60679+void
60680+gr_handle_mem_readwrite(u64 from, u64 to)
60681+{
60682+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
60683+ return;
60684+}
60685+
60686+void
60687+gr_handle_vm86(void)
60688+{
60689+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
60690+ return;
60691+}
60692+
60693+void
60694+gr_log_badprocpid(const char *entry)
60695+{
60696+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
60697+ return;
60698+}
60699diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
60700new file mode 100644
60701index 0000000..2131422
60702--- /dev/null
60703+++ b/grsecurity/grsec_mount.c
60704@@ -0,0 +1,62 @@
60705+#include <linux/kernel.h>
60706+#include <linux/sched.h>
60707+#include <linux/mount.h>
60708+#include <linux/grsecurity.h>
60709+#include <linux/grinternal.h>
60710+
60711+void
60712+gr_log_remount(const char *devname, const int retval)
60713+{
60714+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
60715+ if (grsec_enable_mount && (retval >= 0))
60716+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
60717+#endif
60718+ return;
60719+}
60720+
60721+void
60722+gr_log_unmount(const char *devname, const int retval)
60723+{
60724+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
60725+ if (grsec_enable_mount && (retval >= 0))
60726+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
60727+#endif
60728+ return;
60729+}
60730+
60731+void
60732+gr_log_mount(const char *from, const char *to, const int retval)
60733+{
60734+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
60735+ if (grsec_enable_mount && (retval >= 0))
60736+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
60737+#endif
60738+ return;
60739+}
60740+
60741+int
60742+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
60743+{
60744+#ifdef CONFIG_GRKERNSEC_ROFS
60745+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
60746+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
60747+ return -EPERM;
60748+ } else
60749+ return 0;
60750+#endif
60751+ return 0;
60752+}
60753+
60754+int
60755+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
60756+{
60757+#ifdef CONFIG_GRKERNSEC_ROFS
60758+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
60759+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
60760+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
60761+ return -EPERM;
60762+ } else
60763+ return 0;
60764+#endif
60765+ return 0;
60766+}
60767diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
60768new file mode 100644
60769index 0000000..a3b12a0
60770--- /dev/null
60771+++ b/grsecurity/grsec_pax.c
60772@@ -0,0 +1,36 @@
60773+#include <linux/kernel.h>
60774+#include <linux/sched.h>
60775+#include <linux/mm.h>
60776+#include <linux/file.h>
60777+#include <linux/grinternal.h>
60778+#include <linux/grsecurity.h>
60779+
60780+void
60781+gr_log_textrel(struct vm_area_struct * vma)
60782+{
60783+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
60784+ if (grsec_enable_audit_textrel)
60785+ gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
60786+#endif
60787+ return;
60788+}
60789+
60790+void
60791+gr_log_rwxmmap(struct file *file)
60792+{
60793+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
60794+ if (grsec_enable_log_rwxmaps)
60795+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
60796+#endif
60797+ return;
60798+}
60799+
60800+void
60801+gr_log_rwxmprotect(struct file *file)
60802+{
60803+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
60804+ if (grsec_enable_log_rwxmaps)
60805+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
60806+#endif
60807+ return;
60808+}
60809diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
60810new file mode 100644
60811index 0000000..f7f29aa
60812--- /dev/null
60813+++ b/grsecurity/grsec_ptrace.c
60814@@ -0,0 +1,30 @@
60815+#include <linux/kernel.h>
60816+#include <linux/sched.h>
60817+#include <linux/grinternal.h>
60818+#include <linux/security.h>
60819+
60820+void
60821+gr_audit_ptrace(struct task_struct *task)
60822+{
60823+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
60824+ if (grsec_enable_audit_ptrace)
60825+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
60826+#endif
60827+ return;
60828+}
60829+
60830+int
60831+gr_ptrace_readexec(struct file *file, int unsafe_flags)
60832+{
60833+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
60834+ const struct dentry *dentry = file->f_path.dentry;
60835+ const struct vfsmount *mnt = file->f_path.mnt;
60836+
60837+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
60838+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
60839+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
60840+ return -EACCES;
60841+ }
60842+#endif
60843+ return 0;
60844+}
60845diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
60846new file mode 100644
60847index 0000000..5c00416
60848--- /dev/null
60849+++ b/grsecurity/grsec_sig.c
60850@@ -0,0 +1,222 @@
60851+#include <linux/kernel.h>
60852+#include <linux/sched.h>
60853+#include <linux/delay.h>
60854+#include <linux/grsecurity.h>
60855+#include <linux/grinternal.h>
60856+#include <linux/hardirq.h>
60857+
60858+char *signames[] = {
60859+ [SIGSEGV] = "Segmentation fault",
60860+ [SIGILL] = "Illegal instruction",
60861+ [SIGABRT] = "Abort",
60862+ [SIGBUS] = "Invalid alignment/Bus error"
60863+};
60864+
60865+void
60866+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
60867+{
60868+#ifdef CONFIG_GRKERNSEC_SIGNAL
60869+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
60870+ (sig == SIGABRT) || (sig == SIGBUS))) {
60871+ if (t->pid == current->pid) {
60872+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
60873+ } else {
60874+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
60875+ }
60876+ }
60877+#endif
60878+ return;
60879+}
60880+
60881+int
60882+gr_handle_signal(const struct task_struct *p, const int sig)
60883+{
60884+#ifdef CONFIG_GRKERNSEC
60885+ /* ignore the 0 signal for protected task checks */
60886+ if (current->pid > 1 && sig && gr_check_protected_task(p)) {
60887+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
60888+ return -EPERM;
60889+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
60890+ return -EPERM;
60891+ }
60892+#endif
60893+ return 0;
60894+}
60895+
60896+#ifdef CONFIG_GRKERNSEC
60897+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
60898+
60899+int gr_fake_force_sig(int sig, struct task_struct *t)
60900+{
60901+ unsigned long int flags;
60902+ int ret, blocked, ignored;
60903+ struct k_sigaction *action;
60904+
60905+ spin_lock_irqsave(&t->sighand->siglock, flags);
60906+ action = &t->sighand->action[sig-1];
60907+ ignored = action->sa.sa_handler == SIG_IGN;
60908+ blocked = sigismember(&t->blocked, sig);
60909+ if (blocked || ignored) {
60910+ action->sa.sa_handler = SIG_DFL;
60911+ if (blocked) {
60912+ sigdelset(&t->blocked, sig);
60913+ recalc_sigpending_and_wake(t);
60914+ }
60915+ }
60916+ if (action->sa.sa_handler == SIG_DFL)
60917+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
60918+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
60919+
60920+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
60921+
60922+ return ret;
60923+}
60924+#endif
60925+
60926+#ifdef CONFIG_GRKERNSEC_BRUTE
60927+#define GR_USER_BAN_TIME (15 * 60)
60928+#define GR_DAEMON_BRUTE_TIME (30 * 60)
60929+
60930+static int __get_dumpable(unsigned long mm_flags)
60931+{
60932+ int ret;
60933+
60934+ ret = mm_flags & MMF_DUMPABLE_MASK;
60935+ return (ret >= 2) ? 2 : ret;
60936+}
60937+#endif
60938+
60939+void gr_handle_brute_attach(unsigned long mm_flags)
60940+{
60941+#ifdef CONFIG_GRKERNSEC_BRUTE
60942+ struct task_struct *p = current;
60943+ kuid_t uid = GLOBAL_ROOT_UID;
60944+ int daemon = 0;
60945+
60946+ if (!grsec_enable_brute)
60947+ return;
60948+
60949+ rcu_read_lock();
60950+ read_lock(&tasklist_lock);
60951+ read_lock(&grsec_exec_file_lock);
60952+ if (p->real_parent && p->real_parent->exec_file == p->exec_file) {
60953+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
60954+ p->real_parent->brute = 1;
60955+ daemon = 1;
60956+ } else {
60957+ const struct cred *cred = __task_cred(p), *cred2;
60958+ struct task_struct *tsk, *tsk2;
60959+
60960+ if (!__get_dumpable(mm_flags) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
60961+ struct user_struct *user;
60962+
60963+ uid = cred->uid;
60964+
60965+ /* this is put upon execution past expiration */
60966+ user = find_user(uid);
60967+ if (user == NULL)
60968+ goto unlock;
60969+ user->banned = 1;
60970+ user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
60971+ if (user->ban_expires == ~0UL)
60972+ user->ban_expires--;
60973+
60974+ do_each_thread(tsk2, tsk) {
60975+ cred2 = __task_cred(tsk);
60976+ if (tsk != p && uid_eq(cred2->uid, uid))
60977+ gr_fake_force_sig(SIGKILL, tsk);
60978+ } while_each_thread(tsk2, tsk);
60979+ }
60980+ }
60981+unlock:
60982+ read_unlock(&grsec_exec_file_lock);
60983+ read_unlock(&tasklist_lock);
60984+ rcu_read_unlock();
60985+
60986+ if (!uid_eq(uid, GLOBAL_ROOT_UID))
60987+ printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
60988+ from_kuid_munged(&init_user_ns, uid), GR_USER_BAN_TIME / 60);
60989+ else if (daemon)
60990+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
60991+
60992+#endif
60993+ return;
60994+}
60995+
60996+void gr_handle_brute_check(void)
60997+{
60998+#ifdef CONFIG_GRKERNSEC_BRUTE
60999+ struct task_struct *p = current;
61000+
61001+ if (unlikely(p->brute)) {
61002+ if (!grsec_enable_brute)
61003+ p->brute = 0;
61004+ else if (time_before(get_seconds(), p->brute_expires))
61005+ msleep(30 * 1000);
61006+ }
61007+#endif
61008+ return;
61009+}
61010+
61011+void gr_handle_kernel_exploit(void)
61012+{
61013+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
61014+ const struct cred *cred;
61015+ struct task_struct *tsk, *tsk2;
61016+ struct user_struct *user;
61017+ kuid_t uid;
61018+
61019+ if (in_irq() || in_serving_softirq() || in_nmi())
61020+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
61021+
61022+ uid = current_uid();
61023+
61024+ if (uid_eq(uid, GLOBAL_ROOT_UID))
61025+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
61026+ else {
61027+ /* kill all the processes of this user, hold a reference
61028+ to their creds struct, and prevent them from creating
61029+ another process until system reset
61030+ */
61031+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
61032+ from_kuid_munged(&init_user_ns, uid));
61033+ /* we intentionally leak this ref */
61034+ user = get_uid(current->cred->user);
61035+ if (user) {
61036+ user->banned = 1;
61037+ user->ban_expires = ~0UL;
61038+ }
61039+
61040+ read_lock(&tasklist_lock);
61041+ do_each_thread(tsk2, tsk) {
61042+ cred = __task_cred(tsk);
61043+ if (uid_eq(cred->uid, uid))
61044+ gr_fake_force_sig(SIGKILL, tsk);
61045+ } while_each_thread(tsk2, tsk);
61046+ read_unlock(&tasklist_lock);
61047+ }
61048+#endif
61049+}
61050+
61051+int __gr_process_user_ban(struct user_struct *user)
61052+{
61053+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
61054+ if (unlikely(user->banned)) {
61055+ if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
61056+ user->banned = 0;
61057+ user->ban_expires = 0;
61058+ free_uid(user);
61059+ } else
61060+ return -EPERM;
61061+ }
61062+#endif
61063+ return 0;
61064+}
61065+
61066+int gr_process_user_ban(void)
61067+{
61068+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
61069+ return __gr_process_user_ban(current->cred->user);
61070+#endif
61071+ return 0;
61072+}
61073diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
61074new file mode 100644
61075index 0000000..4030d57
61076--- /dev/null
61077+++ b/grsecurity/grsec_sock.c
61078@@ -0,0 +1,244 @@
61079+#include <linux/kernel.h>
61080+#include <linux/module.h>
61081+#include <linux/sched.h>
61082+#include <linux/file.h>
61083+#include <linux/net.h>
61084+#include <linux/in.h>
61085+#include <linux/ip.h>
61086+#include <net/sock.h>
61087+#include <net/inet_sock.h>
61088+#include <linux/grsecurity.h>
61089+#include <linux/grinternal.h>
61090+#include <linux/gracl.h>
61091+
61092+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
61093+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
61094+
61095+EXPORT_SYMBOL(gr_search_udp_recvmsg);
61096+EXPORT_SYMBOL(gr_search_udp_sendmsg);
61097+
61098+#ifdef CONFIG_UNIX_MODULE
61099+EXPORT_SYMBOL(gr_acl_handle_unix);
61100+EXPORT_SYMBOL(gr_acl_handle_mknod);
61101+EXPORT_SYMBOL(gr_handle_chroot_unix);
61102+EXPORT_SYMBOL(gr_handle_create);
61103+#endif
61104+
61105+#ifdef CONFIG_GRKERNSEC
61106+#define gr_conn_table_size 32749
61107+struct conn_table_entry {
61108+ struct conn_table_entry *next;
61109+ struct signal_struct *sig;
61110+};
61111+
61112+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
61113+DEFINE_SPINLOCK(gr_conn_table_lock);
61114+
61115+extern const char * gr_socktype_to_name(unsigned char type);
61116+extern const char * gr_proto_to_name(unsigned char proto);
61117+extern const char * gr_sockfamily_to_name(unsigned char family);
61118+
61119+static __inline__ int
61120+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
61121+{
61122+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
61123+}
61124+
61125+static __inline__ int
61126+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
61127+ __u16 sport, __u16 dport)
61128+{
61129+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
61130+ sig->gr_sport == sport && sig->gr_dport == dport))
61131+ return 1;
61132+ else
61133+ return 0;
61134+}
61135+
61136+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
61137+{
61138+ struct conn_table_entry **match;
61139+ unsigned int index;
61140+
61141+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
61142+ sig->gr_sport, sig->gr_dport,
61143+ gr_conn_table_size);
61144+
61145+ newent->sig = sig;
61146+
61147+ match = &gr_conn_table[index];
61148+ newent->next = *match;
61149+ *match = newent;
61150+
61151+ return;
61152+}
61153+
61154+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
61155+{
61156+ struct conn_table_entry *match, *last = NULL;
61157+ unsigned int index;
61158+
61159+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
61160+ sig->gr_sport, sig->gr_dport,
61161+ gr_conn_table_size);
61162+
61163+ match = gr_conn_table[index];
61164+ while (match && !conn_match(match->sig,
61165+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
61166+ sig->gr_dport)) {
61167+ last = match;
61168+ match = match->next;
61169+ }
61170+
61171+ if (match) {
61172+ if (last)
61173+ last->next = match->next;
61174+ else
61175+ gr_conn_table[index] = NULL;
61176+ kfree(match);
61177+ }
61178+
61179+ return;
61180+}
61181+
61182+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
61183+ __u16 sport, __u16 dport)
61184+{
61185+ struct conn_table_entry *match;
61186+ unsigned int index;
61187+
61188+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
61189+
61190+ match = gr_conn_table[index];
61191+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
61192+ match = match->next;
61193+
61194+ if (match)
61195+ return match->sig;
61196+ else
61197+ return NULL;
61198+}
61199+
61200+#endif
61201+
61202+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
61203+{
61204+#ifdef CONFIG_GRKERNSEC
61205+ struct signal_struct *sig = task->signal;
61206+ struct conn_table_entry *newent;
61207+
61208+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
61209+ if (newent == NULL)
61210+ return;
61211+ /* no bh lock needed since we are called with bh disabled */
61212+ spin_lock(&gr_conn_table_lock);
61213+ gr_del_task_from_ip_table_nolock(sig);
61214+ sig->gr_saddr = inet->inet_rcv_saddr;
61215+ sig->gr_daddr = inet->inet_daddr;
61216+ sig->gr_sport = inet->inet_sport;
61217+ sig->gr_dport = inet->inet_dport;
61218+ gr_add_to_task_ip_table_nolock(sig, newent);
61219+ spin_unlock(&gr_conn_table_lock);
61220+#endif
61221+ return;
61222+}
61223+
61224+void gr_del_task_from_ip_table(struct task_struct *task)
61225+{
61226+#ifdef CONFIG_GRKERNSEC
61227+ spin_lock_bh(&gr_conn_table_lock);
61228+ gr_del_task_from_ip_table_nolock(task->signal);
61229+ spin_unlock_bh(&gr_conn_table_lock);
61230+#endif
61231+ return;
61232+}
61233+
61234+void
61235+gr_attach_curr_ip(const struct sock *sk)
61236+{
61237+#ifdef CONFIG_GRKERNSEC
61238+ struct signal_struct *p, *set;
61239+ const struct inet_sock *inet = inet_sk(sk);
61240+
61241+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
61242+ return;
61243+
61244+ set = current->signal;
61245+
61246+ spin_lock_bh(&gr_conn_table_lock);
61247+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
61248+ inet->inet_dport, inet->inet_sport);
61249+ if (unlikely(p != NULL)) {
61250+ set->curr_ip = p->curr_ip;
61251+ set->used_accept = 1;
61252+ gr_del_task_from_ip_table_nolock(p);
61253+ spin_unlock_bh(&gr_conn_table_lock);
61254+ return;
61255+ }
61256+ spin_unlock_bh(&gr_conn_table_lock);
61257+
61258+ set->curr_ip = inet->inet_daddr;
61259+ set->used_accept = 1;
61260+#endif
61261+ return;
61262+}
61263+
61264+int
61265+gr_handle_sock_all(const int family, const int type, const int protocol)
61266+{
61267+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
61268+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
61269+ (family != AF_UNIX)) {
61270+ if (family == AF_INET)
61271+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
61272+ else
61273+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
61274+ return -EACCES;
61275+ }
61276+#endif
61277+ return 0;
61278+}
61279+
61280+int
61281+gr_handle_sock_server(const struct sockaddr *sck)
61282+{
61283+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
61284+ if (grsec_enable_socket_server &&
61285+ in_group_p(grsec_socket_server_gid) &&
61286+ sck && (sck->sa_family != AF_UNIX) &&
61287+ (sck->sa_family != AF_LOCAL)) {
61288+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
61289+ return -EACCES;
61290+ }
61291+#endif
61292+ return 0;
61293+}
61294+
61295+int
61296+gr_handle_sock_server_other(const struct sock *sck)
61297+{
61298+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
61299+ if (grsec_enable_socket_server &&
61300+ in_group_p(grsec_socket_server_gid) &&
61301+ sck && (sck->sk_family != AF_UNIX) &&
61302+ (sck->sk_family != AF_LOCAL)) {
61303+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
61304+ return -EACCES;
61305+ }
61306+#endif
61307+ return 0;
61308+}
61309+
61310+int
61311+gr_handle_sock_client(const struct sockaddr *sck)
61312+{
61313+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
61314+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
61315+ sck && (sck->sa_family != AF_UNIX) &&
61316+ (sck->sa_family != AF_LOCAL)) {
61317+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
61318+ return -EACCES;
61319+ }
61320+#endif
61321+ return 0;
61322+}
61323diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
61324new file mode 100644
61325index 0000000..f55ef0f
61326--- /dev/null
61327+++ b/grsecurity/grsec_sysctl.c
61328@@ -0,0 +1,469 @@
61329+#include <linux/kernel.h>
61330+#include <linux/sched.h>
61331+#include <linux/sysctl.h>
61332+#include <linux/grsecurity.h>
61333+#include <linux/grinternal.h>
61334+
61335+int
61336+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
61337+{
61338+#ifdef CONFIG_GRKERNSEC_SYSCTL
61339+ if (dirname == NULL || name == NULL)
61340+ return 0;
61341+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
61342+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
61343+ return -EACCES;
61344+ }
61345+#endif
61346+ return 0;
61347+}
61348+
61349+#ifdef CONFIG_GRKERNSEC_ROFS
61350+static int __maybe_unused one = 1;
61351+#endif
61352+
61353+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
61354+struct ctl_table grsecurity_table[] = {
61355+#ifdef CONFIG_GRKERNSEC_SYSCTL
61356+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
61357+#ifdef CONFIG_GRKERNSEC_IO
61358+ {
61359+ .procname = "disable_priv_io",
61360+ .data = &grsec_disable_privio,
61361+ .maxlen = sizeof(int),
61362+ .mode = 0600,
61363+ .proc_handler = &proc_dointvec,
61364+ },
61365+#endif
61366+#endif
61367+#ifdef CONFIG_GRKERNSEC_LINK
61368+ {
61369+ .procname = "linking_restrictions",
61370+ .data = &grsec_enable_link,
61371+ .maxlen = sizeof(int),
61372+ .mode = 0600,
61373+ .proc_handler = &proc_dointvec,
61374+ },
61375+#endif
61376+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
61377+ {
61378+ .procname = "enforce_symlinksifowner",
61379+ .data = &grsec_enable_symlinkown,
61380+ .maxlen = sizeof(int),
61381+ .mode = 0600,
61382+ .proc_handler = &proc_dointvec,
61383+ },
61384+ {
61385+ .procname = "symlinkown_gid",
61386+ .data = &grsec_symlinkown_gid,
61387+ .maxlen = sizeof(int),
61388+ .mode = 0600,
61389+ .proc_handler = &proc_dointvec,
61390+ },
61391+#endif
61392+#ifdef CONFIG_GRKERNSEC_BRUTE
61393+ {
61394+ .procname = "deter_bruteforce",
61395+ .data = &grsec_enable_brute,
61396+ .maxlen = sizeof(int),
61397+ .mode = 0600,
61398+ .proc_handler = &proc_dointvec,
61399+ },
61400+#endif
61401+#ifdef CONFIG_GRKERNSEC_FIFO
61402+ {
61403+ .procname = "fifo_restrictions",
61404+ .data = &grsec_enable_fifo,
61405+ .maxlen = sizeof(int),
61406+ .mode = 0600,
61407+ .proc_handler = &proc_dointvec,
61408+ },
61409+#endif
61410+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
61411+ {
61412+ .procname = "ptrace_readexec",
61413+ .data = &grsec_enable_ptrace_readexec,
61414+ .maxlen = sizeof(int),
61415+ .mode = 0600,
61416+ .proc_handler = &proc_dointvec,
61417+ },
61418+#endif
61419+#ifdef CONFIG_GRKERNSEC_SETXID
61420+ {
61421+ .procname = "consistent_setxid",
61422+ .data = &grsec_enable_setxid,
61423+ .maxlen = sizeof(int),
61424+ .mode = 0600,
61425+ .proc_handler = &proc_dointvec,
61426+ },
61427+#endif
61428+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
61429+ {
61430+ .procname = "ip_blackhole",
61431+ .data = &grsec_enable_blackhole,
61432+ .maxlen = sizeof(int),
61433+ .mode = 0600,
61434+ .proc_handler = &proc_dointvec,
61435+ },
61436+ {
61437+ .procname = "lastack_retries",
61438+ .data = &grsec_lastack_retries,
61439+ .maxlen = sizeof(int),
61440+ .mode = 0600,
61441+ .proc_handler = &proc_dointvec,
61442+ },
61443+#endif
61444+#ifdef CONFIG_GRKERNSEC_EXECLOG
61445+ {
61446+ .procname = "exec_logging",
61447+ .data = &grsec_enable_execlog,
61448+ .maxlen = sizeof(int),
61449+ .mode = 0600,
61450+ .proc_handler = &proc_dointvec,
61451+ },
61452+#endif
61453+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
61454+ {
61455+ .procname = "rwxmap_logging",
61456+ .data = &grsec_enable_log_rwxmaps,
61457+ .maxlen = sizeof(int),
61458+ .mode = 0600,
61459+ .proc_handler = &proc_dointvec,
61460+ },
61461+#endif
61462+#ifdef CONFIG_GRKERNSEC_SIGNAL
61463+ {
61464+ .procname = "signal_logging",
61465+ .data = &grsec_enable_signal,
61466+ .maxlen = sizeof(int),
61467+ .mode = 0600,
61468+ .proc_handler = &proc_dointvec,
61469+ },
61470+#endif
61471+#ifdef CONFIG_GRKERNSEC_FORKFAIL
61472+ {
61473+ .procname = "forkfail_logging",
61474+ .data = &grsec_enable_forkfail,
61475+ .maxlen = sizeof(int),
61476+ .mode = 0600,
61477+ .proc_handler = &proc_dointvec,
61478+ },
61479+#endif
61480+#ifdef CONFIG_GRKERNSEC_TIME
61481+ {
61482+ .procname = "timechange_logging",
61483+ .data = &grsec_enable_time,
61484+ .maxlen = sizeof(int),
61485+ .mode = 0600,
61486+ .proc_handler = &proc_dointvec,
61487+ },
61488+#endif
61489+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
61490+ {
61491+ .procname = "chroot_deny_shmat",
61492+ .data = &grsec_enable_chroot_shmat,
61493+ .maxlen = sizeof(int),
61494+ .mode = 0600,
61495+ .proc_handler = &proc_dointvec,
61496+ },
61497+#endif
61498+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
61499+ {
61500+ .procname = "chroot_deny_unix",
61501+ .data = &grsec_enable_chroot_unix,
61502+ .maxlen = sizeof(int),
61503+ .mode = 0600,
61504+ .proc_handler = &proc_dointvec,
61505+ },
61506+#endif
61507+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
61508+ {
61509+ .procname = "chroot_deny_mount",
61510+ .data = &grsec_enable_chroot_mount,
61511+ .maxlen = sizeof(int),
61512+ .mode = 0600,
61513+ .proc_handler = &proc_dointvec,
61514+ },
61515+#endif
61516+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
61517+ {
61518+ .procname = "chroot_deny_fchdir",
61519+ .data = &grsec_enable_chroot_fchdir,
61520+ .maxlen = sizeof(int),
61521+ .mode = 0600,
61522+ .proc_handler = &proc_dointvec,
61523+ },
61524+#endif
61525+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
61526+ {
61527+ .procname = "chroot_deny_chroot",
61528+ .data = &grsec_enable_chroot_double,
61529+ .maxlen = sizeof(int),
61530+ .mode = 0600,
61531+ .proc_handler = &proc_dointvec,
61532+ },
61533+#endif
61534+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
61535+ {
61536+ .procname = "chroot_deny_pivot",
61537+ .data = &grsec_enable_chroot_pivot,
61538+ .maxlen = sizeof(int),
61539+ .mode = 0600,
61540+ .proc_handler = &proc_dointvec,
61541+ },
61542+#endif
61543+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
61544+ {
61545+ .procname = "chroot_enforce_chdir",
61546+ .data = &grsec_enable_chroot_chdir,
61547+ .maxlen = sizeof(int),
61548+ .mode = 0600,
61549+ .proc_handler = &proc_dointvec,
61550+ },
61551+#endif
61552+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
61553+ {
61554+ .procname = "chroot_deny_chmod",
61555+ .data = &grsec_enable_chroot_chmod,
61556+ .maxlen = sizeof(int),
61557+ .mode = 0600,
61558+ .proc_handler = &proc_dointvec,
61559+ },
61560+#endif
61561+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
61562+ {
61563+ .procname = "chroot_deny_mknod",
61564+ .data = &grsec_enable_chroot_mknod,
61565+ .maxlen = sizeof(int),
61566+ .mode = 0600,
61567+ .proc_handler = &proc_dointvec,
61568+ },
61569+#endif
61570+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
61571+ {
61572+ .procname = "chroot_restrict_nice",
61573+ .data = &grsec_enable_chroot_nice,
61574+ .maxlen = sizeof(int),
61575+ .mode = 0600,
61576+ .proc_handler = &proc_dointvec,
61577+ },
61578+#endif
61579+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
61580+ {
61581+ .procname = "chroot_execlog",
61582+ .data = &grsec_enable_chroot_execlog,
61583+ .maxlen = sizeof(int),
61584+ .mode = 0600,
61585+ .proc_handler = &proc_dointvec,
61586+ },
61587+#endif
61588+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
61589+ {
61590+ .procname = "chroot_caps",
61591+ .data = &grsec_enable_chroot_caps,
61592+ .maxlen = sizeof(int),
61593+ .mode = 0600,
61594+ .proc_handler = &proc_dointvec,
61595+ },
61596+#endif
61597+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
61598+ {
61599+ .procname = "chroot_deny_sysctl",
61600+ .data = &grsec_enable_chroot_sysctl,
61601+ .maxlen = sizeof(int),
61602+ .mode = 0600,
61603+ .proc_handler = &proc_dointvec,
61604+ },
61605+#endif
61606+#ifdef CONFIG_GRKERNSEC_TPE
61607+ {
61608+ .procname = "tpe",
61609+ .data = &grsec_enable_tpe,
61610+ .maxlen = sizeof(int),
61611+ .mode = 0600,
61612+ .proc_handler = &proc_dointvec,
61613+ },
61614+ {
61615+ .procname = "tpe_gid",
61616+ .data = &grsec_tpe_gid,
61617+ .maxlen = sizeof(int),
61618+ .mode = 0600,
61619+ .proc_handler = &proc_dointvec,
61620+ },
61621+#endif
61622+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
61623+ {
61624+ .procname = "tpe_invert",
61625+ .data = &grsec_enable_tpe_invert,
61626+ .maxlen = sizeof(int),
61627+ .mode = 0600,
61628+ .proc_handler = &proc_dointvec,
61629+ },
61630+#endif
61631+#ifdef CONFIG_GRKERNSEC_TPE_ALL
61632+ {
61633+ .procname = "tpe_restrict_all",
61634+ .data = &grsec_enable_tpe_all,
61635+ .maxlen = sizeof(int),
61636+ .mode = 0600,
61637+ .proc_handler = &proc_dointvec,
61638+ },
61639+#endif
61640+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
61641+ {
61642+ .procname = "socket_all",
61643+ .data = &grsec_enable_socket_all,
61644+ .maxlen = sizeof(int),
61645+ .mode = 0600,
61646+ .proc_handler = &proc_dointvec,
61647+ },
61648+ {
61649+ .procname = "socket_all_gid",
61650+ .data = &grsec_socket_all_gid,
61651+ .maxlen = sizeof(int),
61652+ .mode = 0600,
61653+ .proc_handler = &proc_dointvec,
61654+ },
61655+#endif
61656+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
61657+ {
61658+ .procname = "socket_client",
61659+ .data = &grsec_enable_socket_client,
61660+ .maxlen = sizeof(int),
61661+ .mode = 0600,
61662+ .proc_handler = &proc_dointvec,
61663+ },
61664+ {
61665+ .procname = "socket_client_gid",
61666+ .data = &grsec_socket_client_gid,
61667+ .maxlen = sizeof(int),
61668+ .mode = 0600,
61669+ .proc_handler = &proc_dointvec,
61670+ },
61671+#endif
61672+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
61673+ {
61674+ .procname = "socket_server",
61675+ .data = &grsec_enable_socket_server,
61676+ .maxlen = sizeof(int),
61677+ .mode = 0600,
61678+ .proc_handler = &proc_dointvec,
61679+ },
61680+ {
61681+ .procname = "socket_server_gid",
61682+ .data = &grsec_socket_server_gid,
61683+ .maxlen = sizeof(int),
61684+ .mode = 0600,
61685+ .proc_handler = &proc_dointvec,
61686+ },
61687+#endif
61688+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
61689+ {
61690+ .procname = "audit_group",
61691+ .data = &grsec_enable_group,
61692+ .maxlen = sizeof(int),
61693+ .mode = 0600,
61694+ .proc_handler = &proc_dointvec,
61695+ },
61696+ {
61697+ .procname = "audit_gid",
61698+ .data = &grsec_audit_gid,
61699+ .maxlen = sizeof(int),
61700+ .mode = 0600,
61701+ .proc_handler = &proc_dointvec,
61702+ },
61703+#endif
61704+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
61705+ {
61706+ .procname = "audit_chdir",
61707+ .data = &grsec_enable_chdir,
61708+ .maxlen = sizeof(int),
61709+ .mode = 0600,
61710+ .proc_handler = &proc_dointvec,
61711+ },
61712+#endif
61713+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
61714+ {
61715+ .procname = "audit_mount",
61716+ .data = &grsec_enable_mount,
61717+ .maxlen = sizeof(int),
61718+ .mode = 0600,
61719+ .proc_handler = &proc_dointvec,
61720+ },
61721+#endif
61722+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
61723+ {
61724+ .procname = "audit_textrel",
61725+ .data = &grsec_enable_audit_textrel,
61726+ .maxlen = sizeof(int),
61727+ .mode = 0600,
61728+ .proc_handler = &proc_dointvec,
61729+ },
61730+#endif
61731+#ifdef CONFIG_GRKERNSEC_DMESG
61732+ {
61733+ .procname = "dmesg",
61734+ .data = &grsec_enable_dmesg,
61735+ .maxlen = sizeof(int),
61736+ .mode = 0600,
61737+ .proc_handler = &proc_dointvec,
61738+ },
61739+#endif
61740+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
61741+ {
61742+ .procname = "chroot_findtask",
61743+ .data = &grsec_enable_chroot_findtask,
61744+ .maxlen = sizeof(int),
61745+ .mode = 0600,
61746+ .proc_handler = &proc_dointvec,
61747+ },
61748+#endif
61749+#ifdef CONFIG_GRKERNSEC_RESLOG
61750+ {
61751+ .procname = "resource_logging",
61752+ .data = &grsec_resource_logging,
61753+ .maxlen = sizeof(int),
61754+ .mode = 0600,
61755+ .proc_handler = &proc_dointvec,
61756+ },
61757+#endif
61758+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
61759+ {
61760+ .procname = "audit_ptrace",
61761+ .data = &grsec_enable_audit_ptrace,
61762+ .maxlen = sizeof(int),
61763+ .mode = 0600,
61764+ .proc_handler = &proc_dointvec,
61765+ },
61766+#endif
61767+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
61768+ {
61769+ .procname = "harden_ptrace",
61770+ .data = &grsec_enable_harden_ptrace,
61771+ .maxlen = sizeof(int),
61772+ .mode = 0600,
61773+ .proc_handler = &proc_dointvec,
61774+ },
61775+#endif
61776+ {
61777+ .procname = "grsec_lock",
61778+ .data = &grsec_lock,
61779+ .maxlen = sizeof(int),
61780+ .mode = 0600,
61781+ .proc_handler = &proc_dointvec,
61782+ },
61783+#endif
61784+#ifdef CONFIG_GRKERNSEC_ROFS
61785+ {
61786+ .procname = "romount_protect",
61787+ .data = &grsec_enable_rofs,
61788+ .maxlen = sizeof(int),
61789+ .mode = 0600,
61790+ .proc_handler = &proc_dointvec_minmax,
61791+ .extra1 = &one,
61792+ .extra2 = &one,
61793+ },
61794+#endif
61795+ { }
61796+};
61797+#endif
61798diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
61799new file mode 100644
61800index 0000000..0dc13c3
61801--- /dev/null
61802+++ b/grsecurity/grsec_time.c
61803@@ -0,0 +1,16 @@
61804+#include <linux/kernel.h>
61805+#include <linux/sched.h>
61806+#include <linux/grinternal.h>
61807+#include <linux/module.h>
61808+
61809+void
61810+gr_log_timechange(void)
61811+{
61812+#ifdef CONFIG_GRKERNSEC_TIME
61813+ if (grsec_enable_time)
61814+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
61815+#endif
61816+ return;
61817+}
61818+
61819+EXPORT_SYMBOL(gr_log_timechange);
61820diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
61821new file mode 100644
61822index 0000000..07e0dc0
61823--- /dev/null
61824+++ b/grsecurity/grsec_tpe.c
61825@@ -0,0 +1,73 @@
61826+#include <linux/kernel.h>
61827+#include <linux/sched.h>
61828+#include <linux/file.h>
61829+#include <linux/fs.h>
61830+#include <linux/grinternal.h>
61831+
61832+extern int gr_acl_tpe_check(void);
61833+
61834+int
61835+gr_tpe_allow(const struct file *file)
61836+{
61837+#ifdef CONFIG_GRKERNSEC
61838+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
61839+ const struct cred *cred = current_cred();
61840+ char *msg = NULL;
61841+ char *msg2 = NULL;
61842+
61843+ // never restrict root
61844+ if (!cred->uid)
61845+ return 1;
61846+
61847+ if (grsec_enable_tpe) {
61848+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
61849+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
61850+ msg = "not being in trusted group";
61851+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
61852+ msg = "being in untrusted group";
61853+#else
61854+ if (in_group_p(grsec_tpe_gid))
61855+ msg = "being in untrusted group";
61856+#endif
61857+ }
61858+ if (!msg && gr_acl_tpe_check())
61859+ msg = "being in untrusted role";
61860+
61861+ // not in any affected group/role
61862+ if (!msg)
61863+ goto next_check;
61864+
61865+ if (inode->i_uid)
61866+ msg2 = "file in non-root-owned directory";
61867+ else if (inode->i_mode & S_IWOTH)
61868+ msg2 = "file in world-writable directory";
61869+ else if (inode->i_mode & S_IWGRP)
61870+ msg2 = "file in group-writable directory";
61871+
61872+ if (msg && msg2) {
61873+ char fullmsg[70] = {0};
61874+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
61875+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
61876+ return 0;
61877+ }
61878+ msg = NULL;
61879+next_check:
61880+#ifdef CONFIG_GRKERNSEC_TPE_ALL
61881+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
61882+ return 1;
61883+
61884+ if (inode->i_uid && (inode->i_uid != cred->uid))
61885+ msg = "directory not owned by user";
61886+ else if (inode->i_mode & S_IWOTH)
61887+ msg = "file in world-writable directory";
61888+ else if (inode->i_mode & S_IWGRP)
61889+ msg = "file in group-writable directory";
61890+
61891+ if (msg) {
61892+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
61893+ return 0;
61894+ }
61895+#endif
61896+#endif
61897+ return 1;
61898+}
61899diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
61900new file mode 100644
61901index 0000000..9f7b1ac
61902--- /dev/null
61903+++ b/grsecurity/grsum.c
61904@@ -0,0 +1,61 @@
61905+#include <linux/err.h>
61906+#include <linux/kernel.h>
61907+#include <linux/sched.h>
61908+#include <linux/mm.h>
61909+#include <linux/scatterlist.h>
61910+#include <linux/crypto.h>
61911+#include <linux/gracl.h>
61912+
61913+
61914+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
61915+#error "crypto and sha256 must be built into the kernel"
61916+#endif
61917+
61918+int
61919+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
61920+{
61921+ char *p;
61922+ struct crypto_hash *tfm;
61923+ struct hash_desc desc;
61924+ struct scatterlist sg;
61925+ unsigned char temp_sum[GR_SHA_LEN];
61926+ volatile int retval = 0;
61927+ volatile int dummy = 0;
61928+ unsigned int i;
61929+
61930+ sg_init_table(&sg, 1);
61931+
61932+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
61933+ if (IS_ERR(tfm)) {
61934+ /* should never happen, since sha256 should be built in */
61935+ return 1;
61936+ }
61937+
61938+ desc.tfm = tfm;
61939+ desc.flags = 0;
61940+
61941+ crypto_hash_init(&desc);
61942+
61943+ p = salt;
61944+ sg_set_buf(&sg, p, GR_SALT_LEN);
61945+ crypto_hash_update(&desc, &sg, sg.length);
61946+
61947+ p = entry->pw;
61948+ sg_set_buf(&sg, p, strlen(p));
61949+
61950+ crypto_hash_update(&desc, &sg, sg.length);
61951+
61952+ crypto_hash_final(&desc, temp_sum);
61953+
61954+ memset(entry->pw, 0, GR_PW_LEN);
61955+
61956+ for (i = 0; i < GR_SHA_LEN; i++)
61957+ if (sum[i] != temp_sum[i])
61958+ retval = 1;
61959+ else
61960+ dummy = 1; // waste a cycle
61961+
61962+ crypto_free_hash(tfm);
61963+
61964+ return retval;
61965+}
61966diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
61967index 0daa0fb..f548aa4 100644
61968--- a/include/acpi/acpi_bus.h
61969+++ b/include/acpi/acpi_bus.h
61970@@ -107,7 +107,7 @@ struct acpi_device_ops {
61971 acpi_op_bind bind;
61972 acpi_op_unbind unbind;
61973 acpi_op_notify notify;
61974-};
61975+} __no_const;
61976
61977 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
61978
61979diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
61980index 77ff547..181834f 100644
61981--- a/include/asm-generic/4level-fixup.h
61982+++ b/include/asm-generic/4level-fixup.h
61983@@ -13,8 +13,10 @@
61984 #define pmd_alloc(mm, pud, address) \
61985 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
61986 NULL: pmd_offset(pud, address))
61987+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
61988
61989 #define pud_alloc(mm, pgd, address) (pgd)
61990+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
61991 #define pud_offset(pgd, start) (pgd)
61992 #define pud_none(pud) 0
61993 #define pud_bad(pud) 0
61994diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
61995index b7babf0..04ad282 100644
61996--- a/include/asm-generic/atomic-long.h
61997+++ b/include/asm-generic/atomic-long.h
61998@@ -22,6 +22,12 @@
61999
62000 typedef atomic64_t atomic_long_t;
62001
62002+#ifdef CONFIG_PAX_REFCOUNT
62003+typedef atomic64_unchecked_t atomic_long_unchecked_t;
62004+#else
62005+typedef atomic64_t atomic_long_unchecked_t;
62006+#endif
62007+
62008 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
62009
62010 static inline long atomic_long_read(atomic_long_t *l)
62011@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
62012 return (long)atomic64_read(v);
62013 }
62014
62015+#ifdef CONFIG_PAX_REFCOUNT
62016+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
62017+{
62018+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62019+
62020+ return (long)atomic64_read_unchecked(v);
62021+}
62022+#endif
62023+
62024 static inline void atomic_long_set(atomic_long_t *l, long i)
62025 {
62026 atomic64_t *v = (atomic64_t *)l;
62027@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
62028 atomic64_set(v, i);
62029 }
62030
62031+#ifdef CONFIG_PAX_REFCOUNT
62032+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
62033+{
62034+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62035+
62036+ atomic64_set_unchecked(v, i);
62037+}
62038+#endif
62039+
62040 static inline void atomic_long_inc(atomic_long_t *l)
62041 {
62042 atomic64_t *v = (atomic64_t *)l;
62043@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
62044 atomic64_inc(v);
62045 }
62046
62047+#ifdef CONFIG_PAX_REFCOUNT
62048+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
62049+{
62050+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62051+
62052+ atomic64_inc_unchecked(v);
62053+}
62054+#endif
62055+
62056 static inline void atomic_long_dec(atomic_long_t *l)
62057 {
62058 atomic64_t *v = (atomic64_t *)l;
62059@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
62060 atomic64_dec(v);
62061 }
62062
62063+#ifdef CONFIG_PAX_REFCOUNT
62064+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
62065+{
62066+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62067+
62068+ atomic64_dec_unchecked(v);
62069+}
62070+#endif
62071+
62072 static inline void atomic_long_add(long i, atomic_long_t *l)
62073 {
62074 atomic64_t *v = (atomic64_t *)l;
62075@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
62076 atomic64_add(i, v);
62077 }
62078
62079+#ifdef CONFIG_PAX_REFCOUNT
62080+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
62081+{
62082+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62083+
62084+ atomic64_add_unchecked(i, v);
62085+}
62086+#endif
62087+
62088 static inline void atomic_long_sub(long i, atomic_long_t *l)
62089 {
62090 atomic64_t *v = (atomic64_t *)l;
62091@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
62092 atomic64_sub(i, v);
62093 }
62094
62095+#ifdef CONFIG_PAX_REFCOUNT
62096+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
62097+{
62098+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62099+
62100+ atomic64_sub_unchecked(i, v);
62101+}
62102+#endif
62103+
62104 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
62105 {
62106 atomic64_t *v = (atomic64_t *)l;
62107@@ -101,6 +161,15 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
62108 return (long)atomic64_add_return(i, v);
62109 }
62110
62111+#ifdef CONFIG_PAX_REFCOUNT
62112+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
62113+{
62114+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62115+
62116+ return (long)atomic64_add_return_unchecked(i, v);
62117+}
62118+#endif
62119+
62120 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
62121 {
62122 atomic64_t *v = (atomic64_t *)l;
62123@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
62124 return (long)atomic64_inc_return(v);
62125 }
62126
62127+#ifdef CONFIG_PAX_REFCOUNT
62128+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
62129+{
62130+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62131+
62132+ return (long)atomic64_inc_return_unchecked(v);
62133+}
62134+#endif
62135+
62136 static inline long atomic_long_dec_return(atomic_long_t *l)
62137 {
62138 atomic64_t *v = (atomic64_t *)l;
62139@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
62140
62141 typedef atomic_t atomic_long_t;
62142
62143+#ifdef CONFIG_PAX_REFCOUNT
62144+typedef atomic_unchecked_t atomic_long_unchecked_t;
62145+#else
62146+typedef atomic_t atomic_long_unchecked_t;
62147+#endif
62148+
62149 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
62150 static inline long atomic_long_read(atomic_long_t *l)
62151 {
62152@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
62153 return (long)atomic_read(v);
62154 }
62155
62156+#ifdef CONFIG_PAX_REFCOUNT
62157+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
62158+{
62159+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62160+
62161+ return (long)atomic_read_unchecked(v);
62162+}
62163+#endif
62164+
62165 static inline void atomic_long_set(atomic_long_t *l, long i)
62166 {
62167 atomic_t *v = (atomic_t *)l;
62168@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
62169 atomic_set(v, i);
62170 }
62171
62172+#ifdef CONFIG_PAX_REFCOUNT
62173+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
62174+{
62175+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62176+
62177+ atomic_set_unchecked(v, i);
62178+}
62179+#endif
62180+
62181 static inline void atomic_long_inc(atomic_long_t *l)
62182 {
62183 atomic_t *v = (atomic_t *)l;
62184@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
62185 atomic_inc(v);
62186 }
62187
62188+#ifdef CONFIG_PAX_REFCOUNT
62189+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
62190+{
62191+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62192+
62193+ atomic_inc_unchecked(v);
62194+}
62195+#endif
62196+
62197 static inline void atomic_long_dec(atomic_long_t *l)
62198 {
62199 atomic_t *v = (atomic_t *)l;
62200@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
62201 atomic_dec(v);
62202 }
62203
62204+#ifdef CONFIG_PAX_REFCOUNT
62205+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
62206+{
62207+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62208+
62209+ atomic_dec_unchecked(v);
62210+}
62211+#endif
62212+
62213 static inline void atomic_long_add(long i, atomic_long_t *l)
62214 {
62215 atomic_t *v = (atomic_t *)l;
62216@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
62217 atomic_add(i, v);
62218 }
62219
62220+#ifdef CONFIG_PAX_REFCOUNT
62221+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
62222+{
62223+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62224+
62225+ atomic_add_unchecked(i, v);
62226+}
62227+#endif
62228+
62229 static inline void atomic_long_sub(long i, atomic_long_t *l)
62230 {
62231 atomic_t *v = (atomic_t *)l;
62232@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
62233 atomic_sub(i, v);
62234 }
62235
62236+#ifdef CONFIG_PAX_REFCOUNT
62237+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
62238+{
62239+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62240+
62241+ atomic_sub_unchecked(i, v);
62242+}
62243+#endif
62244+
62245 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
62246 {
62247 atomic_t *v = (atomic_t *)l;
62248@@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
62249 return (long)atomic_add_return(i, v);
62250 }
62251
62252+#ifdef CONFIG_PAX_REFCOUNT
62253+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
62254+{
62255+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62256+
62257+ return (long)atomic_add_return_unchecked(i, v);
62258+}
62259+
62260+#endif
62261+
62262 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
62263 {
62264 atomic_t *v = (atomic_t *)l;
62265@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
62266 return (long)atomic_inc_return(v);
62267 }
62268
62269+#ifdef CONFIG_PAX_REFCOUNT
62270+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
62271+{
62272+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62273+
62274+ return (long)atomic_inc_return_unchecked(v);
62275+}
62276+#endif
62277+
62278 static inline long atomic_long_dec_return(atomic_long_t *l)
62279 {
62280 atomic_t *v = (atomic_t *)l;
62281@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
62282
62283 #endif /* BITS_PER_LONG == 64 */
62284
62285+#ifdef CONFIG_PAX_REFCOUNT
62286+static inline void pax_refcount_needs_these_functions(void)
62287+{
62288+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
62289+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
62290+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
62291+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
62292+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
62293+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
62294+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
62295+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
62296+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
62297+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
62298+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
62299+#ifdef CONFIG_X86
62300+ atomic_clear_mask_unchecked(0, NULL);
62301+ atomic_set_mask_unchecked(0, NULL);
62302+#endif
62303+
62304+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
62305+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
62306+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
62307+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
62308+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
62309+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
62310+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
62311+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
62312+}
62313+#else
62314+#define atomic_read_unchecked(v) atomic_read(v)
62315+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
62316+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
62317+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
62318+#define atomic_inc_unchecked(v) atomic_inc(v)
62319+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
62320+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
62321+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
62322+#define atomic_dec_unchecked(v) atomic_dec(v)
62323+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
62324+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
62325+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
62326+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
62327+
62328+#define atomic_long_read_unchecked(v) atomic_long_read(v)
62329+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
62330+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
62331+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
62332+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
62333+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
62334+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
62335+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
62336+#endif
62337+
62338 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
62339diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
62340index 1ced641..c896ee8 100644
62341--- a/include/asm-generic/atomic.h
62342+++ b/include/asm-generic/atomic.h
62343@@ -159,7 +159,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
62344 * Atomically clears the bits set in @mask from @v
62345 */
62346 #ifndef atomic_clear_mask
62347-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
62348+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
62349 {
62350 unsigned long flags;
62351
62352diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
62353index b18ce4f..2ee2843 100644
62354--- a/include/asm-generic/atomic64.h
62355+++ b/include/asm-generic/atomic64.h
62356@@ -16,6 +16,8 @@ typedef struct {
62357 long long counter;
62358 } atomic64_t;
62359
62360+typedef atomic64_t atomic64_unchecked_t;
62361+
62362 #define ATOMIC64_INIT(i) { (i) }
62363
62364 extern long long atomic64_read(const atomic64_t *v);
62365@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
62366 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
62367 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
62368
62369+#define atomic64_read_unchecked(v) atomic64_read(v)
62370+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
62371+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
62372+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
62373+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
62374+#define atomic64_inc_unchecked(v) atomic64_inc(v)
62375+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
62376+#define atomic64_dec_unchecked(v) atomic64_dec(v)
62377+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
62378+
62379 #endif /* _ASM_GENERIC_ATOMIC64_H */
62380diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
62381index 1bfcfe5..e04c5c9 100644
62382--- a/include/asm-generic/cache.h
62383+++ b/include/asm-generic/cache.h
62384@@ -6,7 +6,7 @@
62385 * cache lines need to provide their own cache.h.
62386 */
62387
62388-#define L1_CACHE_SHIFT 5
62389-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
62390+#define L1_CACHE_SHIFT 5UL
62391+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
62392
62393 #endif /* __ASM_GENERIC_CACHE_H */
62394diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
62395index 0d68a1e..b74a761 100644
62396--- a/include/asm-generic/emergency-restart.h
62397+++ b/include/asm-generic/emergency-restart.h
62398@@ -1,7 +1,7 @@
62399 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
62400 #define _ASM_GENERIC_EMERGENCY_RESTART_H
62401
62402-static inline void machine_emergency_restart(void)
62403+static inline __noreturn void machine_emergency_restart(void)
62404 {
62405 machine_restart(NULL);
62406 }
62407diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
62408index 90f99c7..00ce236 100644
62409--- a/include/asm-generic/kmap_types.h
62410+++ b/include/asm-generic/kmap_types.h
62411@@ -2,9 +2,9 @@
62412 #define _ASM_GENERIC_KMAP_TYPES_H
62413
62414 #ifdef __WITH_KM_FENCE
62415-# define KM_TYPE_NR 41
62416+# define KM_TYPE_NR 42
62417 #else
62418-# define KM_TYPE_NR 20
62419+# define KM_TYPE_NR 21
62420 #endif
62421
62422 #endif
62423diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
62424index 9ceb03b..62b0b8f 100644
62425--- a/include/asm-generic/local.h
62426+++ b/include/asm-generic/local.h
62427@@ -23,24 +23,37 @@ typedef struct
62428 atomic_long_t a;
62429 } local_t;
62430
62431+typedef struct {
62432+ atomic_long_unchecked_t a;
62433+} local_unchecked_t;
62434+
62435 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
62436
62437 #define local_read(l) atomic_long_read(&(l)->a)
62438+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
62439 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
62440+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
62441 #define local_inc(l) atomic_long_inc(&(l)->a)
62442+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
62443 #define local_dec(l) atomic_long_dec(&(l)->a)
62444+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
62445 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
62446+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
62447 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
62448+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
62449
62450 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
62451 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
62452 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
62453 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
62454 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
62455+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
62456 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
62457 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
62458+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
62459
62460 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
62461+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
62462 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
62463 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
62464 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
62465diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
62466index 725612b..9cc513a 100644
62467--- a/include/asm-generic/pgtable-nopmd.h
62468+++ b/include/asm-generic/pgtable-nopmd.h
62469@@ -1,14 +1,19 @@
62470 #ifndef _PGTABLE_NOPMD_H
62471 #define _PGTABLE_NOPMD_H
62472
62473-#ifndef __ASSEMBLY__
62474-
62475 #include <asm-generic/pgtable-nopud.h>
62476
62477-struct mm_struct;
62478-
62479 #define __PAGETABLE_PMD_FOLDED
62480
62481+#define PMD_SHIFT PUD_SHIFT
62482+#define PTRS_PER_PMD 1
62483+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
62484+#define PMD_MASK (~(PMD_SIZE-1))
62485+
62486+#ifndef __ASSEMBLY__
62487+
62488+struct mm_struct;
62489+
62490 /*
62491 * Having the pmd type consist of a pud gets the size right, and allows
62492 * us to conceptually access the pud entry that this pmd is folded into
62493@@ -16,11 +21,6 @@ struct mm_struct;
62494 */
62495 typedef struct { pud_t pud; } pmd_t;
62496
62497-#define PMD_SHIFT PUD_SHIFT
62498-#define PTRS_PER_PMD 1
62499-#define PMD_SIZE (1UL << PMD_SHIFT)
62500-#define PMD_MASK (~(PMD_SIZE-1))
62501-
62502 /*
62503 * The "pud_xxx()" functions here are trivial for a folded two-level
62504 * setup: the pmd is never bad, and a pmd always exists (as it's folded
62505diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
62506index 810431d..0ec4804f 100644
62507--- a/include/asm-generic/pgtable-nopud.h
62508+++ b/include/asm-generic/pgtable-nopud.h
62509@@ -1,10 +1,15 @@
62510 #ifndef _PGTABLE_NOPUD_H
62511 #define _PGTABLE_NOPUD_H
62512
62513-#ifndef __ASSEMBLY__
62514-
62515 #define __PAGETABLE_PUD_FOLDED
62516
62517+#define PUD_SHIFT PGDIR_SHIFT
62518+#define PTRS_PER_PUD 1
62519+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
62520+#define PUD_MASK (~(PUD_SIZE-1))
62521+
62522+#ifndef __ASSEMBLY__
62523+
62524 /*
62525 * Having the pud type consist of a pgd gets the size right, and allows
62526 * us to conceptually access the pgd entry that this pud is folded into
62527@@ -12,11 +17,6 @@
62528 */
62529 typedef struct { pgd_t pgd; } pud_t;
62530
62531-#define PUD_SHIFT PGDIR_SHIFT
62532-#define PTRS_PER_PUD 1
62533-#define PUD_SIZE (1UL << PUD_SHIFT)
62534-#define PUD_MASK (~(PUD_SIZE-1))
62535-
62536 /*
62537 * The "pgd_xxx()" functions here are trivial for a folded two-level
62538 * setup: the pud is never bad, and a pud always exists (as it's folded
62539@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
62540 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
62541
62542 #define pgd_populate(mm, pgd, pud) do { } while (0)
62543+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
62544 /*
62545 * (puds are folded into pgds so this doesn't get actually called,
62546 * but the define is needed for a generic inline function.)
62547diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
62548index b36ce40..019426d 100644
62549--- a/include/asm-generic/pgtable.h
62550+++ b/include/asm-generic/pgtable.h
62551@@ -554,6 +554,14 @@ static inline int pmd_trans_unstable(pmd_t *pmd)
62552 #endif
62553 }
62554
62555+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
62556+static inline unsigned long pax_open_kernel(void) { return 0; }
62557+#endif
62558+
62559+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
62560+static inline unsigned long pax_close_kernel(void) { return 0; }
62561+#endif
62562+
62563 #endif /* CONFIG_MMU */
62564
62565 #endif /* !__ASSEMBLY__ */
62566diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
62567index d1ea7ce..b1ebf2a 100644
62568--- a/include/asm-generic/vmlinux.lds.h
62569+++ b/include/asm-generic/vmlinux.lds.h
62570@@ -218,6 +218,7 @@
62571 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
62572 VMLINUX_SYMBOL(__start_rodata) = .; \
62573 *(.rodata) *(.rodata.*) \
62574+ *(.data..read_only) \
62575 *(__vermagic) /* Kernel version magic */ \
62576 . = ALIGN(8); \
62577 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
62578@@ -725,17 +726,18 @@
62579 * section in the linker script will go there too. @phdr should have
62580 * a leading colon.
62581 *
62582- * Note that this macros defines __per_cpu_load as an absolute symbol.
62583+ * Note that this macros defines per_cpu_load as an absolute symbol.
62584 * If there is no need to put the percpu section at a predetermined
62585 * address, use PERCPU_SECTION.
62586 */
62587 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
62588- VMLINUX_SYMBOL(__per_cpu_load) = .; \
62589- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
62590+ per_cpu_load = .; \
62591+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
62592 - LOAD_OFFSET) { \
62593+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
62594 PERCPU_INPUT(cacheline) \
62595 } phdr \
62596- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
62597+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
62598
62599 /**
62600 * PERCPU_SECTION - define output section for percpu area, simple version
62601diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
62602index 418d270..bfd2794 100644
62603--- a/include/crypto/algapi.h
62604+++ b/include/crypto/algapi.h
62605@@ -34,7 +34,7 @@ struct crypto_type {
62606 unsigned int maskclear;
62607 unsigned int maskset;
62608 unsigned int tfmsize;
62609-};
62610+} __do_const;
62611
62612 struct crypto_instance {
62613 struct crypto_alg alg;
62614diff --git a/include/drm/drmP.h b/include/drm/drmP.h
62615index 3fd8280..2b3c415 100644
62616--- a/include/drm/drmP.h
62617+++ b/include/drm/drmP.h
62618@@ -72,6 +72,7 @@
62619 #include <linux/workqueue.h>
62620 #include <linux/poll.h>
62621 #include <asm/pgalloc.h>
62622+#include <asm/local.h>
62623 #include <drm/drm.h>
62624 #include <drm/drm_sarea.h>
62625
62626@@ -1068,7 +1069,7 @@ struct drm_device {
62627
62628 /** \name Usage Counters */
62629 /*@{ */
62630- int open_count; /**< Outstanding files open */
62631+ local_t open_count; /**< Outstanding files open */
62632 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
62633 atomic_t vma_count; /**< Outstanding vma areas open */
62634 int buf_use; /**< Buffers in use -- cannot alloc */
62635@@ -1079,7 +1080,7 @@ struct drm_device {
62636 /*@{ */
62637 unsigned long counters;
62638 enum drm_stat_type types[15];
62639- atomic_t counts[15];
62640+ atomic_unchecked_t counts[15];
62641 /*@} */
62642
62643 struct list_head filelist;
62644diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
62645index e01cc80..319855d 100644
62646--- a/include/drm/drm_crtc_helper.h
62647+++ b/include/drm/drm_crtc_helper.h
62648@@ -81,7 +81,7 @@ struct drm_crtc_helper_funcs {
62649
62650 /* disable crtc when not in use - more explicit than dpms off */
62651 void (*disable)(struct drm_crtc *crtc);
62652-};
62653+} __no_const;
62654
62655 /**
62656 * drm_encoder_helper_funcs - helper operations for encoders
62657@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
62658 struct drm_connector *connector);
62659 /* disable encoder when not in use - more explicit than dpms off */
62660 void (*disable)(struct drm_encoder *encoder);
62661-};
62662+} __no_const;
62663
62664 /**
62665 * drm_connector_helper_funcs - helper operations for connectors
62666diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
62667index d6d1da4..fdd1ac5 100644
62668--- a/include/drm/ttm/ttm_memory.h
62669+++ b/include/drm/ttm/ttm_memory.h
62670@@ -48,7 +48,7 @@
62671
62672 struct ttm_mem_shrink {
62673 int (*do_shrink) (struct ttm_mem_shrink *);
62674-};
62675+} __no_const;
62676
62677 /**
62678 * struct ttm_mem_global - Global memory accounting structure.
62679diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
62680index 22ef21c..75904ba 100644
62681--- a/include/linux/atmdev.h
62682+++ b/include/linux/atmdev.h
62683@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
62684 #endif
62685
62686 struct k_atm_aal_stats {
62687-#define __HANDLE_ITEM(i) atomic_t i
62688+#define __HANDLE_ITEM(i) atomic_unchecked_t i
62689 __AAL_STAT_ITEMS
62690 #undef __HANDLE_ITEM
62691 };
62692diff --git a/include/linux/backlight.h b/include/linux/backlight.h
62693index 5ffc6dd..e5a41ab 100644
62694--- a/include/linux/backlight.h
62695+++ b/include/linux/backlight.h
62696@@ -98,7 +98,7 @@ struct backlight_device {
62697 const struct backlight_ops *ops;
62698
62699 /* The framebuffer notifier block */
62700- struct notifier_block fb_notif;
62701+ notifier_block_no_const fb_notif;
62702
62703 struct device dev;
62704 };
62705diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
62706index cfcc6bf..9a7c73e 100644
62707--- a/include/linux/binfmts.h
62708+++ b/include/linux/binfmts.h
62709@@ -75,6 +75,7 @@ struct linux_binfmt {
62710 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
62711 int (*load_shlib)(struct file *);
62712 int (*core_dump)(struct coredump_params *cprm);
62713+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
62714 unsigned long min_coredump; /* minimal dump size */
62715 };
62716
62717diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
62718index 1756001..ab117ec 100644
62719--- a/include/linux/blkdev.h
62720+++ b/include/linux/blkdev.h
62721@@ -1478,7 +1478,7 @@ struct block_device_operations {
62722 /* this callback is with swap_lock and sometimes page table lock held */
62723 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
62724 struct module *owner;
62725-};
62726+} __do_const;
62727
62728 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
62729 unsigned long);
62730diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
62731index 7c2e030..b72475d 100644
62732--- a/include/linux/blktrace_api.h
62733+++ b/include/linux/blktrace_api.h
62734@@ -23,7 +23,7 @@ struct blk_trace {
62735 struct dentry *dir;
62736 struct dentry *dropped_file;
62737 struct dentry *msg_file;
62738- atomic_t dropped;
62739+ atomic_unchecked_t dropped;
62740 };
62741
62742 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
62743diff --git a/include/linux/cache.h b/include/linux/cache.h
62744index 4c57065..4307975 100644
62745--- a/include/linux/cache.h
62746+++ b/include/linux/cache.h
62747@@ -16,6 +16,10 @@
62748 #define __read_mostly
62749 #endif
62750
62751+#ifndef __read_only
62752+#define __read_only __read_mostly
62753+#endif
62754+
62755 #ifndef ____cacheline_aligned
62756 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
62757 #endif
62758diff --git a/include/linux/capability.h b/include/linux/capability.h
62759index 98503b7..cc36d18 100644
62760--- a/include/linux/capability.h
62761+++ b/include/linux/capability.h
62762@@ -211,8 +211,13 @@ extern bool capable(int cap);
62763 extern bool ns_capable(struct user_namespace *ns, int cap);
62764 extern bool nsown_capable(int cap);
62765 extern bool inode_capable(const struct inode *inode, int cap);
62766+extern bool capable_nolog(int cap);
62767+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
62768+extern bool inode_capable_nolog(const struct inode *inode, int cap);
62769
62770 /* audit system wants to get cap info from files as well */
62771 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
62772
62773+extern int is_privileged_binary(const struct dentry *dentry);
62774+
62775 #endif /* !_LINUX_CAPABILITY_H */
62776diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
62777index 8609d57..86e4d79 100644
62778--- a/include/linux/cdrom.h
62779+++ b/include/linux/cdrom.h
62780@@ -87,7 +87,6 @@ struct cdrom_device_ops {
62781
62782 /* driver specifications */
62783 const int capability; /* capability flags */
62784- int n_minors; /* number of active minor devices */
62785 /* handle uniform packets for scsi type devices (scsi,atapi) */
62786 int (*generic_packet) (struct cdrom_device_info *,
62787 struct packet_command *);
62788diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
62789index 42e55de..1cd0e66 100644
62790--- a/include/linux/cleancache.h
62791+++ b/include/linux/cleancache.h
62792@@ -31,7 +31,7 @@ struct cleancache_ops {
62793 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
62794 void (*invalidate_inode)(int, struct cleancache_filekey);
62795 void (*invalidate_fs)(int);
62796-};
62797+} __no_const;
62798
62799 extern struct cleancache_ops
62800 cleancache_register_ops(struct cleancache_ops *ops);
62801diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
62802index f9f5e9e..9fb4d36 100644
62803--- a/include/linux/clk-provider.h
62804+++ b/include/linux/clk-provider.h
62805@@ -112,6 +112,7 @@ struct clk_ops {
62806 unsigned long);
62807 void (*init)(struct clk_hw *hw);
62808 };
62809+typedef struct clk_ops __no_const clk_ops_no_const;
62810
62811 /**
62812 * struct clk_init_data - holds init data that's common to all clocks and is
62813diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
62814index 412bc6c..c31666e 100644
62815--- a/include/linux/compiler-gcc4.h
62816+++ b/include/linux/compiler-gcc4.h
62817@@ -32,6 +32,21 @@
62818 #define __linktime_error(message) __attribute__((__error__(message)))
62819
62820 #if __GNUC_MINOR__ >= 5
62821+
62822+#ifdef CONSTIFY_PLUGIN
62823+#define __no_const __attribute__((no_const))
62824+#define __do_const __attribute__((do_const))
62825+#endif
62826+
62827+#ifdef SIZE_OVERFLOW_PLUGIN
62828+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
62829+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
62830+#endif
62831+
62832+#ifdef LATENT_ENTROPY_PLUGIN
62833+#define __latent_entropy __attribute__((latent_entropy))
62834+#endif
62835+
62836 /*
62837 * Mark a position in code as unreachable. This can be used to
62838 * suppress control flow warnings after asm blocks that transfer
62839@@ -47,6 +62,11 @@
62840 #define __noclone __attribute__((__noclone__))
62841
62842 #endif
62843+
62844+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
62845+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
62846+#define __bos0(ptr) __bos((ptr), 0)
62847+#define __bos1(ptr) __bos((ptr), 1)
62848 #endif
62849
62850 #if __GNUC_MINOR__ >= 6
62851diff --git a/include/linux/compiler.h b/include/linux/compiler.h
62852index f430e41..38be90f 100644
62853--- a/include/linux/compiler.h
62854+++ b/include/linux/compiler.h
62855@@ -5,31 +5,62 @@
62856
62857 #ifdef __CHECKER__
62858 # define __user __attribute__((noderef, address_space(1)))
62859+# define __force_user __force __user
62860 # define __kernel __attribute__((address_space(0)))
62861+# define __force_kernel __force __kernel
62862 # define __safe __attribute__((safe))
62863 # define __force __attribute__((force))
62864 # define __nocast __attribute__((nocast))
62865 # define __iomem __attribute__((noderef, address_space(2)))
62866+# define __force_iomem __force __iomem
62867 # define __acquires(x) __attribute__((context(x,0,1)))
62868 # define __releases(x) __attribute__((context(x,1,0)))
62869 # define __acquire(x) __context__(x,1)
62870 # define __release(x) __context__(x,-1)
62871 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
62872 # define __percpu __attribute__((noderef, address_space(3)))
62873+# define __force_percpu __force __percpu
62874 #ifdef CONFIG_SPARSE_RCU_POINTER
62875 # define __rcu __attribute__((noderef, address_space(4)))
62876+# define __force_rcu __force __rcu
62877 #else
62878 # define __rcu
62879+# define __force_rcu
62880 #endif
62881 extern void __chk_user_ptr(const volatile void __user *);
62882 extern void __chk_io_ptr(const volatile void __iomem *);
62883+#elif defined(CHECKER_PLUGIN)
62884+//# define __user
62885+//# define __force_user
62886+//# define __kernel
62887+//# define __force_kernel
62888+# define __safe
62889+# define __force
62890+# define __nocast
62891+# define __iomem
62892+# define __force_iomem
62893+# define __chk_user_ptr(x) (void)0
62894+# define __chk_io_ptr(x) (void)0
62895+# define __builtin_warning(x, y...) (1)
62896+# define __acquires(x)
62897+# define __releases(x)
62898+# define __acquire(x) (void)0
62899+# define __release(x) (void)0
62900+# define __cond_lock(x,c) (c)
62901+# define __percpu
62902+# define __force_percpu
62903+# define __rcu
62904+# define __force_rcu
62905 #else
62906 # define __user
62907+# define __force_user
62908 # define __kernel
62909+# define __force_kernel
62910 # define __safe
62911 # define __force
62912 # define __nocast
62913 # define __iomem
62914+# define __force_iomem
62915 # define __chk_user_ptr(x) (void)0
62916 # define __chk_io_ptr(x) (void)0
62917 # define __builtin_warning(x, y...) (1)
62918@@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
62919 # define __release(x) (void)0
62920 # define __cond_lock(x,c) (c)
62921 # define __percpu
62922+# define __force_percpu
62923 # define __rcu
62924+# define __force_rcu
62925 #endif
62926
62927 #ifdef __KERNEL__
62928@@ -264,6 +297,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
62929 # define __attribute_const__ /* unimplemented */
62930 #endif
62931
62932+#ifndef __no_const
62933+# define __no_const
62934+#endif
62935+
62936+#ifndef __do_const
62937+# define __do_const
62938+#endif
62939+
62940+#ifndef __size_overflow
62941+# define __size_overflow(...)
62942+#endif
62943+
62944+#ifndef __intentional_overflow
62945+# define __intentional_overflow(...)
62946+#endif
62947+
62948+#ifndef __latent_entropy
62949+# define __latent_entropy
62950+#endif
62951+
62952 /*
62953 * Tell gcc if a function is cold. The compiler will assume any path
62954 * directly leading to the call is unlikely.
62955@@ -273,6 +326,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
62956 #define __cold
62957 #endif
62958
62959+#ifndef __alloc_size
62960+#define __alloc_size(...)
62961+#endif
62962+
62963+#ifndef __bos
62964+#define __bos(ptr, arg)
62965+#endif
62966+
62967+#ifndef __bos0
62968+#define __bos0(ptr)
62969+#endif
62970+
62971+#ifndef __bos1
62972+#define __bos1(ptr)
62973+#endif
62974+
62975 /* Simple shorthand for a section definition */
62976 #ifndef __section
62977 # define __section(S) __attribute__ ((__section__(#S)))
62978@@ -312,6 +381,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
62979 * use is to mediate communication between process-level code and irq/NMI
62980 * handlers, all running on the same CPU.
62981 */
62982-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
62983+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
62984+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
62985
62986 #endif /* __LINUX_COMPILER_H */
62987diff --git a/include/linux/cred.h b/include/linux/cred.h
62988index ebbed2c..908cc2c 100644
62989--- a/include/linux/cred.h
62990+++ b/include/linux/cred.h
62991@@ -208,6 +208,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
62992 static inline void validate_process_creds(void)
62993 {
62994 }
62995+static inline void validate_task_creds(struct task_struct *task)
62996+{
62997+}
62998 #endif
62999
63000 /**
63001diff --git a/include/linux/crypto.h b/include/linux/crypto.h
63002index b92eadf..b4ecdc1 100644
63003--- a/include/linux/crypto.h
63004+++ b/include/linux/crypto.h
63005@@ -373,7 +373,7 @@ struct cipher_tfm {
63006 const u8 *key, unsigned int keylen);
63007 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
63008 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
63009-};
63010+} __no_const;
63011
63012 struct hash_tfm {
63013 int (*init)(struct hash_desc *desc);
63014@@ -394,13 +394,13 @@ struct compress_tfm {
63015 int (*cot_decompress)(struct crypto_tfm *tfm,
63016 const u8 *src, unsigned int slen,
63017 u8 *dst, unsigned int *dlen);
63018-};
63019+} __no_const;
63020
63021 struct rng_tfm {
63022 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
63023 unsigned int dlen);
63024 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
63025-};
63026+} __no_const;
63027
63028 #define crt_ablkcipher crt_u.ablkcipher
63029 #define crt_aead crt_u.aead
63030diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
63031index 7925bf0..d5143d2 100644
63032--- a/include/linux/decompress/mm.h
63033+++ b/include/linux/decompress/mm.h
63034@@ -77,7 +77,7 @@ static void free(void *where)
63035 * warnings when not needed (indeed large_malloc / large_free are not
63036 * needed by inflate */
63037
63038-#define malloc(a) kmalloc(a, GFP_KERNEL)
63039+#define malloc(a) kmalloc((a), GFP_KERNEL)
63040 #define free(a) kfree(a)
63041
63042 #define large_malloc(a) vmalloc(a)
63043diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
63044index 281c72a..6438a5e 100644
63045--- a/include/linux/devfreq.h
63046+++ b/include/linux/devfreq.h
63047@@ -152,7 +152,7 @@ struct devfreq {
63048 struct device dev;
63049 struct devfreq_dev_profile *profile;
63050 const struct devfreq_governor *governor;
63051- struct notifier_block nb;
63052+ notifier_block_no_const nb;
63053
63054 unsigned long polling_jiffies;
63055 unsigned long previous_freq;
63056diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
63057index 94af418..b1ca7a2 100644
63058--- a/include/linux/dma-mapping.h
63059+++ b/include/linux/dma-mapping.h
63060@@ -54,7 +54,7 @@ struct dma_map_ops {
63061 u64 (*get_required_mask)(struct device *dev);
63062 #endif
63063 int is_phys;
63064-};
63065+} __do_const;
63066
63067 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
63068
63069diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
63070index d3201e4..8281e63 100644
63071--- a/include/linux/dmaengine.h
63072+++ b/include/linux/dmaengine.h
63073@@ -1018,9 +1018,9 @@ struct dma_pinned_list {
63074 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
63075 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
63076
63077-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
63078+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
63079 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
63080-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
63081+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
63082 struct dma_pinned_list *pinned_list, struct page *page,
63083 unsigned int offset, size_t len);
63084
63085diff --git a/include/linux/efi.h b/include/linux/efi.h
63086index 8670eb1..7eb3ade 100644
63087--- a/include/linux/efi.h
63088+++ b/include/linux/efi.h
63089@@ -643,7 +643,7 @@ struct efivar_operations {
63090 efi_get_variable_t *get_variable;
63091 efi_get_next_variable_t *get_next_variable;
63092 efi_set_variable_t *set_variable;
63093-};
63094+} __no_const;
63095
63096 struct efivars {
63097 /*
63098diff --git a/include/linux/elf.h b/include/linux/elf.h
63099index 8c9048e..16a4665 100644
63100--- a/include/linux/elf.h
63101+++ b/include/linux/elf.h
63102@@ -20,6 +20,7 @@ extern Elf32_Dyn _DYNAMIC [];
63103 #define elf_note elf32_note
63104 #define elf_addr_t Elf32_Off
63105 #define Elf_Half Elf32_Half
63106+#define elf_dyn Elf32_Dyn
63107
63108 #else
63109
63110@@ -30,6 +31,7 @@ extern Elf64_Dyn _DYNAMIC [];
63111 #define elf_note elf64_note
63112 #define elf_addr_t Elf64_Off
63113 #define Elf_Half Elf64_Half
63114+#define elf_dyn Elf64_Dyn
63115
63116 #endif
63117
63118diff --git a/include/linux/extcon.h b/include/linux/extcon.h
63119index 2c26c14..8d0cb0f 100644
63120--- a/include/linux/extcon.h
63121+++ b/include/linux/extcon.h
63122@@ -165,7 +165,7 @@ struct extcon_cable {
63123 * @previous_value the saved previous event value.
63124 */
63125 struct extcon_specific_cable_nb {
63126- struct notifier_block internal_nb;
63127+ notifier_block_no_const internal_nb;
63128 struct notifier_block *user_nb;
63129 int cable_index;
63130 struct extcon_dev *edev;
63131diff --git a/include/linux/filter.h b/include/linux/filter.h
63132index 24d251f..7afb83d 100644
63133--- a/include/linux/filter.h
63134+++ b/include/linux/filter.h
63135@@ -20,6 +20,7 @@ struct compat_sock_fprog {
63136
63137 struct sk_buff;
63138 struct sock;
63139+struct bpf_jit_work;
63140
63141 struct sk_filter
63142 {
63143@@ -27,6 +28,9 @@ struct sk_filter
63144 unsigned int len; /* Number of filter blocks */
63145 unsigned int (*bpf_func)(const struct sk_buff *skb,
63146 const struct sock_filter *filter);
63147+#ifdef CONFIG_BPF_JIT
63148+ struct bpf_jit_work *work;
63149+#endif
63150 struct rcu_head rcu;
63151 struct sock_filter insns[0];
63152 };
63153diff --git a/include/linux/firewire.h b/include/linux/firewire.h
63154index 191501a..3952e37 100644
63155--- a/include/linux/firewire.h
63156+++ b/include/linux/firewire.h
63157@@ -438,7 +438,7 @@ struct fw_iso_context {
63158 union {
63159 fw_iso_callback_t sc;
63160 fw_iso_mc_callback_t mc;
63161- } callback;
63162+ } __no_const callback;
63163 void *callback_data;
63164 };
63165
63166diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
63167index 3044254..9767f41 100644
63168--- a/include/linux/frontswap.h
63169+++ b/include/linux/frontswap.h
63170@@ -11,7 +11,7 @@ struct frontswap_ops {
63171 int (*load)(unsigned, pgoff_t, struct page *);
63172 void (*invalidate_page)(unsigned, pgoff_t);
63173 void (*invalidate_area)(unsigned);
63174-};
63175+} __no_const;
63176
63177 extern bool frontswap_enabled;
63178 extern struct frontswap_ops
63179diff --git a/include/linux/fs.h b/include/linux/fs.h
63180index 75fe9a1..72a4a6b 100644
63181--- a/include/linux/fs.h
63182+++ b/include/linux/fs.h
63183@@ -1543,7 +1543,8 @@ struct file_operations {
63184 int (*setlease)(struct file *, long, struct file_lock **);
63185 long (*fallocate)(struct file *file, int mode, loff_t offset,
63186 loff_t len);
63187-};
63188+} __do_const;
63189+typedef struct file_operations __no_const file_operations_no_const;
63190
63191 struct inode_operations {
63192 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
63193diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
63194index 003dc0f..3c4ea97 100644
63195--- a/include/linux/fs_struct.h
63196+++ b/include/linux/fs_struct.h
63197@@ -6,7 +6,7 @@
63198 #include <linux/seqlock.h>
63199
63200 struct fs_struct {
63201- int users;
63202+ atomic_t users;
63203 spinlock_t lock;
63204 seqcount_t seq;
63205 int umask;
63206diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
63207index ce31408..b1ad003 100644
63208--- a/include/linux/fscache-cache.h
63209+++ b/include/linux/fscache-cache.h
63210@@ -102,7 +102,7 @@ struct fscache_operation {
63211 fscache_operation_release_t release;
63212 };
63213
63214-extern atomic_t fscache_op_debug_id;
63215+extern atomic_unchecked_t fscache_op_debug_id;
63216 extern void fscache_op_work_func(struct work_struct *work);
63217
63218 extern void fscache_enqueue_operation(struct fscache_operation *);
63219@@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
63220 {
63221 INIT_WORK(&op->work, fscache_op_work_func);
63222 atomic_set(&op->usage, 1);
63223- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
63224+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
63225 op->processor = processor;
63226 op->release = release;
63227 INIT_LIST_HEAD(&op->pend_link);
63228diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
63229index 0fbfb46..52a6556 100644
63230--- a/include/linux/fsnotify.h
63231+++ b/include/linux/fsnotify.h
63232@@ -315,7 +315,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
63233 */
63234 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
63235 {
63236- return kstrdup(name, GFP_KERNEL);
63237+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
63238 }
63239
63240 /*
63241diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
63242index 63d966d..cdcb717 100644
63243--- a/include/linux/fsnotify_backend.h
63244+++ b/include/linux/fsnotify_backend.h
63245@@ -105,6 +105,7 @@ struct fsnotify_ops {
63246 void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group);
63247 void (*free_event_priv)(struct fsnotify_event_private_data *priv);
63248 };
63249+typedef struct fsnotify_ops __no_const fsnotify_ops_no_const;
63250
63251 /*
63252 * A group is a "thing" that wants to receive notification about filesystem
63253diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
63254index 642928c..e6c83a7 100644
63255--- a/include/linux/ftrace_event.h
63256+++ b/include/linux/ftrace_event.h
63257@@ -97,7 +97,7 @@ struct trace_event_functions {
63258 trace_print_func raw;
63259 trace_print_func hex;
63260 trace_print_func binary;
63261-};
63262+} __no_const;
63263
63264 struct trace_event {
63265 struct hlist_node node;
63266@@ -266,7 +266,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
63267 extern int trace_add_event_call(struct ftrace_event_call *call);
63268 extern void trace_remove_event_call(struct ftrace_event_call *call);
63269
63270-#define is_signed_type(type) (((type)(-1)) < 0)
63271+#define is_signed_type(type) (((type)(-1)) < (type)1)
63272
63273 int trace_set_clr_event(const char *system, const char *event, int set);
63274
63275diff --git a/include/linux/genhd.h b/include/linux/genhd.h
63276index 4f440b3..342233a 100644
63277--- a/include/linux/genhd.h
63278+++ b/include/linux/genhd.h
63279@@ -190,7 +190,7 @@ struct gendisk {
63280 struct kobject *slave_dir;
63281
63282 struct timer_rand_state *random;
63283- atomic_t sync_io; /* RAID */
63284+ atomic_unchecked_t sync_io; /* RAID */
63285 struct disk_events *ev;
63286 #ifdef CONFIG_BLK_DEV_INTEGRITY
63287 struct blk_integrity *integrity;
63288diff --git a/include/linux/gfp.h b/include/linux/gfp.h
63289index d0a7967..63c4c47 100644
63290--- a/include/linux/gfp.h
63291+++ b/include/linux/gfp.h
63292@@ -35,6 +35,12 @@ struct vm_area_struct;
63293 #define ___GFP_OTHER_NODE 0x800000u
63294 #define ___GFP_WRITE 0x1000000u
63295
63296+#ifdef CONFIG_PAX_USERCOPY_SLABS
63297+#define ___GFP_USERCOPY 0x2000000u
63298+#else
63299+#define ___GFP_USERCOPY 0
63300+#endif
63301+
63302 /*
63303 * GFP bitmasks..
63304 *
63305@@ -89,6 +95,7 @@ struct vm_area_struct;
63306 #define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)
63307 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
63308 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
63309+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
63310
63311 /*
63312 * This may seem redundant, but it's a way of annotating false positives vs.
63313@@ -96,7 +103,7 @@ struct vm_area_struct;
63314 */
63315 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
63316
63317-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
63318+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
63319 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
63320
63321 /* This equals 0, but use constants in case they ever change */
63322@@ -150,6 +157,8 @@ struct vm_area_struct;
63323 /* 4GB DMA on some platforms */
63324 #define GFP_DMA32 __GFP_DMA32
63325
63326+#define GFP_USERCOPY __GFP_USERCOPY
63327+
63328 /* Convert GFP flags to their corresponding migrate type */
63329 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
63330 {
63331diff --git a/include/linux/gracl.h b/include/linux/gracl.h
63332new file mode 100644
63333index 0000000..ebe6d72
63334--- /dev/null
63335+++ b/include/linux/gracl.h
63336@@ -0,0 +1,319 @@
63337+#ifndef GR_ACL_H
63338+#define GR_ACL_H
63339+
63340+#include <linux/grdefs.h>
63341+#include <linux/resource.h>
63342+#include <linux/capability.h>
63343+#include <linux/dcache.h>
63344+#include <asm/resource.h>
63345+
63346+/* Major status information */
63347+
63348+#define GR_VERSION "grsecurity 2.9.1"
63349+#define GRSECURITY_VERSION 0x2901
63350+
63351+enum {
63352+ GR_SHUTDOWN = 0,
63353+ GR_ENABLE = 1,
63354+ GR_SPROLE = 2,
63355+ GR_RELOAD = 3,
63356+ GR_SEGVMOD = 4,
63357+ GR_STATUS = 5,
63358+ GR_UNSPROLE = 6,
63359+ GR_PASSSET = 7,
63360+ GR_SPROLEPAM = 8,
63361+};
63362+
63363+/* Password setup definitions
63364+ * kernel/grhash.c */
63365+enum {
63366+ GR_PW_LEN = 128,
63367+ GR_SALT_LEN = 16,
63368+ GR_SHA_LEN = 32,
63369+};
63370+
63371+enum {
63372+ GR_SPROLE_LEN = 64,
63373+};
63374+
63375+enum {
63376+ GR_NO_GLOB = 0,
63377+ GR_REG_GLOB,
63378+ GR_CREATE_GLOB
63379+};
63380+
63381+#define GR_NLIMITS 32
63382+
63383+/* Begin Data Structures */
63384+
63385+struct sprole_pw {
63386+ unsigned char *rolename;
63387+ unsigned char salt[GR_SALT_LEN];
63388+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
63389+};
63390+
63391+struct name_entry {
63392+ __u32 key;
63393+ ino_t inode;
63394+ dev_t device;
63395+ char *name;
63396+ __u16 len;
63397+ __u8 deleted;
63398+ struct name_entry *prev;
63399+ struct name_entry *next;
63400+};
63401+
63402+struct inodev_entry {
63403+ struct name_entry *nentry;
63404+ struct inodev_entry *prev;
63405+ struct inodev_entry *next;
63406+};
63407+
63408+struct acl_role_db {
63409+ struct acl_role_label **r_hash;
63410+ __u32 r_size;
63411+};
63412+
63413+struct inodev_db {
63414+ struct inodev_entry **i_hash;
63415+ __u32 i_size;
63416+};
63417+
63418+struct name_db {
63419+ struct name_entry **n_hash;
63420+ __u32 n_size;
63421+};
63422+
63423+struct crash_uid {
63424+ uid_t uid;
63425+ unsigned long expires;
63426+};
63427+
63428+struct gr_hash_struct {
63429+ void **table;
63430+ void **nametable;
63431+ void *first;
63432+ __u32 table_size;
63433+ __u32 used_size;
63434+ int type;
63435+};
63436+
63437+/* Userspace Grsecurity ACL data structures */
63438+
63439+struct acl_subject_label {
63440+ char *filename;
63441+ ino_t inode;
63442+ dev_t device;
63443+ __u32 mode;
63444+ kernel_cap_t cap_mask;
63445+ kernel_cap_t cap_lower;
63446+ kernel_cap_t cap_invert_audit;
63447+
63448+ struct rlimit res[GR_NLIMITS];
63449+ __u32 resmask;
63450+
63451+ __u8 user_trans_type;
63452+ __u8 group_trans_type;
63453+ uid_t *user_transitions;
63454+ gid_t *group_transitions;
63455+ __u16 user_trans_num;
63456+ __u16 group_trans_num;
63457+
63458+ __u32 sock_families[2];
63459+ __u32 ip_proto[8];
63460+ __u32 ip_type;
63461+ struct acl_ip_label **ips;
63462+ __u32 ip_num;
63463+ __u32 inaddr_any_override;
63464+
63465+ __u32 crashes;
63466+ unsigned long expires;
63467+
63468+ struct acl_subject_label *parent_subject;
63469+ struct gr_hash_struct *hash;
63470+ struct acl_subject_label *prev;
63471+ struct acl_subject_label *next;
63472+
63473+ struct acl_object_label **obj_hash;
63474+ __u32 obj_hash_size;
63475+ __u16 pax_flags;
63476+};
63477+
63478+struct role_allowed_ip {
63479+ __u32 addr;
63480+ __u32 netmask;
63481+
63482+ struct role_allowed_ip *prev;
63483+ struct role_allowed_ip *next;
63484+};
63485+
63486+struct role_transition {
63487+ char *rolename;
63488+
63489+ struct role_transition *prev;
63490+ struct role_transition *next;
63491+};
63492+
63493+struct acl_role_label {
63494+ char *rolename;
63495+ uid_t uidgid;
63496+ __u16 roletype;
63497+
63498+ __u16 auth_attempts;
63499+ unsigned long expires;
63500+
63501+ struct acl_subject_label *root_label;
63502+ struct gr_hash_struct *hash;
63503+
63504+ struct acl_role_label *prev;
63505+ struct acl_role_label *next;
63506+
63507+ struct role_transition *transitions;
63508+ struct role_allowed_ip *allowed_ips;
63509+ uid_t *domain_children;
63510+ __u16 domain_child_num;
63511+
63512+ umode_t umask;
63513+
63514+ struct acl_subject_label **subj_hash;
63515+ __u32 subj_hash_size;
63516+};
63517+
63518+struct user_acl_role_db {
63519+ struct acl_role_label **r_table;
63520+ __u32 num_pointers; /* Number of allocations to track */
63521+ __u32 num_roles; /* Number of roles */
63522+ __u32 num_domain_children; /* Number of domain children */
63523+ __u32 num_subjects; /* Number of subjects */
63524+ __u32 num_objects; /* Number of objects */
63525+};
63526+
63527+struct acl_object_label {
63528+ char *filename;
63529+ ino_t inode;
63530+ dev_t device;
63531+ __u32 mode;
63532+
63533+ struct acl_subject_label *nested;
63534+ struct acl_object_label *globbed;
63535+
63536+ /* next two structures not used */
63537+
63538+ struct acl_object_label *prev;
63539+ struct acl_object_label *next;
63540+};
63541+
63542+struct acl_ip_label {
63543+ char *iface;
63544+ __u32 addr;
63545+ __u32 netmask;
63546+ __u16 low, high;
63547+ __u8 mode;
63548+ __u32 type;
63549+ __u32 proto[8];
63550+
63551+ /* next two structures not used */
63552+
63553+ struct acl_ip_label *prev;
63554+ struct acl_ip_label *next;
63555+};
63556+
63557+struct gr_arg {
63558+ struct user_acl_role_db role_db;
63559+ unsigned char pw[GR_PW_LEN];
63560+ unsigned char salt[GR_SALT_LEN];
63561+ unsigned char sum[GR_SHA_LEN];
63562+ unsigned char sp_role[GR_SPROLE_LEN];
63563+ struct sprole_pw *sprole_pws;
63564+ dev_t segv_device;
63565+ ino_t segv_inode;
63566+ uid_t segv_uid;
63567+ __u16 num_sprole_pws;
63568+ __u16 mode;
63569+};
63570+
63571+struct gr_arg_wrapper {
63572+ struct gr_arg *arg;
63573+ __u32 version;
63574+ __u32 size;
63575+};
63576+
63577+struct subject_map {
63578+ struct acl_subject_label *user;
63579+ struct acl_subject_label *kernel;
63580+ struct subject_map *prev;
63581+ struct subject_map *next;
63582+};
63583+
63584+struct acl_subj_map_db {
63585+ struct subject_map **s_hash;
63586+ __u32 s_size;
63587+};
63588+
63589+/* End Data Structures Section */
63590+
63591+/* Hash functions generated by empirical testing by Brad Spengler
63592+ Makes good use of the low bits of the inode. Generally 0-1 times
63593+ in loop for successful match. 0-3 for unsuccessful match.
63594+ Shift/add algorithm with modulus of table size and an XOR*/
63595+
63596+static __inline__ unsigned int
63597+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
63598+{
63599+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
63600+}
63601+
63602+ static __inline__ unsigned int
63603+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
63604+{
63605+ return ((const unsigned long)userp % sz);
63606+}
63607+
63608+static __inline__ unsigned int
63609+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
63610+{
63611+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
63612+}
63613+
63614+static __inline__ unsigned int
63615+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
63616+{
63617+ return full_name_hash((const unsigned char *)name, len) % sz;
63618+}
63619+
63620+#define FOR_EACH_ROLE_START(role) \
63621+ role = role_list; \
63622+ while (role) {
63623+
63624+#define FOR_EACH_ROLE_END(role) \
63625+ role = role->prev; \
63626+ }
63627+
63628+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
63629+ subj = NULL; \
63630+ iter = 0; \
63631+ while (iter < role->subj_hash_size) { \
63632+ if (subj == NULL) \
63633+ subj = role->subj_hash[iter]; \
63634+ if (subj == NULL) { \
63635+ iter++; \
63636+ continue; \
63637+ }
63638+
63639+#define FOR_EACH_SUBJECT_END(subj,iter) \
63640+ subj = subj->next; \
63641+ if (subj == NULL) \
63642+ iter++; \
63643+ }
63644+
63645+
63646+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
63647+ subj = role->hash->first; \
63648+ while (subj != NULL) {
63649+
63650+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
63651+ subj = subj->next; \
63652+ }
63653+
63654+#endif
63655+
63656diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
63657new file mode 100644
63658index 0000000..323ecf2
63659--- /dev/null
63660+++ b/include/linux/gralloc.h
63661@@ -0,0 +1,9 @@
63662+#ifndef __GRALLOC_H
63663+#define __GRALLOC_H
63664+
63665+void acl_free_all(void);
63666+int acl_alloc_stack_init(unsigned long size);
63667+void *acl_alloc(unsigned long len);
63668+void *acl_alloc_num(unsigned long num, unsigned long len);
63669+
63670+#endif
63671diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
63672new file mode 100644
63673index 0000000..be66033
63674--- /dev/null
63675+++ b/include/linux/grdefs.h
63676@@ -0,0 +1,140 @@
63677+#ifndef GRDEFS_H
63678+#define GRDEFS_H
63679+
63680+/* Begin grsecurity status declarations */
63681+
63682+enum {
63683+ GR_READY = 0x01,
63684+ GR_STATUS_INIT = 0x00 // disabled state
63685+};
63686+
63687+/* Begin ACL declarations */
63688+
63689+/* Role flags */
63690+
63691+enum {
63692+ GR_ROLE_USER = 0x0001,
63693+ GR_ROLE_GROUP = 0x0002,
63694+ GR_ROLE_DEFAULT = 0x0004,
63695+ GR_ROLE_SPECIAL = 0x0008,
63696+ GR_ROLE_AUTH = 0x0010,
63697+ GR_ROLE_NOPW = 0x0020,
63698+ GR_ROLE_GOD = 0x0040,
63699+ GR_ROLE_LEARN = 0x0080,
63700+ GR_ROLE_TPE = 0x0100,
63701+ GR_ROLE_DOMAIN = 0x0200,
63702+ GR_ROLE_PAM = 0x0400,
63703+ GR_ROLE_PERSIST = 0x0800
63704+};
63705+
63706+/* ACL Subject and Object mode flags */
63707+enum {
63708+ GR_DELETED = 0x80000000
63709+};
63710+
63711+/* ACL Object-only mode flags */
63712+enum {
63713+ GR_READ = 0x00000001,
63714+ GR_APPEND = 0x00000002,
63715+ GR_WRITE = 0x00000004,
63716+ GR_EXEC = 0x00000008,
63717+ GR_FIND = 0x00000010,
63718+ GR_INHERIT = 0x00000020,
63719+ GR_SETID = 0x00000040,
63720+ GR_CREATE = 0x00000080,
63721+ GR_DELETE = 0x00000100,
63722+ GR_LINK = 0x00000200,
63723+ GR_AUDIT_READ = 0x00000400,
63724+ GR_AUDIT_APPEND = 0x00000800,
63725+ GR_AUDIT_WRITE = 0x00001000,
63726+ GR_AUDIT_EXEC = 0x00002000,
63727+ GR_AUDIT_FIND = 0x00004000,
63728+ GR_AUDIT_INHERIT= 0x00008000,
63729+ GR_AUDIT_SETID = 0x00010000,
63730+ GR_AUDIT_CREATE = 0x00020000,
63731+ GR_AUDIT_DELETE = 0x00040000,
63732+ GR_AUDIT_LINK = 0x00080000,
63733+ GR_PTRACERD = 0x00100000,
63734+ GR_NOPTRACE = 0x00200000,
63735+ GR_SUPPRESS = 0x00400000,
63736+ GR_NOLEARN = 0x00800000,
63737+ GR_INIT_TRANSFER= 0x01000000
63738+};
63739+
63740+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
63741+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
63742+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
63743+
63744+/* ACL subject-only mode flags */
63745+enum {
63746+ GR_KILL = 0x00000001,
63747+ GR_VIEW = 0x00000002,
63748+ GR_PROTECTED = 0x00000004,
63749+ GR_LEARN = 0x00000008,
63750+ GR_OVERRIDE = 0x00000010,
63751+ /* just a placeholder, this mode is only used in userspace */
63752+ GR_DUMMY = 0x00000020,
63753+ GR_PROTSHM = 0x00000040,
63754+ GR_KILLPROC = 0x00000080,
63755+ GR_KILLIPPROC = 0x00000100,
63756+ /* just a placeholder, this mode is only used in userspace */
63757+ GR_NOTROJAN = 0x00000200,
63758+ GR_PROTPROCFD = 0x00000400,
63759+ GR_PROCACCT = 0x00000800,
63760+ GR_RELAXPTRACE = 0x00001000,
63761+ //GR_NESTED = 0x00002000,
63762+ GR_INHERITLEARN = 0x00004000,
63763+ GR_PROCFIND = 0x00008000,
63764+ GR_POVERRIDE = 0x00010000,
63765+ GR_KERNELAUTH = 0x00020000,
63766+ GR_ATSECURE = 0x00040000,
63767+ GR_SHMEXEC = 0x00080000
63768+};
63769+
63770+enum {
63771+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
63772+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
63773+ GR_PAX_ENABLE_MPROTECT = 0x0004,
63774+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
63775+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
63776+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
63777+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
63778+ GR_PAX_DISABLE_MPROTECT = 0x0400,
63779+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
63780+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
63781+};
63782+
63783+enum {
63784+ GR_ID_USER = 0x01,
63785+ GR_ID_GROUP = 0x02,
63786+};
63787+
63788+enum {
63789+ GR_ID_ALLOW = 0x01,
63790+ GR_ID_DENY = 0x02,
63791+};
63792+
63793+#define GR_CRASH_RES 31
63794+#define GR_UIDTABLE_MAX 500
63795+
63796+/* begin resource learning section */
63797+enum {
63798+ GR_RLIM_CPU_BUMP = 60,
63799+ GR_RLIM_FSIZE_BUMP = 50000,
63800+ GR_RLIM_DATA_BUMP = 10000,
63801+ GR_RLIM_STACK_BUMP = 1000,
63802+ GR_RLIM_CORE_BUMP = 10000,
63803+ GR_RLIM_RSS_BUMP = 500000,
63804+ GR_RLIM_NPROC_BUMP = 1,
63805+ GR_RLIM_NOFILE_BUMP = 5,
63806+ GR_RLIM_MEMLOCK_BUMP = 50000,
63807+ GR_RLIM_AS_BUMP = 500000,
63808+ GR_RLIM_LOCKS_BUMP = 2,
63809+ GR_RLIM_SIGPENDING_BUMP = 5,
63810+ GR_RLIM_MSGQUEUE_BUMP = 10000,
63811+ GR_RLIM_NICE_BUMP = 1,
63812+ GR_RLIM_RTPRIO_BUMP = 1,
63813+ GR_RLIM_RTTIME_BUMP = 1000000
63814+};
63815+
63816+#endif
63817diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
63818new file mode 100644
63819index 0000000..c9292f7
63820--- /dev/null
63821+++ b/include/linux/grinternal.h
63822@@ -0,0 +1,223 @@
63823+#ifndef __GRINTERNAL_H
63824+#define __GRINTERNAL_H
63825+
63826+#ifdef CONFIG_GRKERNSEC
63827+
63828+#include <linux/fs.h>
63829+#include <linux/mnt_namespace.h>
63830+#include <linux/nsproxy.h>
63831+#include <linux/gracl.h>
63832+#include <linux/grdefs.h>
63833+#include <linux/grmsg.h>
63834+
63835+void gr_add_learn_entry(const char *fmt, ...)
63836+ __attribute__ ((format (printf, 1, 2)));
63837+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
63838+ const struct vfsmount *mnt);
63839+__u32 gr_check_create(const struct dentry *new_dentry,
63840+ const struct dentry *parent,
63841+ const struct vfsmount *mnt, const __u32 mode);
63842+int gr_check_protected_task(const struct task_struct *task);
63843+__u32 to_gr_audit(const __u32 reqmode);
63844+int gr_set_acls(const int type);
63845+int gr_apply_subject_to_task(struct task_struct *task);
63846+int gr_acl_is_enabled(void);
63847+char gr_roletype_to_char(void);
63848+
63849+void gr_handle_alertkill(struct task_struct *task);
63850+char *gr_to_filename(const struct dentry *dentry,
63851+ const struct vfsmount *mnt);
63852+char *gr_to_filename1(const struct dentry *dentry,
63853+ const struct vfsmount *mnt);
63854+char *gr_to_filename2(const struct dentry *dentry,
63855+ const struct vfsmount *mnt);
63856+char *gr_to_filename3(const struct dentry *dentry,
63857+ const struct vfsmount *mnt);
63858+
63859+extern int grsec_enable_ptrace_readexec;
63860+extern int grsec_enable_harden_ptrace;
63861+extern int grsec_enable_link;
63862+extern int grsec_enable_fifo;
63863+extern int grsec_enable_execve;
63864+extern int grsec_enable_shm;
63865+extern int grsec_enable_execlog;
63866+extern int grsec_enable_signal;
63867+extern int grsec_enable_audit_ptrace;
63868+extern int grsec_enable_forkfail;
63869+extern int grsec_enable_time;
63870+extern int grsec_enable_rofs;
63871+extern int grsec_enable_chroot_shmat;
63872+extern int grsec_enable_chroot_mount;
63873+extern int grsec_enable_chroot_double;
63874+extern int grsec_enable_chroot_pivot;
63875+extern int grsec_enable_chroot_chdir;
63876+extern int grsec_enable_chroot_chmod;
63877+extern int grsec_enable_chroot_mknod;
63878+extern int grsec_enable_chroot_fchdir;
63879+extern int grsec_enable_chroot_nice;
63880+extern int grsec_enable_chroot_execlog;
63881+extern int grsec_enable_chroot_caps;
63882+extern int grsec_enable_chroot_sysctl;
63883+extern int grsec_enable_chroot_unix;
63884+extern int grsec_enable_symlinkown;
63885+extern int grsec_symlinkown_gid;
63886+extern int grsec_enable_tpe;
63887+extern int grsec_tpe_gid;
63888+extern int grsec_enable_tpe_all;
63889+extern int grsec_enable_tpe_invert;
63890+extern int grsec_enable_socket_all;
63891+extern int grsec_socket_all_gid;
63892+extern int grsec_enable_socket_client;
63893+extern int grsec_socket_client_gid;
63894+extern int grsec_enable_socket_server;
63895+extern int grsec_socket_server_gid;
63896+extern int grsec_audit_gid;
63897+extern int grsec_enable_group;
63898+extern int grsec_enable_audit_textrel;
63899+extern int grsec_enable_log_rwxmaps;
63900+extern int grsec_enable_mount;
63901+extern int grsec_enable_chdir;
63902+extern int grsec_resource_logging;
63903+extern int grsec_enable_blackhole;
63904+extern int grsec_lastack_retries;
63905+extern int grsec_enable_brute;
63906+extern int grsec_lock;
63907+
63908+extern spinlock_t grsec_alert_lock;
63909+extern unsigned long grsec_alert_wtime;
63910+extern unsigned long grsec_alert_fyet;
63911+
63912+extern spinlock_t grsec_audit_lock;
63913+
63914+extern rwlock_t grsec_exec_file_lock;
63915+
63916+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
63917+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
63918+ (tsk)->exec_file->f_vfsmnt) : "/")
63919+
63920+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
63921+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
63922+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
63923+
63924+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
63925+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
63926+ (tsk)->exec_file->f_vfsmnt) : "/")
63927+
63928+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
63929+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
63930+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
63931+
63932+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
63933+
63934+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
63935+
63936+#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
63937+ (task)->pid, (cred)->uid, \
63938+ (cred)->euid, (cred)->gid, (cred)->egid, \
63939+ gr_parent_task_fullpath(task), \
63940+ (task)->real_parent->comm, (task)->real_parent->pid, \
63941+ (pcred)->uid, (pcred)->euid, \
63942+ (pcred)->gid, (pcred)->egid
63943+
63944+#define GR_CHROOT_CAPS {{ \
63945+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
63946+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
63947+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
63948+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
63949+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
63950+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
63951+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
63952+
63953+#define security_learn(normal_msg,args...) \
63954+({ \
63955+ read_lock(&grsec_exec_file_lock); \
63956+ gr_add_learn_entry(normal_msg "\n", ## args); \
63957+ read_unlock(&grsec_exec_file_lock); \
63958+})
63959+
63960+enum {
63961+ GR_DO_AUDIT,
63962+ GR_DONT_AUDIT,
63963+ /* used for non-audit messages that we shouldn't kill the task on */
63964+ GR_DONT_AUDIT_GOOD
63965+};
63966+
63967+enum {
63968+ GR_TTYSNIFF,
63969+ GR_RBAC,
63970+ GR_RBAC_STR,
63971+ GR_STR_RBAC,
63972+ GR_RBAC_MODE2,
63973+ GR_RBAC_MODE3,
63974+ GR_FILENAME,
63975+ GR_SYSCTL_HIDDEN,
63976+ GR_NOARGS,
63977+ GR_ONE_INT,
63978+ GR_ONE_INT_TWO_STR,
63979+ GR_ONE_STR,
63980+ GR_STR_INT,
63981+ GR_TWO_STR_INT,
63982+ GR_TWO_INT,
63983+ GR_TWO_U64,
63984+ GR_THREE_INT,
63985+ GR_FIVE_INT_TWO_STR,
63986+ GR_TWO_STR,
63987+ GR_THREE_STR,
63988+ GR_FOUR_STR,
63989+ GR_STR_FILENAME,
63990+ GR_FILENAME_STR,
63991+ GR_FILENAME_TWO_INT,
63992+ GR_FILENAME_TWO_INT_STR,
63993+ GR_TEXTREL,
63994+ GR_PTRACE,
63995+ GR_RESOURCE,
63996+ GR_CAP,
63997+ GR_SIG,
63998+ GR_SIG2,
63999+ GR_CRASH1,
64000+ GR_CRASH2,
64001+ GR_PSACCT,
64002+ GR_RWXMAP
64003+};
64004+
64005+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
64006+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
64007+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
64008+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
64009+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
64010+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
64011+#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)
64012+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
64013+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
64014+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
64015+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
64016+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
64017+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
64018+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
64019+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
64020+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
64021+#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)
64022+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
64023+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
64024+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
64025+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
64026+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
64027+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
64028+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
64029+#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)
64030+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
64031+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
64032+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
64033+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
64034+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
64035+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
64036+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
64037+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
64038+#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)
64039+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
64040+
64041+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
64042+
64043+#endif
64044+
64045+#endif
64046diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
64047new file mode 100644
64048index 0000000..2bd4c8d
64049--- /dev/null
64050+++ b/include/linux/grmsg.h
64051@@ -0,0 +1,111 @@
64052+#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"
64053+#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"
64054+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
64055+#define GR_STOPMOD_MSG "denied modification of module state by "
64056+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
64057+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
64058+#define GR_IOPERM_MSG "denied use of ioperm() by "
64059+#define GR_IOPL_MSG "denied use of iopl() by "
64060+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
64061+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
64062+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
64063+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
64064+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
64065+#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"
64066+#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"
64067+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
64068+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
64069+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
64070+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
64071+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
64072+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
64073+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
64074+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
64075+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
64076+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
64077+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
64078+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
64079+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
64080+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
64081+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
64082+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
64083+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
64084+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
64085+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
64086+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
64087+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
64088+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
64089+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
64090+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
64091+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
64092+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
64093+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
64094+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
64095+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
64096+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
64097+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
64098+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
64099+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
64100+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
64101+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
64102+#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"
64103+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
64104+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
64105+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
64106+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
64107+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
64108+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
64109+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
64110+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
64111+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
64112+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
64113+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
64114+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
64115+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
64116+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
64117+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
64118+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
64119+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
64120+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
64121+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
64122+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
64123+#define GR_FAILFORK_MSG "failed fork with errno %s by "
64124+#define GR_NICE_CHROOT_MSG "denied priority change by "
64125+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
64126+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
64127+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
64128+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
64129+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
64130+#define GR_TIME_MSG "time set by "
64131+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
64132+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
64133+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
64134+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
64135+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
64136+#define GR_BIND_MSG "denied bind() by "
64137+#define GR_CONNECT_MSG "denied connect() by "
64138+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
64139+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
64140+#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"
64141+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
64142+#define GR_CAP_ACL_MSG "use of %s denied for "
64143+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
64144+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
64145+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
64146+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
64147+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
64148+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
64149+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
64150+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
64151+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
64152+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
64153+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
64154+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
64155+#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
64156+#define GR_VM86_MSG "denied use of vm86 by "
64157+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
64158+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
64159+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
64160+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
64161+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
64162+#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 "
64163diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
64164new file mode 100644
64165index 0000000..f2f5d5b
64166--- /dev/null
64167+++ b/include/linux/grsecurity.h
64168@@ -0,0 +1,239 @@
64169+#ifndef GR_SECURITY_H
64170+#define GR_SECURITY_H
64171+#include <linux/fs.h>
64172+#include <linux/fs_struct.h>
64173+#include <linux/binfmts.h>
64174+#include <linux/gracl.h>
64175+
64176+/* notify of brain-dead configs */
64177+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64178+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
64179+#endif
64180+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
64181+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
64182+#endif
64183+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
64184+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
64185+#endif
64186+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
64187+#error "CONFIG_PAX enabled, but no PaX options are enabled."
64188+#endif
64189+
64190+#include <linux/compat.h>
64191+
64192+struct user_arg_ptr {
64193+#ifdef CONFIG_COMPAT
64194+ bool is_compat;
64195+#endif
64196+ union {
64197+ const char __user *const __user *native;
64198+#ifdef CONFIG_COMPAT
64199+ const compat_uptr_t __user *compat;
64200+#endif
64201+ } ptr;
64202+};
64203+
64204+void gr_handle_brute_attach(unsigned long mm_flags);
64205+void gr_handle_brute_check(void);
64206+void gr_handle_kernel_exploit(void);
64207+int gr_process_user_ban(void);
64208+
64209+char gr_roletype_to_char(void);
64210+
64211+int gr_acl_enable_at_secure(void);
64212+
64213+int gr_check_user_change(int real, int effective, int fs);
64214+int gr_check_group_change(int real, int effective, int fs);
64215+
64216+void gr_del_task_from_ip_table(struct task_struct *p);
64217+
64218+int gr_pid_is_chrooted(struct task_struct *p);
64219+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
64220+int gr_handle_chroot_nice(void);
64221+int gr_handle_chroot_sysctl(const int op);
64222+int gr_handle_chroot_setpriority(struct task_struct *p,
64223+ const int niceval);
64224+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
64225+int gr_handle_chroot_chroot(const struct dentry *dentry,
64226+ const struct vfsmount *mnt);
64227+void gr_handle_chroot_chdir(struct path *path);
64228+int gr_handle_chroot_chmod(const struct dentry *dentry,
64229+ const struct vfsmount *mnt, const int mode);
64230+int gr_handle_chroot_mknod(const struct dentry *dentry,
64231+ const struct vfsmount *mnt, const int mode);
64232+int gr_handle_chroot_mount(const struct dentry *dentry,
64233+ const struct vfsmount *mnt,
64234+ const char *dev_name);
64235+int gr_handle_chroot_pivot(void);
64236+int gr_handle_chroot_unix(const pid_t pid);
64237+
64238+int gr_handle_rawio(const struct inode *inode);
64239+
64240+void gr_handle_ioperm(void);
64241+void gr_handle_iopl(void);
64242+
64243+umode_t gr_acl_umask(void);
64244+
64245+int gr_tpe_allow(const struct file *file);
64246+
64247+void gr_set_chroot_entries(struct task_struct *task, struct path *path);
64248+void gr_clear_chroot_entries(struct task_struct *task);
64249+
64250+void gr_log_forkfail(const int retval);
64251+void gr_log_timechange(void);
64252+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
64253+void gr_log_chdir(const struct dentry *dentry,
64254+ const struct vfsmount *mnt);
64255+void gr_log_chroot_exec(const struct dentry *dentry,
64256+ const struct vfsmount *mnt);
64257+void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
64258+void gr_log_remount(const char *devname, const int retval);
64259+void gr_log_unmount(const char *devname, const int retval);
64260+void gr_log_mount(const char *from, const char *to, const int retval);
64261+void gr_log_textrel(struct vm_area_struct *vma);
64262+void gr_log_rwxmmap(struct file *file);
64263+void gr_log_rwxmprotect(struct file *file);
64264+
64265+int gr_handle_follow_link(const struct inode *parent,
64266+ const struct inode *inode,
64267+ const struct dentry *dentry,
64268+ const struct vfsmount *mnt);
64269+int gr_handle_fifo(const struct dentry *dentry,
64270+ const struct vfsmount *mnt,
64271+ const struct dentry *dir, const int flag,
64272+ const int acc_mode);
64273+int gr_handle_hardlink(const struct dentry *dentry,
64274+ const struct vfsmount *mnt,
64275+ struct inode *inode,
64276+ const int mode, const struct filename *to);
64277+
64278+int gr_is_capable(const int cap);
64279+int gr_is_capable_nolog(const int cap);
64280+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
64281+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
64282+
64283+void gr_learn_resource(const struct task_struct *task, const int limit,
64284+ const unsigned long wanted, const int gt);
64285+void gr_copy_label(struct task_struct *tsk);
64286+void gr_handle_crash(struct task_struct *task, const int sig);
64287+int gr_handle_signal(const struct task_struct *p, const int sig);
64288+int gr_check_crash_uid(const uid_t uid);
64289+int gr_check_protected_task(const struct task_struct *task);
64290+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
64291+int gr_acl_handle_mmap(const struct file *file,
64292+ const unsigned long prot);
64293+int gr_acl_handle_mprotect(const struct file *file,
64294+ const unsigned long prot);
64295+int gr_check_hidden_task(const struct task_struct *tsk);
64296+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
64297+ const struct vfsmount *mnt);
64298+__u32 gr_acl_handle_utime(const struct dentry *dentry,
64299+ const struct vfsmount *mnt);
64300+__u32 gr_acl_handle_access(const struct dentry *dentry,
64301+ const struct vfsmount *mnt, const int fmode);
64302+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
64303+ const struct vfsmount *mnt, umode_t *mode);
64304+__u32 gr_acl_handle_chown(const struct dentry *dentry,
64305+ const struct vfsmount *mnt);
64306+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
64307+ const struct vfsmount *mnt);
64308+int gr_handle_ptrace(struct task_struct *task, const long request);
64309+int gr_handle_proc_ptrace(struct task_struct *task);
64310+__u32 gr_acl_handle_execve(const struct dentry *dentry,
64311+ const struct vfsmount *mnt);
64312+int gr_check_crash_exec(const struct file *filp);
64313+int gr_acl_is_enabled(void);
64314+void gr_set_kernel_label(struct task_struct *task);
64315+void gr_set_role_label(struct task_struct *task, const uid_t uid,
64316+ const gid_t gid);
64317+int gr_set_proc_label(const struct dentry *dentry,
64318+ const struct vfsmount *mnt,
64319+ const int unsafe_flags);
64320+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
64321+ const struct vfsmount *mnt);
64322+__u32 gr_acl_handle_open(const struct dentry *dentry,
64323+ const struct vfsmount *mnt, int acc_mode);
64324+__u32 gr_acl_handle_creat(const struct dentry *dentry,
64325+ const struct dentry *p_dentry,
64326+ const struct vfsmount *p_mnt,
64327+ int open_flags, int acc_mode, const int imode);
64328+void gr_handle_create(const struct dentry *dentry,
64329+ const struct vfsmount *mnt);
64330+void gr_handle_proc_create(const struct dentry *dentry,
64331+ const struct inode *inode);
64332+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
64333+ const struct dentry *parent_dentry,
64334+ const struct vfsmount *parent_mnt,
64335+ const int mode);
64336+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
64337+ const struct dentry *parent_dentry,
64338+ const struct vfsmount *parent_mnt);
64339+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
64340+ const struct vfsmount *mnt);
64341+void gr_handle_delete(const ino_t ino, const dev_t dev);
64342+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
64343+ const struct vfsmount *mnt);
64344+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
64345+ const struct dentry *parent_dentry,
64346+ const struct vfsmount *parent_mnt,
64347+ const struct filename *from);
64348+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
64349+ const struct dentry *parent_dentry,
64350+ const struct vfsmount *parent_mnt,
64351+ const struct dentry *old_dentry,
64352+ const struct vfsmount *old_mnt, const struct filename *to);
64353+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
64354+int gr_acl_handle_rename(struct dentry *new_dentry,
64355+ struct dentry *parent_dentry,
64356+ const struct vfsmount *parent_mnt,
64357+ struct dentry *old_dentry,
64358+ struct inode *old_parent_inode,
64359+ struct vfsmount *old_mnt, const struct filename *newname);
64360+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
64361+ struct dentry *old_dentry,
64362+ struct dentry *new_dentry,
64363+ struct vfsmount *mnt, const __u8 replace);
64364+__u32 gr_check_link(const struct dentry *new_dentry,
64365+ const struct dentry *parent_dentry,
64366+ const struct vfsmount *parent_mnt,
64367+ const struct dentry *old_dentry,
64368+ const struct vfsmount *old_mnt);
64369+int gr_acl_handle_filldir(const struct file *file, const char *name,
64370+ const unsigned int namelen, const ino_t ino);
64371+
64372+__u32 gr_acl_handle_unix(const struct dentry *dentry,
64373+ const struct vfsmount *mnt);
64374+void gr_acl_handle_exit(void);
64375+void gr_acl_handle_psacct(struct task_struct *task, const long code);
64376+int gr_acl_handle_procpidmem(const struct task_struct *task);
64377+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
64378+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
64379+void gr_audit_ptrace(struct task_struct *task);
64380+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
64381+void gr_put_exec_file(struct task_struct *task);
64382+
64383+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
64384+
64385+#ifdef CONFIG_GRKERNSEC
64386+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
64387+void gr_handle_vm86(void);
64388+void gr_handle_mem_readwrite(u64 from, u64 to);
64389+
64390+void gr_log_badprocpid(const char *entry);
64391+
64392+extern int grsec_enable_dmesg;
64393+extern int grsec_disable_privio;
64394+
64395+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
64396+extern int grsec_proc_gid;
64397+#endif
64398+
64399+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
64400+extern int grsec_enable_chroot_findtask;
64401+#endif
64402+#ifdef CONFIG_GRKERNSEC_SETXID
64403+extern int grsec_enable_setxid;
64404+#endif
64405+#endif
64406+
64407+#endif
64408diff --git a/include/linux/grsock.h b/include/linux/grsock.h
64409new file mode 100644
64410index 0000000..e7ffaaf
64411--- /dev/null
64412+++ b/include/linux/grsock.h
64413@@ -0,0 +1,19 @@
64414+#ifndef __GRSOCK_H
64415+#define __GRSOCK_H
64416+
64417+extern void gr_attach_curr_ip(const struct sock *sk);
64418+extern int gr_handle_sock_all(const int family, const int type,
64419+ const int protocol);
64420+extern int gr_handle_sock_server(const struct sockaddr *sck);
64421+extern int gr_handle_sock_server_other(const struct sock *sck);
64422+extern int gr_handle_sock_client(const struct sockaddr *sck);
64423+extern int gr_search_connect(struct socket * sock,
64424+ struct sockaddr_in * addr);
64425+extern int gr_search_bind(struct socket * sock,
64426+ struct sockaddr_in * addr);
64427+extern int gr_search_listen(struct socket * sock);
64428+extern int gr_search_accept(struct socket * sock);
64429+extern int gr_search_socket(const int domain, const int type,
64430+ const int protocol);
64431+
64432+#endif
64433diff --git a/include/linux/hid.h b/include/linux/hid.h
64434index c076041..6f54d73 100644
64435--- a/include/linux/hid.h
64436+++ b/include/linux/hid.h
64437@@ -671,7 +671,7 @@ struct hid_ll_driver {
64438 unsigned int code, int value);
64439
64440 int (*parse)(struct hid_device *hdev);
64441-};
64442+} __no_const;
64443
64444 #define PM_HINT_FULLON 1<<5
64445 #define PM_HINT_NORMAL 1<<1
64446diff --git a/include/linux/highmem.h b/include/linux/highmem.h
64447index ef788b5..ac41b7b 100644
64448--- a/include/linux/highmem.h
64449+++ b/include/linux/highmem.h
64450@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
64451 kunmap_atomic(kaddr);
64452 }
64453
64454+static inline void sanitize_highpage(struct page *page)
64455+{
64456+ void *kaddr;
64457+ unsigned long flags;
64458+
64459+ local_irq_save(flags);
64460+ kaddr = kmap_atomic(page);
64461+ clear_page(kaddr);
64462+ kunmap_atomic(kaddr);
64463+ local_irq_restore(flags);
64464+}
64465+
64466 static inline void zero_user_segments(struct page *page,
64467 unsigned start1, unsigned end1,
64468 unsigned start2, unsigned end2)
64469diff --git a/include/linux/hsi/hsi.h b/include/linux/hsi/hsi.h
64470index 56fae86..5565cde 100644
64471--- a/include/linux/hsi/hsi.h
64472+++ b/include/linux/hsi/hsi.h
64473@@ -132,7 +132,7 @@ struct hsi_client {
64474 /* private: */
64475 void (*ehandler)(struct hsi_client *, unsigned long);
64476 unsigned int pclaimed:1;
64477- struct notifier_block nb;
64478+ notifier_block_no_const nb;
64479 };
64480
64481 #define to_hsi_client(dev) container_of(dev, struct hsi_client, device)
64482diff --git a/include/linux/i2c.h b/include/linux/i2c.h
64483index 800de22..7a2fa46 100644
64484--- a/include/linux/i2c.h
64485+++ b/include/linux/i2c.h
64486@@ -367,6 +367,7 @@ struct i2c_algorithm {
64487 /* To determine what the adapter supports */
64488 u32 (*functionality) (struct i2c_adapter *);
64489 };
64490+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
64491
64492 /*
64493 * i2c_adapter is the structure used to identify a physical i2c bus along
64494diff --git a/include/linux/i2o.h b/include/linux/i2o.h
64495index d23c3c2..eb63c81 100644
64496--- a/include/linux/i2o.h
64497+++ b/include/linux/i2o.h
64498@@ -565,7 +565,7 @@ struct i2o_controller {
64499 struct i2o_device *exec; /* Executive */
64500 #if BITS_PER_LONG == 64
64501 spinlock_t context_list_lock; /* lock for context_list */
64502- atomic_t context_list_counter; /* needed for unique contexts */
64503+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
64504 struct list_head context_list; /* list of context id's
64505 and pointers */
64506 #endif
64507diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
64508index aff7ad8..3942bbd 100644
64509--- a/include/linux/if_pppox.h
64510+++ b/include/linux/if_pppox.h
64511@@ -76,7 +76,7 @@ struct pppox_proto {
64512 int (*ioctl)(struct socket *sock, unsigned int cmd,
64513 unsigned long arg);
64514 struct module *owner;
64515-};
64516+} __do_const;
64517
64518 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
64519 extern void unregister_pppox_proto(int proto_num);
64520diff --git a/include/linux/if_team.h b/include/linux/if_team.h
64521index 0245def..1199c5a 100644
64522--- a/include/linux/if_team.h
64523+++ b/include/linux/if_team.h
64524@@ -111,6 +111,7 @@ struct team_mode_ops {
64525 void (*port_enabled)(struct team *team, struct team_port *port);
64526 void (*port_disabled)(struct team *team, struct team_port *port);
64527 };
64528+typedef struct team_mode_ops __no_const team_mode_ops_no_const;
64529
64530 enum team_option_type {
64531 TEAM_OPTION_TYPE_U32,
64532@@ -185,7 +186,7 @@ struct team {
64533 struct list_head option_inst_list; /* list of option instances */
64534
64535 const struct team_mode *mode;
64536- struct team_mode_ops ops;
64537+ team_mode_ops_no_const ops;
64538 bool queue_override_enabled;
64539 struct list_head *qom_lists; /* array of queue override mapping lists */
64540 long mode_priv[TEAM_MODE_PRIV_LONGS];
64541diff --git a/include/linux/init.h b/include/linux/init.h
64542index e59041e..df0a975 100644
64543--- a/include/linux/init.h
64544+++ b/include/linux/init.h
64545@@ -39,9 +39,36 @@
64546 * Also note, that this data cannot be "const".
64547 */
64548
64549+#ifdef MODULE
64550+#define add_init_latent_entropy
64551+#define add_devinit_latent_entropy
64552+#define add_cpuinit_latent_entropy
64553+#define add_meminit_latent_entropy
64554+#else
64555+#define add_init_latent_entropy __latent_entropy
64556+
64557+#ifdef CONFIG_HOTPLUG
64558+#define add_devinit_latent_entropy
64559+#else
64560+#define add_devinit_latent_entropy __latent_entropy
64561+#endif
64562+
64563+#ifdef CONFIG_HOTPLUG_CPU
64564+#define add_cpuinit_latent_entropy
64565+#else
64566+#define add_cpuinit_latent_entropy __latent_entropy
64567+#endif
64568+
64569+#ifdef CONFIG_MEMORY_HOTPLUG
64570+#define add_meminit_latent_entropy
64571+#else
64572+#define add_meminit_latent_entropy __latent_entropy
64573+#endif
64574+#endif
64575+
64576 /* These are for everybody (although not all archs will actually
64577 discard it in modules) */
64578-#define __init __section(.init.text) __cold notrace
64579+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
64580 #define __initdata __section(.init.data)
64581 #define __initconst __constsection(.init.rodata)
64582 #define __exitdata __section(.exit.data)
64583@@ -94,7 +121,7 @@
64584 #define __exit __section(.exit.text) __exitused __cold notrace
64585
64586 /* Used for HOTPLUG */
64587-#define __devinit __section(.devinit.text) __cold notrace
64588+#define __devinit __section(.devinit.text) __cold notrace add_devinit_latent_entropy
64589 #define __devinitdata __section(.devinit.data)
64590 #define __devinitconst __constsection(.devinit.rodata)
64591 #define __devexit __section(.devexit.text) __exitused __cold notrace
64592@@ -102,7 +129,7 @@
64593 #define __devexitconst __constsection(.devexit.rodata)
64594
64595 /* Used for HOTPLUG_CPU */
64596-#define __cpuinit __section(.cpuinit.text) __cold notrace
64597+#define __cpuinit __section(.cpuinit.text) __cold notrace add_cpuinit_latent_entropy
64598 #define __cpuinitdata __section(.cpuinit.data)
64599 #define __cpuinitconst __constsection(.cpuinit.rodata)
64600 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
64601@@ -110,7 +137,7 @@
64602 #define __cpuexitconst __constsection(.cpuexit.rodata)
64603
64604 /* Used for MEMORY_HOTPLUG */
64605-#define __meminit __section(.meminit.text) __cold notrace
64606+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
64607 #define __meminitdata __section(.meminit.data)
64608 #define __meminitconst __constsection(.meminit.rodata)
64609 #define __memexit __section(.memexit.text) __exitused __cold notrace
64610diff --git a/include/linux/init_task.h b/include/linux/init_task.h
64611index 6d087c5..401cab8 100644
64612--- a/include/linux/init_task.h
64613+++ b/include/linux/init_task.h
64614@@ -143,6 +143,12 @@ extern struct task_group root_task_group;
64615
64616 #define INIT_TASK_COMM "swapper"
64617
64618+#ifdef CONFIG_X86
64619+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
64620+#else
64621+#define INIT_TASK_THREAD_INFO
64622+#endif
64623+
64624 /*
64625 * INIT_TASK is used to set up the first task table, touch at
64626 * your own risk!. Base=0, limit=0x1fffff (=2MB)
64627@@ -182,6 +188,7 @@ extern struct task_group root_task_group;
64628 RCU_POINTER_INITIALIZER(cred, &init_cred), \
64629 .comm = INIT_TASK_COMM, \
64630 .thread = INIT_THREAD, \
64631+ INIT_TASK_THREAD_INFO \
64632 .fs = &init_fs, \
64633 .files = &init_files, \
64634 .signal = &init_signals, \
64635diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
64636index 78e2ada..745564d 100644
64637--- a/include/linux/intel-iommu.h
64638+++ b/include/linux/intel-iommu.h
64639@@ -296,7 +296,7 @@ struct iommu_flush {
64640 u8 fm, u64 type);
64641 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
64642 unsigned int size_order, u64 type);
64643-};
64644+} __no_const;
64645
64646 enum {
64647 SR_DMAR_FECTL_REG,
64648diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
64649index 5e4e617..eee383d 100644
64650--- a/include/linux/interrupt.h
64651+++ b/include/linux/interrupt.h
64652@@ -435,7 +435,7 @@ enum
64653 /* map softirq index to softirq name. update 'softirq_to_name' in
64654 * kernel/softirq.c when adding a new softirq.
64655 */
64656-extern char *softirq_to_name[NR_SOFTIRQS];
64657+extern const char * const softirq_to_name[NR_SOFTIRQS];
64658
64659 /* softirq mask and active fields moved to irq_cpustat_t in
64660 * asm/hardirq.h to get better cache usage. KAO
64661@@ -443,12 +443,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
64662
64663 struct softirq_action
64664 {
64665- void (*action)(struct softirq_action *);
64666+ void (*action)(void);
64667 };
64668
64669 asmlinkage void do_softirq(void);
64670 asmlinkage void __do_softirq(void);
64671-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
64672+extern void open_softirq(int nr, void (*action)(void));
64673 extern void softirq_init(void);
64674 extern void __raise_softirq_irqoff(unsigned int nr);
64675
64676diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
64677index 5499c92..e6770b3 100644
64678--- a/include/linux/ipc_namespace.h
64679+++ b/include/linux/ipc_namespace.h
64680@@ -50,7 +50,7 @@ struct ipc_namespace {
64681 */
64682 int shm_rmid_forced;
64683
64684- struct notifier_block ipcns_nb;
64685+ notifier_block_no_const ipcns_nb;
64686
64687 /* The kern_mount of the mqueuefs sb. We take a ref on it */
64688 struct vfsmount *mq_mnt;
64689diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
64690index 6883e19..06992b1 100644
64691--- a/include/linux/kallsyms.h
64692+++ b/include/linux/kallsyms.h
64693@@ -15,7 +15,8 @@
64694
64695 struct module;
64696
64697-#ifdef CONFIG_KALLSYMS
64698+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
64699+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
64700 /* Lookup the address for a symbol. Returns 0 if not found. */
64701 unsigned long kallsyms_lookup_name(const char *name);
64702
64703@@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
64704 /* Stupid that this does nothing, but I didn't create this mess. */
64705 #define __print_symbol(fmt, addr)
64706 #endif /*CONFIG_KALLSYMS*/
64707+#else /* when included by kallsyms.c, vsnprintf.c, or
64708+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
64709+extern void __print_symbol(const char *fmt, unsigned long address);
64710+extern int sprint_backtrace(char *buffer, unsigned long address);
64711+extern int sprint_symbol(char *buffer, unsigned long address);
64712+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
64713+const char *kallsyms_lookup(unsigned long addr,
64714+ unsigned long *symbolsize,
64715+ unsigned long *offset,
64716+ char **modname, char *namebuf);
64717+#endif
64718
64719 /* This macro allows us to keep printk typechecking */
64720 static __printf(1, 2)
64721diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
64722index 4dff0c6..1ca9b72 100644
64723--- a/include/linux/kgdb.h
64724+++ b/include/linux/kgdb.h
64725@@ -53,7 +53,7 @@ extern int kgdb_connected;
64726 extern int kgdb_io_module_registered;
64727
64728 extern atomic_t kgdb_setting_breakpoint;
64729-extern atomic_t kgdb_cpu_doing_single_step;
64730+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
64731
64732 extern struct task_struct *kgdb_usethread;
64733 extern struct task_struct *kgdb_contthread;
64734@@ -255,7 +255,7 @@ struct kgdb_arch {
64735 void (*correct_hw_break)(void);
64736
64737 void (*enable_nmi)(bool on);
64738-};
64739+} __do_const;
64740
64741 /**
64742 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
64743@@ -280,7 +280,7 @@ struct kgdb_io {
64744 void (*pre_exception) (void);
64745 void (*post_exception) (void);
64746 int is_console;
64747-};
64748+} __do_const;
64749
64750 extern struct kgdb_arch arch_kgdb_ops;
64751
64752diff --git a/include/linux/kmod.h b/include/linux/kmod.h
64753index 5398d58..5883a34 100644
64754--- a/include/linux/kmod.h
64755+++ b/include/linux/kmod.h
64756@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
64757 * usually useless though. */
64758 extern __printf(2, 3)
64759 int __request_module(bool wait, const char *name, ...);
64760+extern __printf(3, 4)
64761+int ___request_module(bool wait, char *param_name, const char *name, ...);
64762 #define request_module(mod...) __request_module(true, mod)
64763 #define request_module_nowait(mod...) __request_module(false, mod)
64764 #define try_then_request_module(x, mod...) \
64765diff --git a/include/linux/kobject.h b/include/linux/kobject.h
64766index 1e57449..4fede7b 100644
64767--- a/include/linux/kobject.h
64768+++ b/include/linux/kobject.h
64769@@ -111,7 +111,7 @@ struct kobj_type {
64770 struct attribute **default_attrs;
64771 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
64772 const void *(*namespace)(struct kobject *kobj);
64773-};
64774+} __do_const;
64775
64776 struct kobj_uevent_env {
64777 char *envp[UEVENT_NUM_ENVP];
64778diff --git a/include/linux/kref.h b/include/linux/kref.h
64779index 65af688..0592677 100644
64780--- a/include/linux/kref.h
64781+++ b/include/linux/kref.h
64782@@ -64,7 +64,7 @@ static inline void kref_get(struct kref *kref)
64783 static inline int kref_sub(struct kref *kref, unsigned int count,
64784 void (*release)(struct kref *kref))
64785 {
64786- WARN_ON(release == NULL);
64787+ BUG_ON(release == NULL);
64788
64789 if (atomic_sub_and_test((int) count, &kref->refcount)) {
64790 release(kref);
64791diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
64792index ecc5543..0e96bcc 100644
64793--- a/include/linux/kvm_host.h
64794+++ b/include/linux/kvm_host.h
64795@@ -403,7 +403,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
64796 int __must_check vcpu_load(struct kvm_vcpu *vcpu);
64797 void vcpu_put(struct kvm_vcpu *vcpu);
64798
64799-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
64800+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
64801 struct module *module);
64802 void kvm_exit(void);
64803
64804@@ -558,7 +558,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
64805 struct kvm_guest_debug *dbg);
64806 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
64807
64808-int kvm_arch_init(void *opaque);
64809+int kvm_arch_init(const void *opaque);
64810 void kvm_arch_exit(void);
64811
64812 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
64813diff --git a/include/linux/lcd.h b/include/linux/lcd.h
64814index e00c3b0..2ab1e49 100644
64815--- a/include/linux/lcd.h
64816+++ b/include/linux/lcd.h
64817@@ -74,7 +74,7 @@ struct lcd_device {
64818 /* Serialise access to set_power method */
64819 struct mutex update_lock;
64820 /* The framebuffer notifier block */
64821- struct notifier_block fb_notif;
64822+ notifier_block_no_const fb_notif;
64823
64824 struct device dev;
64825 };
64826diff --git a/include/linux/libata.h b/include/linux/libata.h
64827index 77eeeda..062ed69c 100644
64828--- a/include/linux/libata.h
64829+++ b/include/linux/libata.h
64830@@ -914,7 +914,7 @@ struct ata_port_operations {
64831 * fields must be pointers.
64832 */
64833 const struct ata_port_operations *inherits;
64834-};
64835+} __do_const;
64836
64837 struct ata_port_info {
64838 unsigned long flags;
64839diff --git a/include/linux/list.h b/include/linux/list.h
64840index cc6d2aa..71febca 100644
64841--- a/include/linux/list.h
64842+++ b/include/linux/list.h
64843@@ -112,6 +112,9 @@ extern void __list_del_entry(struct list_head *entry);
64844 extern void list_del(struct list_head *entry);
64845 #endif
64846
64847+extern void pax_list_add_tail(struct list_head *new, struct list_head *head);
64848+extern void pax_list_del(struct list_head *entry);
64849+
64850 /**
64851 * list_replace - replace old entry by new one
64852 * @old : the element to be replaced
64853diff --git a/include/linux/memory.h b/include/linux/memory.h
64854index ff9a9f8..c715deb 100644
64855--- a/include/linux/memory.h
64856+++ b/include/linux/memory.h
64857@@ -143,7 +143,7 @@ struct memory_accessor {
64858 size_t count);
64859 ssize_t (*write)(struct memory_accessor *, const char *buf,
64860 off_t offset, size_t count);
64861-};
64862+} __no_const;
64863
64864 /*
64865 * Kernel text modification mutex, used for code patching. Users of this lock
64866diff --git a/include/linux/mfd/abx500.h b/include/linux/mfd/abx500.h
64867index 5d5298d..e3e5a2e 100644
64868--- a/include/linux/mfd/abx500.h
64869+++ b/include/linux/mfd/abx500.h
64870@@ -337,6 +337,7 @@ struct abx500_ops {
64871 int (*event_registers_startup_state_get) (struct device *, u8 *);
64872 int (*startup_irq_enabled) (struct device *, unsigned int);
64873 };
64874+typedef struct abx500_ops __no_const abx500_ops_no_const;
64875
64876 int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
64877 void abx500_remove_ops(struct device *dev);
64878diff --git a/include/linux/mfd/abx500/ux500_chargalg.h b/include/linux/mfd/abx500/ux500_chargalg.h
64879index 9b07725..3d55001 100644
64880--- a/include/linux/mfd/abx500/ux500_chargalg.h
64881+++ b/include/linux/mfd/abx500/ux500_chargalg.h
64882@@ -19,7 +19,7 @@ struct ux500_charger_ops {
64883 int (*enable) (struct ux500_charger *, int, int, int);
64884 int (*kick_wd) (struct ux500_charger *);
64885 int (*update_curr) (struct ux500_charger *, int);
64886-};
64887+} __no_const;
64888
64889 /**
64890 * struct ux500_charger - power supply ux500 charger sub class
64891diff --git a/include/linux/mm.h b/include/linux/mm.h
64892index bcaab4e..f842186 100644
64893--- a/include/linux/mm.h
64894+++ b/include/linux/mm.h
64895@@ -101,6 +101,11 @@ extern unsigned int kobjsize(const void *objp);
64896 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
64897 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
64898 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
64899+
64900+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
64901+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
64902+#endif
64903+
64904 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
64905
64906 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
64907@@ -1040,34 +1045,6 @@ int set_page_dirty(struct page *page);
64908 int set_page_dirty_lock(struct page *page);
64909 int clear_page_dirty_for_io(struct page *page);
64910
64911-/* Is the vma a continuation of the stack vma above it? */
64912-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
64913-{
64914- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
64915-}
64916-
64917-static inline int stack_guard_page_start(struct vm_area_struct *vma,
64918- unsigned long addr)
64919-{
64920- return (vma->vm_flags & VM_GROWSDOWN) &&
64921- (vma->vm_start == addr) &&
64922- !vma_growsdown(vma->vm_prev, addr);
64923-}
64924-
64925-/* Is the vma a continuation of the stack vma below it? */
64926-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
64927-{
64928- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
64929-}
64930-
64931-static inline int stack_guard_page_end(struct vm_area_struct *vma,
64932- unsigned long addr)
64933-{
64934- return (vma->vm_flags & VM_GROWSUP) &&
64935- (vma->vm_end == addr) &&
64936- !vma_growsup(vma->vm_next, addr);
64937-}
64938-
64939 extern pid_t
64940 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
64941
64942@@ -1167,6 +1144,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
64943 }
64944 #endif
64945
64946+#ifdef CONFIG_MMU
64947+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
64948+#else
64949+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
64950+{
64951+ return __pgprot(0);
64952+}
64953+#endif
64954+
64955 int vma_wants_writenotify(struct vm_area_struct *vma);
64956
64957 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
64958@@ -1185,8 +1171,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
64959 {
64960 return 0;
64961 }
64962+
64963+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
64964+ unsigned long address)
64965+{
64966+ return 0;
64967+}
64968 #else
64969 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
64970+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
64971 #endif
64972
64973 #ifdef __PAGETABLE_PMD_FOLDED
64974@@ -1195,8 +1188,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
64975 {
64976 return 0;
64977 }
64978+
64979+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
64980+ unsigned long address)
64981+{
64982+ return 0;
64983+}
64984 #else
64985 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
64986+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
64987 #endif
64988
64989 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
64990@@ -1214,11 +1214,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
64991 NULL: pud_offset(pgd, address);
64992 }
64993
64994+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
64995+{
64996+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
64997+ NULL: pud_offset(pgd, address);
64998+}
64999+
65000 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
65001 {
65002 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
65003 NULL: pmd_offset(pud, address);
65004 }
65005+
65006+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
65007+{
65008+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
65009+ NULL: pmd_offset(pud, address);
65010+}
65011 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
65012
65013 #if USE_SPLIT_PTLOCKS
65014@@ -1448,6 +1460,7 @@ extern unsigned long do_mmap_pgoff(struct file *, unsigned long,
65015 unsigned long, unsigned long,
65016 unsigned long, unsigned long);
65017 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
65018+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
65019
65020 /* These take the mm semaphore themselves */
65021 extern unsigned long vm_brk(unsigned long, unsigned long);
65022@@ -1511,6 +1524,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
65023 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
65024 struct vm_area_struct **pprev);
65025
65026+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
65027+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
65028+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
65029+
65030 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
65031 NULL if none. Assume start_addr < end_addr. */
65032 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
65033@@ -1539,15 +1556,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
65034 return vma;
65035 }
65036
65037-#ifdef CONFIG_MMU
65038-pgprot_t vm_get_page_prot(unsigned long vm_flags);
65039-#else
65040-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
65041-{
65042- return __pgprot(0);
65043-}
65044-#endif
65045-
65046 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
65047 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
65048 unsigned long pfn, unsigned long size, pgprot_t);
65049@@ -1653,7 +1661,7 @@ extern int unpoison_memory(unsigned long pfn);
65050 extern int sysctl_memory_failure_early_kill;
65051 extern int sysctl_memory_failure_recovery;
65052 extern void shake_page(struct page *p, int access);
65053-extern atomic_long_t mce_bad_pages;
65054+extern atomic_long_unchecked_t mce_bad_pages;
65055 extern int soft_offline_page(struct page *page, int flags);
65056
65057 extern void dump_page(struct page *page);
65058@@ -1684,5 +1692,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
65059 static inline bool page_is_guard(struct page *page) { return false; }
65060 #endif /* CONFIG_DEBUG_PAGEALLOC */
65061
65062+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
65063+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
65064+#else
65065+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
65066+#endif
65067+
65068 #endif /* __KERNEL__ */
65069 #endif /* _LINUX_MM_H */
65070diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
65071index 31f8a3a..499f1db 100644
65072--- a/include/linux/mm_types.h
65073+++ b/include/linux/mm_types.h
65074@@ -275,6 +275,8 @@ struct vm_area_struct {
65075 #ifdef CONFIG_NUMA
65076 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
65077 #endif
65078+
65079+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
65080 };
65081
65082 struct core_thread {
65083@@ -348,7 +350,7 @@ struct mm_struct {
65084 unsigned long def_flags;
65085 unsigned long nr_ptes; /* Page table pages */
65086 unsigned long start_code, end_code, start_data, end_data;
65087- unsigned long start_brk, brk, start_stack;
65088+ unsigned long brk_gap, start_brk, brk, start_stack;
65089 unsigned long arg_start, arg_end, env_start, env_end;
65090
65091 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
65092@@ -399,6 +401,24 @@ struct mm_struct {
65093 struct cpumask cpumask_allocation;
65094 #endif
65095 struct uprobes_state uprobes_state;
65096+
65097+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
65098+ unsigned long pax_flags;
65099+#endif
65100+
65101+#ifdef CONFIG_PAX_DLRESOLVE
65102+ unsigned long call_dl_resolve;
65103+#endif
65104+
65105+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
65106+ unsigned long call_syscall;
65107+#endif
65108+
65109+#ifdef CONFIG_PAX_ASLR
65110+ unsigned long delta_mmap; /* randomized offset */
65111+ unsigned long delta_stack; /* randomized offset */
65112+#endif
65113+
65114 };
65115
65116 static inline void mm_init_cpumask(struct mm_struct *mm)
65117diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h
65118index 7abb0e1..cf526e3 100644
65119--- a/include/linux/mmc/host.h
65120+++ b/include/linux/mmc/host.h
65121@@ -188,7 +188,7 @@ struct mmc_host {
65122 u32 ocr_avail_sdio; /* SDIO-specific OCR */
65123 u32 ocr_avail_sd; /* SD-specific OCR */
65124 u32 ocr_avail_mmc; /* MMC-specific OCR */
65125- struct notifier_block pm_notify;
65126+ notifier_block_no_const pm_notify;
65127 u32 max_current_330;
65128 u32 max_current_300;
65129 u32 max_current_180;
65130diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
65131index c5d5278..f0b68c8 100644
65132--- a/include/linux/mmiotrace.h
65133+++ b/include/linux/mmiotrace.h
65134@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
65135 /* Called from ioremap.c */
65136 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
65137 void __iomem *addr);
65138-extern void mmiotrace_iounmap(volatile void __iomem *addr);
65139+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
65140
65141 /* For anyone to insert markers. Remember trailing newline. */
65142 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
65143@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
65144 {
65145 }
65146
65147-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
65148+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
65149 {
65150 }
65151
65152diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
65153index a23923b..073fee4 100644
65154--- a/include/linux/mmzone.h
65155+++ b/include/linux/mmzone.h
65156@@ -421,7 +421,7 @@ struct zone {
65157 unsigned long flags; /* zone flags, see below */
65158
65159 /* Zone statistics */
65160- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
65161+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
65162
65163 /*
65164 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
65165diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
65166index fed3def..7cc3f93 100644
65167--- a/include/linux/mod_devicetable.h
65168+++ b/include/linux/mod_devicetable.h
65169@@ -12,7 +12,7 @@
65170 typedef unsigned long kernel_ulong_t;
65171 #endif
65172
65173-#define PCI_ANY_ID (~0)
65174+#define PCI_ANY_ID ((__u16)~0)
65175
65176 struct pci_device_id {
65177 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
65178@@ -139,7 +139,7 @@ struct usb_device_id {
65179 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
65180 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
65181
65182-#define HID_ANY_ID (~0)
65183+#define HID_ANY_ID (~0U)
65184 #define HID_BUS_ANY 0xffff
65185 #define HID_GROUP_ANY 0x0000
65186
65187diff --git a/include/linux/module.h b/include/linux/module.h
65188index 7760c6d..983ee18 100644
65189--- a/include/linux/module.h
65190+++ b/include/linux/module.h
65191@@ -17,9 +17,11 @@
65192 #include <linux/moduleparam.h>
65193 #include <linux/tracepoint.h>
65194 #include <linux/export.h>
65195+#include <linux/fs.h>
65196
65197 #include <linux/percpu.h>
65198 #include <asm/module.h>
65199+#include <asm/pgtable.h>
65200
65201 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
65202 #define MODULE_SIG_STRING "~Module signature appended~\n"
65203@@ -281,19 +283,16 @@ struct module
65204 int (*init)(void);
65205
65206 /* If this is non-NULL, vfree after init() returns */
65207- void *module_init;
65208+ void *module_init_rx, *module_init_rw;
65209
65210 /* Here is the actual code + data, vfree'd on unload. */
65211- void *module_core;
65212+ void *module_core_rx, *module_core_rw;
65213
65214 /* Here are the sizes of the init and core sections */
65215- unsigned int init_size, core_size;
65216+ unsigned int init_size_rw, core_size_rw;
65217
65218 /* The size of the executable code in each section. */
65219- unsigned int init_text_size, core_text_size;
65220-
65221- /* Size of RO sections of the module (text+rodata) */
65222- unsigned int init_ro_size, core_ro_size;
65223+ unsigned int init_size_rx, core_size_rx;
65224
65225 /* Arch-specific module values */
65226 struct mod_arch_specific arch;
65227@@ -349,6 +348,10 @@ struct module
65228 #ifdef CONFIG_EVENT_TRACING
65229 struct ftrace_event_call **trace_events;
65230 unsigned int num_trace_events;
65231+ struct file_operations trace_id;
65232+ struct file_operations trace_enable;
65233+ struct file_operations trace_format;
65234+ struct file_operations trace_filter;
65235 #endif
65236 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
65237 unsigned int num_ftrace_callsites;
65238@@ -396,16 +399,46 @@ bool is_module_address(unsigned long addr);
65239 bool is_module_percpu_address(unsigned long addr);
65240 bool is_module_text_address(unsigned long addr);
65241
65242+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
65243+{
65244+
65245+#ifdef CONFIG_PAX_KERNEXEC
65246+ if (ktla_ktva(addr) >= (unsigned long)start &&
65247+ ktla_ktva(addr) < (unsigned long)start + size)
65248+ return 1;
65249+#endif
65250+
65251+ return ((void *)addr >= start && (void *)addr < start + size);
65252+}
65253+
65254+static inline int within_module_core_rx(unsigned long addr, struct module *mod)
65255+{
65256+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
65257+}
65258+
65259+static inline int within_module_core_rw(unsigned long addr, struct module *mod)
65260+{
65261+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
65262+}
65263+
65264+static inline int within_module_init_rx(unsigned long addr, struct module *mod)
65265+{
65266+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
65267+}
65268+
65269+static inline int within_module_init_rw(unsigned long addr, struct module *mod)
65270+{
65271+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
65272+}
65273+
65274 static inline int within_module_core(unsigned long addr, struct module *mod)
65275 {
65276- return (unsigned long)mod->module_core <= addr &&
65277- addr < (unsigned long)mod->module_core + mod->core_size;
65278+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
65279 }
65280
65281 static inline int within_module_init(unsigned long addr, struct module *mod)
65282 {
65283- return (unsigned long)mod->module_init <= addr &&
65284- addr < (unsigned long)mod->module_init + mod->init_size;
65285+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
65286 }
65287
65288 /* Search for module by name: must hold module_mutex. */
65289diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
65290index 560ca53..5ee8d73 100644
65291--- a/include/linux/moduleloader.h
65292+++ b/include/linux/moduleloader.h
65293@@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
65294
65295 /* Allocator used for allocating struct module, core sections and init
65296 sections. Returns NULL on failure. */
65297-void *module_alloc(unsigned long size);
65298+void *module_alloc(unsigned long size) __size_overflow(1);
65299+
65300+#ifdef CONFIG_PAX_KERNEXEC
65301+void *module_alloc_exec(unsigned long size) __size_overflow(1);
65302+#else
65303+#define module_alloc_exec(x) module_alloc(x)
65304+#endif
65305
65306 /* Free memory returned from module_alloc. */
65307 void module_free(struct module *mod, void *module_region);
65308
65309+#ifdef CONFIG_PAX_KERNEXEC
65310+void module_free_exec(struct module *mod, void *module_region);
65311+#else
65312+#define module_free_exec(x, y) module_free((x), (y))
65313+#endif
65314+
65315 /*
65316 * Apply the given relocation to the (simplified) ELF. Return -error
65317 * or 0.
65318@@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
65319 unsigned int relsec,
65320 struct module *me)
65321 {
65322+#ifdef CONFIG_MODULES
65323 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
65324+#endif
65325 return -ENOEXEC;
65326 }
65327 #endif
65328@@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
65329 unsigned int relsec,
65330 struct module *me)
65331 {
65332+#ifdef CONFIG_MODULES
65333 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
65334+#endif
65335 return -ENOEXEC;
65336 }
65337 #endif
65338diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
65339index d6a5806..7c13347 100644
65340--- a/include/linux/moduleparam.h
65341+++ b/include/linux/moduleparam.h
65342@@ -286,7 +286,7 @@ static inline void __kernel_param_unlock(void)
65343 * @len is usually just sizeof(string).
65344 */
65345 #define module_param_string(name, string, len, perm) \
65346- static const struct kparam_string __param_string_##name \
65347+ static const struct kparam_string __param_string_##name __used \
65348 = { len, string }; \
65349 __module_param_call(MODULE_PARAM_PREFIX, name, \
65350 &param_ops_string, \
65351@@ -425,7 +425,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
65352 */
65353 #define module_param_array_named(name, array, type, nump, perm) \
65354 param_check_##type(name, &(array)[0]); \
65355- static const struct kparam_array __param_arr_##name \
65356+ static const struct kparam_array __param_arr_##name __used \
65357 = { .max = ARRAY_SIZE(array), .num = nump, \
65358 .ops = &param_ops_##type, \
65359 .elemsize = sizeof(array[0]), .elem = array }; \
65360diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
65361index 81d61e7..eadc192 100644
65362--- a/include/linux/mtd/mtd.h
65363+++ b/include/linux/mtd/mtd.h
65364@@ -238,7 +238,7 @@ struct mtd_info {
65365 */
65366 struct backing_dev_info *backing_dev_info;
65367
65368- struct notifier_block reboot_notifier; /* default mode before reboot */
65369+ notifier_block_no_const reboot_notifier; /* default mode before reboot */
65370
65371 /* ECC status information */
65372 struct mtd_ecc_stats ecc_stats;
65373diff --git a/include/linux/namei.h b/include/linux/namei.h
65374index 4bf19d8..5268cea 100644
65375--- a/include/linux/namei.h
65376+++ b/include/linux/namei.h
65377@@ -18,7 +18,7 @@ struct nameidata {
65378 unsigned seq;
65379 int last_type;
65380 unsigned depth;
65381- char *saved_names[MAX_NESTED_LINKS + 1];
65382+ const char *saved_names[MAX_NESTED_LINKS + 1];
65383 };
65384
65385 /*
65386@@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
65387
65388 extern void nd_jump_link(struct nameidata *nd, struct path *path);
65389
65390-static inline void nd_set_link(struct nameidata *nd, char *path)
65391+static inline void nd_set_link(struct nameidata *nd, const char *path)
65392 {
65393 nd->saved_names[nd->depth] = path;
65394 }
65395
65396-static inline char *nd_get_link(struct nameidata *nd)
65397+static inline const char *nd_get_link(const struct nameidata *nd)
65398 {
65399 return nd->saved_names[nd->depth];
65400 }
65401diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
65402index a848ffc..3bbbaee 100644
65403--- a/include/linux/netdevice.h
65404+++ b/include/linux/netdevice.h
65405@@ -999,6 +999,7 @@ struct net_device_ops {
65406 struct net_device *dev,
65407 int idx);
65408 };
65409+typedef struct net_device_ops __no_const net_device_ops_no_const;
65410
65411 /*
65412 * The DEVICE structure.
65413@@ -1059,7 +1060,7 @@ struct net_device {
65414 int iflink;
65415
65416 struct net_device_stats stats;
65417- atomic_long_t rx_dropped; /* dropped packets by core network
65418+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
65419 * Do not use this in drivers.
65420 */
65421
65422diff --git a/include/linux/netfilter/ipset/ip_set.h b/include/linux/netfilter/ipset/ip_set.h
65423index 7958e84..ed74d7a 100644
65424--- a/include/linux/netfilter/ipset/ip_set.h
65425+++ b/include/linux/netfilter/ipset/ip_set.h
65426@@ -98,7 +98,7 @@ struct ip_set_type_variant {
65427 /* Return true if "b" set is the same as "a"
65428 * according to the create set parameters */
65429 bool (*same_set)(const struct ip_set *a, const struct ip_set *b);
65430-};
65431+} __do_const;
65432
65433 /* The core set type structure */
65434 struct ip_set_type {
65435diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
65436index 4966dde..7d8ce06 100644
65437--- a/include/linux/netfilter/nfnetlink.h
65438+++ b/include/linux/netfilter/nfnetlink.h
65439@@ -16,7 +16,7 @@ struct nfnl_callback {
65440 const struct nlattr * const cda[]);
65441 const struct nla_policy *policy; /* netlink attribute policy */
65442 const u_int16_t attr_count; /* number of nlattr's */
65443-};
65444+} __do_const;
65445
65446 struct nfnetlink_subsystem {
65447 const char *name;
65448diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
65449new file mode 100644
65450index 0000000..33f4af8
65451--- /dev/null
65452+++ b/include/linux/netfilter/xt_gradm.h
65453@@ -0,0 +1,9 @@
65454+#ifndef _LINUX_NETFILTER_XT_GRADM_H
65455+#define _LINUX_NETFILTER_XT_GRADM_H 1
65456+
65457+struct xt_gradm_mtinfo {
65458+ __u16 flags;
65459+ __u16 invflags;
65460+};
65461+
65462+#endif
65463diff --git a/include/linux/notifier.h b/include/linux/notifier.h
65464index d65746e..62e72c2 100644
65465--- a/include/linux/notifier.h
65466+++ b/include/linux/notifier.h
65467@@ -51,7 +51,8 @@ struct notifier_block {
65468 int (*notifier_call)(struct notifier_block *, unsigned long, void *);
65469 struct notifier_block __rcu *next;
65470 int priority;
65471-};
65472+} __do_const;
65473+typedef struct notifier_block __no_const notifier_block_no_const;
65474
65475 struct atomic_notifier_head {
65476 spinlock_t lock;
65477diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
65478index c65a18a..0c05f3a 100644
65479--- a/include/linux/of_pdt.h
65480+++ b/include/linux/of_pdt.h
65481@@ -32,7 +32,7 @@ struct of_pdt_ops {
65482
65483 /* return 0 on success; fill in 'len' with number of bytes in path */
65484 int (*pkg2path)(phandle node, char *buf, const int buflen, int *len);
65485-};
65486+} __no_const;
65487
65488 extern void *prom_early_alloc(unsigned long size);
65489
65490diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
65491index a4c5624..79d6d88 100644
65492--- a/include/linux/oprofile.h
65493+++ b/include/linux/oprofile.h
65494@@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
65495 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
65496 char const * name, ulong * val);
65497
65498-/** Create a file for read-only access to an atomic_t. */
65499+/** Create a file for read-only access to an atomic_unchecked_t. */
65500 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
65501- char const * name, atomic_t * val);
65502+ char const * name, atomic_unchecked_t * val);
65503
65504 /** create a directory */
65505 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
65506diff --git a/include/linux/padata.h b/include/linux/padata.h
65507index 86292be..d67326a 100644
65508--- a/include/linux/padata.h
65509+++ b/include/linux/padata.h
65510@@ -152,7 +152,7 @@ struct parallel_data {
65511 * @flags: padata flags.
65512 */
65513 struct padata_instance {
65514- struct notifier_block cpu_notifier;
65515+ notifier_block_no_const cpu_notifier;
65516 struct workqueue_struct *wq;
65517 struct parallel_data *pd;
65518 struct padata_cpumask cpumask;
65519diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h
65520index b5d1384..70473da 100644
65521--- a/include/linux/page-flags.h
65522+++ b/include/linux/page-flags.h
65523@@ -362,7 +362,7 @@ static inline void ClearPageCompound(struct page *page)
65524 * pages on the LRU and/or pagecache.
65525 */
65526 TESTPAGEFLAG(Compound, compound)
65527-__PAGEFLAG(Head, compound)
65528+__SETPAGEFLAG(Head, compound) __CLEARPAGEFLAG(Head, compound)
65529
65530 /*
65531 * PG_reclaim is used in combination with PG_compound to mark the
65532@@ -374,8 +374,14 @@ __PAGEFLAG(Head, compound)
65533 * PG_compound & PG_reclaim => Tail page
65534 * PG_compound & ~PG_reclaim => Head page
65535 */
65536+#define PG_head_mask ((1L << PG_compound))
65537 #define PG_head_tail_mask ((1L << PG_compound) | (1L << PG_reclaim))
65538
65539+static inline int PageHead(struct page *page)
65540+{
65541+ return ((page->flags & PG_head_tail_mask) == PG_head_mask);
65542+}
65543+
65544 static inline int PageTail(struct page *page)
65545 {
65546 return ((page->flags & PG_head_tail_mask) == PG_head_tail_mask);
65547diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
65548index 6bfb2faa..1204767 100644
65549--- a/include/linux/perf_event.h
65550+++ b/include/linux/perf_event.h
65551@@ -328,8 +328,8 @@ struct perf_event {
65552
65553 enum perf_event_active_state state;
65554 unsigned int attach_state;
65555- local64_t count;
65556- atomic64_t child_count;
65557+ local64_t count; /* PaX: fix it one day */
65558+ atomic64_unchecked_t child_count;
65559
65560 /*
65561 * These are the total time in nanoseconds that the event
65562@@ -380,8 +380,8 @@ struct perf_event {
65563 * These accumulate total time (in nanoseconds) that children
65564 * events have been enabled and running, respectively.
65565 */
65566- atomic64_t child_total_time_enabled;
65567- atomic64_t child_total_time_running;
65568+ atomic64_unchecked_t child_total_time_enabled;
65569+ atomic64_unchecked_t child_total_time_running;
65570
65571 /*
65572 * Protect attach/detach and child_list:
65573diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
65574index ad1a427..6419649 100644
65575--- a/include/linux/pipe_fs_i.h
65576+++ b/include/linux/pipe_fs_i.h
65577@@ -45,9 +45,9 @@ struct pipe_buffer {
65578 struct pipe_inode_info {
65579 wait_queue_head_t wait;
65580 unsigned int nrbufs, curbuf, buffers;
65581- unsigned int readers;
65582- unsigned int writers;
65583- unsigned int waiting_writers;
65584+ atomic_t readers;
65585+ atomic_t writers;
65586+ atomic_t waiting_writers;
65587 unsigned int r_counter;
65588 unsigned int w_counter;
65589 struct page *tmp_page;
65590diff --git a/include/linux/platform_data/usb-ehci-s5p.h b/include/linux/platform_data/usb-ehci-s5p.h
65591index 5f28cae..3d23723 100644
65592--- a/include/linux/platform_data/usb-ehci-s5p.h
65593+++ b/include/linux/platform_data/usb-ehci-s5p.h
65594@@ -14,7 +14,7 @@
65595 struct s5p_ehci_platdata {
65596 int (*phy_init)(struct platform_device *pdev, int type);
65597 int (*phy_exit)(struct platform_device *pdev, int type);
65598-};
65599+} __no_const;
65600
65601 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
65602
65603diff --git a/include/linux/pm_clock.h b/include/linux/pm_clock.h
65604index 8348866..25604bd 100644
65605--- a/include/linux/pm_clock.h
65606+++ b/include/linux/pm_clock.h
65607@@ -13,7 +13,7 @@
65608 #include <linux/notifier.h>
65609
65610 struct pm_clk_notifier_block {
65611- struct notifier_block nb;
65612+ notifier_block_no_const nb;
65613 struct dev_pm_domain *pm_domain;
65614 char *con_ids[];
65615 };
65616diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
65617index f271860..6b3bec5 100644
65618--- a/include/linux/pm_runtime.h
65619+++ b/include/linux/pm_runtime.h
65620@@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
65621
65622 static inline void pm_runtime_mark_last_busy(struct device *dev)
65623 {
65624- ACCESS_ONCE(dev->power.last_busy) = jiffies;
65625+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
65626 }
65627
65628 #else /* !CONFIG_PM_RUNTIME */
65629diff --git a/include/linux/poison.h b/include/linux/poison.h
65630index 2110a81..13a11bb 100644
65631--- a/include/linux/poison.h
65632+++ b/include/linux/poison.h
65633@@ -19,8 +19,8 @@
65634 * under normal circumstances, used to verify that nobody uses
65635 * non-initialized list entries.
65636 */
65637-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
65638-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
65639+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
65640+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
65641
65642 /********** include/linux/timer.h **********/
65643 /*
65644diff --git a/include/linux/power/charger-manager.h b/include/linux/power/charger-manager.h
65645index 0e86840..13032aa 100644
65646--- a/include/linux/power/charger-manager.h
65647+++ b/include/linux/power/charger-manager.h
65648@@ -88,7 +88,7 @@ struct charger_cable {
65649 /* The charger-manager use Exton framework*/
65650 struct extcon_specific_cable_nb extcon_dev;
65651 struct work_struct wq;
65652- struct notifier_block nb;
65653+ notifier_block_no_const nb;
65654
65655 /* The state of charger cable */
65656 bool attached;
65657diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
65658index 4a496eb..d9c5659 100644
65659--- a/include/linux/power/smartreflex.h
65660+++ b/include/linux/power/smartreflex.h
65661@@ -238,7 +238,7 @@ struct omap_sr_class_data {
65662 int (*notify)(struct omap_sr *sr, u32 status);
65663 u8 notify_flags;
65664 u8 class_type;
65665-};
65666+} __do_const;
65667
65668 /**
65669 * struct omap_sr_nvalue_table - Smartreflex n-target value info
65670diff --git a/include/linux/preempt.h b/include/linux/preempt.h
65671index 5a710b9..0b0dab9 100644
65672--- a/include/linux/preempt.h
65673+++ b/include/linux/preempt.h
65674@@ -126,7 +126,7 @@ struct preempt_ops {
65675 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
65676 void (*sched_out)(struct preempt_notifier *notifier,
65677 struct task_struct *next);
65678-};
65679+} __no_const;
65680
65681 /**
65682 * preempt_notifier - key for installing preemption notifiers
65683diff --git a/include/linux/printk.h b/include/linux/printk.h
65684index 9afc01e..92c32e8 100644
65685--- a/include/linux/printk.h
65686+++ b/include/linux/printk.h
65687@@ -101,6 +101,8 @@ void early_printk(const char *fmt, ...);
65688 extern int printk_needs_cpu(int cpu);
65689 extern void printk_tick(void);
65690
65691+extern int kptr_restrict;
65692+
65693 #ifdef CONFIG_PRINTK
65694 asmlinkage __printf(5, 0)
65695 int vprintk_emit(int facility, int level,
65696@@ -135,7 +137,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
65697
65698 extern int printk_delay_msec;
65699 extern int dmesg_restrict;
65700-extern int kptr_restrict;
65701
65702 void log_buf_kexec_setup(void);
65703 void __init setup_log_buf(int early);
65704diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
65705index 3fd2e87..d93a721 100644
65706--- a/include/linux/proc_fs.h
65707+++ b/include/linux/proc_fs.h
65708@@ -155,6 +155,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
65709 return proc_create_data(name, mode, parent, proc_fops, NULL);
65710 }
65711
65712+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
65713+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
65714+{
65715+#ifdef CONFIG_GRKERNSEC_PROC_USER
65716+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
65717+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65718+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
65719+#else
65720+ return proc_create_data(name, mode, parent, proc_fops, NULL);
65721+#endif
65722+}
65723+
65724 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
65725 umode_t mode, struct proc_dir_entry *base,
65726 read_proc_t *read_proc, void * data)
65727@@ -258,7 +270,7 @@ union proc_op {
65728 int (*proc_show)(struct seq_file *m,
65729 struct pid_namespace *ns, struct pid *pid,
65730 struct task_struct *task);
65731-};
65732+} __no_const;
65733
65734 struct ctl_table_header;
65735 struct ctl_table;
65736diff --git a/include/linux/random.h b/include/linux/random.h
65737index 6330ed4..419c6c3 100644
65738--- a/include/linux/random.h
65739+++ b/include/linux/random.h
65740@@ -30,12 +30,17 @@ void srandom32(u32 seed);
65741
65742 u32 prandom32(struct rnd_state *);
65743
65744+static inline unsigned long pax_get_random_long(void)
65745+{
65746+ return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
65747+}
65748+
65749 /*
65750 * Handle minimum values for seeds
65751 */
65752 static inline u32 __seed(u32 x, u32 m)
65753 {
65754- return (x < m) ? x + m : x;
65755+ return (x <= m) ? x + m + 1 : x;
65756 }
65757
65758 /**
65759diff --git a/include/linux/reboot.h b/include/linux/reboot.h
65760index 23b3630..e1bc12b 100644
65761--- a/include/linux/reboot.h
65762+++ b/include/linux/reboot.h
65763@@ -18,9 +18,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
65764 * Architecture-specific implementations of sys_reboot commands.
65765 */
65766
65767-extern void machine_restart(char *cmd);
65768-extern void machine_halt(void);
65769-extern void machine_power_off(void);
65770+extern void machine_restart(char *cmd) __noreturn;
65771+extern void machine_halt(void) __noreturn;
65772+extern void machine_power_off(void) __noreturn;
65773
65774 extern void machine_shutdown(void);
65775 struct pt_regs;
65776@@ -31,9 +31,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
65777 */
65778
65779 extern void kernel_restart_prepare(char *cmd);
65780-extern void kernel_restart(char *cmd);
65781-extern void kernel_halt(void);
65782-extern void kernel_power_off(void);
65783+extern void kernel_restart(char *cmd) __noreturn;
65784+extern void kernel_halt(void) __noreturn;
65785+extern void kernel_power_off(void) __noreturn;
65786
65787 extern int C_A_D; /* for sysctl */
65788 void ctrl_alt_del(void);
65789@@ -47,7 +47,7 @@ extern int orderly_poweroff(bool force);
65790 * Emergency restart, callable from an interrupt handler.
65791 */
65792
65793-extern void emergency_restart(void);
65794+extern void emergency_restart(void) __noreturn;
65795 #include <asm/emergency-restart.h>
65796
65797 #endif /* _LINUX_REBOOT_H */
65798diff --git a/include/linux/regset.h b/include/linux/regset.h
65799index 8e0c9fe..fdb64bc 100644
65800--- a/include/linux/regset.h
65801+++ b/include/linux/regset.h
65802@@ -161,7 +161,7 @@ struct user_regset {
65803 unsigned int align;
65804 unsigned int bias;
65805 unsigned int core_note_type;
65806-};
65807+} __do_const;
65808
65809 /**
65810 * struct user_regset_view - available regsets
65811diff --git a/include/linux/relay.h b/include/linux/relay.h
65812index 91cacc3..b55ff74 100644
65813--- a/include/linux/relay.h
65814+++ b/include/linux/relay.h
65815@@ -160,7 +160,7 @@ struct rchan_callbacks
65816 * The callback should return 0 if successful, negative if not.
65817 */
65818 int (*remove_buf_file)(struct dentry *dentry);
65819-};
65820+} __no_const;
65821
65822 /*
65823 * CONFIG_RELAY kernel API, kernel/relay.c
65824diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
65825index d901078..0b7d00e 100644
65826--- a/include/linux/rfkill.h
65827+++ b/include/linux/rfkill.h
65828@@ -63,6 +63,7 @@ struct rfkill_ops {
65829 void (*query)(struct rfkill *rfkill, void *data);
65830 int (*set_block)(void *data, bool blocked);
65831 };
65832+typedef struct rfkill_ops __no_const rfkill_ops_no_const;
65833
65834 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
65835 /**
65836diff --git a/include/linux/rio.h b/include/linux/rio.h
65837index a3e7842..d973ca6 100644
65838--- a/include/linux/rio.h
65839+++ b/include/linux/rio.h
65840@@ -339,7 +339,7 @@ struct rio_ops {
65841 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
65842 u64 rstart, u32 size, u32 flags);
65843 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
65844-};
65845+} __no_const;
65846
65847 #define RIO_RESOURCE_MEM 0x00000100
65848 #define RIO_RESOURCE_DOORBELL 0x00000200
65849diff --git a/include/linux/rmap.h b/include/linux/rmap.h
65850index bfe1f47..6a33ee3 100644
65851--- a/include/linux/rmap.h
65852+++ b/include/linux/rmap.h
65853@@ -134,8 +134,8 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
65854 void anon_vma_init(void); /* create anon_vma_cachep */
65855 int anon_vma_prepare(struct vm_area_struct *);
65856 void unlink_anon_vmas(struct vm_area_struct *);
65857-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
65858-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
65859+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
65860+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
65861
65862 static inline void anon_vma_merge(struct vm_area_struct *vma,
65863 struct vm_area_struct *next)
65864diff --git a/include/linux/sched.h b/include/linux/sched.h
65865index 0dd42a0..cc9bffb 100644
65866--- a/include/linux/sched.h
65867+++ b/include/linux/sched.h
65868@@ -61,6 +61,7 @@ struct bio_list;
65869 struct fs_struct;
65870 struct perf_event_context;
65871 struct blk_plug;
65872+struct linux_binprm;
65873
65874 /*
65875 * List of flags we want to share for kernel threads,
65876@@ -344,10 +345,13 @@ struct user_namespace;
65877 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
65878
65879 extern int sysctl_max_map_count;
65880+extern unsigned long sysctl_heap_stack_gap;
65881
65882 #include <linux/aio.h>
65883
65884 #ifdef CONFIG_MMU
65885+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
65886+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
65887 extern void arch_pick_mmap_layout(struct mm_struct *mm);
65888 extern unsigned long
65889 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
65890@@ -614,6 +618,17 @@ struct signal_struct {
65891 #ifdef CONFIG_TASKSTATS
65892 struct taskstats *stats;
65893 #endif
65894+
65895+#ifdef CONFIG_GRKERNSEC
65896+ u32 curr_ip;
65897+ u32 saved_ip;
65898+ u32 gr_saddr;
65899+ u32 gr_daddr;
65900+ u16 gr_sport;
65901+ u16 gr_dport;
65902+ u8 used_accept:1;
65903+#endif
65904+
65905 #ifdef CONFIG_AUDIT
65906 unsigned audit_tty;
65907 struct tty_audit_buf *tty_audit_buf;
65908@@ -691,6 +706,11 @@ struct user_struct {
65909 struct key *session_keyring; /* UID's default session keyring */
65910 #endif
65911
65912+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
65913+ unsigned int banned;
65914+ unsigned long ban_expires;
65915+#endif
65916+
65917 /* Hash table maintenance information */
65918 struct hlist_node uidhash_node;
65919 kuid_t uid;
65920@@ -1312,8 +1332,8 @@ struct task_struct {
65921 struct list_head thread_group;
65922
65923 struct completion *vfork_done; /* for vfork() */
65924- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
65925- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
65926+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
65927+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
65928
65929 cputime_t utime, stime, utimescaled, stimescaled;
65930 cputime_t gtime;
65931@@ -1329,11 +1349,6 @@ struct task_struct {
65932 struct task_cputime cputime_expires;
65933 struct list_head cpu_timers[3];
65934
65935-/* process credentials */
65936- const struct cred __rcu *real_cred; /* objective and real subjective task
65937- * credentials (COW) */
65938- const struct cred __rcu *cred; /* effective (overridable) subjective task
65939- * credentials (COW) */
65940 char comm[TASK_COMM_LEN]; /* executable name excluding path
65941 - access with [gs]et_task_comm (which lock
65942 it with task_lock())
65943@@ -1350,6 +1365,10 @@ struct task_struct {
65944 #endif
65945 /* CPU-specific state of this task */
65946 struct thread_struct thread;
65947+/* thread_info moved to task_struct */
65948+#ifdef CONFIG_X86
65949+ struct thread_info tinfo;
65950+#endif
65951 /* filesystem information */
65952 struct fs_struct *fs;
65953 /* open file information */
65954@@ -1423,6 +1442,10 @@ struct task_struct {
65955 gfp_t lockdep_reclaim_gfp;
65956 #endif
65957
65958+/* process credentials */
65959+ const struct cred __rcu *real_cred; /* objective and real subjective task
65960+ * credentials (COW) */
65961+
65962 /* journalling filesystem info */
65963 void *journal_info;
65964
65965@@ -1461,6 +1484,10 @@ struct task_struct {
65966 /* cg_list protected by css_set_lock and tsk->alloc_lock */
65967 struct list_head cg_list;
65968 #endif
65969+
65970+ const struct cred __rcu *cred; /* effective (overridable) subjective task
65971+ * credentials (COW) */
65972+
65973 #ifdef CONFIG_FUTEX
65974 struct robust_list_head __user *robust_list;
65975 #ifdef CONFIG_COMPAT
65976@@ -1548,8 +1575,75 @@ struct task_struct {
65977 #ifdef CONFIG_UPROBES
65978 struct uprobe_task *utask;
65979 #endif
65980+
65981+#ifdef CONFIG_GRKERNSEC
65982+ /* grsecurity */
65983+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65984+ u64 exec_id;
65985+#endif
65986+#ifdef CONFIG_GRKERNSEC_SETXID
65987+ const struct cred *delayed_cred;
65988+#endif
65989+ struct dentry *gr_chroot_dentry;
65990+ struct acl_subject_label *acl;
65991+ struct acl_role_label *role;
65992+ struct file *exec_file;
65993+ unsigned long brute_expires;
65994+ u16 acl_role_id;
65995+ /* is this the task that authenticated to the special role */
65996+ u8 acl_sp_role;
65997+ u8 is_writable;
65998+ u8 brute;
65999+ u8 gr_is_chrooted;
66000+#endif
66001+
66002 };
66003
66004+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
66005+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
66006+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
66007+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
66008+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
66009+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
66010+
66011+#ifdef CONFIG_PAX_SOFTMODE
66012+extern int pax_softmode;
66013+#endif
66014+
66015+extern int pax_check_flags(unsigned long *);
66016+
66017+/* if tsk != current then task_lock must be held on it */
66018+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
66019+static inline unsigned long pax_get_flags(struct task_struct *tsk)
66020+{
66021+ if (likely(tsk->mm))
66022+ return tsk->mm->pax_flags;
66023+ else
66024+ return 0UL;
66025+}
66026+
66027+/* if tsk != current then task_lock must be held on it */
66028+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
66029+{
66030+ if (likely(tsk->mm)) {
66031+ tsk->mm->pax_flags = flags;
66032+ return 0;
66033+ }
66034+ return -EINVAL;
66035+}
66036+#endif
66037+
66038+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
66039+extern void pax_set_initial_flags(struct linux_binprm *bprm);
66040+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
66041+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
66042+#endif
66043+
66044+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
66045+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
66046+extern void pax_report_refcount_overflow(struct pt_regs *regs);
66047+extern void check_object_size(const void *ptr, unsigned long n, bool to);
66048+
66049 /* Future-safe accessor for struct task_struct's cpus_allowed. */
66050 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
66051
66052@@ -2092,7 +2186,9 @@ void yield(void);
66053 extern struct exec_domain default_exec_domain;
66054
66055 union thread_union {
66056+#ifndef CONFIG_X86
66057 struct thread_info thread_info;
66058+#endif
66059 unsigned long stack[THREAD_SIZE/sizeof(long)];
66060 };
66061
66062@@ -2125,6 +2221,7 @@ extern struct pid_namespace init_pid_ns;
66063 */
66064
66065 extern struct task_struct *find_task_by_vpid(pid_t nr);
66066+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
66067 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
66068 struct pid_namespace *ns);
66069
66070@@ -2281,7 +2378,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
66071 extern void exit_itimers(struct signal_struct *);
66072 extern void flush_itimer_signals(void);
66073
66074-extern void do_group_exit(int);
66075+extern __noreturn void do_group_exit(int);
66076
66077 extern void daemonize(const char *, ...);
66078 extern int allow_signal(int);
66079@@ -2485,9 +2582,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
66080
66081 #endif
66082
66083-static inline int object_is_on_stack(void *obj)
66084+static inline int object_starts_on_stack(void *obj)
66085 {
66086- void *stack = task_stack_page(current);
66087+ const void *stack = task_stack_page(current);
66088
66089 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
66090 }
66091diff --git a/include/linux/security.h b/include/linux/security.h
66092index 05e88bd..5cda002 100644
66093--- a/include/linux/security.h
66094+++ b/include/linux/security.h
66095@@ -26,6 +26,7 @@
66096 #include <linux/capability.h>
66097 #include <linux/slab.h>
66098 #include <linux/err.h>
66099+#include <linux/grsecurity.h>
66100
66101 struct linux_binprm;
66102 struct cred;
66103diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
66104index 68a04a3..866e6a1 100644
66105--- a/include/linux/seq_file.h
66106+++ b/include/linux/seq_file.h
66107@@ -26,6 +26,9 @@ struct seq_file {
66108 struct mutex lock;
66109 const struct seq_operations *op;
66110 int poll_event;
66111+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66112+ u64 exec_id;
66113+#endif
66114 #ifdef CONFIG_USER_NS
66115 struct user_namespace *user_ns;
66116 #endif
66117@@ -38,6 +41,7 @@ struct seq_operations {
66118 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
66119 int (*show) (struct seq_file *m, void *v);
66120 };
66121+typedef struct seq_operations __no_const seq_operations_no_const;
66122
66123 #define SEQ_SKIP 1
66124
66125diff --git a/include/linux/shm.h b/include/linux/shm.h
66126index bcf8a6a..4d0af77 100644
66127--- a/include/linux/shm.h
66128+++ b/include/linux/shm.h
66129@@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
66130
66131 /* The task created the shm object. NULL if the task is dead. */
66132 struct task_struct *shm_creator;
66133+#ifdef CONFIG_GRKERNSEC
66134+ time_t shm_createtime;
66135+ pid_t shm_lapid;
66136+#endif
66137 };
66138
66139 /* shm_mode upper byte flags */
66140diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
66141index 6a2c34e..a1f320f 100644
66142--- a/include/linux/skbuff.h
66143+++ b/include/linux/skbuff.h
66144@@ -577,7 +577,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
66145 extern struct sk_buff *__alloc_skb(unsigned int size,
66146 gfp_t priority, int flags, int node);
66147 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
66148-static inline struct sk_buff *alloc_skb(unsigned int size,
66149+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
66150 gfp_t priority)
66151 {
66152 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
66153@@ -687,7 +687,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
66154 */
66155 static inline int skb_queue_empty(const struct sk_buff_head *list)
66156 {
66157- return list->next == (struct sk_buff *)list;
66158+ return list->next == (const struct sk_buff *)list;
66159 }
66160
66161 /**
66162@@ -700,7 +700,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
66163 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
66164 const struct sk_buff *skb)
66165 {
66166- return skb->next == (struct sk_buff *)list;
66167+ return skb->next == (const struct sk_buff *)list;
66168 }
66169
66170 /**
66171@@ -713,7 +713,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
66172 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
66173 const struct sk_buff *skb)
66174 {
66175- return skb->prev == (struct sk_buff *)list;
66176+ return skb->prev == (const struct sk_buff *)list;
66177 }
66178
66179 /**
66180@@ -1626,7 +1626,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
66181 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
66182 */
66183 #ifndef NET_SKB_PAD
66184-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
66185+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
66186 #endif
66187
66188 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
66189@@ -2204,7 +2204,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
66190 int noblock, int *err);
66191 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
66192 struct poll_table_struct *wait);
66193-extern int skb_copy_datagram_iovec(const struct sk_buff *from,
66194+extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
66195 int offset, struct iovec *to,
66196 int size);
66197 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
66198diff --git a/include/linux/slab.h b/include/linux/slab.h
66199index 83d1a14..209e1a6 100644
66200--- a/include/linux/slab.h
66201+++ b/include/linux/slab.h
66202@@ -11,12 +11,20 @@
66203
66204 #include <linux/gfp.h>
66205 #include <linux/types.h>
66206+#include <linux/err.h>
66207
66208 /*
66209 * Flags to pass to kmem_cache_create().
66210 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
66211 */
66212 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
66213+
66214+#ifdef CONFIG_PAX_USERCOPY_SLABS
66215+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
66216+#else
66217+#define SLAB_USERCOPY 0x00000000UL
66218+#endif
66219+
66220 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
66221 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
66222 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
66223@@ -87,10 +95,13 @@
66224 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
66225 * Both make kfree a no-op.
66226 */
66227-#define ZERO_SIZE_PTR ((void *)16)
66228+#define ZERO_SIZE_PTR \
66229+({ \
66230+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
66231+ (void *)(-MAX_ERRNO-1L); \
66232+})
66233
66234-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
66235- (unsigned long)ZERO_SIZE_PTR)
66236+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
66237
66238 /*
66239 * Common fields provided in kmem_cache by all slab allocators
66240@@ -110,7 +121,7 @@ struct kmem_cache {
66241 unsigned int align; /* Alignment as calculated */
66242 unsigned long flags; /* Active flags on the slab */
66243 const char *name; /* Slab name for sysfs */
66244- int refcount; /* Use counter */
66245+ atomic_t refcount; /* Use counter */
66246 void (*ctor)(void *); /* Called on object slot creation */
66247 struct list_head list; /* List of all slab caches on the system */
66248 };
66249@@ -185,6 +196,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
66250 void kfree(const void *);
66251 void kzfree(const void *);
66252 size_t ksize(const void *);
66253+const char *check_heap_object(const void *ptr, unsigned long n);
66254+bool is_usercopy_object(const void *ptr);
66255
66256 /*
66257 * Allocator specific definitions. These are mainly used to establish optimized
66258@@ -323,7 +336,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
66259 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
66260 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
66261 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
66262-extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
66263+extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
66264 #define kmalloc_track_caller(size, flags) \
66265 __kmalloc_track_caller(size, flags, _RET_IP_)
66266 #else
66267@@ -343,7 +356,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
66268 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
66269 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
66270 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
66271-extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
66272+extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
66273 #define kmalloc_node_track_caller(size, flags, node) \
66274 __kmalloc_node_track_caller(size, flags, node, \
66275 _RET_IP_)
66276diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
66277index cc290f0..0ba60931 100644
66278--- a/include/linux/slab_def.h
66279+++ b/include/linux/slab_def.h
66280@@ -52,7 +52,7 @@ struct kmem_cache {
66281 /* 4) cache creation/removal */
66282 const char *name;
66283 struct list_head list;
66284- int refcount;
66285+ atomic_t refcount;
66286 int object_size;
66287 int align;
66288
66289@@ -68,10 +68,10 @@ struct kmem_cache {
66290 unsigned long node_allocs;
66291 unsigned long node_frees;
66292 unsigned long node_overflow;
66293- atomic_t allochit;
66294- atomic_t allocmiss;
66295- atomic_t freehit;
66296- atomic_t freemiss;
66297+ atomic_unchecked_t allochit;
66298+ atomic_unchecked_t allocmiss;
66299+ atomic_unchecked_t freehit;
66300+ atomic_unchecked_t freemiss;
66301
66302 /*
66303 * If debugging is enabled, then the allocator can add additional
66304@@ -104,11 +104,16 @@ struct cache_sizes {
66305 #ifdef CONFIG_ZONE_DMA
66306 struct kmem_cache *cs_dmacachep;
66307 #endif
66308+
66309+#ifdef CONFIG_PAX_USERCOPY_SLABS
66310+ struct kmem_cache *cs_usercopycachep;
66311+#endif
66312+
66313 };
66314 extern struct cache_sizes malloc_sizes[];
66315
66316 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
66317-void *__kmalloc(size_t size, gfp_t flags);
66318+void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
66319
66320 #ifdef CONFIG_TRACING
66321 extern void *kmem_cache_alloc_trace(struct kmem_cache *, gfp_t, size_t);
66322@@ -145,6 +150,13 @@ found:
66323 cachep = malloc_sizes[i].cs_dmacachep;
66324 else
66325 #endif
66326+
66327+#ifdef CONFIG_PAX_USERCOPY_SLABS
66328+ if (flags & GFP_USERCOPY)
66329+ cachep = malloc_sizes[i].cs_usercopycachep;
66330+ else
66331+#endif
66332+
66333 cachep = malloc_sizes[i].cs_cachep;
66334
66335 ret = kmem_cache_alloc_trace(cachep, flags, size);
66336@@ -155,7 +167,7 @@ found:
66337 }
66338
66339 #ifdef CONFIG_NUMA
66340-extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
66341+extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
66342 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
66343
66344 #ifdef CONFIG_TRACING
66345@@ -198,6 +210,13 @@ found:
66346 cachep = malloc_sizes[i].cs_dmacachep;
66347 else
66348 #endif
66349+
66350+#ifdef CONFIG_PAX_USERCOPY_SLABS
66351+ if (flags & GFP_USERCOPY)
66352+ cachep = malloc_sizes[i].cs_usercopycachep;
66353+ else
66354+#endif
66355+
66356 cachep = malloc_sizes[i].cs_cachep;
66357
66358 return kmem_cache_alloc_node_trace(cachep, flags, node, size);
66359diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
66360index f28e14a..7831211 100644
66361--- a/include/linux/slob_def.h
66362+++ b/include/linux/slob_def.h
66363@@ -11,7 +11,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
66364 return kmem_cache_alloc_node(cachep, flags, NUMA_NO_NODE);
66365 }
66366
66367-void *__kmalloc_node(size_t size, gfp_t flags, int node);
66368+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
66369
66370 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
66371 {
66372@@ -31,7 +31,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
66373 return __kmalloc_node(size, flags, NUMA_NO_NODE);
66374 }
66375
66376-static __always_inline void *__kmalloc(size_t size, gfp_t flags)
66377+static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
66378 {
66379 return kmalloc(size, flags);
66380 }
66381diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
66382index df448ad..b99e7f6 100644
66383--- a/include/linux/slub_def.h
66384+++ b/include/linux/slub_def.h
66385@@ -91,7 +91,7 @@ struct kmem_cache {
66386 struct kmem_cache_order_objects max;
66387 struct kmem_cache_order_objects min;
66388 gfp_t allocflags; /* gfp flags to use on each alloc */
66389- int refcount; /* Refcount for slab cache destroy */
66390+ atomic_t refcount; /* Refcount for slab cache destroy */
66391 void (*ctor)(void *);
66392 int inuse; /* Offset to metadata */
66393 int align; /* Alignment */
66394@@ -152,7 +152,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
66395 * Sorry that the following has to be that ugly but some versions of GCC
66396 * have trouble with constant propagation and loops.
66397 */
66398-static __always_inline int kmalloc_index(size_t size)
66399+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
66400 {
66401 if (!size)
66402 return 0;
66403@@ -217,7 +217,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
66404 }
66405
66406 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
66407-void *__kmalloc(size_t size, gfp_t flags);
66408+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
66409
66410 static __always_inline void *
66411 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
66412@@ -258,7 +258,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
66413 }
66414 #endif
66415
66416-static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
66417+static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
66418 {
66419 unsigned int order = get_order(size);
66420 return kmalloc_order_trace(size, flags, order);
66421@@ -283,7 +283,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
66422 }
66423
66424 #ifdef CONFIG_NUMA
66425-void *__kmalloc_node(size_t size, gfp_t flags, int node);
66426+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
66427 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
66428
66429 #ifdef CONFIG_TRACING
66430diff --git a/include/linux/sonet.h b/include/linux/sonet.h
66431index 680f9a3..f13aeb0 100644
66432--- a/include/linux/sonet.h
66433+++ b/include/linux/sonet.h
66434@@ -7,7 +7,7 @@
66435 #include <uapi/linux/sonet.h>
66436
66437 struct k_sonet_stats {
66438-#define __HANDLE_ITEM(i) atomic_t i
66439+#define __HANDLE_ITEM(i) atomic_unchecked_t i
66440 __SONET_ITEMS
66441 #undef __HANDLE_ITEM
66442 };
66443diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
66444index 34206b8..f019e06 100644
66445--- a/include/linux/sunrpc/clnt.h
66446+++ b/include/linux/sunrpc/clnt.h
66447@@ -176,9 +176,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
66448 {
66449 switch (sap->sa_family) {
66450 case AF_INET:
66451- return ntohs(((struct sockaddr_in *)sap)->sin_port);
66452+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
66453 case AF_INET6:
66454- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
66455+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
66456 }
66457 return 0;
66458 }
66459@@ -211,7 +211,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
66460 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
66461 const struct sockaddr *src)
66462 {
66463- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
66464+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
66465 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
66466
66467 dsin->sin_family = ssin->sin_family;
66468@@ -314,7 +314,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
66469 if (sa->sa_family != AF_INET6)
66470 return 0;
66471
66472- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
66473+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
66474 }
66475
66476 #endif /* __KERNEL__ */
66477diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h
66478index dc0c3cc..8503fb6 100644
66479--- a/include/linux/sunrpc/sched.h
66480+++ b/include/linux/sunrpc/sched.h
66481@@ -106,6 +106,7 @@ struct rpc_call_ops {
66482 void (*rpc_count_stats)(struct rpc_task *, void *);
66483 void (*rpc_release)(void *);
66484 };
66485+typedef struct rpc_call_ops __no_const rpc_call_ops_no_const;
66486
66487 struct rpc_task_setup {
66488 struct rpc_task *task;
66489diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
66490index 0b8e3e6..33e0a01 100644
66491--- a/include/linux/sunrpc/svc_rdma.h
66492+++ b/include/linux/sunrpc/svc_rdma.h
66493@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
66494 extern unsigned int svcrdma_max_requests;
66495 extern unsigned int svcrdma_max_req_size;
66496
66497-extern atomic_t rdma_stat_recv;
66498-extern atomic_t rdma_stat_read;
66499-extern atomic_t rdma_stat_write;
66500-extern atomic_t rdma_stat_sq_starve;
66501-extern atomic_t rdma_stat_rq_starve;
66502-extern atomic_t rdma_stat_rq_poll;
66503-extern atomic_t rdma_stat_rq_prod;
66504-extern atomic_t rdma_stat_sq_poll;
66505-extern atomic_t rdma_stat_sq_prod;
66506+extern atomic_unchecked_t rdma_stat_recv;
66507+extern atomic_unchecked_t rdma_stat_read;
66508+extern atomic_unchecked_t rdma_stat_write;
66509+extern atomic_unchecked_t rdma_stat_sq_starve;
66510+extern atomic_unchecked_t rdma_stat_rq_starve;
66511+extern atomic_unchecked_t rdma_stat_rq_poll;
66512+extern atomic_unchecked_t rdma_stat_rq_prod;
66513+extern atomic_unchecked_t rdma_stat_sq_poll;
66514+extern atomic_unchecked_t rdma_stat_sq_prod;
66515
66516 #define RPCRDMA_VERSION 1
66517
66518diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
66519index cd844a6..3ca3592 100644
66520--- a/include/linux/sysctl.h
66521+++ b/include/linux/sysctl.h
66522@@ -41,6 +41,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
66523
66524 extern int proc_dostring(struct ctl_table *, int,
66525 void __user *, size_t *, loff_t *);
66526+extern int proc_dostring_modpriv(struct ctl_table *, int,
66527+ void __user *, size_t *, loff_t *);
66528 extern int proc_dointvec(struct ctl_table *, int,
66529 void __user *, size_t *, loff_t *);
66530 extern int proc_dointvec_minmax(struct ctl_table *, int,
66531diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
66532index 7faf933..eb6f5e3 100644
66533--- a/include/linux/sysrq.h
66534+++ b/include/linux/sysrq.h
66535@@ -36,7 +36,7 @@ struct sysrq_key_op {
66536 char *help_msg;
66537 char *action_msg;
66538 int enable_mask;
66539-};
66540+} __do_const;
66541
66542 #ifdef CONFIG_MAGIC_SYSRQ
66543
66544diff --git a/include/linux/tty.h b/include/linux/tty.h
66545index f0b4eb4..1c4854e 100644
66546--- a/include/linux/tty.h
66547+++ b/include/linux/tty.h
66548@@ -192,7 +192,7 @@ struct tty_port {
66549 const struct tty_port_operations *ops; /* Port operations */
66550 spinlock_t lock; /* Lock protecting tty field */
66551 int blocked_open; /* Waiting to open */
66552- int count; /* Usage count */
66553+ atomic_t count; /* Usage count */
66554 wait_queue_head_t open_wait; /* Open waiters */
66555 wait_queue_head_t close_wait; /* Close waiters */
66556 wait_queue_head_t delta_msr_wait; /* Modem status change */
66557@@ -513,7 +513,7 @@ extern int tty_port_open(struct tty_port *port,
66558 struct tty_struct *tty, struct file *filp);
66559 static inline int tty_port_users(struct tty_port *port)
66560 {
66561- return port->count + port->blocked_open;
66562+ return atomic_read(&port->count) + port->blocked_open;
66563 }
66564
66565 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
66566diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
66567index dd976cf..e272742 100644
66568--- a/include/linux/tty_driver.h
66569+++ b/include/linux/tty_driver.h
66570@@ -284,7 +284,7 @@ struct tty_operations {
66571 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
66572 #endif
66573 const struct file_operations *proc_fops;
66574-};
66575+} __do_const;
66576
66577 struct tty_driver {
66578 int magic; /* magic number for this structure */
66579diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
66580index fb79dd8d..07d4773 100644
66581--- a/include/linux/tty_ldisc.h
66582+++ b/include/linux/tty_ldisc.h
66583@@ -149,7 +149,7 @@ struct tty_ldisc_ops {
66584
66585 struct module *owner;
66586
66587- int refcount;
66588+ atomic_t refcount;
66589 };
66590
66591 struct tty_ldisc {
66592diff --git a/include/linux/types.h b/include/linux/types.h
66593index 1cc0e4b..0d50edf 100644
66594--- a/include/linux/types.h
66595+++ b/include/linux/types.h
66596@@ -175,10 +175,26 @@ typedef struct {
66597 int counter;
66598 } atomic_t;
66599
66600+#ifdef CONFIG_PAX_REFCOUNT
66601+typedef struct {
66602+ int counter;
66603+} atomic_unchecked_t;
66604+#else
66605+typedef atomic_t atomic_unchecked_t;
66606+#endif
66607+
66608 #ifdef CONFIG_64BIT
66609 typedef struct {
66610 long counter;
66611 } atomic64_t;
66612+
66613+#ifdef CONFIG_PAX_REFCOUNT
66614+typedef struct {
66615+ long counter;
66616+} atomic64_unchecked_t;
66617+#else
66618+typedef atomic64_t atomic64_unchecked_t;
66619+#endif
66620 #endif
66621
66622 struct list_head {
66623diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
66624index 5ca0951..ab496a5 100644
66625--- a/include/linux/uaccess.h
66626+++ b/include/linux/uaccess.h
66627@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
66628 long ret; \
66629 mm_segment_t old_fs = get_fs(); \
66630 \
66631- set_fs(KERNEL_DS); \
66632 pagefault_disable(); \
66633- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
66634- pagefault_enable(); \
66635+ set_fs(KERNEL_DS); \
66636+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
66637 set_fs(old_fs); \
66638+ pagefault_enable(); \
66639 ret; \
66640 })
66641
66642diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
66643index 99c1b4d..bb94261 100644
66644--- a/include/linux/unaligned/access_ok.h
66645+++ b/include/linux/unaligned/access_ok.h
66646@@ -6,32 +6,32 @@
66647
66648 static inline u16 get_unaligned_le16(const void *p)
66649 {
66650- return le16_to_cpup((__le16 *)p);
66651+ return le16_to_cpup((const __le16 *)p);
66652 }
66653
66654 static inline u32 get_unaligned_le32(const void *p)
66655 {
66656- return le32_to_cpup((__le32 *)p);
66657+ return le32_to_cpup((const __le32 *)p);
66658 }
66659
66660 static inline u64 get_unaligned_le64(const void *p)
66661 {
66662- return le64_to_cpup((__le64 *)p);
66663+ return le64_to_cpup((const __le64 *)p);
66664 }
66665
66666 static inline u16 get_unaligned_be16(const void *p)
66667 {
66668- return be16_to_cpup((__be16 *)p);
66669+ return be16_to_cpup((const __be16 *)p);
66670 }
66671
66672 static inline u32 get_unaligned_be32(const void *p)
66673 {
66674- return be32_to_cpup((__be32 *)p);
66675+ return be32_to_cpup((const __be32 *)p);
66676 }
66677
66678 static inline u64 get_unaligned_be64(const void *p)
66679 {
66680- return be64_to_cpup((__be64 *)p);
66681+ return be64_to_cpup((const __be64 *)p);
66682 }
66683
66684 static inline void put_unaligned_le16(u16 val, void *p)
66685diff --git a/include/linux/usb.h b/include/linux/usb.h
66686index 10278d1..e21ec3c 100644
66687--- a/include/linux/usb.h
66688+++ b/include/linux/usb.h
66689@@ -551,7 +551,7 @@ struct usb_device {
66690 int maxchild;
66691
66692 u32 quirks;
66693- atomic_t urbnum;
66694+ atomic_unchecked_t urbnum;
66695
66696 unsigned long active_duration;
66697
66698diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
66699index c5d36c6..8478c90 100644
66700--- a/include/linux/usb/renesas_usbhs.h
66701+++ b/include/linux/usb/renesas_usbhs.h
66702@@ -39,7 +39,7 @@ enum {
66703 */
66704 struct renesas_usbhs_driver_callback {
66705 int (*notify_hotplug)(struct platform_device *pdev);
66706-};
66707+} __no_const;
66708
66709 /*
66710 * callback functions for platform
66711@@ -97,7 +97,7 @@ struct renesas_usbhs_platform_callback {
66712 * VBUS control is needed for Host
66713 */
66714 int (*set_vbus)(struct platform_device *pdev, int enable);
66715-};
66716+} __no_const;
66717
66718 /*
66719 * parameters for renesas usbhs
66720diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
66721index 6f8fbcf..8259001 100644
66722--- a/include/linux/vermagic.h
66723+++ b/include/linux/vermagic.h
66724@@ -25,9 +25,35 @@
66725 #define MODULE_ARCH_VERMAGIC ""
66726 #endif
66727
66728+#ifdef CONFIG_PAX_REFCOUNT
66729+#define MODULE_PAX_REFCOUNT "REFCOUNT "
66730+#else
66731+#define MODULE_PAX_REFCOUNT ""
66732+#endif
66733+
66734+#ifdef CONSTIFY_PLUGIN
66735+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
66736+#else
66737+#define MODULE_CONSTIFY_PLUGIN ""
66738+#endif
66739+
66740+#ifdef STACKLEAK_PLUGIN
66741+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
66742+#else
66743+#define MODULE_STACKLEAK_PLUGIN ""
66744+#endif
66745+
66746+#ifdef CONFIG_GRKERNSEC
66747+#define MODULE_GRSEC "GRSEC "
66748+#else
66749+#define MODULE_GRSEC ""
66750+#endif
66751+
66752 #define VERMAGIC_STRING \
66753 UTS_RELEASE " " \
66754 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
66755 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
66756- MODULE_ARCH_VERMAGIC
66757+ MODULE_ARCH_VERMAGIC \
66758+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
66759+ MODULE_GRSEC
66760
66761diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
66762index 6071e91..ca6a489 100644
66763--- a/include/linux/vmalloc.h
66764+++ b/include/linux/vmalloc.h
66765@@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
66766 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
66767 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
66768 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
66769+
66770+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
66771+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
66772+#endif
66773+
66774 /* bits [20..32] reserved for arch specific ioremap internals */
66775
66776 /*
66777@@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
66778 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
66779 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
66780 unsigned long start, unsigned long end, gfp_t gfp_mask,
66781- pgprot_t prot, int node, const void *caller);
66782+ pgprot_t prot, int node, const void *caller) __size_overflow(1);
66783 extern void vfree(const void *addr);
66784
66785 extern void *vmap(struct page **pages, unsigned int count,
66786@@ -124,8 +129,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
66787 extern void free_vm_area(struct vm_struct *area);
66788
66789 /* for /dev/kmem */
66790-extern long vread(char *buf, char *addr, unsigned long count);
66791-extern long vwrite(char *buf, char *addr, unsigned long count);
66792+extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
66793+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
66794
66795 /*
66796 * Internals. Dont't use..
66797diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
66798index 92a86b2..1d9eb3c 100644
66799--- a/include/linux/vmstat.h
66800+++ b/include/linux/vmstat.h
66801@@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
66802 /*
66803 * Zone based page accounting with per cpu differentials.
66804 */
66805-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
66806+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
66807
66808 static inline void zone_page_state_add(long x, struct zone *zone,
66809 enum zone_stat_item item)
66810 {
66811- atomic_long_add(x, &zone->vm_stat[item]);
66812- atomic_long_add(x, &vm_stat[item]);
66813+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
66814+ atomic_long_add_unchecked(x, &vm_stat[item]);
66815 }
66816
66817 static inline unsigned long global_page_state(enum zone_stat_item item)
66818 {
66819- long x = atomic_long_read(&vm_stat[item]);
66820+ long x = atomic_long_read_unchecked(&vm_stat[item]);
66821 #ifdef CONFIG_SMP
66822 if (x < 0)
66823 x = 0;
66824@@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
66825 static inline unsigned long zone_page_state(struct zone *zone,
66826 enum zone_stat_item item)
66827 {
66828- long x = atomic_long_read(&zone->vm_stat[item]);
66829+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
66830 #ifdef CONFIG_SMP
66831 if (x < 0)
66832 x = 0;
66833@@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
66834 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
66835 enum zone_stat_item item)
66836 {
66837- long x = atomic_long_read(&zone->vm_stat[item]);
66838+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
66839
66840 #ifdef CONFIG_SMP
66841 int cpu;
66842@@ -218,8 +218,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
66843
66844 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
66845 {
66846- atomic_long_inc(&zone->vm_stat[item]);
66847- atomic_long_inc(&vm_stat[item]);
66848+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
66849+ atomic_long_inc_unchecked(&vm_stat[item]);
66850 }
66851
66852 static inline void __inc_zone_page_state(struct page *page,
66853@@ -230,8 +230,8 @@ static inline void __inc_zone_page_state(struct page *page,
66854
66855 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
66856 {
66857- atomic_long_dec(&zone->vm_stat[item]);
66858- atomic_long_dec(&vm_stat[item]);
66859+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
66860+ atomic_long_dec_unchecked(&vm_stat[item]);
66861 }
66862
66863 static inline void __dec_zone_page_state(struct page *page,
66864diff --git a/include/media/saa7146_vv.h b/include/media/saa7146_vv.h
66865index 944ecdf..a3994fc 100644
66866--- a/include/media/saa7146_vv.h
66867+++ b/include/media/saa7146_vv.h
66868@@ -161,8 +161,8 @@ struct saa7146_ext_vv
66869 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
66870
66871 /* the extension can override this */
66872- struct v4l2_ioctl_ops vid_ops;
66873- struct v4l2_ioctl_ops vbi_ops;
66874+ v4l2_ioctl_ops_no_const vid_ops;
66875+ v4l2_ioctl_ops_no_const vbi_ops;
66876 /* pointer to the saa7146 core ops */
66877 const struct v4l2_ioctl_ops *core_ops;
66878
66879diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
66880index 95d1c91..19a5d94 100644
66881--- a/include/media/v4l2-dev.h
66882+++ b/include/media/v4l2-dev.h
66883@@ -76,7 +76,8 @@ struct v4l2_file_operations {
66884 int (*mmap) (struct file *, struct vm_area_struct *);
66885 int (*open) (struct file *);
66886 int (*release) (struct file *);
66887-};
66888+} __do_const;
66889+typedef struct v4l2_file_operations __no_const v4l2_file_operations_no_const;
66890
66891 /*
66892 * Newer version of video_device, handled by videodev2.c
66893diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
66894index e48b571..cec1748 100644
66895--- a/include/media/v4l2-ioctl.h
66896+++ b/include/media/v4l2-ioctl.h
66897@@ -281,7 +281,7 @@ struct v4l2_ioctl_ops {
66898 long (*vidioc_default) (struct file *file, void *fh,
66899 bool valid_prio, int cmd, void *arg);
66900 };
66901-
66902+typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
66903
66904 /* v4l debugging and diagnostics */
66905
66906diff --git a/include/net/bluetooth/bluetooth.h b/include/net/bluetooth/bluetooth.h
66907index ede0369..067cf12 100644
66908--- a/include/net/bluetooth/bluetooth.h
66909+++ b/include/net/bluetooth/bluetooth.h
66910@@ -204,7 +204,7 @@ struct bt_sock_list {
66911 struct hlist_head head;
66912 rwlock_t lock;
66913 #ifdef CONFIG_PROC_FS
66914- struct file_operations fops;
66915+ file_operations_no_const fops;
66916 int (* custom_seq_show)(struct seq_file *, void *);
66917 #endif
66918 };
66919diff --git a/include/net/caif/caif_hsi.h b/include/net/caif/caif_hsi.h
66920index bcb9cc3..f4ec722e 100644
66921--- a/include/net/caif/caif_hsi.h
66922+++ b/include/net/caif/caif_hsi.h
66923@@ -98,7 +98,7 @@ struct cfhsi_cb_ops {
66924 void (*rx_done_cb) (struct cfhsi_cb_ops *drv);
66925 void (*wake_up_cb) (struct cfhsi_cb_ops *drv);
66926 void (*wake_down_cb) (struct cfhsi_cb_ops *drv);
66927-};
66928+} __no_const;
66929
66930 /* Structure implemented by HSI device. */
66931 struct cfhsi_ops {
66932diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
66933index 9e5425b..8136ffc 100644
66934--- a/include/net/caif/cfctrl.h
66935+++ b/include/net/caif/cfctrl.h
66936@@ -52,7 +52,7 @@ struct cfctrl_rsp {
66937 void (*radioset_rsp)(void);
66938 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
66939 struct cflayer *client_layer);
66940-};
66941+} __no_const;
66942
66943 /* Link Setup Parameters for CAIF-Links. */
66944 struct cfctrl_link_param {
66945@@ -101,8 +101,8 @@ struct cfctrl_request_info {
66946 struct cfctrl {
66947 struct cfsrvl serv;
66948 struct cfctrl_rsp res;
66949- atomic_t req_seq_no;
66950- atomic_t rsp_seq_no;
66951+ atomic_unchecked_t req_seq_no;
66952+ atomic_unchecked_t rsp_seq_no;
66953 struct list_head list;
66954 /* Protects from simultaneous access to first_req list */
66955 spinlock_t info_list_lock;
66956diff --git a/include/net/flow.h b/include/net/flow.h
66957index 628e11b..4c475df 100644
66958--- a/include/net/flow.h
66959+++ b/include/net/flow.h
66960@@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
66961
66962 extern void flow_cache_flush(void);
66963 extern void flow_cache_flush_deferred(void);
66964-extern atomic_t flow_cache_genid;
66965+extern atomic_unchecked_t flow_cache_genid;
66966
66967 #endif
66968diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
66969index 4fd8a4b..123e31a 100644
66970--- a/include/net/gro_cells.h
66971+++ b/include/net/gro_cells.h
66972@@ -30,7 +30,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
66973 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
66974
66975 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
66976- atomic_long_inc(&dev->rx_dropped);
66977+ atomic_long_inc_unchecked(&dev->rx_dropped);
66978 kfree_skb(skb);
66979 return;
66980 }
66981diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
66982index ba1d361..8163a9c 100644
66983--- a/include/net/inet_connection_sock.h
66984+++ b/include/net/inet_connection_sock.h
66985@@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
66986 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
66987 int (*bind_conflict)(const struct sock *sk,
66988 const struct inet_bind_bucket *tb, bool relax);
66989-};
66990+} __do_const;
66991
66992 /** inet_connection_sock - INET connection oriented sock
66993 *
66994diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
66995index 53f464d..ba76aaa 100644
66996--- a/include/net/inetpeer.h
66997+++ b/include/net/inetpeer.h
66998@@ -47,8 +47,8 @@ struct inet_peer {
66999 */
67000 union {
67001 struct {
67002- atomic_t rid; /* Frag reception counter */
67003- atomic_t ip_id_count; /* IP ID for the next packet */
67004+ atomic_unchecked_t rid; /* Frag reception counter */
67005+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
67006 };
67007 struct rcu_head rcu;
67008 struct inet_peer *gc_next;
67009@@ -182,11 +182,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
67010 more++;
67011 inet_peer_refcheck(p);
67012 do {
67013- old = atomic_read(&p->ip_id_count);
67014+ old = atomic_read_unchecked(&p->ip_id_count);
67015 new = old + more;
67016 if (!new)
67017 new = 1;
67018- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
67019+ } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
67020 return new;
67021 }
67022
67023diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
67024index 9497be1..5a4fafe 100644
67025--- a/include/net/ip_fib.h
67026+++ b/include/net/ip_fib.h
67027@@ -169,7 +169,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
67028
67029 #define FIB_RES_SADDR(net, res) \
67030 ((FIB_RES_NH(res).nh_saddr_genid == \
67031- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
67032+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
67033 FIB_RES_NH(res).nh_saddr : \
67034 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
67035 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
67036diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
67037index ee75ccd..2cc2b95 100644
67038--- a/include/net/ip_vs.h
67039+++ b/include/net/ip_vs.h
67040@@ -510,7 +510,7 @@ struct ip_vs_conn {
67041 struct ip_vs_conn *control; /* Master control connection */
67042 atomic_t n_control; /* Number of controlled ones */
67043 struct ip_vs_dest *dest; /* real server */
67044- atomic_t in_pkts; /* incoming packet counter */
67045+ atomic_unchecked_t in_pkts; /* incoming packet counter */
67046
67047 /* packet transmitter for different forwarding methods. If it
67048 mangles the packet, it must return NF_DROP or better NF_STOLEN,
67049@@ -648,7 +648,7 @@ struct ip_vs_dest {
67050 __be16 port; /* port number of the server */
67051 union nf_inet_addr addr; /* IP address of the server */
67052 volatile unsigned int flags; /* dest status flags */
67053- atomic_t conn_flags; /* flags to copy to conn */
67054+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
67055 atomic_t weight; /* server weight */
67056
67057 atomic_t refcnt; /* reference counter */
67058diff --git a/include/net/irda/ircomm_core.h b/include/net/irda/ircomm_core.h
67059index 69b610a..fe3962c 100644
67060--- a/include/net/irda/ircomm_core.h
67061+++ b/include/net/irda/ircomm_core.h
67062@@ -51,7 +51,7 @@ typedef struct {
67063 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
67064 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
67065 struct ircomm_info *);
67066-} call_t;
67067+} __no_const call_t;
67068
67069 struct ircomm_cb {
67070 irda_queue_t queue;
67071diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
67072index 80ffde3..968b0f4 100644
67073--- a/include/net/irda/ircomm_tty.h
67074+++ b/include/net/irda/ircomm_tty.h
67075@@ -35,6 +35,7 @@
67076 #include <linux/termios.h>
67077 #include <linux/timer.h>
67078 #include <linux/tty.h> /* struct tty_struct */
67079+#include <asm/local.h>
67080
67081 #include <net/irda/irias_object.h>
67082 #include <net/irda/ircomm_core.h>
67083diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
67084index cc7c197..9f2da2a 100644
67085--- a/include/net/iucv/af_iucv.h
67086+++ b/include/net/iucv/af_iucv.h
67087@@ -141,7 +141,7 @@ struct iucv_sock {
67088 struct iucv_sock_list {
67089 struct hlist_head head;
67090 rwlock_t lock;
67091- atomic_t autobind_name;
67092+ atomic_unchecked_t autobind_name;
67093 };
67094
67095 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
67096diff --git a/include/net/neighbour.h b/include/net/neighbour.h
67097index 0dab173..1b76af0 100644
67098--- a/include/net/neighbour.h
67099+++ b/include/net/neighbour.h
67100@@ -123,7 +123,7 @@ struct neigh_ops {
67101 void (*error_report)(struct neighbour *, struct sk_buff *);
67102 int (*output)(struct neighbour *, struct sk_buff *);
67103 int (*connected_output)(struct neighbour *, struct sk_buff *);
67104-};
67105+} __do_const;
67106
67107 struct pneigh_entry {
67108 struct pneigh_entry *next;
67109diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
67110index 95e6466..251016d 100644
67111--- a/include/net/net_namespace.h
67112+++ b/include/net/net_namespace.h
67113@@ -110,7 +110,7 @@ struct net {
67114 #endif
67115 struct netns_ipvs *ipvs;
67116 struct sock *diag_nlsk;
67117- atomic_t rt_genid;
67118+ atomic_unchecked_t rt_genid;
67119 };
67120
67121 /*
67122@@ -320,12 +320,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
67123
67124 static inline int rt_genid(struct net *net)
67125 {
67126- return atomic_read(&net->rt_genid);
67127+ return atomic_read_unchecked(&net->rt_genid);
67128 }
67129
67130 static inline void rt_genid_bump(struct net *net)
67131 {
67132- atomic_inc(&net->rt_genid);
67133+ atomic_inc_unchecked(&net->rt_genid);
67134 }
67135
67136 #endif /* __NET_NET_NAMESPACE_H */
67137diff --git a/include/net/netdma.h b/include/net/netdma.h
67138index 8ba8ce2..99b7fff 100644
67139--- a/include/net/netdma.h
67140+++ b/include/net/netdma.h
67141@@ -24,7 +24,7 @@
67142 #include <linux/dmaengine.h>
67143 #include <linux/skbuff.h>
67144
67145-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
67146+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
67147 struct sk_buff *skb, int offset, struct iovec *to,
67148 size_t len, struct dma_pinned_list *pinned_list);
67149
67150diff --git a/include/net/netfilter/nf_queue.h b/include/net/netfilter/nf_queue.h
67151index 252fd10..aa1421f 100644
67152--- a/include/net/netfilter/nf_queue.h
67153+++ b/include/net/netfilter/nf_queue.h
67154@@ -22,7 +22,7 @@ struct nf_queue_handler {
67155 int (*outfn)(struct nf_queue_entry *entry,
67156 unsigned int queuenum);
67157 char *name;
67158-};
67159+} __do_const;
67160
67161 extern int nf_register_queue_handler(u_int8_t pf,
67162 const struct nf_queue_handler *qh);
67163diff --git a/include/net/netlink.h b/include/net/netlink.h
67164index 9690b0f..87aded7 100644
67165--- a/include/net/netlink.h
67166+++ b/include/net/netlink.h
67167@@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
67168 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
67169 {
67170 if (mark)
67171- skb_trim(skb, (unsigned char *) mark - skb->data);
67172+ skb_trim(skb, (const unsigned char *) mark - skb->data);
67173 }
67174
67175 /**
67176diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
67177index 2ae2b83..dbdc85e 100644
67178--- a/include/net/netns/ipv4.h
67179+++ b/include/net/netns/ipv4.h
67180@@ -64,7 +64,7 @@ struct netns_ipv4 {
67181 kgid_t sysctl_ping_group_range[2];
67182 long sysctl_tcp_mem[3];
67183
67184- atomic_t dev_addr_genid;
67185+ atomic_unchecked_t dev_addr_genid;
67186
67187 #ifdef CONFIG_IP_MROUTE
67188 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
67189diff --git a/include/net/protocol.h b/include/net/protocol.h
67190index 929528c..c84d4f6 100644
67191--- a/include/net/protocol.h
67192+++ b/include/net/protocol.h
67193@@ -48,7 +48,7 @@ struct net_protocol {
67194 int (*gro_complete)(struct sk_buff *skb);
67195 unsigned int no_policy:1,
67196 netns_ok:1;
67197-};
67198+} __do_const;
67199
67200 #if IS_ENABLED(CONFIG_IPV6)
67201 struct inet6_protocol {
67202@@ -69,7 +69,7 @@ struct inet6_protocol {
67203 int (*gro_complete)(struct sk_buff *skb);
67204
67205 unsigned int flags; /* INET6_PROTO_xxx */
67206-};
67207+} __do_const;
67208
67209 #define INET6_PROTO_NOPOLICY 0x1
67210 #define INET6_PROTO_FINAL 0x2
67211diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
67212index 9c6414f..fbd0524 100644
67213--- a/include/net/sctp/sctp.h
67214+++ b/include/net/sctp/sctp.h
67215@@ -318,9 +318,9 @@ do { \
67216
67217 #else /* SCTP_DEBUG */
67218
67219-#define SCTP_DEBUG_PRINTK(whatever...)
67220-#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
67221-#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
67222+#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
67223+#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
67224+#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
67225 #define SCTP_ENABLE_DEBUG
67226 #define SCTP_DISABLE_DEBUG
67227 #define SCTP_ASSERT(expr, str, func)
67228diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
67229index 64158aa..b65533c 100644
67230--- a/include/net/sctp/structs.h
67231+++ b/include/net/sctp/structs.h
67232@@ -496,7 +496,7 @@ struct sctp_af {
67233 int sockaddr_len;
67234 sa_family_t sa_family;
67235 struct list_head list;
67236-};
67237+} __do_const;
67238
67239 struct sctp_af *sctp_get_af_specific(sa_family_t);
67240 int sctp_register_af(struct sctp_af *);
67241@@ -516,7 +516,7 @@ struct sctp_pf {
67242 struct sctp_association *asoc);
67243 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
67244 struct sctp_af *af;
67245-};
67246+} __do_const;
67247
67248
67249 /* Structure to track chunk fragments that have been acked, but peer
67250diff --git a/include/net/sock.h b/include/net/sock.h
67251index c945fba..e162e56 100644
67252--- a/include/net/sock.h
67253+++ b/include/net/sock.h
67254@@ -304,7 +304,7 @@ struct sock {
67255 #ifdef CONFIG_RPS
67256 __u32 sk_rxhash;
67257 #endif
67258- atomic_t sk_drops;
67259+ atomic_unchecked_t sk_drops;
67260 int sk_rcvbuf;
67261
67262 struct sk_filter __rcu *sk_filter;
67263@@ -1763,7 +1763,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
67264 }
67265
67266 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
67267- char __user *from, char *to,
67268+ char __user *from, unsigned char *to,
67269 int copy, int offset)
67270 {
67271 if (skb->ip_summed == CHECKSUM_NONE) {
67272@@ -2022,7 +2022,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
67273 }
67274 }
67275
67276-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
67277+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
67278
67279 /**
67280 * sk_page_frag - return an appropriate page_frag
67281diff --git a/include/net/tcp.h b/include/net/tcp.h
67282index 4af45e3..32163a9 100644
67283--- a/include/net/tcp.h
67284+++ b/include/net/tcp.h
67285@@ -531,7 +531,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
67286 extern void tcp_xmit_retransmit_queue(struct sock *);
67287 extern void tcp_simple_retransmit(struct sock *);
67288 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
67289-extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
67290+extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
67291
67292 extern void tcp_send_probe0(struct sock *);
67293 extern void tcp_send_partial(struct sock *);
67294@@ -702,8 +702,8 @@ struct tcp_skb_cb {
67295 struct inet6_skb_parm h6;
67296 #endif
67297 } header; /* For incoming frames */
67298- __u32 seq; /* Starting sequence number */
67299- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
67300+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
67301+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
67302 __u32 when; /* used to compute rtt's */
67303 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
67304
67305@@ -717,7 +717,7 @@ struct tcp_skb_cb {
67306
67307 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
67308 /* 1 byte hole */
67309- __u32 ack_seq; /* Sequence number ACK'd */
67310+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
67311 };
67312
67313 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
67314@@ -1563,7 +1563,7 @@ struct tcp_seq_afinfo {
67315 char *name;
67316 sa_family_t family;
67317 const struct file_operations *seq_fops;
67318- struct seq_operations seq_ops;
67319+ seq_operations_no_const seq_ops;
67320 };
67321
67322 struct tcp_iter_state {
67323diff --git a/include/net/udp.h b/include/net/udp.h
67324index 065f379..b661b40 100644
67325--- a/include/net/udp.h
67326+++ b/include/net/udp.h
67327@@ -244,7 +244,7 @@ struct udp_seq_afinfo {
67328 sa_family_t family;
67329 struct udp_table *udp_table;
67330 const struct file_operations *seq_fops;
67331- struct seq_operations seq_ops;
67332+ seq_operations_no_const seq_ops;
67333 };
67334
67335 struct udp_iter_state {
67336diff --git a/include/net/xfrm.h b/include/net/xfrm.h
67337index 63445ed..74ef61d 100644
67338--- a/include/net/xfrm.h
67339+++ b/include/net/xfrm.h
67340@@ -423,7 +423,7 @@ struct xfrm_mode {
67341 struct module *owner;
67342 unsigned int encap;
67343 int flags;
67344-};
67345+} __do_const;
67346
67347 /* Flags for xfrm_mode. */
67348 enum {
67349@@ -514,7 +514,7 @@ struct xfrm_policy {
67350 struct timer_list timer;
67351
67352 struct flow_cache_object flo;
67353- atomic_t genid;
67354+ atomic_unchecked_t genid;
67355 u32 priority;
67356 u32 index;
67357 struct xfrm_mark mark;
67358diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
67359index 1a046b1..ee0bef0 100644
67360--- a/include/rdma/iw_cm.h
67361+++ b/include/rdma/iw_cm.h
67362@@ -122,7 +122,7 @@ struct iw_cm_verbs {
67363 int backlog);
67364
67365 int (*destroy_listen)(struct iw_cm_id *cm_id);
67366-};
67367+} __no_const;
67368
67369 /**
67370 * iw_create_cm_id - Create an IW CM identifier.
67371diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
67372index 399162b..b337f1a 100644
67373--- a/include/scsi/libfc.h
67374+++ b/include/scsi/libfc.h
67375@@ -762,6 +762,7 @@ struct libfc_function_template {
67376 */
67377 void (*disc_stop_final) (struct fc_lport *);
67378 };
67379+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
67380
67381 /**
67382 * struct fc_disc - Discovery context
67383@@ -866,7 +867,7 @@ struct fc_lport {
67384 struct fc_vport *vport;
67385
67386 /* Operational Information */
67387- struct libfc_function_template tt;
67388+ libfc_function_template_no_const tt;
67389 u8 link_up;
67390 u8 qfull;
67391 enum fc_lport_state state;
67392diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
67393index 55367b0..d97bd2a 100644
67394--- a/include/scsi/scsi_device.h
67395+++ b/include/scsi/scsi_device.h
67396@@ -169,9 +169,9 @@ struct scsi_device {
67397 unsigned int max_device_blocked; /* what device_blocked counts down from */
67398 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
67399
67400- atomic_t iorequest_cnt;
67401- atomic_t iodone_cnt;
67402- atomic_t ioerr_cnt;
67403+ atomic_unchecked_t iorequest_cnt;
67404+ atomic_unchecked_t iodone_cnt;
67405+ atomic_unchecked_t ioerr_cnt;
67406
67407 struct device sdev_gendev,
67408 sdev_dev;
67409diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
67410index b797e8f..8e2c3aa 100644
67411--- a/include/scsi/scsi_transport_fc.h
67412+++ b/include/scsi/scsi_transport_fc.h
67413@@ -751,7 +751,8 @@ struct fc_function_template {
67414 unsigned long show_host_system_hostname:1;
67415
67416 unsigned long disable_target_scan:1;
67417-};
67418+} __do_const;
67419+typedef struct fc_function_template __no_const fc_function_template_no_const;
67420
67421
67422 /**
67423diff --git a/include/sound/ak4xxx-adda.h b/include/sound/ak4xxx-adda.h
67424index 030b87c..98a6954 100644
67425--- a/include/sound/ak4xxx-adda.h
67426+++ b/include/sound/ak4xxx-adda.h
67427@@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
67428 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
67429 unsigned char val);
67430 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
67431-};
67432+} __no_const;
67433
67434 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
67435
67436diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h
67437index 8c05e47..2b5df97 100644
67438--- a/include/sound/hwdep.h
67439+++ b/include/sound/hwdep.h
67440@@ -49,7 +49,7 @@ struct snd_hwdep_ops {
67441 struct snd_hwdep_dsp_status *status);
67442 int (*dsp_load)(struct snd_hwdep *hw,
67443 struct snd_hwdep_dsp_image *image);
67444-};
67445+} __no_const;
67446
67447 struct snd_hwdep {
67448 struct snd_card *card;
67449diff --git a/include/sound/info.h b/include/sound/info.h
67450index 9ca1a49..aba1728 100644
67451--- a/include/sound/info.h
67452+++ b/include/sound/info.h
67453@@ -44,7 +44,7 @@ struct snd_info_entry_text {
67454 struct snd_info_buffer *buffer);
67455 void (*write)(struct snd_info_entry *entry,
67456 struct snd_info_buffer *buffer);
67457-};
67458+} __no_const;
67459
67460 struct snd_info_entry_ops {
67461 int (*open)(struct snd_info_entry *entry,
67462diff --git a/include/sound/pcm.h b/include/sound/pcm.h
67463index 6268a41..de9b9d1 100644
67464--- a/include/sound/pcm.h
67465+++ b/include/sound/pcm.h
67466@@ -81,6 +81,7 @@ struct snd_pcm_ops {
67467 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
67468 int (*ack)(struct snd_pcm_substream *substream);
67469 };
67470+typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
67471
67472 /*
67473 *
67474diff --git a/include/sound/sb16_csp.h b/include/sound/sb16_csp.h
67475index 7e95056..52df55a 100644
67476--- a/include/sound/sb16_csp.h
67477+++ b/include/sound/sb16_csp.h
67478@@ -146,7 +146,7 @@ struct snd_sb_csp_ops {
67479 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
67480 int (*csp_stop) (struct snd_sb_csp * p);
67481 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
67482-};
67483+} __no_const;
67484
67485 /*
67486 * CSP private data
67487diff --git a/include/sound/soc.h b/include/sound/soc.h
67488index 91244a0..11c542e 100644
67489--- a/include/sound/soc.h
67490+++ b/include/sound/soc.h
67491@@ -769,7 +769,7 @@ struct snd_soc_codec_driver {
67492 /* probe ordering - for components with runtime dependencies */
67493 int probe_order;
67494 int remove_order;
67495-};
67496+} __do_const;
67497
67498 /* SoC platform interface */
67499 struct snd_soc_platform_driver {
67500@@ -815,7 +815,7 @@ struct snd_soc_platform_driver {
67501 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
67502 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
67503 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
67504-};
67505+} __do_const;
67506
67507 struct snd_soc_platform {
67508 const char *name;
67509@@ -1031,7 +1031,7 @@ struct snd_soc_pcm_runtime {
67510 struct snd_soc_dai_link *dai_link;
67511 struct mutex pcm_mutex;
67512 enum snd_soc_pcm_subclass pcm_subclass;
67513- struct snd_pcm_ops ops;
67514+ snd_pcm_ops_no_const ops;
67515
67516 unsigned int dev_registered:1;
67517
67518diff --git a/include/sound/tea575x-tuner.h b/include/sound/tea575x-tuner.h
67519index 098c4de..171054b 100644
67520--- a/include/sound/tea575x-tuner.h
67521+++ b/include/sound/tea575x-tuner.h
67522@@ -49,7 +49,7 @@ struct snd_tea575x_ops {
67523
67524 struct snd_tea575x {
67525 struct v4l2_device *v4l2_dev;
67526- struct v4l2_file_operations fops;
67527+ v4l2_file_operations_no_const fops;
67528 struct video_device vd; /* video device */
67529 int radio_nr; /* radio_nr */
67530 bool tea5759; /* 5759 chip is present */
67531diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
67532index 5be8937..a8e46e9 100644
67533--- a/include/target/target_core_base.h
67534+++ b/include/target/target_core_base.h
67535@@ -434,7 +434,7 @@ struct t10_reservation_ops {
67536 int (*t10_seq_non_holder)(struct se_cmd *, unsigned char *, u32);
67537 int (*t10_pr_register)(struct se_cmd *);
67538 int (*t10_pr_clear)(struct se_cmd *);
67539-};
67540+} __no_const;
67541
67542 struct t10_reservation {
67543 /* Reservation effects all target ports */
67544@@ -758,7 +758,7 @@ struct se_device {
67545 spinlock_t stats_lock;
67546 /* Active commands on this virtual SE device */
67547 atomic_t simple_cmds;
67548- atomic_t dev_ordered_id;
67549+ atomic_unchecked_t dev_ordered_id;
67550 atomic_t dev_ordered_sync;
67551 atomic_t dev_qf_count;
67552 struct se_obj dev_obj;
67553diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
67554new file mode 100644
67555index 0000000..fb634b7
67556--- /dev/null
67557+++ b/include/trace/events/fs.h
67558@@ -0,0 +1,53 @@
67559+#undef TRACE_SYSTEM
67560+#define TRACE_SYSTEM fs
67561+
67562+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
67563+#define _TRACE_FS_H
67564+
67565+#include <linux/fs.h>
67566+#include <linux/tracepoint.h>
67567+
67568+TRACE_EVENT(do_sys_open,
67569+
67570+ TP_PROTO(const char *filename, int flags, int mode),
67571+
67572+ TP_ARGS(filename, flags, mode),
67573+
67574+ TP_STRUCT__entry(
67575+ __string( filename, filename )
67576+ __field( int, flags )
67577+ __field( int, mode )
67578+ ),
67579+
67580+ TP_fast_assign(
67581+ __assign_str(filename, filename);
67582+ __entry->flags = flags;
67583+ __entry->mode = mode;
67584+ ),
67585+
67586+ TP_printk("\"%s\" %x %o",
67587+ __get_str(filename), __entry->flags, __entry->mode)
67588+);
67589+
67590+TRACE_EVENT(open_exec,
67591+
67592+ TP_PROTO(const char *filename),
67593+
67594+ TP_ARGS(filename),
67595+
67596+ TP_STRUCT__entry(
67597+ __string( filename, filename )
67598+ ),
67599+
67600+ TP_fast_assign(
67601+ __assign_str(filename, filename);
67602+ ),
67603+
67604+ TP_printk("\"%s\"",
67605+ __get_str(filename))
67606+);
67607+
67608+#endif /* _TRACE_FS_H */
67609+
67610+/* This part must be outside protection */
67611+#include <trace/define_trace.h>
67612diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
67613index 1c09820..7f5ec79 100644
67614--- a/include/trace/events/irq.h
67615+++ b/include/trace/events/irq.h
67616@@ -36,7 +36,7 @@ struct softirq_action;
67617 */
67618 TRACE_EVENT(irq_handler_entry,
67619
67620- TP_PROTO(int irq, struct irqaction *action),
67621+ TP_PROTO(int irq, const struct irqaction *action),
67622
67623 TP_ARGS(irq, action),
67624
67625@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
67626 */
67627 TRACE_EVENT(irq_handler_exit,
67628
67629- TP_PROTO(int irq, struct irqaction *action, int ret),
67630+ TP_PROTO(int irq, const struct irqaction *action, int ret),
67631
67632 TP_ARGS(irq, action, ret),
67633
67634diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
67635index 7caf44c..23c6f27 100644
67636--- a/include/uapi/linux/a.out.h
67637+++ b/include/uapi/linux/a.out.h
67638@@ -39,6 +39,14 @@ enum machine_type {
67639 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
67640 };
67641
67642+/* Constants for the N_FLAGS field */
67643+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
67644+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
67645+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
67646+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
67647+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
67648+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
67649+
67650 #if !defined (N_MAGIC)
67651 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
67652 #endif
67653diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
67654index d876736..b36014e 100644
67655--- a/include/uapi/linux/byteorder/little_endian.h
67656+++ b/include/uapi/linux/byteorder/little_endian.h
67657@@ -42,51 +42,51 @@
67658
67659 static inline __le64 __cpu_to_le64p(const __u64 *p)
67660 {
67661- return (__force __le64)*p;
67662+ return (__force const __le64)*p;
67663 }
67664 static inline __u64 __le64_to_cpup(const __le64 *p)
67665 {
67666- return (__force __u64)*p;
67667+ return (__force const __u64)*p;
67668 }
67669 static inline __le32 __cpu_to_le32p(const __u32 *p)
67670 {
67671- return (__force __le32)*p;
67672+ return (__force const __le32)*p;
67673 }
67674 static inline __u32 __le32_to_cpup(const __le32 *p)
67675 {
67676- return (__force __u32)*p;
67677+ return (__force const __u32)*p;
67678 }
67679 static inline __le16 __cpu_to_le16p(const __u16 *p)
67680 {
67681- return (__force __le16)*p;
67682+ return (__force const __le16)*p;
67683 }
67684 static inline __u16 __le16_to_cpup(const __le16 *p)
67685 {
67686- return (__force __u16)*p;
67687+ return (__force const __u16)*p;
67688 }
67689 static inline __be64 __cpu_to_be64p(const __u64 *p)
67690 {
67691- return (__force __be64)__swab64p(p);
67692+ return (__force const __be64)__swab64p(p);
67693 }
67694 static inline __u64 __be64_to_cpup(const __be64 *p)
67695 {
67696- return __swab64p((__u64 *)p);
67697+ return __swab64p((const __u64 *)p);
67698 }
67699 static inline __be32 __cpu_to_be32p(const __u32 *p)
67700 {
67701- return (__force __be32)__swab32p(p);
67702+ return (__force const __be32)__swab32p(p);
67703 }
67704 static inline __u32 __be32_to_cpup(const __be32 *p)
67705 {
67706- return __swab32p((__u32 *)p);
67707+ return __swab32p((const __u32 *)p);
67708 }
67709 static inline __be16 __cpu_to_be16p(const __u16 *p)
67710 {
67711- return (__force __be16)__swab16p(p);
67712+ return (__force const __be16)__swab16p(p);
67713 }
67714 static inline __u16 __be16_to_cpup(const __be16 *p)
67715 {
67716- return __swab16p((__u16 *)p);
67717+ return __swab16p((const __u16 *)p);
67718 }
67719 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
67720 #define __le64_to_cpus(x) do { (void)(x); } while (0)
67721diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
67722index 126a817..d522bd1 100644
67723--- a/include/uapi/linux/elf.h
67724+++ b/include/uapi/linux/elf.h
67725@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
67726 #define PT_GNU_EH_FRAME 0x6474e550
67727
67728 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
67729+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
67730+
67731+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
67732+
67733+/* Constants for the e_flags field */
67734+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
67735+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
67736+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
67737+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
67738+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
67739+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
67740
67741 /*
67742 * Extended Numbering
67743@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
67744 #define DT_DEBUG 21
67745 #define DT_TEXTREL 22
67746 #define DT_JMPREL 23
67747+#define DT_FLAGS 30
67748+ #define DF_TEXTREL 0x00000004
67749 #define DT_ENCODING 32
67750 #define OLD_DT_LOOS 0x60000000
67751 #define DT_LOOS 0x6000000d
67752@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
67753 #define PF_W 0x2
67754 #define PF_X 0x1
67755
67756+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
67757+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
67758+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
67759+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
67760+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
67761+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
67762+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
67763+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
67764+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
67765+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
67766+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
67767+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
67768+
67769 typedef struct elf32_phdr{
67770 Elf32_Word p_type;
67771 Elf32_Off p_offset;
67772@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
67773 #define EI_OSABI 7
67774 #define EI_PAD 8
67775
67776+#define EI_PAX 14
67777+
67778 #define ELFMAG0 0x7f /* EI_MAG */
67779 #define ELFMAG1 'E'
67780 #define ELFMAG2 'L'
67781diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
67782index aa169c4..6a2771d 100644
67783--- a/include/uapi/linux/personality.h
67784+++ b/include/uapi/linux/personality.h
67785@@ -30,6 +30,7 @@ enum {
67786 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
67787 ADDR_NO_RANDOMIZE | \
67788 ADDR_COMPAT_LAYOUT | \
67789+ ADDR_LIMIT_3GB | \
67790 MMAP_PAGE_ZERO)
67791
67792 /*
67793diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
67794index 7530e74..e714828 100644
67795--- a/include/uapi/linux/screen_info.h
67796+++ b/include/uapi/linux/screen_info.h
67797@@ -43,7 +43,8 @@ struct screen_info {
67798 __u16 pages; /* 0x32 */
67799 __u16 vesa_attributes; /* 0x34 */
67800 __u32 capabilities; /* 0x36 */
67801- __u8 _reserved[6]; /* 0x3a */
67802+ __u16 vesapm_size; /* 0x3a */
67803+ __u8 _reserved[4]; /* 0x3c */
67804 } __attribute__((packed));
67805
67806 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
67807diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
67808index 6d67213..8dab561 100644
67809--- a/include/uapi/linux/sysctl.h
67810+++ b/include/uapi/linux/sysctl.h
67811@@ -155,7 +155,11 @@ enum
67812 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
67813 };
67814
67815-
67816+#ifdef CONFIG_PAX_SOFTMODE
67817+enum {
67818+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
67819+};
67820+#endif
67821
67822 /* CTL_VM names: */
67823 enum
67824diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
67825index 26607bd..588b65f 100644
67826--- a/include/uapi/linux/xattr.h
67827+++ b/include/uapi/linux/xattr.h
67828@@ -60,5 +60,9 @@
67829 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
67830 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
67831
67832+/* User namespace */
67833+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
67834+#define XATTR_PAX_FLAGS_SUFFIX "flags"
67835+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
67836
67837 #endif /* _UAPI_LINUX_XATTR_H */
67838diff --git a/include/video/omapdss.h b/include/video/omapdss.h
67839index 3729173..7b2df7e 100644
67840--- a/include/video/omapdss.h
67841+++ b/include/video/omapdss.h
67842@@ -323,7 +323,7 @@ struct omap_dss_board_info {
67843 int (*dsi_enable_pads)(int dsi_id, unsigned lane_mask);
67844 void (*dsi_disable_pads)(int dsi_id, unsigned lane_mask);
67845 int (*set_min_bus_tput)(struct device *dev, unsigned long r);
67846-};
67847+} __do_const;
67848
67849 /* Init with the board info */
67850 extern int omap_display_init(struct omap_dss_board_info *board_data);
67851diff --git a/include/video/udlfb.h b/include/video/udlfb.h
67852index f9466fa..f4e2b81 100644
67853--- a/include/video/udlfb.h
67854+++ b/include/video/udlfb.h
67855@@ -53,10 +53,10 @@ struct dlfb_data {
67856 u32 pseudo_palette[256];
67857 int blank_mode; /*one of FB_BLANK_ */
67858 /* blit-only rendering path metrics, exposed through sysfs */
67859- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
67860- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
67861- atomic_t bytes_sent; /* to usb, after compression including overhead */
67862- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
67863+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
67864+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
67865+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
67866+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
67867 };
67868
67869 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
67870diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
67871index 0993a22..32ba2fe 100644
67872--- a/include/video/uvesafb.h
67873+++ b/include/video/uvesafb.h
67874@@ -177,6 +177,7 @@ struct uvesafb_par {
67875 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
67876 u8 pmi_setpal; /* PMI for palette changes */
67877 u16 *pmi_base; /* protected mode interface location */
67878+ u8 *pmi_code; /* protected mode code location */
67879 void *pmi_start;
67880 void *pmi_pal;
67881 u8 *vbe_state_orig; /*
67882diff --git a/init/Kconfig b/init/Kconfig
67883index 6fdd6e3..5b01610 100644
67884--- a/init/Kconfig
67885+++ b/init/Kconfig
67886@@ -925,6 +925,7 @@ endif # CGROUPS
67887
67888 config CHECKPOINT_RESTORE
67889 bool "Checkpoint/restore support" if EXPERT
67890+ depends on !GRKERNSEC
67891 default n
67892 help
67893 Enables additional kernel features in a sake of checkpoint/restore.
67894@@ -1016,6 +1017,8 @@ config UIDGID_CONVERTED
67895 depends on OCFS2_FS = n
67896 depends on XFS_FS = n
67897
67898+ depends on GRKERNSEC = n
67899+
67900 config UIDGID_STRICT_TYPE_CHECKS
67901 bool "Require conversions between uid/gids and their internal representation"
67902 depends on UIDGID_CONVERTED
67903@@ -1405,7 +1408,7 @@ config SLUB_DEBUG
67904
67905 config COMPAT_BRK
67906 bool "Disable heap randomization"
67907- default y
67908+ default n
67909 help
67910 Randomizing heap placement makes heap exploits harder, but it
67911 also breaks ancient binaries (including anything libc5 based).
67912@@ -1648,7 +1651,7 @@ config INIT_ALL_POSSIBLE
67913 config STOP_MACHINE
67914 bool
67915 default y
67916- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
67917+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
67918 help
67919 Need stop_machine() primitive.
67920
67921diff --git a/init/Makefile b/init/Makefile
67922index 7bc47ee..6da2dc7 100644
67923--- a/init/Makefile
67924+++ b/init/Makefile
67925@@ -2,6 +2,9 @@
67926 # Makefile for the linux kernel.
67927 #
67928
67929+ccflags-y := $(GCC_PLUGINS_CFLAGS)
67930+asflags-y := $(GCC_PLUGINS_AFLAGS)
67931+
67932 obj-y := main.o version.o mounts.o
67933 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
67934 obj-y += noinitramfs.o
67935diff --git a/init/do_mounts.c b/init/do_mounts.c
67936index f8a6642..4e5ee1b 100644
67937--- a/init/do_mounts.c
67938+++ b/init/do_mounts.c
67939@@ -336,11 +336,11 @@ static void __init get_fs_names(char *page)
67940 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
67941 {
67942 struct super_block *s;
67943- int err = sys_mount(name, "/root", fs, flags, data);
67944+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
67945 if (err)
67946 return err;
67947
67948- sys_chdir("/root");
67949+ sys_chdir((const char __force_user *)"/root");
67950 s = current->fs->pwd.dentry->d_sb;
67951 ROOT_DEV = s->s_dev;
67952 printk(KERN_INFO
67953@@ -461,18 +461,18 @@ void __init change_floppy(char *fmt, ...)
67954 va_start(args, fmt);
67955 vsprintf(buf, fmt, args);
67956 va_end(args);
67957- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
67958+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
67959 if (fd >= 0) {
67960 sys_ioctl(fd, FDEJECT, 0);
67961 sys_close(fd);
67962 }
67963 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
67964- fd = sys_open("/dev/console", O_RDWR, 0);
67965+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
67966 if (fd >= 0) {
67967 sys_ioctl(fd, TCGETS, (long)&termios);
67968 termios.c_lflag &= ~ICANON;
67969 sys_ioctl(fd, TCSETSF, (long)&termios);
67970- sys_read(fd, &c, 1);
67971+ sys_read(fd, (char __user *)&c, 1);
67972 termios.c_lflag |= ICANON;
67973 sys_ioctl(fd, TCSETSF, (long)&termios);
67974 sys_close(fd);
67975@@ -566,6 +566,6 @@ void __init prepare_namespace(void)
67976 mount_root();
67977 out:
67978 devtmpfs_mount("dev");
67979- sys_mount(".", "/", NULL, MS_MOVE, NULL);
67980- sys_chroot(".");
67981+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
67982+ sys_chroot((const char __force_user *)".");
67983 }
67984diff --git a/init/do_mounts.h b/init/do_mounts.h
67985index f5b978a..69dbfe8 100644
67986--- a/init/do_mounts.h
67987+++ b/init/do_mounts.h
67988@@ -15,15 +15,15 @@ extern int root_mountflags;
67989
67990 static inline int create_dev(char *name, dev_t dev)
67991 {
67992- sys_unlink(name);
67993- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
67994+ sys_unlink((char __force_user *)name);
67995+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
67996 }
67997
67998 #if BITS_PER_LONG == 32
67999 static inline u32 bstat(char *name)
68000 {
68001 struct stat64 stat;
68002- if (sys_stat64(name, &stat) != 0)
68003+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
68004 return 0;
68005 if (!S_ISBLK(stat.st_mode))
68006 return 0;
68007@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
68008 static inline u32 bstat(char *name)
68009 {
68010 struct stat stat;
68011- if (sys_newstat(name, &stat) != 0)
68012+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
68013 return 0;
68014 if (!S_ISBLK(stat.st_mode))
68015 return 0;
68016diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
68017index 5e4ded5..aa3cd7e 100644
68018--- a/init/do_mounts_initrd.c
68019+++ b/init/do_mounts_initrd.c
68020@@ -54,8 +54,8 @@ static void __init handle_initrd(void)
68021 create_dev("/dev/root.old", Root_RAM0);
68022 /* mount initrd on rootfs' /root */
68023 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
68024- sys_mkdir("/old", 0700);
68025- sys_chdir("/old");
68026+ sys_mkdir((const char __force_user *)"/old", 0700);
68027+ sys_chdir((const char __force_user *)"/old");
68028
68029 /*
68030 * In case that a resume from disk is carried out by linuxrc or one of
68031@@ -69,31 +69,31 @@ static void __init handle_initrd(void)
68032 current->flags &= ~PF_FREEZER_SKIP;
68033
68034 /* move initrd to rootfs' /old */
68035- sys_mount("..", ".", NULL, MS_MOVE, NULL);
68036+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
68037 /* switch root and cwd back to / of rootfs */
68038- sys_chroot("..");
68039+ sys_chroot((const char __force_user *)"..");
68040
68041 if (new_decode_dev(real_root_dev) == Root_RAM0) {
68042- sys_chdir("/old");
68043+ sys_chdir((const char __force_user *)"/old");
68044 return;
68045 }
68046
68047- sys_chdir("/");
68048+ sys_chdir((const char __force_user *)"/");
68049 ROOT_DEV = new_decode_dev(real_root_dev);
68050 mount_root();
68051
68052 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
68053- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
68054+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
68055 if (!error)
68056 printk("okay\n");
68057 else {
68058- int fd = sys_open("/dev/root.old", O_RDWR, 0);
68059+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
68060 if (error == -ENOENT)
68061 printk("/initrd does not exist. Ignored.\n");
68062 else
68063 printk("failed\n");
68064 printk(KERN_NOTICE "Unmounting old root\n");
68065- sys_umount("/old", MNT_DETACH);
68066+ sys_umount((char __force_user *)"/old", MNT_DETACH);
68067 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
68068 if (fd < 0) {
68069 error = fd;
68070@@ -116,11 +116,11 @@ int __init initrd_load(void)
68071 * mounted in the normal path.
68072 */
68073 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
68074- sys_unlink("/initrd.image");
68075+ sys_unlink((const char __force_user *)"/initrd.image");
68076 handle_initrd();
68077 return 1;
68078 }
68079 }
68080- sys_unlink("/initrd.image");
68081+ sys_unlink((const char __force_user *)"/initrd.image");
68082 return 0;
68083 }
68084diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
68085index 8cb6db5..d729f50 100644
68086--- a/init/do_mounts_md.c
68087+++ b/init/do_mounts_md.c
68088@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
68089 partitioned ? "_d" : "", minor,
68090 md_setup_args[ent].device_names);
68091
68092- fd = sys_open(name, 0, 0);
68093+ fd = sys_open((char __force_user *)name, 0, 0);
68094 if (fd < 0) {
68095 printk(KERN_ERR "md: open failed - cannot start "
68096 "array %s\n", name);
68097@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
68098 * array without it
68099 */
68100 sys_close(fd);
68101- fd = sys_open(name, 0, 0);
68102+ fd = sys_open((char __force_user *)name, 0, 0);
68103 sys_ioctl(fd, BLKRRPART, 0);
68104 }
68105 sys_close(fd);
68106@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
68107
68108 wait_for_device_probe();
68109
68110- fd = sys_open("/dev/md0", 0, 0);
68111+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
68112 if (fd >= 0) {
68113 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
68114 sys_close(fd);
68115diff --git a/init/init_task.c b/init/init_task.c
68116index 8b2f399..f0797c9 100644
68117--- a/init/init_task.c
68118+++ b/init/init_task.c
68119@@ -20,5 +20,9 @@ EXPORT_SYMBOL(init_task);
68120 * Initial thread structure. Alignment of this is handled by a special
68121 * linker map entry.
68122 */
68123+#ifdef CONFIG_X86
68124+union thread_union init_thread_union __init_task_data;
68125+#else
68126 union thread_union init_thread_union __init_task_data =
68127 { INIT_THREAD_INFO(init_task) };
68128+#endif
68129diff --git a/init/initramfs.c b/init/initramfs.c
68130index 84c6bf1..8899338 100644
68131--- a/init/initramfs.c
68132+++ b/init/initramfs.c
68133@@ -84,7 +84,7 @@ static void __init free_hash(void)
68134 }
68135 }
68136
68137-static long __init do_utime(char *filename, time_t mtime)
68138+static long __init do_utime(char __force_user *filename, time_t mtime)
68139 {
68140 struct timespec t[2];
68141
68142@@ -119,7 +119,7 @@ static void __init dir_utime(void)
68143 struct dir_entry *de, *tmp;
68144 list_for_each_entry_safe(de, tmp, &dir_list, list) {
68145 list_del(&de->list);
68146- do_utime(de->name, de->mtime);
68147+ do_utime((char __force_user *)de->name, de->mtime);
68148 kfree(de->name);
68149 kfree(de);
68150 }
68151@@ -281,7 +281,7 @@ static int __init maybe_link(void)
68152 if (nlink >= 2) {
68153 char *old = find_link(major, minor, ino, mode, collected);
68154 if (old)
68155- return (sys_link(old, collected) < 0) ? -1 : 1;
68156+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
68157 }
68158 return 0;
68159 }
68160@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
68161 {
68162 struct stat st;
68163
68164- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
68165+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
68166 if (S_ISDIR(st.st_mode))
68167- sys_rmdir(path);
68168+ sys_rmdir((char __force_user *)path);
68169 else
68170- sys_unlink(path);
68171+ sys_unlink((char __force_user *)path);
68172 }
68173 }
68174
68175@@ -315,7 +315,7 @@ static int __init do_name(void)
68176 int openflags = O_WRONLY|O_CREAT;
68177 if (ml != 1)
68178 openflags |= O_TRUNC;
68179- wfd = sys_open(collected, openflags, mode);
68180+ wfd = sys_open((char __force_user *)collected, openflags, mode);
68181
68182 if (wfd >= 0) {
68183 sys_fchown(wfd, uid, gid);
68184@@ -327,17 +327,17 @@ static int __init do_name(void)
68185 }
68186 }
68187 } else if (S_ISDIR(mode)) {
68188- sys_mkdir(collected, mode);
68189- sys_chown(collected, uid, gid);
68190- sys_chmod(collected, mode);
68191+ sys_mkdir((char __force_user *)collected, mode);
68192+ sys_chown((char __force_user *)collected, uid, gid);
68193+ sys_chmod((char __force_user *)collected, mode);
68194 dir_add(collected, mtime);
68195 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
68196 S_ISFIFO(mode) || S_ISSOCK(mode)) {
68197 if (maybe_link() == 0) {
68198- sys_mknod(collected, mode, rdev);
68199- sys_chown(collected, uid, gid);
68200- sys_chmod(collected, mode);
68201- do_utime(collected, mtime);
68202+ sys_mknod((char __force_user *)collected, mode, rdev);
68203+ sys_chown((char __force_user *)collected, uid, gid);
68204+ sys_chmod((char __force_user *)collected, mode);
68205+ do_utime((char __force_user *)collected, mtime);
68206 }
68207 }
68208 return 0;
68209@@ -346,15 +346,15 @@ static int __init do_name(void)
68210 static int __init do_copy(void)
68211 {
68212 if (count >= body_len) {
68213- sys_write(wfd, victim, body_len);
68214+ sys_write(wfd, (char __force_user *)victim, body_len);
68215 sys_close(wfd);
68216- do_utime(vcollected, mtime);
68217+ do_utime((char __force_user *)vcollected, mtime);
68218 kfree(vcollected);
68219 eat(body_len);
68220 state = SkipIt;
68221 return 0;
68222 } else {
68223- sys_write(wfd, victim, count);
68224+ sys_write(wfd, (char __force_user *)victim, count);
68225 body_len -= count;
68226 eat(count);
68227 return 1;
68228@@ -365,9 +365,9 @@ static int __init do_symlink(void)
68229 {
68230 collected[N_ALIGN(name_len) + body_len] = '\0';
68231 clean_path(collected, 0);
68232- sys_symlink(collected + N_ALIGN(name_len), collected);
68233- sys_lchown(collected, uid, gid);
68234- do_utime(collected, mtime);
68235+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
68236+ sys_lchown((char __force_user *)collected, uid, gid);
68237+ do_utime((char __force_user *)collected, mtime);
68238 state = SkipIt;
68239 next_state = Reset;
68240 return 0;
68241diff --git a/init/main.c b/init/main.c
68242index e33e09d..b699703 100644
68243--- a/init/main.c
68244+++ b/init/main.c
68245@@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
68246 extern void tc_init(void);
68247 #endif
68248
68249+extern void grsecurity_init(void);
68250+
68251 /*
68252 * Debug helper: via this flag we know that we are in 'early bootup code'
68253 * where only the boot processor is running with IRQ disabled. This means
68254@@ -149,6 +151,61 @@ static int __init set_reset_devices(char *str)
68255
68256 __setup("reset_devices", set_reset_devices);
68257
68258+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
68259+int grsec_proc_gid = CONFIG_GRKERNSEC_PROC_GID;
68260+static int __init setup_grsec_proc_gid(char *str)
68261+{
68262+ grsec_proc_gid = (int)simple_strtol(str, NULL, 0);
68263+ return 1;
68264+}
68265+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
68266+#endif
68267+
68268+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
68269+extern char pax_enter_kernel_user[];
68270+extern char pax_exit_kernel_user[];
68271+extern pgdval_t clone_pgd_mask;
68272+#endif
68273+
68274+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
68275+static int __init setup_pax_nouderef(char *str)
68276+{
68277+#ifdef CONFIG_X86_32
68278+ unsigned int cpu;
68279+ struct desc_struct *gdt;
68280+
68281+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
68282+ gdt = get_cpu_gdt_table(cpu);
68283+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
68284+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
68285+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
68286+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
68287+ }
68288+ loadsegment(ds, __KERNEL_DS);
68289+ loadsegment(es, __KERNEL_DS);
68290+ loadsegment(ss, __KERNEL_DS);
68291+#else
68292+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
68293+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
68294+ clone_pgd_mask = ~(pgdval_t)0UL;
68295+#endif
68296+
68297+ return 0;
68298+}
68299+early_param("pax_nouderef", setup_pax_nouderef);
68300+#endif
68301+
68302+#ifdef CONFIG_PAX_SOFTMODE
68303+int pax_softmode;
68304+
68305+static int __init setup_pax_softmode(char *str)
68306+{
68307+ get_option(&str, &pax_softmode);
68308+ return 1;
68309+}
68310+__setup("pax_softmode=", setup_pax_softmode);
68311+#endif
68312+
68313 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
68314 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
68315 static const char *panic_later, *panic_param;
68316@@ -681,6 +738,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
68317 {
68318 int count = preempt_count();
68319 int ret;
68320+ const char *msg1 = "", *msg2 = "";
68321
68322 if (initcall_debug)
68323 ret = do_one_initcall_debug(fn);
68324@@ -693,15 +751,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
68325 sprintf(msgbuf, "error code %d ", ret);
68326
68327 if (preempt_count() != count) {
68328- strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
68329+ msg1 = " preemption imbalance";
68330 preempt_count() = count;
68331 }
68332 if (irqs_disabled()) {
68333- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
68334+ msg2 = " disabled interrupts";
68335 local_irq_enable();
68336 }
68337- if (msgbuf[0]) {
68338- printk("initcall %pF returned with %s\n", fn, msgbuf);
68339+ if (msgbuf[0] || *msg1 || *msg2) {
68340+ printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
68341 }
68342
68343 return ret;
68344@@ -743,6 +801,10 @@ static char *initcall_level_names[] __initdata = {
68345 "late",
68346 };
68347
68348+#ifdef CONFIG_PAX_LATENT_ENTROPY
68349+u64 latent_entropy;
68350+#endif
68351+
68352 static void __init do_initcall_level(int level)
68353 {
68354 extern const struct kernel_param __start___param[], __stop___param[];
68355@@ -755,8 +817,14 @@ static void __init do_initcall_level(int level)
68356 level, level,
68357 &repair_env_string);
68358
68359- for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
68360+ for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
68361 do_one_initcall(*fn);
68362+
68363+#ifdef CONFIG_PAX_LATENT_ENTROPY
68364+ add_device_randomness(&latent_entropy, sizeof(latent_entropy));
68365+#endif
68366+
68367+ }
68368 }
68369
68370 static void __init do_initcalls(void)
68371@@ -790,8 +858,14 @@ static void __init do_pre_smp_initcalls(void)
68372 {
68373 initcall_t *fn;
68374
68375- for (fn = __initcall_start; fn < __initcall0_start; fn++)
68376+ for (fn = __initcall_start; fn < __initcall0_start; fn++) {
68377 do_one_initcall(*fn);
68378+
68379+#ifdef CONFIG_PAX_LATENT_ENTROPY
68380+ add_device_randomness(&latent_entropy, sizeof(latent_entropy));
68381+#endif
68382+
68383+ }
68384 }
68385
68386 static int run_init_process(const char *init_filename)
68387@@ -876,7 +950,7 @@ static void __init kernel_init_freeable(void)
68388 do_basic_setup();
68389
68390 /* Open the /dev/console on the rootfs, this should never fail */
68391- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
68392+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
68393 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
68394
68395 (void) sys_dup(0);
68396@@ -889,11 +963,13 @@ static void __init kernel_init_freeable(void)
68397 if (!ramdisk_execute_command)
68398 ramdisk_execute_command = "/init";
68399
68400- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
68401+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
68402 ramdisk_execute_command = NULL;
68403 prepare_namespace();
68404 }
68405
68406+ grsecurity_init();
68407+
68408 /*
68409 * Ok, we have completed the initial bootup, and
68410 * we're essentially up and running. Get rid of the
68411diff --git a/ipc/mqueue.c b/ipc/mqueue.c
68412index 71a3ca1..cc330ee 100644
68413--- a/ipc/mqueue.c
68414+++ b/ipc/mqueue.c
68415@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
68416 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
68417 info->attr.mq_msgsize);
68418
68419+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
68420 spin_lock(&mq_lock);
68421 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
68422 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
68423diff --git a/ipc/msg.c b/ipc/msg.c
68424index a71af5a..a90a110 100644
68425--- a/ipc/msg.c
68426+++ b/ipc/msg.c
68427@@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
68428 return security_msg_queue_associate(msq, msgflg);
68429 }
68430
68431+static struct ipc_ops msg_ops = {
68432+ .getnew = newque,
68433+ .associate = msg_security,
68434+ .more_checks = NULL
68435+};
68436+
68437 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
68438 {
68439 struct ipc_namespace *ns;
68440- struct ipc_ops msg_ops;
68441 struct ipc_params msg_params;
68442
68443 ns = current->nsproxy->ipc_ns;
68444
68445- msg_ops.getnew = newque;
68446- msg_ops.associate = msg_security;
68447- msg_ops.more_checks = NULL;
68448-
68449 msg_params.key = key;
68450 msg_params.flg = msgflg;
68451
68452diff --git a/ipc/sem.c b/ipc/sem.c
68453index 58d31f1..cce7a55 100644
68454--- a/ipc/sem.c
68455+++ b/ipc/sem.c
68456@@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
68457 return 0;
68458 }
68459
68460+static struct ipc_ops sem_ops = {
68461+ .getnew = newary,
68462+ .associate = sem_security,
68463+ .more_checks = sem_more_checks
68464+};
68465+
68466 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
68467 {
68468 struct ipc_namespace *ns;
68469- struct ipc_ops sem_ops;
68470 struct ipc_params sem_params;
68471
68472 ns = current->nsproxy->ipc_ns;
68473@@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
68474 if (nsems < 0 || nsems > ns->sc_semmsl)
68475 return -EINVAL;
68476
68477- sem_ops.getnew = newary;
68478- sem_ops.associate = sem_security;
68479- sem_ops.more_checks = sem_more_checks;
68480-
68481 sem_params.key = key;
68482 sem_params.flg = semflg;
68483 sem_params.u.nsems = nsems;
68484diff --git a/ipc/shm.c b/ipc/shm.c
68485index dff40c9..9450e27 100644
68486--- a/ipc/shm.c
68487+++ b/ipc/shm.c
68488@@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
68489 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
68490 #endif
68491
68492+#ifdef CONFIG_GRKERNSEC
68493+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
68494+ const time_t shm_createtime, const uid_t cuid,
68495+ const int shmid);
68496+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
68497+ const time_t shm_createtime);
68498+#endif
68499+
68500 void shm_init_ns(struct ipc_namespace *ns)
68501 {
68502 ns->shm_ctlmax = SHMMAX;
68503@@ -520,6 +528,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
68504 shp->shm_lprid = 0;
68505 shp->shm_atim = shp->shm_dtim = 0;
68506 shp->shm_ctim = get_seconds();
68507+#ifdef CONFIG_GRKERNSEC
68508+ {
68509+ struct timespec timeval;
68510+ do_posix_clock_monotonic_gettime(&timeval);
68511+
68512+ shp->shm_createtime = timeval.tv_sec;
68513+ }
68514+#endif
68515 shp->shm_segsz = size;
68516 shp->shm_nattch = 0;
68517 shp->shm_file = file;
68518@@ -571,18 +587,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
68519 return 0;
68520 }
68521
68522+static struct ipc_ops shm_ops = {
68523+ .getnew = newseg,
68524+ .associate = shm_security,
68525+ .more_checks = shm_more_checks
68526+};
68527+
68528 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
68529 {
68530 struct ipc_namespace *ns;
68531- struct ipc_ops shm_ops;
68532 struct ipc_params shm_params;
68533
68534 ns = current->nsproxy->ipc_ns;
68535
68536- shm_ops.getnew = newseg;
68537- shm_ops.associate = shm_security;
68538- shm_ops.more_checks = shm_more_checks;
68539-
68540 shm_params.key = key;
68541 shm_params.flg = shmflg;
68542 shm_params.u.size = size;
68543@@ -1003,6 +1020,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
68544 f_mode = FMODE_READ | FMODE_WRITE;
68545 }
68546 if (shmflg & SHM_EXEC) {
68547+
68548+#ifdef CONFIG_PAX_MPROTECT
68549+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
68550+ goto out;
68551+#endif
68552+
68553 prot |= PROT_EXEC;
68554 acc_mode |= S_IXUGO;
68555 }
68556@@ -1026,9 +1049,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
68557 if (err)
68558 goto out_unlock;
68559
68560+#ifdef CONFIG_GRKERNSEC
68561+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
68562+ shp->shm_perm.cuid, shmid) ||
68563+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
68564+ err = -EACCES;
68565+ goto out_unlock;
68566+ }
68567+#endif
68568+
68569 path = shp->shm_file->f_path;
68570 path_get(&path);
68571 shp->shm_nattch++;
68572+#ifdef CONFIG_GRKERNSEC
68573+ shp->shm_lapid = current->pid;
68574+#endif
68575 size = i_size_read(path.dentry->d_inode);
68576 shm_unlock(shp);
68577
68578diff --git a/kernel/acct.c b/kernel/acct.c
68579index 051e071..15e0920 100644
68580--- a/kernel/acct.c
68581+++ b/kernel/acct.c
68582@@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
68583 */
68584 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
68585 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
68586- file->f_op->write(file, (char *)&ac,
68587+ file->f_op->write(file, (char __force_user *)&ac,
68588 sizeof(acct_t), &file->f_pos);
68589 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
68590 set_fs(fs);
68591diff --git a/kernel/audit.c b/kernel/audit.c
68592index 40414e9..c920b72 100644
68593--- a/kernel/audit.c
68594+++ b/kernel/audit.c
68595@@ -116,7 +116,7 @@ u32 audit_sig_sid = 0;
68596 3) suppressed due to audit_rate_limit
68597 4) suppressed due to audit_backlog_limit
68598 */
68599-static atomic_t audit_lost = ATOMIC_INIT(0);
68600+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
68601
68602 /* The netlink socket. */
68603 static struct sock *audit_sock;
68604@@ -238,7 +238,7 @@ void audit_log_lost(const char *message)
68605 unsigned long now;
68606 int print;
68607
68608- atomic_inc(&audit_lost);
68609+ atomic_inc_unchecked(&audit_lost);
68610
68611 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
68612
68613@@ -257,7 +257,7 @@ void audit_log_lost(const char *message)
68614 printk(KERN_WARNING
68615 "audit: audit_lost=%d audit_rate_limit=%d "
68616 "audit_backlog_limit=%d\n",
68617- atomic_read(&audit_lost),
68618+ atomic_read_unchecked(&audit_lost),
68619 audit_rate_limit,
68620 audit_backlog_limit);
68621 audit_panic(message);
68622@@ -677,7 +677,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
68623 status_set.pid = audit_pid;
68624 status_set.rate_limit = audit_rate_limit;
68625 status_set.backlog_limit = audit_backlog_limit;
68626- status_set.lost = atomic_read(&audit_lost);
68627+ status_set.lost = atomic_read_unchecked(&audit_lost);
68628 status_set.backlog = skb_queue_len(&audit_skb_queue);
68629 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
68630 &status_set, sizeof(status_set));
68631diff --git a/kernel/auditsc.c b/kernel/auditsc.c
68632index 2f186ed..afb42c2 100644
68633--- a/kernel/auditsc.c
68634+++ b/kernel/auditsc.c
68635@@ -2352,7 +2352,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
68636 }
68637
68638 /* global counter which is incremented every time something logs in */
68639-static atomic_t session_id = ATOMIC_INIT(0);
68640+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
68641
68642 /**
68643 * audit_set_loginuid - set current task's audit_context loginuid
68644@@ -2376,7 +2376,7 @@ int audit_set_loginuid(kuid_t loginuid)
68645 return -EPERM;
68646 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
68647
68648- sessionid = atomic_inc_return(&session_id);
68649+ sessionid = atomic_inc_return_unchecked(&session_id);
68650 if (context && context->in_syscall) {
68651 struct audit_buffer *ab;
68652
68653diff --git a/kernel/capability.c b/kernel/capability.c
68654index 493d972..ea17248 100644
68655--- a/kernel/capability.c
68656+++ b/kernel/capability.c
68657@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
68658 * before modification is attempted and the application
68659 * fails.
68660 */
68661+ if (tocopy > ARRAY_SIZE(kdata))
68662+ return -EFAULT;
68663+
68664 if (copy_to_user(dataptr, kdata, tocopy
68665 * sizeof(struct __user_cap_data_struct))) {
68666 return -EFAULT;
68667@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
68668 int ret;
68669
68670 rcu_read_lock();
68671- ret = security_capable(__task_cred(t), ns, cap);
68672+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
68673+ gr_task_is_capable(t, __task_cred(t), cap);
68674 rcu_read_unlock();
68675
68676- return (ret == 0);
68677+ return ret;
68678 }
68679
68680 /**
68681@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
68682 int ret;
68683
68684 rcu_read_lock();
68685- ret = security_capable_noaudit(__task_cred(t), ns, cap);
68686+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
68687 rcu_read_unlock();
68688
68689- return (ret == 0);
68690+ return ret;
68691 }
68692
68693 /**
68694@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
68695 BUG();
68696 }
68697
68698- if (security_capable(current_cred(), ns, cap) == 0) {
68699+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
68700 current->flags |= PF_SUPERPRIV;
68701 return true;
68702 }
68703@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
68704 }
68705 EXPORT_SYMBOL(ns_capable);
68706
68707+bool ns_capable_nolog(struct user_namespace *ns, int cap)
68708+{
68709+ if (unlikely(!cap_valid(cap))) {
68710+ printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
68711+ BUG();
68712+ }
68713+
68714+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
68715+ current->flags |= PF_SUPERPRIV;
68716+ return true;
68717+ }
68718+ return false;
68719+}
68720+EXPORT_SYMBOL(ns_capable_nolog);
68721+
68722 /**
68723 * capable - Determine if the current task has a superior capability in effect
68724 * @cap: The capability to be tested for
68725@@ -408,6 +427,12 @@ bool capable(int cap)
68726 }
68727 EXPORT_SYMBOL(capable);
68728
68729+bool capable_nolog(int cap)
68730+{
68731+ return ns_capable_nolog(&init_user_ns, cap);
68732+}
68733+EXPORT_SYMBOL(capable_nolog);
68734+
68735 /**
68736 * nsown_capable - Check superior capability to one's own user_ns
68737 * @cap: The capability in question
68738@@ -440,3 +465,10 @@ bool inode_capable(const struct inode *inode, int cap)
68739
68740 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
68741 }
68742+
68743+bool inode_capable_nolog(const struct inode *inode, int cap)
68744+{
68745+ struct user_namespace *ns = current_user_ns();
68746+
68747+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
68748+}
68749diff --git a/kernel/cgroup.c b/kernel/cgroup.c
68750index f24f724..0612ec45 100644
68751--- a/kernel/cgroup.c
68752+++ b/kernel/cgroup.c
68753@@ -5518,7 +5518,7 @@ static int cgroup_css_links_read(struct cgroup *cont,
68754 struct css_set *cg = link->cg;
68755 struct task_struct *task;
68756 int count = 0;
68757- seq_printf(seq, "css_set %p\n", cg);
68758+ seq_printf(seq, "css_set %pK\n", cg);
68759 list_for_each_entry(task, &cg->tasks, cg_list) {
68760 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
68761 seq_puts(seq, " ...\n");
68762diff --git a/kernel/compat.c b/kernel/compat.c
68763index c28a306..b4d0cf3 100644
68764--- a/kernel/compat.c
68765+++ b/kernel/compat.c
68766@@ -13,6 +13,7 @@
68767
68768 #include <linux/linkage.h>
68769 #include <linux/compat.h>
68770+#include <linux/module.h>
68771 #include <linux/errno.h>
68772 #include <linux/time.h>
68773 #include <linux/signal.h>
68774@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
68775 mm_segment_t oldfs;
68776 long ret;
68777
68778- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
68779+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
68780 oldfs = get_fs();
68781 set_fs(KERNEL_DS);
68782 ret = hrtimer_nanosleep_restart(restart);
68783@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
68784 oldfs = get_fs();
68785 set_fs(KERNEL_DS);
68786 ret = hrtimer_nanosleep(&tu,
68787- rmtp ? (struct timespec __user *)&rmt : NULL,
68788+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
68789 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
68790 set_fs(oldfs);
68791
68792@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
68793 mm_segment_t old_fs = get_fs();
68794
68795 set_fs(KERNEL_DS);
68796- ret = sys_sigpending((old_sigset_t __user *) &s);
68797+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
68798 set_fs(old_fs);
68799 if (ret == 0)
68800 ret = put_user(s, set);
68801@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
68802 mm_segment_t old_fs = get_fs();
68803
68804 set_fs(KERNEL_DS);
68805- ret = sys_old_getrlimit(resource, &r);
68806+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
68807 set_fs(old_fs);
68808
68809 if (!ret) {
68810@@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
68811 mm_segment_t old_fs = get_fs();
68812
68813 set_fs(KERNEL_DS);
68814- ret = sys_getrusage(who, (struct rusage __user *) &r);
68815+ ret = sys_getrusage(who, (struct rusage __force_user *) &r);
68816 set_fs(old_fs);
68817
68818 if (ret)
68819@@ -550,8 +551,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
68820 set_fs (KERNEL_DS);
68821 ret = sys_wait4(pid,
68822 (stat_addr ?
68823- (unsigned int __user *) &status : NULL),
68824- options, (struct rusage __user *) &r);
68825+ (unsigned int __force_user *) &status : NULL),
68826+ options, (struct rusage __force_user *) &r);
68827 set_fs (old_fs);
68828
68829 if (ret > 0) {
68830@@ -576,8 +577,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
68831 memset(&info, 0, sizeof(info));
68832
68833 set_fs(KERNEL_DS);
68834- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
68835- uru ? (struct rusage __user *)&ru : NULL);
68836+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
68837+ uru ? (struct rusage __force_user *)&ru : NULL);
68838 set_fs(old_fs);
68839
68840 if ((ret < 0) || (info.si_signo == 0))
68841@@ -707,8 +708,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
68842 oldfs = get_fs();
68843 set_fs(KERNEL_DS);
68844 err = sys_timer_settime(timer_id, flags,
68845- (struct itimerspec __user *) &newts,
68846- (struct itimerspec __user *) &oldts);
68847+ (struct itimerspec __force_user *) &newts,
68848+ (struct itimerspec __force_user *) &oldts);
68849 set_fs(oldfs);
68850 if (!err && old && put_compat_itimerspec(old, &oldts))
68851 return -EFAULT;
68852@@ -725,7 +726,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
68853 oldfs = get_fs();
68854 set_fs(KERNEL_DS);
68855 err = sys_timer_gettime(timer_id,
68856- (struct itimerspec __user *) &ts);
68857+ (struct itimerspec __force_user *) &ts);
68858 set_fs(oldfs);
68859 if (!err && put_compat_itimerspec(setting, &ts))
68860 return -EFAULT;
68861@@ -744,7 +745,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
68862 oldfs = get_fs();
68863 set_fs(KERNEL_DS);
68864 err = sys_clock_settime(which_clock,
68865- (struct timespec __user *) &ts);
68866+ (struct timespec __force_user *) &ts);
68867 set_fs(oldfs);
68868 return err;
68869 }
68870@@ -759,7 +760,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
68871 oldfs = get_fs();
68872 set_fs(KERNEL_DS);
68873 err = sys_clock_gettime(which_clock,
68874- (struct timespec __user *) &ts);
68875+ (struct timespec __force_user *) &ts);
68876 set_fs(oldfs);
68877 if (!err && put_compat_timespec(&ts, tp))
68878 return -EFAULT;
68879@@ -779,7 +780,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
68880
68881 oldfs = get_fs();
68882 set_fs(KERNEL_DS);
68883- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
68884+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
68885 set_fs(oldfs);
68886
68887 err = compat_put_timex(utp, &txc);
68888@@ -799,7 +800,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
68889 oldfs = get_fs();
68890 set_fs(KERNEL_DS);
68891 err = sys_clock_getres(which_clock,
68892- (struct timespec __user *) &ts);
68893+ (struct timespec __force_user *) &ts);
68894 set_fs(oldfs);
68895 if (!err && tp && put_compat_timespec(&ts, tp))
68896 return -EFAULT;
68897@@ -811,9 +812,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
68898 long err;
68899 mm_segment_t oldfs;
68900 struct timespec tu;
68901- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
68902+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
68903
68904- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
68905+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
68906 oldfs = get_fs();
68907 set_fs(KERNEL_DS);
68908 err = clock_nanosleep_restart(restart);
68909@@ -845,8 +846,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
68910 oldfs = get_fs();
68911 set_fs(KERNEL_DS);
68912 err = sys_clock_nanosleep(which_clock, flags,
68913- (struct timespec __user *) &in,
68914- (struct timespec __user *) &out);
68915+ (struct timespec __force_user *) &in,
68916+ (struct timespec __force_user *) &out);
68917 set_fs(oldfs);
68918
68919 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
68920diff --git a/kernel/configs.c b/kernel/configs.c
68921index 42e8fa0..9e7406b 100644
68922--- a/kernel/configs.c
68923+++ b/kernel/configs.c
68924@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
68925 struct proc_dir_entry *entry;
68926
68927 /* create the current config file */
68928+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
68929+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
68930+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
68931+ &ikconfig_file_ops);
68932+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68933+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
68934+ &ikconfig_file_ops);
68935+#endif
68936+#else
68937 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
68938 &ikconfig_file_ops);
68939+#endif
68940+
68941 if (!entry)
68942 return -ENOMEM;
68943
68944diff --git a/kernel/cred.c b/kernel/cred.c
68945index 48cea3d..3476734 100644
68946--- a/kernel/cred.c
68947+++ b/kernel/cred.c
68948@@ -207,6 +207,16 @@ void exit_creds(struct task_struct *tsk)
68949 validate_creds(cred);
68950 alter_cred_subscribers(cred, -1);
68951 put_cred(cred);
68952+
68953+#ifdef CONFIG_GRKERNSEC_SETXID
68954+ cred = (struct cred *) tsk->delayed_cred;
68955+ if (cred != NULL) {
68956+ tsk->delayed_cred = NULL;
68957+ validate_creds(cred);
68958+ alter_cred_subscribers(cred, -1);
68959+ put_cred(cred);
68960+ }
68961+#endif
68962 }
68963
68964 /**
68965@@ -469,7 +479,7 @@ error_put:
68966 * Always returns 0 thus allowing this function to be tail-called at the end
68967 * of, say, sys_setgid().
68968 */
68969-int commit_creds(struct cred *new)
68970+static int __commit_creds(struct cred *new)
68971 {
68972 struct task_struct *task = current;
68973 const struct cred *old = task->real_cred;
68974@@ -488,6 +498,8 @@ int commit_creds(struct cred *new)
68975
68976 get_cred(new); /* we will require a ref for the subj creds too */
68977
68978+ gr_set_role_label(task, new->uid, new->gid);
68979+
68980 /* dumpability changes */
68981 if (!uid_eq(old->euid, new->euid) ||
68982 !gid_eq(old->egid, new->egid) ||
68983@@ -537,6 +549,101 @@ int commit_creds(struct cred *new)
68984 put_cred(old);
68985 return 0;
68986 }
68987+#ifdef CONFIG_GRKERNSEC_SETXID
68988+extern int set_user(struct cred *new);
68989+
68990+void gr_delayed_cred_worker(void)
68991+{
68992+ const struct cred *new = current->delayed_cred;
68993+ struct cred *ncred;
68994+
68995+ current->delayed_cred = NULL;
68996+
68997+ if (current_uid() && new != NULL) {
68998+ // from doing get_cred on it when queueing this
68999+ put_cred(new);
69000+ return;
69001+ } else if (new == NULL)
69002+ return;
69003+
69004+ ncred = prepare_creds();
69005+ if (!ncred)
69006+ goto die;
69007+ // uids
69008+ ncred->uid = new->uid;
69009+ ncred->euid = new->euid;
69010+ ncred->suid = new->suid;
69011+ ncred->fsuid = new->fsuid;
69012+ // gids
69013+ ncred->gid = new->gid;
69014+ ncred->egid = new->egid;
69015+ ncred->sgid = new->sgid;
69016+ ncred->fsgid = new->fsgid;
69017+ // groups
69018+ if (set_groups(ncred, new->group_info) < 0) {
69019+ abort_creds(ncred);
69020+ goto die;
69021+ }
69022+ // caps
69023+ ncred->securebits = new->securebits;
69024+ ncred->cap_inheritable = new->cap_inheritable;
69025+ ncred->cap_permitted = new->cap_permitted;
69026+ ncred->cap_effective = new->cap_effective;
69027+ ncred->cap_bset = new->cap_bset;
69028+
69029+ if (set_user(ncred)) {
69030+ abort_creds(ncred);
69031+ goto die;
69032+ }
69033+
69034+ // from doing get_cred on it when queueing this
69035+ put_cred(new);
69036+
69037+ __commit_creds(ncred);
69038+ return;
69039+die:
69040+ // from doing get_cred on it when queueing this
69041+ put_cred(new);
69042+ do_group_exit(SIGKILL);
69043+}
69044+#endif
69045+
69046+int commit_creds(struct cred *new)
69047+{
69048+#ifdef CONFIG_GRKERNSEC_SETXID
69049+ int ret;
69050+ int schedule_it = 0;
69051+ struct task_struct *t;
69052+
69053+ /* we won't get called with tasklist_lock held for writing
69054+ and interrupts disabled as the cred struct in that case is
69055+ init_cred
69056+ */
69057+ if (grsec_enable_setxid && !current_is_single_threaded() &&
69058+ !current_uid() && new->uid) {
69059+ schedule_it = 1;
69060+ }
69061+ ret = __commit_creds(new);
69062+ if (schedule_it) {
69063+ rcu_read_lock();
69064+ read_lock(&tasklist_lock);
69065+ for (t = next_thread(current); t != current;
69066+ t = next_thread(t)) {
69067+ if (t->delayed_cred == NULL) {
69068+ t->delayed_cred = get_cred(new);
69069+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
69070+ set_tsk_need_resched(t);
69071+ }
69072+ }
69073+ read_unlock(&tasklist_lock);
69074+ rcu_read_unlock();
69075+ }
69076+ return ret;
69077+#else
69078+ return __commit_creds(new);
69079+#endif
69080+}
69081+
69082 EXPORT_SYMBOL(commit_creds);
69083
69084 /**
69085diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
69086index 9a61738..c5c8f3a 100644
69087--- a/kernel/debug/debug_core.c
69088+++ b/kernel/debug/debug_core.c
69089@@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
69090 */
69091 static atomic_t masters_in_kgdb;
69092 static atomic_t slaves_in_kgdb;
69093-static atomic_t kgdb_break_tasklet_var;
69094+static atomic_unchecked_t kgdb_break_tasklet_var;
69095 atomic_t kgdb_setting_breakpoint;
69096
69097 struct task_struct *kgdb_usethread;
69098@@ -132,7 +132,7 @@ int kgdb_single_step;
69099 static pid_t kgdb_sstep_pid;
69100
69101 /* to keep track of the CPU which is doing the single stepping*/
69102-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
69103+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
69104
69105 /*
69106 * If you are debugging a problem where roundup (the collection of
69107@@ -540,7 +540,7 @@ return_normal:
69108 * kernel will only try for the value of sstep_tries before
69109 * giving up and continuing on.
69110 */
69111- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
69112+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
69113 (kgdb_info[cpu].task &&
69114 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
69115 atomic_set(&kgdb_active, -1);
69116@@ -634,8 +634,8 @@ cpu_master_loop:
69117 }
69118
69119 kgdb_restore:
69120- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
69121- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
69122+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
69123+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
69124 if (kgdb_info[sstep_cpu].task)
69125 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
69126 else
69127@@ -887,18 +887,18 @@ static void kgdb_unregister_callbacks(void)
69128 static void kgdb_tasklet_bpt(unsigned long ing)
69129 {
69130 kgdb_breakpoint();
69131- atomic_set(&kgdb_break_tasklet_var, 0);
69132+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
69133 }
69134
69135 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
69136
69137 void kgdb_schedule_breakpoint(void)
69138 {
69139- if (atomic_read(&kgdb_break_tasklet_var) ||
69140+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
69141 atomic_read(&kgdb_active) != -1 ||
69142 atomic_read(&kgdb_setting_breakpoint))
69143 return;
69144- atomic_inc(&kgdb_break_tasklet_var);
69145+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
69146 tasklet_schedule(&kgdb_tasklet_breakpoint);
69147 }
69148 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
69149diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
69150index 4d5f8d5..4743f33 100644
69151--- a/kernel/debug/kdb/kdb_main.c
69152+++ b/kernel/debug/kdb/kdb_main.c
69153@@ -1972,7 +1972,7 @@ static int kdb_lsmod(int argc, const char **argv)
69154 list_for_each_entry(mod, kdb_modules, list) {
69155
69156 kdb_printf("%-20s%8u 0x%p ", mod->name,
69157- mod->core_size, (void *)mod);
69158+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
69159 #ifdef CONFIG_MODULE_UNLOAD
69160 kdb_printf("%4ld ", module_refcount(mod));
69161 #endif
69162@@ -1982,7 +1982,7 @@ static int kdb_lsmod(int argc, const char **argv)
69163 kdb_printf(" (Loading)");
69164 else
69165 kdb_printf(" (Live)");
69166- kdb_printf(" 0x%p", mod->module_core);
69167+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
69168
69169 #ifdef CONFIG_MODULE_UNLOAD
69170 {
69171diff --git a/kernel/events/core.c b/kernel/events/core.c
69172index dbccf83..8c66482 100644
69173--- a/kernel/events/core.c
69174+++ b/kernel/events/core.c
69175@@ -182,7 +182,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
69176 return 0;
69177 }
69178
69179-static atomic64_t perf_event_id;
69180+static atomic64_unchecked_t perf_event_id;
69181
69182 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
69183 enum event_type_t event_type);
69184@@ -2668,7 +2668,7 @@ static void __perf_event_read(void *info)
69185
69186 static inline u64 perf_event_count(struct perf_event *event)
69187 {
69188- return local64_read(&event->count) + atomic64_read(&event->child_count);
69189+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
69190 }
69191
69192 static u64 perf_event_read(struct perf_event *event)
69193@@ -2998,9 +2998,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
69194 mutex_lock(&event->child_mutex);
69195 total += perf_event_read(event);
69196 *enabled += event->total_time_enabled +
69197- atomic64_read(&event->child_total_time_enabled);
69198+ atomic64_read_unchecked(&event->child_total_time_enabled);
69199 *running += event->total_time_running +
69200- atomic64_read(&event->child_total_time_running);
69201+ atomic64_read_unchecked(&event->child_total_time_running);
69202
69203 list_for_each_entry(child, &event->child_list, child_list) {
69204 total += perf_event_read(child);
69205@@ -3403,10 +3403,10 @@ void perf_event_update_userpage(struct perf_event *event)
69206 userpg->offset -= local64_read(&event->hw.prev_count);
69207
69208 userpg->time_enabled = enabled +
69209- atomic64_read(&event->child_total_time_enabled);
69210+ atomic64_read_unchecked(&event->child_total_time_enabled);
69211
69212 userpg->time_running = running +
69213- atomic64_read(&event->child_total_time_running);
69214+ atomic64_read_unchecked(&event->child_total_time_running);
69215
69216 arch_perf_update_userpage(userpg, now);
69217
69218@@ -3965,11 +3965,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
69219 values[n++] = perf_event_count(event);
69220 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
69221 values[n++] = enabled +
69222- atomic64_read(&event->child_total_time_enabled);
69223+ atomic64_read_unchecked(&event->child_total_time_enabled);
69224 }
69225 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
69226 values[n++] = running +
69227- atomic64_read(&event->child_total_time_running);
69228+ atomic64_read_unchecked(&event->child_total_time_running);
69229 }
69230 if (read_format & PERF_FORMAT_ID)
69231 values[n++] = primary_event_id(event);
69232@@ -4712,12 +4712,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
69233 * need to add enough zero bytes after the string to handle
69234 * the 64bit alignment we do later.
69235 */
69236- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
69237+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
69238 if (!buf) {
69239 name = strncpy(tmp, "//enomem", sizeof(tmp));
69240 goto got_name;
69241 }
69242- name = d_path(&file->f_path, buf, PATH_MAX);
69243+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
69244 if (IS_ERR(name)) {
69245 name = strncpy(tmp, "//toolong", sizeof(tmp));
69246 goto got_name;
69247@@ -6156,7 +6156,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
69248 event->parent = parent_event;
69249
69250 event->ns = get_pid_ns(current->nsproxy->pid_ns);
69251- event->id = atomic64_inc_return(&perf_event_id);
69252+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
69253
69254 event->state = PERF_EVENT_STATE_INACTIVE;
69255
69256@@ -6774,10 +6774,10 @@ static void sync_child_event(struct perf_event *child_event,
69257 /*
69258 * Add back the child's count to the parent's count:
69259 */
69260- atomic64_add(child_val, &parent_event->child_count);
69261- atomic64_add(child_event->total_time_enabled,
69262+ atomic64_add_unchecked(child_val, &parent_event->child_count);
69263+ atomic64_add_unchecked(child_event->total_time_enabled,
69264 &parent_event->child_total_time_enabled);
69265- atomic64_add(child_event->total_time_running,
69266+ atomic64_add_unchecked(child_event->total_time_running,
69267 &parent_event->child_total_time_running);
69268
69269 /*
69270diff --git a/kernel/exit.c b/kernel/exit.c
69271index 346616c..a86ec83 100644
69272--- a/kernel/exit.c
69273+++ b/kernel/exit.c
69274@@ -182,6 +182,10 @@ void release_task(struct task_struct * p)
69275 struct task_struct *leader;
69276 int zap_leader;
69277 repeat:
69278+#ifdef CONFIG_NET
69279+ gr_del_task_from_ip_table(p);
69280+#endif
69281+
69282 /* don't need to get the RCU readlock here - the process is dead and
69283 * can't be modifying its own credentials. But shut RCU-lockdep up */
69284 rcu_read_lock();
69285@@ -394,7 +398,7 @@ int allow_signal(int sig)
69286 * know it'll be handled, so that they don't get converted to
69287 * SIGKILL or just silently dropped.
69288 */
69289- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
69290+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
69291 recalc_sigpending();
69292 spin_unlock_irq(&current->sighand->siglock);
69293 return 0;
69294@@ -430,6 +434,8 @@ void daemonize(const char *name, ...)
69295 vsnprintf(current->comm, sizeof(current->comm), name, args);
69296 va_end(args);
69297
69298+ gr_set_kernel_label(current);
69299+
69300 /*
69301 * If we were started as result of loading a module, close all of the
69302 * user space pages. We don't need them, and if we didn't close them
69303@@ -812,6 +818,8 @@ void do_exit(long code)
69304 struct task_struct *tsk = current;
69305 int group_dead;
69306
69307+ set_fs(USER_DS);
69308+
69309 profile_task_exit(tsk);
69310
69311 WARN_ON(blk_needs_flush_plug(tsk));
69312@@ -828,7 +836,6 @@ void do_exit(long code)
69313 * mm_release()->clear_child_tid() from writing to a user-controlled
69314 * kernel address.
69315 */
69316- set_fs(USER_DS);
69317
69318 ptrace_event(PTRACE_EVENT_EXIT, code);
69319
69320@@ -887,6 +894,9 @@ void do_exit(long code)
69321 tsk->exit_code = code;
69322 taskstats_exit(tsk, group_dead);
69323
69324+ gr_acl_handle_psacct(tsk, code);
69325+ gr_acl_handle_exit();
69326+
69327 exit_mm(tsk);
69328
69329 if (group_dead)
69330@@ -1007,7 +1017,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
69331 * Take down every thread in the group. This is called by fatal signals
69332 * as well as by sys_exit_group (below).
69333 */
69334-void
69335+__noreturn void
69336 do_group_exit(int exit_code)
69337 {
69338 struct signal_struct *sig = current->signal;
69339diff --git a/kernel/fork.c b/kernel/fork.c
69340index 8b20ab7..58f2e45 100644
69341--- a/kernel/fork.c
69342+++ b/kernel/fork.c
69343@@ -318,7 +318,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
69344 *stackend = STACK_END_MAGIC; /* for overflow detection */
69345
69346 #ifdef CONFIG_CC_STACKPROTECTOR
69347- tsk->stack_canary = get_random_int();
69348+ tsk->stack_canary = pax_get_random_long();
69349 #endif
69350
69351 /*
69352@@ -344,13 +344,81 @@ free_tsk:
69353 }
69354
69355 #ifdef CONFIG_MMU
69356+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
69357+{
69358+ struct vm_area_struct *tmp;
69359+ unsigned long charge;
69360+ struct mempolicy *pol;
69361+ struct file *file;
69362+
69363+ charge = 0;
69364+ if (mpnt->vm_flags & VM_ACCOUNT) {
69365+ unsigned long len = vma_pages(mpnt);
69366+
69367+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
69368+ goto fail_nomem;
69369+ charge = len;
69370+ }
69371+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
69372+ if (!tmp)
69373+ goto fail_nomem;
69374+ *tmp = *mpnt;
69375+ tmp->vm_mm = mm;
69376+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
69377+ pol = mpol_dup(vma_policy(mpnt));
69378+ if (IS_ERR(pol))
69379+ goto fail_nomem_policy;
69380+ vma_set_policy(tmp, pol);
69381+ if (anon_vma_fork(tmp, mpnt))
69382+ goto fail_nomem_anon_vma_fork;
69383+ tmp->vm_flags &= ~VM_LOCKED;
69384+ tmp->vm_next = tmp->vm_prev = NULL;
69385+ tmp->vm_mirror = NULL;
69386+ file = tmp->vm_file;
69387+ if (file) {
69388+ struct inode *inode = file->f_path.dentry->d_inode;
69389+ struct address_space *mapping = file->f_mapping;
69390+
69391+ get_file(file);
69392+ if (tmp->vm_flags & VM_DENYWRITE)
69393+ atomic_dec(&inode->i_writecount);
69394+ mutex_lock(&mapping->i_mmap_mutex);
69395+ if (tmp->vm_flags & VM_SHARED)
69396+ mapping->i_mmap_writable++;
69397+ flush_dcache_mmap_lock(mapping);
69398+ /* insert tmp into the share list, just after mpnt */
69399+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
69400+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
69401+ else
69402+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
69403+ flush_dcache_mmap_unlock(mapping);
69404+ mutex_unlock(&mapping->i_mmap_mutex);
69405+ }
69406+
69407+ /*
69408+ * Clear hugetlb-related page reserves for children. This only
69409+ * affects MAP_PRIVATE mappings. Faults generated by the child
69410+ * are not guaranteed to succeed, even if read-only
69411+ */
69412+ if (is_vm_hugetlb_page(tmp))
69413+ reset_vma_resv_huge_pages(tmp);
69414+
69415+ return tmp;
69416+
69417+fail_nomem_anon_vma_fork:
69418+ mpol_put(pol);
69419+fail_nomem_policy:
69420+ kmem_cache_free(vm_area_cachep, tmp);
69421+fail_nomem:
69422+ vm_unacct_memory(charge);
69423+ return NULL;
69424+}
69425+
69426 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
69427 {
69428 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
69429 struct rb_node **rb_link, *rb_parent;
69430 int retval;
69431- unsigned long charge;
69432- struct mempolicy *pol;
69433
69434 down_write(&oldmm->mmap_sem);
69435 flush_cache_dup_mm(oldmm);
69436@@ -363,8 +431,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
69437 mm->locked_vm = 0;
69438 mm->mmap = NULL;
69439 mm->mmap_cache = NULL;
69440- mm->free_area_cache = oldmm->mmap_base;
69441- mm->cached_hole_size = ~0UL;
69442+ mm->free_area_cache = oldmm->free_area_cache;
69443+ mm->cached_hole_size = oldmm->cached_hole_size;
69444 mm->map_count = 0;
69445 cpumask_clear(mm_cpumask(mm));
69446 mm->mm_rb = RB_ROOT;
69447@@ -380,57 +448,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
69448
69449 prev = NULL;
69450 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
69451- struct file *file;
69452-
69453 if (mpnt->vm_flags & VM_DONTCOPY) {
69454 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
69455 -vma_pages(mpnt));
69456 continue;
69457 }
69458- charge = 0;
69459- if (mpnt->vm_flags & VM_ACCOUNT) {
69460- unsigned long len = vma_pages(mpnt);
69461-
69462- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
69463- goto fail_nomem;
69464- charge = len;
69465- }
69466- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
69467- if (!tmp)
69468- goto fail_nomem;
69469- *tmp = *mpnt;
69470- INIT_LIST_HEAD(&tmp->anon_vma_chain);
69471- pol = mpol_dup(vma_policy(mpnt));
69472- retval = PTR_ERR(pol);
69473- if (IS_ERR(pol))
69474- goto fail_nomem_policy;
69475- vma_set_policy(tmp, pol);
69476- tmp->vm_mm = mm;
69477- if (anon_vma_fork(tmp, mpnt))
69478- goto fail_nomem_anon_vma_fork;
69479- tmp->vm_flags &= ~VM_LOCKED;
69480- tmp->vm_next = tmp->vm_prev = NULL;
69481- file = tmp->vm_file;
69482- if (file) {
69483- struct inode *inode = file->f_path.dentry->d_inode;
69484- struct address_space *mapping = file->f_mapping;
69485-
69486- get_file(file);
69487- if (tmp->vm_flags & VM_DENYWRITE)
69488- atomic_dec(&inode->i_writecount);
69489- mutex_lock(&mapping->i_mmap_mutex);
69490- if (tmp->vm_flags & VM_SHARED)
69491- mapping->i_mmap_writable++;
69492- flush_dcache_mmap_lock(mapping);
69493- /* insert tmp into the share list, just after mpnt */
69494- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
69495- vma_nonlinear_insert(tmp,
69496- &mapping->i_mmap_nonlinear);
69497- else
69498- vma_interval_tree_insert_after(tmp, mpnt,
69499- &mapping->i_mmap);
69500- flush_dcache_mmap_unlock(mapping);
69501- mutex_unlock(&mapping->i_mmap_mutex);
69502+ tmp = dup_vma(mm, oldmm, mpnt);
69503+ if (!tmp) {
69504+ retval = -ENOMEM;
69505+ goto out;
69506 }
69507
69508 /*
69509@@ -462,6 +488,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
69510 if (retval)
69511 goto out;
69512 }
69513+
69514+#ifdef CONFIG_PAX_SEGMEXEC
69515+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
69516+ struct vm_area_struct *mpnt_m;
69517+
69518+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
69519+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
69520+
69521+ if (!mpnt->vm_mirror)
69522+ continue;
69523+
69524+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
69525+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
69526+ mpnt->vm_mirror = mpnt_m;
69527+ } else {
69528+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
69529+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
69530+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
69531+ mpnt->vm_mirror->vm_mirror = mpnt;
69532+ }
69533+ }
69534+ BUG_ON(mpnt_m);
69535+ }
69536+#endif
69537+
69538 /* a new mm has just been created */
69539 arch_dup_mmap(oldmm, mm);
69540 retval = 0;
69541@@ -470,14 +521,6 @@ out:
69542 flush_tlb_mm(oldmm);
69543 up_write(&oldmm->mmap_sem);
69544 return retval;
69545-fail_nomem_anon_vma_fork:
69546- mpol_put(pol);
69547-fail_nomem_policy:
69548- kmem_cache_free(vm_area_cachep, tmp);
69549-fail_nomem:
69550- retval = -ENOMEM;
69551- vm_unacct_memory(charge);
69552- goto out;
69553 }
69554
69555 static inline int mm_alloc_pgd(struct mm_struct *mm)
69556@@ -692,8 +735,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
69557 return ERR_PTR(err);
69558
69559 mm = get_task_mm(task);
69560- if (mm && mm != current->mm &&
69561- !ptrace_may_access(task, mode)) {
69562+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
69563+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
69564 mmput(mm);
69565 mm = ERR_PTR(-EACCES);
69566 }
69567@@ -912,13 +955,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
69568 spin_unlock(&fs->lock);
69569 return -EAGAIN;
69570 }
69571- fs->users++;
69572+ atomic_inc(&fs->users);
69573 spin_unlock(&fs->lock);
69574 return 0;
69575 }
69576 tsk->fs = copy_fs_struct(fs);
69577 if (!tsk->fs)
69578 return -ENOMEM;
69579+ /* Carry through gr_chroot_dentry and is_chrooted instead
69580+ of recomputing it here. Already copied when the task struct
69581+ is duplicated. This allows pivot_root to not be treated as
69582+ a chroot
69583+ */
69584+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
69585+
69586 return 0;
69587 }
69588
69589@@ -1184,6 +1234,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
69590 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
69591 #endif
69592 retval = -EAGAIN;
69593+
69594+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
69595+
69596 if (atomic_read(&p->real_cred->user->processes) >=
69597 task_rlimit(p, RLIMIT_NPROC)) {
69598 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
69599@@ -1402,6 +1455,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
69600 /* Need tasklist lock for parent etc handling! */
69601 write_lock_irq(&tasklist_lock);
69602
69603+ /* synchronizes with gr_set_acls() */
69604+ gr_copy_label(p);
69605+
69606 /* CLONE_PARENT re-uses the old parent */
69607 if (clone_flags & (CLONE_PARENT|CLONE_THREAD)) {
69608 p->real_parent = current->real_parent;
69609@@ -1512,6 +1568,8 @@ bad_fork_cleanup_count:
69610 bad_fork_free:
69611 free_task(p);
69612 fork_out:
69613+ gr_log_forkfail(retval);
69614+
69615 return ERR_PTR(retval);
69616 }
69617
69618@@ -1612,6 +1670,8 @@ long do_fork(unsigned long clone_flags,
69619 if (clone_flags & CLONE_PARENT_SETTID)
69620 put_user(nr, parent_tidptr);
69621
69622+ gr_handle_brute_check();
69623+
69624 if (clone_flags & CLONE_VFORK) {
69625 p->vfork_done = &vfork;
69626 init_completion(&vfork);
69627@@ -1721,7 +1781,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
69628 return 0;
69629
69630 /* don't need lock here; in the worst case we'll do useless copy */
69631- if (fs->users == 1)
69632+ if (atomic_read(&fs->users) == 1)
69633 return 0;
69634
69635 *new_fsp = copy_fs_struct(fs);
69636@@ -1810,7 +1870,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
69637 fs = current->fs;
69638 spin_lock(&fs->lock);
69639 current->fs = new_fs;
69640- if (--fs->users)
69641+ gr_set_chroot_entries(current, &current->fs->root);
69642+ if (atomic_dec_return(&fs->users))
69643 new_fs = NULL;
69644 else
69645 new_fs = fs;
69646diff --git a/kernel/futex.c b/kernel/futex.c
69647index 19eb089..b8c65ea 100644
69648--- a/kernel/futex.c
69649+++ b/kernel/futex.c
69650@@ -54,6 +54,7 @@
69651 #include <linux/mount.h>
69652 #include <linux/pagemap.h>
69653 #include <linux/syscalls.h>
69654+#include <linux/ptrace.h>
69655 #include <linux/signal.h>
69656 #include <linux/export.h>
69657 #include <linux/magic.h>
69658@@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
69659 struct page *page, *page_head;
69660 int err, ro = 0;
69661
69662+#ifdef CONFIG_PAX_SEGMEXEC
69663+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
69664+ return -EFAULT;
69665+#endif
69666+
69667 /*
69668 * The futex address must be "naturally" aligned.
69669 */
69670@@ -2733,6 +2739,7 @@ static int __init futex_init(void)
69671 {
69672 u32 curval;
69673 int i;
69674+ mm_segment_t oldfs;
69675
69676 /*
69677 * This will fail and we want it. Some arch implementations do
69678@@ -2744,8 +2751,11 @@ static int __init futex_init(void)
69679 * implementation, the non-functional ones will return
69680 * -ENOSYS.
69681 */
69682+ oldfs = get_fs();
69683+ set_fs(USER_DS);
69684 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
69685 futex_cmpxchg_enabled = 1;
69686+ set_fs(oldfs);
69687
69688 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
69689 plist_head_init(&futex_queues[i].chain);
69690diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
69691index 9b22d03..6295b62 100644
69692--- a/kernel/gcov/base.c
69693+++ b/kernel/gcov/base.c
69694@@ -102,11 +102,6 @@ void gcov_enable_events(void)
69695 }
69696
69697 #ifdef CONFIG_MODULES
69698-static inline int within(void *addr, void *start, unsigned long size)
69699-{
69700- return ((addr >= start) && (addr < start + size));
69701-}
69702-
69703 /* Update list and generate events when modules are unloaded. */
69704 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
69705 void *data)
69706@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
69707 prev = NULL;
69708 /* Remove entries located in module from linked list. */
69709 for (info = gcov_info_head; info; info = info->next) {
69710- if (within(info, mod->module_core, mod->core_size)) {
69711+ if (within_module_core_rw((unsigned long)info, mod)) {
69712 if (prev)
69713 prev->next = info->next;
69714 else
69715diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
69716index 6db7a5e..25b6648 100644
69717--- a/kernel/hrtimer.c
69718+++ b/kernel/hrtimer.c
69719@@ -1407,7 +1407,7 @@ void hrtimer_peek_ahead_timers(void)
69720 local_irq_restore(flags);
69721 }
69722
69723-static void run_hrtimer_softirq(struct softirq_action *h)
69724+static void run_hrtimer_softirq(void)
69725 {
69726 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
69727
69728diff --git a/kernel/jump_label.c b/kernel/jump_label.c
69729index 60f48fa..7f3a770 100644
69730--- a/kernel/jump_label.c
69731+++ b/kernel/jump_label.c
69732@@ -13,6 +13,7 @@
69733 #include <linux/sort.h>
69734 #include <linux/err.h>
69735 #include <linux/static_key.h>
69736+#include <linux/mm.h>
69737
69738 #ifdef HAVE_JUMP_LABEL
69739
69740@@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
69741
69742 size = (((unsigned long)stop - (unsigned long)start)
69743 / sizeof(struct jump_entry));
69744+ pax_open_kernel();
69745 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
69746+ pax_close_kernel();
69747 }
69748
69749 static void jump_label_update(struct static_key *key, int enable);
69750@@ -357,10 +360,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
69751 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
69752 struct jump_entry *iter;
69753
69754+ pax_open_kernel();
69755 for (iter = iter_start; iter < iter_stop; iter++) {
69756 if (within_module_init(iter->code, mod))
69757 iter->code = 0;
69758 }
69759+ pax_close_kernel();
69760 }
69761
69762 static int
69763diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
69764index 2169fee..45c017a 100644
69765--- a/kernel/kallsyms.c
69766+++ b/kernel/kallsyms.c
69767@@ -11,6 +11,9 @@
69768 * Changed the compression method from stem compression to "table lookup"
69769 * compression (see scripts/kallsyms.c for a more complete description)
69770 */
69771+#ifdef CONFIG_GRKERNSEC_HIDESYM
69772+#define __INCLUDED_BY_HIDESYM 1
69773+#endif
69774 #include <linux/kallsyms.h>
69775 #include <linux/module.h>
69776 #include <linux/init.h>
69777@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
69778
69779 static inline int is_kernel_inittext(unsigned long addr)
69780 {
69781+ if (system_state != SYSTEM_BOOTING)
69782+ return 0;
69783+
69784 if (addr >= (unsigned long)_sinittext
69785 && addr <= (unsigned long)_einittext)
69786 return 1;
69787 return 0;
69788 }
69789
69790+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
69791+#ifdef CONFIG_MODULES
69792+static inline int is_module_text(unsigned long addr)
69793+{
69794+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
69795+ return 1;
69796+
69797+ addr = ktla_ktva(addr);
69798+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
69799+}
69800+#else
69801+static inline int is_module_text(unsigned long addr)
69802+{
69803+ return 0;
69804+}
69805+#endif
69806+#endif
69807+
69808 static inline int is_kernel_text(unsigned long addr)
69809 {
69810 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
69811@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
69812
69813 static inline int is_kernel(unsigned long addr)
69814 {
69815+
69816+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
69817+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
69818+ return 1;
69819+
69820+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
69821+#else
69822 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
69823+#endif
69824+
69825 return 1;
69826 return in_gate_area_no_mm(addr);
69827 }
69828
69829 static int is_ksym_addr(unsigned long addr)
69830 {
69831+
69832+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
69833+ if (is_module_text(addr))
69834+ return 0;
69835+#endif
69836+
69837 if (all_var)
69838 return is_kernel(addr);
69839
69840@@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
69841
69842 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
69843 {
69844- iter->name[0] = '\0';
69845 iter->nameoff = get_symbol_offset(new_pos);
69846 iter->pos = new_pos;
69847 }
69848@@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
69849 {
69850 struct kallsym_iter *iter = m->private;
69851
69852+#ifdef CONFIG_GRKERNSEC_HIDESYM
69853+ if (current_uid())
69854+ return 0;
69855+#endif
69856+
69857 /* Some debugging symbols have no name. Ignore them. */
69858 if (!iter->name[0])
69859 return 0;
69860@@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
69861 */
69862 type = iter->exported ? toupper(iter->type) :
69863 tolower(iter->type);
69864+
69865 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
69866 type, iter->name, iter->module_name);
69867 } else
69868@@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
69869 struct kallsym_iter *iter;
69870 int ret;
69871
69872- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
69873+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
69874 if (!iter)
69875 return -ENOMEM;
69876 reset_iter(iter, 0);
69877diff --git a/kernel/kcmp.c b/kernel/kcmp.c
69878index 30b7b22..c726387 100644
69879--- a/kernel/kcmp.c
69880+++ b/kernel/kcmp.c
69881@@ -98,6 +98,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
69882 struct task_struct *task1, *task2;
69883 int ret;
69884
69885+#ifdef CONFIG_GRKERNSEC
69886+ return -ENOSYS;
69887+#endif
69888+
69889 rcu_read_lock();
69890
69891 /*
69892diff --git a/kernel/kexec.c b/kernel/kexec.c
69893index 5e4bd78..00c5b91 100644
69894--- a/kernel/kexec.c
69895+++ b/kernel/kexec.c
69896@@ -1045,7 +1045,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
69897 unsigned long flags)
69898 {
69899 struct compat_kexec_segment in;
69900- struct kexec_segment out, __user *ksegments;
69901+ struct kexec_segment out;
69902+ struct kexec_segment __user *ksegments;
69903 unsigned long i, result;
69904
69905 /* Don't allow clients that don't understand the native
69906diff --git a/kernel/kmod.c b/kernel/kmod.c
69907index 1c317e3..4a92a55 100644
69908--- a/kernel/kmod.c
69909+++ b/kernel/kmod.c
69910@@ -74,7 +74,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
69911 kfree(info->argv);
69912 }
69913
69914-static int call_modprobe(char *module_name, int wait)
69915+static int call_modprobe(char *module_name, char *module_param, int wait)
69916 {
69917 static char *envp[] = {
69918 "HOME=/",
69919@@ -83,7 +83,7 @@ static int call_modprobe(char *module_name, int wait)
69920 NULL
69921 };
69922
69923- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
69924+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
69925 if (!argv)
69926 goto out;
69927
69928@@ -95,7 +95,8 @@ static int call_modprobe(char *module_name, int wait)
69929 argv[1] = "-q";
69930 argv[2] = "--";
69931 argv[3] = module_name; /* check free_modprobe_argv() */
69932- argv[4] = NULL;
69933+ argv[4] = module_param;
69934+ argv[5] = NULL;
69935
69936 return call_usermodehelper_fns(modprobe_path, argv, envp,
69937 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
69938@@ -120,9 +121,8 @@ out:
69939 * If module auto-loading support is disabled then this function
69940 * becomes a no-operation.
69941 */
69942-int __request_module(bool wait, const char *fmt, ...)
69943+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
69944 {
69945- va_list args;
69946 char module_name[MODULE_NAME_LEN];
69947 unsigned int max_modprobes;
69948 int ret;
69949@@ -130,9 +130,7 @@ int __request_module(bool wait, const char *fmt, ...)
69950 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
69951 static int kmod_loop_msg;
69952
69953- va_start(args, fmt);
69954- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
69955- va_end(args);
69956+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
69957 if (ret >= MODULE_NAME_LEN)
69958 return -ENAMETOOLONG;
69959
69960@@ -140,6 +138,20 @@ int __request_module(bool wait, const char *fmt, ...)
69961 if (ret)
69962 return ret;
69963
69964+#ifdef CONFIG_GRKERNSEC_MODHARDEN
69965+ if (!current_uid()) {
69966+ /* hack to workaround consolekit/udisks stupidity */
69967+ read_lock(&tasklist_lock);
69968+ if (!strcmp(current->comm, "mount") &&
69969+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
69970+ read_unlock(&tasklist_lock);
69971+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
69972+ return -EPERM;
69973+ }
69974+ read_unlock(&tasklist_lock);
69975+ }
69976+#endif
69977+
69978 /* If modprobe needs a service that is in a module, we get a recursive
69979 * loop. Limit the number of running kmod threads to max_threads/2 or
69980 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
69981@@ -168,11 +180,52 @@ int __request_module(bool wait, const char *fmt, ...)
69982
69983 trace_module_request(module_name, wait, _RET_IP_);
69984
69985- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
69986+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
69987
69988 atomic_dec(&kmod_concurrent);
69989 return ret;
69990 }
69991+
69992+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
69993+{
69994+ va_list args;
69995+ int ret;
69996+
69997+ va_start(args, fmt);
69998+ ret = ____request_module(wait, module_param, fmt, args);
69999+ va_end(args);
70000+
70001+ return ret;
70002+}
70003+
70004+int __request_module(bool wait, const char *fmt, ...)
70005+{
70006+ va_list args;
70007+ int ret;
70008+
70009+#ifdef CONFIG_GRKERNSEC_MODHARDEN
70010+ if (current_uid()) {
70011+ char module_param[MODULE_NAME_LEN];
70012+
70013+ memset(module_param, 0, sizeof(module_param));
70014+
70015+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
70016+
70017+ va_start(args, fmt);
70018+ ret = ____request_module(wait, module_param, fmt, args);
70019+ va_end(args);
70020+
70021+ return ret;
70022+ }
70023+#endif
70024+
70025+ va_start(args, fmt);
70026+ ret = ____request_module(wait, NULL, fmt, args);
70027+ va_end(args);
70028+
70029+ return ret;
70030+}
70031+
70032 EXPORT_SYMBOL(__request_module);
70033 #endif /* CONFIG_MODULES */
70034
70035@@ -283,7 +336,7 @@ static int wait_for_helper(void *data)
70036 *
70037 * Thus the __user pointer cast is valid here.
70038 */
70039- sys_wait4(pid, (int __user *)&ret, 0, NULL);
70040+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
70041
70042 /*
70043 * If ret is 0, either ____call_usermodehelper failed and the
70044diff --git a/kernel/kprobes.c b/kernel/kprobes.c
70045index 098f396..fe85ff1 100644
70046--- a/kernel/kprobes.c
70047+++ b/kernel/kprobes.c
70048@@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
70049 * kernel image and loaded module images reside. This is required
70050 * so x86_64 can correctly handle the %rip-relative fixups.
70051 */
70052- kip->insns = module_alloc(PAGE_SIZE);
70053+ kip->insns = module_alloc_exec(PAGE_SIZE);
70054 if (!kip->insns) {
70055 kfree(kip);
70056 return NULL;
70057@@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
70058 */
70059 if (!list_is_singular(&kip->list)) {
70060 list_del(&kip->list);
70061- module_free(NULL, kip->insns);
70062+ module_free_exec(NULL, kip->insns);
70063 kfree(kip);
70064 }
70065 return 1;
70066@@ -2063,7 +2063,7 @@ static int __init init_kprobes(void)
70067 {
70068 int i, err = 0;
70069 unsigned long offset = 0, size = 0;
70070- char *modname, namebuf[128];
70071+ char *modname, namebuf[KSYM_NAME_LEN];
70072 const char *symbol_name;
70073 void *addr;
70074 struct kprobe_blackpoint *kb;
70075@@ -2148,11 +2148,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
70076 kprobe_type = "k";
70077
70078 if (sym)
70079- seq_printf(pi, "%p %s %s+0x%x %s ",
70080+ seq_printf(pi, "%pK %s %s+0x%x %s ",
70081 p->addr, kprobe_type, sym, offset,
70082 (modname ? modname : " "));
70083 else
70084- seq_printf(pi, "%p %s %p ",
70085+ seq_printf(pi, "%pK %s %pK ",
70086 p->addr, kprobe_type, p->addr);
70087
70088 if (!pp)
70089@@ -2190,7 +2190,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
70090 const char *sym = NULL;
70091 unsigned int i = *(loff_t *) v;
70092 unsigned long offset = 0;
70093- char *modname, namebuf[128];
70094+ char *modname, namebuf[KSYM_NAME_LEN];
70095
70096 head = &kprobe_table[i];
70097 preempt_disable();
70098diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
70099index 4e316e1..5501eef 100644
70100--- a/kernel/ksysfs.c
70101+++ b/kernel/ksysfs.c
70102@@ -47,6 +47,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
70103 {
70104 if (count+1 > UEVENT_HELPER_PATH_LEN)
70105 return -ENOENT;
70106+ if (!capable(CAP_SYS_ADMIN))
70107+ return -EPERM;
70108 memcpy(uevent_helper, buf, count);
70109 uevent_helper[count] = '\0';
70110 if (count && uevent_helper[count-1] == '\n')
70111diff --git a/kernel/lockdep.c b/kernel/lockdep.c
70112index 7981e5b..7f2105c 100644
70113--- a/kernel/lockdep.c
70114+++ b/kernel/lockdep.c
70115@@ -590,6 +590,10 @@ static int static_obj(void *obj)
70116 end = (unsigned long) &_end,
70117 addr = (unsigned long) obj;
70118
70119+#ifdef CONFIG_PAX_KERNEXEC
70120+ start = ktla_ktva(start);
70121+#endif
70122+
70123 /*
70124 * static variable?
70125 */
70126@@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
70127 if (!static_obj(lock->key)) {
70128 debug_locks_off();
70129 printk("INFO: trying to register non-static key.\n");
70130+ printk("lock:%pS key:%pS.\n", lock, lock->key);
70131 printk("the code is fine but needs lockdep annotation.\n");
70132 printk("turning off the locking correctness validator.\n");
70133 dump_stack();
70134@@ -3078,7 +3083,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
70135 if (!class)
70136 return 0;
70137 }
70138- atomic_inc((atomic_t *)&class->ops);
70139+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
70140 if (very_verbose(class)) {
70141 printk("\nacquire class [%p] %s", class->key, class->name);
70142 if (class->name_version > 1)
70143diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
70144index 91c32a0..7b88d63 100644
70145--- a/kernel/lockdep_proc.c
70146+++ b/kernel/lockdep_proc.c
70147@@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
70148
70149 static void print_name(struct seq_file *m, struct lock_class *class)
70150 {
70151- char str[128];
70152+ char str[KSYM_NAME_LEN];
70153 const char *name = class->name;
70154
70155 if (!name) {
70156@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
70157 return 0;
70158 }
70159
70160- seq_printf(m, "%p", class->key);
70161+ seq_printf(m, "%pK", class->key);
70162 #ifdef CONFIG_DEBUG_LOCKDEP
70163 seq_printf(m, " OPS:%8ld", class->ops);
70164 #endif
70165@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
70166
70167 list_for_each_entry(entry, &class->locks_after, entry) {
70168 if (entry->distance == 1) {
70169- seq_printf(m, " -> [%p] ", entry->class->key);
70170+ seq_printf(m, " -> [%pK] ", entry->class->key);
70171 print_name(m, entry->class);
70172 seq_puts(m, "\n");
70173 }
70174@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
70175 if (!class->key)
70176 continue;
70177
70178- seq_printf(m, "[%p] ", class->key);
70179+ seq_printf(m, "[%pK] ", class->key);
70180 print_name(m, class);
70181 seq_puts(m, "\n");
70182 }
70183@@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
70184 if (!i)
70185 seq_line(m, '-', 40-namelen, namelen);
70186
70187- snprintf(ip, sizeof(ip), "[<%p>]",
70188+ snprintf(ip, sizeof(ip), "[<%pK>]",
70189 (void *)class->contention_point[i]);
70190 seq_printf(m, "%40s %14lu %29s %pS\n",
70191 name, stats->contention_point[i],
70192@@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
70193 if (!i)
70194 seq_line(m, '-', 40-namelen, namelen);
70195
70196- snprintf(ip, sizeof(ip), "[<%p>]",
70197+ snprintf(ip, sizeof(ip), "[<%pK>]",
70198 (void *)class->contending_point[i]);
70199 seq_printf(m, "%40s %14lu %29s %pS\n",
70200 name, stats->contending_point[i],
70201diff --git a/kernel/module.c b/kernel/module.c
70202index 6e48c3a..ac2ef5b 100644
70203--- a/kernel/module.c
70204+++ b/kernel/module.c
70205@@ -59,6 +59,7 @@
70206 #include <linux/pfn.h>
70207 #include <linux/bsearch.h>
70208 #include <linux/fips.h>
70209+#include <linux/grsecurity.h>
70210 #include "module-internal.h"
70211
70212 #define CREATE_TRACE_POINTS
70213@@ -153,7 +154,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
70214
70215 /* Bounds of module allocation, for speeding __module_address.
70216 * Protected by module_mutex. */
70217-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
70218+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
70219+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
70220
70221 int register_module_notifier(struct notifier_block * nb)
70222 {
70223@@ -318,7 +320,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
70224 return true;
70225
70226 list_for_each_entry_rcu(mod, &modules, list) {
70227- struct symsearch arr[] = {
70228+ struct symsearch modarr[] = {
70229 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
70230 NOT_GPL_ONLY, false },
70231 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
70232@@ -340,7 +342,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
70233 #endif
70234 };
70235
70236- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
70237+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
70238 return true;
70239 }
70240 return false;
70241@@ -472,7 +474,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
70242 static int percpu_modalloc(struct module *mod,
70243 unsigned long size, unsigned long align)
70244 {
70245- if (align > PAGE_SIZE) {
70246+ if (align-1 >= PAGE_SIZE) {
70247 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
70248 mod->name, align, PAGE_SIZE);
70249 align = PAGE_SIZE;
70250@@ -1072,7 +1074,7 @@ struct module_attribute module_uevent =
70251 static ssize_t show_coresize(struct module_attribute *mattr,
70252 struct module_kobject *mk, char *buffer)
70253 {
70254- return sprintf(buffer, "%u\n", mk->mod->core_size);
70255+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
70256 }
70257
70258 static struct module_attribute modinfo_coresize =
70259@@ -1081,7 +1083,7 @@ static struct module_attribute modinfo_coresize =
70260 static ssize_t show_initsize(struct module_attribute *mattr,
70261 struct module_kobject *mk, char *buffer)
70262 {
70263- return sprintf(buffer, "%u\n", mk->mod->init_size);
70264+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
70265 }
70266
70267 static struct module_attribute modinfo_initsize =
70268@@ -1295,7 +1297,7 @@ resolve_symbol_wait(struct module *mod,
70269 */
70270 #ifdef CONFIG_SYSFS
70271
70272-#ifdef CONFIG_KALLSYMS
70273+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
70274 static inline bool sect_empty(const Elf_Shdr *sect)
70275 {
70276 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
70277@@ -1761,21 +1763,21 @@ static void set_section_ro_nx(void *base,
70278
70279 static void unset_module_core_ro_nx(struct module *mod)
70280 {
70281- set_page_attributes(mod->module_core + mod->core_text_size,
70282- mod->module_core + mod->core_size,
70283+ set_page_attributes(mod->module_core_rw,
70284+ mod->module_core_rw + mod->core_size_rw,
70285 set_memory_x);
70286- set_page_attributes(mod->module_core,
70287- mod->module_core + mod->core_ro_size,
70288+ set_page_attributes(mod->module_core_rx,
70289+ mod->module_core_rx + mod->core_size_rx,
70290 set_memory_rw);
70291 }
70292
70293 static void unset_module_init_ro_nx(struct module *mod)
70294 {
70295- set_page_attributes(mod->module_init + mod->init_text_size,
70296- mod->module_init + mod->init_size,
70297+ set_page_attributes(mod->module_init_rw,
70298+ mod->module_init_rw + mod->init_size_rw,
70299 set_memory_x);
70300- set_page_attributes(mod->module_init,
70301- mod->module_init + mod->init_ro_size,
70302+ set_page_attributes(mod->module_init_rx,
70303+ mod->module_init_rx + mod->init_size_rx,
70304 set_memory_rw);
70305 }
70306
70307@@ -1786,14 +1788,14 @@ void set_all_modules_text_rw(void)
70308
70309 mutex_lock(&module_mutex);
70310 list_for_each_entry_rcu(mod, &modules, list) {
70311- if ((mod->module_core) && (mod->core_text_size)) {
70312- set_page_attributes(mod->module_core,
70313- mod->module_core + mod->core_text_size,
70314+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
70315+ set_page_attributes(mod->module_core_rx,
70316+ mod->module_core_rx + mod->core_size_rx,
70317 set_memory_rw);
70318 }
70319- if ((mod->module_init) && (mod->init_text_size)) {
70320- set_page_attributes(mod->module_init,
70321- mod->module_init + mod->init_text_size,
70322+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
70323+ set_page_attributes(mod->module_init_rx,
70324+ mod->module_init_rx + mod->init_size_rx,
70325 set_memory_rw);
70326 }
70327 }
70328@@ -1807,14 +1809,14 @@ void set_all_modules_text_ro(void)
70329
70330 mutex_lock(&module_mutex);
70331 list_for_each_entry_rcu(mod, &modules, list) {
70332- if ((mod->module_core) && (mod->core_text_size)) {
70333- set_page_attributes(mod->module_core,
70334- mod->module_core + mod->core_text_size,
70335+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
70336+ set_page_attributes(mod->module_core_rx,
70337+ mod->module_core_rx + mod->core_size_rx,
70338 set_memory_ro);
70339 }
70340- if ((mod->module_init) && (mod->init_text_size)) {
70341- set_page_attributes(mod->module_init,
70342- mod->module_init + mod->init_text_size,
70343+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
70344+ set_page_attributes(mod->module_init_rx,
70345+ mod->module_init_rx + mod->init_size_rx,
70346 set_memory_ro);
70347 }
70348 }
70349@@ -1860,16 +1862,19 @@ static void free_module(struct module *mod)
70350
70351 /* This may be NULL, but that's OK */
70352 unset_module_init_ro_nx(mod);
70353- module_free(mod, mod->module_init);
70354+ module_free(mod, mod->module_init_rw);
70355+ module_free_exec(mod, mod->module_init_rx);
70356 kfree(mod->args);
70357 percpu_modfree(mod);
70358
70359 /* Free lock-classes: */
70360- lockdep_free_key_range(mod->module_core, mod->core_size);
70361+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
70362+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
70363
70364 /* Finally, free the core (containing the module structure) */
70365 unset_module_core_ro_nx(mod);
70366- module_free(mod, mod->module_core);
70367+ module_free_exec(mod, mod->module_core_rx);
70368+ module_free(mod, mod->module_core_rw);
70369
70370 #ifdef CONFIG_MPU
70371 update_protections(current->mm);
70372@@ -1939,9 +1944,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
70373 int ret = 0;
70374 const struct kernel_symbol *ksym;
70375
70376+#ifdef CONFIG_GRKERNSEC_MODHARDEN
70377+ int is_fs_load = 0;
70378+ int register_filesystem_found = 0;
70379+ char *p;
70380+
70381+ p = strstr(mod->args, "grsec_modharden_fs");
70382+ if (p) {
70383+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
70384+ /* copy \0 as well */
70385+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
70386+ is_fs_load = 1;
70387+ }
70388+#endif
70389+
70390 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
70391 const char *name = info->strtab + sym[i].st_name;
70392
70393+#ifdef CONFIG_GRKERNSEC_MODHARDEN
70394+ /* it's a real shame this will never get ripped and copied
70395+ upstream! ;(
70396+ */
70397+ if (is_fs_load && !strcmp(name, "register_filesystem"))
70398+ register_filesystem_found = 1;
70399+#endif
70400+
70401 switch (sym[i].st_shndx) {
70402 case SHN_COMMON:
70403 /* We compiled with -fno-common. These are not
70404@@ -1962,7 +1989,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
70405 ksym = resolve_symbol_wait(mod, info, name);
70406 /* Ok if resolved. */
70407 if (ksym && !IS_ERR(ksym)) {
70408+ pax_open_kernel();
70409 sym[i].st_value = ksym->value;
70410+ pax_close_kernel();
70411 break;
70412 }
70413
70414@@ -1981,11 +2010,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
70415 secbase = (unsigned long)mod_percpu(mod);
70416 else
70417 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
70418+ pax_open_kernel();
70419 sym[i].st_value += secbase;
70420+ pax_close_kernel();
70421 break;
70422 }
70423 }
70424
70425+#ifdef CONFIG_GRKERNSEC_MODHARDEN
70426+ if (is_fs_load && !register_filesystem_found) {
70427+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
70428+ ret = -EPERM;
70429+ }
70430+#endif
70431+
70432 return ret;
70433 }
70434
70435@@ -2069,22 +2107,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
70436 || s->sh_entsize != ~0UL
70437 || strstarts(sname, ".init"))
70438 continue;
70439- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
70440+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
70441+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
70442+ else
70443+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
70444 pr_debug("\t%s\n", sname);
70445 }
70446- switch (m) {
70447- case 0: /* executable */
70448- mod->core_size = debug_align(mod->core_size);
70449- mod->core_text_size = mod->core_size;
70450- break;
70451- case 1: /* RO: text and ro-data */
70452- mod->core_size = debug_align(mod->core_size);
70453- mod->core_ro_size = mod->core_size;
70454- break;
70455- case 3: /* whole core */
70456- mod->core_size = debug_align(mod->core_size);
70457- break;
70458- }
70459 }
70460
70461 pr_debug("Init section allocation order:\n");
70462@@ -2098,23 +2126,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
70463 || s->sh_entsize != ~0UL
70464 || !strstarts(sname, ".init"))
70465 continue;
70466- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
70467- | INIT_OFFSET_MASK);
70468+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
70469+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
70470+ else
70471+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
70472+ s->sh_entsize |= INIT_OFFSET_MASK;
70473 pr_debug("\t%s\n", sname);
70474 }
70475- switch (m) {
70476- case 0: /* executable */
70477- mod->init_size = debug_align(mod->init_size);
70478- mod->init_text_size = mod->init_size;
70479- break;
70480- case 1: /* RO: text and ro-data */
70481- mod->init_size = debug_align(mod->init_size);
70482- mod->init_ro_size = mod->init_size;
70483- break;
70484- case 3: /* whole init */
70485- mod->init_size = debug_align(mod->init_size);
70486- break;
70487- }
70488 }
70489 }
70490
70491@@ -2286,7 +2304,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
70492
70493 /* Put symbol section at end of init part of module. */
70494 symsect->sh_flags |= SHF_ALLOC;
70495- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
70496+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
70497 info->index.sym) | INIT_OFFSET_MASK;
70498 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
70499
70500@@ -2306,13 +2324,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
70501 }
70502
70503 /* Append room for core symbols at end of core part. */
70504- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
70505- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
70506- mod->core_size += strtab_size;
70507+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
70508+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
70509+ mod->core_size_rx += strtab_size;
70510
70511 /* Put string table section at end of init part of module. */
70512 strsect->sh_flags |= SHF_ALLOC;
70513- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
70514+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
70515 info->index.str) | INIT_OFFSET_MASK;
70516 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
70517 }
70518@@ -2330,12 +2348,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
70519 /* Make sure we get permanent strtab: don't use info->strtab. */
70520 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
70521
70522+ pax_open_kernel();
70523+
70524 /* Set types up while we still have access to sections. */
70525 for (i = 0; i < mod->num_symtab; i++)
70526 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
70527
70528- mod->core_symtab = dst = mod->module_core + info->symoffs;
70529- mod->core_strtab = s = mod->module_core + info->stroffs;
70530+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
70531+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
70532 src = mod->symtab;
70533 *s++ = 0;
70534 for (ndst = i = 0; i < mod->num_symtab; i++) {
70535@@ -2348,6 +2368,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
70536 }
70537 }
70538 mod->core_num_syms = ndst;
70539+
70540+ pax_close_kernel();
70541 }
70542 #else
70543 static inline void layout_symtab(struct module *mod, struct load_info *info)
70544@@ -2381,17 +2403,33 @@ void * __weak module_alloc(unsigned long size)
70545 return size == 0 ? NULL : vmalloc_exec(size);
70546 }
70547
70548-static void *module_alloc_update_bounds(unsigned long size)
70549+static void *module_alloc_update_bounds_rw(unsigned long size)
70550 {
70551 void *ret = module_alloc(size);
70552
70553 if (ret) {
70554 mutex_lock(&module_mutex);
70555 /* Update module bounds. */
70556- if ((unsigned long)ret < module_addr_min)
70557- module_addr_min = (unsigned long)ret;
70558- if ((unsigned long)ret + size > module_addr_max)
70559- module_addr_max = (unsigned long)ret + size;
70560+ if ((unsigned long)ret < module_addr_min_rw)
70561+ module_addr_min_rw = (unsigned long)ret;
70562+ if ((unsigned long)ret + size > module_addr_max_rw)
70563+ module_addr_max_rw = (unsigned long)ret + size;
70564+ mutex_unlock(&module_mutex);
70565+ }
70566+ return ret;
70567+}
70568+
70569+static void *module_alloc_update_bounds_rx(unsigned long size)
70570+{
70571+ void *ret = module_alloc_exec(size);
70572+
70573+ if (ret) {
70574+ mutex_lock(&module_mutex);
70575+ /* Update module bounds. */
70576+ if ((unsigned long)ret < module_addr_min_rx)
70577+ module_addr_min_rx = (unsigned long)ret;
70578+ if ((unsigned long)ret + size > module_addr_max_rx)
70579+ module_addr_max_rx = (unsigned long)ret + size;
70580 mutex_unlock(&module_mutex);
70581 }
70582 return ret;
70583@@ -2610,8 +2648,14 @@ static struct module *setup_load_info(struct load_info *info)
70584 static int check_modinfo(struct module *mod, struct load_info *info)
70585 {
70586 const char *modmagic = get_modinfo(info, "vermagic");
70587+ const char *license = get_modinfo(info, "license");
70588 int err;
70589
70590+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
70591+ if (!license || !license_is_gpl_compatible(license))
70592+ return -ENOEXEC;
70593+#endif
70594+
70595 /* This is allowed: modprobe --force will invalidate it. */
70596 if (!modmagic) {
70597 err = try_to_force_load(mod, "bad vermagic");
70598@@ -2634,7 +2678,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
70599 }
70600
70601 /* Set up license info based on the info section */
70602- set_license(mod, get_modinfo(info, "license"));
70603+ set_license(mod, license);
70604
70605 return 0;
70606 }
70607@@ -2728,7 +2772,7 @@ static int move_module(struct module *mod, struct load_info *info)
70608 void *ptr;
70609
70610 /* Do the allocs. */
70611- ptr = module_alloc_update_bounds(mod->core_size);
70612+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
70613 /*
70614 * The pointer to this block is stored in the module structure
70615 * which is inside the block. Just mark it as not being a
70616@@ -2738,23 +2782,50 @@ static int move_module(struct module *mod, struct load_info *info)
70617 if (!ptr)
70618 return -ENOMEM;
70619
70620- memset(ptr, 0, mod->core_size);
70621- mod->module_core = ptr;
70622+ memset(ptr, 0, mod->core_size_rw);
70623+ mod->module_core_rw = ptr;
70624
70625- ptr = module_alloc_update_bounds(mod->init_size);
70626+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
70627 /*
70628 * The pointer to this block is stored in the module structure
70629 * which is inside the block. This block doesn't need to be
70630 * scanned as it contains data and code that will be freed
70631 * after the module is initialized.
70632 */
70633- kmemleak_ignore(ptr);
70634- if (!ptr && mod->init_size) {
70635- module_free(mod, mod->module_core);
70636+ kmemleak_not_leak(ptr);
70637+ if (!ptr && mod->init_size_rw) {
70638+ module_free(mod, mod->module_core_rw);
70639 return -ENOMEM;
70640 }
70641- memset(ptr, 0, mod->init_size);
70642- mod->module_init = ptr;
70643+ memset(ptr, 0, mod->init_size_rw);
70644+ mod->module_init_rw = ptr;
70645+
70646+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
70647+ kmemleak_not_leak(ptr);
70648+ if (!ptr) {
70649+ module_free(mod, mod->module_init_rw);
70650+ module_free(mod, mod->module_core_rw);
70651+ return -ENOMEM;
70652+ }
70653+
70654+ pax_open_kernel();
70655+ memset(ptr, 0, mod->core_size_rx);
70656+ pax_close_kernel();
70657+ mod->module_core_rx = ptr;
70658+
70659+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
70660+ kmemleak_not_leak(ptr);
70661+ if (!ptr && mod->init_size_rx) {
70662+ module_free_exec(mod, mod->module_core_rx);
70663+ module_free(mod, mod->module_init_rw);
70664+ module_free(mod, mod->module_core_rw);
70665+ return -ENOMEM;
70666+ }
70667+
70668+ pax_open_kernel();
70669+ memset(ptr, 0, mod->init_size_rx);
70670+ pax_close_kernel();
70671+ mod->module_init_rx = ptr;
70672
70673 /* Transfer each section which specifies SHF_ALLOC */
70674 pr_debug("final section addresses:\n");
70675@@ -2765,16 +2836,45 @@ static int move_module(struct module *mod, struct load_info *info)
70676 if (!(shdr->sh_flags & SHF_ALLOC))
70677 continue;
70678
70679- if (shdr->sh_entsize & INIT_OFFSET_MASK)
70680- dest = mod->module_init
70681- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
70682- else
70683- dest = mod->module_core + shdr->sh_entsize;
70684+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
70685+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
70686+ dest = mod->module_init_rw
70687+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
70688+ else
70689+ dest = mod->module_init_rx
70690+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
70691+ } else {
70692+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
70693+ dest = mod->module_core_rw + shdr->sh_entsize;
70694+ else
70695+ dest = mod->module_core_rx + shdr->sh_entsize;
70696+ }
70697+
70698+ if (shdr->sh_type != SHT_NOBITS) {
70699+
70700+#ifdef CONFIG_PAX_KERNEXEC
70701+#ifdef CONFIG_X86_64
70702+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
70703+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
70704+#endif
70705+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
70706+ pax_open_kernel();
70707+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
70708+ pax_close_kernel();
70709+ } else
70710+#endif
70711
70712- if (shdr->sh_type != SHT_NOBITS)
70713 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
70714+ }
70715 /* Update sh_addr to point to copy in image. */
70716- shdr->sh_addr = (unsigned long)dest;
70717+
70718+#ifdef CONFIG_PAX_KERNEXEC
70719+ if (shdr->sh_flags & SHF_EXECINSTR)
70720+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
70721+ else
70722+#endif
70723+
70724+ shdr->sh_addr = (unsigned long)dest;
70725 pr_debug("\t0x%lx %s\n",
70726 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
70727 }
70728@@ -2829,12 +2929,12 @@ static void flush_module_icache(const struct module *mod)
70729 * Do it before processing of module parameters, so the module
70730 * can provide parameter accessor functions of its own.
70731 */
70732- if (mod->module_init)
70733- flush_icache_range((unsigned long)mod->module_init,
70734- (unsigned long)mod->module_init
70735- + mod->init_size);
70736- flush_icache_range((unsigned long)mod->module_core,
70737- (unsigned long)mod->module_core + mod->core_size);
70738+ if (mod->module_init_rx)
70739+ flush_icache_range((unsigned long)mod->module_init_rx,
70740+ (unsigned long)mod->module_init_rx
70741+ + mod->init_size_rx);
70742+ flush_icache_range((unsigned long)mod->module_core_rx,
70743+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
70744
70745 set_fs(old_fs);
70746 }
70747@@ -2904,8 +3004,10 @@ out:
70748 static void module_deallocate(struct module *mod, struct load_info *info)
70749 {
70750 percpu_modfree(mod);
70751- module_free(mod, mod->module_init);
70752- module_free(mod, mod->module_core);
70753+ module_free_exec(mod, mod->module_init_rx);
70754+ module_free_exec(mod, mod->module_core_rx);
70755+ module_free(mod, mod->module_init_rw);
70756+ module_free(mod, mod->module_core_rw);
70757 }
70758
70759 int __weak module_finalize(const Elf_Ehdr *hdr,
70760@@ -2918,7 +3020,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
70761 static int post_relocation(struct module *mod, const struct load_info *info)
70762 {
70763 /* Sort exception table now relocations are done. */
70764+ pax_open_kernel();
70765 sort_extable(mod->extable, mod->extable + mod->num_exentries);
70766+ pax_close_kernel();
70767
70768 /* Copy relocated percpu area over. */
70769 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
70770@@ -2989,9 +3093,38 @@ static struct module *load_module(void __user *umod,
70771 if (err)
70772 goto free_unload;
70773
70774+ /* Now copy in args */
70775+ mod->args = strndup_user(uargs, ~0UL >> 1);
70776+ if (IS_ERR(mod->args)) {
70777+ err = PTR_ERR(mod->args);
70778+ goto free_unload;
70779+ }
70780+
70781 /* Set up MODINFO_ATTR fields */
70782 setup_modinfo(mod, &info);
70783
70784+#ifdef CONFIG_GRKERNSEC_MODHARDEN
70785+ {
70786+ char *p, *p2;
70787+
70788+ if (strstr(mod->args, "grsec_modharden_netdev")) {
70789+ 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);
70790+ err = -EPERM;
70791+ goto free_modinfo;
70792+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
70793+ p += sizeof("grsec_modharden_normal") - 1;
70794+ p2 = strstr(p, "_");
70795+ if (p2) {
70796+ *p2 = '\0';
70797+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
70798+ *p2 = '_';
70799+ }
70800+ err = -EPERM;
70801+ goto free_modinfo;
70802+ }
70803+ }
70804+#endif
70805+
70806 /* Fix up syms, so that st_value is a pointer to location. */
70807 err = simplify_symbols(mod, &info);
70808 if (err < 0)
70809@@ -3007,13 +3140,6 @@ static struct module *load_module(void __user *umod,
70810
70811 flush_module_icache(mod);
70812
70813- /* Now copy in args */
70814- mod->args = strndup_user(uargs, ~0UL >> 1);
70815- if (IS_ERR(mod->args)) {
70816- err = PTR_ERR(mod->args);
70817- goto free_arch_cleanup;
70818- }
70819-
70820 /* Mark state as coming so strong_try_module_get() ignores us. */
70821 mod->state = MODULE_STATE_COMING;
70822
70823@@ -3081,11 +3207,11 @@ again:
70824 unlock:
70825 mutex_unlock(&module_mutex);
70826 synchronize_sched();
70827- kfree(mod->args);
70828 free_arch_cleanup:
70829 module_arch_cleanup(mod);
70830 free_modinfo:
70831 free_modinfo(mod);
70832+ kfree(mod->args);
70833 free_unload:
70834 module_unload_free(mod);
70835 free_module:
70836@@ -3126,16 +3252,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
70837 MODULE_STATE_COMING, mod);
70838
70839 /* Set RO and NX regions for core */
70840- set_section_ro_nx(mod->module_core,
70841- mod->core_text_size,
70842- mod->core_ro_size,
70843- mod->core_size);
70844+ set_section_ro_nx(mod->module_core_rx,
70845+ mod->core_size_rx,
70846+ mod->core_size_rx,
70847+ mod->core_size_rx);
70848
70849 /* Set RO and NX regions for init */
70850- set_section_ro_nx(mod->module_init,
70851- mod->init_text_size,
70852- mod->init_ro_size,
70853- mod->init_size);
70854+ set_section_ro_nx(mod->module_init_rx,
70855+ mod->init_size_rx,
70856+ mod->init_size_rx,
70857+ mod->init_size_rx);
70858
70859 do_mod_ctors(mod);
70860 /* Start the module */
70861@@ -3180,11 +3306,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
70862 mod->strtab = mod->core_strtab;
70863 #endif
70864 unset_module_init_ro_nx(mod);
70865- module_free(mod, mod->module_init);
70866- mod->module_init = NULL;
70867- mod->init_size = 0;
70868- mod->init_ro_size = 0;
70869- mod->init_text_size = 0;
70870+ module_free(mod, mod->module_init_rw);
70871+ module_free_exec(mod, mod->module_init_rx);
70872+ mod->module_init_rw = NULL;
70873+ mod->module_init_rx = NULL;
70874+ mod->init_size_rw = 0;
70875+ mod->init_size_rx = 0;
70876 mutex_unlock(&module_mutex);
70877 wake_up_all(&module_wq);
70878
70879@@ -3216,10 +3343,16 @@ static const char *get_ksymbol(struct module *mod,
70880 unsigned long nextval;
70881
70882 /* At worse, next value is at end of module */
70883- if (within_module_init(addr, mod))
70884- nextval = (unsigned long)mod->module_init+mod->init_text_size;
70885+ if (within_module_init_rx(addr, mod))
70886+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
70887+ else if (within_module_init_rw(addr, mod))
70888+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
70889+ else if (within_module_core_rx(addr, mod))
70890+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
70891+ else if (within_module_core_rw(addr, mod))
70892+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
70893 else
70894- nextval = (unsigned long)mod->module_core+mod->core_text_size;
70895+ return NULL;
70896
70897 /* Scan for closest preceding symbol, and next symbol. (ELF
70898 starts real symbols at 1). */
70899@@ -3454,7 +3587,7 @@ static int m_show(struct seq_file *m, void *p)
70900 char buf[8];
70901
70902 seq_printf(m, "%s %u",
70903- mod->name, mod->init_size + mod->core_size);
70904+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
70905 print_unload_info(m, mod);
70906
70907 /* Informative for users. */
70908@@ -3463,7 +3596,7 @@ static int m_show(struct seq_file *m, void *p)
70909 mod->state == MODULE_STATE_COMING ? "Loading":
70910 "Live");
70911 /* Used by oprofile and other similar tools. */
70912- seq_printf(m, " 0x%pK", mod->module_core);
70913+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
70914
70915 /* Taints info */
70916 if (mod->taints)
70917@@ -3499,7 +3632,17 @@ static const struct file_operations proc_modules_operations = {
70918
70919 static int __init proc_modules_init(void)
70920 {
70921+#ifndef CONFIG_GRKERNSEC_HIDESYM
70922+#ifdef CONFIG_GRKERNSEC_PROC_USER
70923+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
70924+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
70925+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
70926+#else
70927 proc_create("modules", 0, NULL, &proc_modules_operations);
70928+#endif
70929+#else
70930+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
70931+#endif
70932 return 0;
70933 }
70934 module_init(proc_modules_init);
70935@@ -3558,12 +3701,12 @@ struct module *__module_address(unsigned long addr)
70936 {
70937 struct module *mod;
70938
70939- if (addr < module_addr_min || addr > module_addr_max)
70940+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
70941+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
70942 return NULL;
70943
70944 list_for_each_entry_rcu(mod, &modules, list)
70945- if (within_module_core(addr, mod)
70946- || within_module_init(addr, mod))
70947+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
70948 return mod;
70949 return NULL;
70950 }
70951@@ -3597,11 +3740,20 @@ bool is_module_text_address(unsigned long addr)
70952 */
70953 struct module *__module_text_address(unsigned long addr)
70954 {
70955- struct module *mod = __module_address(addr);
70956+ struct module *mod;
70957+
70958+#ifdef CONFIG_X86_32
70959+ addr = ktla_ktva(addr);
70960+#endif
70961+
70962+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
70963+ return NULL;
70964+
70965+ mod = __module_address(addr);
70966+
70967 if (mod) {
70968 /* Make sure it's within the text section. */
70969- if (!within(addr, mod->module_init, mod->init_text_size)
70970- && !within(addr, mod->module_core, mod->core_text_size))
70971+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
70972 mod = NULL;
70973 }
70974 return mod;
70975diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
70976index 7e3443f..b2a1e6b 100644
70977--- a/kernel/mutex-debug.c
70978+++ b/kernel/mutex-debug.c
70979@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
70980 }
70981
70982 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
70983- struct thread_info *ti)
70984+ struct task_struct *task)
70985 {
70986 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
70987
70988 /* Mark the current thread as blocked on the lock: */
70989- ti->task->blocked_on = waiter;
70990+ task->blocked_on = waiter;
70991 }
70992
70993 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
70994- struct thread_info *ti)
70995+ struct task_struct *task)
70996 {
70997 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
70998- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
70999- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
71000- ti->task->blocked_on = NULL;
71001+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
71002+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
71003+ task->blocked_on = NULL;
71004
71005 list_del_init(&waiter->list);
71006 waiter->task = NULL;
71007diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
71008index 0799fd3..d06ae3b 100644
71009--- a/kernel/mutex-debug.h
71010+++ b/kernel/mutex-debug.h
71011@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
71012 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
71013 extern void debug_mutex_add_waiter(struct mutex *lock,
71014 struct mutex_waiter *waiter,
71015- struct thread_info *ti);
71016+ struct task_struct *task);
71017 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
71018- struct thread_info *ti);
71019+ struct task_struct *task);
71020 extern void debug_mutex_unlock(struct mutex *lock);
71021 extern void debug_mutex_init(struct mutex *lock, const char *name,
71022 struct lock_class_key *key);
71023diff --git a/kernel/mutex.c b/kernel/mutex.c
71024index a307cc9..27fd2e9 100644
71025--- a/kernel/mutex.c
71026+++ b/kernel/mutex.c
71027@@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
71028 spin_lock_mutex(&lock->wait_lock, flags);
71029
71030 debug_mutex_lock_common(lock, &waiter);
71031- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
71032+ debug_mutex_add_waiter(lock, &waiter, task);
71033
71034 /* add waiting tasks to the end of the waitqueue (FIFO): */
71035 list_add_tail(&waiter.list, &lock->wait_list);
71036@@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
71037 * TASK_UNINTERRUPTIBLE case.)
71038 */
71039 if (unlikely(signal_pending_state(state, task))) {
71040- mutex_remove_waiter(lock, &waiter,
71041- task_thread_info(task));
71042+ mutex_remove_waiter(lock, &waiter, task);
71043 mutex_release(&lock->dep_map, 1, ip);
71044 spin_unlock_mutex(&lock->wait_lock, flags);
71045
71046@@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
71047 done:
71048 lock_acquired(&lock->dep_map, ip);
71049 /* got the lock - rejoice! */
71050- mutex_remove_waiter(lock, &waiter, current_thread_info());
71051+ mutex_remove_waiter(lock, &waiter, task);
71052 mutex_set_owner(lock);
71053
71054 /* set it to 0 if there are no waiters left: */
71055diff --git a/kernel/notifier.c b/kernel/notifier.c
71056index 2d5cc4c..d9ea600 100644
71057--- a/kernel/notifier.c
71058+++ b/kernel/notifier.c
71059@@ -5,6 +5,7 @@
71060 #include <linux/rcupdate.h>
71061 #include <linux/vmalloc.h>
71062 #include <linux/reboot.h>
71063+#include <linux/mm.h>
71064
71065 /*
71066 * Notifier list for kernel code which wants to be called
71067@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
71068 while ((*nl) != NULL) {
71069 if (n->priority > (*nl)->priority)
71070 break;
71071- nl = &((*nl)->next);
71072+ nl = (struct notifier_block **)&((*nl)->next);
71073 }
71074- n->next = *nl;
71075+ pax_open_kernel();
71076+ *(const void **)&n->next = *nl;
71077 rcu_assign_pointer(*nl, n);
71078+ pax_close_kernel();
71079 return 0;
71080 }
71081
71082@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
71083 return 0;
71084 if (n->priority > (*nl)->priority)
71085 break;
71086- nl = &((*nl)->next);
71087+ nl = (struct notifier_block **)&((*nl)->next);
71088 }
71089- n->next = *nl;
71090+ pax_open_kernel();
71091+ *(const void **)&n->next = *nl;
71092 rcu_assign_pointer(*nl, n);
71093+ pax_close_kernel();
71094 return 0;
71095 }
71096
71097@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
71098 {
71099 while ((*nl) != NULL) {
71100 if ((*nl) == n) {
71101+ pax_open_kernel();
71102 rcu_assign_pointer(*nl, n->next);
71103+ pax_close_kernel();
71104 return 0;
71105 }
71106- nl = &((*nl)->next);
71107+ nl = (struct notifier_block **)&((*nl)->next);
71108 }
71109 return -ENOENT;
71110 }
71111diff --git a/kernel/panic.c b/kernel/panic.c
71112index e1b2822..5edc1d9 100644
71113--- a/kernel/panic.c
71114+++ b/kernel/panic.c
71115@@ -410,7 +410,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
71116 const char *board;
71117
71118 printk(KERN_WARNING "------------[ cut here ]------------\n");
71119- printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
71120+ printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
71121 board = dmi_get_system_info(DMI_PRODUCT_NAME);
71122 if (board)
71123 printk(KERN_WARNING "Hardware name: %s\n", board);
71124@@ -465,7 +465,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
71125 */
71126 void __stack_chk_fail(void)
71127 {
71128- panic("stack-protector: Kernel stack is corrupted in: %p\n",
71129+ dump_stack();
71130+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
71131 __builtin_return_address(0));
71132 }
71133 EXPORT_SYMBOL(__stack_chk_fail);
71134diff --git a/kernel/pid.c b/kernel/pid.c
71135index aebd4f5..1693c13 100644
71136--- a/kernel/pid.c
71137+++ b/kernel/pid.c
71138@@ -33,6 +33,7 @@
71139 #include <linux/rculist.h>
71140 #include <linux/bootmem.h>
71141 #include <linux/hash.h>
71142+#include <linux/security.h>
71143 #include <linux/pid_namespace.h>
71144 #include <linux/init_task.h>
71145 #include <linux/syscalls.h>
71146@@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
71147
71148 int pid_max = PID_MAX_DEFAULT;
71149
71150-#define RESERVED_PIDS 300
71151+#define RESERVED_PIDS 500
71152
71153 int pid_max_min = RESERVED_PIDS + 1;
71154 int pid_max_max = PID_MAX_LIMIT;
71155@@ -420,10 +421,18 @@ EXPORT_SYMBOL(pid_task);
71156 */
71157 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
71158 {
71159+ struct task_struct *task;
71160+
71161 rcu_lockdep_assert(rcu_read_lock_held(),
71162 "find_task_by_pid_ns() needs rcu_read_lock()"
71163 " protection");
71164- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
71165+
71166+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
71167+
71168+ if (gr_pid_is_chrooted(task))
71169+ return NULL;
71170+
71171+ return task;
71172 }
71173
71174 struct task_struct *find_task_by_vpid(pid_t vnr)
71175@@ -431,6 +440,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
71176 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
71177 }
71178
71179+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
71180+{
71181+ rcu_lockdep_assert(rcu_read_lock_held(),
71182+ "find_task_by_pid_ns() needs rcu_read_lock()"
71183+ " protection");
71184+ return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
71185+}
71186+
71187 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
71188 {
71189 struct pid *pid;
71190diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
71191index 125cb67..2e5c8ad 100644
71192--- a/kernel/posix-cpu-timers.c
71193+++ b/kernel/posix-cpu-timers.c
71194@@ -6,9 +6,11 @@
71195 #include <linux/posix-timers.h>
71196 #include <linux/errno.h>
71197 #include <linux/math64.h>
71198+#include <linux/security.h>
71199 #include <asm/uaccess.h>
71200 #include <linux/kernel_stat.h>
71201 #include <trace/events/timer.h>
71202+#include <linux/random.h>
71203
71204 /*
71205 * Called after updating RLIMIT_CPU to run cpu timer and update
71206@@ -494,6 +496,8 @@ static void cleanup_timers(struct list_head *head,
71207 */
71208 void posix_cpu_timers_exit(struct task_struct *tsk)
71209 {
71210+ add_device_randomness((const void*) &tsk->se.sum_exec_runtime,
71211+ sizeof(unsigned long long));
71212 cleanup_timers(tsk->cpu_timers,
71213 tsk->utime, tsk->stime, tsk->se.sum_exec_runtime);
71214
71215@@ -1578,14 +1582,14 @@ struct k_clock clock_posix_cpu = {
71216
71217 static __init int init_posix_cpu_timers(void)
71218 {
71219- struct k_clock process = {
71220+ static struct k_clock process = {
71221 .clock_getres = process_cpu_clock_getres,
71222 .clock_get = process_cpu_clock_get,
71223 .timer_create = process_cpu_timer_create,
71224 .nsleep = process_cpu_nsleep,
71225 .nsleep_restart = process_cpu_nsleep_restart,
71226 };
71227- struct k_clock thread = {
71228+ static struct k_clock thread = {
71229 .clock_getres = thread_cpu_clock_getres,
71230 .clock_get = thread_cpu_clock_get,
71231 .timer_create = thread_cpu_timer_create,
71232diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
71233index 69185ae..cc2847a 100644
71234--- a/kernel/posix-timers.c
71235+++ b/kernel/posix-timers.c
71236@@ -43,6 +43,7 @@
71237 #include <linux/idr.h>
71238 #include <linux/posix-clock.h>
71239 #include <linux/posix-timers.h>
71240+#include <linux/grsecurity.h>
71241 #include <linux/syscalls.h>
71242 #include <linux/wait.h>
71243 #include <linux/workqueue.h>
71244@@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
71245 * which we beg off on and pass to do_sys_settimeofday().
71246 */
71247
71248-static struct k_clock posix_clocks[MAX_CLOCKS];
71249+static struct k_clock *posix_clocks[MAX_CLOCKS];
71250
71251 /*
71252 * These ones are defined below.
71253@@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
71254 */
71255 static __init int init_posix_timers(void)
71256 {
71257- struct k_clock clock_realtime = {
71258+ static struct k_clock clock_realtime = {
71259 .clock_getres = hrtimer_get_res,
71260 .clock_get = posix_clock_realtime_get,
71261 .clock_set = posix_clock_realtime_set,
71262@@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
71263 .timer_get = common_timer_get,
71264 .timer_del = common_timer_del,
71265 };
71266- struct k_clock clock_monotonic = {
71267+ static struct k_clock clock_monotonic = {
71268 .clock_getres = hrtimer_get_res,
71269 .clock_get = posix_ktime_get_ts,
71270 .nsleep = common_nsleep,
71271@@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
71272 .timer_get = common_timer_get,
71273 .timer_del = common_timer_del,
71274 };
71275- struct k_clock clock_monotonic_raw = {
71276+ static struct k_clock clock_monotonic_raw = {
71277 .clock_getres = hrtimer_get_res,
71278 .clock_get = posix_get_monotonic_raw,
71279 };
71280- struct k_clock clock_realtime_coarse = {
71281+ static struct k_clock clock_realtime_coarse = {
71282 .clock_getres = posix_get_coarse_res,
71283 .clock_get = posix_get_realtime_coarse,
71284 };
71285- struct k_clock clock_monotonic_coarse = {
71286+ static struct k_clock clock_monotonic_coarse = {
71287 .clock_getres = posix_get_coarse_res,
71288 .clock_get = posix_get_monotonic_coarse,
71289 };
71290- struct k_clock clock_boottime = {
71291+ static struct k_clock clock_boottime = {
71292 .clock_getres = hrtimer_get_res,
71293 .clock_get = posix_get_boottime,
71294 .nsleep = common_nsleep,
71295@@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
71296 return;
71297 }
71298
71299- posix_clocks[clock_id] = *new_clock;
71300+ posix_clocks[clock_id] = new_clock;
71301 }
71302 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
71303
71304@@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
71305 return (id & CLOCKFD_MASK) == CLOCKFD ?
71306 &clock_posix_dynamic : &clock_posix_cpu;
71307
71308- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
71309+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
71310 return NULL;
71311- return &posix_clocks[id];
71312+ return posix_clocks[id];
71313 }
71314
71315 static int common_timer_create(struct k_itimer *new_timer)
71316@@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
71317 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
71318 return -EFAULT;
71319
71320+ /* only the CLOCK_REALTIME clock can be set, all other clocks
71321+ have their clock_set fptr set to a nosettime dummy function
71322+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
71323+ call common_clock_set, which calls do_sys_settimeofday, which
71324+ we hook
71325+ */
71326+
71327 return kc->clock_set(which_clock, &new_tp);
71328 }
71329
71330diff --git a/kernel/power/process.c b/kernel/power/process.c
71331index 87da817..30ddd13 100644
71332--- a/kernel/power/process.c
71333+++ b/kernel/power/process.c
71334@@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
71335 u64 elapsed_csecs64;
71336 unsigned int elapsed_csecs;
71337 bool wakeup = false;
71338+ bool timedout = false;
71339
71340 do_gettimeofday(&start);
71341
71342@@ -43,6 +44,8 @@ static int try_to_freeze_tasks(bool user_only)
71343
71344 while (true) {
71345 todo = 0;
71346+ if (time_after(jiffies, end_time))
71347+ timedout = true;
71348 read_lock(&tasklist_lock);
71349 do_each_thread(g, p) {
71350 if (p == current || !freeze_task(p))
71351@@ -58,9 +61,13 @@ static int try_to_freeze_tasks(bool user_only)
71352 * guaranteed that TASK_STOPPED/TRACED -> TASK_RUNNING
71353 * transition can't race with task state testing here.
71354 */
71355- if (!task_is_stopped_or_traced(p) &&
71356- !freezer_should_skip(p))
71357+ if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
71358 todo++;
71359+ if (timedout) {
71360+ printk(KERN_ERR "Task refusing to freeze:\n");
71361+ sched_show_task(p);
71362+ }
71363+ }
71364 } while_each_thread(g, p);
71365 read_unlock(&tasklist_lock);
71366
71367@@ -69,7 +76,7 @@ static int try_to_freeze_tasks(bool user_only)
71368 todo += wq_busy;
71369 }
71370
71371- if (!todo || time_after(jiffies, end_time))
71372+ if (!todo || timedout)
71373 break;
71374
71375 if (pm_wakeup_pending()) {
71376diff --git a/kernel/printk.c b/kernel/printk.c
71377index 2d607f4..7413773 100644
71378--- a/kernel/printk.c
71379+++ b/kernel/printk.c
71380@@ -817,6 +817,11 @@ static int check_syslog_permissions(int type, bool from_file)
71381 if (from_file && type != SYSLOG_ACTION_OPEN)
71382 return 0;
71383
71384+#ifdef CONFIG_GRKERNSEC_DMESG
71385+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
71386+ return -EPERM;
71387+#endif
71388+
71389 if (syslog_action_restricted(type)) {
71390 if (capable(CAP_SYSLOG))
71391 return 0;
71392diff --git a/kernel/profile.c b/kernel/profile.c
71393index 76b8e77..a2930e8 100644
71394--- a/kernel/profile.c
71395+++ b/kernel/profile.c
71396@@ -39,7 +39,7 @@ struct profile_hit {
71397 /* Oprofile timer tick hook */
71398 static int (*timer_hook)(struct pt_regs *) __read_mostly;
71399
71400-static atomic_t *prof_buffer;
71401+static atomic_unchecked_t *prof_buffer;
71402 static unsigned long prof_len, prof_shift;
71403
71404 int prof_on __read_mostly;
71405@@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
71406 hits[i].pc = 0;
71407 continue;
71408 }
71409- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
71410+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
71411 hits[i].hits = hits[i].pc = 0;
71412 }
71413 }
71414@@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
71415 * Add the current hit(s) and flush the write-queue out
71416 * to the global buffer:
71417 */
71418- atomic_add(nr_hits, &prof_buffer[pc]);
71419+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
71420 for (i = 0; i < NR_PROFILE_HIT; ++i) {
71421- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
71422+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
71423 hits[i].pc = hits[i].hits = 0;
71424 }
71425 out:
71426@@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
71427 {
71428 unsigned long pc;
71429 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
71430- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
71431+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
71432 }
71433 #endif /* !CONFIG_SMP */
71434
71435@@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
71436 return -EFAULT;
71437 buf++; p++; count--; read++;
71438 }
71439- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
71440+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
71441 if (copy_to_user(buf, (void *)pnt, count))
71442 return -EFAULT;
71443 read += count;
71444@@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
71445 }
71446 #endif
71447 profile_discard_flip_buffers();
71448- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
71449+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
71450 return count;
71451 }
71452
71453diff --git a/kernel/ptrace.c b/kernel/ptrace.c
71454index 1f5e55d..8b8f969 100644
71455--- a/kernel/ptrace.c
71456+++ b/kernel/ptrace.c
71457@@ -280,7 +280,7 @@ static int ptrace_attach(struct task_struct *task, long request,
71458
71459 if (seize)
71460 flags |= PT_SEIZED;
71461- if (ns_capable(task_user_ns(task), CAP_SYS_PTRACE))
71462+ if (ns_capable_nolog(task_user_ns(task), CAP_SYS_PTRACE))
71463 flags |= PT_PTRACE_CAP;
71464 task->ptrace = flags;
71465
71466@@ -487,7 +487,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
71467 break;
71468 return -EIO;
71469 }
71470- if (copy_to_user(dst, buf, retval))
71471+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
71472 return -EFAULT;
71473 copied += retval;
71474 src += retval;
71475@@ -672,7 +672,7 @@ int ptrace_request(struct task_struct *child, long request,
71476 bool seized = child->ptrace & PT_SEIZED;
71477 int ret = -EIO;
71478 siginfo_t siginfo, *si;
71479- void __user *datavp = (void __user *) data;
71480+ void __user *datavp = (__force void __user *) data;
71481 unsigned long __user *datalp = datavp;
71482 unsigned long flags;
71483
71484@@ -874,14 +874,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
71485 goto out;
71486 }
71487
71488+ if (gr_handle_ptrace(child, request)) {
71489+ ret = -EPERM;
71490+ goto out_put_task_struct;
71491+ }
71492+
71493 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
71494 ret = ptrace_attach(child, request, addr, data);
71495 /*
71496 * Some architectures need to do book-keeping after
71497 * a ptrace attach.
71498 */
71499- if (!ret)
71500+ if (!ret) {
71501 arch_ptrace_attach(child);
71502+ gr_audit_ptrace(child);
71503+ }
71504 goto out_put_task_struct;
71505 }
71506
71507@@ -907,7 +914,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
71508 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
71509 if (copied != sizeof(tmp))
71510 return -EIO;
71511- return put_user(tmp, (unsigned long __user *)data);
71512+ return put_user(tmp, (__force unsigned long __user *)data);
71513 }
71514
71515 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
71516@@ -1017,14 +1024,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
71517 goto out;
71518 }
71519
71520+ if (gr_handle_ptrace(child, request)) {
71521+ ret = -EPERM;
71522+ goto out_put_task_struct;
71523+ }
71524+
71525 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
71526 ret = ptrace_attach(child, request, addr, data);
71527 /*
71528 * Some architectures need to do book-keeping after
71529 * a ptrace attach.
71530 */
71531- if (!ret)
71532+ if (!ret) {
71533 arch_ptrace_attach(child);
71534+ gr_audit_ptrace(child);
71535+ }
71536 goto out_put_task_struct;
71537 }
71538
71539diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
71540index e4c6a59..c86621a 100644
71541--- a/kernel/rcutiny.c
71542+++ b/kernel/rcutiny.c
71543@@ -46,7 +46,7 @@
71544 struct rcu_ctrlblk;
71545 static void invoke_rcu_callbacks(void);
71546 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
71547-static void rcu_process_callbacks(struct softirq_action *unused);
71548+static void rcu_process_callbacks(void);
71549 static void __call_rcu(struct rcu_head *head,
71550 void (*func)(struct rcu_head *rcu),
71551 struct rcu_ctrlblk *rcp);
71552@@ -310,7 +310,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
71553 rcu_is_callbacks_kthread()));
71554 }
71555
71556-static void rcu_process_callbacks(struct softirq_action *unused)
71557+static void rcu_process_callbacks(void)
71558 {
71559 __rcu_process_callbacks(&rcu_sched_ctrlblk);
71560 __rcu_process_callbacks(&rcu_bh_ctrlblk);
71561diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
71562index 3d01902..afbf46e 100644
71563--- a/kernel/rcutiny_plugin.h
71564+++ b/kernel/rcutiny_plugin.h
71565@@ -893,7 +893,7 @@ static int rcu_kthread(void *arg)
71566 have_rcu_kthread_work = morework;
71567 local_irq_restore(flags);
71568 if (work)
71569- rcu_process_callbacks(NULL);
71570+ rcu_process_callbacks();
71571 schedule_timeout_interruptible(1); /* Leave CPU for others. */
71572 }
71573
71574diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
71575index aaa7b9f..055ff1e 100644
71576--- a/kernel/rcutorture.c
71577+++ b/kernel/rcutorture.c
71578@@ -163,12 +163,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
71579 { 0 };
71580 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
71581 { 0 };
71582-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
71583-static atomic_t n_rcu_torture_alloc;
71584-static atomic_t n_rcu_torture_alloc_fail;
71585-static atomic_t n_rcu_torture_free;
71586-static atomic_t n_rcu_torture_mberror;
71587-static atomic_t n_rcu_torture_error;
71588+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
71589+static atomic_unchecked_t n_rcu_torture_alloc;
71590+static atomic_unchecked_t n_rcu_torture_alloc_fail;
71591+static atomic_unchecked_t n_rcu_torture_free;
71592+static atomic_unchecked_t n_rcu_torture_mberror;
71593+static atomic_unchecked_t n_rcu_torture_error;
71594 static long n_rcu_torture_barrier_error;
71595 static long n_rcu_torture_boost_ktrerror;
71596 static long n_rcu_torture_boost_rterror;
71597@@ -272,11 +272,11 @@ rcu_torture_alloc(void)
71598
71599 spin_lock_bh(&rcu_torture_lock);
71600 if (list_empty(&rcu_torture_freelist)) {
71601- atomic_inc(&n_rcu_torture_alloc_fail);
71602+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
71603 spin_unlock_bh(&rcu_torture_lock);
71604 return NULL;
71605 }
71606- atomic_inc(&n_rcu_torture_alloc);
71607+ atomic_inc_unchecked(&n_rcu_torture_alloc);
71608 p = rcu_torture_freelist.next;
71609 list_del_init(p);
71610 spin_unlock_bh(&rcu_torture_lock);
71611@@ -289,7 +289,7 @@ rcu_torture_alloc(void)
71612 static void
71613 rcu_torture_free(struct rcu_torture *p)
71614 {
71615- atomic_inc(&n_rcu_torture_free);
71616+ atomic_inc_unchecked(&n_rcu_torture_free);
71617 spin_lock_bh(&rcu_torture_lock);
71618 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
71619 spin_unlock_bh(&rcu_torture_lock);
71620@@ -410,7 +410,7 @@ rcu_torture_cb(struct rcu_head *p)
71621 i = rp->rtort_pipe_count;
71622 if (i > RCU_TORTURE_PIPE_LEN)
71623 i = RCU_TORTURE_PIPE_LEN;
71624- atomic_inc(&rcu_torture_wcount[i]);
71625+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
71626 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
71627 rp->rtort_mbtest = 0;
71628 rcu_torture_free(rp);
71629@@ -459,7 +459,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
71630 i = rp->rtort_pipe_count;
71631 if (i > RCU_TORTURE_PIPE_LEN)
71632 i = RCU_TORTURE_PIPE_LEN;
71633- atomic_inc(&rcu_torture_wcount[i]);
71634+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
71635 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
71636 rp->rtort_mbtest = 0;
71637 list_del(&rp->rtort_free);
71638@@ -1002,7 +1002,7 @@ rcu_torture_writer(void *arg)
71639 i = old_rp->rtort_pipe_count;
71640 if (i > RCU_TORTURE_PIPE_LEN)
71641 i = RCU_TORTURE_PIPE_LEN;
71642- atomic_inc(&rcu_torture_wcount[i]);
71643+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
71644 old_rp->rtort_pipe_count++;
71645 cur_ops->deferred_free(old_rp);
71646 }
71647@@ -1087,7 +1087,7 @@ static void rcu_torture_timer(unsigned long unused)
71648 }
71649 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
71650 if (p->rtort_mbtest == 0)
71651- atomic_inc(&n_rcu_torture_mberror);
71652+ atomic_inc_unchecked(&n_rcu_torture_mberror);
71653 spin_lock(&rand_lock);
71654 cur_ops->read_delay(&rand);
71655 n_rcu_torture_timers++;
71656@@ -1151,7 +1151,7 @@ rcu_torture_reader(void *arg)
71657 }
71658 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
71659 if (p->rtort_mbtest == 0)
71660- atomic_inc(&n_rcu_torture_mberror);
71661+ atomic_inc_unchecked(&n_rcu_torture_mberror);
71662 cur_ops->read_delay(&rand);
71663 preempt_disable();
71664 pipe_count = p->rtort_pipe_count;
71665@@ -1210,11 +1210,11 @@ rcu_torture_printk(char *page)
71666 rcu_torture_current,
71667 rcu_torture_current_version,
71668 list_empty(&rcu_torture_freelist),
71669- atomic_read(&n_rcu_torture_alloc),
71670- atomic_read(&n_rcu_torture_alloc_fail),
71671- atomic_read(&n_rcu_torture_free));
71672+ atomic_read_unchecked(&n_rcu_torture_alloc),
71673+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
71674+ atomic_read_unchecked(&n_rcu_torture_free));
71675 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
71676- atomic_read(&n_rcu_torture_mberror),
71677+ atomic_read_unchecked(&n_rcu_torture_mberror),
71678 n_rcu_torture_boost_ktrerror,
71679 n_rcu_torture_boost_rterror);
71680 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
71681@@ -1233,14 +1233,14 @@ rcu_torture_printk(char *page)
71682 n_barrier_attempts,
71683 n_rcu_torture_barrier_error);
71684 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
71685- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
71686+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
71687 n_rcu_torture_barrier_error != 0 ||
71688 n_rcu_torture_boost_ktrerror != 0 ||
71689 n_rcu_torture_boost_rterror != 0 ||
71690 n_rcu_torture_boost_failure != 0 ||
71691 i > 1) {
71692 cnt += sprintf(&page[cnt], "!!! ");
71693- atomic_inc(&n_rcu_torture_error);
71694+ atomic_inc_unchecked(&n_rcu_torture_error);
71695 WARN_ON_ONCE(1);
71696 }
71697 cnt += sprintf(&page[cnt], "Reader Pipe: ");
71698@@ -1254,7 +1254,7 @@ rcu_torture_printk(char *page)
71699 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
71700 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
71701 cnt += sprintf(&page[cnt], " %d",
71702- atomic_read(&rcu_torture_wcount[i]));
71703+ atomic_read_unchecked(&rcu_torture_wcount[i]));
71704 }
71705 cnt += sprintf(&page[cnt], "\n");
71706 if (cur_ops->stats)
71707@@ -1938,7 +1938,7 @@ rcu_torture_cleanup(void)
71708
71709 if (cur_ops->cleanup)
71710 cur_ops->cleanup();
71711- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
71712+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
71713 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
71714 else if (n_online_successes != n_online_attempts ||
71715 n_offline_successes != n_offline_attempts)
71716@@ -2007,18 +2007,18 @@ rcu_torture_init(void)
71717
71718 rcu_torture_current = NULL;
71719 rcu_torture_current_version = 0;
71720- atomic_set(&n_rcu_torture_alloc, 0);
71721- atomic_set(&n_rcu_torture_alloc_fail, 0);
71722- atomic_set(&n_rcu_torture_free, 0);
71723- atomic_set(&n_rcu_torture_mberror, 0);
71724- atomic_set(&n_rcu_torture_error, 0);
71725+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
71726+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
71727+ atomic_set_unchecked(&n_rcu_torture_free, 0);
71728+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
71729+ atomic_set_unchecked(&n_rcu_torture_error, 0);
71730 n_rcu_torture_barrier_error = 0;
71731 n_rcu_torture_boost_ktrerror = 0;
71732 n_rcu_torture_boost_rterror = 0;
71733 n_rcu_torture_boost_failure = 0;
71734 n_rcu_torture_boosts = 0;
71735 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
71736- atomic_set(&rcu_torture_wcount[i], 0);
71737+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
71738 for_each_possible_cpu(cpu) {
71739 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
71740 per_cpu(rcu_torture_count, cpu)[i] = 0;
71741diff --git a/kernel/rcutree.c b/kernel/rcutree.c
71742index 2682295..0f2297e 100644
71743--- a/kernel/rcutree.c
71744+++ b/kernel/rcutree.c
71745@@ -348,9 +348,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
71746 rcu_prepare_for_idle(smp_processor_id());
71747 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
71748 smp_mb__before_atomic_inc(); /* See above. */
71749- atomic_inc(&rdtp->dynticks);
71750+ atomic_inc_unchecked(&rdtp->dynticks);
71751 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
71752- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
71753+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
71754
71755 /*
71756 * It is illegal to enter an extended quiescent state while
71757@@ -508,10 +508,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
71758 int user)
71759 {
71760 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
71761- atomic_inc(&rdtp->dynticks);
71762+ atomic_inc_unchecked(&rdtp->dynticks);
71763 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
71764 smp_mb__after_atomic_inc(); /* See above. */
71765- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
71766+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
71767 rcu_cleanup_after_idle(smp_processor_id());
71768 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
71769 if (!user && !is_idle_task(current)) {
71770@@ -670,14 +670,14 @@ void rcu_nmi_enter(void)
71771 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
71772
71773 if (rdtp->dynticks_nmi_nesting == 0 &&
71774- (atomic_read(&rdtp->dynticks) & 0x1))
71775+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
71776 return;
71777 rdtp->dynticks_nmi_nesting++;
71778 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
71779- atomic_inc(&rdtp->dynticks);
71780+ atomic_inc_unchecked(&rdtp->dynticks);
71781 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
71782 smp_mb__after_atomic_inc(); /* See above. */
71783- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
71784+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
71785 }
71786
71787 /**
71788@@ -696,9 +696,9 @@ void rcu_nmi_exit(void)
71789 return;
71790 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
71791 smp_mb__before_atomic_inc(); /* See above. */
71792- atomic_inc(&rdtp->dynticks);
71793+ atomic_inc_unchecked(&rdtp->dynticks);
71794 smp_mb__after_atomic_inc(); /* Force delay to next write. */
71795- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
71796+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
71797 }
71798
71799 /**
71800@@ -712,7 +712,7 @@ int rcu_is_cpu_idle(void)
71801 int ret;
71802
71803 preempt_disable();
71804- ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
71805+ ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
71806 preempt_enable();
71807 return ret;
71808 }
71809@@ -795,7 +795,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
71810 */
71811 static int dyntick_save_progress_counter(struct rcu_data *rdp)
71812 {
71813- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
71814+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
71815 return (rdp->dynticks_snap & 0x1) == 0;
71816 }
71817
71818@@ -810,7 +810,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
71819 unsigned int curr;
71820 unsigned int snap;
71821
71822- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
71823+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
71824 snap = (unsigned int)rdp->dynticks_snap;
71825
71826 /*
71827@@ -858,10 +858,10 @@ static int jiffies_till_stall_check(void)
71828 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
71829 */
71830 if (till_stall_check < 3) {
71831- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
71832+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
71833 till_stall_check = 3;
71834 } else if (till_stall_check > 300) {
71835- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
71836+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
71837 till_stall_check = 300;
71838 }
71839 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
71840@@ -1589,7 +1589,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
71841 rsp->qlen += rdp->qlen;
71842 rdp->n_cbs_orphaned += rdp->qlen;
71843 rdp->qlen_lazy = 0;
71844- ACCESS_ONCE(rdp->qlen) = 0;
71845+ ACCESS_ONCE_RW(rdp->qlen) = 0;
71846 }
71847
71848 /*
71849@@ -1831,7 +1831,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
71850 }
71851 smp_mb(); /* List handling before counting for rcu_barrier(). */
71852 rdp->qlen_lazy -= count_lazy;
71853- ACCESS_ONCE(rdp->qlen) -= count;
71854+ ACCESS_ONCE_RW(rdp->qlen) -= count;
71855 rdp->n_cbs_invoked += count;
71856
71857 /* Reinstate batch limit if we have worked down the excess. */
71858@@ -2024,7 +2024,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
71859 /*
71860 * Do RCU core processing for the current CPU.
71861 */
71862-static void rcu_process_callbacks(struct softirq_action *unused)
71863+static void rcu_process_callbacks(void)
71864 {
71865 struct rcu_state *rsp;
71866
71867@@ -2136,7 +2136,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
71868 local_irq_restore(flags);
71869 return;
71870 }
71871- ACCESS_ONCE(rdp->qlen)++;
71872+ ACCESS_ONCE_RW(rdp->qlen)++;
71873 if (lazy)
71874 rdp->qlen_lazy++;
71875 else
71876@@ -2250,8 +2250,8 @@ void synchronize_rcu_bh(void)
71877 }
71878 EXPORT_SYMBOL_GPL(synchronize_rcu_bh);
71879
71880-static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
71881-static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
71882+static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
71883+static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
71884
71885 static int synchronize_sched_expedited_cpu_stop(void *data)
71886 {
71887@@ -2312,7 +2312,7 @@ void synchronize_sched_expedited(void)
71888 int firstsnap, s, snap, trycount = 0;
71889
71890 /* Note that atomic_inc_return() implies full memory barrier. */
71891- firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
71892+ firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
71893 get_online_cpus();
71894 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
71895
71896@@ -2334,7 +2334,7 @@ void synchronize_sched_expedited(void)
71897 }
71898
71899 /* Check to see if someone else did our work for us. */
71900- s = atomic_read(&sync_sched_expedited_done);
71901+ s = atomic_read_unchecked(&sync_sched_expedited_done);
71902 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
71903 smp_mb(); /* ensure test happens before caller kfree */
71904 return;
71905@@ -2349,7 +2349,7 @@ void synchronize_sched_expedited(void)
71906 * grace period works for us.
71907 */
71908 get_online_cpus();
71909- snap = atomic_read(&sync_sched_expedited_started);
71910+ snap = atomic_read_unchecked(&sync_sched_expedited_started);
71911 smp_mb(); /* ensure read is before try_stop_cpus(). */
71912 }
71913
71914@@ -2360,12 +2360,12 @@ void synchronize_sched_expedited(void)
71915 * than we did beat us to the punch.
71916 */
71917 do {
71918- s = atomic_read(&sync_sched_expedited_done);
71919+ s = atomic_read_unchecked(&sync_sched_expedited_done);
71920 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
71921 smp_mb(); /* ensure test happens before caller kfree */
71922 break;
71923 }
71924- } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
71925+ } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
71926
71927 put_online_cpus();
71928 }
71929@@ -2539,7 +2539,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
71930 * ACCESS_ONCE() to prevent the compiler from speculating
71931 * the increment to precede the early-exit check.
71932 */
71933- ACCESS_ONCE(rsp->n_barrier_done)++;
71934+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
71935 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
71936 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
71937 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
71938@@ -2581,7 +2581,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
71939
71940 /* Increment ->n_barrier_done to prevent duplicate work. */
71941 smp_mb(); /* Keep increment after above mechanism. */
71942- ACCESS_ONCE(rsp->n_barrier_done)++;
71943+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
71944 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
71945 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
71946 smp_mb(); /* Keep increment before caller's subsequent code. */
71947@@ -2626,10 +2626,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
71948 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
71949 init_callback_list(rdp);
71950 rdp->qlen_lazy = 0;
71951- ACCESS_ONCE(rdp->qlen) = 0;
71952+ ACCESS_ONCE_RW(rdp->qlen) = 0;
71953 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
71954 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
71955- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
71956+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
71957 #ifdef CONFIG_RCU_USER_QS
71958 WARN_ON_ONCE(rdp->dynticks->in_user);
71959 #endif
71960@@ -2664,8 +2664,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
71961 rdp->blimit = blimit;
71962 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
71963 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
71964- atomic_set(&rdp->dynticks->dynticks,
71965- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
71966+ atomic_set_unchecked(&rdp->dynticks->dynticks,
71967+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
71968 rcu_prepare_for_idle_init(cpu);
71969 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
71970
71971diff --git a/kernel/rcutree.h b/kernel/rcutree.h
71972index a240f03..d469618 100644
71973--- a/kernel/rcutree.h
71974+++ b/kernel/rcutree.h
71975@@ -86,7 +86,7 @@ struct rcu_dynticks {
71976 long long dynticks_nesting; /* Track irq/process nesting level. */
71977 /* Process level is worth LLONG_MAX/2. */
71978 int dynticks_nmi_nesting; /* Track NMI nesting level. */
71979- atomic_t dynticks; /* Even value for idle, else odd. */
71980+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
71981 #ifdef CONFIG_RCU_FAST_NO_HZ
71982 int dyntick_drain; /* Prepare-for-idle state variable. */
71983 unsigned long dyntick_holdoff;
71984diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
71985index f921154..34c4873 100644
71986--- a/kernel/rcutree_plugin.h
71987+++ b/kernel/rcutree_plugin.h
71988@@ -865,7 +865,7 @@ void synchronize_rcu_expedited(void)
71989
71990 /* Clean up and exit. */
71991 smp_mb(); /* ensure expedited GP seen before counter increment. */
71992- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
71993+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
71994 unlock_mb_ret:
71995 mutex_unlock(&sync_rcu_preempt_exp_mutex);
71996 mb_ret:
71997@@ -2040,7 +2040,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
71998 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
71999 printk(KERN_ERR "\t%d: (%lu %s) idle=%03x/%llx/%d %s\n",
72000 cpu, ticks_value, ticks_title,
72001- atomic_read(&rdtp->dynticks) & 0xfff,
72002+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
72003 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
72004 fast_no_hz);
72005 }
72006diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
72007index 693513b..b9f1d63 100644
72008--- a/kernel/rcutree_trace.c
72009+++ b/kernel/rcutree_trace.c
72010@@ -92,7 +92,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
72011 rdp->completed, rdp->gpnum,
72012 rdp->passed_quiesce, rdp->qs_pending);
72013 seq_printf(m, " dt=%d/%llx/%d df=%lu",
72014- atomic_read(&rdp->dynticks->dynticks),
72015+ atomic_read_unchecked(&rdp->dynticks->dynticks),
72016 rdp->dynticks->dynticks_nesting,
72017 rdp->dynticks->dynticks_nmi_nesting,
72018 rdp->dynticks_fqs);
72019@@ -154,7 +154,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
72020 rdp->completed, rdp->gpnum,
72021 rdp->passed_quiesce, rdp->qs_pending);
72022 seq_printf(m, ",%d,%llx,%d,%lu",
72023- atomic_read(&rdp->dynticks->dynticks),
72024+ atomic_read_unchecked(&rdp->dynticks->dynticks),
72025 rdp->dynticks->dynticks_nesting,
72026 rdp->dynticks->dynticks_nmi_nesting,
72027 rdp->dynticks_fqs);
72028diff --git a/kernel/resource.c b/kernel/resource.c
72029index 73f35d4..4684fc4 100644
72030--- a/kernel/resource.c
72031+++ b/kernel/resource.c
72032@@ -143,8 +143,18 @@ static const struct file_operations proc_iomem_operations = {
72033
72034 static int __init ioresources_init(void)
72035 {
72036+#ifdef CONFIG_GRKERNSEC_PROC_ADD
72037+#ifdef CONFIG_GRKERNSEC_PROC_USER
72038+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
72039+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
72040+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
72041+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
72042+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
72043+#endif
72044+#else
72045 proc_create("ioports", 0, NULL, &proc_ioports_operations);
72046 proc_create("iomem", 0, NULL, &proc_iomem_operations);
72047+#endif
72048 return 0;
72049 }
72050 __initcall(ioresources_init);
72051diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
72052index 98ec494..4241d6d 100644
72053--- a/kernel/rtmutex-tester.c
72054+++ b/kernel/rtmutex-tester.c
72055@@ -20,7 +20,7 @@
72056 #define MAX_RT_TEST_MUTEXES 8
72057
72058 static spinlock_t rttest_lock;
72059-static atomic_t rttest_event;
72060+static atomic_unchecked_t rttest_event;
72061
72062 struct test_thread_data {
72063 int opcode;
72064@@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
72065
72066 case RTTEST_LOCKCONT:
72067 td->mutexes[td->opdata] = 1;
72068- td->event = atomic_add_return(1, &rttest_event);
72069+ td->event = atomic_add_return_unchecked(1, &rttest_event);
72070 return 0;
72071
72072 case RTTEST_RESET:
72073@@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
72074 return 0;
72075
72076 case RTTEST_RESETEVENT:
72077- atomic_set(&rttest_event, 0);
72078+ atomic_set_unchecked(&rttest_event, 0);
72079 return 0;
72080
72081 default:
72082@@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
72083 return ret;
72084
72085 td->mutexes[id] = 1;
72086- td->event = atomic_add_return(1, &rttest_event);
72087+ td->event = atomic_add_return_unchecked(1, &rttest_event);
72088 rt_mutex_lock(&mutexes[id]);
72089- td->event = atomic_add_return(1, &rttest_event);
72090+ td->event = atomic_add_return_unchecked(1, &rttest_event);
72091 td->mutexes[id] = 4;
72092 return 0;
72093
72094@@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
72095 return ret;
72096
72097 td->mutexes[id] = 1;
72098- td->event = atomic_add_return(1, &rttest_event);
72099+ td->event = atomic_add_return_unchecked(1, &rttest_event);
72100 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
72101- td->event = atomic_add_return(1, &rttest_event);
72102+ td->event = atomic_add_return_unchecked(1, &rttest_event);
72103 td->mutexes[id] = ret ? 0 : 4;
72104 return ret ? -EINTR : 0;
72105
72106@@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
72107 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
72108 return ret;
72109
72110- td->event = atomic_add_return(1, &rttest_event);
72111+ td->event = atomic_add_return_unchecked(1, &rttest_event);
72112 rt_mutex_unlock(&mutexes[id]);
72113- td->event = atomic_add_return(1, &rttest_event);
72114+ td->event = atomic_add_return_unchecked(1, &rttest_event);
72115 td->mutexes[id] = 0;
72116 return 0;
72117
72118@@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
72119 break;
72120
72121 td->mutexes[dat] = 2;
72122- td->event = atomic_add_return(1, &rttest_event);
72123+ td->event = atomic_add_return_unchecked(1, &rttest_event);
72124 break;
72125
72126 default:
72127@@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
72128 return;
72129
72130 td->mutexes[dat] = 3;
72131- td->event = atomic_add_return(1, &rttest_event);
72132+ td->event = atomic_add_return_unchecked(1, &rttest_event);
72133 break;
72134
72135 case RTTEST_LOCKNOWAIT:
72136@@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
72137 return;
72138
72139 td->mutexes[dat] = 1;
72140- td->event = atomic_add_return(1, &rttest_event);
72141+ td->event = atomic_add_return_unchecked(1, &rttest_event);
72142 return;
72143
72144 default:
72145diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
72146index 15f60d0..7e50319 100644
72147--- a/kernel/sched/auto_group.c
72148+++ b/kernel/sched/auto_group.c
72149@@ -11,7 +11,7 @@
72150
72151 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
72152 static struct autogroup autogroup_default;
72153-static atomic_t autogroup_seq_nr;
72154+static atomic_unchecked_t autogroup_seq_nr;
72155
72156 void __init autogroup_init(struct task_struct *init_task)
72157 {
72158@@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
72159
72160 kref_init(&ag->kref);
72161 init_rwsem(&ag->lock);
72162- ag->id = atomic_inc_return(&autogroup_seq_nr);
72163+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
72164 ag->tg = tg;
72165 #ifdef CONFIG_RT_GROUP_SCHED
72166 /*
72167diff --git a/kernel/sched/core.c b/kernel/sched/core.c
72168index 2d8927f..f617765 100644
72169--- a/kernel/sched/core.c
72170+++ b/kernel/sched/core.c
72171@@ -3562,6 +3562,8 @@ int can_nice(const struct task_struct *p, const int nice)
72172 /* convert nice value [19,-20] to rlimit style value [1,40] */
72173 int nice_rlim = 20 - nice;
72174
72175+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
72176+
72177 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
72178 capable(CAP_SYS_NICE));
72179 }
72180@@ -3595,7 +3597,8 @@ SYSCALL_DEFINE1(nice, int, increment)
72181 if (nice > 19)
72182 nice = 19;
72183
72184- if (increment < 0 && !can_nice(current, nice))
72185+ if (increment < 0 && (!can_nice(current, nice) ||
72186+ gr_handle_chroot_nice()))
72187 return -EPERM;
72188
72189 retval = security_task_setnice(current, nice);
72190@@ -3749,6 +3752,7 @@ recheck:
72191 unsigned long rlim_rtprio =
72192 task_rlimit(p, RLIMIT_RTPRIO);
72193
72194+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
72195 /* can't set/change the rt policy */
72196 if (policy != p->policy && !rlim_rtprio)
72197 return -EPERM;
72198diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
72199index 6b800a1..0c36227 100644
72200--- a/kernel/sched/fair.c
72201+++ b/kernel/sched/fair.c
72202@@ -4890,7 +4890,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
72203 * run_rebalance_domains is triggered when needed from the scheduler tick.
72204 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
72205 */
72206-static void run_rebalance_domains(struct softirq_action *h)
72207+static void run_rebalance_domains(void)
72208 {
72209 int this_cpu = smp_processor_id();
72210 struct rq *this_rq = cpu_rq(this_cpu);
72211diff --git a/kernel/signal.c b/kernel/signal.c
72212index 0af8868..a00119d 100644
72213--- a/kernel/signal.c
72214+++ b/kernel/signal.c
72215@@ -49,12 +49,12 @@ static struct kmem_cache *sigqueue_cachep;
72216
72217 int print_fatal_signals __read_mostly;
72218
72219-static void __user *sig_handler(struct task_struct *t, int sig)
72220+static __sighandler_t sig_handler(struct task_struct *t, int sig)
72221 {
72222 return t->sighand->action[sig - 1].sa.sa_handler;
72223 }
72224
72225-static int sig_handler_ignored(void __user *handler, int sig)
72226+static int sig_handler_ignored(__sighandler_t handler, int sig)
72227 {
72228 /* Is it explicitly or implicitly ignored? */
72229 return handler == SIG_IGN ||
72230@@ -63,7 +63,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
72231
72232 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
72233 {
72234- void __user *handler;
72235+ __sighandler_t handler;
72236
72237 handler = sig_handler(t, sig);
72238
72239@@ -367,6 +367,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
72240 atomic_inc(&user->sigpending);
72241 rcu_read_unlock();
72242
72243+ if (!override_rlimit)
72244+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
72245+
72246 if (override_rlimit ||
72247 atomic_read(&user->sigpending) <=
72248 task_rlimit(t, RLIMIT_SIGPENDING)) {
72249@@ -491,7 +494,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
72250
72251 int unhandled_signal(struct task_struct *tsk, int sig)
72252 {
72253- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
72254+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
72255 if (is_global_init(tsk))
72256 return 1;
72257 if (handler != SIG_IGN && handler != SIG_DFL)
72258@@ -817,6 +820,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
72259 }
72260 }
72261
72262+ /* allow glibc communication via tgkill to other threads in our
72263+ thread group */
72264+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
72265+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
72266+ && gr_handle_signal(t, sig))
72267+ return -EPERM;
72268+
72269 return security_task_kill(t, info, sig, 0);
72270 }
72271
72272@@ -1198,7 +1208,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
72273 return send_signal(sig, info, p, 1);
72274 }
72275
72276-static int
72277+int
72278 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
72279 {
72280 return send_signal(sig, info, t, 0);
72281@@ -1235,6 +1245,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
72282 unsigned long int flags;
72283 int ret, blocked, ignored;
72284 struct k_sigaction *action;
72285+ int is_unhandled = 0;
72286
72287 spin_lock_irqsave(&t->sighand->siglock, flags);
72288 action = &t->sighand->action[sig-1];
72289@@ -1249,9 +1260,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
72290 }
72291 if (action->sa.sa_handler == SIG_DFL)
72292 t->signal->flags &= ~SIGNAL_UNKILLABLE;
72293+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
72294+ is_unhandled = 1;
72295 ret = specific_send_sig_info(sig, info, t);
72296 spin_unlock_irqrestore(&t->sighand->siglock, flags);
72297
72298+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
72299+ normal operation */
72300+ if (is_unhandled) {
72301+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
72302+ gr_handle_crash(t, sig);
72303+ }
72304+
72305 return ret;
72306 }
72307
72308@@ -1318,8 +1338,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
72309 ret = check_kill_permission(sig, info, p);
72310 rcu_read_unlock();
72311
72312- if (!ret && sig)
72313+ if (!ret && sig) {
72314 ret = do_send_sig_info(sig, info, p, true);
72315+ if (!ret)
72316+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
72317+ }
72318
72319 return ret;
72320 }
72321@@ -2864,7 +2887,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
72322 int error = -ESRCH;
72323
72324 rcu_read_lock();
72325- p = find_task_by_vpid(pid);
72326+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
72327+ /* allow glibc communication via tgkill to other threads in our
72328+ thread group */
72329+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
72330+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
72331+ p = find_task_by_vpid_unrestricted(pid);
72332+ else
72333+#endif
72334+ p = find_task_by_vpid(pid);
72335 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
72336 error = check_kill_permission(sig, info, p);
72337 /*
72338diff --git a/kernel/softirq.c b/kernel/softirq.c
72339index cc96bdc..8bb9750 100644
72340--- a/kernel/softirq.c
72341+++ b/kernel/softirq.c
72342@@ -57,7 +57,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
72343
72344 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
72345
72346-char *softirq_to_name[NR_SOFTIRQS] = {
72347+const char * const softirq_to_name[NR_SOFTIRQS] = {
72348 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
72349 "TASKLET", "SCHED", "HRTIMER", "RCU"
72350 };
72351@@ -244,7 +244,7 @@ restart:
72352 kstat_incr_softirqs_this_cpu(vec_nr);
72353
72354 trace_softirq_entry(vec_nr);
72355- h->action(h);
72356+ h->action();
72357 trace_softirq_exit(vec_nr);
72358 if (unlikely(prev_count != preempt_count())) {
72359 printk(KERN_ERR "huh, entered softirq %u %s %p"
72360@@ -391,9 +391,11 @@ void __raise_softirq_irqoff(unsigned int nr)
72361 or_softirq_pending(1UL << nr);
72362 }
72363
72364-void open_softirq(int nr, void (*action)(struct softirq_action *))
72365+void open_softirq(int nr, void (*action)(void))
72366 {
72367- softirq_vec[nr].action = action;
72368+ pax_open_kernel();
72369+ *(void **)&softirq_vec[nr].action = action;
72370+ pax_close_kernel();
72371 }
72372
72373 /*
72374@@ -447,7 +449,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
72375
72376 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
72377
72378-static void tasklet_action(struct softirq_action *a)
72379+static void tasklet_action(void)
72380 {
72381 struct tasklet_struct *list;
72382
72383@@ -482,7 +484,7 @@ static void tasklet_action(struct softirq_action *a)
72384 }
72385 }
72386
72387-static void tasklet_hi_action(struct softirq_action *a)
72388+static void tasklet_hi_action(void)
72389 {
72390 struct tasklet_struct *list;
72391
72392diff --git a/kernel/srcu.c b/kernel/srcu.c
72393index 97c465e..d83f3bb 100644
72394--- a/kernel/srcu.c
72395+++ b/kernel/srcu.c
72396@@ -302,9 +302,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
72397 preempt_disable();
72398 idx = rcu_dereference_index_check(sp->completed,
72399 rcu_read_lock_sched_held()) & 0x1;
72400- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
72401+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
72402 smp_mb(); /* B */ /* Avoid leaking the critical section. */
72403- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
72404+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
72405 preempt_enable();
72406 return idx;
72407 }
72408@@ -320,7 +320,7 @@ void __srcu_read_unlock(struct srcu_struct *sp, int idx)
72409 {
72410 preempt_disable();
72411 smp_mb(); /* C */ /* Avoid leaking the critical section. */
72412- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
72413+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
72414 preempt_enable();
72415 }
72416 EXPORT_SYMBOL_GPL(__srcu_read_unlock);
72417diff --git a/kernel/sys.c b/kernel/sys.c
72418index e6e0ece..1f2e413 100644
72419--- a/kernel/sys.c
72420+++ b/kernel/sys.c
72421@@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
72422 error = -EACCES;
72423 goto out;
72424 }
72425+
72426+ if (gr_handle_chroot_setpriority(p, niceval)) {
72427+ error = -EACCES;
72428+ goto out;
72429+ }
72430+
72431 no_nice = security_task_setnice(p, niceval);
72432 if (no_nice) {
72433 error = no_nice;
72434@@ -595,6 +601,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
72435 goto error;
72436 }
72437
72438+ if (gr_check_group_change(new->gid, new->egid, -1))
72439+ goto error;
72440+
72441 if (rgid != (gid_t) -1 ||
72442 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
72443 new->sgid = new->egid;
72444@@ -630,6 +639,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
72445 old = current_cred();
72446
72447 retval = -EPERM;
72448+
72449+ if (gr_check_group_change(kgid, kgid, kgid))
72450+ goto error;
72451+
72452 if (nsown_capable(CAP_SETGID))
72453 new->gid = new->egid = new->sgid = new->fsgid = kgid;
72454 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
72455@@ -647,7 +660,7 @@ error:
72456 /*
72457 * change the user struct in a credentials set to match the new UID
72458 */
72459-static int set_user(struct cred *new)
72460+int set_user(struct cred *new)
72461 {
72462 struct user_struct *new_user;
72463
72464@@ -727,6 +740,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
72465 goto error;
72466 }
72467
72468+ if (gr_check_user_change(new->uid, new->euid, -1))
72469+ goto error;
72470+
72471 if (!uid_eq(new->uid, old->uid)) {
72472 retval = set_user(new);
72473 if (retval < 0)
72474@@ -777,6 +793,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
72475 old = current_cred();
72476
72477 retval = -EPERM;
72478+
72479+ if (gr_check_crash_uid(kuid))
72480+ goto error;
72481+ if (gr_check_user_change(kuid, kuid, kuid))
72482+ goto error;
72483+
72484 if (nsown_capable(CAP_SETUID)) {
72485 new->suid = new->uid = kuid;
72486 if (!uid_eq(kuid, old->uid)) {
72487@@ -846,6 +868,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
72488 goto error;
72489 }
72490
72491+ if (gr_check_user_change(kruid, keuid, -1))
72492+ goto error;
72493+
72494 if (ruid != (uid_t) -1) {
72495 new->uid = kruid;
72496 if (!uid_eq(kruid, old->uid)) {
72497@@ -928,6 +953,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
72498 goto error;
72499 }
72500
72501+ if (gr_check_group_change(krgid, kegid, -1))
72502+ goto error;
72503+
72504 if (rgid != (gid_t) -1)
72505 new->gid = krgid;
72506 if (egid != (gid_t) -1)
72507@@ -981,6 +1009,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
72508 if (!uid_valid(kuid))
72509 return old_fsuid;
72510
72511+ if (gr_check_user_change(-1, -1, kuid))
72512+ goto error;
72513+
72514 new = prepare_creds();
72515 if (!new)
72516 return old_fsuid;
72517@@ -995,6 +1026,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
72518 }
72519 }
72520
72521+error:
72522 abort_creds(new);
72523 return old_fsuid;
72524
72525@@ -1027,12 +1059,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
72526 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
72527 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
72528 nsown_capable(CAP_SETGID)) {
72529+ if (gr_check_group_change(-1, -1, kgid))
72530+ goto error;
72531+
72532 if (!gid_eq(kgid, old->fsgid)) {
72533 new->fsgid = kgid;
72534 goto change_okay;
72535 }
72536 }
72537
72538+error:
72539 abort_creds(new);
72540 return old_fsgid;
72541
72542@@ -1340,19 +1376,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
72543 return -EFAULT;
72544
72545 down_read(&uts_sem);
72546- error = __copy_to_user(&name->sysname, &utsname()->sysname,
72547+ error = __copy_to_user(name->sysname, &utsname()->sysname,
72548 __OLD_UTS_LEN);
72549 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
72550- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
72551+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
72552 __OLD_UTS_LEN);
72553 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
72554- error |= __copy_to_user(&name->release, &utsname()->release,
72555+ error |= __copy_to_user(name->release, &utsname()->release,
72556 __OLD_UTS_LEN);
72557 error |= __put_user(0, name->release + __OLD_UTS_LEN);
72558- error |= __copy_to_user(&name->version, &utsname()->version,
72559+ error |= __copy_to_user(name->version, &utsname()->version,
72560 __OLD_UTS_LEN);
72561 error |= __put_user(0, name->version + __OLD_UTS_LEN);
72562- error |= __copy_to_user(&name->machine, &utsname()->machine,
72563+ error |= __copy_to_user(name->machine, &utsname()->machine,
72564 __OLD_UTS_LEN);
72565 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
72566 up_read(&uts_sem);
72567@@ -2026,7 +2062,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
72568 error = get_dumpable(me->mm);
72569 break;
72570 case PR_SET_DUMPABLE:
72571- if (arg2 < 0 || arg2 > 1) {
72572+ if (arg2 > 1) {
72573 error = -EINVAL;
72574 break;
72575 }
72576diff --git a/kernel/sysctl.c b/kernel/sysctl.c
72577index 26f65ea..df8e5ad 100644
72578--- a/kernel/sysctl.c
72579+++ b/kernel/sysctl.c
72580@@ -92,7 +92,6 @@
72581
72582
72583 #if defined(CONFIG_SYSCTL)
72584-
72585 /* External variables not in a header file. */
72586 extern int sysctl_overcommit_memory;
72587 extern int sysctl_overcommit_ratio;
72588@@ -172,10 +171,8 @@ static int proc_taint(struct ctl_table *table, int write,
72589 void __user *buffer, size_t *lenp, loff_t *ppos);
72590 #endif
72591
72592-#ifdef CONFIG_PRINTK
72593 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
72594 void __user *buffer, size_t *lenp, loff_t *ppos);
72595-#endif
72596
72597 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
72598 void __user *buffer, size_t *lenp, loff_t *ppos);
72599@@ -206,6 +203,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
72600
72601 #endif
72602
72603+extern struct ctl_table grsecurity_table[];
72604+
72605 static struct ctl_table kern_table[];
72606 static struct ctl_table vm_table[];
72607 static struct ctl_table fs_table[];
72608@@ -220,6 +219,20 @@ extern struct ctl_table epoll_table[];
72609 int sysctl_legacy_va_layout;
72610 #endif
72611
72612+#ifdef CONFIG_PAX_SOFTMODE
72613+static ctl_table pax_table[] = {
72614+ {
72615+ .procname = "softmode",
72616+ .data = &pax_softmode,
72617+ .maxlen = sizeof(unsigned int),
72618+ .mode = 0600,
72619+ .proc_handler = &proc_dointvec,
72620+ },
72621+
72622+ { }
72623+};
72624+#endif
72625+
72626 /* The default sysctl tables: */
72627
72628 static struct ctl_table sysctl_base_table[] = {
72629@@ -266,6 +279,22 @@ static int max_extfrag_threshold = 1000;
72630 #endif
72631
72632 static struct ctl_table kern_table[] = {
72633+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
72634+ {
72635+ .procname = "grsecurity",
72636+ .mode = 0500,
72637+ .child = grsecurity_table,
72638+ },
72639+#endif
72640+
72641+#ifdef CONFIG_PAX_SOFTMODE
72642+ {
72643+ .procname = "pax",
72644+ .mode = 0500,
72645+ .child = pax_table,
72646+ },
72647+#endif
72648+
72649 {
72650 .procname = "sched_child_runs_first",
72651 .data = &sysctl_sched_child_runs_first,
72652@@ -552,7 +581,7 @@ static struct ctl_table kern_table[] = {
72653 .data = &modprobe_path,
72654 .maxlen = KMOD_PATH_LEN,
72655 .mode = 0644,
72656- .proc_handler = proc_dostring,
72657+ .proc_handler = proc_dostring_modpriv,
72658 },
72659 {
72660 .procname = "modules_disabled",
72661@@ -719,16 +748,20 @@ static struct ctl_table kern_table[] = {
72662 .extra1 = &zero,
72663 .extra2 = &one,
72664 },
72665+#endif
72666 {
72667 .procname = "kptr_restrict",
72668 .data = &kptr_restrict,
72669 .maxlen = sizeof(int),
72670 .mode = 0644,
72671 .proc_handler = proc_dointvec_minmax_sysadmin,
72672+#ifdef CONFIG_GRKERNSEC_HIDESYM
72673+ .extra1 = &two,
72674+#else
72675 .extra1 = &zero,
72676+#endif
72677 .extra2 = &two,
72678 },
72679-#endif
72680 {
72681 .procname = "ngroups_max",
72682 .data = &ngroups_max,
72683@@ -1225,6 +1258,13 @@ static struct ctl_table vm_table[] = {
72684 .proc_handler = proc_dointvec_minmax,
72685 .extra1 = &zero,
72686 },
72687+ {
72688+ .procname = "heap_stack_gap",
72689+ .data = &sysctl_heap_stack_gap,
72690+ .maxlen = sizeof(sysctl_heap_stack_gap),
72691+ .mode = 0644,
72692+ .proc_handler = proc_doulongvec_minmax,
72693+ },
72694 #else
72695 {
72696 .procname = "nr_trim_pages",
72697@@ -1675,6 +1715,16 @@ int proc_dostring(struct ctl_table *table, int write,
72698 buffer, lenp, ppos);
72699 }
72700
72701+int proc_dostring_modpriv(struct ctl_table *table, int write,
72702+ void __user *buffer, size_t *lenp, loff_t *ppos)
72703+{
72704+ if (write && !capable(CAP_SYS_MODULE))
72705+ return -EPERM;
72706+
72707+ return _proc_do_string(table->data, table->maxlen, write,
72708+ buffer, lenp, ppos);
72709+}
72710+
72711 static size_t proc_skip_spaces(char **buf)
72712 {
72713 size_t ret;
72714@@ -1780,6 +1830,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
72715 len = strlen(tmp);
72716 if (len > *size)
72717 len = *size;
72718+ if (len > sizeof(tmp))
72719+ len = sizeof(tmp);
72720 if (copy_to_user(*buf, tmp, len))
72721 return -EFAULT;
72722 *size -= len;
72723@@ -1972,7 +2024,6 @@ static int proc_taint(struct ctl_table *table, int write,
72724 return err;
72725 }
72726
72727-#ifdef CONFIG_PRINTK
72728 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
72729 void __user *buffer, size_t *lenp, loff_t *ppos)
72730 {
72731@@ -1981,7 +2032,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
72732
72733 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
72734 }
72735-#endif
72736
72737 struct do_proc_dointvec_minmax_conv_param {
72738 int *min;
72739@@ -2128,8 +2178,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
72740 *i = val;
72741 } else {
72742 val = convdiv * (*i) / convmul;
72743- if (!first)
72744+ if (!first) {
72745 err = proc_put_char(&buffer, &left, '\t');
72746+ if (err)
72747+ break;
72748+ }
72749 err = proc_put_long(&buffer, &left, val, false);
72750 if (err)
72751 break;
72752@@ -2521,6 +2574,12 @@ int proc_dostring(struct ctl_table *table, int write,
72753 return -ENOSYS;
72754 }
72755
72756+int proc_dostring_modpriv(struct ctl_table *table, int write,
72757+ void __user *buffer, size_t *lenp, loff_t *ppos)
72758+{
72759+ return -ENOSYS;
72760+}
72761+
72762 int proc_dointvec(struct ctl_table *table, int write,
72763 void __user *buffer, size_t *lenp, loff_t *ppos)
72764 {
72765@@ -2577,5 +2636,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
72766 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
72767 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
72768 EXPORT_SYMBOL(proc_dostring);
72769+EXPORT_SYMBOL(proc_dostring_modpriv);
72770 EXPORT_SYMBOL(proc_doulongvec_minmax);
72771 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
72772diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
72773index 65bdcf1..21eb831 100644
72774--- a/kernel/sysctl_binary.c
72775+++ b/kernel/sysctl_binary.c
72776@@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
72777 int i;
72778
72779 set_fs(KERNEL_DS);
72780- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
72781+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
72782 set_fs(old_fs);
72783 if (result < 0)
72784 goto out_kfree;
72785@@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
72786 }
72787
72788 set_fs(KERNEL_DS);
72789- result = vfs_write(file, buffer, str - buffer, &pos);
72790+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
72791 set_fs(old_fs);
72792 if (result < 0)
72793 goto out_kfree;
72794@@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
72795 int i;
72796
72797 set_fs(KERNEL_DS);
72798- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
72799+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
72800 set_fs(old_fs);
72801 if (result < 0)
72802 goto out_kfree;
72803@@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
72804 }
72805
72806 set_fs(KERNEL_DS);
72807- result = vfs_write(file, buffer, str - buffer, &pos);
72808+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
72809 set_fs(old_fs);
72810 if (result < 0)
72811 goto out_kfree;
72812@@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
72813 int i;
72814
72815 set_fs(KERNEL_DS);
72816- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
72817+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
72818 set_fs(old_fs);
72819 if (result < 0)
72820 goto out;
72821@@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
72822 __le16 dnaddr;
72823
72824 set_fs(KERNEL_DS);
72825- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
72826+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
72827 set_fs(old_fs);
72828 if (result < 0)
72829 goto out;
72830@@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
72831 le16_to_cpu(dnaddr) & 0x3ff);
72832
72833 set_fs(KERNEL_DS);
72834- result = vfs_write(file, buf, len, &pos);
72835+ result = vfs_write(file, (const char __force_user *)buf, len, &pos);
72836 set_fs(old_fs);
72837 if (result < 0)
72838 goto out;
72839diff --git a/kernel/taskstats.c b/kernel/taskstats.c
72840index 145bb4d..b2aa969 100644
72841--- a/kernel/taskstats.c
72842+++ b/kernel/taskstats.c
72843@@ -28,9 +28,12 @@
72844 #include <linux/fs.h>
72845 #include <linux/file.h>
72846 #include <linux/pid_namespace.h>
72847+#include <linux/grsecurity.h>
72848 #include <net/genetlink.h>
72849 #include <linux/atomic.h>
72850
72851+extern int gr_is_taskstats_denied(int pid);
72852+
72853 /*
72854 * Maximum length of a cpumask that can be specified in
72855 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
72856@@ -570,6 +573,9 @@ err:
72857
72858 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
72859 {
72860+ if (gr_is_taskstats_denied(current->pid))
72861+ return -EACCES;
72862+
72863 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
72864 return cmd_attr_register_cpumask(info);
72865 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
72866diff --git a/kernel/time.c b/kernel/time.c
72867index d226c6a..c7c0960 100644
72868--- a/kernel/time.c
72869+++ b/kernel/time.c
72870@@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
72871 return error;
72872
72873 if (tz) {
72874+ /* we log in do_settimeofday called below, so don't log twice
72875+ */
72876+ if (!tv)
72877+ gr_log_timechange();
72878+
72879 sys_tz = *tz;
72880 update_vsyscall_tz();
72881 if (firsttime) {
72882diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
72883index f11d83b..d016d91 100644
72884--- a/kernel/time/alarmtimer.c
72885+++ b/kernel/time/alarmtimer.c
72886@@ -750,7 +750,7 @@ static int __init alarmtimer_init(void)
72887 struct platform_device *pdev;
72888 int error = 0;
72889 int i;
72890- struct k_clock alarm_clock = {
72891+ static struct k_clock alarm_clock = {
72892 .clock_getres = alarm_clock_getres,
72893 .clock_get = alarm_clock_get,
72894 .timer_create = alarm_timer_create,
72895diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
72896index f113755..ec24223 100644
72897--- a/kernel/time/tick-broadcast.c
72898+++ b/kernel/time/tick-broadcast.c
72899@@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
72900 * then clear the broadcast bit.
72901 */
72902 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
72903- int cpu = smp_processor_id();
72904+ cpu = smp_processor_id();
72905
72906 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
72907 tick_broadcast_clear_oneshot(cpu);
72908diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
72909index e424970..4c7962b 100644
72910--- a/kernel/time/timekeeping.c
72911+++ b/kernel/time/timekeeping.c
72912@@ -15,6 +15,7 @@
72913 #include <linux/init.h>
72914 #include <linux/mm.h>
72915 #include <linux/sched.h>
72916+#include <linux/grsecurity.h>
72917 #include <linux/syscore_ops.h>
72918 #include <linux/clocksource.h>
72919 #include <linux/jiffies.h>
72920@@ -368,6 +369,8 @@ int do_settimeofday(const struct timespec *tv)
72921 if (!timespec_valid_strict(tv))
72922 return -EINVAL;
72923
72924+ gr_log_timechange();
72925+
72926 write_seqlock_irqsave(&tk->lock, flags);
72927
72928 timekeeping_forward_now(tk);
72929diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
72930index af5a7e9..715611a 100644
72931--- a/kernel/time/timer_list.c
72932+++ b/kernel/time/timer_list.c
72933@@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
72934
72935 static void print_name_offset(struct seq_file *m, void *sym)
72936 {
72937+#ifdef CONFIG_GRKERNSEC_HIDESYM
72938+ SEQ_printf(m, "<%p>", NULL);
72939+#else
72940 char symname[KSYM_NAME_LEN];
72941
72942 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
72943 SEQ_printf(m, "<%pK>", sym);
72944 else
72945 SEQ_printf(m, "%s", symname);
72946+#endif
72947 }
72948
72949 static void
72950@@ -112,7 +116,11 @@ next_one:
72951 static void
72952 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
72953 {
72954+#ifdef CONFIG_GRKERNSEC_HIDESYM
72955+ SEQ_printf(m, " .base: %p\n", NULL);
72956+#else
72957 SEQ_printf(m, " .base: %pK\n", base);
72958+#endif
72959 SEQ_printf(m, " .index: %d\n",
72960 base->index);
72961 SEQ_printf(m, " .resolution: %Lu nsecs\n",
72962@@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
72963 {
72964 struct proc_dir_entry *pe;
72965
72966+#ifdef CONFIG_GRKERNSEC_PROC_ADD
72967+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
72968+#else
72969 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
72970+#endif
72971 if (!pe)
72972 return -ENOMEM;
72973 return 0;
72974diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
72975index 0b537f2..40d6c20 100644
72976--- a/kernel/time/timer_stats.c
72977+++ b/kernel/time/timer_stats.c
72978@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
72979 static unsigned long nr_entries;
72980 static struct entry entries[MAX_ENTRIES];
72981
72982-static atomic_t overflow_count;
72983+static atomic_unchecked_t overflow_count;
72984
72985 /*
72986 * The entries are in a hash-table, for fast lookup:
72987@@ -140,7 +140,7 @@ static void reset_entries(void)
72988 nr_entries = 0;
72989 memset(entries, 0, sizeof(entries));
72990 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
72991- atomic_set(&overflow_count, 0);
72992+ atomic_set_unchecked(&overflow_count, 0);
72993 }
72994
72995 static struct entry *alloc_entry(void)
72996@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
72997 if (likely(entry))
72998 entry->count++;
72999 else
73000- atomic_inc(&overflow_count);
73001+ atomic_inc_unchecked(&overflow_count);
73002
73003 out_unlock:
73004 raw_spin_unlock_irqrestore(lock, flags);
73005@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
73006
73007 static void print_name_offset(struct seq_file *m, unsigned long addr)
73008 {
73009+#ifdef CONFIG_GRKERNSEC_HIDESYM
73010+ seq_printf(m, "<%p>", NULL);
73011+#else
73012 char symname[KSYM_NAME_LEN];
73013
73014 if (lookup_symbol_name(addr, symname) < 0)
73015- seq_printf(m, "<%p>", (void *)addr);
73016+ seq_printf(m, "<%pK>", (void *)addr);
73017 else
73018 seq_printf(m, "%s", symname);
73019+#endif
73020 }
73021
73022 static int tstats_show(struct seq_file *m, void *v)
73023@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
73024
73025 seq_puts(m, "Timer Stats Version: v0.2\n");
73026 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
73027- if (atomic_read(&overflow_count))
73028+ if (atomic_read_unchecked(&overflow_count))
73029 seq_printf(m, "Overflow: %d entries\n",
73030- atomic_read(&overflow_count));
73031+ atomic_read_unchecked(&overflow_count));
73032
73033 for (i = 0; i < nr_entries; i++) {
73034 entry = entries + i;
73035@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
73036 {
73037 struct proc_dir_entry *pe;
73038
73039+#ifdef CONFIG_GRKERNSEC_PROC_ADD
73040+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
73041+#else
73042 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
73043+#endif
73044 if (!pe)
73045 return -ENOMEM;
73046 return 0;
73047diff --git a/kernel/timer.c b/kernel/timer.c
73048index 367d008..46857a0 100644
73049--- a/kernel/timer.c
73050+++ b/kernel/timer.c
73051@@ -1363,7 +1363,7 @@ void update_process_times(int user_tick)
73052 /*
73053 * This function runs timers and the timer-tq in bottom half context.
73054 */
73055-static void run_timer_softirq(struct softirq_action *h)
73056+static void run_timer_softirq(void)
73057 {
73058 struct tvec_base *base = __this_cpu_read(tvec_bases);
73059
73060@@ -1772,7 +1772,7 @@ static int __cpuinit timer_cpu_notify(struct notifier_block *self,
73061 return NOTIFY_OK;
73062 }
73063
73064-static struct notifier_block __cpuinitdata timers_nb = {
73065+static struct notifier_block __cpuinitconst timers_nb = {
73066 .notifier_call = timer_cpu_notify,
73067 };
73068
73069diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
73070index c0bd030..62a1927 100644
73071--- a/kernel/trace/blktrace.c
73072+++ b/kernel/trace/blktrace.c
73073@@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
73074 struct blk_trace *bt = filp->private_data;
73075 char buf[16];
73076
73077- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
73078+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
73079
73080 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
73081 }
73082@@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
73083 return 1;
73084
73085 bt = buf->chan->private_data;
73086- atomic_inc(&bt->dropped);
73087+ atomic_inc_unchecked(&bt->dropped);
73088 return 0;
73089 }
73090
73091@@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
73092
73093 bt->dir = dir;
73094 bt->dev = dev;
73095- atomic_set(&bt->dropped, 0);
73096+ atomic_set_unchecked(&bt->dropped, 0);
73097
73098 ret = -EIO;
73099 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
73100diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
73101index 51b7159..18137d6 100644
73102--- a/kernel/trace/ftrace.c
73103+++ b/kernel/trace/ftrace.c
73104@@ -1874,12 +1874,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
73105 if (unlikely(ftrace_disabled))
73106 return 0;
73107
73108+ ret = ftrace_arch_code_modify_prepare();
73109+ FTRACE_WARN_ON(ret);
73110+ if (ret)
73111+ return 0;
73112+
73113 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
73114+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
73115 if (ret) {
73116 ftrace_bug(ret, ip);
73117- return 0;
73118 }
73119- return 1;
73120+ return ret ? 0 : 1;
73121 }
73122
73123 /*
73124@@ -2965,7 +2970,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
73125
73126 int
73127 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
73128- void *data)
73129+ void *data)
73130 {
73131 struct ftrace_func_probe *entry;
73132 struct ftrace_page *pg;
73133@@ -3832,8 +3837,10 @@ static int ftrace_process_locs(struct module *mod,
73134 if (!count)
73135 return 0;
73136
73137+ pax_open_kernel();
73138 sort(start, count, sizeof(*start),
73139 ftrace_cmp_ips, ftrace_swap_ips);
73140+ pax_close_kernel();
73141
73142 start_pg = ftrace_allocate_pages(count);
73143 if (!start_pg)
73144@@ -4541,8 +4548,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
73145 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
73146
73147 static int ftrace_graph_active;
73148-static struct notifier_block ftrace_suspend_notifier;
73149-
73150 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
73151 {
73152 return 0;
73153@@ -4686,6 +4691,10 @@ ftrace_suspend_notifier_call(struct notifier_block *bl, unsigned long state,
73154 return NOTIFY_DONE;
73155 }
73156
73157+static struct notifier_block ftrace_suspend_notifier = {
73158+ .notifier_call = ftrace_suspend_notifier_call
73159+};
73160+
73161 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
73162 trace_func_graph_ent_t entryfunc)
73163 {
73164@@ -4699,7 +4708,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
73165 goto out;
73166 }
73167
73168- ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
73169 register_pm_notifier(&ftrace_suspend_notifier);
73170
73171 ftrace_graph_active++;
73172diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
73173index 4cb5e51..6010f39 100644
73174--- a/kernel/trace/ring_buffer.c
73175+++ b/kernel/trace/ring_buffer.c
73176@@ -346,9 +346,9 @@ struct buffer_data_page {
73177 */
73178 struct buffer_page {
73179 struct list_head list; /* list of buffer pages */
73180- local_t write; /* index for next write */
73181+ local_unchecked_t write; /* index for next write */
73182 unsigned read; /* index for next read */
73183- local_t entries; /* entries on this page */
73184+ local_unchecked_t entries; /* entries on this page */
73185 unsigned long real_end; /* real end of data */
73186 struct buffer_data_page *page; /* Actual data page */
73187 };
73188@@ -460,8 +460,8 @@ struct ring_buffer_per_cpu {
73189 unsigned long lost_events;
73190 unsigned long last_overrun;
73191 local_t entries_bytes;
73192- local_t commit_overrun;
73193- local_t overrun;
73194+ local_unchecked_t commit_overrun;
73195+ local_unchecked_t overrun;
73196 local_t entries;
73197 local_t committing;
73198 local_t commits;
73199@@ -490,7 +490,7 @@ struct ring_buffer {
73200 struct ring_buffer_per_cpu **buffers;
73201
73202 #ifdef CONFIG_HOTPLUG_CPU
73203- struct notifier_block cpu_notify;
73204+ notifier_block_no_const cpu_notify;
73205 #endif
73206 u64 (*clock)(void);
73207 };
73208@@ -860,8 +860,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
73209 *
73210 * We add a counter to the write field to denote this.
73211 */
73212- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
73213- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
73214+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
73215+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
73216
73217 /*
73218 * Just make sure we have seen our old_write and synchronize
73219@@ -889,8 +889,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
73220 * cmpxchg to only update if an interrupt did not already
73221 * do it for us. If the cmpxchg fails, we don't care.
73222 */
73223- (void)local_cmpxchg(&next_page->write, old_write, val);
73224- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
73225+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
73226+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
73227
73228 /*
73229 * No need to worry about races with clearing out the commit.
73230@@ -1249,12 +1249,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
73231
73232 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
73233 {
73234- return local_read(&bpage->entries) & RB_WRITE_MASK;
73235+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
73236 }
73237
73238 static inline unsigned long rb_page_write(struct buffer_page *bpage)
73239 {
73240- return local_read(&bpage->write) & RB_WRITE_MASK;
73241+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
73242 }
73243
73244 static int
73245@@ -1349,7 +1349,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
73246 * bytes consumed in ring buffer from here.
73247 * Increment overrun to account for the lost events.
73248 */
73249- local_add(page_entries, &cpu_buffer->overrun);
73250+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
73251 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
73252 }
73253
73254@@ -1905,7 +1905,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
73255 * it is our responsibility to update
73256 * the counters.
73257 */
73258- local_add(entries, &cpu_buffer->overrun);
73259+ local_add_unchecked(entries, &cpu_buffer->overrun);
73260 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
73261
73262 /*
73263@@ -2055,7 +2055,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
73264 if (tail == BUF_PAGE_SIZE)
73265 tail_page->real_end = 0;
73266
73267- local_sub(length, &tail_page->write);
73268+ local_sub_unchecked(length, &tail_page->write);
73269 return;
73270 }
73271
73272@@ -2090,7 +2090,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
73273 rb_event_set_padding(event);
73274
73275 /* Set the write back to the previous setting */
73276- local_sub(length, &tail_page->write);
73277+ local_sub_unchecked(length, &tail_page->write);
73278 return;
73279 }
73280
73281@@ -2102,7 +2102,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
73282
73283 /* Set write to end of buffer */
73284 length = (tail + length) - BUF_PAGE_SIZE;
73285- local_sub(length, &tail_page->write);
73286+ local_sub_unchecked(length, &tail_page->write);
73287 }
73288
73289 /*
73290@@ -2128,7 +2128,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
73291 * about it.
73292 */
73293 if (unlikely(next_page == commit_page)) {
73294- local_inc(&cpu_buffer->commit_overrun);
73295+ local_inc_unchecked(&cpu_buffer->commit_overrun);
73296 goto out_reset;
73297 }
73298
73299@@ -2182,7 +2182,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
73300 cpu_buffer->tail_page) &&
73301 (cpu_buffer->commit_page ==
73302 cpu_buffer->reader_page))) {
73303- local_inc(&cpu_buffer->commit_overrun);
73304+ local_inc_unchecked(&cpu_buffer->commit_overrun);
73305 goto out_reset;
73306 }
73307 }
73308@@ -2230,7 +2230,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
73309 length += RB_LEN_TIME_EXTEND;
73310
73311 tail_page = cpu_buffer->tail_page;
73312- write = local_add_return(length, &tail_page->write);
73313+ write = local_add_return_unchecked(length, &tail_page->write);
73314
73315 /* set write to only the index of the write */
73316 write &= RB_WRITE_MASK;
73317@@ -2247,7 +2247,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
73318 kmemcheck_annotate_bitfield(event, bitfield);
73319 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
73320
73321- local_inc(&tail_page->entries);
73322+ local_inc_unchecked(&tail_page->entries);
73323
73324 /*
73325 * If this is the first commit on the page, then update
73326@@ -2280,7 +2280,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
73327
73328 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
73329 unsigned long write_mask =
73330- local_read(&bpage->write) & ~RB_WRITE_MASK;
73331+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
73332 unsigned long event_length = rb_event_length(event);
73333 /*
73334 * This is on the tail page. It is possible that
73335@@ -2290,7 +2290,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
73336 */
73337 old_index += write_mask;
73338 new_index += write_mask;
73339- index = local_cmpxchg(&bpage->write, old_index, new_index);
73340+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
73341 if (index == old_index) {
73342 /* update counters */
73343 local_sub(event_length, &cpu_buffer->entries_bytes);
73344@@ -2629,7 +2629,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
73345
73346 /* Do the likely case first */
73347 if (likely(bpage->page == (void *)addr)) {
73348- local_dec(&bpage->entries);
73349+ local_dec_unchecked(&bpage->entries);
73350 return;
73351 }
73352
73353@@ -2641,7 +2641,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
73354 start = bpage;
73355 do {
73356 if (bpage->page == (void *)addr) {
73357- local_dec(&bpage->entries);
73358+ local_dec_unchecked(&bpage->entries);
73359 return;
73360 }
73361 rb_inc_page(cpu_buffer, &bpage);
73362@@ -2923,7 +2923,7 @@ static inline unsigned long
73363 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
73364 {
73365 return local_read(&cpu_buffer->entries) -
73366- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
73367+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
73368 }
73369
73370 /**
73371@@ -3011,7 +3011,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
73372 return 0;
73373
73374 cpu_buffer = buffer->buffers[cpu];
73375- ret = local_read(&cpu_buffer->overrun);
73376+ ret = local_read_unchecked(&cpu_buffer->overrun);
73377
73378 return ret;
73379 }
73380@@ -3032,7 +3032,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
73381 return 0;
73382
73383 cpu_buffer = buffer->buffers[cpu];
73384- ret = local_read(&cpu_buffer->commit_overrun);
73385+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
73386
73387 return ret;
73388 }
73389@@ -3077,7 +3077,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
73390 /* if you care about this being correct, lock the buffer */
73391 for_each_buffer_cpu(buffer, cpu) {
73392 cpu_buffer = buffer->buffers[cpu];
73393- overruns += local_read(&cpu_buffer->overrun);
73394+ overruns += local_read_unchecked(&cpu_buffer->overrun);
73395 }
73396
73397 return overruns;
73398@@ -3253,8 +3253,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
73399 /*
73400 * Reset the reader page to size zero.
73401 */
73402- local_set(&cpu_buffer->reader_page->write, 0);
73403- local_set(&cpu_buffer->reader_page->entries, 0);
73404+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
73405+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
73406 local_set(&cpu_buffer->reader_page->page->commit, 0);
73407 cpu_buffer->reader_page->real_end = 0;
73408
73409@@ -3288,7 +3288,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
73410 * want to compare with the last_overrun.
73411 */
73412 smp_mb();
73413- overwrite = local_read(&(cpu_buffer->overrun));
73414+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
73415
73416 /*
73417 * Here's the tricky part.
73418@@ -3858,8 +3858,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
73419
73420 cpu_buffer->head_page
73421 = list_entry(cpu_buffer->pages, struct buffer_page, list);
73422- local_set(&cpu_buffer->head_page->write, 0);
73423- local_set(&cpu_buffer->head_page->entries, 0);
73424+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
73425+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
73426 local_set(&cpu_buffer->head_page->page->commit, 0);
73427
73428 cpu_buffer->head_page->read = 0;
73429@@ -3869,14 +3869,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
73430
73431 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
73432 INIT_LIST_HEAD(&cpu_buffer->new_pages);
73433- local_set(&cpu_buffer->reader_page->write, 0);
73434- local_set(&cpu_buffer->reader_page->entries, 0);
73435+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
73436+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
73437 local_set(&cpu_buffer->reader_page->page->commit, 0);
73438 cpu_buffer->reader_page->read = 0;
73439
73440- local_set(&cpu_buffer->commit_overrun, 0);
73441+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
73442 local_set(&cpu_buffer->entries_bytes, 0);
73443- local_set(&cpu_buffer->overrun, 0);
73444+ local_set_unchecked(&cpu_buffer->overrun, 0);
73445 local_set(&cpu_buffer->entries, 0);
73446 local_set(&cpu_buffer->committing, 0);
73447 local_set(&cpu_buffer->commits, 0);
73448@@ -4279,8 +4279,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
73449 rb_init_page(bpage);
73450 bpage = reader->page;
73451 reader->page = *data_page;
73452- local_set(&reader->write, 0);
73453- local_set(&reader->entries, 0);
73454+ local_set_unchecked(&reader->write, 0);
73455+ local_set_unchecked(&reader->entries, 0);
73456 reader->read = 0;
73457 *data_page = bpage;
73458
73459diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
73460index 31e4f55..62da00f 100644
73461--- a/kernel/trace/trace.c
73462+++ b/kernel/trace/trace.c
73463@@ -4436,10 +4436,9 @@ static const struct file_operations tracing_dyn_info_fops = {
73464 };
73465 #endif
73466
73467-static struct dentry *d_tracer;
73468-
73469 struct dentry *tracing_init_dentry(void)
73470 {
73471+ static struct dentry *d_tracer;
73472 static int once;
73473
73474 if (d_tracer)
73475@@ -4459,10 +4458,9 @@ struct dentry *tracing_init_dentry(void)
73476 return d_tracer;
73477 }
73478
73479-static struct dentry *d_percpu;
73480-
73481 struct dentry *tracing_dentry_percpu(void)
73482 {
73483+ static struct dentry *d_percpu;
73484 static int once;
73485 struct dentry *d_tracer;
73486
73487diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
73488index d608d09..7eddcb1 100644
73489--- a/kernel/trace/trace_events.c
73490+++ b/kernel/trace/trace_events.c
73491@@ -1320,10 +1320,6 @@ static LIST_HEAD(ftrace_module_file_list);
73492 struct ftrace_module_file_ops {
73493 struct list_head list;
73494 struct module *mod;
73495- struct file_operations id;
73496- struct file_operations enable;
73497- struct file_operations format;
73498- struct file_operations filter;
73499 };
73500
73501 static struct ftrace_module_file_ops *
73502@@ -1344,17 +1340,12 @@ trace_create_file_ops(struct module *mod)
73503
73504 file_ops->mod = mod;
73505
73506- file_ops->id = ftrace_event_id_fops;
73507- file_ops->id.owner = mod;
73508-
73509- file_ops->enable = ftrace_enable_fops;
73510- file_ops->enable.owner = mod;
73511-
73512- file_ops->filter = ftrace_event_filter_fops;
73513- file_ops->filter.owner = mod;
73514-
73515- file_ops->format = ftrace_event_format_fops;
73516- file_ops->format.owner = mod;
73517+ pax_open_kernel();
73518+ *(void **)&mod->trace_id.owner = mod;
73519+ *(void **)&mod->trace_enable.owner = mod;
73520+ *(void **)&mod->trace_filter.owner = mod;
73521+ *(void **)&mod->trace_format.owner = mod;
73522+ pax_close_kernel();
73523
73524 list_add(&file_ops->list, &ftrace_module_file_list);
73525
73526@@ -1378,8 +1369,8 @@ static void trace_module_add_events(struct module *mod)
73527
73528 for_each_event(call, start, end) {
73529 __trace_add_event_call(*call, mod,
73530- &file_ops->id, &file_ops->enable,
73531- &file_ops->filter, &file_ops->format);
73532+ &mod->trace_id, &mod->trace_enable,
73533+ &mod->trace_filter, &mod->trace_format);
73534 }
73535 }
73536
73537diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
73538index fd3c8aa..5f324a6 100644
73539--- a/kernel/trace/trace_mmiotrace.c
73540+++ b/kernel/trace/trace_mmiotrace.c
73541@@ -24,7 +24,7 @@ struct header_iter {
73542 static struct trace_array *mmio_trace_array;
73543 static bool overrun_detected;
73544 static unsigned long prev_overruns;
73545-static atomic_t dropped_count;
73546+static atomic_unchecked_t dropped_count;
73547
73548 static void mmio_reset_data(struct trace_array *tr)
73549 {
73550@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
73551
73552 static unsigned long count_overruns(struct trace_iterator *iter)
73553 {
73554- unsigned long cnt = atomic_xchg(&dropped_count, 0);
73555+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
73556 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
73557
73558 if (over > prev_overruns)
73559@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
73560 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
73561 sizeof(*entry), 0, pc);
73562 if (!event) {
73563- atomic_inc(&dropped_count);
73564+ atomic_inc_unchecked(&dropped_count);
73565 return;
73566 }
73567 entry = ring_buffer_event_data(event);
73568@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
73569 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
73570 sizeof(*entry), 0, pc);
73571 if (!event) {
73572- atomic_inc(&dropped_count);
73573+ atomic_inc_unchecked(&dropped_count);
73574 return;
73575 }
73576 entry = ring_buffer_event_data(event);
73577diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
73578index 123b189..97b81f5 100644
73579--- a/kernel/trace/trace_output.c
73580+++ b/kernel/trace/trace_output.c
73581@@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
73582
73583 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
73584 if (!IS_ERR(p)) {
73585- p = mangle_path(s->buffer + s->len, p, "\n");
73586+ p = mangle_path(s->buffer + s->len, p, "\n\\");
73587 if (p) {
73588 s->len = p - s->buffer;
73589 return 1;
73590diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
73591index 0c1b1657..95337e9 100644
73592--- a/kernel/trace/trace_stack.c
73593+++ b/kernel/trace/trace_stack.c
73594@@ -53,7 +53,7 @@ static inline void check_stack(void)
73595 return;
73596
73597 /* we do not handle interrupt stacks yet */
73598- if (!object_is_on_stack(&this_size))
73599+ if (!object_starts_on_stack(&this_size))
73600 return;
73601
73602 local_irq_save(flags);
73603diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
73604index 28e9d6c9..50381bd 100644
73605--- a/lib/Kconfig.debug
73606+++ b/lib/Kconfig.debug
73607@@ -1278,6 +1278,7 @@ config LATENCYTOP
73608 depends on DEBUG_KERNEL
73609 depends on STACKTRACE_SUPPORT
73610 depends on PROC_FS
73611+ depends on !GRKERNSEC_HIDESYM
73612 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
73613 select KALLSYMS
73614 select KALLSYMS_ALL
73615@@ -1306,7 +1307,7 @@ config INTERVAL_TREE_TEST
73616
73617 config PROVIDE_OHCI1394_DMA_INIT
73618 bool "Remote debugging over FireWire early on boot"
73619- depends on PCI && X86
73620+ depends on PCI && X86 && !GRKERNSEC
73621 help
73622 If you want to debug problems which hang or crash the kernel early
73623 on boot and the crashing machine has a FireWire port, you can use
73624@@ -1335,7 +1336,7 @@ config PROVIDE_OHCI1394_DMA_INIT
73625
73626 config FIREWIRE_OHCI_REMOTE_DMA
73627 bool "Remote debugging over FireWire with firewire-ohci"
73628- depends on FIREWIRE_OHCI
73629+ depends on FIREWIRE_OHCI && !GRKERNSEC
73630 help
73631 This option lets you use the FireWire bus for remote debugging
73632 with help of the firewire-ohci driver. It enables unfiltered
73633diff --git a/lib/Makefile b/lib/Makefile
73634index a08b791..a3ff1eb 100644
73635--- a/lib/Makefile
73636+++ b/lib/Makefile
73637@@ -46,7 +46,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
73638
73639 obj-$(CONFIG_BTREE) += btree.o
73640 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
73641-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
73642+obj-y += list_debug.o
73643 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
73644
73645 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
73646diff --git a/lib/bitmap.c b/lib/bitmap.c
73647index 06fdfa1..97c5c7d 100644
73648--- a/lib/bitmap.c
73649+++ b/lib/bitmap.c
73650@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
73651 {
73652 int c, old_c, totaldigits, ndigits, nchunks, nbits;
73653 u32 chunk;
73654- const char __user __force *ubuf = (const char __user __force *)buf;
73655+ const char __user *ubuf = (const char __force_user *)buf;
73656
73657 bitmap_zero(maskp, nmaskbits);
73658
73659@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
73660 {
73661 if (!access_ok(VERIFY_READ, ubuf, ulen))
73662 return -EFAULT;
73663- return __bitmap_parse((const char __force *)ubuf,
73664+ return __bitmap_parse((const char __force_kernel *)ubuf,
73665 ulen, 1, maskp, nmaskbits);
73666
73667 }
73668@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
73669 {
73670 unsigned a, b;
73671 int c, old_c, totaldigits;
73672- const char __user __force *ubuf = (const char __user __force *)buf;
73673+ const char __user *ubuf = (const char __force_user *)buf;
73674 int exp_digit, in_range;
73675
73676 totaldigits = c = 0;
73677@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
73678 {
73679 if (!access_ok(VERIFY_READ, ubuf, ulen))
73680 return -EFAULT;
73681- return __bitmap_parselist((const char __force *)ubuf,
73682+ return __bitmap_parselist((const char __force_kernel *)ubuf,
73683 ulen, 1, maskp, nmaskbits);
73684 }
73685 EXPORT_SYMBOL(bitmap_parselist_user);
73686diff --git a/lib/bug.c b/lib/bug.c
73687index a28c141..2bd3d95 100644
73688--- a/lib/bug.c
73689+++ b/lib/bug.c
73690@@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
73691 return BUG_TRAP_TYPE_NONE;
73692
73693 bug = find_bug(bugaddr);
73694+ if (!bug)
73695+ return BUG_TRAP_TYPE_NONE;
73696
73697 file = NULL;
73698 line = 0;
73699diff --git a/lib/debugobjects.c b/lib/debugobjects.c
73700index d11808c..dc2d6f8 100644
73701--- a/lib/debugobjects.c
73702+++ b/lib/debugobjects.c
73703@@ -287,7 +287,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
73704 if (limit > 4)
73705 return;
73706
73707- is_on_stack = object_is_on_stack(addr);
73708+ is_on_stack = object_starts_on_stack(addr);
73709 if (is_on_stack == onstack)
73710 return;
73711
73712diff --git a/lib/devres.c b/lib/devres.c
73713index 80b9c76..9e32279 100644
73714--- a/lib/devres.c
73715+++ b/lib/devres.c
73716@@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
73717 void devm_iounmap(struct device *dev, void __iomem *addr)
73718 {
73719 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
73720- (void *)addr));
73721+ (void __force *)addr));
73722 iounmap(addr);
73723 }
73724 EXPORT_SYMBOL(devm_iounmap);
73725@@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
73726 {
73727 ioport_unmap(addr);
73728 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
73729- devm_ioport_map_match, (void *)addr));
73730+ devm_ioport_map_match, (void __force *)addr));
73731 }
73732 EXPORT_SYMBOL(devm_ioport_unmap);
73733
73734diff --git a/lib/dma-debug.c b/lib/dma-debug.c
73735index d84beb9..da44791 100644
73736--- a/lib/dma-debug.c
73737+++ b/lib/dma-debug.c
73738@@ -754,7 +754,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
73739
73740 void dma_debug_add_bus(struct bus_type *bus)
73741 {
73742- struct notifier_block *nb;
73743+ notifier_block_no_const *nb;
73744
73745 if (global_disable)
73746 return;
73747@@ -919,7 +919,7 @@ out:
73748
73749 static void check_for_stack(struct device *dev, void *addr)
73750 {
73751- if (object_is_on_stack(addr))
73752+ if (object_starts_on_stack(addr))
73753 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
73754 "stack [addr=%p]\n", addr);
73755 }
73756diff --git a/lib/inflate.c b/lib/inflate.c
73757index 013a761..c28f3fc 100644
73758--- a/lib/inflate.c
73759+++ b/lib/inflate.c
73760@@ -269,7 +269,7 @@ static void free(void *where)
73761 malloc_ptr = free_mem_ptr;
73762 }
73763 #else
73764-#define malloc(a) kmalloc(a, GFP_KERNEL)
73765+#define malloc(a) kmalloc((a), GFP_KERNEL)
73766 #define free(a) kfree(a)
73767 #endif
73768
73769diff --git a/lib/ioremap.c b/lib/ioremap.c
73770index 0c9216c..863bd89 100644
73771--- a/lib/ioremap.c
73772+++ b/lib/ioremap.c
73773@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
73774 unsigned long next;
73775
73776 phys_addr -= addr;
73777- pmd = pmd_alloc(&init_mm, pud, addr);
73778+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
73779 if (!pmd)
73780 return -ENOMEM;
73781 do {
73782@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
73783 unsigned long next;
73784
73785 phys_addr -= addr;
73786- pud = pud_alloc(&init_mm, pgd, addr);
73787+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
73788 if (!pud)
73789 return -ENOMEM;
73790 do {
73791diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
73792index bd2bea9..6b3c95e 100644
73793--- a/lib/is_single_threaded.c
73794+++ b/lib/is_single_threaded.c
73795@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
73796 struct task_struct *p, *t;
73797 bool ret;
73798
73799+ if (!mm)
73800+ return true;
73801+
73802 if (atomic_read(&task->signal->live) != 1)
73803 return false;
73804
73805diff --git a/lib/list_debug.c b/lib/list_debug.c
73806index c24c2f7..3fc5da0 100644
73807--- a/lib/list_debug.c
73808+++ b/lib/list_debug.c
73809@@ -11,7 +11,9 @@
73810 #include <linux/bug.h>
73811 #include <linux/kernel.h>
73812 #include <linux/rculist.h>
73813+#include <linux/mm.h>
73814
73815+#ifdef CONFIG_DEBUG_LIST
73816 /*
73817 * Insert a new entry between two known consecutive entries.
73818 *
73819@@ -19,21 +21,32 @@
73820 * the prev/next entries already!
73821 */
73822
73823-void __list_add(struct list_head *new,
73824- struct list_head *prev,
73825- struct list_head *next)
73826+static bool __list_add_debug(struct list_head *new,
73827+ struct list_head *prev,
73828+ struct list_head *next)
73829 {
73830- WARN(next->prev != prev,
73831+ if (WARN(next->prev != prev,
73832 "list_add corruption. next->prev should be "
73833 "prev (%p), but was %p. (next=%p).\n",
73834- prev, next->prev, next);
73835- WARN(prev->next != next,
73836+ prev, next->prev, next) ||
73837+ WARN(prev->next != next,
73838 "list_add corruption. prev->next should be "
73839 "next (%p), but was %p. (prev=%p).\n",
73840- next, prev->next, prev);
73841- WARN(new == prev || new == next,
73842+ next, prev->next, prev) ||
73843+ WARN(new == prev || new == next,
73844 "list_add double add: new=%p, prev=%p, next=%p.\n",
73845- new, prev, next);
73846+ new, prev, next))
73847+ return false;
73848+ return true;
73849+}
73850+
73851+void __list_add(struct list_head *new,
73852+ struct list_head *prev,
73853+ struct list_head *next)
73854+{
73855+ if (!__list_add_debug(new, prev, next))
73856+ return;
73857+
73858 next->prev = new;
73859 new->next = next;
73860 new->prev = prev;
73861@@ -41,7 +54,7 @@ void __list_add(struct list_head *new,
73862 }
73863 EXPORT_SYMBOL(__list_add);
73864
73865-void __list_del_entry(struct list_head *entry)
73866+static bool __list_del_entry_debug(struct list_head *entry)
73867 {
73868 struct list_head *prev, *next;
73869
73870@@ -60,9 +73,16 @@ void __list_del_entry(struct list_head *entry)
73871 WARN(next->prev != entry,
73872 "list_del corruption. next->prev should be %p, "
73873 "but was %p\n", entry, next->prev))
73874+ return false;
73875+ return true;
73876+}
73877+
73878+void __list_del_entry(struct list_head *entry)
73879+{
73880+ if (!__list_del_entry_debug(entry))
73881 return;
73882
73883- __list_del(prev, next);
73884+ __list_del(entry->prev, entry->next);
73885 }
73886 EXPORT_SYMBOL(__list_del_entry);
73887
73888@@ -86,15 +106,54 @@ EXPORT_SYMBOL(list_del);
73889 void __list_add_rcu(struct list_head *new,
73890 struct list_head *prev, struct list_head *next)
73891 {
73892- WARN(next->prev != prev,
73893+ if (WARN(next->prev != prev,
73894 "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
73895- prev, next->prev, next);
73896- WARN(prev->next != next,
73897+ prev, next->prev, next) ||
73898+ WARN(prev->next != next,
73899 "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
73900- next, prev->next, prev);
73901+ next, prev->next, prev))
73902+ return;
73903+
73904 new->next = next;
73905 new->prev = prev;
73906 rcu_assign_pointer(list_next_rcu(prev), new);
73907 next->prev = new;
73908 }
73909 EXPORT_SYMBOL(__list_add_rcu);
73910+#endif
73911+
73912+void pax_list_add_tail(struct list_head *new, struct list_head *head)
73913+{
73914+ struct list_head *prev, *next;
73915+
73916+ prev = head->prev;
73917+ next = head;
73918+
73919+#ifdef CONFIG_DEBUG_LIST
73920+ if (!__list_add_debug(new, prev, next))
73921+ return;
73922+#endif
73923+
73924+ pax_open_kernel();
73925+ next->prev = new;
73926+ new->next = next;
73927+ new->prev = prev;
73928+ prev->next = new;
73929+ pax_close_kernel();
73930+}
73931+EXPORT_SYMBOL(pax_list_add_tail);
73932+
73933+void pax_list_del(struct list_head *entry)
73934+{
73935+#ifdef CONFIG_DEBUG_LIST
73936+ if (!__list_del_entry_debug(entry))
73937+ return;
73938+#endif
73939+
73940+ pax_open_kernel();
73941+ __list_del(entry->prev, entry->next);
73942+ entry->next = LIST_POISON1;
73943+ entry->prev = LIST_POISON2;
73944+ pax_close_kernel();
73945+}
73946+EXPORT_SYMBOL(pax_list_del);
73947diff --git a/lib/radix-tree.c b/lib/radix-tree.c
73948index e796429..6e38f9f 100644
73949--- a/lib/radix-tree.c
73950+++ b/lib/radix-tree.c
73951@@ -92,7 +92,7 @@ struct radix_tree_preload {
73952 int nr;
73953 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
73954 };
73955-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
73956+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
73957
73958 static inline void *ptr_to_indirect(void *ptr)
73959 {
73960diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
73961index bb2b201..46abaf9 100644
73962--- a/lib/strncpy_from_user.c
73963+++ b/lib/strncpy_from_user.c
73964@@ -21,7 +21,7 @@
73965 */
73966 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
73967 {
73968- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
73969+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
73970 long res = 0;
73971
73972 /*
73973diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
73974index a28df52..3d55877 100644
73975--- a/lib/strnlen_user.c
73976+++ b/lib/strnlen_user.c
73977@@ -26,7 +26,7 @@
73978 */
73979 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
73980 {
73981- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
73982+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
73983 long align, res = 0;
73984 unsigned long c;
73985
73986diff --git a/lib/vsprintf.c b/lib/vsprintf.c
73987index 39c99fe..18f060b 100644
73988--- a/lib/vsprintf.c
73989+++ b/lib/vsprintf.c
73990@@ -16,6 +16,9 @@
73991 * - scnprintf and vscnprintf
73992 */
73993
73994+#ifdef CONFIG_GRKERNSEC_HIDESYM
73995+#define __INCLUDED_BY_HIDESYM 1
73996+#endif
73997 #include <stdarg.h>
73998 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
73999 #include <linux/types.h>
74000@@ -533,7 +536,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
74001 char sym[KSYM_SYMBOL_LEN];
74002 if (ext == 'B')
74003 sprint_backtrace(sym, value);
74004- else if (ext != 'f' && ext != 's')
74005+ else if (ext != 'f' && ext != 's' && ext != 'a')
74006 sprint_symbol(sym, value);
74007 else
74008 sprint_symbol_no_offset(sym, value);
74009@@ -966,7 +969,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
74010 return number(buf, end, *(const netdev_features_t *)addr, spec);
74011 }
74012
74013+#ifdef CONFIG_GRKERNSEC_HIDESYM
74014+int kptr_restrict __read_mostly = 2;
74015+#else
74016 int kptr_restrict __read_mostly;
74017+#endif
74018
74019 /*
74020 * Show a '%p' thing. A kernel extension is that the '%p' is followed
74021@@ -980,6 +987,8 @@ int kptr_restrict __read_mostly;
74022 * - 'S' For symbolic direct pointers with offset
74023 * - 's' For symbolic direct pointers without offset
74024 * - 'B' For backtraced symbolic direct pointers with offset
74025+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
74026+ * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
74027 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
74028 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
74029 * - 'M' For a 6-byte MAC address, it prints the address in the
74030@@ -1035,12 +1044,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
74031
74032 if (!ptr && *fmt != 'K') {
74033 /*
74034- * Print (null) with the same width as a pointer so it makes
74035+ * Print (nil) with the same width as a pointer so it makes
74036 * tabular output look nice.
74037 */
74038 if (spec.field_width == -1)
74039 spec.field_width = default_width;
74040- return string(buf, end, "(null)", spec);
74041+ return string(buf, end, "(nil)", spec);
74042 }
74043
74044 switch (*fmt) {
74045@@ -1050,6 +1059,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
74046 /* Fallthrough */
74047 case 'S':
74048 case 's':
74049+#ifdef CONFIG_GRKERNSEC_HIDESYM
74050+ break;
74051+#else
74052+ return symbol_string(buf, end, ptr, spec, *fmt);
74053+#endif
74054+ case 'A':
74055+ case 'a':
74056 case 'B':
74057 return symbol_string(buf, end, ptr, spec, *fmt);
74058 case 'R':
74059@@ -1090,6 +1106,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
74060 va_end(va);
74061 return buf;
74062 }
74063+ case 'P':
74064+ break;
74065 case 'K':
74066 /*
74067 * %pK cannot be used in IRQ context because its test
74068@@ -1113,6 +1131,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
74069 }
74070 break;
74071 }
74072+
74073+#ifdef CONFIG_GRKERNSEC_HIDESYM
74074+ /* 'P' = approved pointers to copy to userland,
74075+ as in the /proc/kallsyms case, as we make it display nothing
74076+ for non-root users, and the real contents for root users
74077+ Also ignore 'K' pointers, since we force their NULLing for non-root users
74078+ above
74079+ */
74080+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
74081+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
74082+ dump_stack();
74083+ ptr = NULL;
74084+ }
74085+#endif
74086+
74087 spec.flags |= SMALL;
74088 if (spec.field_width == -1) {
74089 spec.field_width = default_width;
74090@@ -1831,11 +1864,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
74091 typeof(type) value; \
74092 if (sizeof(type) == 8) { \
74093 args = PTR_ALIGN(args, sizeof(u32)); \
74094- *(u32 *)&value = *(u32 *)args; \
74095- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
74096+ *(u32 *)&value = *(const u32 *)args; \
74097+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
74098 } else { \
74099 args = PTR_ALIGN(args, sizeof(type)); \
74100- value = *(typeof(type) *)args; \
74101+ value = *(const typeof(type) *)args; \
74102 } \
74103 args += sizeof(type); \
74104 value; \
74105@@ -1898,7 +1931,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
74106 case FORMAT_TYPE_STR: {
74107 const char *str_arg = args;
74108 args += strlen(str_arg) + 1;
74109- str = string(str, end, (char *)str_arg, spec);
74110+ str = string(str, end, str_arg, spec);
74111 break;
74112 }
74113
74114diff --git a/localversion-grsec b/localversion-grsec
74115new file mode 100644
74116index 0000000..7cd6065
74117--- /dev/null
74118+++ b/localversion-grsec
74119@@ -0,0 +1 @@
74120+-grsec
74121diff --git a/mm/Kconfig b/mm/Kconfig
74122index a3f8ddd..f31e92e 100644
74123--- a/mm/Kconfig
74124+++ b/mm/Kconfig
74125@@ -252,10 +252,10 @@ config KSM
74126 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
74127
74128 config DEFAULT_MMAP_MIN_ADDR
74129- int "Low address space to protect from user allocation"
74130+ int "Low address space to protect from user allocation"
74131 depends on MMU
74132- default 4096
74133- help
74134+ default 65536
74135+ help
74136 This is the portion of low virtual memory which should be protected
74137 from userspace allocation. Keeping a user from writing to low pages
74138 can help reduce the impact of kernel NULL pointer bugs.
74139@@ -286,7 +286,7 @@ config MEMORY_FAILURE
74140
74141 config HWPOISON_INJECT
74142 tristate "HWPoison pages injector"
74143- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
74144+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
74145 select PROC_PAGE_MONITOR
74146
74147 config NOMMU_INITIAL_TRIM_EXCESS
74148diff --git a/mm/filemap.c b/mm/filemap.c
74149index 83efee7..3f99381 100644
74150--- a/mm/filemap.c
74151+++ b/mm/filemap.c
74152@@ -1747,7 +1747,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
74153 struct address_space *mapping = file->f_mapping;
74154
74155 if (!mapping->a_ops->readpage)
74156- return -ENOEXEC;
74157+ return -ENODEV;
74158 file_accessed(file);
74159 vma->vm_ops = &generic_file_vm_ops;
74160 return 0;
74161@@ -2087,6 +2087,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
74162 *pos = i_size_read(inode);
74163
74164 if (limit != RLIM_INFINITY) {
74165+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
74166 if (*pos >= limit) {
74167 send_sig(SIGXFSZ, current, 0);
74168 return -EFBIG;
74169diff --git a/mm/fremap.c b/mm/fremap.c
74170index a0aaf0e..20325c3 100644
74171--- a/mm/fremap.c
74172+++ b/mm/fremap.c
74173@@ -157,6 +157,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
74174 retry:
74175 vma = find_vma(mm, start);
74176
74177+#ifdef CONFIG_PAX_SEGMEXEC
74178+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
74179+ goto out;
74180+#endif
74181+
74182 /*
74183 * Make sure the vma is shared, that it supports prefaulting,
74184 * and that the remapped range is valid and fully within
74185diff --git a/mm/highmem.c b/mm/highmem.c
74186index 2da13a5..9568fec 100644
74187--- a/mm/highmem.c
74188+++ b/mm/highmem.c
74189@@ -137,9 +137,10 @@ static void flush_all_zero_pkmaps(void)
74190 * So no dangers, even with speculative execution.
74191 */
74192 page = pte_page(pkmap_page_table[i]);
74193+ pax_open_kernel();
74194 pte_clear(&init_mm, (unsigned long)page_address(page),
74195 &pkmap_page_table[i]);
74196-
74197+ pax_close_kernel();
74198 set_page_address(page, NULL);
74199 need_flush = 1;
74200 }
74201@@ -198,9 +199,11 @@ start:
74202 }
74203 }
74204 vaddr = PKMAP_ADDR(last_pkmap_nr);
74205+
74206+ pax_open_kernel();
74207 set_pte_at(&init_mm, vaddr,
74208 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
74209-
74210+ pax_close_kernel();
74211 pkmap_count[last_pkmap_nr] = 1;
74212 set_page_address(page, (void *)vaddr);
74213
74214diff --git a/mm/huge_memory.c b/mm/huge_memory.c
74215index 40f17c3..c1cc011 100644
74216--- a/mm/huge_memory.c
74217+++ b/mm/huge_memory.c
74218@@ -710,7 +710,7 @@ out:
74219 * run pte_offset_map on the pmd, if an huge pmd could
74220 * materialize from under us from a different thread.
74221 */
74222- if (unlikely(__pte_alloc(mm, vma, pmd, address)))
74223+ if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
74224 return VM_FAULT_OOM;
74225 /* if an huge pmd materialized from under us just retry later */
74226 if (unlikely(pmd_trans_huge(*pmd)))
74227diff --git a/mm/hugetlb.c b/mm/hugetlb.c
74228index 59a0059..b3f3d86 100644
74229--- a/mm/hugetlb.c
74230+++ b/mm/hugetlb.c
74231@@ -2518,6 +2518,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
74232 return 1;
74233 }
74234
74235+#ifdef CONFIG_PAX_SEGMEXEC
74236+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
74237+{
74238+ struct mm_struct *mm = vma->vm_mm;
74239+ struct vm_area_struct *vma_m;
74240+ unsigned long address_m;
74241+ pte_t *ptep_m;
74242+
74243+ vma_m = pax_find_mirror_vma(vma);
74244+ if (!vma_m)
74245+ return;
74246+
74247+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
74248+ address_m = address + SEGMEXEC_TASK_SIZE;
74249+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
74250+ get_page(page_m);
74251+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
74252+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
74253+}
74254+#endif
74255+
74256 /*
74257 * Hugetlb_cow() should be called with page lock of the original hugepage held.
74258 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
74259@@ -2636,6 +2657,11 @@ retry_avoidcopy:
74260 make_huge_pte(vma, new_page, 1));
74261 page_remove_rmap(old_page);
74262 hugepage_add_new_anon_rmap(new_page, vma, address);
74263+
74264+#ifdef CONFIG_PAX_SEGMEXEC
74265+ pax_mirror_huge_pte(vma, address, new_page);
74266+#endif
74267+
74268 /* Make the old page be freed below */
74269 new_page = old_page;
74270 }
74271@@ -2795,6 +2821,10 @@ retry:
74272 && (vma->vm_flags & VM_SHARED)));
74273 set_huge_pte_at(mm, address, ptep, new_pte);
74274
74275+#ifdef CONFIG_PAX_SEGMEXEC
74276+ pax_mirror_huge_pte(vma, address, page);
74277+#endif
74278+
74279 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
74280 /* Optimization, do the COW without a second fault */
74281 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
74282@@ -2824,6 +2854,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
74283 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
74284 struct hstate *h = hstate_vma(vma);
74285
74286+#ifdef CONFIG_PAX_SEGMEXEC
74287+ struct vm_area_struct *vma_m;
74288+#endif
74289+
74290 address &= huge_page_mask(h);
74291
74292 ptep = huge_pte_offset(mm, address);
74293@@ -2837,6 +2871,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
74294 VM_FAULT_SET_HINDEX(hstate_index(h));
74295 }
74296
74297+#ifdef CONFIG_PAX_SEGMEXEC
74298+ vma_m = pax_find_mirror_vma(vma);
74299+ if (vma_m) {
74300+ unsigned long address_m;
74301+
74302+ if (vma->vm_start > vma_m->vm_start) {
74303+ address_m = address;
74304+ address -= SEGMEXEC_TASK_SIZE;
74305+ vma = vma_m;
74306+ h = hstate_vma(vma);
74307+ } else
74308+ address_m = address + SEGMEXEC_TASK_SIZE;
74309+
74310+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
74311+ return VM_FAULT_OOM;
74312+ address_m &= HPAGE_MASK;
74313+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
74314+ }
74315+#endif
74316+
74317 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
74318 if (!ptep)
74319 return VM_FAULT_OOM;
74320diff --git a/mm/internal.h b/mm/internal.h
74321index a4fa284..9a02499 100644
74322--- a/mm/internal.h
74323+++ b/mm/internal.h
74324@@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
74325 * in mm/page_alloc.c
74326 */
74327 extern void __free_pages_bootmem(struct page *page, unsigned int order);
74328+extern void free_compound_page(struct page *page);
74329 extern void prep_compound_page(struct page *page, unsigned long order);
74330 #ifdef CONFIG_MEMORY_FAILURE
74331 extern bool is_free_buddy_page(struct page *page);
74332diff --git a/mm/kmemleak.c b/mm/kmemleak.c
74333index a217cc5..74c9ec0 100644
74334--- a/mm/kmemleak.c
74335+++ b/mm/kmemleak.c
74336@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
74337
74338 for (i = 0; i < object->trace_len; i++) {
74339 void *ptr = (void *)object->trace[i];
74340- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
74341+ seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
74342 }
74343 }
74344
74345diff --git a/mm/maccess.c b/mm/maccess.c
74346index d53adf9..03a24bf 100644
74347--- a/mm/maccess.c
74348+++ b/mm/maccess.c
74349@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
74350 set_fs(KERNEL_DS);
74351 pagefault_disable();
74352 ret = __copy_from_user_inatomic(dst,
74353- (__force const void __user *)src, size);
74354+ (const void __force_user *)src, size);
74355 pagefault_enable();
74356 set_fs(old_fs);
74357
74358@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
74359
74360 set_fs(KERNEL_DS);
74361 pagefault_disable();
74362- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
74363+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
74364 pagefault_enable();
74365 set_fs(old_fs);
74366
74367diff --git a/mm/madvise.c b/mm/madvise.c
74368index 03dfa5c..b032917 100644
74369--- a/mm/madvise.c
74370+++ b/mm/madvise.c
74371@@ -48,6 +48,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
74372 pgoff_t pgoff;
74373 unsigned long new_flags = vma->vm_flags;
74374
74375+#ifdef CONFIG_PAX_SEGMEXEC
74376+ struct vm_area_struct *vma_m;
74377+#endif
74378+
74379 switch (behavior) {
74380 case MADV_NORMAL:
74381 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
74382@@ -123,6 +127,13 @@ success:
74383 /*
74384 * vm_flags is protected by the mmap_sem held in write mode.
74385 */
74386+
74387+#ifdef CONFIG_PAX_SEGMEXEC
74388+ vma_m = pax_find_mirror_vma(vma);
74389+ if (vma_m)
74390+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
74391+#endif
74392+
74393 vma->vm_flags = new_flags;
74394
74395 out:
74396@@ -181,6 +192,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
74397 struct vm_area_struct ** prev,
74398 unsigned long start, unsigned long end)
74399 {
74400+
74401+#ifdef CONFIG_PAX_SEGMEXEC
74402+ struct vm_area_struct *vma_m;
74403+#endif
74404+
74405 *prev = vma;
74406 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
74407 return -EINVAL;
74408@@ -193,6 +209,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
74409 zap_page_range(vma, start, end - start, &details);
74410 } else
74411 zap_page_range(vma, start, end - start, NULL);
74412+
74413+#ifdef CONFIG_PAX_SEGMEXEC
74414+ vma_m = pax_find_mirror_vma(vma);
74415+ if (vma_m) {
74416+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
74417+ struct zap_details details = {
74418+ .nonlinear_vma = vma_m,
74419+ .last_index = ULONG_MAX,
74420+ };
74421+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
74422+ } else
74423+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
74424+ }
74425+#endif
74426+
74427 return 0;
74428 }
74429
74430@@ -397,6 +428,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
74431 if (end < start)
74432 goto out;
74433
74434+#ifdef CONFIG_PAX_SEGMEXEC
74435+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
74436+ if (end > SEGMEXEC_TASK_SIZE)
74437+ goto out;
74438+ } else
74439+#endif
74440+
74441+ if (end > TASK_SIZE)
74442+ goto out;
74443+
74444 error = 0;
74445 if (end == start)
74446 goto out;
74447diff --git a/mm/memory-failure.c b/mm/memory-failure.c
74448index 8b20278..05dac18 100644
74449--- a/mm/memory-failure.c
74450+++ b/mm/memory-failure.c
74451@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
74452
74453 int sysctl_memory_failure_recovery __read_mostly = 1;
74454
74455-atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
74456+atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
74457
74458 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
74459
74460@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
74461 pfn, t->comm, t->pid);
74462 si.si_signo = SIGBUS;
74463 si.si_errno = 0;
74464- si.si_addr = (void *)addr;
74465+ si.si_addr = (void __user *)addr;
74466 #ifdef __ARCH_SI_TRAPNO
74467 si.si_trapno = trapno;
74468 #endif
74469@@ -1040,7 +1040,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
74470 }
74471
74472 nr_pages = 1 << compound_trans_order(hpage);
74473- atomic_long_add(nr_pages, &mce_bad_pages);
74474+ atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
74475
74476 /*
74477 * We need/can do nothing about count=0 pages.
74478@@ -1070,7 +1070,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
74479 if (!PageHWPoison(hpage)
74480 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
74481 || (p != hpage && TestSetPageHWPoison(hpage))) {
74482- atomic_long_sub(nr_pages, &mce_bad_pages);
74483+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
74484 return 0;
74485 }
74486 set_page_hwpoison_huge_page(hpage);
74487@@ -1128,7 +1128,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
74488 }
74489 if (hwpoison_filter(p)) {
74490 if (TestClearPageHWPoison(p))
74491- atomic_long_sub(nr_pages, &mce_bad_pages);
74492+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
74493 unlock_page(hpage);
74494 put_page(hpage);
74495 return 0;
74496@@ -1323,7 +1323,7 @@ int unpoison_memory(unsigned long pfn)
74497 return 0;
74498 }
74499 if (TestClearPageHWPoison(p))
74500- atomic_long_sub(nr_pages, &mce_bad_pages);
74501+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
74502 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
74503 return 0;
74504 }
74505@@ -1337,7 +1337,7 @@ int unpoison_memory(unsigned long pfn)
74506 */
74507 if (TestClearPageHWPoison(page)) {
74508 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
74509- atomic_long_sub(nr_pages, &mce_bad_pages);
74510+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
74511 freeit = 1;
74512 if (PageHuge(page))
74513 clear_page_hwpoison_huge_page(page);
74514@@ -1442,7 +1442,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
74515 }
74516 done:
74517 if (!PageHWPoison(hpage))
74518- atomic_long_add(1 << compound_trans_order(hpage),
74519+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
74520 &mce_bad_pages);
74521 set_page_hwpoison_huge_page(hpage);
74522 dequeue_hwpoisoned_huge_page(hpage);
74523@@ -1582,7 +1582,7 @@ int soft_offline_page(struct page *page, int flags)
74524 return ret;
74525
74526 done:
74527- atomic_long_add(1, &mce_bad_pages);
74528+ atomic_long_add_unchecked(1, &mce_bad_pages);
74529 SetPageHWPoison(page);
74530 /* keep elevated page count for bad page */
74531 return ret;
74532diff --git a/mm/memory.c b/mm/memory.c
74533index 221fc9f..d1d4db1 100644
74534--- a/mm/memory.c
74535+++ b/mm/memory.c
74536@@ -426,6 +426,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
74537 free_pte_range(tlb, pmd, addr);
74538 } while (pmd++, addr = next, addr != end);
74539
74540+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
74541 start &= PUD_MASK;
74542 if (start < floor)
74543 return;
74544@@ -440,6 +441,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
74545 pmd = pmd_offset(pud, start);
74546 pud_clear(pud);
74547 pmd_free_tlb(tlb, pmd, start);
74548+#endif
74549+
74550 }
74551
74552 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
74553@@ -459,6 +462,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
74554 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
74555 } while (pud++, addr = next, addr != end);
74556
74557+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
74558 start &= PGDIR_MASK;
74559 if (start < floor)
74560 return;
74561@@ -473,6 +477,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
74562 pud = pud_offset(pgd, start);
74563 pgd_clear(pgd);
74564 pud_free_tlb(tlb, pud, start);
74565+#endif
74566+
74567 }
74568
74569 /*
74570@@ -1621,12 +1627,6 @@ no_page_table:
74571 return page;
74572 }
74573
74574-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
74575-{
74576- return stack_guard_page_start(vma, addr) ||
74577- stack_guard_page_end(vma, addr+PAGE_SIZE);
74578-}
74579-
74580 /**
74581 * __get_user_pages() - pin user pages in memory
74582 * @tsk: task_struct of target task
74583@@ -1699,10 +1699,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
74584 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
74585 i = 0;
74586
74587- do {
74588+ while (nr_pages) {
74589 struct vm_area_struct *vma;
74590
74591- vma = find_extend_vma(mm, start);
74592+ vma = find_vma(mm, start);
74593 if (!vma && in_gate_area(mm, start)) {
74594 unsigned long pg = start & PAGE_MASK;
74595 pgd_t *pgd;
74596@@ -1750,7 +1750,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
74597 goto next_page;
74598 }
74599
74600- if (!vma ||
74601+ if (!vma || start < vma->vm_start ||
74602 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
74603 !(vm_flags & vma->vm_flags))
74604 return i ? : -EFAULT;
74605@@ -1777,11 +1777,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
74606 int ret;
74607 unsigned int fault_flags = 0;
74608
74609- /* For mlock, just skip the stack guard page. */
74610- if (foll_flags & FOLL_MLOCK) {
74611- if (stack_guard_page(vma, start))
74612- goto next_page;
74613- }
74614 if (foll_flags & FOLL_WRITE)
74615 fault_flags |= FAULT_FLAG_WRITE;
74616 if (nonblocking)
74617@@ -1855,7 +1850,7 @@ next_page:
74618 start += PAGE_SIZE;
74619 nr_pages--;
74620 } while (nr_pages && start < vma->vm_end);
74621- } while (nr_pages);
74622+ }
74623 return i;
74624 }
74625 EXPORT_SYMBOL(__get_user_pages);
74626@@ -2062,6 +2057,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
74627 page_add_file_rmap(page);
74628 set_pte_at(mm, addr, pte, mk_pte(page, prot));
74629
74630+#ifdef CONFIG_PAX_SEGMEXEC
74631+ pax_mirror_file_pte(vma, addr, page, ptl);
74632+#endif
74633+
74634 retval = 0;
74635 pte_unmap_unlock(pte, ptl);
74636 return retval;
74637@@ -2106,9 +2105,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
74638 if (!page_count(page))
74639 return -EINVAL;
74640 if (!(vma->vm_flags & VM_MIXEDMAP)) {
74641+
74642+#ifdef CONFIG_PAX_SEGMEXEC
74643+ struct vm_area_struct *vma_m;
74644+#endif
74645+
74646 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
74647 BUG_ON(vma->vm_flags & VM_PFNMAP);
74648 vma->vm_flags |= VM_MIXEDMAP;
74649+
74650+#ifdef CONFIG_PAX_SEGMEXEC
74651+ vma_m = pax_find_mirror_vma(vma);
74652+ if (vma_m)
74653+ vma_m->vm_flags |= VM_MIXEDMAP;
74654+#endif
74655+
74656 }
74657 return insert_page(vma, addr, page, vma->vm_page_prot);
74658 }
74659@@ -2191,6 +2202,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
74660 unsigned long pfn)
74661 {
74662 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
74663+ BUG_ON(vma->vm_mirror);
74664
74665 if (addr < vma->vm_start || addr >= vma->vm_end)
74666 return -EFAULT;
74667@@ -2391,7 +2403,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
74668
74669 BUG_ON(pud_huge(*pud));
74670
74671- pmd = pmd_alloc(mm, pud, addr);
74672+ pmd = (mm == &init_mm) ?
74673+ pmd_alloc_kernel(mm, pud, addr) :
74674+ pmd_alloc(mm, pud, addr);
74675 if (!pmd)
74676 return -ENOMEM;
74677 do {
74678@@ -2411,7 +2425,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
74679 unsigned long next;
74680 int err;
74681
74682- pud = pud_alloc(mm, pgd, addr);
74683+ pud = (mm == &init_mm) ?
74684+ pud_alloc_kernel(mm, pgd, addr) :
74685+ pud_alloc(mm, pgd, addr);
74686 if (!pud)
74687 return -ENOMEM;
74688 do {
74689@@ -2499,6 +2515,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
74690 copy_user_highpage(dst, src, va, vma);
74691 }
74692
74693+#ifdef CONFIG_PAX_SEGMEXEC
74694+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
74695+{
74696+ struct mm_struct *mm = vma->vm_mm;
74697+ spinlock_t *ptl;
74698+ pte_t *pte, entry;
74699+
74700+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
74701+ entry = *pte;
74702+ if (!pte_present(entry)) {
74703+ if (!pte_none(entry)) {
74704+ BUG_ON(pte_file(entry));
74705+ free_swap_and_cache(pte_to_swp_entry(entry));
74706+ pte_clear_not_present_full(mm, address, pte, 0);
74707+ }
74708+ } else {
74709+ struct page *page;
74710+
74711+ flush_cache_page(vma, address, pte_pfn(entry));
74712+ entry = ptep_clear_flush(vma, address, pte);
74713+ BUG_ON(pte_dirty(entry));
74714+ page = vm_normal_page(vma, address, entry);
74715+ if (page) {
74716+ update_hiwater_rss(mm);
74717+ if (PageAnon(page))
74718+ dec_mm_counter_fast(mm, MM_ANONPAGES);
74719+ else
74720+ dec_mm_counter_fast(mm, MM_FILEPAGES);
74721+ page_remove_rmap(page);
74722+ page_cache_release(page);
74723+ }
74724+ }
74725+ pte_unmap_unlock(pte, ptl);
74726+}
74727+
74728+/* PaX: if vma is mirrored, synchronize the mirror's PTE
74729+ *
74730+ * the ptl of the lower mapped page is held on entry and is not released on exit
74731+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
74732+ */
74733+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
74734+{
74735+ struct mm_struct *mm = vma->vm_mm;
74736+ unsigned long address_m;
74737+ spinlock_t *ptl_m;
74738+ struct vm_area_struct *vma_m;
74739+ pmd_t *pmd_m;
74740+ pte_t *pte_m, entry_m;
74741+
74742+ BUG_ON(!page_m || !PageAnon(page_m));
74743+
74744+ vma_m = pax_find_mirror_vma(vma);
74745+ if (!vma_m)
74746+ return;
74747+
74748+ BUG_ON(!PageLocked(page_m));
74749+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
74750+ address_m = address + SEGMEXEC_TASK_SIZE;
74751+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
74752+ pte_m = pte_offset_map(pmd_m, address_m);
74753+ ptl_m = pte_lockptr(mm, pmd_m);
74754+ if (ptl != ptl_m) {
74755+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
74756+ if (!pte_none(*pte_m))
74757+ goto out;
74758+ }
74759+
74760+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
74761+ page_cache_get(page_m);
74762+ page_add_anon_rmap(page_m, vma_m, address_m);
74763+ inc_mm_counter_fast(mm, MM_ANONPAGES);
74764+ set_pte_at(mm, address_m, pte_m, entry_m);
74765+ update_mmu_cache(vma_m, address_m, entry_m);
74766+out:
74767+ if (ptl != ptl_m)
74768+ spin_unlock(ptl_m);
74769+ pte_unmap(pte_m);
74770+ unlock_page(page_m);
74771+}
74772+
74773+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
74774+{
74775+ struct mm_struct *mm = vma->vm_mm;
74776+ unsigned long address_m;
74777+ spinlock_t *ptl_m;
74778+ struct vm_area_struct *vma_m;
74779+ pmd_t *pmd_m;
74780+ pte_t *pte_m, entry_m;
74781+
74782+ BUG_ON(!page_m || PageAnon(page_m));
74783+
74784+ vma_m = pax_find_mirror_vma(vma);
74785+ if (!vma_m)
74786+ return;
74787+
74788+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
74789+ address_m = address + SEGMEXEC_TASK_SIZE;
74790+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
74791+ pte_m = pte_offset_map(pmd_m, address_m);
74792+ ptl_m = pte_lockptr(mm, pmd_m);
74793+ if (ptl != ptl_m) {
74794+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
74795+ if (!pte_none(*pte_m))
74796+ goto out;
74797+ }
74798+
74799+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
74800+ page_cache_get(page_m);
74801+ page_add_file_rmap(page_m);
74802+ inc_mm_counter_fast(mm, MM_FILEPAGES);
74803+ set_pte_at(mm, address_m, pte_m, entry_m);
74804+ update_mmu_cache(vma_m, address_m, entry_m);
74805+out:
74806+ if (ptl != ptl_m)
74807+ spin_unlock(ptl_m);
74808+ pte_unmap(pte_m);
74809+}
74810+
74811+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
74812+{
74813+ struct mm_struct *mm = vma->vm_mm;
74814+ unsigned long address_m;
74815+ spinlock_t *ptl_m;
74816+ struct vm_area_struct *vma_m;
74817+ pmd_t *pmd_m;
74818+ pte_t *pte_m, entry_m;
74819+
74820+ vma_m = pax_find_mirror_vma(vma);
74821+ if (!vma_m)
74822+ return;
74823+
74824+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
74825+ address_m = address + SEGMEXEC_TASK_SIZE;
74826+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
74827+ pte_m = pte_offset_map(pmd_m, address_m);
74828+ ptl_m = pte_lockptr(mm, pmd_m);
74829+ if (ptl != ptl_m) {
74830+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
74831+ if (!pte_none(*pte_m))
74832+ goto out;
74833+ }
74834+
74835+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
74836+ set_pte_at(mm, address_m, pte_m, entry_m);
74837+out:
74838+ if (ptl != ptl_m)
74839+ spin_unlock(ptl_m);
74840+ pte_unmap(pte_m);
74841+}
74842+
74843+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
74844+{
74845+ struct page *page_m;
74846+ pte_t entry;
74847+
74848+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
74849+ goto out;
74850+
74851+ entry = *pte;
74852+ page_m = vm_normal_page(vma, address, entry);
74853+ if (!page_m)
74854+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
74855+ else if (PageAnon(page_m)) {
74856+ if (pax_find_mirror_vma(vma)) {
74857+ pte_unmap_unlock(pte, ptl);
74858+ lock_page(page_m);
74859+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
74860+ if (pte_same(entry, *pte))
74861+ pax_mirror_anon_pte(vma, address, page_m, ptl);
74862+ else
74863+ unlock_page(page_m);
74864+ }
74865+ } else
74866+ pax_mirror_file_pte(vma, address, page_m, ptl);
74867+
74868+out:
74869+ pte_unmap_unlock(pte, ptl);
74870+}
74871+#endif
74872+
74873 /*
74874 * This routine handles present pages, when users try to write
74875 * to a shared page. It is done by copying the page to a new address
74876@@ -2715,6 +2911,12 @@ gotten:
74877 */
74878 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
74879 if (likely(pte_same(*page_table, orig_pte))) {
74880+
74881+#ifdef CONFIG_PAX_SEGMEXEC
74882+ if (pax_find_mirror_vma(vma))
74883+ BUG_ON(!trylock_page(new_page));
74884+#endif
74885+
74886 if (old_page) {
74887 if (!PageAnon(old_page)) {
74888 dec_mm_counter_fast(mm, MM_FILEPAGES);
74889@@ -2766,6 +2968,10 @@ gotten:
74890 page_remove_rmap(old_page);
74891 }
74892
74893+#ifdef CONFIG_PAX_SEGMEXEC
74894+ pax_mirror_anon_pte(vma, address, new_page, ptl);
74895+#endif
74896+
74897 /* Free the old page.. */
74898 new_page = old_page;
74899 ret |= VM_FAULT_WRITE;
74900@@ -3046,6 +3252,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
74901 swap_free(entry);
74902 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
74903 try_to_free_swap(page);
74904+
74905+#ifdef CONFIG_PAX_SEGMEXEC
74906+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
74907+#endif
74908+
74909 unlock_page(page);
74910 if (swapcache) {
74911 /*
74912@@ -3069,6 +3280,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
74913
74914 /* No need to invalidate - it was non-present before */
74915 update_mmu_cache(vma, address, page_table);
74916+
74917+#ifdef CONFIG_PAX_SEGMEXEC
74918+ pax_mirror_anon_pte(vma, address, page, ptl);
74919+#endif
74920+
74921 unlock:
74922 pte_unmap_unlock(page_table, ptl);
74923 out:
74924@@ -3088,40 +3304,6 @@ out_release:
74925 }
74926
74927 /*
74928- * This is like a special single-page "expand_{down|up}wards()",
74929- * except we must first make sure that 'address{-|+}PAGE_SIZE'
74930- * doesn't hit another vma.
74931- */
74932-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
74933-{
74934- address &= PAGE_MASK;
74935- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
74936- struct vm_area_struct *prev = vma->vm_prev;
74937-
74938- /*
74939- * Is there a mapping abutting this one below?
74940- *
74941- * That's only ok if it's the same stack mapping
74942- * that has gotten split..
74943- */
74944- if (prev && prev->vm_end == address)
74945- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
74946-
74947- expand_downwards(vma, address - PAGE_SIZE);
74948- }
74949- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
74950- struct vm_area_struct *next = vma->vm_next;
74951-
74952- /* As VM_GROWSDOWN but s/below/above/ */
74953- if (next && next->vm_start == address + PAGE_SIZE)
74954- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
74955-
74956- expand_upwards(vma, address + PAGE_SIZE);
74957- }
74958- return 0;
74959-}
74960-
74961-/*
74962 * We enter with non-exclusive mmap_sem (to exclude vma changes,
74963 * but allow concurrent faults), and pte mapped but not yet locked.
74964 * We return with mmap_sem still held, but pte unmapped and unlocked.
74965@@ -3130,27 +3312,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
74966 unsigned long address, pte_t *page_table, pmd_t *pmd,
74967 unsigned int flags)
74968 {
74969- struct page *page;
74970+ struct page *page = NULL;
74971 spinlock_t *ptl;
74972 pte_t entry;
74973
74974- pte_unmap(page_table);
74975-
74976- /* Check if we need to add a guard page to the stack */
74977- if (check_stack_guard_page(vma, address) < 0)
74978- return VM_FAULT_SIGBUS;
74979-
74980- /* Use the zero-page for reads */
74981 if (!(flags & FAULT_FLAG_WRITE)) {
74982 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
74983 vma->vm_page_prot));
74984- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
74985+ ptl = pte_lockptr(mm, pmd);
74986+ spin_lock(ptl);
74987 if (!pte_none(*page_table))
74988 goto unlock;
74989 goto setpte;
74990 }
74991
74992 /* Allocate our own private page. */
74993+ pte_unmap(page_table);
74994+
74995 if (unlikely(anon_vma_prepare(vma)))
74996 goto oom;
74997 page = alloc_zeroed_user_highpage_movable(vma, address);
74998@@ -3169,6 +3347,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
74999 if (!pte_none(*page_table))
75000 goto release;
75001
75002+#ifdef CONFIG_PAX_SEGMEXEC
75003+ if (pax_find_mirror_vma(vma))
75004+ BUG_ON(!trylock_page(page));
75005+#endif
75006+
75007 inc_mm_counter_fast(mm, MM_ANONPAGES);
75008 page_add_new_anon_rmap(page, vma, address);
75009 setpte:
75010@@ -3176,6 +3359,12 @@ setpte:
75011
75012 /* No need to invalidate - it was non-present before */
75013 update_mmu_cache(vma, address, page_table);
75014+
75015+#ifdef CONFIG_PAX_SEGMEXEC
75016+ if (page)
75017+ pax_mirror_anon_pte(vma, address, page, ptl);
75018+#endif
75019+
75020 unlock:
75021 pte_unmap_unlock(page_table, ptl);
75022 return 0;
75023@@ -3319,6 +3508,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
75024 */
75025 /* Only go through if we didn't race with anybody else... */
75026 if (likely(pte_same(*page_table, orig_pte))) {
75027+
75028+#ifdef CONFIG_PAX_SEGMEXEC
75029+ if (anon && pax_find_mirror_vma(vma))
75030+ BUG_ON(!trylock_page(page));
75031+#endif
75032+
75033 flush_icache_page(vma, page);
75034 entry = mk_pte(page, vma->vm_page_prot);
75035 if (flags & FAULT_FLAG_WRITE)
75036@@ -3338,6 +3533,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
75037
75038 /* no need to invalidate: a not-present page won't be cached */
75039 update_mmu_cache(vma, address, page_table);
75040+
75041+#ifdef CONFIG_PAX_SEGMEXEC
75042+ if (anon)
75043+ pax_mirror_anon_pte(vma, address, page, ptl);
75044+ else
75045+ pax_mirror_file_pte(vma, address, page, ptl);
75046+#endif
75047+
75048 } else {
75049 if (cow_page)
75050 mem_cgroup_uncharge_page(cow_page);
75051@@ -3492,6 +3695,12 @@ int handle_pte_fault(struct mm_struct *mm,
75052 if (flags & FAULT_FLAG_WRITE)
75053 flush_tlb_fix_spurious_fault(vma, address);
75054 }
75055+
75056+#ifdef CONFIG_PAX_SEGMEXEC
75057+ pax_mirror_pte(vma, address, pte, pmd, ptl);
75058+ return 0;
75059+#endif
75060+
75061 unlock:
75062 pte_unmap_unlock(pte, ptl);
75063 return 0;
75064@@ -3508,6 +3717,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
75065 pmd_t *pmd;
75066 pte_t *pte;
75067
75068+#ifdef CONFIG_PAX_SEGMEXEC
75069+ struct vm_area_struct *vma_m;
75070+#endif
75071+
75072 __set_current_state(TASK_RUNNING);
75073
75074 count_vm_event(PGFAULT);
75075@@ -3519,6 +3732,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
75076 if (unlikely(is_vm_hugetlb_page(vma)))
75077 return hugetlb_fault(mm, vma, address, flags);
75078
75079+#ifdef CONFIG_PAX_SEGMEXEC
75080+ vma_m = pax_find_mirror_vma(vma);
75081+ if (vma_m) {
75082+ unsigned long address_m;
75083+ pgd_t *pgd_m;
75084+ pud_t *pud_m;
75085+ pmd_t *pmd_m;
75086+
75087+ if (vma->vm_start > vma_m->vm_start) {
75088+ address_m = address;
75089+ address -= SEGMEXEC_TASK_SIZE;
75090+ vma = vma_m;
75091+ } else
75092+ address_m = address + SEGMEXEC_TASK_SIZE;
75093+
75094+ pgd_m = pgd_offset(mm, address_m);
75095+ pud_m = pud_alloc(mm, pgd_m, address_m);
75096+ if (!pud_m)
75097+ return VM_FAULT_OOM;
75098+ pmd_m = pmd_alloc(mm, pud_m, address_m);
75099+ if (!pmd_m)
75100+ return VM_FAULT_OOM;
75101+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
75102+ return VM_FAULT_OOM;
75103+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
75104+ }
75105+#endif
75106+
75107 retry:
75108 pgd = pgd_offset(mm, address);
75109 pud = pud_alloc(mm, pgd, address);
75110@@ -3560,7 +3801,7 @@ retry:
75111 * run pte_offset_map on the pmd, if an huge pmd could
75112 * materialize from under us from a different thread.
75113 */
75114- if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
75115+ if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
75116 return VM_FAULT_OOM;
75117 /* if an huge pmd materialized from under us just retry later */
75118 if (unlikely(pmd_trans_huge(*pmd)))
75119@@ -3597,6 +3838,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
75120 spin_unlock(&mm->page_table_lock);
75121 return 0;
75122 }
75123+
75124+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
75125+{
75126+ pud_t *new = pud_alloc_one(mm, address);
75127+ if (!new)
75128+ return -ENOMEM;
75129+
75130+ smp_wmb(); /* See comment in __pte_alloc */
75131+
75132+ spin_lock(&mm->page_table_lock);
75133+ if (pgd_present(*pgd)) /* Another has populated it */
75134+ pud_free(mm, new);
75135+ else
75136+ pgd_populate_kernel(mm, pgd, new);
75137+ spin_unlock(&mm->page_table_lock);
75138+ return 0;
75139+}
75140 #endif /* __PAGETABLE_PUD_FOLDED */
75141
75142 #ifndef __PAGETABLE_PMD_FOLDED
75143@@ -3627,6 +3885,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
75144 spin_unlock(&mm->page_table_lock);
75145 return 0;
75146 }
75147+
75148+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
75149+{
75150+ pmd_t *new = pmd_alloc_one(mm, address);
75151+ if (!new)
75152+ return -ENOMEM;
75153+
75154+ smp_wmb(); /* See comment in __pte_alloc */
75155+
75156+ spin_lock(&mm->page_table_lock);
75157+#ifndef __ARCH_HAS_4LEVEL_HACK
75158+ if (pud_present(*pud)) /* Another has populated it */
75159+ pmd_free(mm, new);
75160+ else
75161+ pud_populate_kernel(mm, pud, new);
75162+#else
75163+ if (pgd_present(*pud)) /* Another has populated it */
75164+ pmd_free(mm, new);
75165+ else
75166+ pgd_populate_kernel(mm, pud, new);
75167+#endif /* __ARCH_HAS_4LEVEL_HACK */
75168+ spin_unlock(&mm->page_table_lock);
75169+ return 0;
75170+}
75171 #endif /* __PAGETABLE_PMD_FOLDED */
75172
75173 int make_pages_present(unsigned long addr, unsigned long end)
75174@@ -3664,7 +3946,7 @@ static int __init gate_vma_init(void)
75175 gate_vma.vm_start = FIXADDR_USER_START;
75176 gate_vma.vm_end = FIXADDR_USER_END;
75177 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
75178- gate_vma.vm_page_prot = __P101;
75179+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
75180
75181 return 0;
75182 }
75183diff --git a/mm/mempolicy.c b/mm/mempolicy.c
75184index 4ea600d..9429765 100644
75185--- a/mm/mempolicy.c
75186+++ b/mm/mempolicy.c
75187@@ -655,6 +655,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
75188 unsigned long vmstart;
75189 unsigned long vmend;
75190
75191+#ifdef CONFIG_PAX_SEGMEXEC
75192+ struct vm_area_struct *vma_m;
75193+#endif
75194+
75195 vma = find_vma(mm, start);
75196 if (!vma || vma->vm_start > start)
75197 return -EFAULT;
75198@@ -691,9 +695,20 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
75199 if (err)
75200 goto out;
75201 }
75202+
75203 err = vma_replace_policy(vma, new_pol);
75204 if (err)
75205 goto out;
75206+
75207+#ifdef CONFIG_PAX_SEGMEXEC
75208+ vma_m = pax_find_mirror_vma(vma);
75209+ if (vma_m) {
75210+ err = vma_replace_policy(vma_m, new_pol);
75211+ if (err)
75212+ goto out;
75213+ }
75214+#endif
75215+
75216 }
75217
75218 out:
75219@@ -1150,6 +1165,17 @@ static long do_mbind(unsigned long start, unsigned long len,
75220
75221 if (end < start)
75222 return -EINVAL;
75223+
75224+#ifdef CONFIG_PAX_SEGMEXEC
75225+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
75226+ if (end > SEGMEXEC_TASK_SIZE)
75227+ return -EINVAL;
75228+ } else
75229+#endif
75230+
75231+ if (end > TASK_SIZE)
75232+ return -EINVAL;
75233+
75234 if (end == start)
75235 return 0;
75236
75237@@ -1373,8 +1399,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
75238 */
75239 tcred = __task_cred(task);
75240 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
75241- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
75242- !capable(CAP_SYS_NICE)) {
75243+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
75244 rcu_read_unlock();
75245 err = -EPERM;
75246 goto out_put;
75247@@ -1405,6 +1430,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
75248 goto out;
75249 }
75250
75251+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
75252+ if (mm != current->mm &&
75253+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
75254+ mmput(mm);
75255+ err = -EPERM;
75256+ goto out;
75257+ }
75258+#endif
75259+
75260 err = do_migrate_pages(mm, old, new,
75261 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
75262
75263@@ -2372,8 +2406,7 @@ void numa_default_policy(void)
75264 */
75265
75266 /*
75267- * "local" is pseudo-policy: MPOL_PREFERRED with MPOL_F_LOCAL flag
75268- * Used only for mpol_parse_str() and mpol_to_str()
75269+ * "local" is implemented internally by MPOL_PREFERRED with MPOL_F_LOCAL flag.
75270 */
75271 #define MPOL_LOCAL MPOL_MAX
75272 static const char * const policy_modes[] =
75273@@ -2388,28 +2421,21 @@ static const char * const policy_modes[] =
75274
75275 #ifdef CONFIG_TMPFS
75276 /**
75277- * mpol_parse_str - parse string to mempolicy
75278+ * mpol_parse_str - parse string to mempolicy, for tmpfs mpol mount option.
75279 * @str: string containing mempolicy to parse
75280 * @mpol: pointer to struct mempolicy pointer, returned on success.
75281- * @no_context: flag whether to "contextualize" the mempolicy
75282+ * @unused: redundant argument, to be removed later.
75283 *
75284 * Format of input:
75285 * <mode>[=<flags>][:<nodelist>]
75286 *
75287- * if @no_context is true, save the input nodemask in w.user_nodemask in
75288- * the returned mempolicy. This will be used to "clone" the mempolicy in
75289- * a specific context [cpuset] at a later time. Used to parse tmpfs mpol
75290- * mount option. Note that if 'static' or 'relative' mode flags were
75291- * specified, the input nodemask will already have been saved. Saving
75292- * it again is redundant, but safe.
75293- *
75294 * On success, returns 0, else 1
75295 */
75296-int mpol_parse_str(char *str, struct mempolicy **mpol, int no_context)
75297+int mpol_parse_str(char *str, struct mempolicy **mpol, int unused)
75298 {
75299 struct mempolicy *new = NULL;
75300 unsigned short mode;
75301- unsigned short uninitialized_var(mode_flags);
75302+ unsigned short mode_flags;
75303 nodemask_t nodes;
75304 char *nodelist = strchr(str, ':');
75305 char *flags = strchr(str, '=');
75306@@ -2497,24 +2523,23 @@ int mpol_parse_str(char *str, struct mempolicy **mpol, int no_context)
75307 if (IS_ERR(new))
75308 goto out;
75309
75310- if (no_context) {
75311- /* save for contextualization */
75312- new->w.user_nodemask = nodes;
75313- } else {
75314- int ret;
75315- NODEMASK_SCRATCH(scratch);
75316- if (scratch) {
75317- task_lock(current);
75318- ret = mpol_set_nodemask(new, &nodes, scratch);
75319- task_unlock(current);
75320- } else
75321- ret = -ENOMEM;
75322- NODEMASK_SCRATCH_FREE(scratch);
75323- if (ret) {
75324- mpol_put(new);
75325- goto out;
75326- }
75327- }
75328+ /*
75329+ * Save nodes for mpol_to_str() to show the tmpfs mount options
75330+ * for /proc/mounts, /proc/pid/mounts and /proc/pid/mountinfo.
75331+ */
75332+ if (mode != MPOL_PREFERRED)
75333+ new->v.nodes = nodes;
75334+ else if (nodelist)
75335+ new->v.preferred_node = first_node(nodes);
75336+ else
75337+ new->flags |= MPOL_F_LOCAL;
75338+
75339+ /*
75340+ * Save nodes for contextualization: this will be used to "clone"
75341+ * the mempolicy in a specific context [cpuset] at a later time.
75342+ */
75343+ new->w.user_nodemask = nodes;
75344+
75345 err = 0;
75346
75347 out:
75348@@ -2534,13 +2559,13 @@ out:
75349 * @buffer: to contain formatted mempolicy string
75350 * @maxlen: length of @buffer
75351 * @pol: pointer to mempolicy to be formatted
75352- * @no_context: "context free" mempolicy - use nodemask in w.user_nodemask
75353+ * @unused: redundant argument, to be removed later.
75354 *
75355 * Convert a mempolicy into a string.
75356 * Returns the number of characters in buffer (if positive)
75357 * or an error (negative)
75358 */
75359-int mpol_to_str(char *buffer, int maxlen, struct mempolicy *pol, int no_context)
75360+int mpol_to_str(char *buffer, int maxlen, struct mempolicy *pol, int unused)
75361 {
75362 char *p = buffer;
75363 int l;
75364@@ -2566,7 +2591,7 @@ int mpol_to_str(char *buffer, int maxlen, struct mempolicy *pol, int no_context)
75365 case MPOL_PREFERRED:
75366 nodes_clear(nodes);
75367 if (flags & MPOL_F_LOCAL)
75368- mode = MPOL_LOCAL; /* pseudo-policy */
75369+ mode = MPOL_LOCAL;
75370 else
75371 node_set(pol->v.preferred_node, nodes);
75372 break;
75373@@ -2574,10 +2599,7 @@ int mpol_to_str(char *buffer, int maxlen, struct mempolicy *pol, int no_context)
75374 case MPOL_BIND:
75375 /* Fall through */
75376 case MPOL_INTERLEAVE:
75377- if (no_context)
75378- nodes = pol->w.user_nodemask;
75379- else
75380- nodes = pol->v.nodes;
75381+ nodes = pol->v.nodes;
75382 break;
75383
75384 default:
75385diff --git a/mm/migrate.c b/mm/migrate.c
75386index 77ed2d7..317d528 100644
75387--- a/mm/migrate.c
75388+++ b/mm/migrate.c
75389@@ -1350,8 +1350,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
75390 */
75391 tcred = __task_cred(task);
75392 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
75393- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
75394- !capable(CAP_SYS_NICE)) {
75395+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
75396 rcu_read_unlock();
75397 err = -EPERM;
75398 goto out;
75399diff --git a/mm/mlock.c b/mm/mlock.c
75400index f0b9ce5..da8d069 100644
75401--- a/mm/mlock.c
75402+++ b/mm/mlock.c
75403@@ -13,6 +13,7 @@
75404 #include <linux/pagemap.h>
75405 #include <linux/mempolicy.h>
75406 #include <linux/syscalls.h>
75407+#include <linux/security.h>
75408 #include <linux/sched.h>
75409 #include <linux/export.h>
75410 #include <linux/rmap.h>
75411@@ -369,7 +370,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
75412 {
75413 unsigned long nstart, end, tmp;
75414 struct vm_area_struct * vma, * prev;
75415- int error;
75416+ int error = 0;
75417
75418 VM_BUG_ON(start & ~PAGE_MASK);
75419 VM_BUG_ON(len != PAGE_ALIGN(len));
75420@@ -378,6 +379,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
75421 return -EINVAL;
75422 if (end == start)
75423 return 0;
75424+ if (end > TASK_SIZE)
75425+ return -EINVAL;
75426+
75427 vma = find_vma(current->mm, start);
75428 if (!vma || vma->vm_start > start)
75429 return -ENOMEM;
75430@@ -389,6 +393,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
75431 for (nstart = start ; ; ) {
75432 vm_flags_t newflags;
75433
75434+#ifdef CONFIG_PAX_SEGMEXEC
75435+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
75436+ break;
75437+#endif
75438+
75439 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
75440
75441 newflags = vma->vm_flags | VM_LOCKED;
75442@@ -494,6 +503,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
75443 lock_limit >>= PAGE_SHIFT;
75444
75445 /* check against resource limits */
75446+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
75447 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
75448 error = do_mlock(start, len, 1);
75449 up_write(&current->mm->mmap_sem);
75450@@ -517,17 +527,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
75451 static int do_mlockall(int flags)
75452 {
75453 struct vm_area_struct * vma, * prev = NULL;
75454- unsigned int def_flags = 0;
75455
75456 if (flags & MCL_FUTURE)
75457- def_flags = VM_LOCKED;
75458- current->mm->def_flags = def_flags;
75459+ current->mm->def_flags |= VM_LOCKED;
75460+ else
75461+ current->mm->def_flags &= ~VM_LOCKED;
75462 if (flags == MCL_FUTURE)
75463 goto out;
75464
75465 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
75466 vm_flags_t newflags;
75467
75468+#ifdef CONFIG_PAX_SEGMEXEC
75469+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
75470+ break;
75471+#endif
75472+
75473+ BUG_ON(vma->vm_end > TASK_SIZE);
75474 newflags = vma->vm_flags | VM_LOCKED;
75475 if (!(flags & MCL_CURRENT))
75476 newflags &= ~VM_LOCKED;
75477@@ -560,6 +576,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
75478 lock_limit >>= PAGE_SHIFT;
75479
75480 ret = -ENOMEM;
75481+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
75482 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
75483 capable(CAP_IPC_LOCK))
75484 ret = do_mlockall(flags);
75485diff --git a/mm/mmap.c b/mm/mmap.c
75486index 9a796c4..4fba820 100644
75487--- a/mm/mmap.c
75488+++ b/mm/mmap.c
75489@@ -47,6 +47,16 @@
75490 #define arch_rebalance_pgtables(addr, len) (addr)
75491 #endif
75492
75493+static inline void verify_mm_writelocked(struct mm_struct *mm)
75494+{
75495+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
75496+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
75497+ up_read(&mm->mmap_sem);
75498+ BUG();
75499+ }
75500+#endif
75501+}
75502+
75503 static void unmap_region(struct mm_struct *mm,
75504 struct vm_area_struct *vma, struct vm_area_struct *prev,
75505 unsigned long start, unsigned long end);
75506@@ -66,22 +76,32 @@ static void unmap_region(struct mm_struct *mm,
75507 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
75508 *
75509 */
75510-pgprot_t protection_map[16] = {
75511+pgprot_t protection_map[16] __read_only = {
75512 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
75513 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
75514 };
75515
75516-pgprot_t vm_get_page_prot(unsigned long vm_flags)
75517+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
75518 {
75519- return __pgprot(pgprot_val(protection_map[vm_flags &
75520+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
75521 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
75522 pgprot_val(arch_vm_get_page_prot(vm_flags)));
75523+
75524+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
75525+ if (!(__supported_pte_mask & _PAGE_NX) &&
75526+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
75527+ (vm_flags & (VM_READ | VM_WRITE)))
75528+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
75529+#endif
75530+
75531+ return prot;
75532 }
75533 EXPORT_SYMBOL(vm_get_page_prot);
75534
75535 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
75536 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
75537 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
75538+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
75539 /*
75540 * Make sure vm_committed_as in one cacheline and not cacheline shared with
75541 * other variables. It can be updated by several CPUs frequently.
75542@@ -223,6 +243,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
75543 struct vm_area_struct *next = vma->vm_next;
75544
75545 might_sleep();
75546+ BUG_ON(vma->vm_mirror);
75547 if (vma->vm_ops && vma->vm_ops->close)
75548 vma->vm_ops->close(vma);
75549 if (vma->vm_file)
75550@@ -266,6 +287,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
75551 * not page aligned -Ram Gupta
75552 */
75553 rlim = rlimit(RLIMIT_DATA);
75554+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
75555 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
75556 (mm->end_data - mm->start_data) > rlim)
75557 goto out;
75558@@ -736,6 +758,12 @@ static int
75559 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
75560 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
75561 {
75562+
75563+#ifdef CONFIG_PAX_SEGMEXEC
75564+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
75565+ return 0;
75566+#endif
75567+
75568 if (is_mergeable_vma(vma, file, vm_flags) &&
75569 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
75570 if (vma->vm_pgoff == vm_pgoff)
75571@@ -755,6 +783,12 @@ static int
75572 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
75573 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
75574 {
75575+
75576+#ifdef CONFIG_PAX_SEGMEXEC
75577+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
75578+ return 0;
75579+#endif
75580+
75581 if (is_mergeable_vma(vma, file, vm_flags) &&
75582 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
75583 pgoff_t vm_pglen;
75584@@ -797,13 +831,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
75585 struct vm_area_struct *vma_merge(struct mm_struct *mm,
75586 struct vm_area_struct *prev, unsigned long addr,
75587 unsigned long end, unsigned long vm_flags,
75588- struct anon_vma *anon_vma, struct file *file,
75589+ struct anon_vma *anon_vma, struct file *file,
75590 pgoff_t pgoff, struct mempolicy *policy)
75591 {
75592 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
75593 struct vm_area_struct *area, *next;
75594 int err;
75595
75596+#ifdef CONFIG_PAX_SEGMEXEC
75597+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
75598+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
75599+
75600+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
75601+#endif
75602+
75603 /*
75604 * We later require that vma->vm_flags == vm_flags,
75605 * so this tests vma->vm_flags & VM_SPECIAL, too.
75606@@ -819,6 +860,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
75607 if (next && next->vm_end == end) /* cases 6, 7, 8 */
75608 next = next->vm_next;
75609
75610+#ifdef CONFIG_PAX_SEGMEXEC
75611+ if (prev)
75612+ prev_m = pax_find_mirror_vma(prev);
75613+ if (area)
75614+ area_m = pax_find_mirror_vma(area);
75615+ if (next)
75616+ next_m = pax_find_mirror_vma(next);
75617+#endif
75618+
75619 /*
75620 * Can it merge with the predecessor?
75621 */
75622@@ -838,9 +888,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
75623 /* cases 1, 6 */
75624 err = vma_adjust(prev, prev->vm_start,
75625 next->vm_end, prev->vm_pgoff, NULL);
75626- } else /* cases 2, 5, 7 */
75627+
75628+#ifdef CONFIG_PAX_SEGMEXEC
75629+ if (!err && prev_m)
75630+ err = vma_adjust(prev_m, prev_m->vm_start,
75631+ next_m->vm_end, prev_m->vm_pgoff, NULL);
75632+#endif
75633+
75634+ } else { /* cases 2, 5, 7 */
75635 err = vma_adjust(prev, prev->vm_start,
75636 end, prev->vm_pgoff, NULL);
75637+
75638+#ifdef CONFIG_PAX_SEGMEXEC
75639+ if (!err && prev_m)
75640+ err = vma_adjust(prev_m, prev_m->vm_start,
75641+ end_m, prev_m->vm_pgoff, NULL);
75642+#endif
75643+
75644+ }
75645 if (err)
75646 return NULL;
75647 khugepaged_enter_vma_merge(prev);
75648@@ -854,12 +919,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
75649 mpol_equal(policy, vma_policy(next)) &&
75650 can_vma_merge_before(next, vm_flags,
75651 anon_vma, file, pgoff+pglen)) {
75652- if (prev && addr < prev->vm_end) /* case 4 */
75653+ if (prev && addr < prev->vm_end) { /* case 4 */
75654 err = vma_adjust(prev, prev->vm_start,
75655 addr, prev->vm_pgoff, NULL);
75656- else /* cases 3, 8 */
75657+
75658+#ifdef CONFIG_PAX_SEGMEXEC
75659+ if (!err && prev_m)
75660+ err = vma_adjust(prev_m, prev_m->vm_start,
75661+ addr_m, prev_m->vm_pgoff, NULL);
75662+#endif
75663+
75664+ } else { /* cases 3, 8 */
75665 err = vma_adjust(area, addr, next->vm_end,
75666 next->vm_pgoff - pglen, NULL);
75667+
75668+#ifdef CONFIG_PAX_SEGMEXEC
75669+ if (!err && area_m)
75670+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
75671+ next_m->vm_pgoff - pglen, NULL);
75672+#endif
75673+
75674+ }
75675 if (err)
75676 return NULL;
75677 khugepaged_enter_vma_merge(area);
75678@@ -968,16 +1048,13 @@ none:
75679 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
75680 struct file *file, long pages)
75681 {
75682- const unsigned long stack_flags
75683- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
75684-
75685 mm->total_vm += pages;
75686
75687 if (file) {
75688 mm->shared_vm += pages;
75689 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
75690 mm->exec_vm += pages;
75691- } else if (flags & stack_flags)
75692+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
75693 mm->stack_vm += pages;
75694 }
75695 #endif /* CONFIG_PROC_FS */
75696@@ -1013,7 +1090,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
75697 * (the exception is when the underlying filesystem is noexec
75698 * mounted, in which case we dont add PROT_EXEC.)
75699 */
75700- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
75701+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
75702 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
75703 prot |= PROT_EXEC;
75704
75705@@ -1039,7 +1116,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
75706 /* Obtain the address to map to. we verify (or select) it and ensure
75707 * that it represents a valid section of the address space.
75708 */
75709- addr = get_unmapped_area(file, addr, len, pgoff, flags);
75710+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
75711 if (addr & ~PAGE_MASK)
75712 return addr;
75713
75714@@ -1050,6 +1127,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
75715 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
75716 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
75717
75718+#ifdef CONFIG_PAX_MPROTECT
75719+ if (mm->pax_flags & MF_PAX_MPROTECT) {
75720+#ifndef CONFIG_PAX_MPROTECT_COMPAT
75721+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
75722+ gr_log_rwxmmap(file);
75723+
75724+#ifdef CONFIG_PAX_EMUPLT
75725+ vm_flags &= ~VM_EXEC;
75726+#else
75727+ return -EPERM;
75728+#endif
75729+
75730+ }
75731+
75732+ if (!(vm_flags & VM_EXEC))
75733+ vm_flags &= ~VM_MAYEXEC;
75734+#else
75735+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
75736+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
75737+#endif
75738+ else
75739+ vm_flags &= ~VM_MAYWRITE;
75740+ }
75741+#endif
75742+
75743+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
75744+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
75745+ vm_flags &= ~VM_PAGEEXEC;
75746+#endif
75747+
75748 if (flags & MAP_LOCKED)
75749 if (!can_do_mlock())
75750 return -EPERM;
75751@@ -1061,6 +1168,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
75752 locked += mm->locked_vm;
75753 lock_limit = rlimit(RLIMIT_MEMLOCK);
75754 lock_limit >>= PAGE_SHIFT;
75755+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
75756 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
75757 return -EAGAIN;
75758 }
75759@@ -1127,6 +1235,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
75760 }
75761 }
75762
75763+ if (!gr_acl_handle_mmap(file, prot))
75764+ return -EACCES;
75765+
75766 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
75767 }
75768
75769@@ -1203,7 +1314,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
75770 vm_flags_t vm_flags = vma->vm_flags;
75771
75772 /* If it was private or non-writable, the write bit is already clear */
75773- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
75774+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
75775 return 0;
75776
75777 /* The backer wishes to know when pages are first written to? */
75778@@ -1252,13 +1363,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
75779 unsigned long charged = 0;
75780 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
75781
75782+#ifdef CONFIG_PAX_SEGMEXEC
75783+ struct vm_area_struct *vma_m = NULL;
75784+#endif
75785+
75786+ /*
75787+ * mm->mmap_sem is required to protect against another thread
75788+ * changing the mappings in case we sleep.
75789+ */
75790+ verify_mm_writelocked(mm);
75791+
75792 /* Clear old maps */
75793 error = -ENOMEM;
75794-munmap_back:
75795 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
75796 if (do_munmap(mm, addr, len))
75797 return -ENOMEM;
75798- goto munmap_back;
75799+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
75800 }
75801
75802 /* Check against address space limit. */
75803@@ -1307,6 +1427,16 @@ munmap_back:
75804 goto unacct_error;
75805 }
75806
75807+#ifdef CONFIG_PAX_SEGMEXEC
75808+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
75809+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
75810+ if (!vma_m) {
75811+ error = -ENOMEM;
75812+ goto free_vma;
75813+ }
75814+ }
75815+#endif
75816+
75817 vma->vm_mm = mm;
75818 vma->vm_start = addr;
75819 vma->vm_end = addr + len;
75820@@ -1331,6 +1461,13 @@ munmap_back:
75821 if (error)
75822 goto unmap_and_free_vma;
75823
75824+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
75825+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
75826+ vma->vm_flags |= VM_PAGEEXEC;
75827+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
75828+ }
75829+#endif
75830+
75831 /* Can addr have changed??
75832 *
75833 * Answer: Yes, several device drivers can do it in their
75834@@ -1365,6 +1502,11 @@ munmap_back:
75835 vma_link(mm, vma, prev, rb_link, rb_parent);
75836 file = vma->vm_file;
75837
75838+#ifdef CONFIG_PAX_SEGMEXEC
75839+ if (vma_m)
75840+ BUG_ON(pax_mirror_vma(vma_m, vma));
75841+#endif
75842+
75843 /* Once vma denies write, undo our temporary denial count */
75844 if (correct_wcount)
75845 atomic_inc(&inode->i_writecount);
75846@@ -1372,6 +1514,7 @@ out:
75847 perf_event_mmap(vma);
75848
75849 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
75850+ track_exec_limit(mm, addr, addr + len, vm_flags);
75851 if (vm_flags & VM_LOCKED) {
75852 if (!mlock_vma_pages_range(vma, addr, addr + len))
75853 mm->locked_vm += (len >> PAGE_SHIFT);
75854@@ -1393,6 +1536,12 @@ unmap_and_free_vma:
75855 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
75856 charged = 0;
75857 free_vma:
75858+
75859+#ifdef CONFIG_PAX_SEGMEXEC
75860+ if (vma_m)
75861+ kmem_cache_free(vm_area_cachep, vma_m);
75862+#endif
75863+
75864 kmem_cache_free(vm_area_cachep, vma);
75865 unacct_error:
75866 if (charged)
75867@@ -1400,6 +1549,44 @@ unacct_error:
75868 return error;
75869 }
75870
75871+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
75872+{
75873+ if (!vma) {
75874+#ifdef CONFIG_STACK_GROWSUP
75875+ if (addr > sysctl_heap_stack_gap)
75876+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
75877+ else
75878+ vma = find_vma(current->mm, 0);
75879+ if (vma && (vma->vm_flags & VM_GROWSUP))
75880+ return false;
75881+#endif
75882+ return true;
75883+ }
75884+
75885+ if (addr + len > vma->vm_start)
75886+ return false;
75887+
75888+ if (vma->vm_flags & VM_GROWSDOWN)
75889+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
75890+#ifdef CONFIG_STACK_GROWSUP
75891+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
75892+ return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
75893+#endif
75894+
75895+ return true;
75896+}
75897+
75898+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
75899+{
75900+ if (vma->vm_start < len)
75901+ return -ENOMEM;
75902+ if (!(vma->vm_flags & VM_GROWSDOWN))
75903+ return vma->vm_start - len;
75904+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
75905+ return vma->vm_start - len - sysctl_heap_stack_gap;
75906+ return -ENOMEM;
75907+}
75908+
75909 /* Get an address range which is currently unmapped.
75910 * For shmat() with addr=0.
75911 *
75912@@ -1426,18 +1613,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
75913 if (flags & MAP_FIXED)
75914 return addr;
75915
75916+#ifdef CONFIG_PAX_RANDMMAP
75917+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
75918+#endif
75919+
75920 if (addr) {
75921 addr = PAGE_ALIGN(addr);
75922- vma = find_vma(mm, addr);
75923- if (TASK_SIZE - len >= addr &&
75924- (!vma || addr + len <= vma->vm_start))
75925- return addr;
75926+ if (TASK_SIZE - len >= addr) {
75927+ vma = find_vma(mm, addr);
75928+ if (check_heap_stack_gap(vma, addr, len))
75929+ return addr;
75930+ }
75931 }
75932 if (len > mm->cached_hole_size) {
75933- start_addr = addr = mm->free_area_cache;
75934+ start_addr = addr = mm->free_area_cache;
75935 } else {
75936- start_addr = addr = TASK_UNMAPPED_BASE;
75937- mm->cached_hole_size = 0;
75938+ start_addr = addr = mm->mmap_base;
75939+ mm->cached_hole_size = 0;
75940 }
75941
75942 full_search:
75943@@ -1448,34 +1640,40 @@ full_search:
75944 * Start a new search - just in case we missed
75945 * some holes.
75946 */
75947- if (start_addr != TASK_UNMAPPED_BASE) {
75948- addr = TASK_UNMAPPED_BASE;
75949- start_addr = addr;
75950+ if (start_addr != mm->mmap_base) {
75951+ start_addr = addr = mm->mmap_base;
75952 mm->cached_hole_size = 0;
75953 goto full_search;
75954 }
75955 return -ENOMEM;
75956 }
75957- if (!vma || addr + len <= vma->vm_start) {
75958- /*
75959- * Remember the place where we stopped the search:
75960- */
75961- mm->free_area_cache = addr + len;
75962- return addr;
75963- }
75964+ if (check_heap_stack_gap(vma, addr, len))
75965+ break;
75966 if (addr + mm->cached_hole_size < vma->vm_start)
75967 mm->cached_hole_size = vma->vm_start - addr;
75968 addr = vma->vm_end;
75969 }
75970+
75971+ /*
75972+ * Remember the place where we stopped the search:
75973+ */
75974+ mm->free_area_cache = addr + len;
75975+ return addr;
75976 }
75977 #endif
75978
75979 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
75980 {
75981+
75982+#ifdef CONFIG_PAX_SEGMEXEC
75983+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
75984+ return;
75985+#endif
75986+
75987 /*
75988 * Is this a new hole at the lowest possible address?
75989 */
75990- if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
75991+ if (addr >= mm->mmap_base && addr < mm->free_area_cache)
75992 mm->free_area_cache = addr;
75993 }
75994
75995@@ -1491,7 +1689,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
75996 {
75997 struct vm_area_struct *vma;
75998 struct mm_struct *mm = current->mm;
75999- unsigned long addr = addr0, start_addr;
76000+ unsigned long base = mm->mmap_base, addr = addr0, start_addr;
76001
76002 /* requested length too big for entire address space */
76003 if (len > TASK_SIZE)
76004@@ -1500,13 +1698,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
76005 if (flags & MAP_FIXED)
76006 return addr;
76007
76008+#ifdef CONFIG_PAX_RANDMMAP
76009+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
76010+#endif
76011+
76012 /* requesting a specific address */
76013 if (addr) {
76014 addr = PAGE_ALIGN(addr);
76015- vma = find_vma(mm, addr);
76016- if (TASK_SIZE - len >= addr &&
76017- (!vma || addr + len <= vma->vm_start))
76018- return addr;
76019+ if (TASK_SIZE - len >= addr) {
76020+ vma = find_vma(mm, addr);
76021+ if (check_heap_stack_gap(vma, addr, len))
76022+ return addr;
76023+ }
76024 }
76025
76026 /* check if free_area_cache is useful for us */
76027@@ -1530,7 +1733,7 @@ try_again:
76028 * return with success:
76029 */
76030 vma = find_vma(mm, addr);
76031- if (!vma || addr+len <= vma->vm_start)
76032+ if (check_heap_stack_gap(vma, addr, len))
76033 /* remember the address as a hint for next time */
76034 return (mm->free_area_cache = addr);
76035
76036@@ -1539,8 +1742,8 @@ try_again:
76037 mm->cached_hole_size = vma->vm_start - addr;
76038
76039 /* try just below the current vma->vm_start */
76040- addr = vma->vm_start-len;
76041- } while (len < vma->vm_start);
76042+ addr = skip_heap_stack_gap(vma, len);
76043+ } while (!IS_ERR_VALUE(addr));
76044
76045 fail:
76046 /*
76047@@ -1563,13 +1766,21 @@ fail:
76048 * can happen with large stack limits and large mmap()
76049 * allocations.
76050 */
76051+ mm->mmap_base = TASK_UNMAPPED_BASE;
76052+
76053+#ifdef CONFIG_PAX_RANDMMAP
76054+ if (mm->pax_flags & MF_PAX_RANDMMAP)
76055+ mm->mmap_base += mm->delta_mmap;
76056+#endif
76057+
76058+ mm->free_area_cache = mm->mmap_base;
76059 mm->cached_hole_size = ~0UL;
76060- mm->free_area_cache = TASK_UNMAPPED_BASE;
76061 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
76062 /*
76063 * Restore the topdown base:
76064 */
76065- mm->free_area_cache = mm->mmap_base;
76066+ mm->mmap_base = base;
76067+ mm->free_area_cache = base;
76068 mm->cached_hole_size = ~0UL;
76069
76070 return addr;
76071@@ -1578,6 +1789,12 @@ fail:
76072
76073 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
76074 {
76075+
76076+#ifdef CONFIG_PAX_SEGMEXEC
76077+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
76078+ return;
76079+#endif
76080+
76081 /*
76082 * Is this a new hole at the highest possible address?
76083 */
76084@@ -1585,8 +1802,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
76085 mm->free_area_cache = addr;
76086
76087 /* dont allow allocations above current base */
76088- if (mm->free_area_cache > mm->mmap_base)
76089+ if (mm->free_area_cache > mm->mmap_base) {
76090 mm->free_area_cache = mm->mmap_base;
76091+ mm->cached_hole_size = ~0UL;
76092+ }
76093 }
76094
76095 unsigned long
76096@@ -1685,6 +1904,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
76097 return vma;
76098 }
76099
76100+#ifdef CONFIG_PAX_SEGMEXEC
76101+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
76102+{
76103+ struct vm_area_struct *vma_m;
76104+
76105+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
76106+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
76107+ BUG_ON(vma->vm_mirror);
76108+ return NULL;
76109+ }
76110+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
76111+ vma_m = vma->vm_mirror;
76112+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
76113+ BUG_ON(vma->vm_file != vma_m->vm_file);
76114+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
76115+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
76116+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
76117+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
76118+ return vma_m;
76119+}
76120+#endif
76121+
76122 /*
76123 * Verify that the stack growth is acceptable and
76124 * update accounting. This is shared with both the
76125@@ -1701,6 +1942,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
76126 return -ENOMEM;
76127
76128 /* Stack limit test */
76129+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
76130 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
76131 return -ENOMEM;
76132
76133@@ -1711,6 +1953,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
76134 locked = mm->locked_vm + grow;
76135 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
76136 limit >>= PAGE_SHIFT;
76137+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
76138 if (locked > limit && !capable(CAP_IPC_LOCK))
76139 return -ENOMEM;
76140 }
76141@@ -1740,37 +1983,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
76142 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
76143 * vma is the last one with address > vma->vm_end. Have to extend vma.
76144 */
76145+#ifndef CONFIG_IA64
76146+static
76147+#endif
76148 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
76149 {
76150 int error;
76151+ bool locknext;
76152
76153 if (!(vma->vm_flags & VM_GROWSUP))
76154 return -EFAULT;
76155
76156+ /* Also guard against wrapping around to address 0. */
76157+ if (address < PAGE_ALIGN(address+1))
76158+ address = PAGE_ALIGN(address+1);
76159+ else
76160+ return -ENOMEM;
76161+
76162 /*
76163 * We must make sure the anon_vma is allocated
76164 * so that the anon_vma locking is not a noop.
76165 */
76166 if (unlikely(anon_vma_prepare(vma)))
76167 return -ENOMEM;
76168+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
76169+ if (locknext && anon_vma_prepare(vma->vm_next))
76170+ return -ENOMEM;
76171 vma_lock_anon_vma(vma);
76172+ if (locknext)
76173+ vma_lock_anon_vma(vma->vm_next);
76174
76175 /*
76176 * vma->vm_start/vm_end cannot change under us because the caller
76177 * is required to hold the mmap_sem in read mode. We need the
76178- * anon_vma lock to serialize against concurrent expand_stacks.
76179- * Also guard against wrapping around to address 0.
76180+ * anon_vma locks to serialize against concurrent expand_stacks
76181+ * and expand_upwards.
76182 */
76183- if (address < PAGE_ALIGN(address+4))
76184- address = PAGE_ALIGN(address+4);
76185- else {
76186- vma_unlock_anon_vma(vma);
76187- return -ENOMEM;
76188- }
76189 error = 0;
76190
76191 /* Somebody else might have raced and expanded it already */
76192- if (address > vma->vm_end) {
76193+ 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)
76194+ error = -ENOMEM;
76195+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
76196 unsigned long size, grow;
76197
76198 size = address - vma->vm_start;
76199@@ -1787,6 +2041,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
76200 }
76201 }
76202 }
76203+ if (locknext)
76204+ vma_unlock_anon_vma(vma->vm_next);
76205 vma_unlock_anon_vma(vma);
76206 khugepaged_enter_vma_merge(vma);
76207 validate_mm(vma->vm_mm);
76208@@ -1801,6 +2057,8 @@ int expand_downwards(struct vm_area_struct *vma,
76209 unsigned long address)
76210 {
76211 int error;
76212+ bool lockprev = false;
76213+ struct vm_area_struct *prev;
76214
76215 /*
76216 * We must make sure the anon_vma is allocated
76217@@ -1814,6 +2072,15 @@ int expand_downwards(struct vm_area_struct *vma,
76218 if (error)
76219 return error;
76220
76221+ prev = vma->vm_prev;
76222+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
76223+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
76224+#endif
76225+ if (lockprev && anon_vma_prepare(prev))
76226+ return -ENOMEM;
76227+ if (lockprev)
76228+ vma_lock_anon_vma(prev);
76229+
76230 vma_lock_anon_vma(vma);
76231
76232 /*
76233@@ -1823,9 +2090,17 @@ int expand_downwards(struct vm_area_struct *vma,
76234 */
76235
76236 /* Somebody else might have raced and expanded it already */
76237- if (address < vma->vm_start) {
76238+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
76239+ error = -ENOMEM;
76240+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
76241 unsigned long size, grow;
76242
76243+#ifdef CONFIG_PAX_SEGMEXEC
76244+ struct vm_area_struct *vma_m;
76245+
76246+ vma_m = pax_find_mirror_vma(vma);
76247+#endif
76248+
76249 size = vma->vm_end - address;
76250 grow = (vma->vm_start - address) >> PAGE_SHIFT;
76251
76252@@ -1837,6 +2112,17 @@ int expand_downwards(struct vm_area_struct *vma,
76253 vma->vm_start = address;
76254 vma->vm_pgoff -= grow;
76255 anon_vma_interval_tree_post_update_vma(vma);
76256+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
76257+
76258+#ifdef CONFIG_PAX_SEGMEXEC
76259+ if (vma_m) {
76260+ anon_vma_interval_tree_pre_update_vma(vma_m);
76261+ vma_m->vm_start -= grow << PAGE_SHIFT;
76262+ vma_m->vm_pgoff -= grow;
76263+ anon_vma_interval_tree_post_update_vma(vma_m);
76264+ }
76265+#endif
76266+
76267 perf_event_mmap(vma);
76268 }
76269 }
76270@@ -1914,6 +2200,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
76271 do {
76272 long nrpages = vma_pages(vma);
76273
76274+#ifdef CONFIG_PAX_SEGMEXEC
76275+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
76276+ vma = remove_vma(vma);
76277+ continue;
76278+ }
76279+#endif
76280+
76281 if (vma->vm_flags & VM_ACCOUNT)
76282 nr_accounted += nrpages;
76283 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
76284@@ -1959,6 +2252,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
76285 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
76286 vma->vm_prev = NULL;
76287 do {
76288+
76289+#ifdef CONFIG_PAX_SEGMEXEC
76290+ if (vma->vm_mirror) {
76291+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
76292+ vma->vm_mirror->vm_mirror = NULL;
76293+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
76294+ vma->vm_mirror = NULL;
76295+ }
76296+#endif
76297+
76298 rb_erase(&vma->vm_rb, &mm->mm_rb);
76299 mm->map_count--;
76300 tail_vma = vma;
76301@@ -1987,14 +2290,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
76302 struct vm_area_struct *new;
76303 int err = -ENOMEM;
76304
76305+#ifdef CONFIG_PAX_SEGMEXEC
76306+ struct vm_area_struct *vma_m, *new_m = NULL;
76307+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
76308+#endif
76309+
76310 if (is_vm_hugetlb_page(vma) && (addr &
76311 ~(huge_page_mask(hstate_vma(vma)))))
76312 return -EINVAL;
76313
76314+#ifdef CONFIG_PAX_SEGMEXEC
76315+ vma_m = pax_find_mirror_vma(vma);
76316+#endif
76317+
76318 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
76319 if (!new)
76320 goto out_err;
76321
76322+#ifdef CONFIG_PAX_SEGMEXEC
76323+ if (vma_m) {
76324+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
76325+ if (!new_m) {
76326+ kmem_cache_free(vm_area_cachep, new);
76327+ goto out_err;
76328+ }
76329+ }
76330+#endif
76331+
76332 /* most fields are the same, copy all, and then fixup */
76333 *new = *vma;
76334
76335@@ -2007,6 +2329,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
76336 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
76337 }
76338
76339+#ifdef CONFIG_PAX_SEGMEXEC
76340+ if (vma_m) {
76341+ *new_m = *vma_m;
76342+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
76343+ new_m->vm_mirror = new;
76344+ new->vm_mirror = new_m;
76345+
76346+ if (new_below)
76347+ new_m->vm_end = addr_m;
76348+ else {
76349+ new_m->vm_start = addr_m;
76350+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
76351+ }
76352+ }
76353+#endif
76354+
76355 pol = mpol_dup(vma_policy(vma));
76356 if (IS_ERR(pol)) {
76357 err = PTR_ERR(pol);
76358@@ -2029,6 +2367,36 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
76359 else
76360 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
76361
76362+#ifdef CONFIG_PAX_SEGMEXEC
76363+ if (!err && vma_m) {
76364+ if (anon_vma_clone(new_m, vma_m))
76365+ goto out_free_mpol;
76366+
76367+ mpol_get(pol);
76368+ vma_set_policy(new_m, pol);
76369+
76370+ if (new_m->vm_file)
76371+ get_file(new_m->vm_file);
76372+
76373+ if (new_m->vm_ops && new_m->vm_ops->open)
76374+ new_m->vm_ops->open(new_m);
76375+
76376+ if (new_below)
76377+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
76378+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
76379+ else
76380+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
76381+
76382+ if (err) {
76383+ if (new_m->vm_ops && new_m->vm_ops->close)
76384+ new_m->vm_ops->close(new_m);
76385+ if (new_m->vm_file)
76386+ fput(new_m->vm_file);
76387+ mpol_put(pol);
76388+ }
76389+ }
76390+#endif
76391+
76392 /* Success. */
76393 if (!err)
76394 return 0;
76395@@ -2038,10 +2406,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
76396 new->vm_ops->close(new);
76397 if (new->vm_file)
76398 fput(new->vm_file);
76399- unlink_anon_vmas(new);
76400 out_free_mpol:
76401 mpol_put(pol);
76402 out_free_vma:
76403+
76404+#ifdef CONFIG_PAX_SEGMEXEC
76405+ if (new_m) {
76406+ unlink_anon_vmas(new_m);
76407+ kmem_cache_free(vm_area_cachep, new_m);
76408+ }
76409+#endif
76410+
76411+ unlink_anon_vmas(new);
76412 kmem_cache_free(vm_area_cachep, new);
76413 out_err:
76414 return err;
76415@@ -2054,6 +2430,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
76416 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
76417 unsigned long addr, int new_below)
76418 {
76419+
76420+#ifdef CONFIG_PAX_SEGMEXEC
76421+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
76422+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
76423+ if (mm->map_count >= sysctl_max_map_count-1)
76424+ return -ENOMEM;
76425+ } else
76426+#endif
76427+
76428 if (mm->map_count >= sysctl_max_map_count)
76429 return -ENOMEM;
76430
76431@@ -2065,11 +2450,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
76432 * work. This now handles partial unmappings.
76433 * Jeremy Fitzhardinge <jeremy@goop.org>
76434 */
76435+#ifdef CONFIG_PAX_SEGMEXEC
76436 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
76437 {
76438+ int ret = __do_munmap(mm, start, len);
76439+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
76440+ return ret;
76441+
76442+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
76443+}
76444+
76445+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
76446+#else
76447+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
76448+#endif
76449+{
76450 unsigned long end;
76451 struct vm_area_struct *vma, *prev, *last;
76452
76453+ /*
76454+ * mm->mmap_sem is required to protect against another thread
76455+ * changing the mappings in case we sleep.
76456+ */
76457+ verify_mm_writelocked(mm);
76458+
76459 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
76460 return -EINVAL;
76461
76462@@ -2144,6 +2548,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
76463 /* Fix up all other VM information */
76464 remove_vma_list(mm, vma);
76465
76466+ track_exec_limit(mm, start, end, 0UL);
76467+
76468 return 0;
76469 }
76470
76471@@ -2152,6 +2558,13 @@ int vm_munmap(unsigned long start, size_t len)
76472 int ret;
76473 struct mm_struct *mm = current->mm;
76474
76475+
76476+#ifdef CONFIG_PAX_SEGMEXEC
76477+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
76478+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
76479+ return -EINVAL;
76480+#endif
76481+
76482 down_write(&mm->mmap_sem);
76483 ret = do_munmap(mm, start, len);
76484 up_write(&mm->mmap_sem);
76485@@ -2165,16 +2578,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
76486 return vm_munmap(addr, len);
76487 }
76488
76489-static inline void verify_mm_writelocked(struct mm_struct *mm)
76490-{
76491-#ifdef CONFIG_DEBUG_VM
76492- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
76493- WARN_ON(1);
76494- up_read(&mm->mmap_sem);
76495- }
76496-#endif
76497-}
76498-
76499 /*
76500 * this is really a simplified "do_mmap". it only handles
76501 * anonymous maps. eventually we may be able to do some
76502@@ -2188,6 +2591,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
76503 struct rb_node ** rb_link, * rb_parent;
76504 pgoff_t pgoff = addr >> PAGE_SHIFT;
76505 int error;
76506+ unsigned long charged;
76507
76508 len = PAGE_ALIGN(len);
76509 if (!len)
76510@@ -2195,16 +2599,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
76511
76512 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
76513
76514+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
76515+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
76516+ flags &= ~VM_EXEC;
76517+
76518+#ifdef CONFIG_PAX_MPROTECT
76519+ if (mm->pax_flags & MF_PAX_MPROTECT)
76520+ flags &= ~VM_MAYEXEC;
76521+#endif
76522+
76523+ }
76524+#endif
76525+
76526 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
76527 if (error & ~PAGE_MASK)
76528 return error;
76529
76530+ charged = len >> PAGE_SHIFT;
76531+
76532 /*
76533 * mlock MCL_FUTURE?
76534 */
76535 if (mm->def_flags & VM_LOCKED) {
76536 unsigned long locked, lock_limit;
76537- locked = len >> PAGE_SHIFT;
76538+ locked = charged;
76539 locked += mm->locked_vm;
76540 lock_limit = rlimit(RLIMIT_MEMLOCK);
76541 lock_limit >>= PAGE_SHIFT;
76542@@ -2221,21 +2639,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
76543 /*
76544 * Clear old maps. this also does some error checking for us
76545 */
76546- munmap_back:
76547 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
76548 if (do_munmap(mm, addr, len))
76549 return -ENOMEM;
76550- goto munmap_back;
76551+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
76552 }
76553
76554 /* Check against address space limits *after* clearing old maps... */
76555- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
76556+ if (!may_expand_vm(mm, charged))
76557 return -ENOMEM;
76558
76559 if (mm->map_count > sysctl_max_map_count)
76560 return -ENOMEM;
76561
76562- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
76563+ if (security_vm_enough_memory_mm(mm, charged))
76564 return -ENOMEM;
76565
76566 /* Can we just expand an old private anonymous mapping? */
76567@@ -2249,7 +2666,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
76568 */
76569 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
76570 if (!vma) {
76571- vm_unacct_memory(len >> PAGE_SHIFT);
76572+ vm_unacct_memory(charged);
76573 return -ENOMEM;
76574 }
76575
76576@@ -2263,11 +2680,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
76577 vma_link(mm, vma, prev, rb_link, rb_parent);
76578 out:
76579 perf_event_mmap(vma);
76580- mm->total_vm += len >> PAGE_SHIFT;
76581+ mm->total_vm += charged;
76582 if (flags & VM_LOCKED) {
76583 if (!mlock_vma_pages_range(vma, addr, addr + len))
76584- mm->locked_vm += (len >> PAGE_SHIFT);
76585+ mm->locked_vm += charged;
76586 }
76587+ track_exec_limit(mm, addr, addr + len, flags);
76588 return addr;
76589 }
76590
76591@@ -2325,6 +2743,7 @@ void exit_mmap(struct mm_struct *mm)
76592 while (vma) {
76593 if (vma->vm_flags & VM_ACCOUNT)
76594 nr_accounted += vma_pages(vma);
76595+ vma->vm_mirror = NULL;
76596 vma = remove_vma(vma);
76597 }
76598 vm_unacct_memory(nr_accounted);
76599@@ -2341,6 +2760,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
76600 struct vm_area_struct *prev;
76601 struct rb_node **rb_link, *rb_parent;
76602
76603+#ifdef CONFIG_PAX_SEGMEXEC
76604+ struct vm_area_struct *vma_m = NULL;
76605+#endif
76606+
76607+ if (security_mmap_addr(vma->vm_start))
76608+ return -EPERM;
76609+
76610 /*
76611 * The vm_pgoff of a purely anonymous vma should be irrelevant
76612 * until its first write fault, when page's anon_vma and index
76613@@ -2364,7 +2790,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
76614 security_vm_enough_memory_mm(mm, vma_pages(vma)))
76615 return -ENOMEM;
76616
76617+#ifdef CONFIG_PAX_SEGMEXEC
76618+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
76619+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
76620+ if (!vma_m)
76621+ return -ENOMEM;
76622+ }
76623+#endif
76624+
76625 vma_link(mm, vma, prev, rb_link, rb_parent);
76626+
76627+#ifdef CONFIG_PAX_SEGMEXEC
76628+ if (vma_m)
76629+ BUG_ON(pax_mirror_vma(vma_m, vma));
76630+#endif
76631+
76632 return 0;
76633 }
76634
76635@@ -2384,6 +2824,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
76636 struct mempolicy *pol;
76637 bool faulted_in_anon_vma = true;
76638
76639+ BUG_ON(vma->vm_mirror);
76640+
76641 /*
76642 * If anonymous vma has not yet been faulted, update new pgoff
76643 * to match new location, to increase its chance of merging.
76644@@ -2450,6 +2892,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
76645 return NULL;
76646 }
76647
76648+#ifdef CONFIG_PAX_SEGMEXEC
76649+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
76650+{
76651+ struct vm_area_struct *prev_m;
76652+ struct rb_node **rb_link_m, *rb_parent_m;
76653+ struct mempolicy *pol_m;
76654+
76655+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
76656+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
76657+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
76658+ *vma_m = *vma;
76659+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
76660+ if (anon_vma_clone(vma_m, vma))
76661+ return -ENOMEM;
76662+ pol_m = vma_policy(vma_m);
76663+ mpol_get(pol_m);
76664+ vma_set_policy(vma_m, pol_m);
76665+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
76666+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
76667+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
76668+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
76669+ if (vma_m->vm_file)
76670+ get_file(vma_m->vm_file);
76671+ if (vma_m->vm_ops && vma_m->vm_ops->open)
76672+ vma_m->vm_ops->open(vma_m);
76673+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
76674+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
76675+ vma_m->vm_mirror = vma;
76676+ vma->vm_mirror = vma_m;
76677+ return 0;
76678+}
76679+#endif
76680+
76681 /*
76682 * Return true if the calling process may expand its vm space by the passed
76683 * number of pages
76684@@ -2461,6 +2936,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
76685
76686 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
76687
76688+#ifdef CONFIG_PAX_RANDMMAP
76689+ if (mm->pax_flags & MF_PAX_RANDMMAP)
76690+ cur -= mm->brk_gap;
76691+#endif
76692+
76693+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
76694 if (cur + npages > lim)
76695 return 0;
76696 return 1;
76697@@ -2531,6 +3012,22 @@ int install_special_mapping(struct mm_struct *mm,
76698 vma->vm_start = addr;
76699 vma->vm_end = addr + len;
76700
76701+#ifdef CONFIG_PAX_MPROTECT
76702+ if (mm->pax_flags & MF_PAX_MPROTECT) {
76703+#ifndef CONFIG_PAX_MPROTECT_COMPAT
76704+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
76705+ return -EPERM;
76706+ if (!(vm_flags & VM_EXEC))
76707+ vm_flags &= ~VM_MAYEXEC;
76708+#else
76709+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
76710+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
76711+#endif
76712+ else
76713+ vm_flags &= ~VM_MAYWRITE;
76714+ }
76715+#endif
76716+
76717 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
76718 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
76719
76720diff --git a/mm/mprotect.c b/mm/mprotect.c
76721index a409926..8b32e6d 100644
76722--- a/mm/mprotect.c
76723+++ b/mm/mprotect.c
76724@@ -23,10 +23,17 @@
76725 #include <linux/mmu_notifier.h>
76726 #include <linux/migrate.h>
76727 #include <linux/perf_event.h>
76728+
76729+#ifdef CONFIG_PAX_MPROTECT
76730+#include <linux/elf.h>
76731+#include <linux/binfmts.h>
76732+#endif
76733+
76734 #include <asm/uaccess.h>
76735 #include <asm/pgtable.h>
76736 #include <asm/cacheflush.h>
76737 #include <asm/tlbflush.h>
76738+#include <asm/mmu_context.h>
76739
76740 #ifndef pgprot_modify
76741 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
76742@@ -141,6 +148,48 @@ static void change_protection(struct vm_area_struct *vma,
76743 flush_tlb_range(vma, start, end);
76744 }
76745
76746+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
76747+/* called while holding the mmap semaphor for writing except stack expansion */
76748+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
76749+{
76750+ unsigned long oldlimit, newlimit = 0UL;
76751+
76752+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
76753+ return;
76754+
76755+ spin_lock(&mm->page_table_lock);
76756+ oldlimit = mm->context.user_cs_limit;
76757+ if ((prot & VM_EXEC) && oldlimit < end)
76758+ /* USER_CS limit moved up */
76759+ newlimit = end;
76760+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
76761+ /* USER_CS limit moved down */
76762+ newlimit = start;
76763+
76764+ if (newlimit) {
76765+ mm->context.user_cs_limit = newlimit;
76766+
76767+#ifdef CONFIG_SMP
76768+ wmb();
76769+ cpus_clear(mm->context.cpu_user_cs_mask);
76770+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
76771+#endif
76772+
76773+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
76774+ }
76775+ spin_unlock(&mm->page_table_lock);
76776+ if (newlimit == end) {
76777+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
76778+
76779+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
76780+ if (is_vm_hugetlb_page(vma))
76781+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
76782+ else
76783+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
76784+ }
76785+}
76786+#endif
76787+
76788 int
76789 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
76790 unsigned long start, unsigned long end, unsigned long newflags)
76791@@ -153,11 +202,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
76792 int error;
76793 int dirty_accountable = 0;
76794
76795+#ifdef CONFIG_PAX_SEGMEXEC
76796+ struct vm_area_struct *vma_m = NULL;
76797+ unsigned long start_m, end_m;
76798+
76799+ start_m = start + SEGMEXEC_TASK_SIZE;
76800+ end_m = end + SEGMEXEC_TASK_SIZE;
76801+#endif
76802+
76803 if (newflags == oldflags) {
76804 *pprev = vma;
76805 return 0;
76806 }
76807
76808+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
76809+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
76810+
76811+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
76812+ return -ENOMEM;
76813+
76814+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
76815+ return -ENOMEM;
76816+ }
76817+
76818 /*
76819 * If we make a private mapping writable we increase our commit;
76820 * but (without finer accounting) cannot reduce our commit if we
76821@@ -174,6 +241,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
76822 }
76823 }
76824
76825+#ifdef CONFIG_PAX_SEGMEXEC
76826+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
76827+ if (start != vma->vm_start) {
76828+ error = split_vma(mm, vma, start, 1);
76829+ if (error)
76830+ goto fail;
76831+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
76832+ *pprev = (*pprev)->vm_next;
76833+ }
76834+
76835+ if (end != vma->vm_end) {
76836+ error = split_vma(mm, vma, end, 0);
76837+ if (error)
76838+ goto fail;
76839+ }
76840+
76841+ if (pax_find_mirror_vma(vma)) {
76842+ error = __do_munmap(mm, start_m, end_m - start_m);
76843+ if (error)
76844+ goto fail;
76845+ } else {
76846+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
76847+ if (!vma_m) {
76848+ error = -ENOMEM;
76849+ goto fail;
76850+ }
76851+ vma->vm_flags = newflags;
76852+ error = pax_mirror_vma(vma_m, vma);
76853+ if (error) {
76854+ vma->vm_flags = oldflags;
76855+ goto fail;
76856+ }
76857+ }
76858+ }
76859+#endif
76860+
76861 /*
76862 * First try to merge with previous and/or next vma.
76863 */
76864@@ -204,9 +307,21 @@ success:
76865 * vm_flags and vm_page_prot are protected by the mmap_sem
76866 * held in write mode.
76867 */
76868+
76869+#ifdef CONFIG_PAX_SEGMEXEC
76870+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
76871+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
76872+#endif
76873+
76874 vma->vm_flags = newflags;
76875+
76876+#ifdef CONFIG_PAX_MPROTECT
76877+ if (mm->binfmt && mm->binfmt->handle_mprotect)
76878+ mm->binfmt->handle_mprotect(vma, newflags);
76879+#endif
76880+
76881 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
76882- vm_get_page_prot(newflags));
76883+ vm_get_page_prot(vma->vm_flags));
76884
76885 if (vma_wants_writenotify(vma)) {
76886 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
76887@@ -248,6 +363,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
76888 end = start + len;
76889 if (end <= start)
76890 return -ENOMEM;
76891+
76892+#ifdef CONFIG_PAX_SEGMEXEC
76893+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
76894+ if (end > SEGMEXEC_TASK_SIZE)
76895+ return -EINVAL;
76896+ } else
76897+#endif
76898+
76899+ if (end > TASK_SIZE)
76900+ return -EINVAL;
76901+
76902 if (!arch_validate_prot(prot))
76903 return -EINVAL;
76904
76905@@ -255,7 +381,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
76906 /*
76907 * Does the application expect PROT_READ to imply PROT_EXEC:
76908 */
76909- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
76910+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
76911 prot |= PROT_EXEC;
76912
76913 vm_flags = calc_vm_prot_bits(prot);
76914@@ -288,6 +414,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
76915 if (start > vma->vm_start)
76916 prev = vma;
76917
76918+#ifdef CONFIG_PAX_MPROTECT
76919+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
76920+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
76921+#endif
76922+
76923 for (nstart = start ; ; ) {
76924 unsigned long newflags;
76925
76926@@ -297,6 +428,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
76927
76928 /* newflags >> 4 shift VM_MAY% in place of VM_% */
76929 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
76930+ if (prot & (PROT_WRITE | PROT_EXEC))
76931+ gr_log_rwxmprotect(vma->vm_file);
76932+
76933+ error = -EACCES;
76934+ goto out;
76935+ }
76936+
76937+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
76938 error = -EACCES;
76939 goto out;
76940 }
76941@@ -311,6 +450,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
76942 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
76943 if (error)
76944 goto out;
76945+
76946+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
76947+
76948 nstart = tmp;
76949
76950 if (nstart < prev->vm_end)
76951diff --git a/mm/mremap.c b/mm/mremap.c
76952index 1b61c2d..1cc0e3c 100644
76953--- a/mm/mremap.c
76954+++ b/mm/mremap.c
76955@@ -125,6 +125,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
76956 continue;
76957 pte = ptep_get_and_clear(mm, old_addr, old_pte);
76958 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
76959+
76960+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
76961+ if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
76962+ pte = pte_exprotect(pte);
76963+#endif
76964+
76965 set_pte_at(mm, new_addr, new_pte, pte);
76966 }
76967
76968@@ -319,6 +325,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
76969 if (is_vm_hugetlb_page(vma))
76970 goto Einval;
76971
76972+#ifdef CONFIG_PAX_SEGMEXEC
76973+ if (pax_find_mirror_vma(vma))
76974+ goto Einval;
76975+#endif
76976+
76977 /* We can't remap across vm area boundaries */
76978 if (old_len > vma->vm_end - addr)
76979 goto Efault;
76980@@ -375,20 +386,25 @@ static unsigned long mremap_to(unsigned long addr,
76981 unsigned long ret = -EINVAL;
76982 unsigned long charged = 0;
76983 unsigned long map_flags;
76984+ unsigned long pax_task_size = TASK_SIZE;
76985
76986 if (new_addr & ~PAGE_MASK)
76987 goto out;
76988
76989- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
76990+#ifdef CONFIG_PAX_SEGMEXEC
76991+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
76992+ pax_task_size = SEGMEXEC_TASK_SIZE;
76993+#endif
76994+
76995+ pax_task_size -= PAGE_SIZE;
76996+
76997+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
76998 goto out;
76999
77000 /* Check if the location we're moving into overlaps the
77001 * old location at all, and fail if it does.
77002 */
77003- if ((new_addr <= addr) && (new_addr+new_len) > addr)
77004- goto out;
77005-
77006- if ((addr <= new_addr) && (addr+old_len) > new_addr)
77007+ if (addr + old_len > new_addr && new_addr + new_len > addr)
77008 goto out;
77009
77010 ret = do_munmap(mm, new_addr, new_len);
77011@@ -456,6 +472,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
77012 struct vm_area_struct *vma;
77013 unsigned long ret = -EINVAL;
77014 unsigned long charged = 0;
77015+ unsigned long pax_task_size = TASK_SIZE;
77016
77017 down_write(&current->mm->mmap_sem);
77018
77019@@ -476,6 +493,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
77020 if (!new_len)
77021 goto out;
77022
77023+#ifdef CONFIG_PAX_SEGMEXEC
77024+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
77025+ pax_task_size = SEGMEXEC_TASK_SIZE;
77026+#endif
77027+
77028+ pax_task_size -= PAGE_SIZE;
77029+
77030+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
77031+ old_len > pax_task_size || addr > pax_task_size-old_len)
77032+ goto out;
77033+
77034 if (flags & MREMAP_FIXED) {
77035 if (flags & MREMAP_MAYMOVE)
77036 ret = mremap_to(addr, old_len, new_addr, new_len);
77037@@ -524,6 +552,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
77038 addr + new_len);
77039 }
77040 ret = addr;
77041+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
77042 goto out;
77043 }
77044 }
77045@@ -547,7 +576,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
77046 goto out;
77047 }
77048
77049+ map_flags = vma->vm_flags;
77050 ret = move_vma(vma, addr, old_len, new_len, new_addr);
77051+ if (!(ret & ~PAGE_MASK)) {
77052+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
77053+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
77054+ }
77055 }
77056 out:
77057 if (ret & ~PAGE_MASK)
77058diff --git a/mm/nommu.c b/mm/nommu.c
77059index 45131b4..c521665 100644
77060--- a/mm/nommu.c
77061+++ b/mm/nommu.c
77062@@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
77063 int sysctl_overcommit_ratio = 50; /* default is 50% */
77064 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
77065 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
77066-int heap_stack_gap = 0;
77067
77068 atomic_long_t mmap_pages_allocated;
77069
77070@@ -824,15 +823,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
77071 EXPORT_SYMBOL(find_vma);
77072
77073 /*
77074- * find a VMA
77075- * - we don't extend stack VMAs under NOMMU conditions
77076- */
77077-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
77078-{
77079- return find_vma(mm, addr);
77080-}
77081-
77082-/*
77083 * expand a stack to a given address
77084 * - not supported under NOMMU conditions
77085 */
77086@@ -1540,6 +1530,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
77087
77088 /* most fields are the same, copy all, and then fixup */
77089 *new = *vma;
77090+ INIT_LIST_HEAD(&new->anon_vma_chain);
77091 *region = *vma->vm_region;
77092 new->vm_region = region;
77093
77094diff --git a/mm/page_alloc.c b/mm/page_alloc.c
77095index 7e208f0..d96f232 100644
77096--- a/mm/page_alloc.c
77097+++ b/mm/page_alloc.c
77098@@ -340,7 +340,7 @@ out:
77099 * This usage means that zero-order pages may not be compound.
77100 */
77101
77102-static void free_compound_page(struct page *page)
77103+void free_compound_page(struct page *page)
77104 {
77105 __free_pages_ok(page, compound_order(page));
77106 }
77107@@ -693,6 +693,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
77108 int i;
77109 int bad = 0;
77110
77111+#ifdef CONFIG_PAX_MEMORY_SANITIZE
77112+ unsigned long index = 1UL << order;
77113+#endif
77114+
77115 trace_mm_page_free(page, order);
77116 kmemcheck_free_shadow(page, order);
77117
77118@@ -708,6 +712,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
77119 debug_check_no_obj_freed(page_address(page),
77120 PAGE_SIZE << order);
77121 }
77122+
77123+#ifdef CONFIG_PAX_MEMORY_SANITIZE
77124+ for (; index; --index)
77125+ sanitize_highpage(page + index - 1);
77126+#endif
77127+
77128 arch_free_page(page, order);
77129 kernel_map_pages(page, 1 << order, 0);
77130
77131@@ -849,8 +859,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
77132 arch_alloc_page(page, order);
77133 kernel_map_pages(page, 1 << order, 1);
77134
77135+#ifndef CONFIG_PAX_MEMORY_SANITIZE
77136 if (gfp_flags & __GFP_ZERO)
77137 prep_zero_page(page, order, gfp_flags);
77138+#endif
77139
77140 if (order && (gfp_flags & __GFP_COMP))
77141 prep_compound_page(page, order);
77142@@ -3703,7 +3715,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
77143 unsigned long pfn;
77144
77145 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
77146+#ifdef CONFIG_X86_32
77147+ /* boot failures in VMware 8 on 32bit vanilla since
77148+ this change */
77149+ if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
77150+#else
77151 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
77152+#endif
77153 return 1;
77154 }
77155 return 0;
77156diff --git a/mm/percpu.c b/mm/percpu.c
77157index ddc5efb..f632d2c 100644
77158--- a/mm/percpu.c
77159+++ b/mm/percpu.c
77160@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
77161 static unsigned int pcpu_high_unit_cpu __read_mostly;
77162
77163 /* the address of the first chunk which starts with the kernel static area */
77164-void *pcpu_base_addr __read_mostly;
77165+void *pcpu_base_addr __read_only;
77166 EXPORT_SYMBOL_GPL(pcpu_base_addr);
77167
77168 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
77169diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
77170index 926b466..b23df53 100644
77171--- a/mm/process_vm_access.c
77172+++ b/mm/process_vm_access.c
77173@@ -13,6 +13,7 @@
77174 #include <linux/uio.h>
77175 #include <linux/sched.h>
77176 #include <linux/highmem.h>
77177+#include <linux/security.h>
77178 #include <linux/ptrace.h>
77179 #include <linux/slab.h>
77180 #include <linux/syscalls.h>
77181@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
77182 size_t iov_l_curr_offset = 0;
77183 ssize_t iov_len;
77184
77185+ return -ENOSYS; // PaX: until properly audited
77186+
77187 /*
77188 * Work out how many pages of struct pages we're going to need
77189 * when eventually calling get_user_pages
77190 */
77191 for (i = 0; i < riovcnt; i++) {
77192 iov_len = rvec[i].iov_len;
77193- if (iov_len > 0) {
77194- nr_pages_iov = ((unsigned long)rvec[i].iov_base
77195- + iov_len)
77196- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
77197- / PAGE_SIZE + 1;
77198- nr_pages = max(nr_pages, nr_pages_iov);
77199- }
77200+ if (iov_len <= 0)
77201+ continue;
77202+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
77203+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
77204+ nr_pages = max(nr_pages, nr_pages_iov);
77205 }
77206
77207 if (nr_pages == 0)
77208@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
77209 goto free_proc_pages;
77210 }
77211
77212+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
77213+ rc = -EPERM;
77214+ goto put_task_struct;
77215+ }
77216+
77217 mm = mm_access(task, PTRACE_MODE_ATTACH);
77218 if (!mm || IS_ERR(mm)) {
77219 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
77220diff --git a/mm/rmap.c b/mm/rmap.c
77221index 2ee1ef0..2e175ba 100644
77222--- a/mm/rmap.c
77223+++ b/mm/rmap.c
77224@@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
77225 struct anon_vma *anon_vma = vma->anon_vma;
77226 struct anon_vma_chain *avc;
77227
77228+#ifdef CONFIG_PAX_SEGMEXEC
77229+ struct anon_vma_chain *avc_m = NULL;
77230+#endif
77231+
77232 might_sleep();
77233 if (unlikely(!anon_vma)) {
77234 struct mm_struct *mm = vma->vm_mm;
77235@@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
77236 if (!avc)
77237 goto out_enomem;
77238
77239+#ifdef CONFIG_PAX_SEGMEXEC
77240+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
77241+ if (!avc_m)
77242+ goto out_enomem_free_avc;
77243+#endif
77244+
77245 anon_vma = find_mergeable_anon_vma(vma);
77246 allocated = NULL;
77247 if (!anon_vma) {
77248@@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
77249 /* page_table_lock to protect against threads */
77250 spin_lock(&mm->page_table_lock);
77251 if (likely(!vma->anon_vma)) {
77252+
77253+#ifdef CONFIG_PAX_SEGMEXEC
77254+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
77255+
77256+ if (vma_m) {
77257+ BUG_ON(vma_m->anon_vma);
77258+ vma_m->anon_vma = anon_vma;
77259+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
77260+ avc_m = NULL;
77261+ }
77262+#endif
77263+
77264 vma->anon_vma = anon_vma;
77265 anon_vma_chain_link(vma, avc, anon_vma);
77266 allocated = NULL;
77267@@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
77268
77269 if (unlikely(allocated))
77270 put_anon_vma(allocated);
77271+
77272+#ifdef CONFIG_PAX_SEGMEXEC
77273+ if (unlikely(avc_m))
77274+ anon_vma_chain_free(avc_m);
77275+#endif
77276+
77277 if (unlikely(avc))
77278 anon_vma_chain_free(avc);
77279 }
77280 return 0;
77281
77282 out_enomem_free_avc:
77283+
77284+#ifdef CONFIG_PAX_SEGMEXEC
77285+ if (avc_m)
77286+ anon_vma_chain_free(avc_m);
77287+#endif
77288+
77289 anon_vma_chain_free(avc);
77290 out_enomem:
77291 return -ENOMEM;
77292@@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
77293 * Attach the anon_vmas from src to dst.
77294 * Returns 0 on success, -ENOMEM on failure.
77295 */
77296-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
77297+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
77298 {
77299 struct anon_vma_chain *avc, *pavc;
77300 struct anon_vma *root = NULL;
77301@@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
77302 * the corresponding VMA in the parent process is attached to.
77303 * Returns 0 on success, non-zero on failure.
77304 */
77305-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
77306+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
77307 {
77308 struct anon_vma_chain *avc;
77309 struct anon_vma *anon_vma;
77310diff --git a/mm/shmem.c b/mm/shmem.c
77311index 50c5b8f..0bc87f7 100644
77312--- a/mm/shmem.c
77313+++ b/mm/shmem.c
77314@@ -31,7 +31,7 @@
77315 #include <linux/export.h>
77316 #include <linux/swap.h>
77317
77318-static struct vfsmount *shm_mnt;
77319+struct vfsmount *shm_mnt;
77320
77321 #ifdef CONFIG_SHMEM
77322 /*
77323@@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
77324 #define BOGO_DIRENT_SIZE 20
77325
77326 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
77327-#define SHORT_SYMLINK_LEN 128
77328+#define SHORT_SYMLINK_LEN 64
77329
77330 /*
77331 * shmem_fallocate and shmem_writepage communicate via inode->i_private
77332@@ -2112,6 +2112,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
77333 static int shmem_xattr_validate(const char *name)
77334 {
77335 struct { const char *prefix; size_t len; } arr[] = {
77336+
77337+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
77338+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
77339+#endif
77340+
77341 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
77342 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
77343 };
77344@@ -2167,6 +2172,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
77345 if (err)
77346 return err;
77347
77348+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
77349+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
77350+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
77351+ return -EOPNOTSUPP;
77352+ if (size > 8)
77353+ return -EINVAL;
77354+ }
77355+#endif
77356+
77357 return simple_xattr_set(&info->xattrs, name, value, size, flags);
77358 }
77359
77360@@ -2466,8 +2480,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
77361 int err = -ENOMEM;
77362
77363 /* Round up to L1_CACHE_BYTES to resist false sharing */
77364- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
77365- L1_CACHE_BYTES), GFP_KERNEL);
77366+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
77367 if (!sbinfo)
77368 return -ENOMEM;
77369
77370diff --git a/mm/slab.c b/mm/slab.c
77371index 33d3363..93c6810 100644
77372--- a/mm/slab.c
77373+++ b/mm/slab.c
77374@@ -164,7 +164,7 @@ static bool pfmemalloc_active __read_mostly;
77375
77376 /* Legal flag mask for kmem_cache_create(). */
77377 #if DEBUG
77378-# define CREATE_MASK (SLAB_RED_ZONE | \
77379+# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
77380 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
77381 SLAB_CACHE_DMA | \
77382 SLAB_STORE_USER | \
77383@@ -172,7 +172,7 @@ static bool pfmemalloc_active __read_mostly;
77384 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
77385 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
77386 #else
77387-# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
77388+# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
77389 SLAB_CACHE_DMA | \
77390 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
77391 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
77392@@ -322,7 +322,7 @@ struct kmem_list3 {
77393 * Need this for bootstrapping a per node allocator.
77394 */
77395 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
77396-static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
77397+static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
77398 #define CACHE_CACHE 0
77399 #define SIZE_AC MAX_NUMNODES
77400 #define SIZE_L3 (2 * MAX_NUMNODES)
77401@@ -423,10 +423,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
77402 if ((x)->max_freeable < i) \
77403 (x)->max_freeable = i; \
77404 } while (0)
77405-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
77406-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
77407-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
77408-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
77409+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
77410+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
77411+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
77412+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
77413 #else
77414 #define STATS_INC_ACTIVE(x) do { } while (0)
77415 #define STATS_DEC_ACTIVE(x) do { } while (0)
77416@@ -534,7 +534,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
77417 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
77418 */
77419 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
77420- const struct slab *slab, void *obj)
77421+ const struct slab *slab, const void *obj)
77422 {
77423 u32 offset = (obj - slab->s_mem);
77424 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
77425@@ -555,12 +555,13 @@ EXPORT_SYMBOL(malloc_sizes);
77426 struct cache_names {
77427 char *name;
77428 char *name_dma;
77429+ char *name_usercopy;
77430 };
77431
77432 static struct cache_names __initdata cache_names[] = {
77433-#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
77434+#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
77435 #include <linux/kmalloc_sizes.h>
77436- {NULL,}
77437+ {NULL}
77438 #undef CACHE
77439 };
77440
77441@@ -721,6 +722,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
77442 if (unlikely(gfpflags & GFP_DMA))
77443 return csizep->cs_dmacachep;
77444 #endif
77445+
77446+#ifdef CONFIG_PAX_USERCOPY_SLABS
77447+ if (unlikely(gfpflags & GFP_USERCOPY))
77448+ return csizep->cs_usercopycachep;
77449+#endif
77450+
77451 return csizep->cs_cachep;
77452 }
77453
77454@@ -1676,7 +1683,7 @@ void __init kmem_cache_init(void)
77455 sizes[INDEX_AC].cs_cachep->size = sizes[INDEX_AC].cs_size;
77456 sizes[INDEX_AC].cs_cachep->object_size = sizes[INDEX_AC].cs_size;
77457 sizes[INDEX_AC].cs_cachep->align = ARCH_KMALLOC_MINALIGN;
77458- __kmem_cache_create(sizes[INDEX_AC].cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC);
77459+ __kmem_cache_create(sizes[INDEX_AC].cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY);
77460 list_add(&sizes[INDEX_AC].cs_cachep->list, &slab_caches);
77461
77462 if (INDEX_AC != INDEX_L3) {
77463@@ -1685,7 +1692,7 @@ void __init kmem_cache_init(void)
77464 sizes[INDEX_L3].cs_cachep->size = sizes[INDEX_L3].cs_size;
77465 sizes[INDEX_L3].cs_cachep->object_size = sizes[INDEX_L3].cs_size;
77466 sizes[INDEX_L3].cs_cachep->align = ARCH_KMALLOC_MINALIGN;
77467- __kmem_cache_create(sizes[INDEX_L3].cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC);
77468+ __kmem_cache_create(sizes[INDEX_L3].cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY);
77469 list_add(&sizes[INDEX_L3].cs_cachep->list, &slab_caches);
77470 }
77471
77472@@ -1705,7 +1712,7 @@ void __init kmem_cache_init(void)
77473 sizes->cs_cachep->size = sizes->cs_size;
77474 sizes->cs_cachep->object_size = sizes->cs_size;
77475 sizes->cs_cachep->align = ARCH_KMALLOC_MINALIGN;
77476- __kmem_cache_create(sizes->cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC);
77477+ __kmem_cache_create(sizes->cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY);
77478 list_add(&sizes->cs_cachep->list, &slab_caches);
77479 }
77480 #ifdef CONFIG_ZONE_DMA
77481@@ -1718,6 +1725,17 @@ void __init kmem_cache_init(void)
77482 ARCH_KMALLOC_FLAGS|SLAB_CACHE_DMA| SLAB_PANIC);
77483 list_add(&sizes->cs_dmacachep->list, &slab_caches);
77484 #endif
77485+
77486+#ifdef CONFIG_PAX_USERCOPY_SLABS
77487+ sizes->cs_usercopycachep = kmem_cache_zalloc(kmem_cache, GFP_NOWAIT);
77488+ sizes->cs_usercopycachep->name = names->name_dma;
77489+ sizes->cs_usercopycachep->size = sizes->cs_size;
77490+ sizes->cs_usercopycachep->object_size = sizes->cs_size;
77491+ sizes->cs_usercopycachep->align = ARCH_KMALLOC_MINALIGN;
77492+ __kmem_cache_create(sizes->cs_usercopycachep, ARCH_KMALLOC_FLAGS| SLAB_PANIC|SLAB_USERCOPY);
77493+ list_add(&sizes->cs_usercopycachep->list, &slab_caches);
77494+#endif
77495+
77496 sizes++;
77497 names++;
77498 }
77499@@ -4405,10 +4423,10 @@ static int s_show(struct seq_file *m, void *p)
77500 }
77501 /* cpu stats */
77502 {
77503- unsigned long allochit = atomic_read(&cachep->allochit);
77504- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
77505- unsigned long freehit = atomic_read(&cachep->freehit);
77506- unsigned long freemiss = atomic_read(&cachep->freemiss);
77507+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
77508+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
77509+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
77510+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
77511
77512 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
77513 allochit, allocmiss, freehit, freemiss);
77514@@ -4667,13 +4685,71 @@ static int __init slab_proc_init(void)
77515 {
77516 proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
77517 #ifdef CONFIG_DEBUG_SLAB_LEAK
77518- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
77519+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
77520 #endif
77521 return 0;
77522 }
77523 module_init(slab_proc_init);
77524 #endif
77525
77526+bool is_usercopy_object(const void *ptr)
77527+{
77528+ struct page *page;
77529+ struct kmem_cache *cachep;
77530+
77531+ if (ZERO_OR_NULL_PTR(ptr))
77532+ return false;
77533+
77534+ if (!slab_is_available())
77535+ return false;
77536+
77537+ if (!virt_addr_valid(ptr))
77538+ return false;
77539+
77540+ page = virt_to_head_page(ptr);
77541+
77542+ if (!PageSlab(page))
77543+ return false;
77544+
77545+ cachep = page->slab_cache;
77546+ return cachep->flags & SLAB_USERCOPY;
77547+}
77548+
77549+#ifdef CONFIG_PAX_USERCOPY
77550+const char *check_heap_object(const void *ptr, unsigned long n)
77551+{
77552+ struct page *page;
77553+ struct kmem_cache *cachep;
77554+ struct slab *slabp;
77555+ unsigned int objnr;
77556+ unsigned long offset;
77557+
77558+ if (ZERO_OR_NULL_PTR(ptr))
77559+ return "<null>";
77560+
77561+ if (!virt_addr_valid(ptr))
77562+ return NULL;
77563+
77564+ page = virt_to_head_page(ptr);
77565+
77566+ if (!PageSlab(page))
77567+ return NULL;
77568+
77569+ cachep = page->slab_cache;
77570+ if (!(cachep->flags & SLAB_USERCOPY))
77571+ return cachep->name;
77572+
77573+ slabp = page->slab_page;
77574+ objnr = obj_to_index(cachep, slabp, ptr);
77575+ BUG_ON(objnr >= cachep->num);
77576+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
77577+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
77578+ return NULL;
77579+
77580+ return cachep->name;
77581+}
77582+#endif
77583+
77584 /**
77585 * ksize - get the actual amount of memory allocated for a given object
77586 * @objp: Pointer to the object
77587diff --git a/mm/slab_common.c b/mm/slab_common.c
77588index 069a24e6..226a310 100644
77589--- a/mm/slab_common.c
77590+++ b/mm/slab_common.c
77591@@ -127,7 +127,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size, size_t align
77592 err = __kmem_cache_create(s, flags);
77593 if (!err) {
77594
77595- s->refcount = 1;
77596+ atomic_set(&s->refcount, 1);
77597 list_add(&s->list, &slab_caches);
77598
77599 } else {
77600@@ -163,8 +163,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
77601 {
77602 get_online_cpus();
77603 mutex_lock(&slab_mutex);
77604- s->refcount--;
77605- if (!s->refcount) {
77606+ if (atomic_dec_and_test(&s->refcount)) {
77607 list_del(&s->list);
77608
77609 if (!__kmem_cache_shutdown(s)) {
77610diff --git a/mm/slob.c b/mm/slob.c
77611index 1e921c5..1ce12c2 100644
77612--- a/mm/slob.c
77613+++ b/mm/slob.c
77614@@ -159,7 +159,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
77615 /*
77616 * Return the size of a slob block.
77617 */
77618-static slobidx_t slob_units(slob_t *s)
77619+static slobidx_t slob_units(const slob_t *s)
77620 {
77621 if (s->units > 0)
77622 return s->units;
77623@@ -169,7 +169,7 @@ static slobidx_t slob_units(slob_t *s)
77624 /*
77625 * Return the next free slob block pointer after this one.
77626 */
77627-static slob_t *slob_next(slob_t *s)
77628+static slob_t *slob_next(const slob_t *s)
77629 {
77630 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
77631 slobidx_t next;
77632@@ -184,14 +184,14 @@ static slob_t *slob_next(slob_t *s)
77633 /*
77634 * Returns true if s is the last free block in its page.
77635 */
77636-static int slob_last(slob_t *s)
77637+static int slob_last(const slob_t *s)
77638 {
77639 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
77640 }
77641
77642-static void *slob_new_pages(gfp_t gfp, int order, int node)
77643+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
77644 {
77645- void *page;
77646+ struct page *page;
77647
77648 #ifdef CONFIG_NUMA
77649 if (node != NUMA_NO_NODE)
77650@@ -203,14 +203,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
77651 if (!page)
77652 return NULL;
77653
77654- return page_address(page);
77655+ __SetPageSlab(page);
77656+ return page;
77657 }
77658
77659-static void slob_free_pages(void *b, int order)
77660+static void slob_free_pages(struct page *sp, int order)
77661 {
77662 if (current->reclaim_state)
77663 current->reclaim_state->reclaimed_slab += 1 << order;
77664- free_pages((unsigned long)b, order);
77665+ __ClearPageSlab(sp);
77666+ reset_page_mapcount(sp);
77667+ sp->private = 0;
77668+ __free_pages(sp, order);
77669 }
77670
77671 /*
77672@@ -315,15 +319,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
77673
77674 /* Not enough space: must allocate a new page */
77675 if (!b) {
77676- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
77677- if (!b)
77678+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
77679+ if (!sp)
77680 return NULL;
77681- sp = virt_to_page(b);
77682- __SetPageSlab(sp);
77683+ b = page_address(sp);
77684
77685 spin_lock_irqsave(&slob_lock, flags);
77686 sp->units = SLOB_UNITS(PAGE_SIZE);
77687 sp->freelist = b;
77688+ sp->private = 0;
77689 INIT_LIST_HEAD(&sp->list);
77690 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
77691 set_slob_page_free(sp, slob_list);
77692@@ -361,9 +365,7 @@ static void slob_free(void *block, int size)
77693 if (slob_page_free(sp))
77694 clear_slob_page_free(sp);
77695 spin_unlock_irqrestore(&slob_lock, flags);
77696- __ClearPageSlab(sp);
77697- reset_page_mapcount(sp);
77698- slob_free_pages(b, 0);
77699+ slob_free_pages(sp, 0);
77700 return;
77701 }
77702
77703@@ -426,11 +428,10 @@ out:
77704 */
77705
77706 static __always_inline void *
77707-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
77708+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
77709 {
77710- unsigned int *m;
77711- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
77712- void *ret;
77713+ slob_t *m;
77714+ void *ret = NULL;
77715
77716 gfp &= gfp_allowed_mask;
77717
77718@@ -444,20 +445,23 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
77719
77720 if (!m)
77721 return NULL;
77722- *m = size;
77723+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
77724+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
77725+ m[0].units = size;
77726+ m[1].units = align;
77727 ret = (void *)m + align;
77728
77729 trace_kmalloc_node(caller, ret,
77730 size, size + align, gfp, node);
77731 } else {
77732 unsigned int order = get_order(size);
77733+ struct page *page;
77734
77735 if (likely(order))
77736 gfp |= __GFP_COMP;
77737- ret = slob_new_pages(gfp, order, node);
77738- if (ret) {
77739- struct page *page;
77740- page = virt_to_page(ret);
77741+ page = slob_new_pages(gfp, order, node);
77742+ if (page) {
77743+ ret = page_address(page);
77744 page->private = size;
77745 }
77746
77747@@ -465,7 +469,17 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
77748 size, PAGE_SIZE << order, gfp, node);
77749 }
77750
77751- kmemleak_alloc(ret, size, 1, gfp);
77752+ return ret;
77753+}
77754+
77755+static __always_inline void *
77756+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
77757+{
77758+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
77759+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
77760+
77761+ if (!ZERO_OR_NULL_PTR(ret))
77762+ kmemleak_alloc(ret, size, 1, gfp);
77763 return ret;
77764 }
77765
77766@@ -501,15 +515,91 @@ void kfree(const void *block)
77767 kmemleak_free(block);
77768
77769 sp = virt_to_page(block);
77770- if (PageSlab(sp)) {
77771+ VM_BUG_ON(!PageSlab(sp));
77772+ if (!sp->private) {
77773 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
77774- unsigned int *m = (unsigned int *)(block - align);
77775- slob_free(m, *m + align);
77776- } else
77777+ slob_t *m = (slob_t *)(block - align);
77778+ slob_free(m, m[0].units + align);
77779+ } else {
77780+ __ClearPageSlab(sp);
77781+ reset_page_mapcount(sp);
77782+ sp->private = 0;
77783 put_page(sp);
77784+ }
77785 }
77786 EXPORT_SYMBOL(kfree);
77787
77788+bool is_usercopy_object(const void *ptr)
77789+{
77790+ if (!slab_is_available())
77791+ return false;
77792+
77793+ // PAX: TODO
77794+
77795+ return false;
77796+}
77797+
77798+#ifdef CONFIG_PAX_USERCOPY
77799+const char *check_heap_object(const void *ptr, unsigned long n)
77800+{
77801+ struct page *page;
77802+ const slob_t *free;
77803+ const void *base;
77804+ unsigned long flags;
77805+
77806+ if (ZERO_OR_NULL_PTR(ptr))
77807+ return "<null>";
77808+
77809+ if (!virt_addr_valid(ptr))
77810+ return NULL;
77811+
77812+ page = virt_to_head_page(ptr);
77813+ if (!PageSlab(page))
77814+ return NULL;
77815+
77816+ if (page->private) {
77817+ base = page;
77818+ if (base <= ptr && n <= page->private - (ptr - base))
77819+ return NULL;
77820+ return "<slob>";
77821+ }
77822+
77823+ /* some tricky double walking to find the chunk */
77824+ spin_lock_irqsave(&slob_lock, flags);
77825+ base = (void *)((unsigned long)ptr & PAGE_MASK);
77826+ free = page->freelist;
77827+
77828+ while (!slob_last(free) && (void *)free <= ptr) {
77829+ base = free + slob_units(free);
77830+ free = slob_next(free);
77831+ }
77832+
77833+ while (base < (void *)free) {
77834+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
77835+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
77836+ int offset;
77837+
77838+ if (ptr < base + align)
77839+ break;
77840+
77841+ offset = ptr - base - align;
77842+ if (offset >= m) {
77843+ base += size;
77844+ continue;
77845+ }
77846+
77847+ if (n > m - offset)
77848+ break;
77849+
77850+ spin_unlock_irqrestore(&slob_lock, flags);
77851+ return NULL;
77852+ }
77853+
77854+ spin_unlock_irqrestore(&slob_lock, flags);
77855+ return "<slob>";
77856+}
77857+#endif
77858+
77859 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
77860 size_t ksize(const void *block)
77861 {
77862@@ -520,10 +610,11 @@ size_t ksize(const void *block)
77863 return 0;
77864
77865 sp = virt_to_page(block);
77866- if (PageSlab(sp)) {
77867+ VM_BUG_ON(!PageSlab(sp));
77868+ if (!sp->private) {
77869 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
77870- unsigned int *m = (unsigned int *)(block - align);
77871- return SLOB_UNITS(*m) * SLOB_UNIT;
77872+ slob_t *m = (slob_t *)(block - align);
77873+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
77874 } else
77875 return sp->private;
77876 }
77877@@ -550,23 +641,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
77878
77879 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
77880 {
77881- void *b;
77882+ void *b = NULL;
77883
77884 flags &= gfp_allowed_mask;
77885
77886 lockdep_trace_alloc(flags);
77887
77888+#ifdef CONFIG_PAX_USERCOPY_SLABS
77889+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
77890+#else
77891 if (c->size < PAGE_SIZE) {
77892 b = slob_alloc(c->size, flags, c->align, node);
77893 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
77894 SLOB_UNITS(c->size) * SLOB_UNIT,
77895 flags, node);
77896 } else {
77897- b = slob_new_pages(flags, get_order(c->size), node);
77898+ struct page *sp;
77899+
77900+ sp = slob_new_pages(flags, get_order(c->size), node);
77901+ if (sp) {
77902+ b = page_address(sp);
77903+ sp->private = c->size;
77904+ }
77905 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
77906 PAGE_SIZE << get_order(c->size),
77907 flags, node);
77908 }
77909+#endif
77910
77911 if (c->ctor)
77912 c->ctor(b);
77913@@ -578,10 +679,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
77914
77915 static void __kmem_cache_free(void *b, int size)
77916 {
77917- if (size < PAGE_SIZE)
77918+ struct page *sp;
77919+
77920+ sp = virt_to_page(b);
77921+ BUG_ON(!PageSlab(sp));
77922+ if (!sp->private)
77923 slob_free(b, size);
77924 else
77925- slob_free_pages(b, get_order(size));
77926+ slob_free_pages(sp, get_order(size));
77927 }
77928
77929 static void kmem_rcu_free(struct rcu_head *head)
77930@@ -594,17 +699,31 @@ static void kmem_rcu_free(struct rcu_head *head)
77931
77932 void kmem_cache_free(struct kmem_cache *c, void *b)
77933 {
77934+ int size = c->size;
77935+
77936+#ifdef CONFIG_PAX_USERCOPY_SLABS
77937+ if (size + c->align < PAGE_SIZE) {
77938+ size += c->align;
77939+ b -= c->align;
77940+ }
77941+#endif
77942+
77943 kmemleak_free_recursive(b, c->flags);
77944 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
77945 struct slob_rcu *slob_rcu;
77946- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
77947- slob_rcu->size = c->size;
77948+ slob_rcu = b + (size - sizeof(struct slob_rcu));
77949+ slob_rcu->size = size;
77950 call_rcu(&slob_rcu->head, kmem_rcu_free);
77951 } else {
77952- __kmem_cache_free(b, c->size);
77953+ __kmem_cache_free(b, size);
77954 }
77955
77956+#ifdef CONFIG_PAX_USERCOPY_SLABS
77957+ trace_kfree(_RET_IP_, b);
77958+#else
77959 trace_kmem_cache_free(_RET_IP_, b);
77960+#endif
77961+
77962 }
77963 EXPORT_SYMBOL(kmem_cache_free);
77964
77965diff --git a/mm/slub.c b/mm/slub.c
77966index a0d6984..e280e5d 100644
77967--- a/mm/slub.c
77968+++ b/mm/slub.c
77969@@ -201,7 +201,7 @@ struct track {
77970
77971 enum track_item { TRACK_ALLOC, TRACK_FREE };
77972
77973-#ifdef CONFIG_SYSFS
77974+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
77975 static int sysfs_slab_add(struct kmem_cache *);
77976 static int sysfs_slab_alias(struct kmem_cache *, const char *);
77977 static void sysfs_slab_remove(struct kmem_cache *);
77978@@ -521,7 +521,7 @@ static void print_track(const char *s, struct track *t)
77979 if (!t->addr)
77980 return;
77981
77982- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
77983+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
77984 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
77985 #ifdef CONFIG_STACKTRACE
77986 {
77987@@ -2623,6 +2623,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
77988
77989 page = virt_to_head_page(x);
77990
77991+ BUG_ON(!PageSlab(page));
77992+
77993 if (kmem_cache_debug(s) && page->slab != s) {
77994 pr_err("kmem_cache_free: Wrong slab cache. %s but object"
77995 " is from %s\n", page->slab->name, s->name);
77996@@ -2663,7 +2665,7 @@ static int slub_min_objects;
77997 * Merge control. If this is set then no merging of slab caches will occur.
77998 * (Could be removed. This was introduced to pacify the merge skeptics.)
77999 */
78000-static int slub_nomerge;
78001+static int slub_nomerge = 1;
78002
78003 /*
78004 * Calculate the order of allocation given an slab object size.
78005@@ -3225,6 +3227,10 @@ EXPORT_SYMBOL(kmalloc_caches);
78006 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
78007 #endif
78008
78009+#ifdef CONFIG_PAX_USERCOPY_SLABS
78010+static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
78011+#endif
78012+
78013 static int __init setup_slub_min_order(char *str)
78014 {
78015 get_option(&str, &slub_min_order);
78016@@ -3342,6 +3348,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
78017 return kmalloc_dma_caches[index];
78018
78019 #endif
78020+
78021+#ifdef CONFIG_PAX_USERCOPY_SLABS
78022+ if (flags & SLAB_USERCOPY)
78023+ return kmalloc_usercopy_caches[index];
78024+
78025+#endif
78026+
78027 return kmalloc_caches[index];
78028 }
78029
78030@@ -3410,6 +3423,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
78031 EXPORT_SYMBOL(__kmalloc_node);
78032 #endif
78033
78034+bool is_usercopy_object(const void *ptr)
78035+{
78036+ struct page *page;
78037+ struct kmem_cache *s;
78038+
78039+ if (ZERO_OR_NULL_PTR(ptr))
78040+ return false;
78041+
78042+ if (!slab_is_available())
78043+ return false;
78044+
78045+ if (!virt_addr_valid(ptr))
78046+ return false;
78047+
78048+ page = virt_to_head_page(ptr);
78049+
78050+ if (!PageSlab(page))
78051+ return false;
78052+
78053+ s = page->slab;
78054+ return s->flags & SLAB_USERCOPY;
78055+}
78056+
78057+#ifdef CONFIG_PAX_USERCOPY
78058+const char *check_heap_object(const void *ptr, unsigned long n)
78059+{
78060+ struct page *page;
78061+ struct kmem_cache *s;
78062+ unsigned long offset;
78063+
78064+ if (ZERO_OR_NULL_PTR(ptr))
78065+ return "<null>";
78066+
78067+ if (!virt_addr_valid(ptr))
78068+ return NULL;
78069+
78070+ page = virt_to_head_page(ptr);
78071+
78072+ if (!PageSlab(page))
78073+ return NULL;
78074+
78075+ s = page->slab;
78076+ if (!(s->flags & SLAB_USERCOPY))
78077+ return s->name;
78078+
78079+ offset = (ptr - page_address(page)) % s->size;
78080+ if (offset <= s->object_size && n <= s->object_size - offset)
78081+ return NULL;
78082+
78083+ return s->name;
78084+}
78085+#endif
78086+
78087 size_t ksize(const void *object)
78088 {
78089 struct page *page;
78090@@ -3684,7 +3750,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
78091 int node;
78092
78093 list_add(&s->list, &slab_caches);
78094- s->refcount = -1;
78095+ atomic_set(&s->refcount, -1);
78096
78097 for_each_node_state(node, N_NORMAL_MEMORY) {
78098 struct kmem_cache_node *n = get_node(s, node);
78099@@ -3807,17 +3873,17 @@ void __init kmem_cache_init(void)
78100
78101 /* Caches that are not of the two-to-the-power-of size */
78102 if (KMALLOC_MIN_SIZE <= 32) {
78103- kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
78104+ kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
78105 caches++;
78106 }
78107
78108 if (KMALLOC_MIN_SIZE <= 64) {
78109- kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
78110+ kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
78111 caches++;
78112 }
78113
78114 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
78115- kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
78116+ kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
78117 caches++;
78118 }
78119
78120@@ -3859,6 +3925,22 @@ void __init kmem_cache_init(void)
78121 }
78122 }
78123 #endif
78124+
78125+#ifdef CONFIG_PAX_USERCOPY_SLABS
78126+ for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
78127+ struct kmem_cache *s = kmalloc_caches[i];
78128+
78129+ if (s && s->size) {
78130+ char *name = kasprintf(GFP_NOWAIT,
78131+ "usercopy-kmalloc-%d", s->object_size);
78132+
78133+ BUG_ON(!name);
78134+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
78135+ s->object_size, SLAB_USERCOPY);
78136+ }
78137+ }
78138+#endif
78139+
78140 printk(KERN_INFO
78141 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
78142 " CPUs=%d, Nodes=%d\n",
78143@@ -3885,7 +3967,7 @@ static int slab_unmergeable(struct kmem_cache *s)
78144 /*
78145 * We may have set a slab to be unmergeable during bootstrap.
78146 */
78147- if (s->refcount < 0)
78148+ if (atomic_read(&s->refcount) < 0)
78149 return 1;
78150
78151 return 0;
78152@@ -3939,7 +4021,7 @@ struct kmem_cache *__kmem_cache_alias(const char *name, size_t size,
78153
78154 s = find_mergeable(size, align, flags, name, ctor);
78155 if (s) {
78156- s->refcount++;
78157+ atomic_inc(&s->refcount);
78158 /*
78159 * Adjust the object sizes so that we clear
78160 * the complete object on kzalloc.
78161@@ -3948,7 +4030,7 @@ struct kmem_cache *__kmem_cache_alias(const char *name, size_t size,
78162 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
78163
78164 if (sysfs_slab_alias(s, name)) {
78165- s->refcount--;
78166+ atomic_dec(&s->refcount);
78167 s = NULL;
78168 }
78169 }
78170@@ -4063,7 +4145,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
78171 }
78172 #endif
78173
78174-#ifdef CONFIG_SYSFS
78175+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
78176 static int count_inuse(struct page *page)
78177 {
78178 return page->inuse;
78179@@ -4450,12 +4532,12 @@ static void resiliency_test(void)
78180 validate_slab_cache(kmalloc_caches[9]);
78181 }
78182 #else
78183-#ifdef CONFIG_SYSFS
78184+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
78185 static void resiliency_test(void) {};
78186 #endif
78187 #endif
78188
78189-#ifdef CONFIG_SYSFS
78190+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
78191 enum slab_stat_type {
78192 SL_ALL, /* All slabs */
78193 SL_PARTIAL, /* Only partially allocated slabs */
78194@@ -4699,7 +4781,7 @@ SLAB_ATTR_RO(ctor);
78195
78196 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
78197 {
78198- return sprintf(buf, "%d\n", s->refcount - 1);
78199+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
78200 }
78201 SLAB_ATTR_RO(aliases);
78202
78203@@ -5261,6 +5343,7 @@ static char *create_unique_id(struct kmem_cache *s)
78204 return name;
78205 }
78206
78207+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
78208 static int sysfs_slab_add(struct kmem_cache *s)
78209 {
78210 int err;
78211@@ -5323,6 +5406,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
78212 kobject_del(&s->kobj);
78213 kobject_put(&s->kobj);
78214 }
78215+#endif
78216
78217 /*
78218 * Need to buffer aliases during bootup until sysfs becomes
78219@@ -5336,6 +5420,7 @@ struct saved_alias {
78220
78221 static struct saved_alias *alias_list;
78222
78223+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
78224 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
78225 {
78226 struct saved_alias *al;
78227@@ -5358,6 +5443,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
78228 alias_list = al;
78229 return 0;
78230 }
78231+#endif
78232
78233 static int __init slab_sysfs_init(void)
78234 {
78235diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
78236index 1b7e22a..3fcd4f3 100644
78237--- a/mm/sparse-vmemmap.c
78238+++ b/mm/sparse-vmemmap.c
78239@@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
78240 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
78241 if (!p)
78242 return NULL;
78243- pud_populate(&init_mm, pud, p);
78244+ pud_populate_kernel(&init_mm, pud, p);
78245 }
78246 return pud;
78247 }
78248@@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
78249 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
78250 if (!p)
78251 return NULL;
78252- pgd_populate(&init_mm, pgd, p);
78253+ pgd_populate_kernel(&init_mm, pgd, p);
78254 }
78255 return pgd;
78256 }
78257diff --git a/mm/swap.c b/mm/swap.c
78258index 6310dc2..3662b3f 100644
78259--- a/mm/swap.c
78260+++ b/mm/swap.c
78261@@ -30,6 +30,7 @@
78262 #include <linux/backing-dev.h>
78263 #include <linux/memcontrol.h>
78264 #include <linux/gfp.h>
78265+#include <linux/hugetlb.h>
78266
78267 #include "internal.h"
78268
78269@@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
78270
78271 __page_cache_release(page);
78272 dtor = get_compound_page_dtor(page);
78273+ if (!PageHuge(page))
78274+ BUG_ON(dtor != free_compound_page);
78275 (*dtor)(page);
78276 }
78277
78278diff --git a/mm/swapfile.c b/mm/swapfile.c
78279index f91a255..9dcac21 100644
78280--- a/mm/swapfile.c
78281+++ b/mm/swapfile.c
78282@@ -64,7 +64,7 @@ static DEFINE_MUTEX(swapon_mutex);
78283
78284 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
78285 /* Activity counter to indicate that a swapon or swapoff has occurred */
78286-static atomic_t proc_poll_event = ATOMIC_INIT(0);
78287+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
78288
78289 static inline unsigned char swap_count(unsigned char ent)
78290 {
78291@@ -1601,7 +1601,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
78292 }
78293 filp_close(swap_file, NULL);
78294 err = 0;
78295- atomic_inc(&proc_poll_event);
78296+ atomic_inc_unchecked(&proc_poll_event);
78297 wake_up_interruptible(&proc_poll_wait);
78298
78299 out_dput:
78300@@ -1618,8 +1618,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
78301
78302 poll_wait(file, &proc_poll_wait, wait);
78303
78304- if (seq->poll_event != atomic_read(&proc_poll_event)) {
78305- seq->poll_event = atomic_read(&proc_poll_event);
78306+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
78307+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
78308 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
78309 }
78310
78311@@ -1717,7 +1717,7 @@ static int swaps_open(struct inode *inode, struct file *file)
78312 return ret;
78313
78314 seq = file->private_data;
78315- seq->poll_event = atomic_read(&proc_poll_event);
78316+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
78317 return 0;
78318 }
78319
78320@@ -2059,7 +2059,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
78321 (frontswap_map) ? "FS" : "");
78322
78323 mutex_unlock(&swapon_mutex);
78324- atomic_inc(&proc_poll_event);
78325+ atomic_inc_unchecked(&proc_poll_event);
78326 wake_up_interruptible(&proc_poll_wait);
78327
78328 if (S_ISREG(inode->i_mode))
78329diff --git a/mm/util.c b/mm/util.c
78330index dc3036c..b6c7c9d 100644
78331--- a/mm/util.c
78332+++ b/mm/util.c
78333@@ -292,6 +292,12 @@ done:
78334 void arch_pick_mmap_layout(struct mm_struct *mm)
78335 {
78336 mm->mmap_base = TASK_UNMAPPED_BASE;
78337+
78338+#ifdef CONFIG_PAX_RANDMMAP
78339+ if (mm->pax_flags & MF_PAX_RANDMMAP)
78340+ mm->mmap_base += mm->delta_mmap;
78341+#endif
78342+
78343 mm->get_unmapped_area = arch_get_unmapped_area;
78344 mm->unmap_area = arch_unmap_area;
78345 }
78346diff --git a/mm/vmalloc.c b/mm/vmalloc.c
78347index 78e0830..bc6bbd8 100644
78348--- a/mm/vmalloc.c
78349+++ b/mm/vmalloc.c
78350@@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
78351
78352 pte = pte_offset_kernel(pmd, addr);
78353 do {
78354- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
78355- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
78356+
78357+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
78358+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
78359+ BUG_ON(!pte_exec(*pte));
78360+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
78361+ continue;
78362+ }
78363+#endif
78364+
78365+ {
78366+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
78367+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
78368+ }
78369 } while (pte++, addr += PAGE_SIZE, addr != end);
78370 }
78371
78372@@ -100,16 +111,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
78373 pte = pte_alloc_kernel(pmd, addr);
78374 if (!pte)
78375 return -ENOMEM;
78376+
78377+ pax_open_kernel();
78378 do {
78379 struct page *page = pages[*nr];
78380
78381- if (WARN_ON(!pte_none(*pte)))
78382+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
78383+ if (pgprot_val(prot) & _PAGE_NX)
78384+#endif
78385+
78386+ if (!pte_none(*pte)) {
78387+ pax_close_kernel();
78388+ WARN_ON(1);
78389 return -EBUSY;
78390- if (WARN_ON(!page))
78391+ }
78392+ if (!page) {
78393+ pax_close_kernel();
78394+ WARN_ON(1);
78395 return -ENOMEM;
78396+ }
78397 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
78398 (*nr)++;
78399 } while (pte++, addr += PAGE_SIZE, addr != end);
78400+ pax_close_kernel();
78401 return 0;
78402 }
78403
78404@@ -119,7 +143,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
78405 pmd_t *pmd;
78406 unsigned long next;
78407
78408- pmd = pmd_alloc(&init_mm, pud, addr);
78409+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
78410 if (!pmd)
78411 return -ENOMEM;
78412 do {
78413@@ -136,7 +160,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
78414 pud_t *pud;
78415 unsigned long next;
78416
78417- pud = pud_alloc(&init_mm, pgd, addr);
78418+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
78419 if (!pud)
78420 return -ENOMEM;
78421 do {
78422@@ -191,11 +215,20 @@ int is_vmalloc_or_module_addr(const void *x)
78423 * and fall back on vmalloc() if that fails. Others
78424 * just put it in the vmalloc space.
78425 */
78426-#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
78427+#ifdef CONFIG_MODULES
78428+#ifdef MODULES_VADDR
78429 unsigned long addr = (unsigned long)x;
78430 if (addr >= MODULES_VADDR && addr < MODULES_END)
78431 return 1;
78432 #endif
78433+
78434+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
78435+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
78436+ return 1;
78437+#endif
78438+
78439+#endif
78440+
78441 return is_vmalloc_addr(x);
78442 }
78443
78444@@ -216,8 +249,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
78445
78446 if (!pgd_none(*pgd)) {
78447 pud_t *pud = pud_offset(pgd, addr);
78448+#ifdef CONFIG_X86
78449+ if (!pud_large(*pud))
78450+#endif
78451 if (!pud_none(*pud)) {
78452 pmd_t *pmd = pmd_offset(pud, addr);
78453+#ifdef CONFIG_X86
78454+ if (!pmd_large(*pmd))
78455+#endif
78456 if (!pmd_none(*pmd)) {
78457 pte_t *ptep, pte;
78458
78459@@ -329,7 +368,7 @@ static void purge_vmap_area_lazy(void);
78460 * Allocate a region of KVA of the specified size and alignment, within the
78461 * vstart and vend.
78462 */
78463-static struct vmap_area *alloc_vmap_area(unsigned long size,
78464+static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
78465 unsigned long align,
78466 unsigned long vstart, unsigned long vend,
78467 int node, gfp_t gfp_mask)
78468@@ -1328,6 +1367,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
78469 struct vm_struct *area;
78470
78471 BUG_ON(in_interrupt());
78472+
78473+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
78474+ if (flags & VM_KERNEXEC) {
78475+ if (start != VMALLOC_START || end != VMALLOC_END)
78476+ return NULL;
78477+ start = (unsigned long)MODULES_EXEC_VADDR;
78478+ end = (unsigned long)MODULES_EXEC_END;
78479+ }
78480+#endif
78481+
78482 if (flags & VM_IOREMAP) {
78483 int bit = fls(size);
78484
78485@@ -1568,6 +1617,11 @@ void *vmap(struct page **pages, unsigned int count,
78486 if (count > totalram_pages)
78487 return NULL;
78488
78489+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
78490+ if (!(pgprot_val(prot) & _PAGE_NX))
78491+ flags |= VM_KERNEXEC;
78492+#endif
78493+
78494 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
78495 __builtin_return_address(0));
78496 if (!area)
78497@@ -1669,6 +1723,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
78498 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
78499 goto fail;
78500
78501+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
78502+ if (!(pgprot_val(prot) & _PAGE_NX))
78503+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
78504+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
78505+ else
78506+#endif
78507+
78508 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
78509 start, end, node, gfp_mask, caller);
78510 if (!area)
78511@@ -1842,10 +1903,9 @@ EXPORT_SYMBOL(vzalloc_node);
78512 * For tight control over page level allocator and protection flags
78513 * use __vmalloc() instead.
78514 */
78515-
78516 void *vmalloc_exec(unsigned long size)
78517 {
78518- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
78519+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
78520 -1, __builtin_return_address(0));
78521 }
78522
78523@@ -2136,6 +2196,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
78524 unsigned long uaddr = vma->vm_start;
78525 unsigned long usize = vma->vm_end - vma->vm_start;
78526
78527+ BUG_ON(vma->vm_mirror);
78528+
78529 if ((PAGE_SIZE-1) & (unsigned long)addr)
78530 return -EINVAL;
78531
78532@@ -2575,7 +2637,11 @@ static int s_show(struct seq_file *m, void *p)
78533 v->addr, v->addr + v->size, v->size);
78534
78535 if (v->caller)
78536+#ifdef CONFIG_GRKERNSEC_HIDESYM
78537+ seq_printf(m, " %pK", v->caller);
78538+#else
78539 seq_printf(m, " %pS", v->caller);
78540+#endif
78541
78542 if (v->nr_pages)
78543 seq_printf(m, " pages=%d", v->nr_pages);
78544diff --git a/mm/vmstat.c b/mm/vmstat.c
78545index c737057..a49753a 100644
78546--- a/mm/vmstat.c
78547+++ b/mm/vmstat.c
78548@@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
78549 *
78550 * vm_stat contains the global counters
78551 */
78552-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
78553+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
78554 EXPORT_SYMBOL(vm_stat);
78555
78556 #ifdef CONFIG_SMP
78557@@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
78558 v = p->vm_stat_diff[i];
78559 p->vm_stat_diff[i] = 0;
78560 local_irq_restore(flags);
78561- atomic_long_add(v, &zone->vm_stat[i]);
78562+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
78563 global_diff[i] += v;
78564 #ifdef CONFIG_NUMA
78565 /* 3 seconds idle till flush */
78566@@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
78567
78568 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
78569 if (global_diff[i])
78570- atomic_long_add(global_diff[i], &vm_stat[i]);
78571+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
78572 }
78573
78574 void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
78575@@ -503,8 +503,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
78576 if (pset->vm_stat_diff[i]) {
78577 int v = pset->vm_stat_diff[i];
78578 pset->vm_stat_diff[i] = 0;
78579- atomic_long_add(v, &zone->vm_stat[i]);
78580- atomic_long_add(v, &vm_stat[i]);
78581+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
78582+ atomic_long_add_unchecked(v, &vm_stat[i]);
78583 }
78584 }
78585 #endif
78586@@ -1224,10 +1224,20 @@ static int __init setup_vmstat(void)
78587 start_cpu_timer(cpu);
78588 #endif
78589 #ifdef CONFIG_PROC_FS
78590- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
78591- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
78592- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
78593- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
78594+ {
78595+ mode_t gr_mode = S_IRUGO;
78596+#ifdef CONFIG_GRKERNSEC_PROC_ADD
78597+ gr_mode = S_IRUSR;
78598+#endif
78599+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
78600+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
78601+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
78602+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
78603+#else
78604+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
78605+#endif
78606+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
78607+ }
78608 #endif
78609 return 0;
78610 }
78611diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
78612index ee07072..593e3fd 100644
78613--- a/net/8021q/vlan.c
78614+++ b/net/8021q/vlan.c
78615@@ -484,7 +484,7 @@ out:
78616 return NOTIFY_DONE;
78617 }
78618
78619-static struct notifier_block vlan_notifier_block __read_mostly = {
78620+static struct notifier_block vlan_notifier_block = {
78621 .notifier_call = vlan_device_event,
78622 };
78623
78624@@ -559,8 +559,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
78625 err = -EPERM;
78626 if (!capable(CAP_NET_ADMIN))
78627 break;
78628- if ((args.u.name_type >= 0) &&
78629- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
78630+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
78631 struct vlan_net *vn;
78632
78633 vn = net_generic(net, vlan_net_id);
78634diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
78635index 02efb25..41541a9 100644
78636--- a/net/9p/trans_fd.c
78637+++ b/net/9p/trans_fd.c
78638@@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
78639 oldfs = get_fs();
78640 set_fs(get_ds());
78641 /* The cast to a user pointer is valid due to the set_fs() */
78642- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
78643+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
78644 set_fs(oldfs);
78645
78646 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
78647diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
78648index 876fbe8..8bbea9f 100644
78649--- a/net/atm/atm_misc.c
78650+++ b/net/atm/atm_misc.c
78651@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
78652 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
78653 return 1;
78654 atm_return(vcc, truesize);
78655- atomic_inc(&vcc->stats->rx_drop);
78656+ atomic_inc_unchecked(&vcc->stats->rx_drop);
78657 return 0;
78658 }
78659 EXPORT_SYMBOL(atm_charge);
78660@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
78661 }
78662 }
78663 atm_return(vcc, guess);
78664- atomic_inc(&vcc->stats->rx_drop);
78665+ atomic_inc_unchecked(&vcc->stats->rx_drop);
78666 return NULL;
78667 }
78668 EXPORT_SYMBOL(atm_alloc_charge);
78669@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
78670
78671 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
78672 {
78673-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
78674+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
78675 __SONET_ITEMS
78676 #undef __HANDLE_ITEM
78677 }
78678@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
78679
78680 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
78681 {
78682-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
78683+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
78684 __SONET_ITEMS
78685 #undef __HANDLE_ITEM
78686 }
78687diff --git a/net/atm/lec.h b/net/atm/lec.h
78688index a86aff9..3a0d6f6 100644
78689--- a/net/atm/lec.h
78690+++ b/net/atm/lec.h
78691@@ -48,7 +48,7 @@ struct lane2_ops {
78692 const u8 *tlvs, u32 sizeoftlvs);
78693 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
78694 const u8 *tlvs, u32 sizeoftlvs);
78695-};
78696+} __no_const;
78697
78698 /*
78699 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
78700diff --git a/net/atm/mpc.h b/net/atm/mpc.h
78701index 0919a88..a23d54e 100644
78702--- a/net/atm/mpc.h
78703+++ b/net/atm/mpc.h
78704@@ -33,7 +33,7 @@ struct mpoa_client {
78705 struct mpc_parameters parameters; /* parameters for this client */
78706
78707 const struct net_device_ops *old_ops;
78708- struct net_device_ops new_ops;
78709+ net_device_ops_no_const new_ops;
78710 };
78711
78712
78713diff --git a/net/atm/proc.c b/net/atm/proc.c
78714index 0d020de..011c7bb 100644
78715--- a/net/atm/proc.c
78716+++ b/net/atm/proc.c
78717@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
78718 const struct k_atm_aal_stats *stats)
78719 {
78720 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
78721- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
78722- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
78723- atomic_read(&stats->rx_drop));
78724+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
78725+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
78726+ atomic_read_unchecked(&stats->rx_drop));
78727 }
78728
78729 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
78730diff --git a/net/atm/resources.c b/net/atm/resources.c
78731index 0447d5d..3cf4728 100644
78732--- a/net/atm/resources.c
78733+++ b/net/atm/resources.c
78734@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
78735 static void copy_aal_stats(struct k_atm_aal_stats *from,
78736 struct atm_aal_stats *to)
78737 {
78738-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
78739+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
78740 __AAL_STAT_ITEMS
78741 #undef __HANDLE_ITEM
78742 }
78743@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
78744 static void subtract_aal_stats(struct k_atm_aal_stats *from,
78745 struct atm_aal_stats *to)
78746 {
78747-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
78748+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
78749 __AAL_STAT_ITEMS
78750 #undef __HANDLE_ITEM
78751 }
78752diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
78753index b02b75d..0a9636e 100644
78754--- a/net/batman-adv/bat_iv_ogm.c
78755+++ b/net/batman-adv/bat_iv_ogm.c
78756@@ -62,7 +62,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
78757
78758 /* randomize initial seqno to avoid collision */
78759 get_random_bytes(&random_seqno, sizeof(random_seqno));
78760- atomic_set(&hard_iface->seqno, random_seqno);
78761+ atomic_set_unchecked(&hard_iface->seqno, random_seqno);
78762
78763 hard_iface->packet_len = BATADV_OGM_HLEN;
78764 hard_iface->packet_buff = kmalloc(hard_iface->packet_len, GFP_ATOMIC);
78765@@ -608,9 +608,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
78766 batadv_ogm_packet = (struct batadv_ogm_packet *)hard_iface->packet_buff;
78767
78768 /* change sequence number to network order */
78769- seqno = (uint32_t)atomic_read(&hard_iface->seqno);
78770+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->seqno);
78771 batadv_ogm_packet->seqno = htonl(seqno);
78772- atomic_inc(&hard_iface->seqno);
78773+ atomic_inc_unchecked(&hard_iface->seqno);
78774
78775 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
78776 batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
78777@@ -1015,7 +1015,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
78778 return;
78779
78780 /* could be changed by schedule_own_packet() */
78781- if_incoming_seqno = atomic_read(&if_incoming->seqno);
78782+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
78783
78784 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
78785 has_directlink_flag = 1;
78786diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
78787index d112fd6..686a447 100644
78788--- a/net/batman-adv/hard-interface.c
78789+++ b/net/batman-adv/hard-interface.c
78790@@ -327,7 +327,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
78791 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
78792 dev_add_pack(&hard_iface->batman_adv_ptype);
78793
78794- atomic_set(&hard_iface->frag_seqno, 1);
78795+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
78796 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
78797 hard_iface->net_dev->name);
78798
78799@@ -450,7 +450,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
78800 /* This can't be called via a bat_priv callback because
78801 * we have no bat_priv yet.
78802 */
78803- atomic_set(&hard_iface->seqno, 1);
78804+ atomic_set_unchecked(&hard_iface->seqno, 1);
78805 hard_iface->packet_buff = NULL;
78806
78807 return hard_iface;
78808diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
78809index ce0684a..4a0cbf1 100644
78810--- a/net/batman-adv/soft-interface.c
78811+++ b/net/batman-adv/soft-interface.c
78812@@ -234,7 +234,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
78813 primary_if->net_dev->dev_addr, ETH_ALEN);
78814
78815 /* set broadcast sequence number */
78816- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
78817+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
78818 bcast_packet->seqno = htonl(seqno);
78819
78820 batadv_add_bcast_packet_to_list(bat_priv, skb, 1);
78821@@ -427,7 +427,7 @@ struct net_device *batadv_softif_create(const char *name)
78822 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
78823
78824 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
78825- atomic_set(&bat_priv->bcast_seqno, 1);
78826+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
78827 atomic_set(&bat_priv->tt.vn, 0);
78828 atomic_set(&bat_priv->tt.local_changes, 0);
78829 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
78830diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
78831index ac1e07a..4c846e2 100644
78832--- a/net/batman-adv/types.h
78833+++ b/net/batman-adv/types.h
78834@@ -33,8 +33,8 @@ struct batadv_hard_iface {
78835 int16_t if_num;
78836 char if_status;
78837 struct net_device *net_dev;
78838- atomic_t seqno;
78839- atomic_t frag_seqno;
78840+ atomic_unchecked_t seqno;
78841+ atomic_unchecked_t frag_seqno;
78842 unsigned char *packet_buff;
78843 int packet_len;
78844 struct kobject *hardif_obj;
78845@@ -244,7 +244,7 @@ struct batadv_priv {
78846 atomic_t orig_interval; /* uint */
78847 atomic_t hop_penalty; /* uint */
78848 atomic_t log_level; /* uint */
78849- atomic_t bcast_seqno;
78850+ atomic_unchecked_t bcast_seqno;
78851 atomic_t bcast_queue_left;
78852 atomic_t batman_queue_left;
78853 char num_ifaces;
78854diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
78855index f397232..3206a33 100644
78856--- a/net/batman-adv/unicast.c
78857+++ b/net/batman-adv/unicast.c
78858@@ -272,7 +272,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
78859 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
78860 frag2->flags = large_tail;
78861
78862- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
78863+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
78864 frag1->seqno = htons(seqno - 1);
78865 frag2->seqno = htons(seqno);
78866
78867diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
78868index 07f0739..3c42e34 100644
78869--- a/net/bluetooth/hci_sock.c
78870+++ b/net/bluetooth/hci_sock.c
78871@@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
78872 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
78873 }
78874
78875- len = min_t(unsigned int, len, sizeof(uf));
78876+ len = min((size_t)len, sizeof(uf));
78877 if (copy_from_user(&uf, optval, len)) {
78878 err = -EFAULT;
78879 break;
78880diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
78881index a91239d..d7ed533 100644
78882--- a/net/bluetooth/l2cap_core.c
78883+++ b/net/bluetooth/l2cap_core.c
78884@@ -3183,8 +3183,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
78885 break;
78886
78887 case L2CAP_CONF_RFC:
78888- if (olen == sizeof(rfc))
78889- memcpy(&rfc, (void *)val, olen);
78890+ if (olen != sizeof(rfc))
78891+ break;
78892+
78893+ memcpy(&rfc, (void *)val, olen);
78894
78895 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
78896 rfc.mode != chan->mode)
78897diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
78898index 083f2bf..799f9448 100644
78899--- a/net/bluetooth/l2cap_sock.c
78900+++ b/net/bluetooth/l2cap_sock.c
78901@@ -471,7 +471,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
78902 struct sock *sk = sock->sk;
78903 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
78904 struct l2cap_options opts;
78905- int len, err = 0;
78906+ int err = 0;
78907+ size_t len = optlen;
78908 u32 opt;
78909
78910 BT_DBG("sk %p", sk);
78911@@ -493,7 +494,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
78912 opts.max_tx = chan->max_tx;
78913 opts.txwin_size = chan->tx_win;
78914
78915- len = min_t(unsigned int, sizeof(opts), optlen);
78916+ len = min(sizeof(opts), len);
78917 if (copy_from_user((char *) &opts, optval, len)) {
78918 err = -EFAULT;
78919 break;
78920@@ -571,7 +572,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
78921 struct bt_security sec;
78922 struct bt_power pwr;
78923 struct l2cap_conn *conn;
78924- int len, err = 0;
78925+ int err = 0;
78926+ size_t len = optlen;
78927 u32 opt;
78928
78929 BT_DBG("sk %p", sk);
78930@@ -594,7 +596,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
78931
78932 sec.level = BT_SECURITY_LOW;
78933
78934- len = min_t(unsigned int, sizeof(sec), optlen);
78935+ len = min(sizeof(sec), len);
78936 if (copy_from_user((char *) &sec, optval, len)) {
78937 err = -EFAULT;
78938 break;
78939@@ -691,7 +693,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
78940
78941 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
78942
78943- len = min_t(unsigned int, sizeof(pwr), optlen);
78944+ len = min(sizeof(pwr), len);
78945 if (copy_from_user((char *) &pwr, optval, len)) {
78946 err = -EFAULT;
78947 break;
78948diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
78949index b3226f3..8916f43 100644
78950--- a/net/bluetooth/rfcomm/sock.c
78951+++ b/net/bluetooth/rfcomm/sock.c
78952@@ -667,7 +667,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
78953 struct sock *sk = sock->sk;
78954 struct bt_security sec;
78955 int err = 0;
78956- size_t len;
78957+ size_t len = optlen;
78958 u32 opt;
78959
78960 BT_DBG("sk %p", sk);
78961@@ -689,7 +689,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
78962
78963 sec.level = BT_SECURITY_LOW;
78964
78965- len = min_t(unsigned int, sizeof(sec), optlen);
78966+ len = min(sizeof(sec), len);
78967 if (copy_from_user((char *) &sec, optval, len)) {
78968 err = -EFAULT;
78969 break;
78970diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
78971index ccc2487..921073d 100644
78972--- a/net/bluetooth/rfcomm/tty.c
78973+++ b/net/bluetooth/rfcomm/tty.c
78974@@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
78975 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
78976
78977 spin_lock_irqsave(&dev->port.lock, flags);
78978- if (dev->port.count > 0) {
78979+ if (atomic_read(&dev->port.count) > 0) {
78980 spin_unlock_irqrestore(&dev->port.lock, flags);
78981 return;
78982 }
78983@@ -664,10 +664,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
78984 return -ENODEV;
78985
78986 BT_DBG("dev %p dst %s channel %d opened %d", dev, batostr(&dev->dst),
78987- dev->channel, dev->port.count);
78988+ dev->channel, atomic_read(&dev->port.count));
78989
78990 spin_lock_irqsave(&dev->port.lock, flags);
78991- if (++dev->port.count > 1) {
78992+ if (atomic_inc_return(&dev->port.count) > 1) {
78993 spin_unlock_irqrestore(&dev->port.lock, flags);
78994 return 0;
78995 }
78996@@ -732,10 +732,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
78997 return;
78998
78999 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
79000- dev->port.count);
79001+ atomic_read(&dev->port.count));
79002
79003 spin_lock_irqsave(&dev->port.lock, flags);
79004- if (!--dev->port.count) {
79005+ if (!atomic_dec_return(&dev->port.count)) {
79006 spin_unlock_irqrestore(&dev->port.lock, flags);
79007 if (dev->tty_dev->parent)
79008 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
79009diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
79010index 5fe2ff3..121d696 100644
79011--- a/net/bridge/netfilter/ebtables.c
79012+++ b/net/bridge/netfilter/ebtables.c
79013@@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
79014 tmp.valid_hooks = t->table->valid_hooks;
79015 }
79016 mutex_unlock(&ebt_mutex);
79017- if (copy_to_user(user, &tmp, *len) != 0){
79018+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
79019 BUGPRINT("c2u Didn't work\n");
79020 ret = -EFAULT;
79021 break;
79022@@ -2327,7 +2327,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
79023 goto out;
79024 tmp.valid_hooks = t->valid_hooks;
79025
79026- if (copy_to_user(user, &tmp, *len) != 0) {
79027+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
79028 ret = -EFAULT;
79029 break;
79030 }
79031@@ -2338,7 +2338,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
79032 tmp.entries_size = t->table->entries_size;
79033 tmp.valid_hooks = t->table->valid_hooks;
79034
79035- if (copy_to_user(user, &tmp, *len) != 0) {
79036+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
79037 ret = -EFAULT;
79038 break;
79039 }
79040diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
79041index 44f270f..1f5602d 100644
79042--- a/net/caif/cfctrl.c
79043+++ b/net/caif/cfctrl.c
79044@@ -10,6 +10,7 @@
79045 #include <linux/spinlock.h>
79046 #include <linux/slab.h>
79047 #include <linux/pkt_sched.h>
79048+#include <linux/sched.h>
79049 #include <net/caif/caif_layer.h>
79050 #include <net/caif/cfpkt.h>
79051 #include <net/caif/cfctrl.h>
79052@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
79053 memset(&dev_info, 0, sizeof(dev_info));
79054 dev_info.id = 0xff;
79055 cfsrvl_init(&this->serv, 0, &dev_info, false);
79056- atomic_set(&this->req_seq_no, 1);
79057- atomic_set(&this->rsp_seq_no, 1);
79058+ atomic_set_unchecked(&this->req_seq_no, 1);
79059+ atomic_set_unchecked(&this->rsp_seq_no, 1);
79060 this->serv.layer.receive = cfctrl_recv;
79061 sprintf(this->serv.layer.name, "ctrl");
79062 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
79063@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
79064 struct cfctrl_request_info *req)
79065 {
79066 spin_lock_bh(&ctrl->info_list_lock);
79067- atomic_inc(&ctrl->req_seq_no);
79068- req->sequence_no = atomic_read(&ctrl->req_seq_no);
79069+ atomic_inc_unchecked(&ctrl->req_seq_no);
79070+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
79071 list_add_tail(&req->list, &ctrl->list);
79072 spin_unlock_bh(&ctrl->info_list_lock);
79073 }
79074@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
79075 if (p != first)
79076 pr_warn("Requests are not received in order\n");
79077
79078- atomic_set(&ctrl->rsp_seq_no,
79079+ atomic_set_unchecked(&ctrl->rsp_seq_no,
79080 p->sequence_no);
79081 list_del(&p->list);
79082 goto out;
79083diff --git a/net/can/af_can.c b/net/can/af_can.c
79084index ddac1ee..3ee0a78 100644
79085--- a/net/can/af_can.c
79086+++ b/net/can/af_can.c
79087@@ -872,7 +872,7 @@ static const struct net_proto_family can_family_ops = {
79088 };
79089
79090 /* notifier block for netdevice event */
79091-static struct notifier_block can_netdev_notifier __read_mostly = {
79092+static struct notifier_block can_netdev_notifier = {
79093 .notifier_call = can_notifier,
79094 };
79095
79096diff --git a/net/can/bcm.c b/net/can/bcm.c
79097index 969b7cd..f69fccb 100644
79098--- a/net/can/bcm.c
79099+++ b/net/can/bcm.c
79100@@ -119,7 +119,7 @@ struct bcm_sock {
79101 struct sock sk;
79102 int bound;
79103 int ifindex;
79104- struct notifier_block notifier;
79105+ notifier_block_no_const notifier;
79106 struct list_head rx_ops;
79107 struct list_head tx_ops;
79108 unsigned long dropped_usr_msgs;
79109diff --git a/net/can/gw.c b/net/can/gw.c
79110index 1f5c978..30b397f 100644
79111--- a/net/can/gw.c
79112+++ b/net/can/gw.c
79113@@ -67,7 +67,6 @@ MODULE_AUTHOR("Oliver Hartkopp <oliver.hartkopp@volkswagen.de>");
79114 MODULE_ALIAS("can-gw");
79115
79116 static HLIST_HEAD(cgw_list);
79117-static struct notifier_block notifier;
79118
79119 static struct kmem_cache *cgw_cache __read_mostly;
79120
79121@@ -96,7 +95,7 @@ struct cf_mod {
79122 struct {
79123 void (*xor)(struct can_frame *cf, struct cgw_csum_xor *xor);
79124 void (*crc8)(struct can_frame *cf, struct cgw_csum_crc8 *crc8);
79125- } csumfunc;
79126+ } __no_const csumfunc;
79127 };
79128
79129
79130@@ -887,6 +886,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
79131 return err;
79132 }
79133
79134+static struct notifier_block notifier = {
79135+ .notifier_call = cgw_notifier
79136+};
79137+
79138 static __init int cgw_module_init(void)
79139 {
79140 printk(banner);
79141@@ -898,7 +901,6 @@ static __init int cgw_module_init(void)
79142 return -ENOMEM;
79143
79144 /* set notifier */
79145- notifier.notifier_call = cgw_notifier;
79146 register_netdevice_notifier(&notifier);
79147
79148 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
79149diff --git a/net/can/raw.c b/net/can/raw.c
79150index 5b0e3e3..615c72b 100644
79151--- a/net/can/raw.c
79152+++ b/net/can/raw.c
79153@@ -79,7 +79,7 @@ struct raw_sock {
79154 struct sock sk;
79155 int bound;
79156 int ifindex;
79157- struct notifier_block notifier;
79158+ notifier_block_no_const notifier;
79159 int loopback;
79160 int recv_own_msgs;
79161 int fd_frames;
79162diff --git a/net/compat.c b/net/compat.c
79163index 79ae884..17c5c09 100644
79164--- a/net/compat.c
79165+++ b/net/compat.c
79166@@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
79167 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
79168 __get_user(kmsg->msg_flags, &umsg->msg_flags))
79169 return -EFAULT;
79170- kmsg->msg_name = compat_ptr(tmp1);
79171- kmsg->msg_iov = compat_ptr(tmp2);
79172- kmsg->msg_control = compat_ptr(tmp3);
79173+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
79174+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
79175+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
79176 return 0;
79177 }
79178
79179@@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
79180
79181 if (kern_msg->msg_namelen) {
79182 if (mode == VERIFY_READ) {
79183- int err = move_addr_to_kernel(kern_msg->msg_name,
79184+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
79185 kern_msg->msg_namelen,
79186 kern_address);
79187 if (err < 0)
79188@@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
79189 kern_msg->msg_name = NULL;
79190
79191 tot_len = iov_from_user_compat_to_kern(kern_iov,
79192- (struct compat_iovec __user *)kern_msg->msg_iov,
79193+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
79194 kern_msg->msg_iovlen);
79195 if (tot_len >= 0)
79196 kern_msg->msg_iov = kern_iov;
79197@@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
79198
79199 #define CMSG_COMPAT_FIRSTHDR(msg) \
79200 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
79201- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
79202+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
79203 (struct compat_cmsghdr __user *)NULL)
79204
79205 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
79206 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
79207 (ucmlen) <= (unsigned long) \
79208 ((mhdr)->msg_controllen - \
79209- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
79210+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
79211
79212 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
79213 struct compat_cmsghdr __user *cmsg, int cmsg_len)
79214 {
79215 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
79216- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
79217+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
79218 msg->msg_controllen)
79219 return NULL;
79220 return (struct compat_cmsghdr __user *)ptr;
79221@@ -219,7 +219,7 @@ Efault:
79222
79223 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
79224 {
79225- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
79226+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
79227 struct compat_cmsghdr cmhdr;
79228 struct compat_timeval ctv;
79229 struct compat_timespec cts[3];
79230@@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
79231
79232 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
79233 {
79234- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
79235+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
79236 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
79237 int fdnum = scm->fp->count;
79238 struct file **fp = scm->fp->fp;
79239@@ -363,7 +363,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
79240 return -EFAULT;
79241 old_fs = get_fs();
79242 set_fs(KERNEL_DS);
79243- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
79244+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
79245 set_fs(old_fs);
79246
79247 return err;
79248@@ -424,7 +424,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
79249 len = sizeof(ktime);
79250 old_fs = get_fs();
79251 set_fs(KERNEL_DS);
79252- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
79253+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
79254 set_fs(old_fs);
79255
79256 if (!err) {
79257@@ -567,7 +567,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
79258 case MCAST_JOIN_GROUP:
79259 case MCAST_LEAVE_GROUP:
79260 {
79261- struct compat_group_req __user *gr32 = (void *)optval;
79262+ struct compat_group_req __user *gr32 = (void __user *)optval;
79263 struct group_req __user *kgr =
79264 compat_alloc_user_space(sizeof(struct group_req));
79265 u32 interface;
79266@@ -588,7 +588,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
79267 case MCAST_BLOCK_SOURCE:
79268 case MCAST_UNBLOCK_SOURCE:
79269 {
79270- struct compat_group_source_req __user *gsr32 = (void *)optval;
79271+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
79272 struct group_source_req __user *kgsr = compat_alloc_user_space(
79273 sizeof(struct group_source_req));
79274 u32 interface;
79275@@ -609,7 +609,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
79276 }
79277 case MCAST_MSFILTER:
79278 {
79279- struct compat_group_filter __user *gf32 = (void *)optval;
79280+ struct compat_group_filter __user *gf32 = (void __user *)optval;
79281 struct group_filter __user *kgf;
79282 u32 interface, fmode, numsrc;
79283
79284@@ -647,7 +647,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
79285 char __user *optval, int __user *optlen,
79286 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
79287 {
79288- struct compat_group_filter __user *gf32 = (void *)optval;
79289+ struct compat_group_filter __user *gf32 = (void __user *)optval;
79290 struct group_filter __user *kgf;
79291 int __user *koptlen;
79292 u32 interface, fmode, numsrc;
79293@@ -796,7 +796,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
79294
79295 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
79296 return -EINVAL;
79297- if (copy_from_user(a, args, nas[call]))
79298+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
79299 return -EFAULT;
79300 a0 = a[0];
79301 a1 = a[1];
79302diff --git a/net/core/datagram.c b/net/core/datagram.c
79303index 0337e2b..47914a0 100644
79304--- a/net/core/datagram.c
79305+++ b/net/core/datagram.c
79306@@ -289,7 +289,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
79307 }
79308
79309 kfree_skb(skb);
79310- atomic_inc(&sk->sk_drops);
79311+ atomic_inc_unchecked(&sk->sk_drops);
79312 sk_mem_reclaim_partial(sk);
79313
79314 return err;
79315diff --git a/net/core/dev.c b/net/core/dev.c
79316index e5942bf..25998c3 100644
79317--- a/net/core/dev.c
79318+++ b/net/core/dev.c
79319@@ -1162,9 +1162,13 @@ void dev_load(struct net *net, const char *name)
79320 if (no_module && capable(CAP_NET_ADMIN))
79321 no_module = request_module("netdev-%s", name);
79322 if (no_module && capable(CAP_SYS_MODULE)) {
79323+#ifdef CONFIG_GRKERNSEC_MODHARDEN
79324+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
79325+#else
79326 if (!request_module("%s", name))
79327 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
79328 name);
79329+#endif
79330 }
79331 }
79332 EXPORT_SYMBOL(dev_load);
79333@@ -1627,7 +1631,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
79334 {
79335 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
79336 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
79337- atomic_long_inc(&dev->rx_dropped);
79338+ atomic_long_inc_unchecked(&dev->rx_dropped);
79339 kfree_skb(skb);
79340 return NET_RX_DROP;
79341 }
79342@@ -1637,7 +1641,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
79343 nf_reset(skb);
79344
79345 if (unlikely(!is_skb_forwardable(dev, skb))) {
79346- atomic_long_inc(&dev->rx_dropped);
79347+ atomic_long_inc_unchecked(&dev->rx_dropped);
79348 kfree_skb(skb);
79349 return NET_RX_DROP;
79350 }
79351@@ -2093,7 +2097,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
79352
79353 struct dev_gso_cb {
79354 void (*destructor)(struct sk_buff *skb);
79355-};
79356+} __no_const;
79357
79358 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
79359
79360@@ -2955,7 +2959,7 @@ enqueue:
79361
79362 local_irq_restore(flags);
79363
79364- atomic_long_inc(&skb->dev->rx_dropped);
79365+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
79366 kfree_skb(skb);
79367 return NET_RX_DROP;
79368 }
79369@@ -3027,7 +3031,7 @@ int netif_rx_ni(struct sk_buff *skb)
79370 }
79371 EXPORT_SYMBOL(netif_rx_ni);
79372
79373-static void net_tx_action(struct softirq_action *h)
79374+static void net_tx_action(void)
79375 {
79376 struct softnet_data *sd = &__get_cpu_var(softnet_data);
79377
79378@@ -3358,7 +3362,7 @@ ncls:
79379 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
79380 } else {
79381 drop:
79382- atomic_long_inc(&skb->dev->rx_dropped);
79383+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
79384 kfree_skb(skb);
79385 /* Jamal, now you will not able to escape explaining
79386 * me how you were going to use this. :-)
79387@@ -3944,7 +3948,7 @@ void netif_napi_del(struct napi_struct *napi)
79388 }
79389 EXPORT_SYMBOL(netif_napi_del);
79390
79391-static void net_rx_action(struct softirq_action *h)
79392+static void net_rx_action(void)
79393 {
79394 struct softnet_data *sd = &__get_cpu_var(softnet_data);
79395 unsigned long time_limit = jiffies + 2;
79396@@ -4423,8 +4427,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
79397 else
79398 seq_printf(seq, "%04x", ntohs(pt->type));
79399
79400+#ifdef CONFIG_GRKERNSEC_HIDESYM
79401+ seq_printf(seq, " %-8s %p\n",
79402+ pt->dev ? pt->dev->name : "", NULL);
79403+#else
79404 seq_printf(seq, " %-8s %pF\n",
79405 pt->dev ? pt->dev->name : "", pt->func);
79406+#endif
79407 }
79408
79409 return 0;
79410@@ -5987,7 +5996,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
79411 } else {
79412 netdev_stats_to_stats64(storage, &dev->stats);
79413 }
79414- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
79415+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
79416 return storage;
79417 }
79418 EXPORT_SYMBOL(dev_get_stats);
79419diff --git a/net/core/flow.c b/net/core/flow.c
79420index e318c7e..98aee7d 100644
79421--- a/net/core/flow.c
79422+++ b/net/core/flow.c
79423@@ -55,13 +55,13 @@ struct flow_flush_info {
79424 struct flow_cache {
79425 u32 hash_shift;
79426 struct flow_cache_percpu __percpu *percpu;
79427- struct notifier_block hotcpu_notifier;
79428+ notifier_block_no_const hotcpu_notifier;
79429 int low_watermark;
79430 int high_watermark;
79431 struct timer_list rnd_timer;
79432 };
79433
79434-atomic_t flow_cache_genid = ATOMIC_INIT(0);
79435+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
79436 EXPORT_SYMBOL(flow_cache_genid);
79437 static struct flow_cache flow_cache_global;
79438 static struct kmem_cache *flow_cachep __read_mostly;
79439@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
79440
79441 static int flow_entry_valid(struct flow_cache_entry *fle)
79442 {
79443- if (atomic_read(&flow_cache_genid) != fle->genid)
79444+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
79445 return 0;
79446 if (fle->object && !fle->object->ops->check(fle->object))
79447 return 0;
79448@@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
79449 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
79450 fcp->hash_count++;
79451 }
79452- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
79453+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
79454 flo = fle->object;
79455 if (!flo)
79456 goto ret_object;
79457@@ -280,7 +280,7 @@ nocache:
79458 }
79459 flo = resolver(net, key, family, dir, flo, ctx);
79460 if (fle) {
79461- fle->genid = atomic_read(&flow_cache_genid);
79462+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
79463 if (!IS_ERR(flo))
79464 fle->object = flo;
79465 else
79466diff --git a/net/core/iovec.c b/net/core/iovec.c
79467index 7e7aeb0..2a998cb 100644
79468--- a/net/core/iovec.c
79469+++ b/net/core/iovec.c
79470@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
79471 if (m->msg_namelen) {
79472 if (mode == VERIFY_READ) {
79473 void __user *namep;
79474- namep = (void __user __force *) m->msg_name;
79475+ namep = (void __force_user *) m->msg_name;
79476 err = move_addr_to_kernel(namep, m->msg_namelen,
79477 address);
79478 if (err < 0)
79479@@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
79480 }
79481
79482 size = m->msg_iovlen * sizeof(struct iovec);
79483- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
79484+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
79485 return -EFAULT;
79486
79487 m->msg_iov = iov;
79488diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
79489index fad649a..df5891e 100644
79490--- a/net/core/rtnetlink.c
79491+++ b/net/core/rtnetlink.c
79492@@ -58,7 +58,7 @@ struct rtnl_link {
79493 rtnl_doit_func doit;
79494 rtnl_dumpit_func dumpit;
79495 rtnl_calcit_func calcit;
79496-};
79497+} __no_const;
79498
79499 static DEFINE_MUTEX(rtnl_mutex);
79500
79501diff --git a/net/core/scm.c b/net/core/scm.c
79502index ab57084..0190c8f 100644
79503--- a/net/core/scm.c
79504+++ b/net/core/scm.c
79505@@ -223,7 +223,7 @@ EXPORT_SYMBOL(__scm_send);
79506 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
79507 {
79508 struct cmsghdr __user *cm
79509- = (__force struct cmsghdr __user *)msg->msg_control;
79510+ = (struct cmsghdr __force_user *)msg->msg_control;
79511 struct cmsghdr cmhdr;
79512 int cmlen = CMSG_LEN(len);
79513 int err;
79514@@ -246,7 +246,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
79515 err = -EFAULT;
79516 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
79517 goto out;
79518- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
79519+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
79520 goto out;
79521 cmlen = CMSG_SPACE(len);
79522 if (msg->msg_controllen < cmlen)
79523@@ -262,7 +262,7 @@ EXPORT_SYMBOL(put_cmsg);
79524 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
79525 {
79526 struct cmsghdr __user *cm
79527- = (__force struct cmsghdr __user*)msg->msg_control;
79528+ = (struct cmsghdr __force_user *)msg->msg_control;
79529
79530 int fdmax = 0;
79531 int fdnum = scm->fp->count;
79532@@ -282,7 +282,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
79533 if (fdnum < fdmax)
79534 fdmax = fdnum;
79535
79536- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
79537+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
79538 i++, cmfptr++)
79539 {
79540 struct socket *sock;
79541diff --git a/net/core/sock.c b/net/core/sock.c
79542index 8a146cf..ee08914d 100644
79543--- a/net/core/sock.c
79544+++ b/net/core/sock.c
79545@@ -388,7 +388,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
79546 struct sk_buff_head *list = &sk->sk_receive_queue;
79547
79548 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
79549- atomic_inc(&sk->sk_drops);
79550+ atomic_inc_unchecked(&sk->sk_drops);
79551 trace_sock_rcvqueue_full(sk, skb);
79552 return -ENOMEM;
79553 }
79554@@ -398,7 +398,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
79555 return err;
79556
79557 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
79558- atomic_inc(&sk->sk_drops);
79559+ atomic_inc_unchecked(&sk->sk_drops);
79560 return -ENOBUFS;
79561 }
79562
79563@@ -418,7 +418,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
79564 skb_dst_force(skb);
79565
79566 spin_lock_irqsave(&list->lock, flags);
79567- skb->dropcount = atomic_read(&sk->sk_drops);
79568+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
79569 __skb_queue_tail(list, skb);
79570 spin_unlock_irqrestore(&list->lock, flags);
79571
79572@@ -438,7 +438,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
79573 skb->dev = NULL;
79574
79575 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
79576- atomic_inc(&sk->sk_drops);
79577+ atomic_inc_unchecked(&sk->sk_drops);
79578 goto discard_and_relse;
79579 }
79580 if (nested)
79581@@ -456,7 +456,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
79582 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
79583 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
79584 bh_unlock_sock(sk);
79585- atomic_inc(&sk->sk_drops);
79586+ atomic_inc_unchecked(&sk->sk_drops);
79587 goto discard_and_relse;
79588 }
79589
79590@@ -875,12 +875,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
79591 struct timeval tm;
79592 } v;
79593
79594- int lv = sizeof(int);
79595- int len;
79596+ unsigned int lv = sizeof(int);
79597+ unsigned int len;
79598
79599 if (get_user(len, optlen))
79600 return -EFAULT;
79601- if (len < 0)
79602+ if (len > INT_MAX)
79603 return -EINVAL;
79604
79605 memset(&v, 0, sizeof(v));
79606@@ -1028,11 +1028,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
79607
79608 case SO_PEERNAME:
79609 {
79610- char address[128];
79611+ char address[_K_SS_MAXSIZE];
79612
79613 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
79614 return -ENOTCONN;
79615- if (lv < len)
79616+ if (lv < len || sizeof address < len)
79617 return -EINVAL;
79618 if (copy_to_user(optval, address, len))
79619 return -EFAULT;
79620@@ -1080,7 +1080,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
79621
79622 if (len > lv)
79623 len = lv;
79624- if (copy_to_user(optval, &v, len))
79625+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
79626 return -EFAULT;
79627 lenout:
79628 if (put_user(len, optlen))
79629@@ -2212,7 +2212,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
79630 */
79631 smp_wmb();
79632 atomic_set(&sk->sk_refcnt, 1);
79633- atomic_set(&sk->sk_drops, 0);
79634+ atomic_set_unchecked(&sk->sk_drops, 0);
79635 }
79636 EXPORT_SYMBOL(sock_init_data);
79637
79638diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
79639index 602cd63..05c6c60 100644
79640--- a/net/core/sock_diag.c
79641+++ b/net/core/sock_diag.c
79642@@ -15,20 +15,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
79643
79644 int sock_diag_check_cookie(void *sk, __u32 *cookie)
79645 {
79646+#ifndef CONFIG_GRKERNSEC_HIDESYM
79647 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
79648 cookie[1] != INET_DIAG_NOCOOKIE) &&
79649 ((u32)(unsigned long)sk != cookie[0] ||
79650 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
79651 return -ESTALE;
79652 else
79653+#endif
79654 return 0;
79655 }
79656 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
79657
79658 void sock_diag_save_cookie(void *sk, __u32 *cookie)
79659 {
79660+#ifdef CONFIG_GRKERNSEC_HIDESYM
79661+ cookie[0] = 0;
79662+ cookie[1] = 0;
79663+#else
79664 cookie[0] = (u32)(unsigned long)sk;
79665 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
79666+#endif
79667 }
79668 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
79669
79670diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
79671index a55eecc..dd8428c 100644
79672--- a/net/decnet/sysctl_net_decnet.c
79673+++ b/net/decnet/sysctl_net_decnet.c
79674@@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
79675
79676 if (len > *lenp) len = *lenp;
79677
79678- if (copy_to_user(buffer, addr, len))
79679+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
79680 return -EFAULT;
79681
79682 *lenp = len;
79683@@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
79684
79685 if (len > *lenp) len = *lenp;
79686
79687- if (copy_to_user(buffer, devname, len))
79688+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
79689 return -EFAULT;
79690
79691 *lenp = len;
79692diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
79693index 825c608..750ff29 100644
79694--- a/net/ipv4/fib_frontend.c
79695+++ b/net/ipv4/fib_frontend.c
79696@@ -1020,12 +1020,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
79697 #ifdef CONFIG_IP_ROUTE_MULTIPATH
79698 fib_sync_up(dev);
79699 #endif
79700- atomic_inc(&net->ipv4.dev_addr_genid);
79701+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
79702 rt_cache_flush(dev_net(dev));
79703 break;
79704 case NETDEV_DOWN:
79705 fib_del_ifaddr(ifa, NULL);
79706- atomic_inc(&net->ipv4.dev_addr_genid);
79707+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
79708 if (ifa->ifa_dev->ifa_list == NULL) {
79709 /* Last address was deleted from this interface.
79710 * Disable IP.
79711@@ -1061,7 +1061,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
79712 #ifdef CONFIG_IP_ROUTE_MULTIPATH
79713 fib_sync_up(dev);
79714 #endif
79715- atomic_inc(&net->ipv4.dev_addr_genid);
79716+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
79717 rt_cache_flush(net);
79718 break;
79719 case NETDEV_DOWN:
79720diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
79721index 71b125c..f4c70b0 100644
79722--- a/net/ipv4/fib_semantics.c
79723+++ b/net/ipv4/fib_semantics.c
79724@@ -767,7 +767,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
79725 nh->nh_saddr = inet_select_addr(nh->nh_dev,
79726 nh->nh_gw,
79727 nh->nh_parent->fib_scope);
79728- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
79729+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
79730
79731 return nh->nh_saddr;
79732 }
79733diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
79734index 7880af9..70f92a3 100644
79735--- a/net/ipv4/inet_hashtables.c
79736+++ b/net/ipv4/inet_hashtables.c
79737@@ -18,12 +18,15 @@
79738 #include <linux/sched.h>
79739 #include <linux/slab.h>
79740 #include <linux/wait.h>
79741+#include <linux/security.h>
79742
79743 #include <net/inet_connection_sock.h>
79744 #include <net/inet_hashtables.h>
79745 #include <net/secure_seq.h>
79746 #include <net/ip.h>
79747
79748+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
79749+
79750 /*
79751 * Allocate and initialize a new local port bind bucket.
79752 * The bindhash mutex for snum's hash chain must be held here.
79753@@ -530,6 +533,8 @@ ok:
79754 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
79755 spin_unlock(&head->lock);
79756
79757+ gr_update_task_in_ip_table(current, inet_sk(sk));
79758+
79759 if (tw) {
79760 inet_twsk_deschedule(tw, death_row);
79761 while (twrefcnt) {
79762diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
79763index 000e3d2..5472da3 100644
79764--- a/net/ipv4/inetpeer.c
79765+++ b/net/ipv4/inetpeer.c
79766@@ -503,8 +503,8 @@ relookup:
79767 if (p) {
79768 p->daddr = *daddr;
79769 atomic_set(&p->refcnt, 1);
79770- atomic_set(&p->rid, 0);
79771- atomic_set(&p->ip_id_count,
79772+ atomic_set_unchecked(&p->rid, 0);
79773+ atomic_set_unchecked(&p->ip_id_count,
79774 (daddr->family == AF_INET) ?
79775 secure_ip_id(daddr->addr.a4) :
79776 secure_ipv6_id(daddr->addr.a6));
79777diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
79778index 8d5cc75..821fd11 100644
79779--- a/net/ipv4/ip_fragment.c
79780+++ b/net/ipv4/ip_fragment.c
79781@@ -322,7 +322,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
79782 return 0;
79783
79784 start = qp->rid;
79785- end = atomic_inc_return(&peer->rid);
79786+ end = atomic_inc_return_unchecked(&peer->rid);
79787 qp->rid = end;
79788
79789 rc = qp->q.fragments && (end - start) > max;
79790diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
79791index 14bbfcf..644f472 100644
79792--- a/net/ipv4/ip_sockglue.c
79793+++ b/net/ipv4/ip_sockglue.c
79794@@ -1151,7 +1151,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
79795 len = min_t(unsigned int, len, opt->optlen);
79796 if (put_user(len, optlen))
79797 return -EFAULT;
79798- if (copy_to_user(optval, opt->__data, len))
79799+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
79800+ copy_to_user(optval, opt->__data, len))
79801 return -EFAULT;
79802 return 0;
79803 }
79804@@ -1282,7 +1283,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
79805 if (sk->sk_type != SOCK_STREAM)
79806 return -ENOPROTOOPT;
79807
79808- msg.msg_control = optval;
79809+ msg.msg_control = (void __force_kernel *)optval;
79810 msg.msg_controllen = len;
79811 msg.msg_flags = flags;
79812
79813diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
79814index 798358b..73570b7 100644
79815--- a/net/ipv4/ipconfig.c
79816+++ b/net/ipv4/ipconfig.c
79817@@ -321,7 +321,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
79818
79819 mm_segment_t oldfs = get_fs();
79820 set_fs(get_ds());
79821- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
79822+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
79823 set_fs(oldfs);
79824 return res;
79825 }
79826@@ -332,7 +332,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
79827
79828 mm_segment_t oldfs = get_fs();
79829 set_fs(get_ds());
79830- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
79831+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
79832 set_fs(oldfs);
79833 return res;
79834 }
79835@@ -343,7 +343,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
79836
79837 mm_segment_t oldfs = get_fs();
79838 set_fs(get_ds());
79839- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
79840+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
79841 set_fs(oldfs);
79842 return res;
79843 }
79844diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
79845index 97e61ea..cac1bbb 100644
79846--- a/net/ipv4/netfilter/arp_tables.c
79847+++ b/net/ipv4/netfilter/arp_tables.c
79848@@ -879,14 +879,14 @@ static int compat_table_info(const struct xt_table_info *info,
79849 #endif
79850
79851 static int get_info(struct net *net, void __user *user,
79852- const int *len, int compat)
79853+ int len, int compat)
79854 {
79855 char name[XT_TABLE_MAXNAMELEN];
79856 struct xt_table *t;
79857 int ret;
79858
79859- if (*len != sizeof(struct arpt_getinfo)) {
79860- duprintf("length %u != %Zu\n", *len,
79861+ if (len != sizeof(struct arpt_getinfo)) {
79862+ duprintf("length %u != %Zu\n", len,
79863 sizeof(struct arpt_getinfo));
79864 return -EINVAL;
79865 }
79866@@ -923,7 +923,7 @@ static int get_info(struct net *net, void __user *user,
79867 info.size = private->size;
79868 strcpy(info.name, name);
79869
79870- if (copy_to_user(user, &info, *len) != 0)
79871+ if (copy_to_user(user, &info, len) != 0)
79872 ret = -EFAULT;
79873 else
79874 ret = 0;
79875@@ -1682,7 +1682,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
79876
79877 switch (cmd) {
79878 case ARPT_SO_GET_INFO:
79879- ret = get_info(sock_net(sk), user, len, 1);
79880+ ret = get_info(sock_net(sk), user, *len, 1);
79881 break;
79882 case ARPT_SO_GET_ENTRIES:
79883 ret = compat_get_entries(sock_net(sk), user, len);
79884@@ -1727,7 +1727,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
79885
79886 switch (cmd) {
79887 case ARPT_SO_GET_INFO:
79888- ret = get_info(sock_net(sk), user, len, 0);
79889+ ret = get_info(sock_net(sk), user, *len, 0);
79890 break;
79891
79892 case ARPT_SO_GET_ENTRIES:
79893diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
79894index 170b1fd..6105b91 100644
79895--- a/net/ipv4/netfilter/ip_tables.c
79896+++ b/net/ipv4/netfilter/ip_tables.c
79897@@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
79898 #endif
79899
79900 static int get_info(struct net *net, void __user *user,
79901- const int *len, int compat)
79902+ int len, int compat)
79903 {
79904 char name[XT_TABLE_MAXNAMELEN];
79905 struct xt_table *t;
79906 int ret;
79907
79908- if (*len != sizeof(struct ipt_getinfo)) {
79909- duprintf("length %u != %zu\n", *len,
79910+ if (len != sizeof(struct ipt_getinfo)) {
79911+ duprintf("length %u != %zu\n", len,
79912 sizeof(struct ipt_getinfo));
79913 return -EINVAL;
79914 }
79915@@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
79916 info.size = private->size;
79917 strcpy(info.name, name);
79918
79919- if (copy_to_user(user, &info, *len) != 0)
79920+ if (copy_to_user(user, &info, len) != 0)
79921 ret = -EFAULT;
79922 else
79923 ret = 0;
79924@@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
79925
79926 switch (cmd) {
79927 case IPT_SO_GET_INFO:
79928- ret = get_info(sock_net(sk), user, len, 1);
79929+ ret = get_info(sock_net(sk), user, *len, 1);
79930 break;
79931 case IPT_SO_GET_ENTRIES:
79932 ret = compat_get_entries(sock_net(sk), user, len);
79933@@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
79934
79935 switch (cmd) {
79936 case IPT_SO_GET_INFO:
79937- ret = get_info(sock_net(sk), user, len, 0);
79938+ ret = get_info(sock_net(sk), user, *len, 0);
79939 break;
79940
79941 case IPT_SO_GET_ENTRIES:
79942diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
79943index 8f3d054..c58d05d 100644
79944--- a/net/ipv4/ping.c
79945+++ b/net/ipv4/ping.c
79946@@ -843,7 +843,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
79947 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
79948 0, sock_i_ino(sp),
79949 atomic_read(&sp->sk_refcnt), sp,
79950- atomic_read(&sp->sk_drops), len);
79951+ atomic_read_unchecked(&sp->sk_drops), len);
79952 }
79953
79954 static int ping_seq_show(struct seq_file *seq, void *v)
79955diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
79956index 73d1e4d..3af0e8f 100644
79957--- a/net/ipv4/raw.c
79958+++ b/net/ipv4/raw.c
79959@@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
79960 int raw_rcv(struct sock *sk, struct sk_buff *skb)
79961 {
79962 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
79963- atomic_inc(&sk->sk_drops);
79964+ atomic_inc_unchecked(&sk->sk_drops);
79965 kfree_skb(skb);
79966 return NET_RX_DROP;
79967 }
79968@@ -747,16 +747,20 @@ static int raw_init(struct sock *sk)
79969
79970 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
79971 {
79972+ struct icmp_filter filter;
79973+
79974 if (optlen > sizeof(struct icmp_filter))
79975 optlen = sizeof(struct icmp_filter);
79976- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
79977+ if (copy_from_user(&filter, optval, optlen))
79978 return -EFAULT;
79979+ raw_sk(sk)->filter = filter;
79980 return 0;
79981 }
79982
79983 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
79984 {
79985 int len, ret = -EFAULT;
79986+ struct icmp_filter filter;
79987
79988 if (get_user(len, optlen))
79989 goto out;
79990@@ -766,8 +770,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
79991 if (len > sizeof(struct icmp_filter))
79992 len = sizeof(struct icmp_filter);
79993 ret = -EFAULT;
79994- if (put_user(len, optlen) ||
79995- copy_to_user(optval, &raw_sk(sk)->filter, len))
79996+ filter = raw_sk(sk)->filter;
79997+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
79998 goto out;
79999 ret = 0;
80000 out: return ret;
80001@@ -997,7 +1001,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
80002 0, 0L, 0,
80003 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
80004 0, sock_i_ino(sp),
80005- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
80006+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
80007 }
80008
80009 static int raw_seq_show(struct seq_file *seq, void *v)
80010diff --git a/net/ipv4/route.c b/net/ipv4/route.c
80011index df25142..e92a82a 100644
80012--- a/net/ipv4/route.c
80013+++ b/net/ipv4/route.c
80014@@ -2529,7 +2529,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
80015
80016 static __net_init int rt_genid_init(struct net *net)
80017 {
80018- atomic_set(&net->rt_genid, 0);
80019+ atomic_set_unchecked(&net->rt_genid, 0);
80020 get_random_bytes(&net->ipv4.dev_addr_genid,
80021 sizeof(net->ipv4.dev_addr_genid));
80022 return 0;
80023diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
80024index 181fc82..f211869 100644
80025--- a/net/ipv4/tcp_input.c
80026+++ b/net/ipv4/tcp_input.c
80027@@ -4704,7 +4704,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
80028 * simplifies code)
80029 */
80030 static void
80031-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
80032+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
80033 struct sk_buff *head, struct sk_buff *tail,
80034 u32 start, u32 end)
80035 {
80036@@ -5536,6 +5536,9 @@ slow_path:
80037 if (len < (th->doff << 2) || tcp_checksum_complete_user(sk, skb))
80038 goto csum_error;
80039
80040+ if (!th->ack)
80041+ goto discard;
80042+
80043 /*
80044 * Standard slow path.
80045 */
80046@@ -5544,7 +5547,7 @@ slow_path:
80047 return 0;
80048
80049 step5:
80050- if (th->ack && tcp_ack(sk, skb, FLAG_SLOWPATH) < 0)
80051+ if (tcp_ack(sk, skb, FLAG_SLOWPATH) < 0)
80052 goto discard;
80053
80054 /* ts_recent update must be made after we are sure that the packet
80055@@ -5930,7 +5933,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
80056 goto discard;
80057
80058 if (th->syn) {
80059- if (th->fin)
80060+ if (th->fin || th->urg || th->psh)
80061 goto discard;
80062 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
80063 return 1;
80064@@ -5977,11 +5980,15 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
80065 if (tcp_check_req(sk, skb, req, NULL, true) == NULL)
80066 goto discard;
80067 }
80068+
80069+ if (!th->ack)
80070+ goto discard;
80071+
80072 if (!tcp_validate_incoming(sk, skb, th, 0))
80073 return 0;
80074
80075 /* step 5: check the ACK field */
80076- if (th->ack) {
80077+ if (true) {
80078 int acceptable = tcp_ack(sk, skb, FLAG_SLOWPATH) > 0;
80079
80080 switch (sk->sk_state) {
80081@@ -6131,8 +6138,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
80082 }
80083 break;
80084 }
80085- } else
80086- goto discard;
80087+ }
80088
80089 /* ts_recent update must be made after we are sure that the packet
80090 * is in window.
80091diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
80092index 0c4a643..e584990 100644
80093--- a/net/ipv4/tcp_ipv4.c
80094+++ b/net/ipv4/tcp_ipv4.c
80095@@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
80096 EXPORT_SYMBOL(sysctl_tcp_low_latency);
80097
80098
80099+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80100+extern int grsec_enable_blackhole;
80101+#endif
80102+
80103 #ifdef CONFIG_TCP_MD5SIG
80104 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
80105 __be32 daddr, __be32 saddr, const struct tcphdr *th);
80106@@ -1901,6 +1905,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
80107 return 0;
80108
80109 reset:
80110+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80111+ if (!grsec_enable_blackhole)
80112+#endif
80113 tcp_v4_send_reset(rsk, skb);
80114 discard:
80115 kfree_skb(skb);
80116@@ -2001,12 +2008,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
80117 TCP_SKB_CB(skb)->sacked = 0;
80118
80119 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
80120- if (!sk)
80121+ if (!sk) {
80122+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80123+ ret = 1;
80124+#endif
80125 goto no_tcp_socket;
80126-
80127+ }
80128 process:
80129- if (sk->sk_state == TCP_TIME_WAIT)
80130+ if (sk->sk_state == TCP_TIME_WAIT) {
80131+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80132+ ret = 2;
80133+#endif
80134 goto do_time_wait;
80135+ }
80136
80137 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
80138 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
80139@@ -2057,6 +2071,10 @@ no_tcp_socket:
80140 bad_packet:
80141 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
80142 } else {
80143+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80144+ if (!grsec_enable_blackhole || (ret == 1 &&
80145+ (skb->dev->flags & IFF_LOOPBACK)))
80146+#endif
80147 tcp_v4_send_reset(NULL, skb);
80148 }
80149
80150diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
80151index a7302d9..e3ec754 100644
80152--- a/net/ipv4/tcp_minisocks.c
80153+++ b/net/ipv4/tcp_minisocks.c
80154@@ -27,6 +27,10 @@
80155 #include <net/inet_common.h>
80156 #include <net/xfrm.h>
80157
80158+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80159+extern int grsec_enable_blackhole;
80160+#endif
80161+
80162 int sysctl_tcp_syncookies __read_mostly = 1;
80163 EXPORT_SYMBOL(sysctl_tcp_syncookies);
80164
80165@@ -742,7 +746,10 @@ embryonic_reset:
80166 * avoid becoming vulnerable to outside attack aiming at
80167 * resetting legit local connections.
80168 */
80169- req->rsk_ops->send_reset(sk, skb);
80170+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80171+ if (!grsec_enable_blackhole)
80172+#endif
80173+ req->rsk_ops->send_reset(sk, skb);
80174 } else if (fastopen) { /* received a valid RST pkt */
80175 reqsk_fastopen_remove(sk, req, true);
80176 tcp_reset(sk);
80177diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
80178index 4526fe6..1a34e43 100644
80179--- a/net/ipv4/tcp_probe.c
80180+++ b/net/ipv4/tcp_probe.c
80181@@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
80182 if (cnt + width >= len)
80183 break;
80184
80185- if (copy_to_user(buf + cnt, tbuf, width))
80186+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
80187 return -EFAULT;
80188 cnt += width;
80189 }
80190diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
80191index d47c1b4..b0584de 100644
80192--- a/net/ipv4/tcp_timer.c
80193+++ b/net/ipv4/tcp_timer.c
80194@@ -22,6 +22,10 @@
80195 #include <linux/gfp.h>
80196 #include <net/tcp.h>
80197
80198+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80199+extern int grsec_lastack_retries;
80200+#endif
80201+
80202 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
80203 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
80204 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
80205@@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
80206 }
80207 }
80208
80209+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80210+ if ((sk->sk_state == TCP_LAST_ACK) &&
80211+ (grsec_lastack_retries > 0) &&
80212+ (grsec_lastack_retries < retry_until))
80213+ retry_until = grsec_lastack_retries;
80214+#endif
80215+
80216 if (retransmits_timed_out(sk, retry_until,
80217 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
80218 /* Has it gone just too far? */
80219diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
80220index 79c8dbe..aceb1b6 100644
80221--- a/net/ipv4/udp.c
80222+++ b/net/ipv4/udp.c
80223@@ -87,6 +87,7 @@
80224 #include <linux/types.h>
80225 #include <linux/fcntl.h>
80226 #include <linux/module.h>
80227+#include <linux/security.h>
80228 #include <linux/socket.h>
80229 #include <linux/sockios.h>
80230 #include <linux/igmp.h>
80231@@ -111,6 +112,10 @@
80232 #include <trace/events/skb.h>
80233 #include "udp_impl.h"
80234
80235+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80236+extern int grsec_enable_blackhole;
80237+#endif
80238+
80239 struct udp_table udp_table __read_mostly;
80240 EXPORT_SYMBOL(udp_table);
80241
80242@@ -569,6 +574,9 @@ found:
80243 return s;
80244 }
80245
80246+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
80247+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
80248+
80249 /*
80250 * This routine is called by the ICMP module when it gets some
80251 * sort of error condition. If err < 0 then the socket should
80252@@ -864,9 +872,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
80253 dport = usin->sin_port;
80254 if (dport == 0)
80255 return -EINVAL;
80256+
80257+ err = gr_search_udp_sendmsg(sk, usin);
80258+ if (err)
80259+ return err;
80260 } else {
80261 if (sk->sk_state != TCP_ESTABLISHED)
80262 return -EDESTADDRREQ;
80263+
80264+ err = gr_search_udp_sendmsg(sk, NULL);
80265+ if (err)
80266+ return err;
80267+
80268 daddr = inet->inet_daddr;
80269 dport = inet->inet_dport;
80270 /* Open fast path for connected socket.
80271@@ -1108,7 +1125,7 @@ static unsigned int first_packet_length(struct sock *sk)
80272 udp_lib_checksum_complete(skb)) {
80273 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
80274 IS_UDPLITE(sk));
80275- atomic_inc(&sk->sk_drops);
80276+ atomic_inc_unchecked(&sk->sk_drops);
80277 __skb_unlink(skb, rcvq);
80278 __skb_queue_tail(&list_kill, skb);
80279 }
80280@@ -1194,6 +1211,10 @@ try_again:
80281 if (!skb)
80282 goto out;
80283
80284+ err = gr_search_udp_recvmsg(sk, skb);
80285+ if (err)
80286+ goto out_free;
80287+
80288 ulen = skb->len - sizeof(struct udphdr);
80289 copied = len;
80290 if (copied > ulen)
80291@@ -1227,7 +1248,7 @@ try_again:
80292 if (unlikely(err)) {
80293 trace_kfree_skb(skb, udp_recvmsg);
80294 if (!peeked) {
80295- atomic_inc(&sk->sk_drops);
80296+ atomic_inc_unchecked(&sk->sk_drops);
80297 UDP_INC_STATS_USER(sock_net(sk),
80298 UDP_MIB_INERRORS, is_udplite);
80299 }
80300@@ -1510,7 +1531,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
80301
80302 drop:
80303 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
80304- atomic_inc(&sk->sk_drops);
80305+ atomic_inc_unchecked(&sk->sk_drops);
80306 kfree_skb(skb);
80307 return -1;
80308 }
80309@@ -1529,7 +1550,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
80310 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
80311
80312 if (!skb1) {
80313- atomic_inc(&sk->sk_drops);
80314+ atomic_inc_unchecked(&sk->sk_drops);
80315 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
80316 IS_UDPLITE(sk));
80317 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
80318@@ -1698,6 +1719,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
80319 goto csum_error;
80320
80321 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
80322+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80323+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
80324+#endif
80325 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
80326
80327 /*
80328@@ -2119,7 +2143,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
80329 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
80330 0, sock_i_ino(sp),
80331 atomic_read(&sp->sk_refcnt), sp,
80332- atomic_read(&sp->sk_drops), len);
80333+ atomic_read_unchecked(&sp->sk_drops), len);
80334 }
80335
80336 int udp4_seq_show(struct seq_file *seq, void *v)
80337diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
80338index 0424e4e..308dd43 100644
80339--- a/net/ipv6/addrconf.c
80340+++ b/net/ipv6/addrconf.c
80341@@ -2121,7 +2121,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
80342 p.iph.ihl = 5;
80343 p.iph.protocol = IPPROTO_IPV6;
80344 p.iph.ttl = 64;
80345- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
80346+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
80347
80348 if (ops->ndo_do_ioctl) {
80349 mm_segment_t oldfs = get_fs();
80350diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
80351index d5cb3c4..b3e38d0 100644
80352--- a/net/ipv6/ip6_gre.c
80353+++ b/net/ipv6/ip6_gre.c
80354@@ -1353,7 +1353,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
80355 }
80356
80357
80358-static struct inet6_protocol ip6gre_protocol __read_mostly = {
80359+static struct inet6_protocol ip6gre_protocol = {
80360 .handler = ip6gre_rcv,
80361 .err_handler = ip6gre_err,
80362 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
80363diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
80364index e02faed..9780f28 100644
80365--- a/net/ipv6/ipv6_sockglue.c
80366+++ b/net/ipv6/ipv6_sockglue.c
80367@@ -990,7 +990,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
80368 if (sk->sk_type != SOCK_STREAM)
80369 return -ENOPROTOOPT;
80370
80371- msg.msg_control = optval;
80372+ msg.msg_control = (void __force_kernel *)optval;
80373 msg.msg_controllen = len;
80374 msg.msg_flags = flags;
80375
80376diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
80377index d7cb045..8c0ded6 100644
80378--- a/net/ipv6/netfilter/ip6_tables.c
80379+++ b/net/ipv6/netfilter/ip6_tables.c
80380@@ -1078,14 +1078,14 @@ static int compat_table_info(const struct xt_table_info *info,
80381 #endif
80382
80383 static int get_info(struct net *net, void __user *user,
80384- const int *len, int compat)
80385+ int len, int compat)
80386 {
80387 char name[XT_TABLE_MAXNAMELEN];
80388 struct xt_table *t;
80389 int ret;
80390
80391- if (*len != sizeof(struct ip6t_getinfo)) {
80392- duprintf("length %u != %zu\n", *len,
80393+ if (len != sizeof(struct ip6t_getinfo)) {
80394+ duprintf("length %u != %zu\n", len,
80395 sizeof(struct ip6t_getinfo));
80396 return -EINVAL;
80397 }
80398@@ -1122,7 +1122,7 @@ static int get_info(struct net *net, void __user *user,
80399 info.size = private->size;
80400 strcpy(info.name, name);
80401
80402- if (copy_to_user(user, &info, *len) != 0)
80403+ if (copy_to_user(user, &info, len) != 0)
80404 ret = -EFAULT;
80405 else
80406 ret = 0;
80407@@ -1976,7 +1976,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
80408
80409 switch (cmd) {
80410 case IP6T_SO_GET_INFO:
80411- ret = get_info(sock_net(sk), user, len, 1);
80412+ ret = get_info(sock_net(sk), user, *len, 1);
80413 break;
80414 case IP6T_SO_GET_ENTRIES:
80415 ret = compat_get_entries(sock_net(sk), user, len);
80416@@ -2023,7 +2023,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
80417
80418 switch (cmd) {
80419 case IP6T_SO_GET_INFO:
80420- ret = get_info(sock_net(sk), user, len, 0);
80421+ ret = get_info(sock_net(sk), user, *len, 0);
80422 break;
80423
80424 case IP6T_SO_GET_ENTRIES:
80425diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
80426index d8e95c7..81422bc 100644
80427--- a/net/ipv6/raw.c
80428+++ b/net/ipv6/raw.c
80429@@ -379,7 +379,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
80430 {
80431 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
80432 skb_checksum_complete(skb)) {
80433- atomic_inc(&sk->sk_drops);
80434+ atomic_inc_unchecked(&sk->sk_drops);
80435 kfree_skb(skb);
80436 return NET_RX_DROP;
80437 }
80438@@ -407,7 +407,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
80439 struct raw6_sock *rp = raw6_sk(sk);
80440
80441 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
80442- atomic_inc(&sk->sk_drops);
80443+ atomic_inc_unchecked(&sk->sk_drops);
80444 kfree_skb(skb);
80445 return NET_RX_DROP;
80446 }
80447@@ -431,7 +431,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
80448
80449 if (inet->hdrincl) {
80450 if (skb_checksum_complete(skb)) {
80451- atomic_inc(&sk->sk_drops);
80452+ atomic_inc_unchecked(&sk->sk_drops);
80453 kfree_skb(skb);
80454 return NET_RX_DROP;
80455 }
80456@@ -604,7 +604,7 @@ out:
80457 return err;
80458 }
80459
80460-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
80461+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
80462 struct flowi6 *fl6, struct dst_entry **dstp,
80463 unsigned int flags)
80464 {
80465@@ -916,12 +916,15 @@ do_confirm:
80466 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
80467 char __user *optval, int optlen)
80468 {
80469+ struct icmp6_filter filter;
80470+
80471 switch (optname) {
80472 case ICMPV6_FILTER:
80473 if (optlen > sizeof(struct icmp6_filter))
80474 optlen = sizeof(struct icmp6_filter);
80475- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
80476+ if (copy_from_user(&filter, optval, optlen))
80477 return -EFAULT;
80478+ raw6_sk(sk)->filter = filter;
80479 return 0;
80480 default:
80481 return -ENOPROTOOPT;
80482@@ -934,6 +937,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
80483 char __user *optval, int __user *optlen)
80484 {
80485 int len;
80486+ struct icmp6_filter filter;
80487
80488 switch (optname) {
80489 case ICMPV6_FILTER:
80490@@ -945,7 +949,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
80491 len = sizeof(struct icmp6_filter);
80492 if (put_user(len, optlen))
80493 return -EFAULT;
80494- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
80495+ filter = raw6_sk(sk)->filter;
80496+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
80497 return -EFAULT;
80498 return 0;
80499 default:
80500@@ -1253,7 +1258,7 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
80501 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
80502 0,
80503 sock_i_ino(sp),
80504- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
80505+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
80506 }
80507
80508 static int raw6_seq_show(struct seq_file *seq, void *v)
80509diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
80510index 26175bf..fc3e4fb 100644
80511--- a/net/ipv6/tcp_ipv6.c
80512+++ b/net/ipv6/tcp_ipv6.c
80513@@ -106,6 +106,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
80514 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
80515 }
80516
80517+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80518+extern int grsec_enable_blackhole;
80519+#endif
80520+
80521 static void tcp_v6_hash(struct sock *sk)
80522 {
80523 if (sk->sk_state != TCP_CLOSE) {
80524@@ -1524,6 +1528,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
80525 return 0;
80526
80527 reset:
80528+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80529+ if (!grsec_enable_blackhole)
80530+#endif
80531 tcp_v6_send_reset(sk, skb);
80532 discard:
80533 if (opt_skb)
80534@@ -1605,12 +1612,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
80535 TCP_SKB_CB(skb)->sacked = 0;
80536
80537 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
80538- if (!sk)
80539+ if (!sk) {
80540+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80541+ ret = 1;
80542+#endif
80543 goto no_tcp_socket;
80544+ }
80545
80546 process:
80547- if (sk->sk_state == TCP_TIME_WAIT)
80548+ if (sk->sk_state == TCP_TIME_WAIT) {
80549+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80550+ ret = 2;
80551+#endif
80552 goto do_time_wait;
80553+ }
80554
80555 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
80556 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
80557@@ -1659,6 +1674,10 @@ no_tcp_socket:
80558 bad_packet:
80559 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
80560 } else {
80561+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80562+ if (!grsec_enable_blackhole || (ret == 1 &&
80563+ (skb->dev->flags & IFF_LOOPBACK)))
80564+#endif
80565 tcp_v6_send_reset(NULL, skb);
80566 }
80567
80568diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
80569index fc99972..69397e8 100644
80570--- a/net/ipv6/udp.c
80571+++ b/net/ipv6/udp.c
80572@@ -51,6 +51,10 @@
80573 #include <trace/events/skb.h>
80574 #include "udp_impl.h"
80575
80576+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80577+extern int grsec_enable_blackhole;
80578+#endif
80579+
80580 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
80581 {
80582 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
80583@@ -395,7 +399,7 @@ try_again:
80584 if (unlikely(err)) {
80585 trace_kfree_skb(skb, udpv6_recvmsg);
80586 if (!peeked) {
80587- atomic_inc(&sk->sk_drops);
80588+ atomic_inc_unchecked(&sk->sk_drops);
80589 if (is_udp4)
80590 UDP_INC_STATS_USER(sock_net(sk),
80591 UDP_MIB_INERRORS,
80592@@ -633,7 +637,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
80593 return rc;
80594 drop:
80595 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
80596- atomic_inc(&sk->sk_drops);
80597+ atomic_inc_unchecked(&sk->sk_drops);
80598 kfree_skb(skb);
80599 return -1;
80600 }
80601@@ -691,7 +695,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
80602 if (likely(skb1 == NULL))
80603 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
80604 if (!skb1) {
80605- atomic_inc(&sk->sk_drops);
80606+ atomic_inc_unchecked(&sk->sk_drops);
80607 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
80608 IS_UDPLITE(sk));
80609 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
80610@@ -862,6 +866,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
80611 goto discard;
80612
80613 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
80614+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80615+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
80616+#endif
80617 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
80618
80619 kfree_skb(skb);
80620@@ -1473,7 +1480,7 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
80621 0,
80622 sock_i_ino(sp),
80623 atomic_read(&sp->sk_refcnt), sp,
80624- atomic_read(&sp->sk_drops));
80625+ atomic_read_unchecked(&sp->sk_drops));
80626 }
80627
80628 int udp6_seq_show(struct seq_file *seq, void *v)
80629diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
80630index 496ce2c..f79fac8 100644
80631--- a/net/irda/ircomm/ircomm_tty.c
80632+++ b/net/irda/ircomm/ircomm_tty.c
80633@@ -311,12 +311,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
80634 add_wait_queue(&port->open_wait, &wait);
80635
80636 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
80637- __FILE__, __LINE__, tty->driver->name, port->count);
80638+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
80639
80640 spin_lock_irqsave(&port->lock, flags);
80641 if (!tty_hung_up_p(filp)) {
80642 extra_count = 1;
80643- port->count--;
80644+ atomic_dec(&port->count);
80645 }
80646 spin_unlock_irqrestore(&port->lock, flags);
80647 port->blocked_open++;
80648@@ -352,7 +352,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
80649 }
80650
80651 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
80652- __FILE__, __LINE__, tty->driver->name, port->count);
80653+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
80654
80655 schedule();
80656 }
80657@@ -363,13 +363,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
80658 if (extra_count) {
80659 /* ++ is not atomic, so this should be protected - Jean II */
80660 spin_lock_irqsave(&port->lock, flags);
80661- port->count++;
80662+ atomic_inc(&port->count);
80663 spin_unlock_irqrestore(&port->lock, flags);
80664 }
80665 port->blocked_open--;
80666
80667 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
80668- __FILE__, __LINE__, tty->driver->name, port->count);
80669+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
80670
80671 if (!retval)
80672 port->flags |= ASYNC_NORMAL_ACTIVE;
80673@@ -443,12 +443,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
80674
80675 /* ++ is not atomic, so this should be protected - Jean II */
80676 spin_lock_irqsave(&self->port.lock, flags);
80677- self->port.count++;
80678+ atomic_inc(&self->port.count);
80679 spin_unlock_irqrestore(&self->port.lock, flags);
80680 tty_port_tty_set(&self->port, tty);
80681
80682 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
80683- self->line, self->port.count);
80684+ self->line, atomic_read(&self->port.count));
80685
80686 /* Not really used by us, but lets do it anyway */
80687 tty->low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
80688@@ -985,7 +985,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
80689 tty_kref_put(port->tty);
80690 }
80691 port->tty = NULL;
80692- port->count = 0;
80693+ atomic_set(&port->count, 0);
80694 spin_unlock_irqrestore(&port->lock, flags);
80695
80696 wake_up_interruptible(&port->open_wait);
80697@@ -1342,7 +1342,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
80698 seq_putc(m, '\n');
80699
80700 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
80701- seq_printf(m, "Open count: %d\n", self->port.count);
80702+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
80703 seq_printf(m, "Max data size: %d\n", self->max_data_size);
80704 seq_printf(m, "Max header size: %d\n", self->max_header_size);
80705
80706diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
80707index cd6f7a9..e63fe89 100644
80708--- a/net/iucv/af_iucv.c
80709+++ b/net/iucv/af_iucv.c
80710@@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
80711
80712 write_lock_bh(&iucv_sk_list.lock);
80713
80714- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
80715+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
80716 while (__iucv_get_sock_by_name(name)) {
80717 sprintf(name, "%08x",
80718- atomic_inc_return(&iucv_sk_list.autobind_name));
80719+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
80720 }
80721
80722 write_unlock_bh(&iucv_sk_list.lock);
80723diff --git a/net/key/af_key.c b/net/key/af_key.c
80724index 08897a3..0b812ab 100644
80725--- a/net/key/af_key.c
80726+++ b/net/key/af_key.c
80727@@ -3019,10 +3019,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
80728 static u32 get_acqseq(void)
80729 {
80730 u32 res;
80731- static atomic_t acqseq;
80732+ static atomic_unchecked_t acqseq;
80733
80734 do {
80735- res = atomic_inc_return(&acqseq);
80736+ res = atomic_inc_return_unchecked(&acqseq);
80737 } while (!res);
80738 return res;
80739 }
80740diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
80741index 7371f67..9897314 100644
80742--- a/net/mac80211/cfg.c
80743+++ b/net/mac80211/cfg.c
80744@@ -2594,7 +2594,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
80745 else
80746 local->probe_req_reg--;
80747
80748- if (!local->open_count)
80749+ if (!local_read(&local->open_count))
80750 break;
80751
80752 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
80753diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
80754index 156e583..076e28a 100644
80755--- a/net/mac80211/ieee80211_i.h
80756+++ b/net/mac80211/ieee80211_i.h
80757@@ -28,6 +28,7 @@
80758 #include <net/ieee80211_radiotap.h>
80759 #include <net/cfg80211.h>
80760 #include <net/mac80211.h>
80761+#include <asm/local.h>
80762 #include "key.h"
80763 #include "sta_info.h"
80764 #include "debug.h"
80765@@ -848,7 +849,7 @@ struct ieee80211_local {
80766 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
80767 spinlock_t queue_stop_reason_lock;
80768
80769- int open_count;
80770+ local_t open_count;
80771 int monitors, cooked_mntrs;
80772 /* number of interfaces with corresponding FIF_ flags */
80773 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
80774@@ -1047,8 +1048,8 @@ struct ieee80211_local {
80775 struct work_struct dynamic_ps_enable_work;
80776 struct work_struct dynamic_ps_disable_work;
80777 struct timer_list dynamic_ps_timer;
80778- struct notifier_block network_latency_notifier;
80779- struct notifier_block ifa_notifier;
80780+ notifier_block_no_const network_latency_notifier;
80781+ notifier_block_no_const ifa_notifier;
80782
80783 /*
80784 * The dynamic ps timeout configured from user space via WEXT -
80785diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
80786index 7de7717..3de8e97 100644
80787--- a/net/mac80211/iface.c
80788+++ b/net/mac80211/iface.c
80789@@ -465,7 +465,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
80790 break;
80791 }
80792
80793- if (local->open_count == 0) {
80794+ if (local_read(&local->open_count) == 0) {
80795 res = drv_start(local);
80796 if (res)
80797 goto err_del_bss;
80798@@ -508,7 +508,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
80799 break;
80800 }
80801
80802- if (local->monitors == 0 && local->open_count == 0) {
80803+ if (local->monitors == 0 && local_read(&local->open_count) == 0) {
80804 res = ieee80211_add_virtual_monitor(local);
80805 if (res)
80806 goto err_stop;
80807@@ -616,7 +616,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
80808 mutex_unlock(&local->mtx);
80809
80810 if (coming_up)
80811- local->open_count++;
80812+ local_inc(&local->open_count);
80813
80814 if (hw_reconf_flags)
80815 ieee80211_hw_config(local, hw_reconf_flags);
80816@@ -630,7 +630,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
80817 err_del_interface:
80818 drv_remove_interface(local, sdata);
80819 err_stop:
80820- if (!local->open_count)
80821+ if (!local_read(&local->open_count))
80822 drv_stop(local);
80823 err_del_bss:
80824 sdata->bss = NULL;
80825@@ -762,7 +762,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
80826 }
80827
80828 if (going_down)
80829- local->open_count--;
80830+ local_dec(&local->open_count);
80831
80832 switch (sdata->vif.type) {
80833 case NL80211_IFTYPE_AP_VLAN:
80834@@ -827,7 +827,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
80835
80836 ieee80211_recalc_ps(local, -1);
80837
80838- if (local->open_count == 0) {
80839+ if (local_read(&local->open_count) == 0) {
80840 if (local->ops->napi_poll)
80841 napi_disable(&local->napi);
80842 ieee80211_clear_tx_pending(local);
80843@@ -859,7 +859,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
80844 }
80845 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
80846
80847- if (local->monitors == local->open_count && local->monitors > 0)
80848+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
80849 ieee80211_add_virtual_monitor(local);
80850 }
80851
80852diff --git a/net/mac80211/main.c b/net/mac80211/main.c
80853index f57f597..e0a7c03 100644
80854--- a/net/mac80211/main.c
80855+++ b/net/mac80211/main.c
80856@@ -164,7 +164,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
80857 local->hw.conf.power_level = power;
80858 }
80859
80860- if (changed && local->open_count) {
80861+ if (changed && local_read(&local->open_count)) {
80862 ret = drv_config(local, changed);
80863 /*
80864 * Goal:
80865diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
80866index 5c572e7..ecf75ce 100644
80867--- a/net/mac80211/pm.c
80868+++ b/net/mac80211/pm.c
80869@@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
80870 struct ieee80211_sub_if_data *sdata;
80871 struct sta_info *sta;
80872
80873- if (!local->open_count)
80874+ if (!local_read(&local->open_count))
80875 goto suspend;
80876
80877 ieee80211_scan_cancel(local);
80878@@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
80879 cancel_work_sync(&local->dynamic_ps_enable_work);
80880 del_timer_sync(&local->dynamic_ps_timer);
80881
80882- local->wowlan = wowlan && local->open_count;
80883+ local->wowlan = wowlan && local_read(&local->open_count);
80884 if (local->wowlan) {
80885 int err = drv_suspend(local, wowlan);
80886 if (err < 0) {
80887@@ -143,7 +143,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
80888 drv_remove_interface(local, sdata);
80889
80890 /* stop hardware - this must stop RX */
80891- if (local->open_count)
80892+ if (local_read(&local->open_count))
80893 ieee80211_stop_device(local);
80894
80895 suspend:
80896diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
80897index 3313c11..bec9f17 100644
80898--- a/net/mac80211/rate.c
80899+++ b/net/mac80211/rate.c
80900@@ -494,7 +494,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
80901
80902 ASSERT_RTNL();
80903
80904- if (local->open_count)
80905+ if (local_read(&local->open_count))
80906 return -EBUSY;
80907
80908 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
80909diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
80910index c97a065..ff61928 100644
80911--- a/net/mac80211/rc80211_pid_debugfs.c
80912+++ b/net/mac80211/rc80211_pid_debugfs.c
80913@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
80914
80915 spin_unlock_irqrestore(&events->lock, status);
80916
80917- if (copy_to_user(buf, pb, p))
80918+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
80919 return -EFAULT;
80920
80921 return p;
80922diff --git a/net/mac80211/util.c b/net/mac80211/util.c
80923index 0151ae3..26709d3 100644
80924--- a/net/mac80211/util.c
80925+++ b/net/mac80211/util.c
80926@@ -1332,7 +1332,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
80927 }
80928 #endif
80929 /* everything else happens only if HW was up & running */
80930- if (!local->open_count)
80931+ if (!local_read(&local->open_count))
80932 goto wake_up;
80933
80934 /*
80935diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
80936index fefa514..0755f23 100644
80937--- a/net/netfilter/Kconfig
80938+++ b/net/netfilter/Kconfig
80939@@ -929,6 +929,16 @@ config NETFILTER_XT_MATCH_ESP
80940
80941 To compile it as a module, choose M here. If unsure, say N.
80942
80943+config NETFILTER_XT_MATCH_GRADM
80944+ tristate '"gradm" match support'
80945+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
80946+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
80947+ ---help---
80948+ The gradm match allows to match on grsecurity RBAC being enabled.
80949+ It is useful when iptables rules are applied early on bootup to
80950+ prevent connections to the machine (except from a trusted host)
80951+ while the RBAC system is disabled.
80952+
80953 config NETFILTER_XT_MATCH_HASHLIMIT
80954 tristate '"hashlimit" match support'
80955 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
80956diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
80957index 3259697..54d5393 100644
80958--- a/net/netfilter/Makefile
80959+++ b/net/netfilter/Makefile
80960@@ -109,6 +109,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
80961 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
80962 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
80963 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
80964+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
80965 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
80966 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
80967 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
80968diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
80969index 1548df9..98ad9b4 100644
80970--- a/net/netfilter/ipvs/ip_vs_conn.c
80971+++ b/net/netfilter/ipvs/ip_vs_conn.c
80972@@ -557,7 +557,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
80973 /* Increase the refcnt counter of the dest */
80974 atomic_inc(&dest->refcnt);
80975
80976- conn_flags = atomic_read(&dest->conn_flags);
80977+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
80978 if (cp->protocol != IPPROTO_UDP)
80979 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
80980 flags = cp->flags;
80981@@ -902,7 +902,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
80982 atomic_set(&cp->refcnt, 1);
80983
80984 atomic_set(&cp->n_control, 0);
80985- atomic_set(&cp->in_pkts, 0);
80986+ atomic_set_unchecked(&cp->in_pkts, 0);
80987
80988 atomic_inc(&ipvs->conn_count);
80989 if (flags & IP_VS_CONN_F_NO_CPORT)
80990@@ -1183,7 +1183,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
80991
80992 /* Don't drop the entry if its number of incoming packets is not
80993 located in [0, 8] */
80994- i = atomic_read(&cp->in_pkts);
80995+ i = atomic_read_unchecked(&cp->in_pkts);
80996 if (i > 8 || i < 0) return 0;
80997
80998 if (!todrop_rate[i]) return 0;
80999diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
81000index 58918e2..4d177a9 100644
81001--- a/net/netfilter/ipvs/ip_vs_core.c
81002+++ b/net/netfilter/ipvs/ip_vs_core.c
81003@@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
81004 ret = cp->packet_xmit(skb, cp, pd->pp);
81005 /* do not touch skb anymore */
81006
81007- atomic_inc(&cp->in_pkts);
81008+ atomic_inc_unchecked(&cp->in_pkts);
81009 ip_vs_conn_put(cp);
81010 return ret;
81011 }
81012@@ -1681,7 +1681,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
81013 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
81014 pkts = sysctl_sync_threshold(ipvs);
81015 else
81016- pkts = atomic_add_return(1, &cp->in_pkts);
81017+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
81018
81019 if (ipvs->sync_state & IP_VS_STATE_MASTER)
81020 ip_vs_sync_conn(net, cp, pkts);
81021diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
81022index c4ee437..a774a74 100644
81023--- a/net/netfilter/ipvs/ip_vs_ctl.c
81024+++ b/net/netfilter/ipvs/ip_vs_ctl.c
81025@@ -787,7 +787,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
81026 ip_vs_rs_hash(ipvs, dest);
81027 write_unlock_bh(&ipvs->rs_lock);
81028 }
81029- atomic_set(&dest->conn_flags, conn_flags);
81030+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
81031
81032 /* bind the service */
81033 if (!dest->svc) {
81034@@ -2081,7 +2081,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
81035 " %-7s %-6d %-10d %-10d\n",
81036 &dest->addr.in6,
81037 ntohs(dest->port),
81038- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
81039+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
81040 atomic_read(&dest->weight),
81041 atomic_read(&dest->activeconns),
81042 atomic_read(&dest->inactconns));
81043@@ -2092,7 +2092,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
81044 "%-7s %-6d %-10d %-10d\n",
81045 ntohl(dest->addr.ip),
81046 ntohs(dest->port),
81047- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
81048+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
81049 atomic_read(&dest->weight),
81050 atomic_read(&dest->activeconns),
81051 atomic_read(&dest->inactconns));
81052@@ -2562,7 +2562,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
81053
81054 entry.addr = dest->addr.ip;
81055 entry.port = dest->port;
81056- entry.conn_flags = atomic_read(&dest->conn_flags);
81057+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
81058 entry.weight = atomic_read(&dest->weight);
81059 entry.u_threshold = dest->u_threshold;
81060 entry.l_threshold = dest->l_threshold;
81061@@ -3098,7 +3098,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
81062 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
81063 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
81064 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
81065- (atomic_read(&dest->conn_flags) &
81066+ (atomic_read_unchecked(&dest->conn_flags) &
81067 IP_VS_CONN_F_FWD_MASK)) ||
81068 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
81069 atomic_read(&dest->weight)) ||
81070diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
81071index effa10c..9058928 100644
81072--- a/net/netfilter/ipvs/ip_vs_sync.c
81073+++ b/net/netfilter/ipvs/ip_vs_sync.c
81074@@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
81075 cp = cp->control;
81076 if (cp) {
81077 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
81078- pkts = atomic_add_return(1, &cp->in_pkts);
81079+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
81080 else
81081 pkts = sysctl_sync_threshold(ipvs);
81082 ip_vs_sync_conn(net, cp->control, pkts);
81083@@ -758,7 +758,7 @@ control:
81084 if (!cp)
81085 return;
81086 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
81087- pkts = atomic_add_return(1, &cp->in_pkts);
81088+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
81089 else
81090 pkts = sysctl_sync_threshold(ipvs);
81091 goto sloop;
81092@@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
81093
81094 if (opt)
81095 memcpy(&cp->in_seq, opt, sizeof(*opt));
81096- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
81097+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
81098 cp->state = state;
81099 cp->old_state = cp->state;
81100 /*
81101diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
81102index cc4c809..50f8fe5 100644
81103--- a/net/netfilter/ipvs/ip_vs_xmit.c
81104+++ b/net/netfilter/ipvs/ip_vs_xmit.c
81105@@ -1202,7 +1202,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
81106 else
81107 rc = NF_ACCEPT;
81108 /* do not touch skb anymore */
81109- atomic_inc(&cp->in_pkts);
81110+ atomic_inc_unchecked(&cp->in_pkts);
81111 goto out;
81112 }
81113
81114@@ -1323,7 +1323,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
81115 else
81116 rc = NF_ACCEPT;
81117 /* do not touch skb anymore */
81118- atomic_inc(&cp->in_pkts);
81119+ atomic_inc_unchecked(&cp->in_pkts);
81120 goto out;
81121 }
81122
81123diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
81124index 0f241be..2c9be6d 100644
81125--- a/net/netfilter/nf_conntrack_core.c
81126+++ b/net/netfilter/nf_conntrack_core.c
81127@@ -1532,6 +1532,10 @@ err_extend:
81128 #define UNCONFIRMED_NULLS_VAL ((1<<30)+0)
81129 #define DYING_NULLS_VAL ((1<<30)+1)
81130
81131+#ifdef CONFIG_GRKERNSEC_HIDESYM
81132+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
81133+#endif
81134+
81135 static int nf_conntrack_init_net(struct net *net)
81136 {
81137 int ret;
81138@@ -1545,7 +1549,11 @@ static int nf_conntrack_init_net(struct net *net)
81139 goto err_stat;
81140 }
81141
81142+#ifdef CONFIG_GRKERNSEC_HIDESYM
81143+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
81144+#else
81145 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
81146+#endif
81147 if (!net->ct.slabname) {
81148 ret = -ENOMEM;
81149 goto err_slabname;
81150diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
81151index 9f199f2..719ad23 100644
81152--- a/net/netfilter/nfnetlink_log.c
81153+++ b/net/netfilter/nfnetlink_log.c
81154@@ -71,7 +71,7 @@ struct nfulnl_instance {
81155 };
81156
81157 static DEFINE_SPINLOCK(instances_lock);
81158-static atomic_t global_seq;
81159+static atomic_unchecked_t global_seq;
81160
81161 #define INSTANCE_BUCKETS 16
81162 static struct hlist_head instance_table[INSTANCE_BUCKETS];
81163@@ -527,7 +527,7 @@ __build_packet_message(struct nfulnl_instance *inst,
81164 /* global sequence number */
81165 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
81166 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
81167- htonl(atomic_inc_return(&global_seq))))
81168+ htonl(atomic_inc_return_unchecked(&global_seq))))
81169 goto nla_put_failure;
81170
81171 if (data_len) {
81172diff --git a/net/netfilter/xt_TEE.c b/net/netfilter/xt_TEE.c
81173index bd93e51..fcbbac4 100644
81174--- a/net/netfilter/xt_TEE.c
81175+++ b/net/netfilter/xt_TEE.c
81176@@ -31,7 +31,7 @@
81177 #endif
81178
81179 struct xt_tee_priv {
81180- struct notifier_block notifier;
81181+ notifier_block_no_const notifier;
81182 struct xt_tee_tginfo *tginfo;
81183 int oif;
81184 };
81185diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
81186new file mode 100644
81187index 0000000..c566332
81188--- /dev/null
81189+++ b/net/netfilter/xt_gradm.c
81190@@ -0,0 +1,51 @@
81191+/*
81192+ * gradm match for netfilter
81193